- trace_data = data_generic_trace;
- trace_data_size = 4;
- CodeIClassTagAnswer(trace_data , trace_data_size);
- memcpy(data_response, ToSend, ToSendMax);
- modulated_response = data_response;
- modulated_response_size = ToSendMax;
- response_delay = 0;//We need to hurry here...
- //exitLoop = true;
- }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;
- }
- }
-
- } else if(receivedCmd[0] == ICLASS_CMD_HALT && len == 1) {
- // Reader ends the session
- modulated_response = resp_sof; modulated_response_size = 0; //order = 0;
- trace_data = NULL;
- trace_data_size = 0;
- } else if(simulationMode == MODE_FULLSIM && receivedCmd[0] == ICLASS_CMD_READ_OR_IDENTIFY && len == 4){
- //Read block
- uint16_t blk = receivedCmd[1];
- //Take the data...
- memcpy(data_generic_trace, emulator+(blk << 3),8);
- //Add crc
- AppendCrc(data_generic_trace, 8);
- trace_data = data_generic_trace;
- trace_data_size = 10;
- CodeIClassTagAnswer(trace_data , trace_data_size);
- memcpy(data_response, ToSend, ToSendMax);
- modulated_response = data_response;
- modulated_response_size = ToSendMax;
- }else if(receivedCmd[0] == ICLASS_CMD_UPDATE && simulationMode == MODE_FULLSIM)
- {//Probably the reader wants to update the nonce. Let's just ignore that for now.
- // OBS! If this is implemented, don't forget to regenerate the cipher_state
- //We're expected to respond with the data+crc, exactly what's already in the receivedcmd
- //receivedcmd is now UPDATE 1b | ADDRESS 1b| DATA 8b| Signature 4b or CRC 2b|
-
- //Take the data...
- memcpy(data_generic_trace, receivedCmd+2,8);
- //Add crc
- AppendCrc(data_generic_trace, 8);
- trace_data = data_generic_trace;
- trace_data_size = 10;
- CodeIClassTagAnswer(trace_data , trace_data_size);
- memcpy(data_response, ToSend, ToSendMax);
- modulated_response = data_response;
- modulated_response_size = ToSendMax;
- }
- else if(receivedCmd[0] == ICLASS_CMD_PAGESEL)
- {//Pagesel
- //Pagesel enables to select a page in the selected chip memory and return its configuration block
- //Chips with a single page will not answer to this command
- // It appears we're fine ignoring this.
- //Otherwise, we should answer 8bytes (block) + 2bytes CRC
- }
- else {
- //#db# Unknown command received from reader (len=5): 26 1 0 f6 a 44 44 44 44
- // Never seen this command before
- Dbprintf("Unknown command received from reader (len=%d): %x %x %x %x %x %x %x %x %x",
- len,
- receivedCmd[0], receivedCmd[1], receivedCmd[2],
- receivedCmd[3], receivedCmd[4], receivedCmd[5],
- receivedCmd[6], receivedCmd[7], receivedCmd[8]);
- // Do not respond
- modulated_response = resp_sof; modulated_response_size = 0; //order = 0;
- trace_data = NULL;
- trace_data_size = 0;
- }
-
- if(cmdsRecvd > 100) {
- //DbpString("100 commands later...");
- //break;
- }
- else {
- cmdsRecvd++;
- }
- /**
- A legit tag has about 380us delay between reader EOT and tag SOF.
- **/
- if(modulated_response_size > 0) {
- SendIClassAnswer(modulated_response, modulated_response_size, response_delay);
- t2r_time = GetCountSspClk();
- }
-
- if (tracing) {
- uint8_t parity[MAX_PARITY_SIZE];
- GetParity(receivedCmd, len, parity);
- LogTrace(receivedCmd,len, (r2t_time-time_0)<< 4, (r2t_time-time_0) << 4, parity, TRUE);