API Reference

Task Scheduler

void schedule_task(void (*cb)(void *arg), void *arg, )

Schedule task

Scheduling tasks is safe from an interrupt handler and from an other task.

Parameters
  • cb: task function to be scheduled

void scheduler_run_task(void)

Run first task in queue This function should be called from the main loop of a user application

static void scheduler_run_tasks(void)

Run all tasks in loop

This function should be used as a main loop in user application

Timers

TIMER_INIT(__tim)

Initialize a timer at compile time

void timer_subsystem_init(void)

Initialize timer subsystem

This function should be called from architecture dependant timer interrupt handler.

static void timer_subsystem_stop(void)

Stop architecture dependant timer interrupt

void timer_init(tim_t *timer)

Initialize timer

Parameters
  • timer: timer

void timer_add(tim_t *timer, uint32_t expiry, void (*cb)(void *), void *arg, )

Schedule timer

Parameters
  • timer: timer
  • expiry: expiry in microseconds
  • cb: callback function

void timer_reschedule(tim_t *timer, uint32_t expiry)

Reschedule timer

This function is not re-entrant, a timer cannot be added multiple times.

Parameters
  • timer: timer
  • expiry: expiry in microseconds

void timer_del(tim_t *timer)

Remove timer

This function is re-entrant, it is safe to remove a timer that is not scheduled.

Parameters
  • timer: timer

void timer_process(void)

Process scheduled timers

This function should only be used in architecture dependant timer interrupt.

static uint8_t timer_is_pending(tim_t *timer)

Check if timer is pending

Return
0 if timer if not pending, 1 otherwise
Parameters
  • timer: timer

Power Management

power_management_pwr_down_reset

Reset inactivity counter

Use this macro to prevent the uC from sleeping when there is a given activity.

power_management_set_inactivity(value)

Set a sleep delay

The uC will go to sleep after that delay. Unit: second.

void power_management_power_down_init(uint16_t inactivity_timeout, void (*on_sleep)(void *arg), void *arg, )

Initialize power management system

Parameters
  • inactivity_timeout: Set the uC to sleep after that delay (in seconds)
  • on_sleep: Callback to be called before going to sleep
  • arg: Callback’s argument pointer

void power_management_power_down_enable(void)

Enable power down mode

void power_management_power_down_disable(void)

Disable power down mode

Buffers

Defines

buf2sbuf(buf)
sbuf2buf(sbuf)
SBUF_INITS(str)
SBUF_INIT_BIN(__data)
SBUF_INIT(__data, __len)
BUF_INIT(__data, __len)
BUF_INIT_BIN(__data)
SBUF_INIT_NULL
BUF(sz)

Typedefs

typedef struct static_buf sbuf_t
typedef struct buf buf_t

Functions

