Christina Quast | 158c1dd | 2015-04-17 20:19:29 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | import constants |
| 4 | import array |
| 5 | |
| 6 | INS = 1 |
Christina Quast | fb91bb7 | 2015-04-18 13:31:42 +0200 | [diff] [blame] | 7 | LEN = 4 |
Christina Quast | 158c1dd | 2015-04-17 20:19:29 +0200 | [diff] [blame] | 8 | |
| 9 | class SmartCardEmulator: |
| 10 | def getATR(self): |
Christina Quast | 6118146 | 2015-05-03 16:34:06 +0200 | [diff] [blame^] | 11 | return array.array('B', constants.ATR_SYSMOCOM1) |
Christina Quast | 158c1dd | 2015-04-17 20:19:29 +0200 | [diff] [blame] | 12 | |
| 13 | def send_receive_cmd(self, cmd): |
Christina Quast | fb91bb7 | 2015-04-18 13:31:42 +0200 | [diff] [blame] | 14 | if cmd[INS] == 0xA4: |
Christina Quast | 158c1dd | 2015-04-17 20:19:29 +0200 | [diff] [blame] | 15 | resp = [0x9F, 0x16] |
Christina Quast | 6118146 | 2015-05-03 16:34:06 +0200 | [diff] [blame^] | 16 | elif cmd == [0xff, 0x00, 0xff]: |
| 17 | resp = [0xff] |
Christina Quast | fb91bb7 | 2015-04-18 13:31:42 +0200 | [diff] [blame] | 18 | elif len(cmd) == 5 and cmd[INS] == 0xC0: |
| 19 | data = self.ans_from_len[cmd[LEN]] |
| 20 | SW = [0x90, 0x00] |
| 21 | resp = data + SW # Respond with INS byte |
| 22 | #state = WAIT_RST |
Christina Quast | 158c1dd | 2015-04-17 20:19:29 +0200 | [diff] [blame] | 23 | else: |
Christina Quast | fb91bb7 | 2015-04-18 13:31:42 +0200 | [diff] [blame] | 24 | print("Unknown cmd") |
Christina Quast | 158c1dd | 2015-04-17 20:19:29 +0200 | [diff] [blame] | 25 | resp = [0x60, 0x00] |
| 26 | |
| 27 | print("Cmd, resp: ") |
| 28 | print("".join("%02x " % b for b in cmd)) |
| 29 | print("".join("%02x " % b for b in resp)) |
| 30 | |
| 31 | return array.array('B', resp) |
| 32 | |
| 33 | def reset_card(): |
| 34 | pass |
| 35 | |
| 36 | def close(self): |
| 37 | pass |
Christina Quast | fb91bb7 | 2015-04-18 13:31:42 +0200 | [diff] [blame] | 38 | |
| 39 | ans_from_len = {0x16: [0x00, 0x00, 0x00, 0x00, 0x7F, 0x20, 0x02, 0x00, |
| 40 | 0x00, 0x00, 0x00, 0x00, 0x09, 0x91, 0x00, 0x17, |
| 41 | 0x04, 0x00, 0x83, 0x8A, 0x83, 0x8A], |
| 42 | } |