void ctccid_dump(void *_ptr, int len) { unsigned char *ptr = (unsigned char *)_ptr; int i; static char *MinStack = (char *)-1; static char *MaxStack; /* = 0; */ if (debugFileHandle == (FILE *)1) { /* open on demand */ ctccid_initDebug(); } if (debugFileHandle == NULL) { return; } if (MinStack > (char *)&ptr) MinStack = (char *)&ptr; if (MaxStack < (char *)&ptr) MaxStack = (char *)&ptr; ctccid_debug("Dump(%p, %d) stack used so far: %d\n", ptr, len, (int)(MaxStack - MinStack)); ctccid_debug("Buffer content:\n", ptr, len, (int)(MaxStack - MinStack)); for (i = 0; i < len; i += 16) { int i1 = i + 16; int i2 = i1; int j; if (i1 > len) { i1 = len; } if (i % 16 == 0) { fprintf(debugFileHandle, "\n %04x: ", i); } for (j = i; j < i1; j++) { fprintf(debugFileHandle, "%02x ", ptr[j]); } for ( ; j < i2; j++) { fprintf(debugFileHandle, " "); } fprintf(debugFileHandle, " "); for (j = i; j < i1; j++) { unsigned char ch = ptr[j]; if (!isprint(ch)) { ch = '.'; } fprintf(debugFileHandle, "%c", ch); } } fprintf(debugFileHandle, "\n"); }
/** * CT-BCS Get Status command * * @param ctx Reader context * @param cmd Command * @param lr Length of response * @param rsp Response buffer * @return \ref OK, \ref ERR_CT, \ref ERR_MEMORY */ int GetStatus(struct scr *ctx, unsigned char *cmd, unsigned int *lr, unsigned char *rsp) { int response; unsigned char func_unit = cmd[2]; unsigned char what = cmd[3]; #ifdef DEBUG ctccid_debug("GetStatus(FU=%02x,%02x)\n", func_unit, what); #endif if (func_unit == 0x00) { switch (what) { case 0x46: /* Card Manufacturer DO */ if (*lr < 19) { return ERR_MEMORY; } memcpy(rsp, "\x46\x0F" "DESCMSCR3X00000", 17); rsp[17] = HIGH(SMARTCARD_SUCCESS); rsp[18] = LOW(SMARTCARD_SUCCESS); *lr = 17 + 2; break; case 0x80: /* ICC Status DO */ if ((response = GetICCStatus(ctx, lr, rsp)) < 0) { return response; } break; case 0x81: /* Functional Unit DO */ if (*lr < 5) { return ERR_MEMORY; } rsp[0] = 0x81; /* TAG */ rsp[1] = 0x01; /* Length of following data */ rsp[2] = 0x01; /* Status for CT/ICC-Interface1 */ rsp[3] = HIGH(SMARTCARD_SUCCESS); rsp[4] = LOW(SMARTCARD_SUCCESS); *lr = 5; break; } } else { if ((response = GetICCStatus(ctx, lr, rsp)) < 0) { return response; } } return OK; }