static void sbuf_init(sbuf_t *sbuf, const void *data, unsigned len)
static void buf_init(buf_t *buf, void *data, unsigned len)
static int buf_get_free_space(const buf_t *buf)
static int sbuf_cmp(const sbuf_t *buf1, const sbuf_t *buf2)
static int buf_cmp(const buf_t *buf1, const buf_t *buf2)
static void buf_reset(buf_t *buf)
static void __buf_reset_keep(buf_t *buf)
static void __buf_shrink(buf_t *buf, int len)
static void buf_shrink(buf_t *buf, int len)
static void sbuf_reset(sbuf_t *sbuf)
static int buf_has_room(buf_t *buf, int len)
static void buf_adj(buf_t *buf, int len)
static void __buf_add(buf_t *buf, const void *data, int len)
static void __buf_adds(buf_t *buf, const char *data)
static int buf_adds(buf_t *buf, const char *data)
static int buf_addf(buf_t *buf, const char *fmt, ...)
static int buf_add(buf_t *buf, const void *data, int len)
static int buf_addc(buf_t *buf, uint8_t c)
static void __buf_addc(buf_t *buf, uint8_t c)
static void __buf_addsbuf(buf_t *buf, const sbuf_t *sbuf)
static int buf_get_lastc(buf_t *buf, uint8_t *c)
static void __buf_getc(buf_t *buf, uint8_t *c)
static int buf_getc(buf_t *buf, uint8_t *c)
static void __buf_skip(buf_t *buf, int len)
static int buf_skip(buf_t *buf, int len)
static void __buf_get_u16(buf_t *buf, uint16_t *val)
static int buf_get_u16(buf_t *buf, uint16_t *val)
static void __buf_get(buf_t *buf, void *data, int len)
static int buf_get(buf_t *buf, void *data, int len)
static void buf_skip_spaces(buf_t *buf)
static void *__memmem(const void *haystack, unsigned haystacklen, const void *needle, unsigned needlelen)
static void buf_print(const buf_t *buf)
static void sbuf_print(const sbuf_t *buf)
static int __buf_get_sbuf_upto_sbuf(buf_t *buf, sbuf_t *sbuf, const sbuf_t *s, uint8_t skip)
static int buf_get_sbuf_upto_sbuf_and_skip(buf_t *buf, sbuf_t *sbuf, const sbuf_t *s)
static int buf_get_sbuf_upto_sbuf(buf_t *buf, sbuf_t *sbuf, const sbuf_t *s)
static int buf_get_sbuf_upto(buf_t *buf, sbuf_t *sbuf, const char *s)
static int buf_get_long(buf_t *buf, long *i)
static int buf_get_sbuf_upto_and_skip(buf_t *buf, sbuf_t *sbuf, const char *s)
static int buf_addbuf(buf_t *dst, const buf_t *src)
static void __buf_addbuf(buf_t *dst, const buf_t *src)
static int buf_addsbuf(buf_t *dst, const sbuf_t *src)
static int buf_pad(buf_t *buf, uint8_t order)
static void __sbuf_print(const sbuf_t *buf, uint8_t hex)
static void sbuf_print_hex(const sbuf_t *buf)
static void buf_print_hex(const buf_t *buf)

Variables

struct buf __PACKED__
struct static_buf
#include <buf.h>

Static buffer

Public Members

int len
const uint8_t *data
struct buf
#include <buf.h>

Buffer

Public Members

int len
int size
int skip
uint8_t *data

Circular ring buffers

Defines

TYPE

Single producer - single consumer circular buffer ring implementation. Note: multi prod/cons rings on AVR architecture are not possible as atomic ‘compare & set’ is not provided.

RING_DECL(name, size)

Ring declaration The following ring declaration can be used for declaring a ring as a global variable in a C file. The size of a ring MUST be a power of 2.

STATIC_RING_DECL(name, size)

Static ring declaration The following static ring declaration can be used for declaring a ring as a global variable in a C file. The size of a ring MUST be a power of 2.

RING_DECL_IN_STRUCT(name, size)

Ring declaration in C structures

Use this macro to declare rings in C structures

Example of usage: struct { RING_DECL_IN_STRUCT(my_ring, 4); } a = { .my_ring = RING_INIT(a.my_ring), };

RING_INIT(name)

Initialize ring at compile time

Parameters
  • name: ring name

Typedefs

typedef struct ring ring_t

Functions

static void ring_reset(ring_t *ring)

Reset ring

Parameters
  • ring: ring

static void ring_init(ring_t *ring, int size)

Initialize ring

Parameters
  • ring: ring
  • size: ring size

static uint8_t ring_is_full(const ring_t *ring)

Check if ring is full

Return
1 if full, 0 otherwise
Parameters
  • ring: ring

static uint8_t ring_is_empty(const ring_t *ring)

Check if ring is empty

Return
1 if empty, 0 otherwise
Parameters
  • ring: ring

static int ring_len(const ring_t *ring)

Get ring length

Return
ring length
Parameters
  • ring: ring

static int ring_free_entries(const ring_t *ring)

Get ring available entriees

Return
number of free entriess in ring
Parameters
  • ring: ring

static void __ring_addc(ring_t *ring, uint8_t c)

Add byte to ring without checking

Parameters
  • ring: ring
  • c: byte to add

