Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import usb
- import time
- dh = None
- for bus in usb.busses():
- for dev in bus.devices:
- if (dev.idVendor, dev.idProduct) == (0x072f, 0x2200):
- print "trying reader at usb port {0}:{1}"\
- .format(bus.dirname, dev.filename)
- if False:
- print "Device:", dev.filename
- print " Device class:",dev.deviceClass
- print " Device sub class:",dev.deviceSubClass
- print " Device protocol:",dev.deviceProtocol
- print " Max packet size:",dev.maxPacketSize
- print " idVendor: %d (0x%04x)" % (dev.idVendor, dev.idVendor)
- print " idProduct: %d (0x%04x)" % (dev.idProduct, dev.idProduct)
- print " Device Version:",dev.deviceVersion
- for config in dev.configurations:
- print " Configuration:", config.value
- print " Total length:", config.totalLength
- print " selfPowered:", config.selfPowered
- print " remoteWakeup:", config.remoteWakeup
- print " maxPower:", config.maxPower
- for intf in config.interfaces:
- print " Interface:",intf[0].interfaceNumber
- for alt in intf:
- print " Alternate Setting:",alt.alternateSetting
- print " Interface class:",alt.interfaceClass
- print " Interface sub class:",alt.interfaceSubClass
- print " Interface protocol:",alt.interfaceProtocol
- for ep in alt.endpoints:
- print " Endpoint:",hex(ep.address)
- print " Type:",ep.type
- print " Max packet size:",ep.maxPacketSize
- print " Interval:",ep.interval
- configuration = dev.configurations[0]
- interface = configuration.interfaces[0]
- for ep in interface[0].endpoints:
- if ep.type == usb.ENDPOINT_TYPE_BULK:
- if ep.address & usb.ENDPOINT_DIR_MASK == usb.ENDPOINT_IN:
- usb_inp = ep.address
- else:
- usb_out = ep.address
- dh = dev.open()
- dh.reset()
- #dh.setConfiguration(configuration)
- dh.claimInterface(interface[0])
- dh.setAltInterface(interface[0])
- dh.getDescriptor(usb.DT_CONFIG, 0, 512)
- #try: dh.interruptRead(0x81, 100, 5000)
- #except: pass
- if dh is not None:
- seq = -1
- #get_parameters = bytearray("\x6C\x00\x00\x00\x00\x00\x00\x00\x00\x00")
- #dh.bulkWrite(usb_out, get_parameters, 100)
- if 1:
- # CCID GetSlotStatus
- seq = (seq + 1) % 256
- cmd = bytearray("\x65\x00\x00\x00\x00\x00"+chr(seq)+"\x00\x00\x00")
- print ">>> " + " ".join(["{0:02x}".format(b) for b in cmd])
- dh.bulkWrite(usb_out, cmd, 1000)
- rsp = dh.bulkRead(usb_inp, 300, 1000)
- print "<<< " + " ".join(["{0:02x}".format(b) for b in rsp])
- if False:
- # CCID IccPowerOff
- seq = (seq + 1) % 256
- cmd = bytearray("\x63\x00\x00\x00\x00\x00"+chr(seq)+"\x00\x00\x00")
- print ">>> " + " ".join(["{0:02x}".format(b) for b in cmd])
- dh.bulkWrite(usb_out, cmd, 1000)
- rsp = dh.bulkRead(usb_inp, 300, 1000)
- print "<<< " + " ".join(["{0:02x}".format(b) for b in rsp])
- if False:
- # CCID IccPowerOn
- seq = (seq + 1) % 256
- cmd = bytearray("\x62\x00\x00\x00\x00\x00"+chr(seq)+"\x00\x00\x00")
- print ">>> " + " ".join(["{0:02x}".format(b) for b in cmd])
- dh.bulkWrite(usb_out, cmd, 1000)
- rsp = dh.bulkRead(usb_inp, 300, 1000)
- print "<<< " + " ".join(["{0:02x}".format(b) for b in rsp])
- if False:
- # PN532 GetFirmware
- seq = (seq + 1) % 256
- cmd = bytearray("\x6B\x07\x00\x00\x00\x00"+chr(seq)+"\x00\x00\x00")
- cmd += bytearray("\xFF\x00\x00\x00\x02" + "\xD4\x02")
- print ">>> " + " ".join(["{0:02x}".format(b) for b in cmd])
- dh.bulkWrite(usb_out, cmd, 1000)
- rsp = dh.bulkRead(usb_inp, 300, 1000)
- print "<<< " + " ".join(["{0:02x}".format(b) for b in rsp])
- if 1:
- # PN532 InListPassiveTarget (FeliCa)
- seq = (seq + 1) % 256
- cmd = "d44a010100ffff0103".decode("hex")
- cmd = "\xFF\x00\x00\x00"+chr(len(cmd))+cmd
- cmd = "\x6B"+chr(len(cmd))+"\x00\x00\x00\x00"+chr(seq)+"\x00\x00\x00"+cmd
- cmd = bytearray(cmd)
- print ">>> " + " ".join(["{0:02x}".format(b) for b in cmd])
- dh.bulkWrite(usb_out, cmd, 1000)
- rsp = bytearray(dh.bulkRead(usb_inp, 300, 1000))
- print "<<< " + " ".join(["{0:02x}".format(b) for b in rsp])
- if False:
- # PN532 RFParameters (RF off)
- seq = (seq + 1) % 256
- cmd = "FF00000004D4320100".decode("hex")
- cmd = "\x6B"+chr(len(cmd))+"\x00\x00\x00\x00"+chr(seq)+"\x00\x00\x00"+cmd
- cmd = bytearray(cmd)
- print ">>> " + " ".join(["{0:02x}".format(b) for b in cmd])
- dh.bulkWrite(usb_out, cmd, 1000)
- rsp = bytearray(dh.bulkRead(usb_inp, 300, 1000))
- print "<<< " + " ".join(["{0:02x}".format(b) for b in rsp])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement