1 /*
2  * Copyright (c) 2015-2018 Nitrokey UG
3  *
4  * This file is part of libnitrokey.
5  *
6  * libnitrokey is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * any later version.
10  *
11  * libnitrokey is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with libnitrokey. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * SPDX-License-Identifier: LGPL-3.0
20  */
21 
22 #ifndef COMMAND_ID_H
23 #define COMMAND_ID_H
24 #include <stdint.h>
25 
26 namespace nitrokey {
27 namespace proto {
28     namespace stick20 {
29       enum class device_status : uint8_t {
30         idle = 0,
31         ok,
32         busy,
33         wrong_password,
34         busy_progressbar,
35         password_matrix_ready,
36         no_user_password_unlock, // FIXME: translate on receive to command status error (fix in firmware?)
37         smartcard_error,
38         security_bit_active
39       };
40       const int CMD_START_VALUE = 0x20;
41       const int CMD_END_VALUE = 0x60;
42     }
43     namespace stick10 {
44       enum class command_status : uint8_t {
45           ok = 0,
46           wrong_CRC,
47           wrong_slot,
48           slot_not_programmed,
49           wrong_password  = 4,
50           not_authorized,
51           timestamp_warning,
52           no_name_error,
53           not_supported,
54           unknown_command,
55           AES_dec_failed
56       };
57       enum class device_status : uint8_t {
58         ok = 0,
59         busy = 1,
60         error,
61         received_report,
62       };
63     }
64 
65 
66 enum class CommandID : uint8_t {
67   GET_STATUS = 0x00,
68   WRITE_TO_SLOT = 0x01,
69   READ_SLOT_NAME = 0x02,
70   READ_SLOT = 0x03,
71   GET_CODE = 0x04,
72   WRITE_CONFIG = 0x05,
73   ERASE_SLOT = 0x06,
74   FIRST_AUTHENTICATE = 0x07,
75   AUTHORIZE = 0x08,
76   GET_PASSWORD_RETRY_COUNT = 0x09,
77   CLEAR_WARNING = 0x0A,
78   SET_TIME = 0x0B,
79   TEST_COUNTER = 0x0C,
80   TEST_TIME = 0x0D,
81   USER_AUTHENTICATE = 0x0E,
82   GET_USER_PASSWORD_RETRY_COUNT = 0x0F,
83   USER_AUTHORIZE = 0x10,
84   UNLOCK_USER_PASSWORD = 0x11,
85   LOCK_DEVICE = 0x12,
86   FACTORY_RESET = 0x13,
87   CHANGE_USER_PIN = 0x14,
88   CHANGE_ADMIN_PIN = 0x15,
89   WRITE_TO_SLOT_2 = 0x16,
90   SEND_OTP_DATA = 0x17,
91   FIRMWARE_UPDATE = 0x19,
92   FIRMWARE_PASSWORD_CHANGE = 0x1A,
93 
94   ENABLE_CRYPTED_PARI = 0x20,
95   DISABLE_CRYPTED_PARI = 0x20 + 1,
96   ENABLE_HIDDEN_CRYPTED_PARI = 0x20 + 2,
97   DISABLE_HIDDEN_CRYPTED_PARI = 0x20 + 3,
98   ENABLE_FIRMWARE_UPDATE = 0x20 + 4, //enables update mode
99   EXPORT_FIRMWARE_TO_FILE = 0x20 + 5,
100   GENERATE_NEW_KEYS = 0x20 + 6,
101   FILL_SD_CARD_WITH_RANDOM_CHARS = 0x20 + 7,
102 
103   WRITE_STATUS_DATA = 0x20 + 8, //@unused
104   ENABLE_READONLY_UNCRYPTED_LUN = 0x20 + 9,
105   ENABLE_READWRITE_UNCRYPTED_LUN = 0x20 + 10,
106 
107   SEND_PASSWORD_MATRIX = 0x20 + 11, //@unused
108   SEND_PASSWORD_MATRIX_PINDATA = 0x20 + 12, //@unused
109   SEND_PASSWORD_MATRIX_SETUP = 0x20 + 13, //@unused
110 
111   GET_DEVICE_STATUS = 0x20 + 14,
112   SEND_DEVICE_STATUS = 0x20 + 15,
113 
114   SEND_HIDDEN_VOLUME_PASSWORD = 0x20 + 16, //@unused
115   SEND_HIDDEN_VOLUME_SETUP = 0x20 + 17,
116   SEND_PASSWORD = 0x20 + 18,
117   SEND_NEW_PASSWORD = 0x20 + 19,
118   CLEAR_NEW_SD_CARD_FOUND = 0x20 + 20,
119 
120   SEND_STARTUP = 0x20 + 21,
121   SEND_CLEAR_STICK_KEYS_NOT_INITIATED = 0x20 + 22,
122   SEND_LOCK_STICK_HARDWARE = 0x20 + 23, //locks firmware upgrade
123 
124   PRODUCTION_TEST = 0x20 + 24,
125   SEND_DEBUG_DATA = 0x20 + 25, //@unused
126 
127   CHANGE_UPDATE_PIN = 0x20 + 26,
128 
129   //added in v0.48.5
130   ENABLE_ADMIN_READONLY_UNCRYPTED_LUN = 0x20 + 28,
131   ENABLE_ADMIN_READWRITE_UNCRYPTED_LUN = 0x20 + 29,
132   ENABLE_ADMIN_READONLY_ENCRYPTED_LUN = 0x20 + 30,
133   ENABLE_ADMIN_READWRITE_ENCRYPTED_LUN = 0x20 + 31,
134   CHECK_SMARTCARD_USAGE = 0x20 + 32,
135   //v0.52+
136   WINK = 0x20 + 33,
137 
138   GET_PW_SAFE_SLOT_STATUS = 0x60,
139   GET_PW_SAFE_SLOT_NAME = 0x61,
140   GET_PW_SAFE_SLOT_PASSWORD = 0x62,
141   GET_PW_SAFE_SLOT_LOGINNAME = 0x63,
142   SET_PW_SAFE_SLOT_DATA_1 = 0x64,
143   SET_PW_SAFE_SLOT_DATA_2 = 0x65,
144   PW_SAFE_ERASE_SLOT = 0x66,
145   PW_SAFE_ENABLE = 0x67,
146   PW_SAFE_INIT_KEY = 0x68, //@unused
147   PW_SAFE_SEND_DATA = 0x69, //@unused
148   SD_CARD_HIGH_WATERMARK = 0x70,
149   DETECT_SC_AES = 0x6a,
150   NEW_AES_KEY = 0x6b
151 };
152 
153 const char *commandid_to_string(CommandID id);
154 }
155 }
156 #endif
157