Skip to content

nimble/controller: Add Channel Sounding setup phase #1765

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion nimble/controller/include/controller/ble_ll_conn.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ struct ble_ll_conn_subrate_req_params {
uint16_t supervision_tmo;
};

#if MYNEWT_VAL(BLE_LL_CHANNEL_SOUNDING)
struct ble_ll_cs_sm;
#endif

/* Connection state machine */
struct ble_ll_conn_sm
{
Expand Down Expand Up @@ -274,7 +278,7 @@ struct ble_ll_conn_sm
uint8_t vers_nr;
uint8_t conn_features;
uint8_t remote_features[7];
uint16_t pending_ctrl_procs;
uint32_t pending_ctrl_procs;
uint16_t event_cntr;
uint16_t completed_pkts;
uint16_t comp_id;
Expand Down Expand Up @@ -400,6 +404,10 @@ struct ble_ll_conn_sm
uint16_t css_slot_idx_pending;
uint8_t css_period_idx;
#endif

#if MYNEWT_VAL(BLE_LL_CHANNEL_SOUNDING)
struct ble_ll_cs_sm *cssm;
#endif
};

/* Role */
Expand Down
20 changes: 20 additions & 0 deletions nimble/controller/include/controller/ble_ll_cs.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,26 @@
extern "C" {
#endif

void ble_ll_cs_init(void);
void ble_ll_cs_reset(void);

void ble_ll_cs_capabilities_pdu_make(struct ble_ll_conn_sm *connsm, uint8_t *dptr);
void ble_ll_cs_config_req_make(struct ble_ll_conn_sm *connsm, uint8_t *dptr);
void ble_ll_cs_security_req_make(struct ble_ll_conn_sm *connsm, uint8_t *dptr);

int ble_ll_cs_rx_capabilities_req(struct ble_ll_conn_sm *connsm, uint8_t *dptr, uint8_t *rspbuf);
void ble_ll_cs_rx_capabilities_rsp(struct ble_ll_conn_sm *connsm, uint8_t *dptr);
void ble_ll_cs_rx_capabilities_req_rejected(struct ble_ll_conn_sm *connsm, uint8_t ble_error);
int ble_ll_cs_rx_fae_req(struct ble_ll_conn_sm *connsm, struct os_mbuf *om);
void ble_ll_cs_rx_fae_rsp(struct ble_ll_conn_sm *connsm, uint8_t *dptr);
void ble_ll_cs_rx_fae_req_rejected(struct ble_ll_conn_sm *connsm, uint8_t ble_error);
int ble_ll_cs_rx_config_req(struct ble_ll_conn_sm *connsm, uint8_t *dptr, uint8_t *rspbuf);
void ble_ll_cs_rx_config_rsp(struct ble_ll_conn_sm *connsm, uint8_t *dptr);
void ble_ll_cs_rx_config_req_rejected(struct ble_ll_conn_sm *connsm, uint8_t ble_error);
int ble_ll_cs_rx_security_req(struct ble_ll_conn_sm *connsm, uint8_t *dptr, uint8_t *rspbuf);
void ble_ll_cs_rx_security_rsp(struct ble_ll_conn_sm *connsm, uint8_t *dptr);
void ble_ll_cs_rx_security_req_rejected(struct ble_ll_conn_sm *connsm, uint8_t ble_error);

/* HCI handlers */
int ble_ll_cs_hci_rd_loc_supp_cap(uint8_t *rspbuf, uint8_t *rsplen);
int ble_ll_cs_hci_rd_rem_supp_cap(const uint8_t *cmdbuf, uint8_t cmdlen);
Expand Down
48 changes: 45 additions & 3 deletions nimble/controller/include/controller/ble_ll_ctrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ extern "C" {
#define BLE_LL_CTRL_PROC_CIS_CREATE (11)
#define BLE_LL_CTRL_PROC_SUBRATE_REQ (12)
#define BLE_LL_CTRL_PROC_SUBRATE_UPDATE (13)
#define BLE_LL_CTRL_PROC_NUM (14)
#define BLE_LL_CTRL_PROC_CS_CAP_XCHG (14)
#define BLE_LL_CTRL_PROC_CS_FAE_REQ (15)
#define BLE_LL_CTRL_PROC_CS_CONF (16)
#define BLE_LL_CTRL_PROC_CS_SEC_START (17)
#define BLE_LL_CTRL_PROC_NUM (18)
#define BLE_LL_CTRL_PROC_IDLE (255)

/* Checks if a particular control procedure is running */
Expand Down Expand Up @@ -100,14 +104,32 @@ extern "C" {
#define BLE_LL_CTRL_SUBRATE_IND (0x27)
#define BLE_LL_CTRL_CHAN_REPORTING_IND (0x28)
#define BLE_LL_CTRL_CHAN_STATUS_IND (0x29)
#define BLE_LL_CTRL_PERIODIC_SYNC_WR_IND (0x2A)
#define BLE_LL_CTRL_FEATURE_EXT_REQ (0x2B)
#define BLE_LL_CTRL_FEATURE_EXT_RSP (0x2C)
#define BLE_LL_CTRL_CS_SEC_RSP (0x2D)
#define BLE_LL_CTRL_CS_CAPABILITIES_REQ (0x2E)
#define BLE_LL_CTRL_CS_CAPABILITIES_RSP (0x2F)
#define BLE_LL_CTRL_CS_CONFIG_REQ (0x30)
#define BLE_LL_CTRL_CS_CONFIG_RSP (0x31)
#define BLE_LL_CTRL_CS_REQ (0x32)
#define BLE_LL_CTRL_CS_RSP (0x33)
#define BLE_LL_CTRL_CS_IND (0x34)
#define BLE_LL_CTRL_CS_TERMINATE_IND (0x35)
#define BLE_LL_CTRL_CS_FAE_REQ (0x36)
#define BLE_LL_CTRL_CS_FAE_RSP (0x37)
#define BLE_LL_CTRL_CS_CHANNEL_MAP_IND (0x38)
#define BLE_LL_CTRL_CS_SEC_REQ (0x39)

/* Maximum opcode value */
#define BLE_LL_CTRL_OPCODES (BLE_LL_CTRL_CHAN_STATUS_IND + 1)
#define BLE_LL_CTRL_OPCODES (BLE_LL_CTRL_CS_SEC_REQ + 1)

extern const uint8_t g_ble_ll_ctrl_pkt_lengths[BLE_LL_CTRL_OPCODES];

/* Maximum LL control PDU size */
#if MYNEWT_VAL(BLE_ISO)
#if MYNEWT_VAL(BLE_CHANNEL_SOUNDING)
#define BLE_LL_CTRL_MAX_PDU_LEN (73)
#elif MYNEWT_VAL(BLE_ISO)
#define BLE_LL_CTRL_MAX_PDU_LEN (42)
#elif MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PERIODIC_ADV_SYNC_TRANSFER)
#define BLE_LL_CTRL_MAX_PDU_LEN (35)
Expand Down Expand Up @@ -292,6 +314,26 @@ struct ble_ll_len_req
#define BLE_LL_CTRL_CHAN_REPORTING_IND_LEN (3)
#define BLE_LL_CTRL_CHAN_STATUS_IND_LEN (10)

/* Not implemented */
#define BLE_LL_CTRL_PERIODIC_SYNC_WR_IND_LEN (0)
#define BLE_LL_CTRL_FEATURE_EXT_REQ_LEN (0)
#define BLE_LL_CTRL_FEATURE_EXT_RSP_LEN (0)

/* Channel Sounding */
#define BLE_LL_CTRL_CS_SEC_RSP_LEN (20)
#define BLE_LL_CTRL_CS_CAPABILITIES_REQ_LEN (25)
#define BLE_LL_CTRL_CS_CAPABILITIES_RSP_LEN (25)
#define BLE_LL_CTRL_CS_CONFIG_REQ_LEN (27)
#define BLE_LL_CTRL_CS_CONFIG_RSP_LEN (1)
#define BLE_LL_CTRL_CS_REQ_LEN (28)
#define BLE_LL_CTRL_CS_RSP_LEN (21)
#define BLE_LL_CTRL_CS_IND_LEN (18)
#define BLE_LL_CTRL_CS_TERMINATE_IND_LEN (4)
#define BLE_LL_CTRL_CS_FAE_REQ_LEN (0)
#define BLE_LL_CTRL_CS_FAE_RSP_LEN (72)
#define BLE_LL_CTRL_CS_CHANNEL_MAP_IND_LEN (12)
#define BLE_LL_CTRL_CS_SEC_REQ_LEN (20)

/* API */
struct ble_ll_conn_sm;
void ble_ll_ctrl_proc_start(struct ble_ll_conn_sm *connsm, int ctrl_proc,
Expand Down
7 changes: 7 additions & 0 deletions nimble/controller/pkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ pkg.deps:
- nimble
- nimble/transport

pkg.deps.TEST:
- "@apache-mynewt-core/crypto/mbedtls"

pkg.init:
ble_ll_init:
- $before:ble_transport_hs_init
- $before:ble_transport_ll_init

pkg.cflags.TEST:
- -Irepos/mbedtls/include
- -Irepos/include/mbedtls
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

includes should be added automatically from pkg dep

11 changes: 11 additions & 0 deletions nimble/controller/src/ble_ll.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
#if MYNEWT_VAL(BLE_LL_ISO_BROADCASTER)
#include "controller/ble_ll_iso_big.h"
#endif
#if MYNEWT_VAL(BLE_LL_CHANNEL_SOUNDING)
#include "controller/ble_ll_cs.h"
#endif
#if MYNEWT_VAL(BLE_LL_EXT)
#include "controller/ble_ll_ext.h"
#endif
Expand Down Expand Up @@ -1704,6 +1707,10 @@ ble_ll_reset(void)
ble_ll_iso_reset();
#endif

#if MYNEWT_VAL(BLE_LL_CHANNEL_SOUNDING)
ble_ll_cs_reset();
#endif

/* Re-initialize the PHY */
rc = ble_phy_init();

Expand Down Expand Up @@ -1990,6 +1997,10 @@ ble_ll_init(void)
ble_ll_iso_big_init();
#endif

#if MYNEWT_VAL(BLE_LL_CHANNEL_SOUNDING)
ble_ll_cs_init();
#endif

#if MYNEWT_VAL(BLE_LL_EXT)
ble_ll_ext_init();
#endif
Expand Down
21 changes: 19 additions & 2 deletions nimble/controller/src/ble_ll_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -1964,6 +1964,11 @@ ble_ll_conn_set_csa(struct ble_ll_conn_sm *connsm, bool chsel)
connsm->data_chan_index = ble_ll_conn_calc_dci(connsm, 1);
}

#if MYNEWT_VAL(BLE_LL_CHANNEL_SOUNDING)
void ble_ll_cs_sm_init(struct ble_ll_conn_sm *connsm);
void ble_ll_cs_sm_free(struct ble_ll_conn_sm *connsm);
#endif

/**
* Create a new connection state machine. This is done once per
* connection when the HCI command "create connection" is issued to the
Expand Down Expand Up @@ -2086,6 +2091,10 @@ ble_ll_conn_sm_new(struct ble_ll_conn_sm *connsm)
ble_ll_conn_css_update_list(connsm);
}
#endif

#if MYNEWT_VAL(BLE_LL_CHANNEL_SOUNDING)
ble_ll_cs_sm_init(connsm);
#endif
}

void
Expand Down Expand Up @@ -2211,6 +2220,10 @@ ble_ll_conn_end(struct ble_ll_conn_sm *connsm, uint8_t ble_err)
}
#endif

#if MYNEWT_VAL(BLE_LL_CHANNEL_SOUNDING)
ble_ll_cs_sm_free(connsm);
#endif

#if MYNEWT_VAL(BLE_LL_CFG_FEAT_CTRL_TO_HOST_FLOW_CONTROL)
ble_ll_conn_cth_flow_free_credit(connsm, connsm->cth_flow_pending);
#endif
Expand Down Expand Up @@ -3971,9 +3984,13 @@ ble_ll_conn_enqueue_pkt(struct ble_ll_conn_sm *connsm, struct os_mbuf *om,
return;
}

/* Set mbuf length and packet length if a control PDU */
/* Set overall packet length if a control PDU */
if (hdr_byte == BLE_LL_LLID_CTRL) {
om->om_len = length;
/* Set mbuf length if not chained mbufs */
if (SLIST_NEXT(om, om_next) == NULL) {
om->om_len = length;
}

OS_MBUF_PKTHDR(om)->omp_len = length;
num_pkt = 0;
} else {
Expand Down
Loading