Search code examples
pythonsmartcardpcscpyscard

pcscd protocol changes but atr does not


I've been working on hid omnikey 5325 cl and trying to get the ATR value. I'm using pcscd and pyscard library on Ubuntu. System automatically gets the ATR using T0 protocol but I need RAW return. On windows using helloprox or omnikey's official software I can get what I need, but on ubuntu even though I've change the protocol but ATR does not change.

here is the code I use:

class PrintObserver(CardObserver):

"""A simple card observer that is notified
when cards are inserted/removed from the system and
prints the list of cards
"""

def update(self, observable, actions):
    (addedcards, removedcards) = actions
    for card in addedcards:
       card.connection=card.createConnection()
       card.connection.connect(protocol=CardConnection.RAW_protocol)

    binary_atr=bin(int(toHexString(card.connection.getATR()).replace(" ",""), 16))

       binary_atr=binary_atr[len(binary_atr)-24:len(binary_atr)-1]
       print int(binary_atr,2)

    for card in removedcards:
        print "-Removed: ", toHexString(card.atr)


if __name__ == '__main__':
    cardmonitor = CardMonitor()
    cardobserver = PrintObserver()
    cardmonitor.addObserver(cardobserver)

#Get Ports
config=ConfigParser.ConfigParser()
config.read('../config.ini')
Read_Port=int(config.get('CardReaderSocketPorts','Read',0))
Write_Port=int(config.get('CardReaderSocketPorts','Write',0))

# Initialise socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server_address = ('localhost', Read_Port)
return_address = ('localhost', Write_Port)
sock.bind(server_address)

while 1:
  message, address = sock.recvfrom(4096)
  if message:
    parsed_json=json.loads(message)

    #Single Line
    if parsed_json['set'].upper()=="Stop":
        sock.sendto('{"success":"True"}',return_address)        
        break


# don't forget to remove observer, or the
# monitor will poll forever...
cardmonitor.deleteObserver(cardobserver)

Solution

  • After contacting the Omnikey support, the problem is solved. As in developer guide I was looking for the config file "/etc/cmrfid.ini" to change the prox format. The file name was changed into "/etc/Omnikey.ini"