def __init__(self, app, phy, int_num): # TODO: un-hardcode string index (last arg before 'verbose') super(USBCDCDataInterface, self).__init__( app=app, phy=phy, interface_number=int_num, interface_alternate=0, interface_class=USBClass.CDCData, interface_subclass=0, interface_protocol=0, interface_string_index=0, endpoints=[ USBEndpoint(app=app, phy=phy, number=0x1, direction=USBEndpoint.direction_out, transfer_type=USBEndpoint.transfer_type_bulk, sync_type=USBEndpoint.sync_type_none, usage_type=USBEndpoint.usage_type_data, max_packet_size=0x40, interval=0x00, handler=self.handle_ep1_data_available), USBEndpoint(app=app, phy=phy, number=0x2, direction=USBEndpoint.direction_in, transfer_type=USBEndpoint.transfer_type_bulk, sync_type=USBEndpoint.sync_type_none, usage_type=USBEndpoint.usage_type_data, max_packet_size=0x40, interval=0x00, handler=self.handle_ep2_buffer_available) ], usb_class=USBCDCClass(app, phy))
def __init__(self, app, phy, scsi_device, usbclass, sub, proto): super(USBMassStorageInterface, self).__init__( app=app, phy=phy, interface_number=0, interface_alternate=0, interface_class=usbclass, interface_subclass=sub, interface_protocol=proto, interface_string_index=0, endpoints=[ USBEndpoint(app=app, phy=phy, number=1, direction=USBEndpoint.direction_out, transfer_type=USBEndpoint.transfer_type_bulk, sync_type=USBEndpoint.sync_type_none, usage_type=USBEndpoint.usage_type_data, max_packet_size=0x40, interval=0, handler=self.handle_data_available), USBEndpoint(app=app, phy=phy, number=3, direction=USBEndpoint.direction_in, transfer_type=USBEndpoint.transfer_type_bulk, sync_type=USBEndpoint.sync_type_none, usage_type=USBEndpoint.usage_type_data, max_packet_size=0x40, interval=0, handler=self.handle_buffer_available), ], usb_class=USBMassStorageClass(app, phy, scsi_device), ) self.scsi_device = scsi_device
def __init__(self, app, phy, interface_number): super(USBFtdiInterface, self).__init__( app=app, phy=phy, interface_number=interface_number, interface_alternate=0, interface_class=USBClass.VendorSpecific, interface_subclass=0xff, interface_protocol=0xff, interface_string_index=0, endpoints=[ USBEndpoint(app=app, phy=phy, number=1, direction=USBEndpoint.direction_out, transfer_type=USBEndpoint.transfer_type_bulk, sync_type=USBEndpoint.sync_type_none, usage_type=USBEndpoint.usage_type_data, max_packet_size=0x40, interval=0, handler=self.handle_data_available), USBEndpoint( app=app, phy=phy, number=3, direction=USBEndpoint.direction_in, transfer_type=USBEndpoint.transfer_type_bulk, sync_type=USBEndpoint.sync_type_none, usage_type=USBEndpoint.usage_type_data, max_packet_size=0x40, interval=0, handler=None # at this point, we don't send data to the host ) ], )
def __init__(self, app, phy, vid=0x2548, pid=0x1001, rev=0x0010, cs_interfaces=None, cdc_cls=None, bmCapabilities=0x01, **kwargs): if cdc_cls is None: cdc_cls = self.get_default_class(app, phy) cs_interfaces = [ # Header Functional Descriptor FD(app, phy, FD.Header, '\x01\x01'), # Call Management Functional Descriptor FD(app, phy, FD.CM, struct.pack('BB', bmCapabilities, USBCDCDevice.bDataInterface)), FD(app, phy, FD.DLM, struct.pack('B', bmCapabilities)), FD(app, phy, FD.UN, struct.pack('BB', USBCDCDevice.bControlInterface, USBCDCDevice.bDataInterface)), ] interfaces = [ USBInterface( app=app, phy=phy, interface_number=self.bDataInterface, interface_alternate=0, interface_class=USBClass.CDCData, interface_subclass=self.bDataSubclass, interface_protocol=self.bDataProtocol, interface_string_index=0, endpoints=[ USBEndpoint( app=app, phy=phy, number=0x1, direction=USBEndpoint.direction_out, transfer_type=USBEndpoint.transfer_type_bulk, sync_type=USBEndpoint.sync_type_none, usage_type=USBEndpoint.usage_type_data, max_packet_size=0x40, interval=0x00, handler=self.handle_ep1_data_available ), USBEndpoint( app=app, phy=phy, number=0x2, direction=USBEndpoint.direction_in, transfer_type=USBEndpoint.transfer_type_bulk, sync_type=USBEndpoint.sync_type_none, usage_type=USBEndpoint.usage_type_data, max_packet_size=0x40, interval=0x00, handler=self.handle_ep2_buffer_available ) ], usb_class=cdc_cls ) ] super(USBCdcDlDevice, self).__init__( app, phy, vid=vid, pid=pid, rev=rev, interfaces=interfaces, cs_interfaces=cs_interfaces, cdc_cls=cdc_cls, bmCapabilities=0x03, **kwargs ) self.receive_buffer = b''
def __init__(self, app, phy): super(USBKeyboardInterface, self).__init__( app=app, phy=phy, interface_number=0, interface_alternate=0, interface_class=USBClass.HID, interface_subclass=0, interface_protocol=0, interface_string_index=0, endpoints=[ USBEndpoint(app=app, phy=phy, number=2, direction=USBEndpoint.direction_in, transfer_type=USBEndpoint.transfer_type_interrupt, sync_type=USBEndpoint.sync_type_none, usage_type=USBEndpoint.usage_type_data, max_packet_size=0x40, interval=0x40, handler=self.handle_buffer_available) ], descriptors={ DescriptorType.hid: self.get_hid_descriptor, DescriptorType.report: self.get_report_descriptor }, usb_class=USBKeyboardClass(app, phy)) empty_preamble = [0x00] * 10 text = [0x0f, 0x00, 0x16, 0x00, 0x28, 0x00] self.keys = [chr(x) for x in empty_preamble + text] self.call_count = 0 self.first_call = None
def __init__(self, app, phy, num=0): # TODO: un-hardcode string index super(USBHubInterface, self).__init__( app=app, phy=phy, interface_number=num, interface_alternate=0, interface_class=USBClass.Hub, interface_subclass=0, interface_protocol=0, interface_string_index=0, endpoints=[ USBEndpoint(app=app, phy=phy, number=0x2, direction=USBEndpoint.direction_in, transfer_type=USBEndpoint.transfer_type_interrupt, sync_type=USBEndpoint.sync_type_none, usage_type=USBEndpoint.usage_type_data, max_packet_size=0x40, interval=0x40, handler=self.handle_buffer_available) ], descriptors={DescriptorType.hub: self.get_hub_descriptor}, usb_class=USBHubClass(app, phy))
def get_endpoint(self, num, direction, transfer_type, max_packet_size=0x40): return USBEndpoint( app=self.app, phy=self.phy, number=num, direction=direction, transfer_type=transfer_type, sync_type=USBEndpoint.sync_type_none, usage_type=USBEndpoint.usage_type_data, max_packet_size=max_packet_size, interval=1, handler=self.global_handler, usb_class=USBVendorSpecificClass(self.app, self.phy), usb_vendor=USBVendorSpecificVendor(self.app, self.phy) )
def __init__(self, app, phy, vid=0x2548, pid=0x1001, rev=0x0010, bmCapabilities=0x03, interfaces=None, cs_interfaces=None, cdc_cls=None, **kwargs): if cs_interfaces is None: cs_interfaces = [] if cdc_cls is None: cdc_cls = self.get_default_class(app, phy) if interfaces is None: interfaces = [] control_interface = USBCDCControlInterface( app=app, phy=phy, interface_number=self.bControlInterface, interface_alternate=0, interface_class=USBClass.CDC, interface_subclass=self.bControlSubclass, interface_protocol=self.bControlProtocol, interface_string_index=0, endpoints=[ USBEndpoint( app=app, phy=phy, number=0x3, direction=USBEndpoint.direction_in, transfer_type=USBEndpoint.transfer_type_interrupt, sync_type=USBEndpoint.sync_type_none, usage_type=USBEndpoint.usage_type_data, max_packet_size=0x40, interval=9, handler=self.handle_ep3_buffer_available ) ], cs_interfaces=cs_interfaces, ) interfaces.insert(0, control_interface) super(USBCDCDevice, self).__init__( app=app, phy=phy, device_class=USBClass.CDC, device_subclass=0, protocol_rel_num=0, max_packet_size_ep0=64, vendor_id=vid, product_id=pid, device_rev=rev, manufacturer_string='UMAP2 NetSolutions', product_string='UMAP2 CDC-TRON', serial_number_string='UMAP2-13337-CDC', configurations=[ USBConfiguration( app=app, phy=phy, index=1, string='Emulated CDC', interfaces=interfaces, ) ])
def __init__(self, app, phy, int_num, data_iface_num): bmCapabilities = 0x03 bControlInterface = int_num bDataInterface = data_iface_num super(USBCommunicationInterface, self).__init__( app=app, phy=phy, interface_number=int_num, interface_alternate=0, interface_class=USBClass.CDC, interface_subclass=0x02, interface_protocol=0x01, interface_string_index=0, endpoints=[ USBEndpoint(app=app, phy=phy, number=0x3, direction=USBEndpoint.direction_in, transfer_type=USBEndpoint.transfer_type_interrupt, sync_type=USBEndpoint.sync_type_none, usage_type=USBEndpoint.usage_type_data, max_packet_size=0x40, interval=0xff, handler=self.handle_ep3_buffer_available) ], cs_interfaces=[ # Header Functional Descriptor USBCSInterface('Header', app, phy, '\x00\x01\x01'), # Call Management Functional Descriptor USBCSInterface( 'CMF', app, phy, struct.pack('BBB', 1, bmCapabilities, bDataInterface)), USBCSInterface('ACMF1', app, phy, struct.pack('BB', 2, bmCapabilities)), USBCSInterface( 'ACMF2', app, phy, struct.pack('BBB', 6, bControlInterface, bDataInterface)), ], usb_class=USBCDCClass(app, phy))
def __init__(self, app, phy, int_num, usbclass, sub, proto): self.filename = time.strftime('%Y%m%d%H%M%S', time.localtime()) self.filename += '.pcl' self.writing = False endpoints0 = [ USBEndpoint( app=app, phy=phy, number=1, # endpoint address direction=USBEndpoint.direction_out, transfer_type=USBEndpoint.transfer_type_bulk, sync_type=USBEndpoint.sync_type_none, usage_type=USBEndpoint.usage_type_data, max_packet_size=0x40, # max packet size interval=0xff, # polling interval, see USB 2.0 spec Table 9-13 handler=self.handle_data_available # handler function ), USBEndpoint( app=app, phy=phy, number=2, # endpoint address direction=USBEndpoint.direction_in, transfer_type=USBEndpoint.transfer_type_bulk, sync_type=USBEndpoint.sync_type_none, usage_type=USBEndpoint.usage_type_data, max_packet_size=0x40, # max packet size interval=0, # polling interval, see USB 2.0 spec Table 9-13 handler=None # handler function ) ] endpoints1 = [ USBEndpoint( app=app, phy=phy, number=1, # endpoint address direction=USBEndpoint.direction_out, transfer_type=USBEndpoint.transfer_type_bulk, sync_type=USBEndpoint.sync_type_none, usage_type=USBEndpoint.usage_type_data, max_packet_size=0x40, # max packet size interval=0xff, # polling interval, see USB 2.0 spec Table 9-13 handler=self.handle_data_available # handler function ), USBEndpoint( app=app, phy=phy, number=2, # endpoint address direction=USBEndpoint.direction_in, transfer_type=USBEndpoint.transfer_type_bulk, sync_type=USBEndpoint.sync_type_none, usage_type=USBEndpoint.usage_type_data, max_packet_size=0x40, # max packet size interval=0, # polling interval, see USB 2.0 spec Table 9-13 handler=None # handler function ) ] if int_num == 0: endpoints = endpoints0 if int_num == 1: endpoints = endpoints1 # TODO: un-hardcode string index (last arg before 'verbose') super(USBPrinterInterface, self).__init__( app=app, phy=phy, interface_number=int_num, # interface number interface_alternate=0, # alternate setting interface_class=usbclass, # interface class interface_subclass=sub, # subclass interface_protocol=proto, # protocol interface_string_index=0, # string index endpoints=endpoints, device_class=USBPrinterClass(app, phy), )
def __init__(self, app, phy, vid=0x0d8c, pid=0x000c, rev=0x0001, *args, **kwargs): audio_streaming = AudioStreaming(app, phy, 2, 1) usb_class = USBAudioClass(app, phy) super(USBAudioDevice, self).__init__( app=app, phy=phy, device_class=USBClass.Unspecified, device_subclass=0, protocol_rel_num=0, max_packet_size_ep0=0x40, vendor_id=vid, product_id=pid, device_rev=rev, manufacturer_string='UMAP2 Sound Inc.', product_string='UMAP2 Audio Adapter', serial_number_string='UMAP2-12345-AUDIO', configurations=[ USBConfiguration( app=app, phy=phy, index=1, string='UMAP2 Audio Configuration', attributes=USBConfiguration.ATTR_BASE, interfaces=[ # standard AC interface (4.3.1) # At this point - with no endpoints USBAudioControlInterface( app=app, phy=phy, iface_num=0, iface_alt=0, iface_str_idx=0, cs_ifaces=[ # Class specific AC interface: header (4.3.2) USBCSInterface('ACHeader', app, phy, '\x01\x00\x01\x64\x00\x02\x01\x02'), # Class specific AC interface: input terminal (Table 4.3.2.1) USBCSInterface('ACInputTerminal0', app, phy, '\x02\x01\x01\x01\x00\x02\x03\x00\x00\x00'), USBCSInterface('ACInputTerminal1', app, phy, '\x02\x02\x01\x02\x00\x01\x01\x00\x00\x00'), # Class specific AC interface: output terminal (Table 4.3.2.2) USBCSInterface('ACOutputTerminal0', app, phy, '\x03\x06\x01\x03\x00\x09\x00'), USBCSInterface('ACOutputTerminal1', app, phy, '\x03\x07\x01\x01\x00\x08\x00'), # Class specific AC interface: selector unit (Table 4.3.2.4) USBCSInterface('ACSelectorUnit', app, phy, '\x05\x08\x01\x0a\x00'), # Class specific AC interface: feature unit (Table 4.3.2.5) USBCSInterface('ACFeatureUnit0', app, phy, '\x06\x09\x0f\x01\x01\x02\x02\x00'), USBCSInterface('ACFeatureUnit1', app, phy, '\x06\x0a\x02\x01\x43\x00\x00'), USBCSInterface('ACFeatureUnit2', app, phy, '\x06\x0d\x02\x01\x03\x00\x00'), # Class specific AC interface: mixer unit (Table 4.3.2.3) USBCSInterface('ACMixerUnit', app, phy, '\x04\x0f\x02\x01\x0d\x02\x03\x00\x00\x00\x00'), ], usb_class=usb_class ), USBAudioStreamingInterface( app=app, phy=phy, iface_num=1, iface_alt=0, iface_str_idx=0, cs_ifaces=[ USBCSInterface('ASGeneral', app, phy, '\x01\x01\x01\x01\x00'), USBCSInterface('ASFormatType', app, phy, '\x02\x01\x02\x02\x10\x02\x44\xac\x00\x44\xac\x00'), ], endpoints=[ USBEndpoint( app=app, phy=phy, number=1, direction=USBEndpoint.direction_out, transfer_type=USBEndpoint.transfer_type_isochronous, sync_type=USBEndpoint.sync_type_adaptive, usage_type=USBEndpoint.usage_type_data, max_packet_size=0x40, interval=1, handler=audio_streaming.data_available, cs_endpoints=[ USBCSEndpoint('ASEndpoint', app, phy, '\x01\x01\x01\x01\x00') ], usb_class=usb_class, ) ], usb_class=usb_class, ), USBAudioStreamingInterface( app=app, phy=phy, iface_num=2, iface_alt=0, iface_str_idx=0, cs_ifaces=[ USBCSInterface('ASGeneral', app, phy, '\x01\x07\x01\x01\x00'), USBCSInterface('ASFormatType', app, phy, '\x02\x01\x01\x02\x10\x02\x44\xac\x00\x44\xac\x00'), ], endpoints=[ USBEndpoint( app=app, phy=phy, number=2, direction=USBEndpoint.direction_in, transfer_type=USBEndpoint.transfer_type_isochronous, sync_type=USBEndpoint.sync_type_async, usage_type=USBEndpoint.usage_type_data, max_packet_size=0x40, interval=1, handler=audio_streaming.buffer_available, cs_endpoints=[ USBCSEndpoint('ASEndpoint', app, phy, '\x01\x01\x00\x00\x00') ], usb_class=usb_class, ) ], usb_class=usb_class, ) ] ), ], usb_vendor=None )
def __init__(self, app, phy): if not mtpdeviceloaded: raise Exception( 'You cannot use USBMtp until you install pymtpdevice') # TODO: un-hardcode string index (last arg before 'verbose') super(USBMtpInterface, self).__init__( app=app, phy=phy, interface_number=0, interface_alternate=0, interface_class=USBClass.VendorSpecific, interface_subclass=0xff, interface_protocol=0, interface_string_index=0, endpoints=[ USBEndpoint(app=app, phy=phy, number=1, direction=USBEndpoint.direction_out, transfer_type=USBEndpoint.transfer_type_bulk, sync_type=USBEndpoint.sync_type_none, usage_type=USBEndpoint.usage_type_data, max_packet_size=64, interval=0, handler=self.handle_ep1_data_available), USBEndpoint(app=app, phy=phy, number=2, direction=USBEndpoint.direction_in, transfer_type=USBEndpoint.transfer_type_bulk, sync_type=USBEndpoint.sync_type_none, usage_type=USBEndpoint.usage_type_data, max_packet_size=64, interval=0, handler=None), USBEndpoint(app=app, phy=phy, number=3, direction=USBEndpoint.direction_in, transfer_type=USBEndpoint.transfer_type_interrupt, sync_type=USBEndpoint.sync_type_none, usage_type=USBEndpoint.usage_type_data, max_packet_size=64, interval=32, handler=None), ], ) self.object = MtpObject.from_fs_recursive('mtp_fs') # self.object = MtpObject.from_fs_recursive('mtp_fs/eits.mp3') self.storage_info = MtpStorageInfo( st_type=1, fs_type=2, access=0, max_cap=150000, free_bytes=0, free_objs=0, desc='MyStorage', vol_id='Python MTP Device Stack', ) self.storage = MtpStorage(self.storage_info) self.storage.add_object(self.object) self.dev_info = MtpDeviceInfo( std_version=0x0064, mtp_vendor_ext_id=0x00000006, mtp_version=0x0064, mtp_extensions='microsoft.com: 1.0;', functional_mode=0x0000, capture_formats=[], playback_formats=[], manufacturer='UMAP2', model='Role', device_version='1.2', serial_number='3031323334353637', ) properties = [ MtpDeviceProperty(MtpDevicePropertyCode.MTP_DeviceFriendlyName, 0, MStr('UmapMtpDevice'), MStr('')), MtpDeviceProperty(MtpDevicePropertyCode.BatteryLevel, 0, UInt8(100), UInt8(0)) ] self.dev = MtpDevice(self.dev_info, properties, self.logger) self.dev.add_storage(self.storage) self.dev.set_fuzzer(app.fuzzer) self.api = MtpApi(self.dev) # OS String descriptor # self.add_string_with_id(50, 'MTP'.encode('utf-16') + b'\x00\x00') self.add_string_with_id(0xee, 'MSFT100'.encode('utf-16') + b'\x00\x00')
def __init__(self, app, phy, int_num, usbclass, sub, proto): descriptors = { DescriptorType.hid: self.get_hid_descriptor, DescriptorType.report: self.get_report_descriptor } wTotalLength = 0x0047 bInCollection = 0x02 baInterfaceNr1 = 0x01 baInterfaceNr2 = 0x02 cs_config1 = [ 0x01, # HEADER 0x0001, # bcdADC wTotalLength, # wTotalLength bInCollection, # bInCollection baInterfaceNr1, # baInterfaceNr1 baInterfaceNr2 # baInterfaceNr2 ] bTerminalID = 0x01 wTerminalType = 0x0101 bAssocTerminal = 0x0 bNrChannel = 0x02 wChannelConfig = 0x0002 cs_config2 = [ 0x02, # INPUT_TERMINAL bTerminalID, # bTerminalID wTerminalType, # wTerminalType bAssocTerminal, # bAssocTerminal bNrChannel, # bNrChannel wChannelConfig, # wChannelConfig 0, # iChannelNames 0 # iTerminal ] cs_config3 = [ 0x02, # INPUT_TERMINAL 0x02, # bTerminalID 0x0201, # wTerminalType 0, # bAssocTerminal 0x01, # bNrChannel 0x0001, # wChannelConfig 0, # iChannelNames 0 # iTerminal ] bSourceID = 0x09 cs_config4 = [ 0x03, # OUTPUT_TERMINAL 0x06, # bTerminalID 0x0301, # wTerminalType 0, # bAssocTerminal bSourceID, # bSourceID 0 # iTerminal ] cs_config5 = [ 0x03, # OUTPUT_TERMINAL 0x07, # bTerminalID 0x0101, # wTerminalType 0, # bAssocTerminal 0x0a, # bSourceID 0 # iTerminal ] bUnitID = 0x09 bSourceID = 0x01 bControlSize = 0x01 bmaControls0 = 0x01 bmaControls1 = 0x02 bmaControls2 = 0x02 cs_config6 = [ 0x06, # FEATURE_UNIT bUnitID, # bUnitID bSourceID, # bSourceID bControlSize, # bControlSize bmaControls0, # bmaControls0 bmaControls1, # bmaControls1 bmaControls2, # bmaControls2 0 # iFeature ] cs_config7 = [ 0x06, # FEATURE_UNIT 0x0a, # bUnitID 0x02, # bSourceID 0x01, # bControlSize 0x43, # bmaControls0 0x00, # bmaControls1 0x00, # bmaControls2 0 # iFeature ] cs_interfaces0 = [ USBCSInterface(app, phy, cs_config1, 1, 1, 0), USBCSInterface(app, phy, cs_config2, 1, 1, 0), USBCSInterface(app, phy, cs_config3, 1, 1, 0), USBCSInterface(app, phy, cs_config4, 1, 1, 0), USBCSInterface(app, phy, cs_config5, 1, 1, 0), USBCSInterface(app, phy, cs_config6, 1, 1, 0), USBCSInterface(app, phy, cs_config7, 1, 1, 0) ] # cs_config8 = [ # 0x01, # AS_GENERAL # 0x01, # bTerminalLink # 0x01, # bDelay # 0x0001 # wFormatTag # ] # cs_config9 = [ # 0x02, # FORMAT_TYPE # 0x01, # bFormatType # 0x02, # bNrChannels # 0x02, # bSubframeSize # 0x10, # bBitResolution # 0x02, # SamFreqType # 0x80bb00, # tSamFreq1 # 0x44ac00 # tSamFreq2 # ] cs_interfaces1 = [] cs_interfaces2 = [] cs_interfaces3 = [] # ep_cs_config1 = [ # 0x01, # EP_GENERAL # 0x01, # Endpoint number # 0x01, # bmAttributes # 0x01, # bLockDelayUnits # 0x0001, # wLockeDelay # ] endpoints0 = [ USBEndpoint(app=app, phy=phy, number=2, direction=USBEndpoint.direction_in, transfer_type=USBEndpoint.transfer_type_interrupt, sync_type=USBEndpoint.sync_type_none, usage_type=USBEndpoint.usage_type_data, max_packet_size=0x40, interval=0x02, handler=self.audio_ep2_buffer_available) ] if int_num == 3: endpoints = endpoints0 else: endpoints = [] if int_num == 0: cs_interfaces = cs_interfaces0 if int_num == 1: cs_interfaces = cs_interfaces1 if int_num == 2: cs_interfaces = cs_interfaces2 if int_num == 3: cs_interfaces = cs_interfaces3 # if self.int_num == 1: # endpoints = endpoints1 # TODO: un-hardcode string index super(USBAudioInterface, self).__init__(app=app, phy=phy, interface_number=int_num, interface_alternate=0, interface_class=usbclass, interface_subclass=sub, interface_protocol=proto, interface_string_index=0, endpoints=endpoints, descriptors=descriptors, cs_interfaces=cs_interfaces, device_class=USBAudioClass(app, phy))
def __init__(self, app, phy): descriptors = {DescriptorType.hid: self.get_icc_descriptor} self.clock_frequencies = [ 0x00003267, 0x000064ce, 0x0000c99d, 0x0001933a, 0x00032674, 0x00064ce7, 0x000c99ce, 0x00025cd7, 0x0003f011, 0x00004334, 0x00008669, 0x00010cd1, 0x000219a2, 0x00043345, 0x0008668a, 0x0002a00b, 0x00003073, 0x000060e6, 0x0000c1cc, 0x00018399, 0x00030732, 0x00060e63, 0x000122b3, 0x0001e47f, 0x00015006, 0x00009736, 0x0000fc04, 0x00002853, 0x000050a5, 0x0000a14a, 0x00014295, 0x00028529, 0x000078f8, 0x0000493e, 0x0000927c, 0x000124f8, 0x000249f0, 0x000493e0, 0x000927c0, 0x0001b774, 0x0002dc6c, 0x000030d4, 0x000061a8, 0x0000c350, 0x000186a0, 0x00030d40, 0x00061a80, 0x0001e848, 0x0000dbba, 0x00016e36, 0x0000f424, 0x00006ddd, 0x0000b71b ] self.data_rates = [] self.clock_freq = self.clock_frequencies[0] self.data_rate = 0 if not self.data_rates else self.data_rates[0] endpoints = [ # CCID command pipe USBEndpoint(app=app, phy=phy, number=1, direction=USBEndpoint.direction_out, transfer_type=USBEndpoint.transfer_type_bulk, sync_type=USBEndpoint.sync_type_none, usage_type=USBEndpoint.usage_type_data, max_packet_size=0x40, interval=0, handler=self.handle_data_available), # CCID response pipe USBEndpoint(app=app, phy=phy, number=2, direction=USBEndpoint.direction_in, transfer_type=USBEndpoint.transfer_type_bulk, sync_type=USBEndpoint.sync_type_none, usage_type=USBEndpoint.usage_type_data, max_packet_size=0x40, interval=0, handler=None), # CCID event notification pipe USBEndpoint(app=app, phy=phy, number=3, direction=USBEndpoint.direction_in, transfer_type=USBEndpoint.transfer_type_interrupt, sync_type=USBEndpoint.sync_type_none, usage_type=USBEndpoint.usage_type_data, max_packet_size=8, interval=0, handler=self.handle_buffer_available), ] # TODO: un-hardcode string index (last arg before 'verbose') super(USBSmartcardInterface, self).__init__(app=app, phy=phy, interface_number=0, interface_alternate=0, interface_class=USBClass.SmartCard, interface_subclass=0, interface_protocol=0, interface_string_index=0, endpoints=endpoints, descriptors=descriptors, usb_class=USBSmartcardClass(app, phy)) self.proto = 0 self.abProtocolDataStructure = b'\x11\x00\x00\x0a\x00' self.clock_status = 0x00 self.int_q = Queue() self.int_q.put(b'\x50\x03') self.operations = { PcToRdrOpcode.IccPowerOn: self.handle_PcToRdr_IccPowerOn, PcToRdrOpcode.IccPowerOff: self.handle_PcToRdr_IccPowerOff, PcToRdrOpcode.GetSlotStatus: self.handle_PcToRdr_GetSlotStatus, PcToRdrOpcode.XfrBlock: self.handle_PcToRdr_XfrBlock, PcToRdrOpcode.GetParameters: self.handle_PcToRdr_GetParameters, PcToRdrOpcode.ResetParameters: self.handle_PcToRdr_ResetParameters, PcToRdrOpcode.SetParameters: self.handle_PcToRdr_SetParameters, PcToRdrOpcode.Escape: self.handle_PcToRdr_Escape, PcToRdrOpcode.IccClock: self.handle_PcToRdr_IccClock, PcToRdrOpcode.T0APDU: self.handle_PcToRdr_T0APDU, PcToRdrOpcode.Secure: self.handle_PcToRdr_Secure, PcToRdrOpcode.Mechanical: self.handle_PcToRdr_Mechanical, PcToRdrOpcode.Abort: self.handle_PcToRdr_Abort, PcToRdrOpcode.SetDataRateAndClock_Frequency: self.handle_PcToRdr_SetDataRateAndClock_Frequency, }