diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index 98b0d20723d..fc91d230b7a 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -3080,13 +3080,55 @@ static int common_init(void) return 0; } +static int le_set_event_mask(void) +{ + struct bt_hci_cp_le_set_event_mask *cp_mask; + struct net_buf *buf; + u64_t mask = 0; + + /* Set LE event mask */ + buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_EVENT_MASK, sizeof(*cp_mask)); + if (!buf) { + return -ENOBUFS; + } + + cp_mask = net_buf_add(buf, sizeof(*cp_mask)); + + mask |= BT_EVT_MASK_LE_ADVERTISING_REPORT; + + if (IS_ENABLED(CONFIG_BLUETOOTH_CONN)) { + mask |= BT_EVT_MASK_LE_CONN_COMPLETE; + mask |= BT_EVT_MASK_LE_CONN_UPDATE_COMPLETE; + mask |= BT_EVT_MASK_LE_REMOTE_FEAT_COMPLETE; + if (BT_FEAT_LE_CONN_PARAM_REQ_PROC(bt_dev.le.features)) { + mask |= BT_EVT_MASK_LE_CONN_PARAM_REQ; + } + } + + if (IS_ENABLED(CONFIG_BLUETOOTH_SMP) && + BT_FEAT_LE_ENCR(bt_dev.le.features)) { + mask |= BT_EVT_MASK_LE_LTK_REQUEST; + } + + /* + * If "LE Read Local P-256 Public Key" and "LE Generate DH Key" are + * supported we need to enable events generated by those commands. + */ + if ((bt_dev.supported_commands[34] & 0x02) && + (bt_dev.supported_commands[34] & 0x04)) { + mask |= BT_EVT_MASK_LE_P256_PUBLIC_KEY_COMPLETE; + mask |= BT_EVT_MASK_LE_GENERATE_DHKEY_COMPLETE; + } + + sys_put_le64(mask, cp_mask->events); + return bt_hci_cmd_send_sync(BT_HCI_OP_LE_SET_EVENT_MASK, buf, NULL); +} + static int le_init(void) { struct bt_hci_cp_write_le_host_supp *cp_le; - struct bt_hci_cp_le_set_event_mask *cp_mask; struct net_buf *buf; struct net_buf *rsp; - u64_t mask = 0; int err; /* For now we only support LE capable controllers */ @@ -3145,44 +3187,7 @@ static int le_init(void) net_buf_unref(rsp); } - /* Set LE event mask */ - buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_EVENT_MASK, sizeof(*cp_mask)); - if (!buf) { - return -ENOBUFS; - } - - cp_mask = net_buf_add(buf, sizeof(*cp_mask)); - - mask |= BT_EVT_MASK_LE_ADVERTISING_REPORT; - - if (IS_ENABLED(CONFIG_BLUETOOTH_CONN)) { - mask |= BT_EVT_MASK_LE_CONN_COMPLETE; - mask |= BT_EVT_MASK_LE_CONN_UPDATE_COMPLETE; - mask |= BT_EVT_MASK_LE_REMOTE_FEAT_COMPLETE; - mask |= BT_EVT_MASK_LE_CONN_PARAM_REQ; - } - - if (IS_ENABLED(CONFIG_BLUETOOTH_SMP)) { - mask |= BT_EVT_MASK_LE_LTK_REQUEST; - } - - /* - * If "LE Read Local P-256 Public Key" and "LE Generate DH Key" are - * supported we need to enable events generated by those commands. - */ - if ((bt_dev.supported_commands[34] & 0x02) && - (bt_dev.supported_commands[34] & 0x04)) { - mask |= BT_EVT_MASK_LE_P256_PUBLIC_KEY_COMPLETE; - mask |= BT_EVT_MASK_LE_GENERATE_DHKEY_COMPLETE; - } - - sys_put_le64(mask, cp_mask->events); - err = bt_hci_cmd_send_sync(BT_HCI_OP_LE_SET_EVENT_MASK, buf, NULL); - if (err) { - return err; - } - - return 0; + return le_set_event_mask(); } #if defined(CONFIG_BLUETOOTH_BREDR) @@ -3408,6 +3413,9 @@ static int set_event_mask(void) ev = net_buf_add(buf, sizeof(*ev)); if (IS_ENABLED(CONFIG_BLUETOOTH_BREDR)) { + /* Since we require LE support, we can count on a + * Bluetooth 4.0 feature set + */ mask |= BT_EVT_MASK_INQUIRY_COMPLETE; mask |= BT_EVT_MASK_CONN_COMPLETE; mask |= BT_EVT_MASK_CONN_REQUEST;