From f3955e24752de2452ef1e2a9a4115d042a6d8ed3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20H=E1=BB=93ng=20Qu=C3=A2n?= Date: Fri, 1 Jun 2012 17:41:49 +0200 Subject: [PATCH] opensc-explorer: implement put_data opensc-explorer: use larger buffer for put_data --- src/tools/opensc-explorer.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/tools/opensc-explorer.c b/src/tools/opensc-explorer.c index 3a79deac..65863275 100644 --- a/src/tools/opensc-explorer.c +++ b/src/tools/opensc-explorer.c @@ -1456,9 +1456,40 @@ static int do_get_data(int argc, char **argv) return 0; } +/** + * Use PUT DATA command to write to Data Object. + **/ static int do_put_data(int argc, char **argv) { - return usage(do_put_data); + unsigned int tag; + u8 buf[8192]; + size_t buflen = sizeof(buf); + int r; + + if (argc != 2) + return usage(do_put_data); + + /* Extract DO's tag */ + tag = strtoul(argv[0], NULL, 16); + + /* Extract the new content */ + /* buflen is the max length of reception buffer */ + r = parse_string_or_hexdata(argv[1], buf, &buflen); + if (r < 0) { + printf("unable to parse data\n"); + return -1; + } + + /* Call OpenSC to do put data */ + r = sc_put_data(card, tag, buf, buflen); + if (r < 0) { + printf("Cannot put data to %04X; return %i\n", tag, r); + return -1; + } + + printf("Total of %d bytes written.\n", r); + + return 0; } static int do_apdu(int argc, char **argv)