static int ring_addc(ring_t *ring, uint8_t c)

Add byte to ring

Return
0 on success, -1 on failure
Parameters
  • ring: ring
  • c: byte to add

static void __ring_addbuf(ring_t *ring, const buf_t *buf)

Add buffer to ring without checking

Parameters
  • ring: ring
  • buf: buffer

static int ring_addbuf(ring_t *ring, const buf_t *buf)

Add buffer to ring

Return
0 on success, -1 on failure
Parameters
  • ring: ring
  • buf: buffer

static int ring_add(ring_t *ring, const void *data, int len)

Add data to ring

Return
0 on success, -1 on failure
Parameters
  • ring: ring
  • data: pointer to data to add
  • len: data length

static void __ring_getc_at(ring_t *ring, uint8_t *c, int pos)

Get byte at position in ring

Parameters
  • ring: ring
  • c: byte
  • pos: position in ring

static void __ring_getc(ring_t *ring, uint8_t *c)

Get byte from ring without checking

Parameters
  • ring: ring
  • c: byte

static int __ring_get_dont_skip(const ring_t *ring, buf_t *buf, int len)

Get buffer from ring without skipping

Return
0 on success, -1 on failure
Parameters
  • ring: ring
  • buf: buffer
  • len: data length to get

static int ring_getc(ring_t *ring, uint8_t *c)

Get byte from ring

Return
0 on success, -1 on failure
Parameters
  • ring: ring
  • c: bytes

static int ring_get_last_byte(ring_t *ring, uint8_t *c)

Get last byte from ring

Return
0 on sucess, -1 on failure
Parameters
  • ring: ring
  • c: byte

static void __ring_skip(ring_t *ring, int len)

Skip data in ring without checking

Parameters
  • ring: ring
  • len: length to skip

static int ring_skip_upto(ring_t *ring, uint8_t c)

Skip data up to given byte

Return
0 on success, -1 on failure
Parameters
  • ring: ring
  • c: byte

static int __ring_get(ring_t *ring, buf_t *buf, int max_len)

Get buffer from ring

Parameters
  • ring: ring
  • buf: buffer
  • max_len: data length to get

static void __ring_get_buf(ring_t *ring, buf_t *buf)

Get buffer from ring without checking

Parameters
  • ring: ring
  • buf: buffer

static int ring_get(ring_t *ring, buf_t *buf)

Get buffer from ring

Return
0 on success, -1 on failure
Parameters
  • ring: ring
  • buf: buffer

static void ring_skip(ring_t *ring, int len)

Skip data in ring without checking

Parameters
  • ring: ring
  • len: data length to skip

static void ring_print_limit(const ring_t *ring, int limit, uint8_t hex)

Print data limited by size

Parameters
  • ring: ring
  • limit: size to print
  • hex: print in hexadecimal

static void ring_print(const ring_t *ring)

Print ring content

Parameters
  • ring: ring

static void ring_print_hex(const ring_t *ring)

Print ring content in hexadecimal

Parameters
  • ring: ring

static void ring_print_bits(const ring_t *ring)

Print bits from ring

Parameters
  • ring: ring

static int ring_cmp(const ring_t *ring, const uint8_t *data, int len)

Compare ring content with data in linear buffer

Return
0 if data are identical, -1 otherwise
Parameters
  • ring: ring
  • data: linear buffer
  • len: length to compare

static int ring_sbuf_cmp(const ring_t *ring, const sbuf_t *sbuf)

Compare ring content with data in static linear buffer

Return
0 if data are identical, -1 otherwise
Parameters
  • ring: ring
  • sbuf: static buffer

static int __ring_cksum(const ring_t *ring, int len)

Get ring content checksum

Return
checksum
Parameters
  • ring: ring
  • len: length

Variables

struct ring __PACKED__
struct ring

Public Members

volatile TYPE head
volatile TYPE tail
TYPE mask
uint8_t data[]

Lists

Defines

