]>
Commit | Line | Data |
---|---|---|
05ddb52c | 1 | //----------------------------------------------------------------------------- |
2 | // Copyright (C) 2015 Piwi | |
3 | // | |
4 | // This code is licensed to you under the terms of the GNU GPL, version 2 or, | |
5 | // at your option, any later version. See the LICENSE.txt file for the text of | |
6 | // the license. | |
7 | //----------------------------------------------------------------------------- | |
8 | // High frequency Topaz (NFC Type 1) commands | |
9 | //----------------------------------------------------------------------------- | |
10 | ||
11 | #include <stdio.h> | |
12 | #include <stdlib.h> | |
13 | #include <string.h> | |
14 | #include <unistd.h> | |
15 | #include "cmdmain.h" | |
16 | #include "cmdparser.h" | |
17 | #include "cmdhftopaz.h" | |
18 | #include "cmdhf14a.h" | |
19 | #include "ui.h" | |
48ece4a7 | 20 | #include "mifare.h" |
21 | #include "proxmark3.h" | |
22 | #include "iso14443crc.h" | |
23 | #include "protocols.h" | |
24 | ||
25 | ||
26 | ||
27 | static void topaz_switch_on_field(void) | |
28 | { | |
29 | UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT | ISO14A_NO_SELECT | ISO14A_NO_DISCONNECT | ISO14A_TOPAZMODE, 0, 0}}; | |
30 | SendCommand(&c); | |
31 | ||
32 | UsbCommand resp; | |
33 | WaitForResponse(CMD_ACK, &resp); | |
34 | } | |
35 | ||
36 | ||
37 | static void topaz_switch_off_field(void) | |
38 | { | |
39 | UsbCommand c = {CMD_READER_ISO_14443a, {0, 0, 0}}; | |
40 | SendCommand(&c); | |
41 | ||
42 | UsbCommand resp; | |
43 | WaitForResponse(CMD_ACK, &resp); | |
44 | } | |
45 | ||
46 | ||
47 | static void topaz_send_cmd_raw(uint8_t *cmd, uint8_t len, uint8_t *response) | |
48 | { | |
49 | UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_RAW | ISO14A_NO_DISCONNECT | ISO14A_TOPAZMODE, len, 0}}; | |
50 | memcpy(c.d.asBytes, cmd, len); | |
51 | SendCommand(&c); | |
52 | ||
53 | UsbCommand resp; | |
54 | WaitForResponse(CMD_ACK, &resp); | |
55 | ||
56 | memcpy(response, resp.d.asBytes, resp.arg[0]); | |
57 | } | |
58 | ||
59 | ||
60 | static void topaz_send_cmd(uint8_t *cmd, uint8_t len, uint8_t *response) | |
61 | { | |
62 | if (len > 1) { | |
63 | uint8_t first, second; | |
64 | ComputeCrc14443(CRC_14443_B, cmd, len, &first, &second); | |
65 | cmd[len] = first; | |
66 | cmd[len+1] = second; | |
67 | } | |
68 | ||
69 | topaz_send_cmd_raw(cmd, len+2, response); | |
70 | } | |
71 | ||
72 | ||
73 | static void topaz_select(uint8_t *atqa, uint8_t *uid) | |
74 | { | |
75 | // ToDo: implement anticollision | |
76 | uint8_t rid_cmd[] = {TOPAZ_RID, 0, 0, 0, 0, 0, 0, 0, 0}; | |
77 | uint8_t wupa_cmd[] = {TOPAZ_WUPA}; | |
78 | ||
79 | topaz_switch_on_field(); | |
80 | topaz_send_cmd(wupa_cmd, sizeof(wupa_cmd), atqa); | |
81 | topaz_send_cmd(rid_cmd, sizeof(rid_cmd) - 2, uid); | |
82 | topaz_switch_off_field(); | |
83 | } | |
84 | ||
05ddb52c | 85 | |
86 | int CmdHFTopazReader(const char *Cmd) | |
87 | { | |
88 | PrintAndLog("not yet implemented"); | |
89 | return 0; | |
90 | } | |
91 | ||
92 | ||
93 | int CmdHFTopazSim(const char *Cmd) | |
94 | { | |
95 | PrintAndLog("not yet implemented"); | |
96 | return 0; | |
97 | } | |
98 | ||
99 | ||
100 | int CmdHFTopazCmdRaw(const char *Cmd) | |
101 | { | |
102 | PrintAndLog("not yet implemented"); | |
103 | return 0; | |
104 | } | |
105 | ||
106 | ||
107 | static int CmdHelp(const char *Cmd); | |
108 | ||
109 | ||
110 | static command_t CommandTable[] = | |
111 | { | |
112 | {"help", CmdHelp, 1, "This help"}, | |
113 | {"reader", CmdHFTopazReader, 0, "Act like a Topaz reader"}, | |
114 | {"sim", CmdHFTopazSim, 0, "<UID> -- Simulate Topaz tag"}, | |
115 | {"snoop", CmdHF14ASnoop, 0, "Eavesdrop a Topaz reader-tag communication"}, | |
116 | {"raw", CmdHFTopazCmdRaw, 0, "Send raw hex data to tag"}, | |
117 | {NULL, NULL, 0, NULL} | |
118 | }; | |
119 | ||
120 | ||
121 | int CmdHFTopaz(const char *Cmd) { | |
122 | // flush | |
123 | WaitForResponseTimeout(CMD_ACK,NULL,100); | |
124 | ||
125 | // parse | |
126 | CmdsParse(CommandTable, Cmd); | |
127 | return 0; | |
128 | } | |
129 | ||
130 | static int CmdHelp(const char *Cmd) | |
131 | { | |
132 | CmdsHelp(CommandTable); | |
133 | return 0; | |
134 | } | |
135 | ||
136 |