BLE Host - Read BD_ADDR on startup.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/93c01c53 Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/93c01c53 Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/93c01c53 Branch: refs/heads/develop Commit: 93c01c53da4e79430ed2bb64d89a2ab37a3fe1cc Parents: 1f8bbd8 Author: Christopher Collins <[email protected]> Authored: Mon Aug 1 13:32:25 2016 -0700 Committer: Christopher Collins <[email protected]> Committed: Wed Aug 3 19:54:15 2016 -0700 ---------------------------------------------------------------------- net/nimble/host/include/host/host_hci.h | 1 + net/nimble/host/src/ble_hs_startup.c | 30 +++++++++++++++++++++++++--- net/nimble/host/src/host_hci_cmd.c | 14 +++++++++++++ net/nimble/include/nimble/hci_common.h | 3 +++ 4 files changed, 45 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/93c01c53/net/nimble/host/include/host/host_hci.h ---------------------------------------------------------------------- diff --git a/net/nimble/host/include/host/host_hci.h b/net/nimble/host/include/host/host_hci.h index f92c1a9..dbe626a 100644 --- a/net/nimble/host/include/host/host_hci.h +++ b/net/nimble/host/include/host/host_hci.h @@ -36,6 +36,7 @@ void host_hci_write_hdr(uint8_t ogf, uint8_t ocf, uint8_t len, void *buf); int host_hci_cmd_send(uint8_t ogf, uint8_t ocf, uint8_t len, const void *cmddata); int host_hci_cmd_send_buf(void *cmddata); +void host_hci_cmd_build_read_bd_addr(uint8_t *dst, int dst_len); void host_hci_cmd_build_set_event_mask(uint64_t event_mask, uint8_t *dst, int dst_len); void host_hci_cmd_build_set_event_mask2(uint64_t event_mask, uint8_t *dst, http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/93c01c53/net/nimble/host/src/ble_hs_startup.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/ble_hs_startup.c b/net/nimble/host/src/ble_hs_startup.c index 568f1ed..45fb5ce 100644 --- a/net/nimble/host/src/ble_hs_startup.c +++ b/net/nimble/host/src/ble_hs_startup.c @@ -78,6 +78,28 @@ ble_hs_startup_le_read_buf_sz_tx(void) } static int +ble_hs_startup_read_bd_addr(void) +{ + uint8_t ack_params[BLE_HCI_IP_RD_BD_ADDR_ACK_PARAM_LEN]; + uint8_t buf[BLE_HCI_CMD_HDR_LEN]; + uint8_t ack_params_len; + int rc; + + host_hci_cmd_build_read_bd_addr(buf, sizeof buf); + rc = ble_hci_cmd_tx(buf, ack_params, sizeof ack_params, &ack_params_len); + if (rc != 0) { + return rc; + } + + if (ack_params_len != sizeof ack_params) { + return BLE_HS_ECONTROLLER; + } + + ble_hs_id_set_pub(ack_params); + return 0; +} + +static int ble_hs_startup_le_set_evmask_tx(void) { uint8_t buf[BLE_HCI_CMD_HDR_LEN + BLE_HCI_SET_LE_EVENT_MASK_LEN]; @@ -224,10 +246,12 @@ ble_hs_startup_go(void) return rc; } - /* XXX: Read BD_ADDR. */ + rc = ble_hs_startup_read_bd_addr(); + if (rc != 0) { + return rc; + } - ble_hs_id_set_pub(g_dev_addr); ble_hs_pvcy_set_our_irk(NULL); - return rc; + return 0; } http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/93c01c53/net/nimble/host/src/host_hci_cmd.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/host_hci_cmd.c b/net/nimble/host/src/host_hci_cmd.c index 9dbb036..a3e021d 100644 --- a/net/nimble/host/src/host_hci_cmd.c +++ b/net/nimble/host/src/host_hci_cmd.c @@ -138,6 +138,20 @@ host_hci_le_cmd_send(uint16_t ocf, uint8_t len, void *cmddata) return rc; } +/** + * Read BD_ADDR + * + * OGF = 0x04 (Informational parameters) + * OCF = 0x0009 + */ +void +host_hci_cmd_build_read_bd_addr(uint8_t *dst, int dst_len) +{ + BLE_HS_DBG_ASSERT(dst_len >= BLE_HCI_CMD_HDR_LEN); + host_hci_write_hdr(BLE_HCI_OGF_INFO_PARAMS, BLE_HCI_OCF_IP_RD_BD_ADDR, + 0, dst); +} + static int host_hci_cmd_body_le_whitelist_chg(const uint8_t *addr, uint8_t addr_type, uint8_t *dst) http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/93c01c53/net/nimble/include/nimble/hci_common.h ---------------------------------------------------------------------- diff --git a/net/nimble/include/nimble/hci_common.h b/net/nimble/include/nimble/hci_common.h index d5c8743..3b44b0e 100644 --- a/net/nimble/include/nimble/hci_common.h +++ b/net/nimble/include/nimble/hci_common.h @@ -131,6 +131,9 @@ /* --- Set event mask (OGF 0x03, OCF 0x0001 --- */ #define BLE_HCI_SET_EVENT_MASK_LEN (8) +/* --- Read BD_ADDR (OGF 0x04, OCF 0x0009 --- */ +#define BLE_HCI_IP_RD_BD_ADDR_ACK_PARAM_LEN (6) + /* --- Read/Write authenticated payload timeout (ocf 0x007B/0x007C) */ #define BLE_HCI_RD_AUTH_PYLD_TMO_LEN (4) #define BLE_HCI_WR_AUTH_PYLD_TMO_LEN (2)
