Connection State Management for netif

Helper module for managing the memory needed to store the BLE connection state for the netif wrapper. More...

Detailed Description

Helper module for managing the memory needed to store the BLE connection state for the netif wrapper.

Files

file  nimble_netif_conn.h
 Connection allocation and maintenance for NimBLE netif.
 

Data Structures

struct  nimble_netif_conn_t
 Memory layout for holding the relevant connection information. More...
 

Macros

#define NIMBLE_NETIF_CONN_INVALID   (-1)
 Value for marking a handle invalid.
 

Typedefs

typedef int(* nimble_netif_conn_iter_t) (nimble_netif_conn_t *conn, int handle, void *arg)
 Iterator function signature used by nimble_netif_conn_foreach() More...
 

Functions

void nimble_netif_conn_init (void)
 Initialize the connection state manager. More...
 
nimble_netif_conn_tnimble_netif_conn_get (int handle)
 Get the connection context corresponding to the given handle. More...
 
int nimble_netif_conn_get_adv (void)
 Get the handle to the context that is currently advertising. More...
 
int nimble_netif_conn_get_connecting (void)
 Get the handle to the context that is busy connecting. More...
 
int nimble_netif_conn_get_by_addr (const uint8_t *addr)
 Find the connection to the peer with the given BLE address. More...
 
int nimble_netif_conn_get_by_gaphandle (uint16_t gaphandle)
 Find the connection using the given NimBLE GAP handle. More...
 
void nimble_netif_conn_foreach (uint16_t filter, nimble_netif_conn_iter_t cb, void *arg)
 Iterate over all connection contexts that match the filter condition. More...
 
int nimble_netif_conn_get_next (int handle, uint16_t filter)
 Find the next context that matches the filter condition. More...
 
unsigned nimble_netif_conn_count (uint16_t filter)
 Count the number of connections contexts for which the given filter applies. More...
 
int nimble_netif_conn_start_connection (const uint8_t *addr)
 Allocate an unused context for starting a connection. More...
 
int nimble_netif_conn_start_adv (void)
 Reserve a unused context for the purpose of accepting a new connection. More...
 
void nimble_netif_conn_free (int handle, uint8_t *addr)
 Free the connection context with the given handle.
 
static nimble_netif_conn_tnimble_netif_conn_from_gaphandle (uint16_t gh)
 Find the connection context with a given GAP handle and return a pointer to it. More...
 
static int nimble_netif_conn_connecting (void)
 Convenience function to check if any context is currently in the connecting state (NIMBLE_NETIF_CONNECTING) More...
 
static int nimble_netif_conn_connected (const uint8_t *addr)
 Convenience function to check if we are currently connected to a peer with the given address. More...
 
static int nimble_netif_conn_is_open (const nimble_netif_conn_t *conn)
 Test if the given connection is (still) open. More...
 
static int nimble_netif_conn_is_adv (void)
 Convenience function to check if any context is currently in the advertising state (NIMBLE_NETIF_ADV) More...
 

Typedef Documentation

◆ nimble_netif_conn_iter_t

typedef int(* nimble_netif_conn_iter_t) (nimble_netif_conn_t *conn, int handle, void *arg)

Iterator function signature used by nimble_netif_conn_foreach()

Parameters
[in]connconnection context of the current entry
[in]handlehandle of the current entry
[in]arguser supplied argument
Returns
0 to continue
!= 0 to stop iterating

Definition at line 59 of file nimble_netif_conn.h.

Function Documentation

◆ nimble_netif_conn_connected()

static int nimble_netif_conn_connected ( const uint8_t *  addr)
inlinestatic

Convenience function to check if we are currently connected to a peer with the given address.

Parameters
[in]addrBLE address, in network byte order
Returns
!= 0 if true
0 if false

Definition at line 214 of file nimble_netif_conn.h.

◆ nimble_netif_conn_connecting()

static int nimble_netif_conn_connecting ( void  )
inlinestatic

Convenience function to check if any context is currently in the connecting state (NIMBLE_NETIF_CONNECTING)

Returns
!= 0 if true
0 if false

Definition at line 200 of file nimble_netif_conn.h.

◆ nimble_netif_conn_count()

unsigned nimble_netif_conn_count ( uint16_t  filter)

