Libu2f-emu  0.0.0
Universal 2nd Factor (U2F) Emulation C Library
Macros | Typedefs | Functions | Variables
cmd.c File Reference
#include <stddef.h>
#include <string.h>
#include "cmd.h"
#include "raw/raw.h"
Include dependency graph for cmd.c:

Macros

#define __unused   __attribute__((unused))
 

Typedefs

typedef struct message *(* cmd_handler_t) (struct usb_state *state, const struct message *request)
 Commands handler for U2FHID commands processing. More...
 
typedef struct cmd cmd_t
 Command of U2FHID. More...
 

Functions

static struct messagecmd_ping_handler (struct usb_state *state, const struct message *request)
 
static struct messagecmd_msg_handler (struct usb_state *state, const struct message *request)
 The Handler for CMD_MSG. More...
 
static struct messagecmd_lock_handler (struct usb_state *state, const struct message *request)
 The Handler for CMD_LOCK. More...
 
static struct messagecmd_init_handler (struct usb_state *state, const struct message *request)
 
static struct messagecmd_wink_handler (struct usb_state *state, const struct message *request)
 
static struct messagecmd_sync_handler (struct usb_state *state, const struct message *request)
 
static struct messagecmd_error_handler (struct usb_state *state, const struct message *request)
 
static cmd_handler_t cmd_get_handler (uint8_t cmd)
 Get the command handler for a specific command. More...
 
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...
 
static struct messagecmd_ping_handler (struct usb_state *state __attribute__((unused)), const struct message *request)
 The Handler for CMD_PING. More...
 
static struct messagecmd_wink_handler (struct usb_state *state __attribute__((unused)), const struct message *request)
 The Handler for CMD_WINK. More...
 
static struct messagecmd_init_handler (struct usb_state *state __attribute__((unused)), const struct message *request)
 The Handler for CMD_INIT. More...
 
static struct messagecmd_sync_handler (struct usb_state *state __attribute__((unused)), const struct message *request)
 The Handler for CMD_SYNC. More...
 
static struct messagecmd_error_handler (struct usb_state *state __attribute__((unused)), const struct message *request __attribute__((unused)))
 The Handler for CMD_ERROR. More...
 
struct messagecmd_process (struct usb_state *state, const struct message *request)
 Process a command request. More...
 

Variables

static const cmd_t cmds []
 Commands handlers for U2FHID commands processing, depending of the associated command. More...
 
static const size_t cmds_nb = sizeof(cmds) / sizeof(cmds[0])
 Number of commands. More...
 

Macro Definition Documentation

#define __unused   __attribute__((unused))

Typedef Documentation

typedef struct message*(* cmd_handler_t) (struct usb_state *state, const struct message *request)

Commands handler for U2FHID commands processing.

typedef struct cmd cmd_t

Command of U2FHID.

Function Documentation

static struct message* cmd_error_handler ( struct usb_state state,
const struct message request 
)
static
static struct message* cmd_error_handler ( struct usb_state *state   __attribute__(unused),
const struct message *request   __attribute__(unused) 
)
static

The Handler for CMD_ERROR.

Parameters
stateThe USB transport state.
requestThe request.
Returns
The response.
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
static cmd_handler_t cmd_get_handler ( uint8_t  cmd)
static

Get the command handler for a specific command.

Parameters
cmdThe command.
Returns
The command handler?
static struct message* cmd_init_handler ( struct usb_state state,
const struct message request 
)
static
static struct message* cmd_init_handler ( struct usb_state *state   __attribute__(unused),
const struct message request 
)
static

The Handler for CMD_INIT.

Parameters
stateThe USB transport state.
requestThe request
Returns
The response.
static struct message * cmd_lock_handler ( struct usb_state state,
const struct message request 
)
static

The Handler for CMD_LOCK.

Parameters
stateThe USB transport state.
requestThe request.
Returns
The response.
static struct message * cmd_msg_handler ( struct usb_state state,
const struct message request 
)
static

The Handler for CMD_MSG.

Parameters
stateThe USB transport state.
requestThe request.
Returns
The response.
static struct message* cmd_ping_handler ( struct usb_state state,
const struct message request 
)
static
static struct message* cmd_ping_handler ( struct usb_state *state   __attribute__(unused),
const struct message request 
)
static

The Handler for CMD_PING.

Parameters
stateThe USB transport state.
requestThe request.
Returns
The response.
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

static struct message* cmd_sync_handler ( struct usb_state state,
const struct message request 
)
static
static struct message* cmd_sync_handler ( struct usb_state *state   __attribute__(unused),
const struct message request 
)
static

The Handler for CMD_SYNC.

Parameters
stateThe USB transport state.
requestThe request.
Returns
The response.
static struct message* cmd_wink_handler ( struct usb_state state,
const struct message request 
)
static
static struct message* cmd_wink_handler ( struct usb_state *state   __attribute__(unused),
const struct message request 
)
static

The Handler for CMD_WINK.

Parameters
stateThe USB transport state.
requestThe request.
Returns
The response.

Variable Documentation

const cmd_t cmds[]
static
Initial value:
=
{
{ (1 << ( 7 )) | 0x1 , cmd_ping_handler },
{ (1 << ( 7 )) | 0x3 , cmd_msg_handler },
{ (1 << ( 7 )) | 0x4 , cmd_lock_handler },
{ (1 << ( 7 )) | 0x6 , cmd_init_handler },
{ (1 << ( 7 )) | 0x8 , cmd_wink_handler },
{ (1 << ( 7 )) | 0x3c , cmd_sync_handler },
{ (1 << ( 7 )) | 0x3f , cmd_error_handler }
}
static struct message * cmd_error_handler(struct usb_state *state, const struct message *request)
static struct message * cmd_ping_handler(struct usb_state *state, const struct message *request)
static struct message * cmd_sync_handler(struct usb_state *state, const struct message *request)
static struct message * cmd_lock_handler(struct usb_state *state, const struct message *request)
The Handler for CMD_LOCK.
Definition: cmd.c:184
static struct message * cmd_msg_handler(struct usb_state *state, const struct message *request)
The Handler for CMD_MSG.
Definition: cmd.c:153
static struct message * cmd_wink_handler(struct usb_state *state, const struct message *request)
static struct message * cmd_init_handler(struct usb_state *state, const struct message *request)

Commands handlers for U2FHID commands processing, depending of the associated command.

const size_t cmds_nb = sizeof(cmds) / sizeof(cmds[0])
static

Number of commands.