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

Macros

#define FLOOR_NB(nb, m)   ((nb) & ~((m) - 1))
 
#define CEIL_NB(nb, m)   FLOOR_NB(nb + m - 1, m)
 

Functions

struct messagemessage_new (const struct packet_init *init_packet)
 Allocate and initialize a new message from an init packet. More...
 
struct messagemessage_new_blank (uint32_t cid, uint8_t cmd)
 Allocate and initialize a new blank message. More...
 
struct messagemessage_new_from_data (uint32_t cid, uint8_t cmd, const uint8_t *data, size_t size)
 Allocate and initialize a new message from data. More...
 
struct messagemessage_new_from_payload (uint32_t cid, uint8_t cmd, const struct payload *payload)
 Allocate and initialize a new message from payload. More...
 
struct messagemessage_copy (const struct message *message)
 Allocate and initialize a new message from another message. More...
 
bool message_add_data (struct message *message, const uint8_t *data, size_t size)
 Add data to a message. More...
 
bool message_add_part (struct message *message, const struct packet_cont *cont_packet)
 Add a part to a message. More...
 
bool message_next_packet (struct message *message, void **packet_ref)
 Get next packet part of a message for sending a message. More...
 
void message_free (struct message *message)
 Free a message. More...
 

Macro Definition Documentation

#define CEIL_NB (   nb,
 
)    FLOOR_NB(nb + m - 1, m)
#define FLOOR_NB (   nb,
 
)    ((nb) & ~((m) - 1))

Function Documentation

bool message_add_data ( struct message message,
const uint8_t *  data,
size_t  size 
)

Add data to a message.

Parameters
messageThe message to add data to.
dataThe data to add.
sizeThe size of the data.
Returns
Success: true. Failure: false.
bool message_add_part ( struct message message,
const struct packet_cont cont_packet 
)

Add a part to a message.

Parameters
messageThe message.
cont_packetThe continuation packet.
Returns
Success: true. Failure: false.
struct message* message_copy ( const struct message message)

Allocate and initialize a new message from another message.

Parameters
messageThe message to copy.
Returns
Success: The new allocated and initialized message. Failure: NULL.
void message_free ( struct message message)

Free a message.

Parameters
messageThe message to free.
struct message* message_new ( const struct packet_init init_packet)

Allocate and initialize a new message from an init packet.

Parameters
init_packetThe initialisation packet of the message.
Returns
Success: The new allocated and initialiazed message. Failure: NULL.
struct message* message_new_blank ( uint32_t  cid,
uint8_t  cmd 
)

Allocate and initialize a new blank message.

Parameters
cidThe channel id.
cmdThe associated command.
Returns
Success: The new allocated and initialized blank message. Failure: NULL.
struct message* message_new_from_data ( uint32_t  cid,
uint8_t  cmd,
const uint8_t *  data,
size_t  size 
)

Allocate and initialize a new message from data.

Parameters
cidThe channel id.
cmdThe associated command.
dataThe data to put in the message.
sizeThe size of the data.
Returns
Success: The new allocated and initialized message. Failure: NULL.
struct message* message_new_from_payload ( uint32_t  cid,
uint8_t  cmd,
const struct payload payload 
)

Allocate and initialize a new message from payload.

Parameters
cidThe channel id.
cmdThe associated command.
payloadThe payload ot put in the message.
Returns
Success: The new allocated and initialized message. Failure: NULL.
bool message_next_packet ( struct message message,
void **  packet_ref 
)

Get next packet part of a message for sending a message.

Parameters
messageThe message to get the next packet from.
packet_refPacket reference to put the crafted packet.
Returns
End of message: false. Not end of message: true.