Skip to content
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

[wip] nimble/ll: Add initial Channel Sounding scheduling #1789

Draft
wants to merge 33 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d8dcb7c
nimble/ll: Add DRBG for Channel Sounding
mkasenberg Apr 11, 2024
ec2959e
nimble/ll: Add unit tests for CS DRBG
mkasenberg Feb 27, 2024
2a7ef5a
nimble/host: ble_cs: Fix 'defined but not used' warning
mkasenberg Mar 14, 2024
f22a4ad
nimble/hci: Update Channel Sounding HCI
mkasenberg Apr 14, 2024
f4801f8
nimble/ll: Add Channel Sounding state machine
mkasenberg Apr 14, 2024
e43b560
nimble/ll: Add Channel Sounding LL CTRL opcodes
mkasenberg Apr 14, 2024
83702c4
nimble/ll: Add Channel Sounding capabilities
mkasenberg Apr 14, 2024
2e84451
nimble/ll: Add CS Capabilities Exchange procedure
mkasenberg Apr 14, 2024
e57b5b8
nimble/ll: Add LE CS Set Default Settings command
mkasenberg Apr 15, 2024
87343fa
nimble/ll: Add CS Mode-0 FAE Table Request procedure
mkasenberg Apr 15, 2024
58ea93f
nimble/ll: Add CS Configuration procedure
mkasenberg Apr 15, 2024
7ffaf72
nimble/ll: Add CS Security Start procedure
mkasenberg Apr 16, 2024
84d508f
nimble/ll: Add LE CS Set Channel Classification command
mkasenberg Apr 16, 2024
e5c19a3
nimble/ll: Add LE CS Set Procedure Parameters command
mkasenberg Apr 16, 2024
5e68123
nimble/ll: Add CS Start procedure
mkasenberg Apr 16, 2024
681232e
nimble/ll: Add initial Channel Sounding scheduling
mkasenberg Apr 18, 2024
d205439
nimble/ll: Add CS step modes and states
mkasenberg Apr 19, 2024
9913b20
nimble/ll: Add to CS states support for multiple antenna paths
mkasenberg Apr 19, 2024
c3ab86a
nimble/ll: Add CS subevent states
mkasenberg Apr 19, 2024
8a432b4
nimble/ll: Add CS channel generation
mkasenberg Apr 23, 2024
e54a25e
nimble/ll: Add packets durations to CS scheduling
mkasenberg Apr 24, 2024
f7088cc
nimble/ll: Add CS_SYNC transmission/reception
mkasenberg Apr 24, 2024
7792bf8
nimble/ll: Add CS Procedure Repeat Termination procedure
mkasenberg Jun 3, 2024
8e94cb7
nimble/ll: Add CS backtracking resistance
mkasenberg Jun 3, 2024
d46d95c
nimble/phy: babblesim: Add missing g_ble_phy_t_txaddrdelay
mkasenberg Aug 22, 2024
993a8cd
babblesim: Configure TIMER3 to 16MHz
mkasenberg Aug 22, 2024
6fa75b9
nimble: host: CS fixes
mkasenberg Aug 22, 2024
fa8152a
nimble/apps: Add sample apps for CS initiator and reflector
mkasenberg Feb 5, 2024
56cea23
babblesim: targets: Add targets for CS apps
mkasenberg Feb 5, 2024
dbf1985
[wip] Quasi CS
mkasenberg Jun 5, 2024
d3b280d
[wip] nimble/phy: Add Channel Sounding to PHY
mkasenberg Jun 5, 2024
8bff1d8
[wip] nimble/ll: Add usage of CS PHY
mkasenberg Aug 22, 2024
db6987d
[wip]nimble/ll: Add HCI Subevent Result (Continue) events
mkasenberg Aug 22, 2024
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
Prev Previous commit
Next Next commit
nimble/ll: Add CS Mode-0 FAE Table Request procedure
Implements:
- LE CS Read Remote FAE Table command
- LE CS Write Cached Remote FAE Table command
  • Loading branch information
mkasenberg committed Dec 25, 2024
commit 87343fa6f5c097e74fb3dc30d1f01cfe3d79c56a
3 changes: 3 additions & 0 deletions nimble/controller/include/controller/ble_ll_cs.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ void ble_ll_cs_capabilities_pdu_make(struct ble_ll_conn_sm *connsm, uint8_t *dpt
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);

