Skip to content

Commit 51e365a

Browse files
committed
nimble/ll: Add LE CS Set Channel Classification command
1 parent c7c1458 commit 51e365a

File tree

1 file changed

+63
-1
lines changed

1 file changed

+63
-1
lines changed

nimble/controller/src/ble_ll_cs.c

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ static const uint8_t t_ip1[] = {10, 20, 30, 40, 50, 60, 80, 145};
6969
static const uint8_t t_ip2[] = {10, 20, 30, 40, 50, 60, 80, 145};
7070
static const uint8_t t_fcs[] = {15, 20, 30, 40, 50, 60, 80, 100, 120, 150};
7171
static const uint8_t t_pm[] = {10, 20, 40};
72+
static const uint8_t default_channel_classification[10] = {
73+
0xFC, 0xFF, 0x7F, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x1F
74+
};
75+
static uint8_t g_ble_ll_cs_chan_class[10];
76+
static uint8_t g_ble_ll_cs_chan_count = 0;
77+
static uint8_t g_ble_ll_cs_chan_indices[72];
7278

7379
void ble_ll_ctrl_rej_ext_ind_make(uint8_t rej_opcode, uint8_t err, uint8_t *ctrdata);
7480

@@ -1120,10 +1126,64 @@ ble_ll_cs_hci_remove_config(const uint8_t *cmdbuf, uint8_t cmdlen)
11201126
return BLE_ERR_SUCCESS;
11211127
}
11221128

1129+
static int
1130+
ble_ll_cs_proc_set_chan_class(const uint8_t *channel_classification)
1131+
{
1132+
uint8_t i, j, next_id, byte;
1133+
1134+
/* TODO:
1135+
* 1. The interval between two successive commands sent shall be at least 1 second.
1136+
* Otherwise, the Controller shall return the error code Command Disallowed (0x0C).
1137+
*
1138+
* 2. Combine the Host chan_class with local chan_class capabilities?
1139+
*/
1140+
1141+
if (channel_classification[0] & 0b00000011 ||
1142+
channel_classification[2] & 0b10000000 ||
1143+
channel_classification[3] & 0b00000011 ||
1144+
channel_classification[9] & 0b11100000) {
1145+
/* Channels 0, 1, 23, 24, 25, 77, 78, and the bit 79 (non-channel)
1146+
* are RFU. At least 15 channels shall be enabled.
1147+
*/
1148+
return -1;
1149+
}
1150+
1151+
for (i = 0, j = 0; i < ARRAY_SIZE(g_ble_ll_cs_chan_class); ++i) {
1152+
byte = channel_classification[i];
1153+
next_id = i * 8;
1154+
1155+
while (byte) {
1156+
if (byte & 1) {
1157+
g_ble_ll_cs_chan_indices[j++] = next_id;
1158+
}
1159+
++next_id;
1160+
byte >>= 1;
1161+
}
1162+
}
1163+
1164+
g_ble_ll_cs_chan_count = j;
1165+
if (g_ble_ll_cs_chan_count < 15) {
1166+
return -1;
1167+
}
1168+
1169+
memcpy(g_ble_ll_cs_chan_class, channel_classification,
1170+
sizeof(g_ble_ll_cs_chan_class));
1171+
1172+
return 0;
1173+
}
1174+
11231175
int
11241176
ble_ll_cs_hci_set_chan_class(const uint8_t *cmdbuf, uint8_t cmdlen)
11251177
{
1126-
return BLE_ERR_UNSUPPORTED;
1178+
int rc;
1179+
const struct ble_hci_le_cs_set_chan_class_cp *cmd = (const void *)cmdbuf;
1180+
1181+
rc = ble_ll_cs_proc_set_chan_class(cmd->channel_classification);
1182+
if (rc) {
1183+
return BLE_ERR_INV_HCI_CMD_PARMS;
1184+
}
1185+
1186+
return BLE_ERR_SUCCESS;
11271187
}
11281188

11291189
int
@@ -1180,6 +1240,8 @@ ble_ll_cs_init(void)
11801240
cap->t_fcs_capability = 1 << T_FCS_CAP_ID_150US;
11811241
cap->t_pm_capability = 1 << T_PM_CAP_ID_40US;
11821242
cap->tx_snr_capablity = 0x00;
1243+
1244+
ble_ll_cs_proc_set_chan_class(default_channel_classification);
11831245
}
11841246

11851247
void

0 commit comments

Comments
 (0)