LIST_POISON1
LIST_POISON2
LIST_HEAD_INIT(name)
LIST_HEAD(name)
list_entry(ptr, type, member)
list_first_entry(ptr, type, member)
list_last_entry(ptr, type, member)
list_next_entry(pos, member)
list_prev_entry(pos, member)
list_for_each(pos, head)
list_for_each_prev(pos, head)
list_for_each_safe(pos, n, head)
list_for_each_prev_safe(pos, n, head)
list_for_each_entry(pos, head, member)
list_for_each_entry_reverse(pos, head, member)
list_for_each_entry_safe(pos, n, head, member)
SLIST_HEAD_INIT(name)
SLIST_HEAD(name)
slist_first_entry(list, type, member)
slist_for_each(pos, list)

Typedefs

typedef struct list_head list_t
typedef struct slist_node slist_node_t
typedef struct slist_head slist_t

Functions

static void INIT_LIST_HEAD(list_t *list)
static void __list_add(list_t *new, list_t *prev, list_t *next)
static void list_add(list_t *new, list_t *head)
static void list_add_tail(list_t *new, list_t *head)
static void __list_move_tail_list(list_t *dst, list_t *src)
static void list_move_tail_list(list_t *dst, list_t *src)
static void __list_del(list_t *prev, list_t *next)
static void __list_del_entry(list_t *entry)
static void list_del(list_t *entry)
static void list_del_init(list_t *entry)
static void list_move(list_t *list, list_t *head)
static void list_move_tail(list_t *list, list_t *head)
static int list_is_last(const list_t *list, const list_t *head)
static int list_empty(const list_t *head)
static int list_is_singular(const list_t *head)
static void INIT_SLIST_HEAD(slist_t *list)
static int slist_empty(const slist_t *list)
static void slist_add(slist_node_t *node, slist_t *list)
static void slist_add_tail(slist_node_t *node, slist_t *list)
static slist_node_t *slist_get_first(slist_t *list)
struct list_head

Public Members

struct list_head *next
struct list_head *prev
struct slist_node

Public Members

struct slist_node *next
struct slist_head

Public Members

slist_node_t *head
slist_node_t *tail

Byte

Typedefs

typedef struct byte byte_t

Functions

static void byte_reset(byte_t *byte)
static void byte_init(byte_t *byte, uint8_t c)
static uint8_t byte_is_empty(const byte_t *byte)
static uint8_t byte_is_set(const byte_t *byte)
static int byte_add_bit(byte_t *byte, uint8_t bit)
static uint8_t __byte_get_bit(byte_t *byte)
static int byte_get_bit(byte_t *byte)
static void print_byte(const byte_t *byte)

Variables

struct byte __PACKED__
struct byte

Public Members

uint8_t c
uint8_t pos

Misc Utils

Defines

offsetof(TYPE, MEMBER)
container_of(ptr, type, member)
countof(array)
POWEROF2(x)
__error__(msg)
STATIC_ASSERT(cond)
STATIC_IF(cond, if_statement, else_statement)
htons(x)
ntohs(x)
htonl(l)
ntohl(x)
__STR(x)
MIN(a, b)
MAX(a, b)
ROUNDUP_PWR2(x)
IS_UNSIGNED(a)
MAX_VALUE_UNSIGNED(a)
MAX_VALUE_SIGNED(a)
MAX_VALUE(a)
__PACKED__

Functions

static long map(long x, long in_min, long in_max, long out_min, long out_max)

Networking

Interface

void if_init(iface_t *iface, uint8_t type, ring_t *pkt_pool, ring_t *rx, ring_t *tx, uint8_t is_interrupt_driven)

Initialize an interface.

Parameters
  • iface: interface to initialize
  • type: type of interface (eg: IF_TYPE_ETHERNET)
  • pkt_pool: driver’s free packet pool
  • rx: inbound packet bucket
  • tx: outbound packet bucket
  • is_interrupt_driven: indicates if the driver handle packet reception/sending on hardware interrupt

void if_schedule_receive(iface_t *iface, pkt_t **pkt)

Schedule packet reception

Parameters
  • iface: network interface
  • pkt: packet to be scheduled The packet is set to null.

