FreeCalypso > hg > freecalypso-hwlab
comparison uicc/writeops.c @ 145:14dee03e9675
fc-uicc-tool: low-level write commands ported over
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Sat, 06 Feb 2021 02:17:51 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 144:429a8f80426e | 145:14dee03e9675 |
|---|---|
| 1 #include <sys/types.h> | |
| 2 #include <string.h> | |
| 3 #include <strings.h> | |
| 4 #include <stdio.h> | |
| 5 #include <stdlib.h> | |
| 6 #include <pcsclite.h> | |
| 7 #include <winscard.h> | |
| 8 #include "globals.h" | |
| 9 | |
| 10 update_bin_op(offset, data, len) | |
| 11 unsigned offset, len; | |
| 12 u_char *data; | |
| 13 { | |
| 14 u_char cmd[260]; | |
| 15 int rc; | |
| 16 | |
| 17 /* UPDATE BINARY command APDU */ | |
| 18 cmd[0] = 0x00; | |
| 19 cmd[1] = 0xD6; | |
| 20 cmd[2] = offset >> 8; | |
| 21 cmd[3] = offset; | |
| 22 cmd[4] = len; | |
| 23 bcopy(data, cmd + 5, len); | |
| 24 rc = apdu_exchange(cmd, len + 5); | |
| 25 if (rc < 0) | |
| 26 return(rc); | |
| 27 if (sim_resp_sw != 0x9000) { | |
| 28 fprintf(stderr, "bad SW response to UPDATE BINARY: %04X\n", | |
| 29 sim_resp_sw); | |
| 30 return(-1); | |
| 31 } | |
| 32 return(0); | |
| 33 } | |
| 34 | |
| 35 update_rec_op(recno, mode, data, len) | |
| 36 unsigned recno, mode, len; | |
| 37 u_char *data; | |
| 38 { | |
| 39 u_char cmd[260]; | |
| 40 int rc; | |
| 41 | |
| 42 /* UPDATE RECORD command APDU */ | |
| 43 cmd[0] = 0x00; | |
| 44 cmd[1] = 0xDC; | |
| 45 cmd[2] = recno; | |
| 46 cmd[3] = mode; | |
| 47 cmd[4] = len; | |
| 48 bcopy(data, cmd + 5, len); | |
| 49 rc = apdu_exchange(cmd, len + 5); | |
| 50 if (rc < 0) | |
| 51 return(rc); | |
| 52 if (sim_resp_sw != 0x9000) { | |
| 53 fprintf(stderr, "bad SW response to UPDATE RECORD: %04X\n", | |
| 54 sim_resp_sw); | |
| 55 return(-1); | |
| 56 } | |
| 57 return(0); | |
| 58 } |
