fix one too small
[RRG-proxmark3.git] / client / src / cmdhfseos.c
blob4ab7c1b15d27dca2e55e073c4b3945b3c91eb2e4
1 //-----------------------------------------------------------------------------
2 // Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // See LICENSE.txt for the text of the license.
15 //-----------------------------------------------------------------------------
16 // SEOS commands
17 //-----------------------------------------------------------------------------
18 #include "cmdhfseos.h"
19 #include <stdio.h>
20 #include <string.h>
21 #include <ctype.h> // tolower
22 #include "cliparser.h"
23 #include "cmdparser.h" // command_t
24 #include "comms.h" // clearCommandBuffer
25 #include "cmdtrace.h"
26 #include "crc16.h"
27 #include "ui.h"
28 #include "cmdhf14a.h" // manufacture
29 #include "protocols.h" // definitions of ISO14A/7816 protocol
30 #include "iso7816/apduinfo.h" // GetAPDUCodeDescription
31 #include "crypto/asn1utils.h" // ASN1 decode / print
32 #include "commonutil.h" // get_sw
33 #include "protocols.h" // ISO7816 APDU return codes
35 static int CmdHelp(const char *Cmd);
37 static int seos_select(void) {
38 bool activate_field = true;
39 bool keep_field_on = true;
40 uint8_t response[PM3_CMD_DATA_SIZE];
41 int resplen = 0;
43 // --------------- Select SEOS applet ----------------
44 uint8_t aSELECT_AID[80];
45 int aSELECT_AID_n = 0;
46 param_gethex_to_eol("00a404000aa000000440000101000100", 0, aSELECT_AID, sizeof(aSELECT_AID), &aSELECT_AID_n);
47 int res = ExchangeAPDU14a(aSELECT_AID, aSELECT_AID_n, activate_field, keep_field_on, response, sizeof(response), &resplen);
48 if (res != PM3_SUCCESS) {
49 DropField();
50 return res;
53 if (resplen < 2) {
54 DropField();
55 return PM3_ESOFT;
58 uint16_t sw = get_sw(response, resplen);
59 if (sw != ISO7816_OK) {
60 PrintAndLogEx(ERR, "Selecting SEOS applet aid failed (%04x - %s).", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
61 DropField();
62 return PM3_ESOFT;
65 activate_field = false;
66 keep_field_on = false;
67 // --------------- CC file reading ----------------
69 uint8_t aSELECT_FILE_ADF[30];
70 int aSELECT_FILE_ADF_n = 0;
71 param_gethex_to_eol("80a504001306112b0601040181e43801010201180101020200", 0, aSELECT_FILE_ADF, sizeof(aSELECT_FILE_ADF), &aSELECT_FILE_ADF_n);
72 res = ExchangeAPDU14a(aSELECT_FILE_ADF, aSELECT_FILE_ADF_n, activate_field, keep_field_on, response, sizeof(response), &resplen);
73 if (res != PM3_SUCCESS) {
74 DropField();
75 return res;
78 sw = get_sw(response, resplen);
79 if (sw != ISO7816_OK) {
80 PrintAndLogEx(ERR, "Selecting ADF file failed (%04x - %s).", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
81 DropField();
82 return PM3_ESOFT;
85 // remove the 2byte SW
86 asn1_print(response, resplen - 2, " ");
87 return PM3_SUCCESS;
90 int infoSeos(bool verbose) {
91 int res = seos_select();
92 if (res == PM3_SUCCESS) {
93 PrintAndLogEx(NORMAL, "");
94 PrintAndLogEx(INFO, "--- " _CYAN_("Tag Information") " ---------------------------");
96 return PM3_SUCCESS;
99 static int CmdHfSeosInfo(const char *Cmd) {
100 CLIParserContext *ctx;
101 CLIParserInit(&ctx, "hf seos info",
102 "Get info from SEOS tags",
103 "hf seos info");
105 void *argtable[] = {
106 arg_param_begin,
107 arg_param_end
109 CLIExecWithReturn(ctx, Cmd, argtable, true);
110 CLIParserFree(ctx);
111 return infoSeos(true);
114 static int CmdHfSeosList(const char *Cmd) {
115 return CmdTraceListAlias(Cmd, "hf seos", "seos -c");
118 static command_t CommandTable[] = {
119 {"help", CmdHelp, AlwaysAvailable, "This help"},
120 {"info", CmdHfSeosInfo, IfPm3NfcBarcode, "Tag information"},
121 {"list", CmdHfSeosList, AlwaysAvailable, "List SEOS history"},
122 {NULL, NULL, NULL, NULL}
125 static int CmdHelp(const char *Cmd) {
126 (void)Cmd; // Cmd is not used so far
127 CmdsHelp(CommandTable);
128 return PM3_SUCCESS;
131 int CmdHFSeos(const char *Cmd) {
132 clearCommandBuffer();
133 return CmdsParse(CommandTable, Cmd);