Skip to content

Commit 6a3e225

Browse files
committed
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
1 parent 94daf9c commit 6a3e225

File tree

5 files changed

+94
-4
lines changed

5 files changed

+94
-4
lines changed

nimble/controller/include/controller/ble_ll_cs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ void ble_ll_cs_capabilities_pdu_make(struct ble_ll_conn_sm *connsm, uint8_t *dpt
3535

3636
int ble_ll_cs_rx_capabilities_req(struct ble_ll_conn_sm *connsm, uint8_t *dptr, uint8_t *rspbuf);
3737
void ble_ll_cs_rx_capabilities_rsp(struct ble_ll_conn_sm *connsm, uint8_t *dptr);
38+
int ble_ll_cs_rx_fae_req(struct ble_ll_conn_sm *connsm, uint8_t *rspbuf);
39+
void ble_ll_cs_rx_fae_rsp(struct ble_ll_conn_sm *connsm, uint8_t *dptr);
3840

3941
/* HCI handlers */
4042
int ble_ll_cs_hci_rd_loc_supp_cap(uint8_t *rspbuf, uint8_t *rsplen);

nimble/controller/include/controller/ble_ll_ctrl.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ extern "C" {
4444
#define BLE_LL_CTRL_PROC_SUBRATE_REQ (12)
4545
#define BLE_LL_CTRL_PROC_SUBRATE_UPDATE (13)
4646
#define BLE_LL_CTRL_PROC_CS_CAP_XCHG (14)
47-
#define BLE_LL_CTRL_PROC_NUM (15)
47+
#define BLE_LL_CTRL_PROC_CS_FAE_REQ (15)
48+
#define BLE_LL_CTRL_PROC_NUM (16)
4849
#define BLE_LL_CTRL_PROC_IDLE (255)
4950

5051
/* Checks if a particular control procedure is running */
@@ -124,7 +125,9 @@ extern "C" {
124125
extern const uint8_t g_ble_ll_ctrl_pkt_lengths[BLE_LL_CTRL_OPCODES];
125126

126127
/* Maximum LL control PDU size */
127-
#if MYNEWT_VAL(BLE_ISO)
128+
#if MYNEWT_VAL(BLE_CHANNEL_SOUNDING)
129+
#define BLE_LL_CTRL_MAX_PDU_LEN (72)
130+
#elif MYNEWT_VAL(BLE_ISO)
128131
#define BLE_LL_CTRL_MAX_PDU_LEN (42)
129132
#elif MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PERIODIC_ADV_SYNC_TRANSFER)
130133
#define BLE_LL_CTRL_MAX_PDU_LEN (35)

nimble/controller/src/ble_ll_cs.c

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,17 +348,88 @@ ble_ll_cs_hci_set_def_settings(const uint8_t *cmdbuf, uint8_t cmdlen,
348348
return BLE_ERR_SUCCESS;
349349
}
350350

351+
int
352+
ble_ll_cs_rx_fae_req(struct ble_ll_conn_sm *connsm, uint8_t *rspbuf)
353+
{
354+
memcpy(rspbuf, connsm->cssm->local_fae_table, 72);
355+
356+
return BLE_LL_CTRL_CS_FAE_RSP;
357+
}
358+
359+
static void
360+
ble_ll_cs_ev_rd_rem_fae_complete(struct ble_ll_conn_sm *connsm, uint8_t status)
361+
{
362+
struct ble_hci_ev_le_subev_cs_rd_rem_fae_complete *ev;
363+
struct ble_hci_ev *hci_ev;
364+
365+
if (ble_ll_hci_is_le_event_enabled(
366+
BLE_HCI_LE_SUBEV_CS_RD_REM_FAE_COMPLETE)) {
367+
hci_ev = ble_transport_alloc_evt(0);
368+
if (hci_ev) {
369+
hci_ev->opcode = BLE_HCI_EVCODE_LE_META;
370+
hci_ev->length = sizeof(*ev);
371+
ev = (void *) hci_ev->data;
372+
373+
ev->subev_code = BLE_HCI_LE_SUBEV_CS_RD_REM_FAE_COMPLETE;
374+
ev->status = status;
375+
ev->conn_handle = htole16(connsm->conn_handle);
376+
memcpy(ev->remote_fae_table, connsm->cssm->remote_fae_table, 72);
377+
378+
ble_ll_hci_event_send(hci_ev);
379+
}
380+
}
381+
}
382+
383+
void
384+
ble_ll_cs_rx_fae_rsp(struct ble_ll_conn_sm *connsm, uint8_t *dptr)
385+
{
386+
if (!IS_PENDING_CTRL_PROC(connsm, BLE_LL_CTRL_PROC_CS_FAE_REQ)) {
387+
/* Should never happen */
388+
return;
389+
}
390+
391+
memcpy(connsm->cssm->remote_fae_table, dptr, 72);
392+
393+
/* Stop the control procedure and send an event to the host */
394+
ble_ll_ctrl_proc_stop(connsm, BLE_LL_CTRL_PROC_CS_FAE_REQ);
395+
ble_ll_cs_ev_rd_rem_fae_complete(connsm, BLE_ERR_SUCCESS);
396+
}
397+
351398
int
352399
ble_ll_cs_hci_rd_rem_fae(const uint8_t *cmdbuf, uint8_t cmdlen)
353400
{
354-
return BLE_ERR_UNSUPPORTED;
401+
const struct ble_hci_le_cs_rd_rem_fae_cp *cmd = (const void *)cmdbuf;
402+
struct ble_ll_conn_sm *connsm;
403+
404+
connsm = ble_ll_conn_find_by_handle(le16toh(cmd->conn_handle));
405+
if (!connsm) {
406+
return BLE_ERR_UNK_CONN_ID;
407+
}
408+
409+
ble_ll_ctrl_proc_start(connsm, BLE_LL_CTRL_PROC_CS_FAE_REQ, NULL);
410+
411+
return BLE_ERR_SUCCESS;
355412
}
356413

357414
int
358415
ble_ll_cs_hci_wr_cached_rem_fae(const uint8_t *cmdbuf, uint8_t cmdlen,
359416
uint8_t *rspbuf, uint8_t *rsplen)
360417
{
361-
return BLE_ERR_UNSUPPORTED;
418+
const struct ble_hci_le_cs_wr_cached_rem_fae_cp *cmd = (const void *)cmdbuf;
419+
struct ble_hci_le_cs_wr_cached_rem_fae_rp *rsp = (void *)rspbuf;
420+
struct ble_ll_conn_sm *connsm;
421+
422+
connsm = ble_ll_conn_find_by_handle(le16toh(cmd->conn_handle));
423+
if (!connsm) {
424+
return BLE_ERR_UNK_CONN_ID;
425+
}
426+
427+
memcpy(connsm->cssm->remote_fae_table, cmd->remote_fae_table, 72);
428+
429+
rsp->conn_handle = cmd->conn_handle;
430+
*rsplen = sizeof(*rsp);
431+
432+
return BLE_ERR_SUCCESS;
362433
}
363434

364435
int

nimble/controller/src/ble_ll_cs_priv.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ struct ble_ll_cs_sm {
7272
uint8_t roles_enabled;
7373
uint8_t cs_sync_antenna_selection;
7474
uint8_t max_tx_power;
75+
76+
/* Cached FAE tables */
77+
uint8_t remote_fae_table[72];
78+
uint8_t local_fae_table[72];
7579
};
7680

7781
#ifdef __cplusplus

nimble/controller/src/ble_ll_ctrl.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2574,6 +2574,10 @@ ble_ll_ctrl_proc_init(struct ble_ll_conn_sm *connsm, int ctrl_proc, void *data)
25742574
opcode = BLE_LL_CTRL_CS_CAPABILITIES_REQ;
25752575
ble_ll_cs_capabilities_pdu_make(connsm, ctrdata);
25762576
break;
2577+
case BLE_LL_CTRL_PROC_CS_FAE_REQ:
2578+
opcode = BLE_LL_CTRL_CS_FAE_REQ;
2579+
/* No command parameters in LL_CS_FAE_REQ PDU */
2580+
break;
25772581
#endif
25782582
default:
25792583
BLE_LL_ASSERT(0);
@@ -3043,6 +3047,12 @@ ble_ll_ctrl_rx_pdu(struct ble_ll_conn_sm *connsm, struct os_mbuf *om)
30433047
case BLE_LL_CTRL_CS_CAPABILITIES_RSP:
30443048
ble_ll_cs_rx_capabilities_rsp(connsm, dptr);
30453049
break;
3050+
case BLE_LL_CTRL_CS_FAE_REQ:
3051+
rsp_opcode = ble_ll_cs_rx_fae_req(connsm, rspdata);
3052+
break;
3053+
case BLE_LL_CTRL_CS_FAE_RSP:
3054+
ble_ll_cs_rx_fae_rsp(connsm, dptr);
3055+
break;
30463056
#endif
30473057
default:
30483058
/* Nothing to do here */

0 commit comments

Comments
 (0)