Libu2f-emu  0.0.0
Universal 2nd Factor (U2F) Emulation C Library
cmd.h
Go to the documentation of this file.
1 #ifndef CMD_H
2 #define CMD_H
3 
4 #include <stdint.h>
5 
6 #include "message.h"
7 #include "usb.h"
8 
9 
10 /* bit macro */
11 #define BIT(x) (1 << (x))
12 
13 /* Packed macro */
14 #define __packed __attribute__((__packed__))
15 
16 /* Command bits */
17 #define CMD_PING BIT(7) | 0x1
18 #define CMD_MSG BIT(7) | 0x3
19 #define CMD_LOCK BIT(7) | 0x4
20 #define CMD_INIT BIT(7) | 0x6
21 #define CMD_WINK BIT(7) | 0x8
22 #define CMD_SYNC BIT(7) | 0x3c
23 #define CMD_ERROR BIT(7) | 0x3f
24 
25 /* Errors bits */
26 #define ERR_NONE 0x00
27 #define ERR_INVALID_CMD 0x01
28 #define ERR_INVALID_PAR 0x02
29 #define ERR_INVALID_LEN 0x03
30 #define ERR_INVALID_SEQ 0x04
31 #define ERR_MSG_TIMEOUT 0x05
32 #define ERR_CHANNEL_BUSY 0x06
33 #define ERR_LOCK_REQUIRED 0x0a
34 #define ERR_SYNC_FAILED 0x0b
35 #define ERR_INVALID_CID 0x0b
36 #define ERR_OTHER 0x7f
38 /* Init CMD informations */
39 #define PROTOCOL_VERSION 2
40 #define MAJ_DEV_VERSION 0
41 #define MIN_DEV_VERSION 1
42 #define BUILD_DEV_VERSION 0
43 #define CAP_FLAGS 0
44 #define CAPABILITY_WINK 0
45 
50 {
51  uint8_t nonce[8];
52  uint32_t cid;
53  uint8_t protocol_ver;
54  uint8_t maj_dev_ver;
55  uint8_t min_dev_ver;
56  uint8_t build_dev_ver;
57  uint8_t cap_flags;
58 } __packed;
59 
66 const char *cmd_strerror(int error_nb);
67 
75 struct message *cmd_generate_error(uint32_t cid, uint8_t error);
76 
84 struct message *cmd_process(struct usb_state *state,
85  const struct message *request);
86 
87 
88 #endif
struct message * cmd_process(struct usb_state *state, const struct message *request)
Process a command request.
Definition: cmd.c:294
Message representation.
Definition: message.h:26
uint8_t cap_flags
Definition: cmd.h:57
uint8_t nonce[8]
Definition: cmd.h:51
uint8_t maj_dev_ver
Definition: cmd.h:54
uint32_t cid
Definition: cmd.h:52
uint32_t cid
Definition: cmd.h:49
uint8_t protocol_ver
Definition: cmd.h:53
struct message * cmd_generate_error(uint32_t cid, uint8_t error)
Generate an error response.
Definition: cmd.c:122
The command init reponse payload.
Definition: cmd.h:49
uint8_t build_dev_ver
Definition: cmd.h:56
#define __packed
Definition: cmd.h:14
USB transport state.
Definition: usb.h:20
uint8_t min_dev_ver
Definition: cmd.h:55
const char * cmd_strerror(int error_nb)
Get the command error description.
Definition: cmd.c:89