Dict, Tuple, Set, Callable, cast, NamedTuple, orb from scapy.error import Scapy_Exception, log_interactive from scapy.utils import make_lined_table, EDecimal import scapy.modules.six as six from scapy.packet import Packet from scapy.contrib.automotive.ecu import EcuState, EcuResponse from scapy.contrib.automotive.scanner.test_case import AutomotiveTestCase, \ StateGenerator, _SocketUnion, _TransitionTuple from scapy.contrib.automotive.scanner.configuration import \ AutomotiveTestCaseExecutorConfiguration from scapy.contrib.automotive.scanner.graph import _Edge # Definition outside the class ServiceEnumerator to allow pickling _AutomotiveTestCaseScanResult = NamedTuple( "_AutomotiveTestCaseScanResult", [("state", EcuState), ("req", Packet), ("resp", Optional[Packet]), ("req_ts", Union[EDecimal, float]), ("resp_ts", Optional[Union[EDecimal, float]])]) _AutomotiveTestCaseFilteredScanResult = NamedTuple( "_AutomotiveTestCaseFilteredScanResult", [("state", EcuState), ("req", Packet), ("resp", Packet), ("req_ts", Union[EDecimal, float]), ("resp_ts", Union[EDecimal, float])]) @six.add_metaclass(abc.ABCMeta) class ServiceEnumerator(AutomotiveTestCase): """ Base class for ServiceEnumerators of automotive diagnostic protocols """
Iterator, List, NamedTuple, Optional, Tuple, Type, TypeVar, Union, ) from scapy.packet import Packet ############# # Results # ############# QueryAnswer = NamedTuple("QueryAnswer", [("query", Packet), ("answer", Packet)]) _Inner = TypeVar("_Inner", Packet, QueryAnswer) @six.add_metaclass(PacketList_metaclass) class _PacketList(Generic[_Inner]): __slots__ = ["stats", "res", "listname"] def __init__( self, res=None, # type: Optional[Union[_PacketList[_Inner], List[_Inner]]] # noqa: E501 name="PacketList", # type: str stats=None # type: Optional[List[Type[Packet]]] ): # type: (...) -> None
# TODO: Refactor this import from scapy.contrib.automotive.uds_ecu_states import * # noqa: F401, F403 if six.PY34: from abc import ABC else: from abc import ABCMeta ABC = ABCMeta('ABC', (), {}) # type: ignore # Definition outside the class UDS_RMBASequentialEnumerator # to allow pickling _PointOfInterest = NamedTuple( "_PointOfInterest", [ ("memory_address", int), ("direction", bool), # True = increasing / upward, False = decreasing / downward # noqa: E501 ("memorySizeLen", int), ("memoryAddressLen", int), ("memorySize", int) ]) class UDS_Enumerator(ServiceEnumerator, ABC): @staticmethod def _get_negative_response_code(resp): # type: (Packet) -> int return resp.negativeResponseCode @staticmethod def _get_negative_response_desc(nrc): # type: (int) -> str