Count the number of connections contexts for which the given filter applies.

Parameters
[in]filterfilter mask
Returns
number of contexts for which the filter applied

◆ nimble_netif_conn_foreach()

void nimble_netif_conn_foreach ( uint16_t  filter,
nimble_netif_conn_iter_t  cb,
void *  arg 
)

Iterate over all connection contexts that match the filter condition.

Warning
Do not call any other nimble_netif_conn function from within the callback, this will lead to a deadlock!
Parameters
[in]filterfilter mask
[in]cbcallback called on each filtered entry
[in]arguser argument

◆ nimble_netif_conn_from_gaphandle()

static nimble_netif_conn_t* nimble_netif_conn_from_gaphandle ( uint16_t  gh)
inlinestatic

Find the connection context with a given GAP handle and return a pointer to it.

Parameters
[in]ghGAP handle used by NimBLE
Returns
Pointer to the selected context
NULL if no fitting context was found

Definition at line 188 of file nimble_netif_conn.h.

◆ nimble_netif_conn_get()

nimble_netif_conn_t* nimble_netif_conn_get ( int  handle)

Get the connection context corresponding to the given handle.

Parameters
[in]handlehandle to a connection context
Returns
pointer to the corresponding connection context
NULL if handle in invalid

◆ nimble_netif_conn_get_adv()

int nimble_netif_conn_get_adv ( void  )

Get the handle to the context that is currently advertising.

Returns
handle to the currently advertising context
NIMBLE_NETIF_CONN_INVALID if not advertising

◆ nimble_netif_conn_get_by_addr()

int nimble_netif_conn_get_by_addr ( const uint8_t *  addr)

Find the connection to the peer with the given BLE address.

Parameters
[in]addrBLE address, in network byte order
Returns
handle to the matching connection context
NIMBLE_NETIF_CONN_INVALID if no matching connection was found

◆ nimble_netif_conn_get_by_gaphandle()

int nimble_netif_conn_get_by_gaphandle ( uint16_t  gaphandle)

Find the connection using the given NimBLE GAP handle.

Parameters
[in]gaphandleGAP handle as exposed by NimBLE
Returns
handle to the matching connection context
NIMBLE_NETIF_CONN_INVALID if no matching connection was found

◆ nimble_netif_conn_get_connecting()

int nimble_netif_conn_get_connecting ( void  )

Get the handle to the context that is busy connecting.

Returns
handle to the busy context
NIMBLE_NETIF_CONN_INVALID if not busy connecting

◆ nimble_netif_conn_get_next()

int nimble_netif_conn_get_next ( int  handle,
uint16_t  filter 
)

Find the next context that matches the filter condition.

This function allows for iterating connection contexts in a non-blocking way.

Parameters
[in]handlelast used handle, set to NIMBLE_NETIF_CONN_INVALID to get the first matching entry
[in]filterfilter mask
Returns
handle of the next matching connection context
NIMBLE_NETIF_CONN_INVALID if no matching context was found

◆ nimble_netif_conn_init()

void nimble_netif_conn_init ( void  )

Initialize the connection state manager.

This functions is typically called by nimble_netif_init().

◆ nimble_netif_conn_is_adv()

static int nimble_netif_conn_is_adv ( void  )
inlinestatic

Convenience function to check if any context is currently in the advertising state (NIMBLE_NETIF_ADV)

Returns
!= 0 if true
0 if false

Definition at line 239 of file nimble_netif_conn.h.

◆ nimble_netif_conn_is_open()

static int nimble_netif_conn_is_open ( const nimble_netif_conn_t conn)
inlinestatic

Test if the given connection is (still) open.

Parameters
[in]connConnection to test
Returns
!= 0 if true
0 if false

Definition at line 227 of file nimble_netif_conn.h.

◆ nimble_netif_conn_start_adv()

int nimble_netif_conn_start_adv ( void  )

Reserve a unused context for the purpose of accepting a new connection.

Returns
handle of the reserved context
NIMBLE_NETIF_CONN_INVALID if no unused context was available

◆ nimble_netif_conn_start_connection()

int nimble_netif_conn_start_connection ( const uint8_t *  addr)

Allocate an unused context for starting a connection.

Parameters
[in]addrthe BLE address of the peer node, in network byte order
Returns
handle used for the new connection