X-Git-Url: http://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/05ddb52c43f932db852e18fe6836bee71e91f74e..48ece4a750b41536ba2c56dfd9a088b192976c82:/client/cmdhftopaz.c diff --git a/client/cmdhftopaz.c b/client/cmdhftopaz.c index d747ed05..aed5f023 100644 --- a/client/cmdhftopaz.c +++ b/client/cmdhftopaz.c @@ -17,6 +17,71 @@ #include "cmdhftopaz.h" #include "cmdhf14a.h" #include "ui.h" +#include "mifare.h" +#include "proxmark3.h" +#include "iso14443crc.h" +#include "protocols.h" + + + +static void topaz_switch_on_field(void) +{ + UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT | ISO14A_NO_SELECT | ISO14A_NO_DISCONNECT | ISO14A_TOPAZMODE, 0, 0}}; + SendCommand(&c); + + UsbCommand resp; + WaitForResponse(CMD_ACK, &resp); +} + + +static void topaz_switch_off_field(void) +{ + UsbCommand c = {CMD_READER_ISO_14443a, {0, 0, 0}}; + SendCommand(&c); + + UsbCommand resp; + WaitForResponse(CMD_ACK, &resp); +} + + +static void topaz_send_cmd_raw(uint8_t *cmd, uint8_t len, uint8_t *response) +{ + UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_RAW | ISO14A_NO_DISCONNECT | ISO14A_TOPAZMODE, len, 0}}; + memcpy(c.d.asBytes, cmd, len); + SendCommand(&c); + + UsbCommand resp; + WaitForResponse(CMD_ACK, &resp); + + memcpy(response, resp.d.asBytes, resp.arg[0]); +} + + +static void topaz_send_cmd(uint8_t *cmd, uint8_t len, uint8_t *response) +{ + if (len > 1) { + uint8_t first, second; + ComputeCrc14443(CRC_14443_B, cmd, len, &first, &second); + cmd[len] = first; + cmd[len+1] = second; + } + + topaz_send_cmd_raw(cmd, len+2, response); +} + + +static void topaz_select(uint8_t *atqa, uint8_t *uid) +{ + // ToDo: implement anticollision + uint8_t rid_cmd[] = {TOPAZ_RID, 0, 0, 0, 0, 0, 0, 0, 0}; + uint8_t wupa_cmd[] = {TOPAZ_WUPA}; + + topaz_switch_on_field(); + topaz_send_cmd(wupa_cmd, sizeof(wupa_cmd), atqa); + topaz_send_cmd(rid_cmd, sizeof(rid_cmd) - 2, uid); + topaz_switch_off_field(); +} + int CmdHFTopazReader(const char *Cmd) {