def GMLAN_BroadcastSocket(interface): """Returns a GMLAN broadcast socket using interface.""" return ISOTPSocket(interface, sid=0x101, did=0x0, basecls=GMLAN, extended_addr=0xfe)
def generate_isotp_list( found_packets, # type: Dict[int, Tuple[Packet, int]] can_interface, # type: Union[SuperSocket, str] extended_addressing=False # type: bool ): # type: (...) -> List[SuperSocket] """Generate a list of ISOTPSocket objects from the result of the `scan` or the `scan_extended` function. :param found_packets: result of the `scan` or `scan_extended` function :param can_interface: description string for a CAN interface to be used for the creation of the output. :param extended_addressing: print results from a scan with ISOTP extended addressing :return: A list of all found ISOTPSockets """ from scapy.contrib.isotp import ISOTPSocket socket_list = [] # type: List[SuperSocket] for pack in found_packets: pkt = found_packets[pack][0] dest_id = pkt.identifier pad = True if pkt.length == 8 else False if extended_addressing: source_id = pack >> 8 source_ext = int(pack - (source_id * 256)) dest_ext = orb(pkt.data[0]) socket_list.append( ISOTPSocket(can_interface, sid=source_id, extended_addr=source_ext, did=dest_id, extended_rx_addr=dest_ext, padding=pad, basecls=ISOTP)) else: source_id = pack socket_list.append( ISOTPSocket(can_interface, sid=source_id, did=dest_id, padding=pad, basecls=ISOTP)) return socket_list
def GMLAN_BroadcastSocket(interface): # type: (str) -> SuperSocket """ Returns a GMLAN broadcast socket using interface. :param interface: interface name :return: ISOTPSocket configured as GMLAN Broadcast Socket """ return ISOTPSocket(interface, sid=0x101, did=0x0, basecls=GMLAN, extended_addr=0xfe, padding=True)
def main(): channel = None interface = None source = 0x7e0 destination = 0x7df bitrate = None timeout = 0.1 supported = False unsupported = False verbose = False options = getopt.getopt( sys.argv[1:], 'i:c:s:d:b:t:hruv', ['interface=', 'channel=', 'source=', 'destination=', 'bitrate=', 'help', 'timeout=', 'supported', 'unsupported', 'verbose']) try: for opt, arg in options[0]: if opt in ('-i', '--interface'): interface = arg elif opt in ('-c', '--channel'): channel = arg elif opt in ('-s', '--source'): source = int(arg, 16) elif opt in ('-d', '--destination'): destination = int(arg, 16) elif opt in ('-b', '--bitrate'): bitrate = int(arg) elif opt in ('-h', '--help'): usage() sys.exit(-1) elif opt in ('-r', '--supported'): supported = True elif opt in ('-u', '--unsupported'): unsupported = True elif opt in ('-v', '--verbose'): verbose = True except getopt.GetoptError as msg: usage() print("ERROR:", msg, file=sys.stderr) raise SystemExit if channel is None or \ (PYTHON_CAN and (bitrate is None or interface is None)): usage() print("\nPlease provide all required arguments.\n", file=sys.stderr) sys.exit(-1) if 0 > source >= 0x800 or 0 > destination >= 0x800\ or source == destination: print("The ids must be >= 0 and < 0x800 and not equal.", file=sys.stderr) sys.exit(-1) if 0 > timeout: print("The timeout must be a positive value") sys.exit(-1) csock = None try: if PYTHON_CAN: csock = CANSocket(bustype='socketcan', channel=channel, bitrate=bitrate,) else: csock = CANSocket(channel) with ISOTPSocket(csock, source, destination, basecls=OBD, padding=True) as isock: signal.signal(signal.SIGINT, signal_handler) obd_scan(isock, timeout, supported, unsupported, verbose) except Exception as e: usage() print("\nSocket couldn't be created. Check your arguments.\n", file=sys.stderr) print(e, file=sys.stderr) sys.exit(-1) finally: if csock is not None: csock.close()
def main(): channel = None interface = None source = 0x7e0 destination = 0x7df timeout = 0.1 full_scan = False specific_scan = False verbose = False python_can_args = None custom_enumerators = [] conf.verb = -1 options = getopt.getopt(sys.argv[1:], 'i:c:s:d:a:t:hfv1236789A', [ 'interface=', 'channel=', 'source=', 'destination=', 'help', 'timeout=', 'python-can_args=', 'full', 'verbose' ]) try: for opt, arg in options[0]: if opt in ('-i', '--interface'): interface = arg elif opt in ('-c', '--channel'): channel = arg elif opt in ('-a', '--python-can_args'): python_can_args = arg elif opt in ('-s', '--source'): source = int(arg, 16) elif opt in ('-d', '--destination'): destination = int(arg, 16) elif opt in ('-h', '--help'): usage(False) sys.exit(0) elif opt in ('-t', '--timeout'): timeout = float(arg) elif opt in ('-f', '--full'): full_scan = True elif opt == '-1': specific_scan = True custom_enumerators += [OBD_S01_Enumerator] elif opt == '-2': specific_scan = True custom_enumerators += [OBD_S02_Enumerator] elif opt == '-3': specific_scan = True custom_enumerators += [OBD_S03_Enumerator] elif opt == '-6': specific_scan = True custom_enumerators += [OBD_S06_Enumerator] elif opt == '-7': specific_scan = True custom_enumerators += [OBD_S07_Enumerator] elif opt == '-8': specific_scan = True custom_enumerators += [OBD_S08_Enumerator] elif opt == '-9': specific_scan = True custom_enumerators += [OBD_S09_Enumerator] elif opt == '-A': specific_scan = True custom_enumerators += [OBD_S0A_Enumerator] elif opt in ('-v', '--verbose'): verbose = True except getopt.GetoptError as msg: usage(True) print("ERROR:", msg, file=sys.stderr) raise SystemExit if channel is None or \ (PYTHON_CAN and interface is None): usage(True) print("\nPlease provide all required arguments.\n", file=sys.stderr) sys.exit(1) if 0 > source >= 0x800 or 0 > destination >= 0x800\ or source == destination: print("The ids must be >= 0 and < 0x800 and not equal.", file=sys.stderr) sys.exit(1) if 0 > timeout: print("The timeout must be a positive value") sys.exit(1) csock = None try: if PYTHON_CAN: if python_can_args: arg_dict = dict((k, literal_eval(v)) for k, v in ( pair.split('=') for pair in re.split(', | |,', python_can_args))) csock = CANSocket(bustype=interface, channel=channel, **arg_dict) else: csock = CANSocket(bustype=interface, channel=channel) else: csock = CANSocket(channel=channel) with ISOTPSocket(csock, source, destination, basecls=OBD, padding=True) as isock: signal.signal(signal.SIGINT, signal_handler) if specific_scan: es = custom_enumerators else: es = OBD_Scanner.default_enumerator_clss s = OBD_Scanner(isock, enumerators=es, full_scan=full_scan, verbose=verbose, timeout=timeout) print("Starting OBD-Scan...") s.scan() for e in s.enumerators: e.show() except Exception as e: usage(True) print("\nSocket couldn't be created. Check your arguments.\n", file=sys.stderr) print(e, file=sys.stderr) sys.exit(1) finally: if csock is not None: csock.close()
def get_isotp_socket(csock, source, destination): return ISOTPSocket(csock, source, destination, basecls=OBD, padding=True)
def main(): channel = None interface = None source = 0x7e0 destination = 0x7df timeout = 0.1 supported = False unsupported = False verbose = False python_can_args = None options = getopt.getopt(sys.argv[1:], 'i:c:s:d:a:t:hruv', [ 'interface=', 'channel=', 'source=', 'destination=', 'help', 'timeout=', 'python-can_args=', 'supported', 'unsupported', 'verbose' ]) try: for opt, arg in options[0]: if opt in ('-i', '--interface'): interface = arg elif opt in ('-c', '--channel'): channel = arg elif opt in ('-a', '--python-can_args'): python_can_args = arg elif opt in ('-s', '--source'): source = int(arg, 16) elif opt in ('-d', '--destination'): destination = int(arg, 16) elif opt in ('-h', '--help'): usage(False) sys.exit(0) elif opt in ('-t', '--timeout'): timeout = float(arg) elif opt in ('-r', '--supported'): supported = True elif opt in ('-u', '--unsupported'): unsupported = True elif opt in ('-v', '--verbose'): verbose = True except getopt.GetoptError as msg: usage(True) print("ERROR:", msg, file=sys.stderr) raise SystemExit if channel is None or \ (PYTHON_CAN and interface is None): usage(True) print("\nPlease provide all required arguments.\n", file=sys.stderr) sys.exit(1) if 0 > source >= 0x800 or 0 > destination >= 0x800\ or source == destination: print("The ids must be >= 0 and < 0x800 and not equal.", file=sys.stderr) sys.exit(1) if 0 > timeout: print("The timeout must be a positive value") sys.exit(1) csock = None try: if PYTHON_CAN: if python_can_args: arg_dict = dict((k, literal_eval(v)) for k, v in ( pair.split('=') for pair in re.split(', | |,', python_can_args))) csock = CANSocket(bustype=interface, channel=channel, **arg_dict) else: csock = CANSocket(bustype=interface, channel=channel) else: csock = CANSocket(channel=channel) with ISOTPSocket(csock, source, destination, basecls=OBD, padding=True) as isock: signal.signal(signal.SIGINT, signal_handler) obd_scan(isock, timeout, supported, unsupported, verbose) except Exception as e: usage(True) print("\nSocket couldn't be created. Check your arguments.\n", file=sys.stderr) print(e, file=sys.stderr) sys.exit(1) finally: if csock is not None: csock.close()