/* HCI handlers */
int ble_ll_cs_hci_rd_loc_supp_cap(uint8_t *rspbuf, uint8_t *rsplen);
Expand Down
7 changes: 5 additions & 2 deletions nimble/controller/include/controller/ble_ll_ctrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ extern "C" {
#define BLE_LL_CTRL_PROC_SUBRATE_REQ (12)
#define BLE_LL_CTRL_PROC_SUBRATE_UPDATE (13)
#define BLE_LL_CTRL_PROC_CS_CAP_XCHG (14)
#define BLE_LL_CTRL_PROC_NUM (15)
#define BLE_LL_CTRL_PROC_CS_FAE_REQ (15)
#define BLE_LL_CTRL_PROC_NUM (16)
#define BLE_LL_CTRL_PROC_IDLE (255)

/* Checks if a particular control procedure is running */
Expand Down Expand Up @@ -124,7 +125,9 @@ extern "C" {
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
8 changes: 6 additions & 2 deletions nimble/controller/src/ble_ll_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -3961,9 +3961,13 @@ ble_ll_conn_enqueue_pkt(struct ble_ll_conn_sm *connsm, struct os_mbuf *om,
struct ble_mbuf_hdr *ble_hdr;
int lifo;

/* 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;
}

Expand Down
91 changes: 89 additions & 2 deletions nimble/controller/src/ble_ll_cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "controller/ble_ll_cs.h"
#include "ble_ll_conn_priv.h"
#include "ble_ll_cs_priv.h"
#include "os/os_mbuf.h"

#define T_IP1_CAP_ID_10US 0
#define T_IP1_CAP_ID_20US 1
Expand Down Expand Up @@ -427,17 +428,103 @@ ble_ll_cs_hci_set_def_settings(const uint8_t *cmdbuf, uint8_t cmdlen,
return BLE_ERR_SUCCESS;
}

int
ble_ll_cs_rx_fae_req(struct ble_ll_conn_sm *connsm, struct os_mbuf *om)
{
/* Space for response code */
om->om_len = 1;
OS_MBUF_PKTLEN(om) = om->om_len;
os_mbuf_append(om, connsm->cssm->local_fae_table, 72);

return BLE_LL_CTRL_CS_FAE_RSP;
}

static void
ble_ll_cs_ev_rd_rem_fae_complete(struct ble_ll_conn_sm *connsm, uint8_t status)
{
struct ble_hci_ev_le_subev_cs_rd_rem_fae_complete *ev;
struct ble_hci_ev *hci_ev;

if (ble_ll_hci_is_le_event_enabled(
BLE_HCI_LE_SUBEV_CS_RD_REM_FAE_COMPLETE)) {
hci_ev = ble_transport_alloc_evt(0);
if (hci_ev) {
hci_ev->opcode = BLE_HCI_EVCODE_LE_META;
hci_ev->length = sizeof(*ev);
ev = (void *) hci_ev->data;

memset(ev, 0, sizeof(*ev));
ev->subev_code = BLE_HCI_LE_SUBEV_CS_RD_REM_FAE_COMPLETE;
ev->status = status;
ev->conn_handle = htole16(connsm->conn_handle);

if (status == BLE_ERR_SUCCESS) {
memcpy(ev->remote_fae_table, connsm->cssm->remote_fae_table, 72);
}

ble_ll_hci_event_send(hci_ev);
}
}
}

void
ble_ll_cs_rx_fae_rsp(struct ble_ll_conn_sm *connsm, uint8_t *dptr)
{
if (!IS_PENDING_CTRL_PROC(connsm, BLE_LL_CTRL_PROC_CS_FAE_REQ)) {
/* Ignore */
return;
}

memcpy(connsm->cssm->remote_fae_table, dptr, 72);

/* Stop the control procedure and send an event to the host */
ble_ll_ctrl_proc_stop(connsm, BLE_LL_CTRL_PROC_CS_FAE_REQ);
ble_ll_cs_ev_rd_rem_fae_complete(connsm, BLE_ERR_SUCCESS);
}

void
ble_ll_cs_rx_fae_req_rejected(struct ble_ll_conn_sm *connsm, uint8_t ble_error)
{
/* Stop the control procedure and send an event to the host */
ble_ll_ctrl_proc_stop(connsm, BLE_LL_CTRL_PROC_CS_FAE_REQ);
ble_ll_cs_ev_rd_rem_fae_complete(connsm, ble_error);
}

int
ble_ll_cs_hci_rd_rem_fae(const uint8_t *cmdbuf, uint8_t cmdlen)
{
return BLE_ERR_UNSUPPORTED;
const struct ble_hci_le_cs_rd_rem_fae_cp *cmd = (const void *)cmdbuf;
struct ble_ll_conn_sm *connsm;

connsm = ble_ll_conn_find_by_handle(le16toh(cmd->conn_handle));
if (!connsm) {
return BLE_ERR_UNK_CONN_ID;
}

ble_ll_ctrl_proc_start(connsm, BLE_LL_CTRL_PROC_CS_FAE_REQ, NULL);

return BLE_ERR_SUCCESS;
}

int
ble_ll_cs_hci_wr_cached_rem_fae(const uint8_t *cmdbuf, uint8_t cmdlen,
uint8_t *rspbuf, uint8_t *rsplen)
{
return BLE_ERR_UNSUPPORTED;
const struct ble_hci_le_cs_wr_cached_rem_fae_cp *cmd = (const void *)cmdbuf;
struct ble_hci_le_cs_wr_cached_rem_fae_rp *rsp = (void *)rspbuf;
struct ble_ll_conn_sm *connsm;

connsm = ble_ll_conn_find_by_handle(le16toh(cmd->conn_handle));
if (!connsm) {
return BLE_ERR_UNK_CONN_ID;
}

memcpy(connsm->cssm->remote_fae_table, cmd->remote_fae_table, 72);

rsp->conn_handle = cmd->conn_handle;
*rsplen = sizeof(*rsp);

return BLE_ERR_SUCCESS;
}

int
Expand Down
4 changes: 4 additions & 0 deletions nimble/controller/src/ble_ll_cs_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ struct ble_ll_cs_sm {
uint8_t roles_enabled;
uint8_t cs_sync_antenna_selection;
uint8_t max_tx_power;

/* Cached FAE tables */
uint8_t remote_fae_table[72];
uint8_t local_fae_table[72];
};

#ifdef __cplusplus
Expand Down
13 changes: 13 additions & 0 deletions nimble/controller/src/ble_ll_ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2064,6 +2064,9 @@ ble_ll_ctrl_rx_reject_ind(struct ble_ll_conn_sm *connsm, uint8_t *dptr,
case BLE_LL_CTRL_PROC_CS_CAP_XCHG:
ble_ll_cs_rx_capabilities_req_rejected(connsm, ble_error);
break;
case BLE_LL_CTRL_PROC_CS_FAE_REQ:
ble_ll_cs_rx_fae_req_rejected(connsm, ble_error);
break;
#endif

default:
Expand Down Expand Up @@ -2593,6 +2596,10 @@ ble_ll_ctrl_proc_init(struct ble_ll_conn_sm *connsm, int ctrl_proc, void *data)
opcode = BLE_LL_CTRL_CS_CAPABILITIES_REQ;
ble_ll_cs_capabilities_pdu_make(connsm, ctrdata);
break;
case BLE_LL_CTRL_PROC_CS_FAE_REQ:
opcode = BLE_LL_CTRL_CS_FAE_REQ;
/* No command parameters in LL_CS_FAE_REQ PDU */
break;
#endif
default:
BLE_LL_ASSERT(0);
Expand Down Expand Up @@ -3071,6 +3078,12 @@ ble_ll_ctrl_rx_pdu(struct ble_ll_conn_sm *connsm, struct os_mbuf *om)
case BLE_LL_CTRL_CS_CAPABILITIES_RSP:
ble_ll_cs_rx_capabilities_rsp(connsm, dptr);
break;
case BLE_LL_CTRL_CS_FAE_REQ:
rsp_opcode = ble_ll_cs_rx_fae_req(connsm, om);
break;
case BLE_LL_CTRL_CS_FAE_RSP:
ble_ll_cs_rx_fae_rsp(connsm, dptr);
break;
#endif
default:
/* Nothing to do here */
Expand Down