Skip to content

Commit 385f977

Browse files
committed
nimble/ll: Add LE CS Set Channel Classification command
1 parent f429a90 commit 385f977

File tree

1 file changed

+63
-1
lines changed

1 file changed

+63
-1
lines changed

nimble/controller/src/ble_ll_cs.c

+63-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ static const uint8_t t_ip1[] = {10, 20, 30, 40, 50, 60, 80, 145};
3535
static const uint8_t t_ip2[] = {10, 20, 30, 40, 50, 60, 80, 145};
3636
static const uint8_t t_fcs[] = {15, 20, 30, 40, 50, 60, 80, 100, 120, 150};
3737
static const uint8_t t_pm[] = {10, 20, 40};
38+
static const uint8_t default_channel_classification[10] = {
39+
0xFC, 0xFF, 0x7F, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x1F
40+
};
41+
static uint8_t g_ble_ll_cs_chan_class[10];
42+
static uint8_t g_ble_ll_cs_chan_count = 0;
43+
static uint8_t g_ble_ll_cs_chan_indices[72];
3844

3945
int
4046
ble_ll_cs_hci_rd_loc_supp_cap(uint8_t *rspbuf, uint8_t *rsplen)
@@ -868,10 +874,64 @@ ble_ll_cs_hci_remove_config(const uint8_t *cmdbuf, uint8_t cmdlen)
868874
return BLE_ERR_SUCCESS;
869875
}
870876

877+
static int
878+
ble_ll_cs_proc_set_chan_class(const uint8_t *channel_classification)
879+
{
880+
uint8_t i, j, next_id, byte;
881+
882+
/* TODO:
883+
* 1. The interval between two successive commands sent shall be at least 1 second.
884+
* Otherwise, the Controller shall return the error code Command Disallowed (0x0C).
885+
*
886+
* 2. Combine the Host chan_class with local chan_class capabilities?
887+
*/
888+
889+
if (channel_classification[0] & 0b00000011 ||
890+
channel_classification[2] & 0b10000000 ||
891+
channel_classification[3] & 0b00000011 ||
892+
channel_classification[9] & 0b11100000) {
893+
/* Channels 0, 1, 23, 24, 25, 77, 78, and the bit 79 (non-channel)
894+
* are RFU. At least 15 channels shall be enabled.
895+
*/
896+
return -1;
897+
}
898+
899+
for (i = 0, j = 0; i < ARRAY_SIZE(g_ble_ll_cs_chan_class); ++i) {
900+
byte = channel_classification[i];
901+
next_id = i * 8;
902+
903+
while (byte) {
904+
if (byte & 1) {
905+
g_ble_ll_cs_chan_indices[j++] = next_id;
906+
}
907+
++next_id;
908+
byte >>= 1;
909+
}
910+
}
911+
912+
g_ble_ll_cs_chan_count = j;
913+
if (g_ble_ll_cs_chan_count < 15) {
914+
return -1;
915+
}
916+
917+
memcpy(g_ble_ll_cs_chan_class, channel_classification,
918+
sizeof(g_ble_ll_cs_chan_class));
919+
920+
return 0;
921+
}
922+
871923
int
872924
ble_ll_cs_hci_set_chan_class(const uint8_t *cmdbuf, uint8_t cmdlen)
873925
{
874-
return BLE_ERR_UNSUPPORTED;
926+
int rc;
927+
const struct ble_hci_le_cs_set_chan_class_cp *cmd = (const void *)cmdbuf;
928+
929+
rc = ble_ll_cs_proc_set_chan_class(cmd->channel_classification);
930+
if (rc) {
931+
return BLE_ERR_INV_HCI_CMD_PARMS;
932+
}
933+
934+
return BLE_ERR_SUCCESS;
875935
}
876936

877937
int
@@ -928,6 +988,8 @@ ble_ll_cs_init(void)
928988
cap->t_fcs_capability = 0x0100;
929989
cap->t_pm_capability = 0x0004;
930990
cap->tx_snr_capablity = 0x00;
991+
992+
ble_ll_cs_proc_set_chan_class(default_channel_classification);
931993
}
932994

933995
void

0 commit comments

Comments
 (0)