FreeCalypso > hg > fc-pcsc-tools
changeset 139:c13ed9194ecd
fc-uicc-tool create-file implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 24 Feb 2021 17:08:37 +0000 |
parents | 58406ead2497 |
children | 13ab44761ea6 |
files | uicc/Makefile uicc/createfile.c uicc/dispatch.c |
diffstat | 3 files changed, 52 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/uicc/Makefile Tue Feb 23 02:34:46 2021 +0000 +++ b/uicc/Makefile Wed Feb 24 17:08:37 2021 +0000 @@ -1,8 +1,8 @@ CC= gcc CFLAGS= -O2 -I/usr/include/PCSC -I../libcommon PROG= fc-uicc-tool -OBJS= dispatch.o dumpdir.o hlread.o main.o pins.o readcmd.o readops.o \ - script.o select.o writecmd.o writeops.o +OBJS= createfile.o dispatch.o dumpdir.o hlread.o main.o pins.o readcmd.o \ + readops.o script.o select.o writecmd.o writeops.o LIBS= ../libcommon/libcommon.a INSTBIN=/opt/freecalypso/bin
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/uicc/createfile.c Wed Feb 24 17:08:37 2021 +0000 @@ -0,0 +1,48 @@ +/* + * This module implements commands that exercise ETSI TS 102 222 + * CREATE FILE and DELETE FILE operations. + */ + +#include <sys/types.h> +#include <stdio.h> +#include <string.h> +#include <strings.h> +#include "simresp.h" + +cmd_create_file(argc, argv) + char **argv; +{ + u_char apdu[260], inbuf[252], *dp; + unsigned len1, len2; + int rc; + + rc = decode_hex_data_from_string(argv[1], inbuf, 1, 252); + if (rc < 0) + return(rc); + len1 = rc; + dp = apdu + 5; + *dp++ = 0x62; + if (len1 < 0x80) { + *dp++ = len1; + len2 = len1 + 2; + } else { + *dp++ = 0x81; + *dp++ = len1; + len2 = len1 + 3; + } + bcopy(inbuf, dp, len1); + /* command header */ + apdu[0] = 0x00; + apdu[1] = 0xE0; + apdu[2] = 0; + apdu[3] = 0; + apdu[4] = len2; + rc = apdu_exchange(apdu, len2 + 5); + if (rc < 0) + return(rc); + if (sim_resp_sw != 0x9000) { + fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw); + return(-1); + } + return(0); +}
--- a/uicc/dispatch.c Tue Feb 23 02:34:46 2021 +0000 +++ b/uicc/dispatch.c Wed Feb 24 17:08:37 2021 +0000 @@ -11,6 +11,7 @@ extern int cmd_apdu(); extern int cmd_cd(); extern int cmd_change_pin(); +extern int cmd_create_file(); extern int cmd_dir(); extern int cmd_disable_pin(); extern int cmd_enable_pin(); @@ -47,6 +48,7 @@ {"atr", 0, 0, 0, retrieve_atr}, {"cd", 1, 1, 0, cmd_cd}, {"change-pin", 3, 3, 0, cmd_change_pin}, + {"create-file", 1, 1, 0, cmd_create_file}, {"dir", 0, 0, 1, cmd_dir}, {"disable-pin", 2, 2, 0, cmd_disable_pin}, {"enable-pin", 2, 2, 0, cmd_enable_pin},