void if_schedule_tx_pkt_free(pkt_t **pkt)

Free transmitted packet

Parameters
  • pkt: packet to be freed asynchronously

void if_dump_stats(const iface_t *iface)

Dump interface statistics

Parameters
  • iface: interface

Packet memory pool

void pkt_mempool_init(void)

Initialize packet memory pool

void pkt_mempool_shutdown(void)

Destroy packet memory pool

pkt_t *pkt_get(ring_t *ring)

Get a packet from pool

Return
packet or NULL if no packets in pool
Parameters
  • ring: packet pool

int pkt_put(ring_t *ring, pkt_t *pkt)

Put a packet to pool

Return
0 on success, -1 if no more room in pool
Parameters
  • ring: packet pool
  • pkt: packet

pkt_t *pkt_alloc(void)

Allocate a packet

Note: Allocs and frees can only be called from a task scheduler

Return
new packet or NULL if no more packets

void pkt_free(pkt_t *pkt)

Free a packet

Note: Allocs and frees can only be called from a task scheduler

Parameters
  • pkt: packet to free

pkt_t *pkt_alloc_emergency(void)

Allocate an emergency packet

The emergency packet should only be used for sending to avoid a race on packet allocation if all packets are used.

Return
packet

int pkt_is_emergency(pkt_t *pkt)

Check if a packet is an emergency packet

Return
1 is packet is an emergency packet, 0 otherwise
Parameters
  • pkt: packet

static int pkt_len(const pkt_t *pkt)

Get packet length

Return
packet length
Parameters
  • pkt: packet

static void pkt_retain(pkt_t *pkt)

Retain packet

Increment packet reference counter

Parameters
  • pkt: packet

unsigned int pkt_pool_get_nb_free(void)

Get number of available packets

Return
number of available packets

void pkt_get_traced_pkts(void)

Get last used functions of packets in pool (for debugging)

Socket API

enum sock_status

Values:

SOCK_CLOSED
SOCK_TCP_SYN_SENT
SOCK_TCP_SYN_ACK_SENT
SOCK_TCP_FIN_SENT
SOCK_CONNECTED
struct sock_info

Public Members

struct list_head list
uint16_t port
uint8_t type
uint8_t family
uint8_t fd
listen_t *listen
transport_queue_t trq
event_t event
void socket_event_register(sock_info_t *sock_info, uint8_t events, void (*ev_cb)(event_t *ev, uint8_t events))

Register an event on a socket

Parameters
  • sock_info: network socket
  • events: events to wake up on
  • ev_cb: function to be called on wake up

void socket_event_register_fd(int fd, uint8_t events, void (*ev_cb)(event_t *ev, uint8_t events))

Register an event on a file descriptor

Parameters
  • fd: file descriptor
  • events: events to wake up on
  • ev_cb: function to be called on wake up

static void socket_event_unregister(sock_info_t *sock_info)

Unregister events on a socket

Parameters

static void socket_event_set_mask(sock_info_t *sock_info, uint8_t events)

Set event mask on a socket

Parameters
  • sock_info: network socket
  • events: event mask to wake up on

static void socket_event_clear_mask(sock_info_t *sock_info, uint8_t events)

Clear event mask on a socket

Parameters
  • sock_info: network socket
  • events: events to be cleared

static sock_info_t *socket_event_get_sock_info(event_t *ev)

Get socket from event

Return
network socket
Parameters
  • ev: event

int socket(int family, int type, int protocol)

Initialize a BSD compatible network socket

Return
a file descriptor on success, -1 on failure
Parameters
  • family: family of the socket
  • type: type of the socket
  • protocol: used protocol

int close(int fd)

Close a BSD compatible network socket

Return
0 on success, -1 on failure
Parameters
  • fd: file descriptor

int bind(int fd, const struct sockaddr *addr, socklen_t addrlen)

Bind a BSD compatible network socket

Return
0 on success, -1 on failure
Parameters
  • fd: file descriptor
  • sockaddr: address
  • addrlen: address length

int listen(int fd, int backlog)

