+ uint8_t blockNo = receivedCmd[1];
+ if (blockNo == 2) { // update e-purse
+ memcpy(card_challenge_data, receivedCmd+2, 8);
+ CodeIso15693AsTag(card_challenge_data, sizeof(card_challenge_data));
+ memcpy(resp_cc, ToSend, ToSendMax);
+ resp_cc_len = ToSendMax;
+ cipher_state_KD = opt_doTagMAC_1(card_challenge_data, diversified_key_d);
+ cipher_state_KC = opt_doTagMAC_1(card_challenge_data, diversified_key_c);
+ if (simulationMode == ICLASS_SIM_MODE_FULL) {
+ memcpy(emulator + 8*2, card_challenge_data, 8);
+ }
+ } else if (blockNo == 3) { // update Kd
+ for (int i = 0; i < 8; i++){
+ diversified_key_d[i] = diversified_key_d[i] ^ receivedCmd[2 + i];
+ }
+ cipher_state_KD = opt_doTagMAC_1(card_challenge_data, diversified_key_d);
+ if (simulationMode == ICLASS_SIM_MODE_FULL) {
+ memcpy(emulator + 8*3, diversified_key_d, 8);
+ }
+ } else if (blockNo == 4) { // update Kc
+ for(int i = 0; i < 8; i++){
+ diversified_key_c[i] = diversified_key_c[i] ^ receivedCmd[2 + i];
+ }
+ cipher_state_KC = opt_doTagMAC_1(card_challenge_data, diversified_key_c);
+ if (simulationMode == ICLASS_SIM_MODE_FULL) {
+ memcpy(emulator + 8*4, diversified_key_c, 8);
+ }
+ } else if (simulationMode == ICLASS_SIM_MODE_FULL) { // update any other data block
+ memcpy(emulator + 8*blockNo, receivedCmd+2, 8);
+ }