Skip to content

Commit addc7d1

Browse files
committed
nimble/ll: Add LE CS Set Channel Classification command
1 parent 57f0990 commit addc7d1

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)
@@ -858,10 +864,64 @@ ble_ll_cs_hci_remove_config(const uint8_t *cmdbuf, uint8_t cmdlen)
858864
return BLE_ERR_SUCCESS;
859865
}
860866

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

867927
int
@@ -918,6 +978,8 @@ ble_ll_cs_init(void)
918978
cap->t_fcs_capability = 0x0100;
919979
cap->t_pm_capability = 0x0004;
920980
cap->tx_snr_capablity = 0x00;
981+
982+
ble_ll_cs_proc_set_chan_class(default_channel_classification);
921983
}
922984

923985
void

0 commit comments

Comments
 (0)