Loading...
Searching...
No Matches
BLE L2CAP CLA Implementation

Implementation of a basic CLA over BLE L2CAP. More...

Detailed Description

Implementation of a basic CLA over BLE L2CAP.

About

Sends bundles via BLE between two statically connected devices.

To use this, call bplib_cla_ble_start(). The remote MAC address of the client will be taken from the NC (Node Config) wrapper tables, so bplib_contact_set_out_addr() needs to be configured before. The server currently accepts any connection.

Now the Convergence Layer Adapter (CLA) is ready to receive but bplib does not know this contact is active, so you also have to call BPLib_CLA_ContactSetup() and BPLib_CLA_ContactStart().

For an extended BLE CLA which also handles discovery, these functions should be called from within the CLA. A basic implementation of this can be enabled with bplib_cla_ble_manage_state(), which lets the CLA start and stop the contact when the BLE connection is disconnected.

This configuration makes sense only for the client, since for the server an "active" contact is not configured and any incoming connection is accepted. So, the reachable (Endpoint IDs) EIDs, configured for a contact, are not known to be valid for this connection.

In the future this could be extended to feature an exchange of reachable endpoints, automatic discovery and more reliable means of detecting when a connection is stable.

Files

file  bplib_cla_ble.h
 BLE CLA implementation.
 

Macros

#define CONFIG_BPLIB_CLA_BLE_TIMEOUT   10000
 Timeout after all CLA threads are stopped after bplib_cla_ble_stop, in ms.
 
#define CONFIG_BPLIB_CLA_BLE_MTU   1000
 MTU of an L2CAP message.
 
#define CONFIG_BPLIB_CLA_BLE_CID   0xabc1
 L2CAP CID to use.
 

Functions

int bplib_cla_ble_start (uint32_t contact_id, bool client)
 Start the CLA on BLE.
 
void bplib_cla_ble_manage_state (bool manage_state)
 If the CLA should change the state of the contact when a disconnect is detected.
 
void bplib_cla_ble_stop (void)
 Stops the CLA, and the BLE connection.
 

Macro Definition Documentation

◆ CONFIG_BPLIB_CLA_BLE_CID

#define CONFIG_BPLIB_CLA_BLE_CID   0xabc1

L2CAP CID to use.

Definition at line 62 of file bplib_cla_ble.h.

◆ CONFIG_BPLIB_CLA_BLE_MTU

#define CONFIG_BPLIB_CLA_BLE_MTU   1000

MTU of an L2CAP message.

Nimble's MSYS has to have enough buffer space.

Definition at line 57 of file bplib_cla_ble.h.

◆ CONFIG_BPLIB_CLA_BLE_TIMEOUT

#define CONFIG_BPLIB_CLA_BLE_TIMEOUT   10000

Timeout after all CLA threads are stopped after bplib_cla_ble_stop, in ms.

Definition at line 52 of file bplib_cla_ble.h.

Function Documentation

◆ bplib_cla_ble_manage_state()

void bplib_cla_ble_manage_state ( bool manage_state)

If the CLA should change the state of the contact when a disconnect is detected.

If this is enabled, the CLA will call BPLib_CLA_ContactStart and BPLib_CLA_ContactStop functions, increasing the chances that bundles will be stored when the connection is down. In the case of very unstable connections, i.e. repetitive disconnects and connects this does not really help with increasing the reliability, since bundles get pulled from bplib and BLE loses the bundle anyways.

Parameters
manage_statetrue to enable, false otherwise. Default: false

◆ bplib_cla_ble_start()

int bplib_cla_ble_start ( uint32_t contact_id,
bool client )

Start the CLA on BLE.

No bundles are sent until BPLib_CLA_ContactSetup and BPLib_CLA_ContactStart are called.

Parameters
contact_idThe contact table index. This table should contain the destination MAC address to connect to
clienttrue of the CLA should send bundles, false if it should receive bundles. Bidirectional connection are currently not supported.
Return values
0on success
1when the CLA is already started
<0negative errno codes from thread creation attempts if these fail.

◆ bplib_cla_ble_stop()

void bplib_cla_ble_stop ( void )

Stops the CLA, and the BLE connection.

May take up to CONFIG_BPLIB_CLA_BLE_TIMEOUT until the threads are stopped, since they wait (timed) for bplib functions.