+void annotateIso7816(char *exp, size_t size, uint8_t* cmd, uint8_t cmdsize)
+{
+ switch ( cmd[1] ){
+ case ISO7816_READ_BINARY :snprintf(exp, size, "READ BINARY");break;
+ case ISO7816_WRITE_BINARY :snprintf(exp, size, "WRITE BINARY");break;
+ case ISO7816_UPDATE_BINARY :snprintf(exp, size, "UPDATE BINARY");break;
+ case ISO7816_ERASE_BINARY :snprintf(exp, size, "ERASE BINARY");break;
+ case ISO7816_READ_RECORDS :snprintf(exp, size, "READ RECORD(S)");break;
+ case ISO7816_WRITE_RECORD :snprintf(exp, size, "WRITE RECORD");break;
+ case ISO7816_APPEND_RECORD :snprintf(exp, size, "APPEND RECORD");break;
+ case ISO7816_UPDATE_DATA :snprintf(exp, size, "UPDATE DATA");break;
+ case ISO7816_GET_DATA :snprintf(exp, size, "GET DATA");break;
+ case ISO7816_PUT_DATA :snprintf(exp, size, "PUT DATA");break;
+ case ISO7816_SELECT_FILE :snprintf(exp, size, "SELECT FILE");break;
+ case ISO7816_VERIFY :snprintf(exp, size, "VERIFY");break;
+ case ISO7816_INTERNAL_AUTHENTICATE :snprintf(exp, size, "INTERNAL AUTHENTICATE");break;
+ case ISO7816_EXTERNAL_AUTHENTICATE :snprintf(exp, size, "EXTERNAL AUTHENTICATE");break;
+ case ISO7816_GET_CHALLENGE :snprintf(exp, size, "GET CHALLENGE");break;
+ case ISO7816_MANAGE_CHANNEL :snprintf(exp, size, "MANAGE CHANNEL");break;
+ case ISO7816_GET_RESPONSE :snprintf(exp, size, "GET RESPONSE");break;
+ case ISO7816_ENVELOPE :snprintf(exp, size, "ENVELOPE");break;
+ case ISO7816_GET_PROCESSING_OPTIONS :snprintf(exp, size, "GET PROCESSING OPTIONS");break;
+ default :snprintf(exp,size,"?"); break;
+ }
+}
+
+
+void annotateIso14443_4(char *exp, size_t size, uint8_t* cmd, uint8_t cmdsize) {
+ // S-block
+ if ((cmd[0] & 0xc3) == 0xc2) {
+ switch (cmd[0] & 0x30) {
+ case 0x00 : snprintf(exp, size, "S-block DESELECT"); break;
+ case 0x30 : snprintf(exp, size, "S-block WTX"); break;
+ default : snprintf(exp, size, "S-block (RFU)"); break;
+ }
+ }
+ // R-block (ack)
+ else if ((cmd[0] & 0xe0) == 0xa0) {
+ if ((cmd[0] & 0x10) == 0)
+ snprintf(exp, size, "R-block ACK");
+ else
+ snprintf(exp, size, "R-block NACK");
+ }
+ // I-block
+ else {
+ int pos = 1;
+ switch (cmd[0] & 0x0c) {
+ case 0x08: // CID following
+ case 0x04: // NAD following
+ pos = 2;
+ break;
+ case 0x0c: // CID and NAD following
+ pos = 3;
+ break;
+ default:
+ pos = 1; // no CID, no NAD
+ break;
+ }
+ annotateIso7816(exp, size, &cmd[pos], cmdsize-pos);
+ }
+}
+
+