Listen on a BSD compatible network socket

Return
0 on success, -1 on failure
Parameters
  • fd: file descriptor
  • backlog: maximum number of unhandled client connections

int accept(int fd, struct sockaddr *addr, socklen_t *addrlen)

Accept an incoming connection on a BSD compatible network socket

Return
0 on success, -1 on failure
Parameters
  • fd: file descriptor
  • addr: address
  • addrlen: address length

int connect(int fd, const struct sockaddr *addr, socklen_t addrlen)

Connect a BSD compatible network socket

Return
0 on success, -1 on failure
Parameters
  • fd: file descriptor
  • addr: address
  • addrlen: address length

ssize_t sendto(int fd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen)

Send data on a BSD compatible network socket

Return
0 on success, -1 on failure
Parameters
  • fd: file descriptor
  • buf: data buffer
  • len: data length
  • flags: BSD flags
  • addr: dest address
  • addrlen: address length

ssize_t recvfrom(int fd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen)

Receive a buffer from a BSD compatible network socket

Return
0 on success, -1 on failure
Parameters
  • fd: file descriptor
  • buf: data buffer
  • len: data length
  • flags: BSD flags
  • addr: source address
  • addrlen: address length

int socket_get_pkt(int fd, pkt_t **pkt, struct sockaddr_in *addr)

Get packet from a BSD compatible network socket

Return
0 on success, -1 on failure
Parameters
  • fd: file descriptor
  • pkt: packet
  • addr: source address

int socket_put_sbuf(int fd, const sbuf_t *sbuf, const struct sockaddr_in *addr)

Send data on a BSD compatible network socket

Return
0 on success, -1 on failure
Parameters
  • fd: file descriptor
  • sbuf: static buffer
  • addr: dest sockaddr

int __socket_get_pkt(sock_info_t *sock_info, pkt_t **pkt, uint32_t *src_addr, uint16_t *src_port)

Get packet from a network socket

Return
0 on success, -1 on failure
Parameters
  • sock_info: network socket
  • pkt: packet
  • src_addr: source address
  • src_port: source port

int __socket_put_sbuf(sock_info_t *sock_info, const sbuf_t *sbuf, uint32_t dst_addr, uint16_t dst_port)

Send data on a network socket

Return
0 on success, -1 on failure
Parameters
  • sock_info: network socket
  • sbuf: static buffer
  • dst_addr: dest address
  • dst_port: dest port

int sock_info_init(sock_info_t *sock_info, int sock_type)

Initialize a network socket

Return
0 on success, -1 on failure
Parameters
  • sock_info: network socket
  • type: type of the socket

int sock_info_bind(sock_info_t *sock_info, uint16_t port)

Bind a network socket

Return
0 on success, -1 on failure
Parameters

int sock_info_close(sock_info_t *sock_info)

Close a network socket

Return
0 on success, -1 on failure
Parameters

int sock_info_listen(sock_info_t *sock_info, int backlog)

Listen on a network socket

Return
0 on success, -1 on failure
Parameters
  • sock_info: network socket
  • backlog: maximum number of unhandled client connections

int sock_info_accept(sock_info_t *sock_info_server, sock_info_t *sock_info_client, uint32_t *src_addr, uint16_t *src_port)

Accept a connection on a network socket

Return
0 on success, -1 on failure
Parameters
  • sock_info_server: local network socket
  • sock_info_client: client network socket
  • src_addr: client address
  • src_port: client port

int sock_info_connect(sock_info_t *sock_info, uint32_t addr, uint16_t port)

Connect a network socket

Return
0 on success, -1 on failure
Parameters
  • sock_info: network socket
  • src_addr: address
  • src_port: port

sock_status_t sock_info_state(const sock_info_t *sock_info)

Get state of a network socket

Return
socket status
Parameters

Swen (level 2) API

enum generic_cmd_status

Values:

