+ switch (cardSTATE) {
+ //case SIM_NOFIELD:
+ case SIM_HALTED:
+ case SIM_IDLE: {
+ LogTrace(receivedCmd, len, 0, 0, NULL, TRUE);
+ break;
+ }
+ case SIM_SELECTING: {
+ TransmitFor14443b_AsTag( encodedATQB, encodedATQBLen );
+ LogTrace(respATQB, sizeof(respATQB), 0, 0, NULL, FALSE);
+ cardSTATE = SIM_WORK;
+ break;
+ }
+ case SIM_HALTING: {
+ TransmitFor14443b_AsTag( encodedOK, encodedOKLen );
+ LogTrace(respOK, sizeof(respOK), 0, 0, NULL, FALSE);
+ cardSTATE = SIM_HALTED;
+ break;
+ }
+ case SIM_ACKNOWLEDGE: {
+ TransmitFor14443b_AsTag( encodedOK, encodedOKLen );
+ LogTrace(respOK, sizeof(respOK), 0, 0, NULL, FALSE);
+ cardSTATE = SIM_IDLE;
+ break;
+ }
+ case SIM_WORK: {
+ if ( len == 7 && receivedCmd[0] == ISO14443B_HALT ) {
+ cardSTATE = SIM_HALTED;
+ } else if ( len == 11 && receivedCmd[0] == ISO14443B_ATTRIB ) {
+ cardSTATE = SIM_ACKNOWLEDGE;
+ } else {
+ // Todo:
+ // - SLOT MARKER
+ // - ISO7816
+ // - emulate with a memory dump
+ Dbprintf("new cmd from reader: len=%d, cmdsRecvd=%d", len, cmdsReceived);
+
+ // CRC Check
+ uint8_t b1, b2;
+ if (len >= 3){ // if crc exists
+ ComputeCrc14443(CRC_14443_B, receivedCmd, len-2, &b1, &b2);
+ if(b1 != receivedCmd[len-2] || b2 != receivedCmd[len-1])
+ DbpString("+++CRC fail");
+ else
+ DbpString("CRC passes");
+ }
+ cardSTATE = SIM_IDLE;
+ }
+ break;
+ }
+ default: break;
+ }
+
+ ++cmdsReceived;
+ // iceman, could add a switch to turn this on/off (if off, no logging?)
+ if(cmdsReceived > 1000) {
+ DbpString("14B Simulate, 1000 commands later...");
+ break;
+ }