- bool buttonPressed = false;
-
- while(!exitLoop) {
-
- LED_B_OFF();
- //Signal tracer
- // Can be used to get a trigger for an oscilloscope..
- LED_C_OFF();
-
- if(!GetIClassCommandFromReader(receivedCmd, &len, 100)) {
- buttonPressed = true;
- break;
- }
- r2t_time = GetCountSspClk();
- //Signal tracer
- LED_C_ON();
-
- // Okay, look at the command now.
- if(receivedCmd[0] == ICLASS_CMD_ACTALL ) {
- // Reader in anticollission phase
- modulated_response = resp_sof; modulated_response_size = resp_sof_Len; //order = 1;
- trace_data = sof_data;
- trace_data_size = sizeof(sof_data);
- } else if(receivedCmd[0] == ICLASS_CMD_READ_OR_IDENTIFY && len == 1) {
- // Reader asks for anticollission CSN
- modulated_response = resp_anticoll; modulated_response_size = resp_anticoll_len; //order = 2;
- trace_data = anticoll_data;
- trace_data_size = sizeof(anticoll_data);
- //DbpString("Reader requests anticollission CSN:");
- } else if(receivedCmd[0] == ICLASS_CMD_SELECT) {
- // Reader selects anticollission CSN.
- // Tag sends the corresponding real CSN
- modulated_response = resp_csn; modulated_response_size = resp_csn_len; //order = 3;
- trace_data = csn_data;
- trace_data_size = sizeof(csn_data);
- //DbpString("Reader selects anticollission CSN:");
- } else if(receivedCmd[0] == ICLASS_CMD_READCHECK_KD) {
- // Read e-purse (88 02)
- modulated_response = resp_cc; modulated_response_size = resp_cc_len; //order = 4;
- trace_data = card_challenge_data;
- trace_data_size = sizeof(card_challenge_data);
- LED_B_ON();
- } else if(receivedCmd[0] == ICLASS_CMD_CHECK) {
- // Reader random and reader MAC!!!
- if(simulationMode == MODE_FULLSIM)
- { //This is what we must do..
- //Reader just sent us NR and MAC(k,cc * nr)
- //The diversified key should be stored on block 3
- //However, from a typical dump, the key will not be there
- uint8_t *diversified_key = { 0 };
- //Get the diversified key from emulator memory
- memcpy(diversified_key, emulator+(8*3),8);
- uint8_t ccnr[12] = { 0 };
- //Put our cc there (block 2)
- memcpy(ccnr, emulator + (8 * 2), 8);
- //Put nr there
- memcpy(ccnr+8, receivedCmd+1,4);
- //Now, calc MAC
- doMAC(ccnr,diversified_key, trace_data);
- trace_data_size = 4;
- CodeIClassTagAnswer(trace_data , trace_data_size);
- memcpy(data_response, ToSend, ToSendMax);
- modulated_response = data_response;
- modulated_response_size = ToSendMax;
- }else
- { //Not fullsim, we don't respond
- // We do not know what to answer, so lets keep quiet
- modulated_response = resp_sof; modulated_response_size = 0;
- trace_data = NULL;
- trace_data_size = 0;
- if (simulationMode == MODE_EXIT_AFTER_MAC){
- // dbprintf:ing ...
- Dbprintf("CSN: %02x %02x %02x %02x %02x %02x %02x %02x"
- ,csn[0],csn[1],csn[2],csn[3],csn[4],csn[5],csn[6],csn[7]);
- Dbprintf("RDR: (len=%02d): %02x %02x %02x %02x %02x %02x %02x %02x %02x",len,
- receivedCmd[0], receivedCmd[1], receivedCmd[2],
- receivedCmd[3], receivedCmd[4], receivedCmd[5],
- receivedCmd[6], receivedCmd[7], receivedCmd[8]);
- if (reader_mac_buf != NULL)
- {
- memcpy(reader_mac_buf,receivedCmd+1,8);
- }
- exitLoop = true;
- }
- }