def encapsulate(datas, protocolType=0x00, timeoutType=0x00, defaultSW=True): if len(datas) < 1 or len(datas) > 255: raise apduBuilderException( "invalid data size, a value between 1 and 255 was expected, got " + str(len(datas))) if timeoutType < 0 or timeoutType > 0x0D: raise apduBuilderException( "invalid argument timeoutType, a value between 0 and 13 was expected, got " + str(timeoutType)) if protocolType != 0x00 and protocolType != 0x01 and protocolType != 0x02 and protocolType != 0x04 and protocolType != 0x05 and protocolType != 0x09 and protocolType != 0x0A and protocolType != 0x0C and protocolType != 0x0F and protocolType != 0x1F and protocolType != 0x2F and protocolType != 0x3F and protocolType != 0x4F and protocolType != 0x5F and protocolType != 0x6F and protocolType != 0x7F and protocolType != 0x80 and protocolType != 0x81 and protocolType != 0x82 and protocolType != 0x83 and protocolType != 0x84: raise apduBuilderException( "invalid argument protocolType, see the documentation") if not defaultSW: timeoutType &= 0x80 return ApduDefault(cla=0xFF, ins=0xFE, p1=protocolType, p2=timeoutType, data=datas)
def verifyCommand(pin, reference=0, ReaderKey=None): if len(pin) < 1 or len(pin) > 255: raise apduBuilderException( "invalid pin size, must be a list from 1 to 255 item, got " + str(len(pin))) if reference < 0 or reference > 255: raise apduBuilderException( "invalid argument reference, a value between 0 and 255 was expected, got " + str(reference)) structure = 0 if ReaderKey != None: structure |= 0x40 if ReaderKey < 0 or ReaderKey > 15: raise apduBuilderException( "invalid argument ReaderKey, a value between 0 and 255 was expected, got " + str(ReaderKey)) structure |= (ReaderKey & 0xf) return ApduDefault(cla=0xFF, ins=0x20, p1=structure, p2=reference, data=pin)
def generalAuthenticate(blockNumber, KeyIndex, InVolatile=True, isTypeA=True): if blockNumber < 0 or blockNumber > 255: raise apduBuilderException( "invalid argument blockNumber, a value between 0 and 255 was expected, got " + str(blockNumber)) if InVolatile: if KeyIndex < 0 or KeyIndex > 3: raise apduBuilderException( "invalid argument KeyIndex, a value between 0 and 3 was expected, got " + str(KeyIndex)) #volatile key special index KeyIndex &= 0x20 else: if KeyIndex < 0 or KeyIndex > 15: raise apduBuilderException( "invalid argument KeyIndex, a value between 0 and 15 was expected, got " + str(KeyIndex)) ap = pcscAPDUBuilder.generalAuthenticate(blockNumber, KeyIndex, InVolatile, isTypeA) ap.setIns(0x88) return ap
def nfcType3Write(ServiceCodeList,BlockCodeList,DataList): #check len(BlockCodeList) vs len(DataList) if len(BlockCodeList) * 16 != len(DataList): raise apduBuilderException("invalid DataList size, must be a list equals to "+str(len(BlockCodeList) * 16)+" bytes, got "+str(len(DataList))) Data = [] for s in ServiceCodeList: if s < 0 or s > 0xFFFF: raise apduBuilderException("invalid argument in service code list, a value between 0 and 65535 was expected, got "+str(s)) lsb = s&0xFF msb = (s>>8)&0xFF Data.extend([msb,lsb]) for s in BlockCodeList: if s < 0 or s > 0xFFFF: raise apduBuilderException("invalid argument in block code list, a value between 0 and 65535 was expected, got "+str(s)) lsb = s&0xFF msb = (s>>8)&0xFF Data.extend([msb,lsb]) #append DataList Data.extend(DataList) return ApduDefault(cla=0xFF,ins=0x48,p1=len(ServiceCodes),p2=len(BlockCodes),data=Data)
def loadKey(key, InVolatile=True, isCardKey=True, ReaderKey=None): if len(key) < 1 or len(key) > 255: raise apduBuilderException( "invalid key size, must be a list from 1 to 255 item, got " + str(len(pin))) if KeyIndex < 0 or KeyIndex > 255: raise apduBuilderException( "invalid argument KeyIndex, a value between 0 and 255 was expected, got " + str(KeyIndex)) P1 = 0x00 if not InVolatile: P1 |= 0x20 if not isCardKey: P1 |= 0x80 if ReaderKey != None: if ReaderKey < 0 or ReaderKey > 15: raise apduBuilderException( "invalid argument ReaderKey, a value between 0 and 15 was expected, got " + str(ReaderKey)) P1 |= 0x40 P1 |= (ReaderKey & 0x0f) #the 0x10 bit is Reserved Future Use return ApduDefault(cla=0xFF, ins=0x82, p1=P1, p2=KeyIndex, data=keys[KeyName])
def mifareClassifWrite(blockNumber, datas, Key=None): if blockNumber < 0 or blockNumber > 255: raise apduBuilderException( "invalid argument blockNumber, a value between 0 and 255 was expected, got " + str(blockNumber)) if len(datas) < 1 or len(datas) > 255: raise apduBuilderException( "invalid datas size, must be a list from 1 to 255 item, got " + str(len(datas))) if (len(datas) % 16) != 0: raise apduBuilderException( "invalid datas size, must be a multiple of 16") if Key == None: return ApduDefault(cla=0xFF, ins=0xF4, p1=0x00, p2=blockNumber, data=datas) else: if len(Key) != 6: raise apduBuilderException( "invalid key length, must be 6, got " + str(len(Key))) toSend = [] toSend.extend(datas) toSend.extend(Key) return ApduDefault(cla=0xFF, ins=0xF4, p1=0x00, p2=blockNumber, data=toSend)
def writeSector(datas, address=0): if address < 0 or address > 0xFF: #TODO raise apduBuilderException("invalid argument address, a value between 0 and 15 was expected, got "+str(address)) if len(datas) != 4: raise apduBuilderException("invalid datas size, must be a list with 4 item, got "+str(len(datas))) return ApduMifareUltralight(ins=0xA2,param=(address&0xFF),data=datas)
def updateBinary(datas,address=0): if address < 0 or address > 255: raise apduBuilderException("invalid argument address, a value between 0 and 255 was expected, got "+str(address)) if len(datas) < 1 or len(datas) > 255: raise apduBuilderException("invalid datas size, must be a list from 1 to 255 item, got "+str(len(datas))) return ApduDefault(cla=0xFF,ins=0xD6,p1=0x00,p2=address&0xFF,data=datas)
def nfcType1ReadByte(byteNumber=0,blockNumber=0): if byteNumber < 0 or byteNumber > 7: raise apduBuilderException("invalid argument byteNumber, a value between 0 and 7 was expected, got "+str(byteNumber)) if blockNumber < 0 or blockNumber > 0xE: raise apduBuilderException("invalid argument byteNumber, a value between 0 and 14 was expected, got "+str(byteNumber)) P2 = (byteNumber&0x7) | ((blockNumber&0x0f)<<3) return ApduDefault(cla=0xFF,ins=0x54,p1=0x00,p2=P2)
def CompatibilityWrite(datas, address=0): if address < 0 or address > 0x0F: raise apduBuilderException("invalid argument address, a value between 0 and 15 was expected, got "+str(address)) if len(datas) != 4: raise apduBuilderException("invalid datas size, must be a list with 4 item, got "+str(len(datas))) datas.extend([0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]) return ApduMifareUltralight(ins=0xA0,param=(address&0xFF),data=datas)
def InListPassiveTarget(BrTy,MaxTg=1,InitiatorData=[]): if MaxTg < 1 or MaxTg > 2: raise apduBuilderException("invalid argument MaxTg, a value between 1 and 2 was expected, got "+str(MaxTg)) if BrTy < 0 or BrTy > 4: raise apduBuilderException("invalid argument BrTy, a value between 0 and 4 was expected, got "+str(BrTy)) data = [MaxTg,BrTy] data.extend(InitiatorData) return ApduPn53x(0x4A,data)
def increment(address=0,value=0x01,increment=True): if address < 0 or address > 255: raise apduBuilderException("invalid argument address, a value between 0 and 255 was expected, got "+str(address)) if value < 0 or value > 0xFFFFFFFF: raise apduBuilderException("invalid argument value, a value between 0 and 4294967295 was expected, got "+str(value)) if increment: return ApduDefault(cla=0xFF,ins=0xF0,p1=0x00,p2=address,data=[0xC0,address,value&0xFF,(value>>8)&0xFF,(value>>16)&0xFF,(value>>24)&0xFF]) else: return ApduDefault(cla=0xFF,ins=0xF0,p1=0x00,p2=address,data=[0xC1,address,value&0xFF,(value>>8)&0xFF,(value>>16)&0xFF,(value>>24)&0xFF])
def nfcType3REQC(serviceCode,RFU,TSN): if serviceCode < 0 or serviceCode > 0xFFFF: raise apduBuilderException("invalid argument serviceCode, a value between 0 and 65535 was expected, got "+str(serviceCode)) if RFU < 0 or RFU > 0xFF: raise apduBuilderException("invalid argument RFU, a value between 0 and 255 was expected, got "+str(RFU)) if TSN < 0 or TSN > 0xFF: raise apduBuilderException("invalid argument TSN, a value between 0 and 255 was expected, got "+str(TSN)) return ApduDefault(cla=0xFF,ins=0x40,p1=0x00,p2=0x00,data=[(serviceCode>>8)&0xFF,serviceCode&0xFF,RFU,TSN])
def nfcType1Write8Bytes(bytes,address=0,erase=True): if address < 0 or address > 0xFF: raise apduBuilderException("invalid argument address, a value between 0 and 255 was expected, got "+str(address)) if len(bytes) != 8: raise apduBuilderException("invalid bytes size, must be a list of 8 item, got "+str(len(bytes))) if erase: return ApduDefault(cla=0xFF,ins=0x5E,p1=0x00,p2=address,data=bytes) else: return ApduDefault(cla=0xFF,ins=0x60,p1=0x00,p2=address,data=bytes)
def mifareClassicRead(blockNumber,Key = None): if blockNumber < 0 or blockNumber > 255: raise apduBuilderException("invalid argument blockNumber, a value between 0 and 255 was expected, got "+str(blockNumber)) if Key == None: return ApduDefault(cla=0xFF,ins=0xF3,p1=0x00,p2=blockNumber) else: if len(Key) != 6: raise apduBuilderException("invalid key length, must be 6, got "+str(len(Key))) return ApduDefault(cla=0xFF,ins=0xF3,p1=0x00,p2=blockNumber,data=Key)
def mifareDecrement(address,value = 0): if address < 0 or address > 65535: raise apduBuilderException("invalid argument address, a value between 0 and 65535 was expected, got "+str(address)) if value < 0 or value > 0xffffffff: raise apduBuilderException("invalid argument value, a value between 0 and "+str(0xffffffff)+" was expected, got "+str(value)) lsb = address&0xFF msb = (address>>8)&0xFF return ApduDefault(cla=0xFF,ins=0xD8,p1=msb,p2=lsb,data=[value&0xff , (value>>8)&0xff , (value>>16)&0xff , (value>>24)&0xff])
def test(expected_answer_size = 0,delay_to_answer=0, datas = []): if expected_answer_size < 0 or expected_answer_size > 255: raise apduBuilderException("invalid argument expected_answer_size, a value between 0 and 255 was expected, got "+str(expected_answer_size)) if delay_to_answer < 0 or delay_to_answer > 63: raise apduBuilderException("invalid argument delay_to_answer, a value between 0 and 63 was expected, got "+str(delay_to_answer)) if len(datas) < 0 or len(datas) > 255: raise apduBuilderException("invalid argument datas, a value list of length 0 to 255 was expected, got "+str(len(datas))) return ApduDefault(cla=0xFF,ins=0xFD,p1=expected_answer_size,p2=delay_to_answer,data=datas)
def setLedColorFun(red,green,yellow_blue = None): if red < 0 or red > 5: raise apduBuilderException("invalid argument red, a value between 0 and 5 was expected, got "+str(red)) if green < 0 or green > 5: raise apduBuilderException("invalid argument green, a value between 0 and 5 was expected, got "+str(green)) if yellow_blue == None: d = [0x1E,red,green] else: if yellow_blue < 0 or yellow_blue > 5: raise apduBuilderException("invalid argument yellow_blue, a value between 0 and 5 was expected, got "+str(yellow_blue)) d = [0x1E,red,green,yellow_blue] return ApduDefault(cla=0xFF,ins=0xF0,p1=0x00,p2=0x00,data=d)
def encapsulate(datas,protocolType=0x00,timeoutType=0x00,defaultSW = True): if len(datas) < 1 or len(datas) > 255: raise apduBuilderException("invalid data size, a value between 1 and 255 was expected, got "+str(len(datas))) if timeoutType < 0 or timeoutType > 0x0D: raise apduBuilderException("invalid argument timeoutType, a value between 0 and 13 was expected, got "+str(timeoutType)) if protocolType != 0x00 and protocolType != 0x01 and protocolType != 0x02 and protocolType != 0x04 and protocolType != 0x05 and protocolType != 0x09 and protocolType != 0x0A and protocolType != 0x0C and protocolType != 0x0F and protocolType != 0x1F and protocolType != 0x2F and protocolType != 0x3F and protocolType != 0x4F and protocolType != 0x5F and protocolType != 0x6F and protocolType != 0x7F and protocolType != 0x80 and protocolType != 0x81 and protocolType != 0x82 and protocolType != 0x83 and protocolType != 0x84: raise apduBuilderException("invalid argument protocolType, see the documentation") if not defaultSW: timeoutType &= 0x80 return ApduDefault(cla=0xFF,ins=0xFE,p1=protocolType,p2=timeoutType,data=datas)
def updateBinary(datas, address=0): if address < 0 or address > 65535: raise apduBuilderException( "invalid argument address, a value between 0 and 65535 was expected, got " + str(address)) if len(datas) < 1 or len(datas) > 255: raise apduBuilderException( "invalid datas size, must be a list from 1 to 255 item, got " + str(len(datas))) lsb = address & 0xFF msb = (address >> 8) & 0xFF return ApduDefault(cla=0xFF, ins=0xD6, p1=msb, p2=lsb, data=datas)
def getResponse(Length): "acr122 get response from pn532" if Length < 1 or Length > 255: raise apduBuilderException("invalid argument Length, must be a value between 1 and 255, got "+str(Length)) return ApduDefault(cla=0xFF,ins=0xC0,p1=0x00,p2=0x00,expected_answer=Length)
def directTransmit(args): "acr122 transmit data to pn532" if len(args) < 1 or len(args) > 255: raise apduBuilderException("invalid args size, must be a list from 1 to 255 item, got "+str(len(datas))) return ApduDefault(cla=0xFF,ins=0x00,p1=0x00,p2=0x00,data=args)
def nfcType1WriteByte(byteValue,byteNumber=0,blockNumber=0,erase=True): if byteValue < 0 or byteValue > 255: raise apduBuilderException("invalid argument byteValue, a value between 0 and 255 was expected, got "+str(byteValue)) if byteNumber < 0 or byteNumber > 7: raise apduBuilderException("invalid argument byteNumber, a value between 0 and 7 was expected, got "+str(byteNumber)) if blockNumber < 0 or blockNumber > 0xE: raise apduBuilderException("invalid argument byteNumber, a value between 0 and 14 was expected, got "+str(byteNumber)) P2 = (byteNumber&0x7) | ((blockNumber&0x0f)<<3) if erase: return ApduDefault(cla=0xFF,ins=0x56,p1=0x00,p2=P2,data=[byteValue]) else: return ApduDefault(cla=0xFF,ins=0x58,p1=0x00,p2=P2,data=[byteValue])
def SLE_checkPinCode(pinBytes): if len(pinBytes) < 2 or len(pinBytes) > 3: raise apduBuilderException("invalid argument pinBytes, a list of bytes of lenght 2 or 3 was expected, got "+str(len(pinBytes))) apdu = ApduDefault(cla=0xFF,ins=0x20,p1=0x00,p2=0x00, data=pinBytes) apdu.removeExpectedAnswer() return apdu
def I2C_selectPageSize(page_size = I2C_PAGE_SIZE_8BYTES): if page_size < 0x03 or page_size > 0x0A: raise apduBuilderException("invalid argument page_size, a value between 0x03 and 0x07 was expected, got "+str(page_size)) apdu = ApduDefault(cla=0xFF,ins=0x01,p1=0x00,p2=0x00, data=(page_size,)) apdu.removeExpectedAnswer() return apdu
def generalAuthenticate(blockNumber,isTypeA = True,KeyIndex = 0): if blockNumber < 0 or blockNumber > 65535: raise apduBuilderException("invalid argument blockNumber, a value between 0 and 65535 was expected, got "+str(blockNumber)) lsb = address&0xFF msb = (address>>8)&0xFF if KeyIndex < 0 or KeyIndex > 255: #verification hasardeuse, le nombre de cle dans la doc n'est pas dis raise apduBuilderException("invalid argument KeyIndex, a value between 0 and 255 was expected, got "+str(KeyIndex)) if isTypeA: datas = [0x01,msb,lsb,0x60,KeyIndex] else: datas = [0x01,msb,lsb,0x61,KeyIndex] return ApduDefault(cla=0xFF,ins=0x88,p1=0x00,p2=0x00,data=datas)
def selectType(TYPE = TYPE_AUTO): if TYPE < 0 or TYPE > 0xD: raise apduBuilderException("invalid argument TYPE, a value between 0 and 13 was expected, got "+str(TYPE)) apdu = ApduDefault(cla=0xFF,ins=0xA4,p1=0x00,p2=0x00,data=[TYPE]) apdu.removeExpectedAnswer() return apdu
def sendCommandGenericSession(Cmd): if len(Cmd) < 1 or len(Cmd) > 249: raise apduBuilderException("invalid Cmd size, must be a list from 1 to 249 item, got "+str(len(Cmd))) d = [0x01, 0x00,0xF3, 0x00, 0x00, 0x64] d.extend(Cmd) return ApduDefault(cla=0xFF,ins=0xA0,p1=0x00,p2=0x05,data=[0x01 , 0x00 , 0x02])
def setBuzzerDuration(duration): if duration < 0 or duration > 60000: raise apduBuilderException("invalid argument duration, a value between 0 and 60000 was expected, got "+str(duration)) lsb = duration&0xFF msb = (duration>>8)&0xFF return ApduDefault(cla=0xFF,ins=0xF0,p1=0x00,p2=0x00,data=[0x1C,msb,lsb])
def read(adress, length=0, area = READ_AREA_0): if adress < 0 or adress > 0x1ffff: raise apduBuilderException("invalid argument adress, a value between 0 and 1023 was expected, got "+str(TYPE)) if length < 0 or length > 0xff: raise apduBuilderException("invalid argument length, a value between 0 and 255 was expected, got "+str(length)) if area < 0xb0 or area > 0xb4: raise apduBuilderException("invalid argument area, a value between 0xb0 and 0xb4 was expected, got "+str(area)) if adress >= 0x10000: area |= 0x1 msb = (adress >> 8) & 0xFF lsb = adress & 0xFF return ApduDefault(cla=0xFF,ins=area,p1=msb,p2=lsb, expected_answer=length)
def mifareClassicRead(blockNumber, Key=None): if blockNumber < 0 or blockNumber > 255: raise apduBuilderException( "invalid argument blockNumber, a value between 0 and 255 was expected, got " + str(blockNumber)) if Key == None: return ApduDefault(cla=0xFF, ins=0xF3, p1=0x00, p2=blockNumber) else: if len(Key) != 6: raise apduBuilderException( "invalid key length, must be 6, got " + str(len(Key))) return ApduDefault(cla=0xFF, ins=0xF3, p1=0x00, p2=blockNumber, data=Key)
def generalAuthenticate(blockNumber,KeyIndex,InVolatile = True ,isTypeA = True): if blockNumber < 0 or blockNumber > 255: raise apduBuilderException("invalid argument blockNumber, a value between 0 and 255 was expected, got "+str(blockNumber)) if InVolatile: if KeyIndex < 0 or KeyIndex > 3: raise apduBuilderException("invalid argument KeyIndex, a value between 0 and 3 was expected, got "+str(KeyIndex)) #volatile key special index KeyIndex &= 0x20 else: if KeyIndex < 0 or KeyIndex > 15: raise apduBuilderException("invalid argument KeyIndex, a value between 0 and 15 was expected, got "+str(KeyIndex)) ap = pcscAPDUBuilder.generalAuthenticate(blockNumber,KeyIndex,InVolatile,isTypeA) ap.setIns(0x88) return ap
def loadKey(KeyIndex,Key,InVolatile = True ,isTypeA = True): #only allow mifare key if len(Key) != 6: raise apduBuilderException("invalid key length, must be 6, got "+str(len(Key))) #proxnroll specific params if InVolatile: if KeyIndex < 0 or KeyIndex > 3: raise apduBuilderException("invalid argument KeyIndex, a value between 0 and 3 was expected, got "+str(KeyIndex)) else: if KeyIndex < 0 or KeyIndex > 15: raise apduBuilderException("invalid argument KeyIndex, a value between 0 and 15 was expected, got "+str(KeyIndex)) #B key special index if not isTypeA: KeyIndex &= 0x10 return pcscAPDUBuilder.loadKey(KeyIndex,Key,InVolatile)
def getAuthenticateData(address, KeyIndex, InVolatile=True, isTypeA=True): if address < 0 or address > 65535: raise apduBuilderException( "invalid argument address, a value between 0 and 255 was expected, got " + str(address)) if KeyIndex < 0 or KeyIndex > 255: raise apduBuilderException( "invalid argument KeyIndex, a value between 0 and 255 was expected, got " + str(KeyIndex)) lsb = address & 0xFF msb = (address >> 8) & 0xFF if isTypeA: datas = [msb, lsb, 0x60, KeyIndex] else: datas = [msb, lsb, 0x61, KeyIndex]
def iclassGetKeySlotInfo(KeySlot=0,Secured=False): if KeySlot < 0 or KeySlot > 255: raise apduBuilderException("invalid argument KeySlot, a value between 0 and 255 was expected, got "+str(address)) if Secured: return ApduDefault(cla=0x84,ins=0xC4,p1=0x00,p2=KeySlot,data=[]) else: return ApduDefault(cla=0x80,ins=0xC4,p1=0x00,p2=KeySlot,data=[])
def write(adress, datas, area = WRITE_AREA_0): if adress < 0 or adress > 0x1ffff: raise apduBuilderException("invalid argument adress, a value between 0 and 1023 was expected, got "+str(TYPE)) if len(datas) < 1 or len(datas) > 255: raise apduBuilderException("invalid datas size, must be a list from 1 to 255 item, got "+str(len(datas))) if area < 0xd0 or area > 0xd4: raise apduBuilderException("invalid argument area, a value between 0xd0 and 0xd4 was expected, got "+str(area)) if adress >= 0x10000: area |= 0x1 msb = (adress >> 8) & 0xFF lsb = adress & 0xFF apdu = ApduDefault(cla=0xFF,ins=area,p1=msb,p2=lsb, data=datas) apdu.removeExpectedAnswer() return apdu
def mifareClassifWrite(blockNumber,datas,Key = None): if blockNumber < 0 or blockNumber > 255: raise apduBuilderException("invalid argument blockNumber, a value between 0 and 255 was expected, got "+str(blockNumber)) if len(datas) < 1 or len(datas) > 255: raise apduBuilderException("invalid datas size, must be a list from 1 to 255 item, got "+str(len(datas))) if (len(datas) % 16) != 0: raise apduBuilderException("invalid datas size, must be a multiple of 16") if Key == None: return ApduDefault(cla=0xFF,ins=0xF4,p1=0x00,p2=blockNumber,data=datas) else: if len(Key) != 6: raise apduBuilderException("invalid key length, must be 6, got "+str(len(Key))) toSend = [] toSend.extend(datas) toSend.extend(Key) return ApduDefault(cla=0xFF,ins=0xF4,p1=0x00,p2=blockNumber,data=toSend)
def setLedColorFun(red, green, yellow_blue=None): if red < 0 or red > 5: raise apduBuilderException( "invalid argument red, a value between 0 and 5 was expected, got " + str(red)) if green < 0 or green > 5: raise apduBuilderException( "invalid argument green, a value between 0 and 5 was expected, got " + str(green)) if yellow_blue == None: d = [0x1E, red, green] else: if yellow_blue < 0 or yellow_blue > 5: raise apduBuilderException( "invalid argument yellow_blue, a value between 0 and 5 was expected, got " + str(yellow_blue)) d = [0x1E, red, green, yellow_blue] return ApduDefault(cla=0xFF, ins=0xF0, p1=0x00, p2=0x00, data=d)
def loadKey(KeyName,isTypeA = True): #TODO KeyName if len(Key) != 6: raise apduBuilderException("invalid key size, must be 6, got "+str(len(Key))) if isTypeA: P2 = 0x60 else: P2 = 0x61 return ApduDefault(cla=0xFF,ins=0x82,p1=0x00,p2=P2,data=Key)
def test(expected_answer_size=0, delay_to_answer=0, datas=[]): if expected_answer_size < 0 or expected_answer_size > 255: raise apduBuilderException( "invalid argument expected_answer_size, a value between 0 and 255 was expected, got " + str(expected_answer_size)) if delay_to_answer < 0 or delay_to_answer > 63: raise apduBuilderException( "invalid argument delay_to_answer, a value between 0 and 63 was expected, got " + str(delay_to_answer)) if len(datas) < 0 or len(datas) > 255: raise apduBuilderException( "invalid argument datas, a value list of length 0 to 255 was expected, got " + str(len(datas))) return ApduDefault(cla=0xFF, ins=0xFD, p1=expected_answer_size, p2=delay_to_answer, data=datas)
def loadKey(KeyIndex, Key, InVolatile=True, isTypeA=True): #only allow mifare key if len(Key) != 6: raise apduBuilderException("invalid key length, must be 6, got " + str(len(Key))) #proxnroll specific params if InVolatile: if KeyIndex < 0 or KeyIndex > 3: raise apduBuilderException( "invalid argument KeyIndex, a value between 0 and 3 was expected, got " + str(KeyIndex)) else: if KeyIndex < 0 or KeyIndex > 15: raise apduBuilderException( "invalid argument KeyIndex, a value between 0 and 15 was expected, got " + str(KeyIndex)) #B key special index if not isTypeA: KeyIndex &= 0x10 return pcscAPDUBuilder.loadKey(KeyIndex, Key, InVolatile)
def setBuzzerDuration(duration): if duration < 0 or duration > 60000: raise apduBuilderException( "invalid argument duration, a value between 0 and 60000 was expected, got " + str(duration)) lsb = duration & 0xFF msb = (duration >> 8) & 0xFF return ApduDefault(cla=0xFF, ins=0xF0, p1=0x00, p2=0x00, data=[0x1C, msb, lsb])
def readBinary(address=0, expected=0): if address < 0 or address > 65535: raise apduBuilderException( "invalid argument address, a value between 0 and 65535 was expected, got " + str(address)) lsb = address & 0xFF msb = (address >> 8) & 0xFF return ApduDefault(cla=0xFF, ins=0xB0, p1=msb, p2=lsb, expected_answer=expected)