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

Go to the source code of this file.

Data Structures

struct  packet_init
 U2FHID packet use for start messsaging during transaction. More...
 
struct  packet_cont
 U2FHID packet use for start messsaging during transaction. More...
 

Macros

#define BIT(x)   (1 << (x))
 
#define __packed   __attribute__((__packed__))
 
#define PACKET_SIZE   64
 
#define PACKET_INIT_HEADER_SIZE   7
 
#define PACKET_INIT_DATA_SIZE   (PACKET_SIZE - PACKET_INIT_HEADER_SIZE)
 
#define PACKET_CONT_HEADER_SIZE   5
 
#define PACKET_CONT_DATA_SIZE   (PACKET_SIZE - PACKET_CONT_HEADER_SIZE)
 
#define PACKET_CONT_MAX_SEQ   (BIT(7) - 1)
 
#define BROADCAST_CID   0xFFFFFFFF
 

Functions

struct packet_init __attribute__ ((__packed__))
 
static uint32_t packet_get_cid (const void *packet)
 Get the channel id of a packet. More...
 
static bool packet_is_init (const void *packet)
 Check if a packet is an init packet. More...
 
static uint16_t packet_init_get_bcnt (const struct packet_init *init_packet)
 Get the bcnt of an init packet. More...
 
static void packet_init_set_bcnt (struct packet_init *init_packet, uint16_t bcnt)
 Set the bcnt of an init packet. More...
 
static void packet_init_add_bcnt (struct packet_init *init_packet, uint16_t value)
 Add a number to the current bcnt of an init packet. More...
 
struct packet_initpacket_init_new (uint32_t cid, uint8_t cmd, uint16_t bcnt)
 Allocate and initialize a initialisation packet. More...
 
struct packet_contpacket_cont_new (uint32_t cid, uint8_t seq)
 Allocate and initialize a initialisation packet. More...
 
void * packet_copy (const void *packet)
 Copy a packet. More...
 

Variables

uint32_t cid
 
uint8_t cmd
 
uint8_t bcnth
 
uint8_t bcntl
 
uint8_t data [(64-7)]
 
uint8_t seq
 

Macro Definition Documentation

#define __packed   __attribute__((__packed__))
#define BIT (   x)    (1 << (x))
#define BROADCAST_CID   0xFFFFFFFF
#define PACKET_CONT_DATA_SIZE   (PACKET_SIZE - PACKET_CONT_HEADER_SIZE)
#define PACKET_CONT_HEADER_SIZE   5
#define PACKET_CONT_MAX_SEQ   (BIT(7) - 1)
#define PACKET_INIT_DATA_SIZE   (PACKET_SIZE - PACKET_INIT_HEADER_SIZE)
#define PACKET_INIT_HEADER_SIZE   7
#define PACKET_SIZE   64

Function Documentation

struct packet_init __attribute__ ( (__packed__)  )
struct packet_cont* packet_cont_new ( uint32_t  cid,
uint8_t  seq 
)

Allocate and initialize a initialisation packet.

Parameters
cidThe channel id
seqThe packet sequence
Returns
The continuation packet allocated and initialized
void* packet_copy ( const void *  packet)

Copy a packet.

Parameters
packetThe packet to copy
Returns
The copy
static uint32_t packet_get_cid ( const void *  packet)
inlinestatic

Get the channel id of a packet.

Parameters
packetThe packet
Returns
The channel id
static void packet_init_add_bcnt ( struct packet_init init_packet,
uint16_t  value 
)
inlinestatic

Add a number to the current bcnt of an init packet.

Parameters
init_packetThe init_packet
valueThe value to add to bcnt
static uint16_t packet_init_get_bcnt ( const struct packet_init init_packet)
inlinestatic

Get the bcnt of an init packet.

Parameters
init_packetThe init packet
Returns
The bcnt
struct packet_init* packet_init_new ( uint32_t  cid,
uint8_t  cmd,
uint16_t  bcnt 
)

Allocate and initialize a initialisation packet.

Parameters
cidThe channel id
cmdThe commannd
bcntThe payload length
Returns
The initialisation packet allocated and initialized
static void packet_init_set_bcnt ( struct packet_init init_packet,
uint16_t  bcnt 
)
inlinestatic

Set the bcnt of an init packet.

Parameters
init_packetThe init packet
bcntThe bcnt to set
static bool packet_is_init ( const void *  packet)
inlinestatic

Check if a packet is an init packet.

Parameters
packetThe packet
Returns
true : init packet, false: cont packet

Variable Documentation

uint8_t bcnth

High part of payload length

uint8_t bcntl

Low part of the payload length

uint32_t cid

Channel identifier

uint8_t cmd

Command identifier (bit 7 set)

uint8_t data

Payload data

uint8_t seq

Packet sequence 0x00..0x7f (bit 7 cleared)