Libu2f-emu  0.0.0
Universal 2nd Factor (U2F) Emulation C Library
Data Structures | Macros | Functions | Variables
cmd.h File Reference
#include <stdint.h>
#include "message.h"
#include "usb.h"
Include dependency graph for cmd.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  cmd_init_resp_payload
 The command init reponse payload. More...
 

Macros

#define BIT(x)   (1 << (x))
 
#define __packed   __attribute__((__packed__))
 
#define CMD_PING   BIT(7) | 0x1
 
#define CMD_MSG   BIT(7) | 0x3
 
#define CMD_LOCK   BIT(7) | 0x4
 
#define CMD_INIT   BIT(7) | 0x6
 
#define CMD_WINK   BIT(7) | 0x8
 
#define CMD_SYNC   BIT(7) | 0x3c
 
#define CMD_ERROR   BIT(7) | 0x3f
 
#define ERR_NONE   0x00
 
#define ERR_INVALID_CMD   0x01
 
#define ERR_INVALID_PAR   0x02
 
#define ERR_INVALID_LEN   0x03
 
#define ERR_INVALID_SEQ   0x04
 
#define ERR_MSG_TIMEOUT   0x05
 
#define ERR_CHANNEL_BUSY   0x06
 
#define ERR_LOCK_REQUIRED   0x0a
 
#define ERR_SYNC_FAILED   0x0b
 
#define ERR_INVALID_CID   0x0b
 
#define ERR_OTHER   0x7f
 
#define PROTOCOL_VERSION   2
 
#define MAJ_DEV_VERSION   0
 
#define MIN_DEV_VERSION   1
 
#define BUILD_DEV_VERSION   0
 
#define CAP_FLAGS   0
 
#define CAPABILITY_WINK   0
 

Functions

struct cmd_init_resp_payload __attribute__ ((__packed__))
 
const char * cmd_strerror (int error_nb)
 Get the command error description. More...
 
struct messagecmd_generate_error (uint32_t cid, uint8_t error)
 Generate an error response. More...
 
struct messagecmd_process (struct usb_state *state, const struct message *request)
 Process a command request. More...
 

Variables

uint8_t nonce [8]
 
uint32_t cid
 
uint8_t protocol_ver
 
uint8_t maj_dev_ver
 
uint8_t min_dev_ver
 
uint8_t build_dev_ver
 
uint8_t cap_flags
 

Macro Definition Documentation

#define __packed   __attribute__((__packed__))
#define BIT (   x)    (1 << (x))
#define BUILD_DEV_VERSION   0
#define CAP_FLAGS   0
#define CAPABILITY_WINK   0
#define CMD_ERROR   BIT(7) | 0x3f
#define CMD_INIT   BIT(7) | 0x6
#define CMD_LOCK   BIT(7) | 0x4
#define CMD_MSG   BIT(7) | 0x3
#define CMD_PING   BIT(7) | 0x1
#define CMD_SYNC   BIT(7) | 0x3c
#define CMD_WINK   BIT(7) | 0x8
#define ERR_CHANNEL_BUSY   0x06

Channel is busy

#define ERR_INVALID_CID   0x0b

Message on CID 0

#define ERR_INVALID_CMD   0x01

Invalid command

#define ERR_INVALID_LEN   0x03

Invalid message length

#define ERR_INVALID_PAR   0x02

Invalid parameter

#define ERR_INVALID_SEQ   0x04

Invalide message sequencing

#define ERR_LOCK_REQUIRED   0x0a

Command requires channel lock

#define ERR_MSG_TIMEOUT   0x05

Message has timed out

#define ERR_NONE   0x00

No error

#define ERR_OTHER   0x7f

Other unspecified error

#define ERR_SYNC_FAILED   0x0b

Command sync failed

#define MAJ_DEV_VERSION   0
#define MIN_DEV_VERSION   1
#define PROTOCOL_VERSION   2

Function Documentation

struct cmd_init_resp_payload __attribute__ ( (__packed__)  )
struct message* cmd_generate_error ( uint32_t  cid,
uint8_t  error 
)

Generate an error response.

Parameters
cidChannel id.
errorThe error.
Returns
The respective error reponse generated
struct message* cmd_process ( struct usb_state state,
const struct message request 
)

Process a command request.

Parameters
stateThe USB transport state.
requestThe command request message.
Returns
The reponse generated bu the request process.

< Invalid command

const char* cmd_strerror ( int  error_nb)

Get the command error description.

Parameters
error_nbThe error number.
Returns
The respective error description

< No error

< Invalid command

< Invalid parameter

< Invalid message length

< Invalide message sequencing

< Message has timed out

< Channel is busy

< Command requires channel lock

< Command sync failed

< Other unspecified error

Variable Documentation

uint8_t build_dev_ver

Build device version

uint8_t cap_flags

Capabilities flags

uint32_t cid

Channel id

Channel identifier

uint8_t maj_dev_ver

Major device version

uint8_t min_dev_ver

Minor device version

uint8_t nonce[8]

Nonce

uint8_t protocol_ver

U2FHID protocol version