GENERIC_CMD_STATUS_OK
GENERIC_CMD_STATUS_RCV
GENERIC_CMD_STATUS_LIST
GENERIC_CMD_STATUS_ERROR_FULL
GENERIC_CMD_STATUS_ERROR_TIMEOUT
GENERIC_CMD_STATUS_ERROR_DUPLICATE
GENERIC_CMD_STATUS_ERROR_NOT_FOUND
int swen_sendto(iface_t *iface, uint8_t to, const sbuf_t *sbuf)

Send buffer to a peer

Parameters
  • iface: interface
  • to: destination address
  • sbuf: static buffer to send

void swen_generic_cmds_init(void (*cb)(uint16_t cmd, uint8_t status))

Initialize generic commands

Parameters
  • cb: callback on reception

void swen_generic_cmds_start_recording(int16_t value)

Start recording generic commands

Parameters
  • value: command number to record

void swen_ev_set(void (*ev_cb)(uint8_t from, uint8_t events, buf_t *buf))

Set event callback

Parameters
  • ev_cb: function to be called on wake up

void swen_generic_cmds_get_list(buf_t *buf)

Get generic command list

Parameters
  • buf: buffer

void swen_generic_cmds_delete_recorded_cmd(int number)

Delete recorded generic command

Parameters
  • number: command number

Swen (level 3) API

enum swen_l3_state

Values:

S_STATE_CLOSED
S_STATE_CLOSING
S_STATE_CONNECTING
S_STATE_CONN_COMPLETE
S_STATE_CONNECTED
static uint8_t swen_l3_get_state(swen_l3_assoc_t *assoc)

Get association state

Return
association state
Parameters
  • assoc: association

void swen_l3_assoc_init(swen_l3_assoc_t *assoc, const uint32_t *enc_key)

Initialize an association

Parameters
  • assoc: association
  • enc_key: encryption key

void swen_l3_assoc_shutdown(swen_l3_assoc_t *assoc)

Shutdown association

Parameters
  • assoc: association

int swen_l3_associate(swen_l3_assoc_t *assoc)

Associate with peer

Return
0 on success, -1 on failure
Parameters
  • assoc: association

void swen_l3_disassociate(swen_l3_assoc_t *assoc)

Disassociate from peer

Parameters
  • assoc: association

static uint8_t swen_l3_is_assoc_bound(swen_l3_assoc_t *assoc)

Check if an association is made

Return
0 if not bound, 1 if bound
Parameters
  • assoc: association

void swen_l3_assoc_bind(swen_l3_assoc_t *assoc, uint8_t to, iface_t *iface)

Bind

Setup destination address and interface

Parameters
  • assoc: association
  • to: remote address
  • iface: interface

int swen_l3_send(swen_l3_assoc_t *assoc, const sbuf_t *sbuf)

Send static buffer

Return
0 on success, -1 on failure
Parameters
  • assoc: association
  • sbuf: static buffer to send

static int swen_l3_send_buf(swen_l3_assoc_t *assoc, const buf_t *buf)

Send buffer

Return
0 on success, -1 on failure
Parameters
  • assoc: association
  • buf: buffer to send

pkt_t *swen_l3_get_pkt(swen_l3_assoc_t *assoc)

Get received packets

Return
received packet or NULL if no packet has been received
Parameters
  • assoc: association

static void swen_l3_event_register(swen_l3_assoc_t *assoc, uint8_t events, void (*ev_cb)(event_t *ev, uint8_t events))

Register events

Parameters
  • assoc: association
  • events: events to wake up on
  • ev_cb: function to be called on wake up

static void swen_l3_event_unregister(swen_l3_assoc_t *assoc)

Unregister events

Parameters
  • assoc: association

static void swen_l3_event_set_mask(swen_l3_assoc_t *assoc, uint8_t events)

Set event mask

Parameters
  • assoc: association
  • events: event mask to wake up on

static void swen_l3_event_clear_mask(swen_l3_assoc_t *assoc, uint8_t events)

Clear event mask

Parameters
  • assoc: association
  • events: events to be cleared

static swen_l3_assoc_t *swen_l3_event_get_assoc(event_t *ev)

Get association from event

Return
association
Parameters
  • ev: event