Static connection manager for NimBLE netif that keeps opens connections on demand and takes care of keeping them open. More...

Detailed Description

Static connection manager for NimBLE netif that keeps opens connections on demand and takes care of keeping them open.

Warning
This feature is experimental!

WARNING

This module is highly experimental! Expect bugs, instabilities and sudden API changes :-)

About

Statconn is the implementation of a static connection manager for the NimBLE netif module. It initiates new connections when told and additionally takes care of reopening connections in case of connection loss.

Usage

A node can either be a master, the one initiating the connection, or a slave, the one advertising its presence, w.r.t. to BLE connections. To open a connection between two nodes, call nimble_statconn_add_slave() with the BLE address of the slave node on the designated master node and call nimble_statconn_add_master() with the address of the master node on the designated slave node. From that point on, statconn will take care of opening and maintaining the connection between these two nodes.

Configuration

This module is configured completely statically. All relevant configuration options are set at compile time using a couple of macros.

Files

file  nimble_statconn.h
 Simple static connection manager for NimBLE netif.
 

Macros

#define NIMBLE_STATCONN_ADV_ITVL_MS   (90U)
 Advertising interval used when in advertising mode [in ms].
 
#define NIMBLE_STATCONN_CONN_WIN_MS   (100U)
 Scan window used when opening new connections [in ms].
 
#define NIMBLE_STATCONN_CONN_TIMEOUT_MS   (600U)
 Opening a new connection is aborted after this time [in ms].
 
#define NIMBLE_STATCONN_CONN_ITVL_MS   (75U)
 Connection interval used when opening a new connection [in ms].
 
#define NIMBLE_STATCONN_CONN_LATENCY   (0)
 Slave latency used for new connections [# of connection events].
 
#define NIMBLE_STATCONN_CONN_SUPERTO_MS   (2500U)
 Supervision timeout used for new connections [in ms].
 

Enumerations

enum  { NIMBLE_STATCONN_OK = 0, NIMBLE_STATCONN_NOSLOT = -1, NIMBLE_STATCONN_NOTCONN = -2, NIMBLE_STATCONN_INUSE = -3 }
 Return codes used by the statconn module. More...
 

Functions

void nimble_statconn_init (void)
 Initialize the statconn module. More...
 
void nimble_statconn_eventcb (nimble_netif_eventcb_t cb)
 Register a callback that is called on netif events. More...
 
int nimble_statconn_add_master (const uint8_t *addr)
 Connect to peer (master) with a given address as slave. More...
 
int nimble_statconn_add_slave (const uint8_t *addr)
 Connect to a peer (slave) with a given address as master. More...
 
int nimble_statconn_rm (const uint8_t *addr)
 Remove the connection to the given peer. More...
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Return codes used by the statconn module.

Enumerator
NIMBLE_STATCONN_OK 

all groovy

NIMBLE_STATCONN_NOSLOT 

no more connection slot available

NIMBLE_STATCONN_NOTCONN 

given address is not managed

NIMBLE_STATCONN_INUSE 

given peer is already managed

Definition at line 106 of file nimble_statconn.h.

Function Documentation

◆ nimble_statconn_add_master()

int nimble_statconn_add_master ( const uint8_t *  addr)

Connect to peer (master) with a given address as slave.

Adding a master will make this node advertise itself to wait for an incoming connection by that master.

Parameters
[in]addrBLE address of the peer
Returns
NIMBLE_STATCONN_OK if peer was successfully added
NIMBLE_STATCONN_INUSE if the peer address is already in use
NIMBLE_STATCONN_NOSLOT if no empty connection slot is available

◆ nimble_statconn_add_slave()

int nimble_statconn_add_slave ( const uint8_t *  addr)

Connect to a peer (slave) with a given address as master.

Parameters
[in]addrBLE address of the peer
Returns
NIMBLE_STATCONN_OK if peer was successfully added
NIMBLE_STATCONN_INUSE if the peer address is already in use
NIMBLE_STATCONN_NOSLOT if no empty connection slot is available

◆ nimble_statconn_eventcb()

void nimble_statconn_eventcb ( nimble_netif_eventcb_t  cb)

Register a callback that is called on netif events.

The registered callback function is a simple pass-through of nimble_netif events. The callback is executed in the context of NimBLE's host thread.

Parameters
[in]cbevent callback to register, may be NULL

◆ nimble_statconn_init()

void nimble_statconn_init ( void  )

Initialize the statconn module.

Warning
This function must only be called once. Typically this is done during system initialization via auto-init.

◆ nimble_statconn_rm()

int nimble_statconn_rm ( const uint8_t *  addr)

Remove the connection to the given peer.

Parameters
[in]addrBLE address of the peer
Returns
NIMBLE_STATCONN_OK if peer was successfully removed
NIMBLE_STATCONN_NOTCONN if given address is not managed