BLE Host - Reset on hardware error.
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/ef6ef4c5 Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/ef6ef4c5 Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/ef6ef4c5 Branch: refs/heads/develop Commit: ef6ef4c50980df5a0d28b9bdff51118d6a41c8c9 Parents: 2444d8f Author: Christopher Collins <[email protected]> Authored: Wed Aug 3 13:30:54 2016 -0700 Committer: Christopher Collins <[email protected]> Committed: Wed Aug 3 19:54:16 2016 -0700 ---------------------------------------------------------------------- net/nimble/host/include/host/ble_hs.h | 4 ++++ net/nimble/host/src/ble_hs.c | 6 ++++++ net/nimble/host/src/ble_hs_priv.h | 1 + net/nimble/host/src/host_hci.c | 17 +++++++++++++++++ net/nimble/include/nimble/hci_common.h | 3 +++ 5 files changed, 31 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ef6ef4c5/net/nimble/host/include/host/ble_hs.h ---------------------------------------------------------------------- diff --git a/net/nimble/host/include/host/ble_hs.h b/net/nimble/host/include/host/ble_hs.h index faeaf14..4a707af 100644 --- a/net/nimble/host/include/host/ble_hs.h +++ b/net/nimble/host/include/host/ble_hs.h @@ -80,6 +80,10 @@ struct os_event; #define BLE_HS_ERR_SM_PEER_BASE 0x500 /* 1280 */ #define BLE_HS_SM_PEER_ERR(x) ((x) ? BLE_HS_ERR_SM_PEER_BASE + (x) : 0) +/* Note: A hardware error of 0 is not success. */ +#define BLE_HS_ERR_HW_BASE 0x600 /* 1536 */ +#define BLE_HS_HW_ERR(x) (BLE_HS_ERR_HW_BASE + (x)) + /* Defines the IO capabilities for the local device. */ #define BLE_HS_IO_DISPLAY_ONLY 0x00 #define BLE_HS_IO_DISPLAY_YESNO 0x01 http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ef6ef4c5/net/nimble/host/src/ble_hs.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/ble_hs.c b/net/nimble/host/src/ble_hs.c index 6e8a59f..95befc0 100644 --- a/net/nimble/host/src/ble_hs.c +++ b/net/nimble/host/src/ble_hs.c @@ -443,6 +443,12 @@ ble_hs_sched_reset(int reason) ble_hs_event_enqueue(&ble_hs_event_reset); } +void +ble_hs_hw_error(uint8_t hw_code) +{ + ble_hs_sched_reset(BLE_HS_HW_ERR(hw_code)); +} + /** * Synchronizes the host with the controller by sending a sequence of HCI * commands. This function must be called before any other host functionality http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ef6ef4c5/net/nimble/host/src/ble_hs_priv.h ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/ble_hs_priv.h b/net/nimble/host/src/ble_hs_priv.h index 9e788dd..d8b5e82 100644 --- a/net/nimble/host/src/ble_hs_priv.h +++ b/net/nimble/host/src/ble_hs_priv.h @@ -102,6 +102,7 @@ int ble_hs_is_parent_task(void); void ble_hs_lock(void); void ble_hs_unlock(void); void ble_hs_sched_reset(int reason); +void ble_hs_hw_error(uint8_t hw_code); void ble_hs_heartbeat_sched(int32_t ticks); void ble_hs_notifications_sched(void); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ef6ef4c5/net/nimble/host/src/host_hci.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/host_hci.c b/net/nimble/host/src/host_hci.c index ed5dd6a..b9bdaf9 100644 --- a/net/nimble/host/src/host_hci.c +++ b/net/nimble/host/src/host_hci.c @@ -35,6 +35,7 @@ _Static_assert(sizeof (struct hci_data_hdr) == BLE_HCI_DATA_HDR_SZ, typedef int host_hci_event_fn(uint8_t event_code, uint8_t *data, int len); static host_hci_event_fn host_hci_rx_disconn_complete; static host_hci_event_fn host_hci_rx_encrypt_change; +static host_hci_event_fn host_hci_rx_hw_error; static host_hci_event_fn host_hci_rx_num_completed_pkts; static host_hci_event_fn host_hci_rx_enc_key_refresh; static host_hci_event_fn host_hci_rx_le_meta; @@ -70,6 +71,7 @@ struct host_hci_event_dispatch_entry { static const struct host_hci_event_dispatch_entry host_hci_event_dispatch[] = { { BLE_HCI_EVCODE_DISCONN_CMP, host_hci_rx_disconn_complete }, { BLE_HCI_EVCODE_ENCRYPT_CHG, host_hci_rx_encrypt_change }, + { BLE_HCI_EVCODE_HW_ERROR, host_hci_rx_hw_error }, { BLE_HCI_EVCODE_NUM_COMP_PKTS, host_hci_rx_num_completed_pkts }, { BLE_HCI_EVCODE_ENC_KEY_REFRESH, host_hci_rx_enc_key_refresh }, { BLE_HCI_EVCODE_LE_META, host_hci_rx_le_meta }, @@ -185,6 +187,21 @@ host_hci_rx_encrypt_change(uint8_t event_code, uint8_t *data, int len) } static int +host_hci_rx_hw_error(uint8_t event_code, uint8_t *data, int len) +{ + uint8_t hw_code; + + if (len < BLE_HCI_EVENT_HW_ERROR_LEN) { + return BLE_HS_ECONTROLLER; + } + + hw_code = data[0]; + ble_hs_hw_error(hw_code); + + return 0; +} + +static int host_hci_rx_enc_key_refresh(uint8_t event_code, uint8_t *data, int len) { struct hci_encrypt_key_refresh evt; http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ef6ef4c5/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 3b44b0e..f094cc7 100644 --- a/net/nimble/include/nimble/hci_common.h +++ b/net/nimble/include/nimble/hci_common.h @@ -480,6 +480,9 @@ /* Event encryption change (code=0x08) */ #define BLE_HCI_EVENT_ENCRYPT_CHG_LEN (4) +/* Event hardware error (code=0x10) */ +#define BLE_HCI_EVENT_HW_ERROR_LEN (1) + /* Event key refresh complete (code=0x30) */ #define BLE_HCI_EVENT_ENC_KEY_REFRESH_LEN (3)
