Skip to content

Commit

Permalink
nimble/host: Read supported HCI commands from controller
Browse files Browse the repository at this point in the history
This patch adds a new function, ble_hs_startup_read_sup_cmd_tx(), which
reads the list of supported HCI commands from the controller on HCI
startup. This is used to determine whether a HCI Set Event
Mask Page 2 command should be sent to the controller.
  • Loading branch information
donatieng committed Dec 21, 2023
1 parent a2c7937 commit 2d03e26
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
12 changes: 12 additions & 0 deletions nimble/host/src/ble_hs_hci.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ static uint32_t ble_hs_hci_sup_feat;

static uint8_t ble_hs_hci_version;

static struct ble_hs_hci_sup_cmd ble_hs_hci_sup_cmd;

#if MYNEWT_VAL(BLE_CONTROLLER)
#define BLE_HS_HCI_FRAG_DATABUF_SIZE \
(BLE_ACL_MAX_PKT_SIZE + \
Expand Down Expand Up @@ -632,6 +634,16 @@ ble_hs_hci_get_hci_version(void)
return ble_hs_hci_version;
}

void
ble_hs_hci_set_hci_supported_cmd(struct ble_hs_hci_sup_cmd sup_cmd) {
ble_hs_hci_sup_cmd = sup_cmd;
}

struct ble_hs_hci_sup_cmd
ble_hs_hci_get_hci_supported_cmd(void) {
return ble_hs_hci_sup_cmd;
}

void
ble_hs_hci_init(void)
{
Expand Down
6 changes: 6 additions & 0 deletions nimble/host/src/ble_hs_hci_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ struct hci_periodic_adv_params
#endif
#endif

struct ble_hs_hci_sup_cmd {
unsigned event_mask2:1; /** Indicates whether the controller supports the set event mask page 2 command */
};

extern uint16_t ble_hs_hci_avail_pkts;

/* This function is not waiting for command status/complete HCI events */
Expand All @@ -91,6 +95,8 @@ void ble_hs_hci_set_le_supported_feat(uint32_t feat);
uint32_t ble_hs_hci_get_le_supported_feat(void);
void ble_hs_hci_set_hci_version(uint8_t hci_version);
uint8_t ble_hs_hci_get_hci_version(void);
void ble_hs_hci_set_hci_supported_cmd(struct ble_hs_hci_sup_cmd sup_cmd);
struct ble_hs_hci_sup_cmd ble_hs_hci_get_hci_supported_cmd(void);

#if MYNEWT_VAL(BLE_HS_PHONY_HCI_ACKS)
typedef int ble_hs_hci_phony_ack_fn(uint8_t *ack, int ack_buf_len);
Expand Down
31 changes: 29 additions & 2 deletions nimble/host/src/ble_hs_startup.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,27 @@ ble_hs_startup_read_local_ver_tx(void)
return 0;
}

static int
ble_hs_startup_read_sup_cmd_tx(void)
{
struct ble_hci_ip_rd_loc_supp_cmd_rp rsp;
struct ble_hs_hci_sup_cmd sup_cmd;
int rc;

rc = ble_hs_hci_cmd_tx(BLE_HCI_OP(BLE_HCI_OGF_INFO_PARAMS,
BLE_HCI_OCF_IP_RD_LOC_SUPP_CMD),
NULL, 0, &rsp, sizeof(rsp));
if (rc != 0) {
return rc;
}

/* Only check support for Set Event ­Mask ­Page ­2 command */
sup_cmd.event_mask2 = (rsp.commands[22] & 0x02) != 0;
ble_hs_hci_set_hci_supported_cmd(sup_cmd);

return 0;
}

static int
ble_hs_startup_le_read_sup_f_tx(void)
{
Expand Down Expand Up @@ -289,9 +310,11 @@ ble_hs_startup_set_evmask_tx(void)
struct ble_hci_cb_set_event_mask_cp cmd;
struct ble_hci_cb_set_event_mask2_cp cmd2;
uint8_t version;
struct ble_hs_hci_sup_cmd sup_cmd;
int rc;

version = ble_hs_hci_get_hci_version();
sup_cmd = ble_hs_hci_get_hci_supported_cmd();

/**
* Enable the following events:
Expand All @@ -311,7 +334,7 @@ ble_hs_startup_set_evmask_tx(void)
return rc;
}

if (version >= BLE_HCI_VER_BCS_4_1) {
if ((version >= BLE_HCI_VER_BCS_4_1) && sup_cmd.event_mask2 ) {
/**
* Enable the following events:
* 0x0000000000800000 Authenticated Payload Timeout Event
Expand Down Expand Up @@ -352,7 +375,11 @@ ble_hs_startup_go(void)
return rc;
}

/* XXX: Read local supported commands. */
/* Read local supported commands. */
rc = ble_hs_startup_read_sup_cmd_tx();
if (rc != 0) {
return rc;
}

/* we need to check this only if using external controller */
#if !MYNEWT_VAL(BLE_CONTROLLER)
Expand Down

0 comments on commit 2d03e26

Please sign in to comment.