diff --git a/pico-ccid b/pico-ccid index de04dd6..efb6c8d 160000 --- a/pico-ccid +++ b/pico-ccid @@ -1 +1 @@ -Subproject commit de04dd612102bd9f82a51006d631ff0b9198d82a +Subproject commit efb6c8d8cdd9f5a27281465c1dc72d5d227b473c diff --git a/src/openpgp/openpgp.c b/src/openpgp/openpgp.c index c4a257a..49f0980 100644 --- a/src/openpgp/openpgp.c +++ b/src/openpgp/openpgp.c @@ -320,12 +320,29 @@ int openpgp_unload() { return CCID_OK; } +extern char __StackLimit; +int heapLeft() { + char *p = malloc(256); // try to avoid undue fragmentation + int left = &__StackLimit - p; + free(p); + return left; +} + app_t *openpgp_select_aid(app_t *a) { if (!memcmp(apdu.cmd_apdu_data, openpgp_aid+1, openpgp_aid[0])) { a->aid = openpgp_aid; a->process_apdu = openpgp_process_apdu; a->unload = openpgp_unload; init_openpgp(); + process_fci(file_openpgp); + memcpy(res_APDU+res_APDU_size,"\x64\x06\x53\x04", 4); + res_APDU_size += 4; + int heap_left = heapLeft(); + res_APDU[res_APDU_size++] = ((heap_left >> 24) & 0xff); + res_APDU[res_APDU_size++] = ((heap_left >> 16) & 0xff); + res_APDU[res_APDU_size++] = ((heap_left >> 8) & 0xff); + res_APDU[res_APDU_size++] = ((heap_left >> 0) & 0xff); + res_APDU[1] += 8; return a; } return NULL;