/* * Convert a string of bytes in BCD coding to a string of hexadecimal char. * */ void decodeBCDString(unsigned char *Inbuff, int len, char *Outbuff) { while (len--) { *Outbuff++ = bcddigit(*Inbuff >> 4); *Outbuff++ = bcddigit(*Inbuff & 15); Inbuff++; } *Outbuff++ = '\0'; }
int starcosReadICCSN(struct p11Token_t *token) { static struct bytestring_s EFICCSN = { (unsigned char *)"\x2F\x02", 2 }; unsigned char scr[12],*s,*d; unsigned short SW1SW2; struct starcosPrivateData *sc; int rc,*sa; FUNC_CALLED(); // Clear currently selected application indicator sc = starcosGetPrivateData(token); if (token->slot->primarySlot) { sa = &(starcosGetPrivateData(getBaseToken(token))->selectedApplication); } else { sa = &sc->selectedApplication; } *sa = 0; // Select MF rc = transmitAPDU(token->slot, 0x00, 0xA4, 0x00, 0x0C, 0, NULL, 0, NULL, 0, &SW1SW2); if (rc < 0) { FUNC_FAILS(rc, "transmitAPDU failed"); } if (SW1SW2 != 0x9000) { FUNC_FAILS(-1, "Could not select MF"); } rc = starcosReadTLVEF(token, &EFICCSN, scr, sizeof(scr)); if (rc < 0) FUNC_FAILS(rc, "Reading EF.SN.ICC"); memset(token->info.serialNumber, ' ', sizeof(token->info.serialNumber)); s = scr + 4; // Ignore 5A08 and first two bytes as serial number is only 16 digits while ICCSN is 20 digits rc -= 4; d = token->info.serialNumber; while (rc > 0) { *d++ = bcddigit(*s >> 4); *d++ = bcddigit(*s & 15); s++; rc--; } return 0; }