Bluetooth: controller: Implement event masks
HCI event masking allows the host to choose which events are reported to it to avoid interruption and excessive traffic. This patch implements masking to drop any non-enabled events as specified by the host. Jira: ZEP-1769 Change-Id: If09d4aa22b0da8f743fc42a3b0db3f369daaff96 Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
This commit is contained in:
parent
27e83660ff
commit
9a9699ebdb
2 changed files with 105 additions and 2 deletions
|
@ -1269,6 +1269,46 @@ struct bt_hci_ev_le_direct_adv_report {
|
|||
struct bt_hci_ev_le_direct_adv_info direct_adv_info[0];
|
||||
} __packed;
|
||||
|
||||
/* Event mask bits */
|
||||
|
||||
#define BT_EVT_BIT_INQUIRY_COMPLETE 0
|
||||
#define BT_EVT_BIT_CONN_COMPLETE 2
|
||||
#define BT_EVT_BIT_CONN_REQUEST 3
|
||||
#define BT_EVT_BIT_DISCONN_COMPLETE 4
|
||||
#define BT_EVT_BIT_AUTH_COMPLETE 5
|
||||
#define BT_EVT_BIT_REMOTE_NAME_REQ_COMPLETE 6
|
||||
#define BT_EVT_BIT_ENCRYPT_CHANGE 7
|
||||
#define BT_EVT_BIT_REMOTE_FEATURES 10
|
||||
#define BT_EVT_BIT_REMOTE_VERSION_INFO 11
|
||||
#define BT_EVT_BIT_ROLE_CHANGE 17
|
||||
#define BT_EVT_BIT_PIN_CODE_REQ 21
|
||||
#define BT_EVT_BIT_LINK_KEY_REQ 22
|
||||
#define BT_EVT_BIT_LINK_KEY_NOTIFY 23
|
||||
#define BT_EVT_BIT_INQUIRY_RESULT_WITH_RSSI 33
|
||||
#define BT_EVT_BIT_REMOTE_EXT_FEATURES 34
|
||||
#define BT_EVT_BIT_SYNC_CONN_COMPLETE 43
|
||||
#define BT_EVT_BIT_EXTENDED_INQUIRY_RESULT 46
|
||||
#define BT_EVT_BIT_ENCRYPT_KEY_REFRESH_COMPLETE 47
|
||||
#define BT_EVT_BIT_IO_CAPA_REQ 48
|
||||
#define BT_EVT_BIT_IO_CAPA_RESP 49
|
||||
#define BT_EVT_BIT_USER_CONFIRM_REQ 50
|
||||
#define BT_EVT_BIT_USER_PASSKEY_REQ 51
|
||||
#define BT_EVT_BIT_SSP_COMPLETE 53
|
||||
#define BT_EVT_BIT_USER_PASSKEY_NOTIFY 58
|
||||
#define BT_EVT_BIT_LE_META_EVENT 61
|
||||
|
||||
#define BT_EVT_BIT_LE_CONN_COMPLETE 0
|
||||
#define BT_EVT_BIT_LE_ADVERTISING_REPORT 1
|
||||
#define BT_EVT_BIT_LE_CONN_UPDATE_COMPLETE 2
|
||||
#define BT_EVT_BIT_LE_REMOTE_FEAT_COMPLETE 3
|
||||
#define BT_EVT_BIT_LE_LTK_REQUEST 4
|
||||
#define BT_EVT_BIT_LE_CONN_PARAM_REQ 5
|
||||
#define BT_EVT_BIT_LE_DATA_LEN_CHANGE 6
|
||||
#define BT_EVT_BIT_LE_P256_PUBLIC_KEY_COMPLETE 7
|
||||
#define BT_EVT_BIT_LE_GENERATE_DHKEY_COMPLETE 8
|
||||
#define BT_EVT_BIT_LE_ENH_CONN_COMPLETE 9
|
||||
#define BT_EVT_BIT_LE_DIRECT_ADV_REPORT 10
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -46,6 +46,13 @@ static int32_t dup_count;
|
|||
static uint32_t dup_curr;
|
||||
#endif
|
||||
|
||||
#define BIT64(n) (1ULL << (n))
|
||||
#define DEFAULT_EVENT_MASK 0x1fffffffffff
|
||||
#define DEFAULT_LE_EVENT_MASK 0x1f
|
||||
|
||||
static uint64_t event_mask = DEFAULT_EVENT_MASK;
|
||||
static uint64_t le_event_mask = DEFAULT_LE_EVENT_MASK;
|
||||
|
||||
static void evt_create(struct net_buf *buf, uint8_t evt, uint8_t len)
|
||||
{
|
||||
struct bt_hci_evt_hdr *hdr;
|
||||
|
@ -140,9 +147,10 @@ static int link_control_cmd_handle(uint8_t ocf, struct net_buf *cmd,
|
|||
|
||||
static void set_event_mask(struct net_buf *buf, struct net_buf **evt)
|
||||
{
|
||||
struct bt_hci_cp_set_event_mask *cmd = (void *)buf->data;
|
||||
struct bt_hci_evt_cc_status *ccst;
|
||||
|
||||
/** TODO */
|
||||
event_mask = sys_get_le64(cmd->events);
|
||||
|
||||
ccst = cmd_complete(evt, sizeof(*ccst));
|
||||
ccst->status = 0x00;
|
||||
|
@ -157,6 +165,9 @@ static void reset(struct net_buf *buf, struct net_buf **evt)
|
|||
#if CONFIG_BLUETOOTH_CONTROLLER_DUP_FILTER_LEN > 0
|
||||
dup_count = -1;
|
||||
#endif
|
||||
/* reset event masks */
|
||||
event_mask = DEFAULT_EVENT_MASK;
|
||||
le_event_mask = DEFAULT_LE_EVENT_MASK;
|
||||
|
||||
ccst = cmd_complete(evt, sizeof(*ccst));
|
||||
ccst->status = 0x00;
|
||||
|
@ -295,9 +306,10 @@ static int info_cmd_handle(uint8_t ocf, struct net_buf *cmd,
|
|||
|
||||
static void le_set_event_mask(struct net_buf *buf, struct net_buf **evt)
|
||||
{
|
||||
struct bt_hci_cp_set_event_mask *cmd = (void *)buf->data;
|
||||
struct bt_hci_evt_cc_status *ccst;
|
||||
|
||||
/** TODO */
|
||||
le_event_mask = sys_get_le64(cmd->events);
|
||||
|
||||
ccst = cmd_complete(evt, sizeof(*ccst));
|
||||
ccst->status = 0x00;
|
||||
|
@ -999,6 +1011,11 @@ static void le_advertising_report(struct pdu_data *pdu_data, uint8_t *b,
|
|||
uint8_t info_len;
|
||||
int i;
|
||||
|
||||
if (!(event_mask & BIT64(BT_EVT_BIT_LE_META_EVENT)) ||
|
||||
!(le_event_mask & BIT64(BT_EVT_BIT_LE_ADVERTISING_REPORT))) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if CONFIG_BLUETOOTH_CONTROLLER_DUP_FILTER_LEN > 0
|
||||
/* check for duplicate filtering */
|
||||
if (dup_count >= 0) {
|
||||
|
@ -1072,6 +1089,11 @@ static void le_conn_complete(struct pdu_data *pdu_data, uint16_t handle,
|
|||
struct bt_hci_evt_le_conn_complete *sep;
|
||||
struct radio_le_conn_cmplt *radio_cc;
|
||||
|
||||
if (!(event_mask & BIT64(BT_EVT_BIT_LE_META_EVENT)) ||
|
||||
!(le_event_mask & BIT64(BT_EVT_BIT_LE_CONN_COMPLETE))) {
|
||||
return;
|
||||
}
|
||||
|
||||
radio_cc = (struct radio_le_conn_cmplt *) (pdu_data->payload.lldata);
|
||||
|
||||
sep = meta_evt(buf, BT_HCI_EVT_LE_CONN_COMPLETE, sizeof(*sep));
|
||||
|
@ -1092,6 +1114,10 @@ static void disconn_complete(struct pdu_data *pdu_data, uint16_t handle,
|
|||
{
|
||||
struct bt_hci_evt_disconn_complete *ep;
|
||||
|
||||
if (!(event_mask & BIT64(BT_EVT_BIT_DISCONN_COMPLETE))) {
|
||||
return;
|
||||
}
|
||||
|
||||
evt_create(buf, BT_HCI_EVT_DISCONN_COMPLETE, sizeof(*ep));
|
||||
ep = net_buf_add(buf, sizeof(*ep));
|
||||
|
||||
|
@ -1106,6 +1132,11 @@ static void le_conn_update_complete(struct pdu_data *pdu_data, uint16_t handle,
|
|||
struct bt_hci_evt_le_conn_update_complete *sep;
|
||||
struct radio_le_conn_update_cmplt *radio_cu;
|
||||
|
||||
if (!(event_mask & BIT64(BT_EVT_BIT_LE_META_EVENT)) ||
|
||||
!(le_event_mask & BIT64(BT_EVT_BIT_LE_CONN_UPDATE_COMPLETE))) {
|
||||
return;
|
||||
}
|
||||
|
||||
radio_cu = (struct radio_le_conn_update_cmplt *)
|
||||
(pdu_data->payload.lldata);
|
||||
|
||||
|
@ -1123,6 +1154,10 @@ static void enc_refresh_complete(struct pdu_data *pdu_data, uint16_t handle,
|
|||
{
|
||||
struct bt_hci_evt_encrypt_key_refresh_complete *ep;
|
||||
|
||||
if (!(event_mask & BIT64(BT_EVT_BIT_ENCRYPT_KEY_REFRESH_COMPLETE))) {
|
||||
return;
|
||||
}
|
||||
|
||||
evt_create(buf, BT_HCI_EVT_ENCRYPT_KEY_REFRESH_COMPLETE, sizeof(*ep));
|
||||
ep = net_buf_add(buf, sizeof(*ep));
|
||||
|
||||
|
@ -1214,6 +1249,11 @@ static void le_ltk_request(struct pdu_data *pdu_data, uint16_t handle,
|
|||
{
|
||||
struct bt_hci_evt_le_ltk_request *sep;
|
||||
|
||||
if (!(event_mask & BIT64(BT_EVT_BIT_LE_META_EVENT)) ||
|
||||
!(le_event_mask & BIT64(BT_EVT_BIT_LE_LTK_REQUEST))) {
|
||||
return;
|
||||
}
|
||||
|
||||
sep = meta_evt(buf, BT_HCI_EVT_LE_LTK_REQUEST, sizeof(*sep));
|
||||
|
||||
sep->handle = sys_cpu_to_le16(handle);
|
||||
|
@ -1228,6 +1268,10 @@ static void encrypt_change(uint8_t err, uint16_t handle,
|
|||
{
|
||||
struct bt_hci_evt_encrypt_change *ep;
|
||||
|
||||
if (!(event_mask & BIT64(BT_EVT_BIT_ENCRYPT_CHANGE))) {
|
||||
return;
|
||||
}
|
||||
|
||||
evt_create(buf, BT_HCI_EVT_ENCRYPT_CHANGE, sizeof(*ep));
|
||||
ep = net_buf_add(buf, sizeof(*ep));
|
||||
|
||||
|
@ -1241,6 +1285,11 @@ static void le_remote_feat_complete(uint8_t status, struct pdu_data *pdu_data,
|
|||
{
|
||||
struct bt_hci_ev_le_remote_feat_complete *sep;
|
||||
|
||||
if (!(event_mask & BIT64(BT_EVT_BIT_LE_META_EVENT)) ||
|
||||
!(le_event_mask & BIT64(BT_EVT_BIT_LE_REMOTE_FEAT_COMPLETE))) {
|
||||
return;
|
||||
}
|
||||
|
||||
sep = meta_evt(buf, BT_HCI_EV_LE_REMOTE_FEAT_COMPLETE, sizeof(*sep));
|
||||
|
||||
sep->status = status;
|
||||
|
@ -1276,6 +1325,10 @@ static void remote_version_info(struct pdu_data *pdu_data, uint16_t handle,
|
|||
{
|
||||
struct bt_hci_evt_remote_version_info *ep;
|
||||
|
||||
if (!(event_mask & BIT64(BT_EVT_BIT_REMOTE_VERSION_INFO))) {
|
||||
return;
|
||||
}
|
||||
|
||||
evt_create(buf, BT_HCI_EVT_REMOTE_VERSION_INFO, sizeof(*ep));
|
||||
ep = net_buf_add(buf, sizeof(*ep));
|
||||
|
||||
|
@ -1294,6 +1347,11 @@ static void le_conn_param_req(struct pdu_data *pdu_data, uint16_t handle,
|
|||
{
|
||||
struct bt_hci_evt_le_conn_param_req *sep;
|
||||
|
||||
if (!(event_mask & BIT64(BT_EVT_BIT_LE_META_EVENT)) ||
|
||||
!(le_event_mask & BIT64(BT_EVT_BIT_LE_CONN_PARAM_REQ))) {
|
||||
return;
|
||||
}
|
||||
|
||||
sep = meta_evt(buf, BT_HCI_EVT_LE_CONN_PARAM_REQ, sizeof(*sep));
|
||||
|
||||
sep->handle = sys_cpu_to_le16(handle);
|
||||
|
@ -1310,6 +1368,11 @@ static void le_data_len_change(struct pdu_data *pdu_data, uint16_t handle,
|
|||
{
|
||||
struct bt_hci_evt_le_data_len_change *sep;
|
||||
|
||||
if (!(event_mask & BIT64(BT_EVT_BIT_LE_META_EVENT)) ||
|
||||
!(le_event_mask & BIT64(BT_EVT_BIT_LE_DATA_LEN_CHANGE))) {
|
||||
return;
|
||||
}
|
||||
|
||||
sep = meta_evt(buf, BT_HCI_EVT_LE_DATA_LEN_CHANGE, sizeof(*sep));
|
||||
|
||||
sep->handle = sys_cpu_to_le16(handle);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue