Loading...
Searching...
No Matches

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.
 

Data Structures

struct  nimble_statconn_cfg_t
 Statconn connection parameters. More...
 

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_MIN_MS   (75U)
 Minimum connection interval used when opening a new connection.
 
#define NIMBLE_STATCONN_CONN_ITVL_MAX_MS   (75U)
 Maximum connection interval to use.
 
#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].
 
#define NIMBLE_STATCONN_PHY_MODE   NIMBLE_PHY_1M
 BLE PHY mode used by statconn.
 

Functions

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

Macro Definition Documentation

◆ NIMBLE_STATCONN_ADV_ITVL_MS

#define NIMBLE_STATCONN_ADV_ITVL_MS   (90U)

Advertising interval used when in advertising mode [in ms].

Definition at line 66 of file nimble_statconn.h.

◆ NIMBLE_STATCONN_CONN_ITVL_MAX_MS

#define NIMBLE_STATCONN_CONN_ITVL_MAX_MS   (75U)

Maximum connection interval to use.

See NIMBLE_STATCONN_CONN_ITVL_MIN_MS for more information. [in ms]

Definition at line 99 of file nimble_statconn.h.

◆ NIMBLE_STATCONN_CONN_ITVL_MIN_MS

#define NIMBLE_STATCONN_CONN_ITVL_MIN_MS   (75U)

Minimum connection interval used when opening a new connection.

The actual used connection interval will be a random value ranging from NIMBLE_STATCONN_CONN_ITVL_MIN_MS to NIMBLE_STATCONN_CONN_ITVL_MAX_MS. Set both variables to the same value to use a fixed connection interval. [in ms]

Definition at line 91 of file nimble_statconn.h.

◆ NIMBLE_STATCONN_CONN_LATENCY

#define NIMBLE_STATCONN_CONN_LATENCY   (0)

Slave latency used for new connections [# of connection events].

Definition at line 106 of file nimble_statconn.h.

◆ NIMBLE_STATCONN_CONN_SUPERTO_MS

#define NIMBLE_STATCONN_CONN_SUPERTO_MS   (2500U)

Supervision timeout used for new connections [in ms].

Definition at line 113 of file nimble_statconn.h.

◆ NIMBLE_STATCONN_CONN_TIMEOUT_MS

#define NIMBLE_STATCONN_CONN_TIMEOUT_MS   (600U)

Opening a new connection is aborted after this time [in ms].

Definition at line 80 of file nimble_statconn.h.

◆ NIMBLE_STATCONN_CONN_WIN_MS

#define NIMBLE_STATCONN_CONN_WIN_MS   (100U)

Scan window used when opening new connections [in ms].

Definition at line 73 of file nimble_statconn.h.

◆ NIMBLE_STATCONN_PHY_MODE

#define NIMBLE_STATCONN_PHY_MODE   NIMBLE_PHY_1M

BLE PHY mode used by statconn.

This value is only used if statconn is used in its extended mode (module nimble_statconn_ext)

Definition at line 121 of file nimble_statconn.h.

Function Documentation

◆ nimble_statconn_add_master()

int nimble_statconn_add_master ( const uint8_t *  addr,
const nimble_statconn_cfg_t cfg 
)

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
[in]cfgadditional connection parameters, set to NULL to apply default values
Returns
0 if peer was successfully added
-EALREADY if the peer address is already in use
-ENOMEM if no empty connection slot is available
-EINVAL if invalid configuration parameters are given

◆ nimble_statconn_add_slave()

int nimble_statconn_add_slave ( const uint8_t *  addr,
const nimble_statconn_cfg_t cfg 
)

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

Parameters
[in]addrBLE address of the peer
[in]cfgadditional connection parameters, set to NULL to apply default values
Returns
0 if peer was successfully added
-EALREADY if the peer address is already in use
-ENOMEM if no empty connection slot is available
-EINVAL if invalid configuration parameters are given

◆ 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
0 if peer was successfully removed
-ENOTCONN if given address is not managed