aa
Dependents: Peripheral_1_serial_copy Peripheral_1_serial 151006_1st_Scenario_normal
Fork of nRF51822 by
btle/btle.cpp@127:bd1e1fe607e0, 2015-05-08 (annotated)
- Committer:
- rgrover1
- Date:
- Fri May 08 15:33:55 2015 +0100
- Revision:
- 127:bd1e1fe607e0
- Parent:
- 125:35e4f65364bc
- Child:
- 128:b7fc7925b5da
Synchronized with git rev 7b0a9a79
Author: Rohit Grover
add handling for initializeSecurity()
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Rohit Grover |
22:c6ee8136847e | 1 | /* mbed Microcontroller Library |
Rohit Grover |
22:c6ee8136847e | 2 | * Copyright (c) 2006-2013 ARM Limited |
Rohit Grover |
22:c6ee8136847e | 3 | * |
Rohit Grover |
22:c6ee8136847e | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Rohit Grover |
22:c6ee8136847e | 5 | * you may not use this file except in compliance with the License. |
Rohit Grover |
22:c6ee8136847e | 6 | * You may obtain a copy of the License at |
Rohit Grover |
22:c6ee8136847e | 7 | * |
Rohit Grover |
22:c6ee8136847e | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Rohit Grover |
22:c6ee8136847e | 9 | * |
Rohit Grover |
22:c6ee8136847e | 10 | * Unless required by applicable law or agreed to in writing, software |
Rohit Grover |
22:c6ee8136847e | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
Rohit Grover |
22:c6ee8136847e | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Rohit Grover |
22:c6ee8136847e | 13 | * See the License for the specific language governing permissions and |
Rohit Grover |
22:c6ee8136847e | 14 | * limitations under the License. |
Rohit Grover |
22:c6ee8136847e | 15 | */ |
Rohit Grover |
52:120bd37b9d0d | 16 | |
Rohit Grover |
22:c6ee8136847e | 17 | #include "common/common.h" |
Rohit Grover |
37:c29c330d942c | 18 | #include "nordic_common.h" |
Rohit Grover |
22:c6ee8136847e | 19 | |
Rohit Grover |
22:c6ee8136847e | 20 | #include "btle.h" |
Rohit Grover |
22:c6ee8136847e | 21 | |
Rohit Grover |
22:c6ee8136847e | 22 | #include "ble_stack_handler_types.h" |
Rohit Grover |
22:c6ee8136847e | 23 | #include "ble_flash.h" |
Rohit Grover |
22:c6ee8136847e | 24 | #include "ble_conn_params.h" |
Rohit Grover |
22:c6ee8136847e | 25 | |
Rohit Grover |
22:c6ee8136847e | 26 | #include "btle_gap.h" |
Rohit Grover |
22:c6ee8136847e | 27 | #include "btle_advertising.h" |
Rohit Grover |
22:c6ee8136847e | 28 | #include "custom/custom_helper.h" |
Rohit Grover |
22:c6ee8136847e | 29 | |
Rohit Grover |
22:c6ee8136847e | 30 | #include "softdevice_handler.h" |
Rohit Grover |
22:c6ee8136847e | 31 | #include "pstorage.h" |
Rohit Grover |
22:c6ee8136847e | 32 | |
Rohit Grover |
52:120bd37b9d0d | 33 | #include "GapEvents.h" |
Rohit Grover |
22:c6ee8136847e | 34 | #include "nRF51Gap.h" |
Rohit Grover |
22:c6ee8136847e | 35 | #include "nRF51GattServer.h" |
rgrover1 | 124:664d4257a9f8 | 36 | #include "device_manager.h" |
Rohit Grover |
22:c6ee8136847e | 37 | |
Rohit Grover |
56:a1071b629aa3 | 38 | #include "ble_hci.h" |
Rohit Grover |
56:a1071b629aa3 | 39 | |
Rohit Grover |
56:a1071b629aa3 | 40 | extern "C" void assert_nrf_callback(uint16_t line_num, const uint8_t *p_file_name); |
Rohit Grover |
56:a1071b629aa3 | 41 | void app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t *p_file_name); |
Rohit Grover |
22:c6ee8136847e | 42 | |
Rohit Grover |
22:c6ee8136847e | 43 | static void btle_handler(ble_evt_t *p_ble_evt); |
Rohit Grover |
22:c6ee8136847e | 44 | |
rgrover1 | 125:35e4f65364bc | 45 | ret_code_t dm_handler(dm_handle_t const *p_handle, dm_event_t const *p_event, ret_code_t event_result); |
rgrover1 | 125:35e4f65364bc | 46 | |
Rohit Grover |
22:c6ee8136847e | 47 | static void sys_evt_dispatch(uint32_t sys_evt) |
Rohit Grover |
22:c6ee8136847e | 48 | { |
Rohit Grover |
22:c6ee8136847e | 49 | pstorage_sys_event_handler(sys_evt); |
Rohit Grover |
22:c6ee8136847e | 50 | } |
Rohit Grover |
22:c6ee8136847e | 51 | |
Rohit Grover |
22:c6ee8136847e | 52 | error_t btle_init(void) |
Rohit Grover |
22:c6ee8136847e | 53 | { |
rgrover1 | 94:2bac1b3c5cfc | 54 | #if defined(TARGET_DELTA_DFCM_NNN40) || defined(TARGET_HRM1017) |
rgrover1 | 112:737b08b3b995 | 55 | SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_RC_250_PPM_4000MS_CALIBRATION, NULL); |
ytsuboi | 61:d0158c65d0d7 | 56 | #else |
rgrover1 | 112:737b08b3b995 | 57 | SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, NULL); |
ytsuboi | 61:d0158c65d0d7 | 58 | #endif |
Rohit Grover |
56:a1071b629aa3 | 59 | |
Rohit Grover |
56:a1071b629aa3 | 60 | // Enable BLE stack |
Rohit Grover |
56:a1071b629aa3 | 61 | /** |
Rohit Grover |
56:a1071b629aa3 | 62 | * Using this call, the application can select whether to include the |
Rohit Grover |
56:a1071b629aa3 | 63 | * Service Changed characteristic in the GATT Server. The default in all |
Rohit Grover |
56:a1071b629aa3 | 64 | * previous releases has been to include the Service Changed characteristic, |
Rohit Grover |
56:a1071b629aa3 | 65 | * but this affects how GATT clients behave. Specifically, it requires |
Rohit Grover |
56:a1071b629aa3 | 66 | * clients to subscribe to this attribute and not to cache attribute handles |
Rohit Grover |
56:a1071b629aa3 | 67 | * between connections unless the devices are bonded. If the application |
Rohit Grover |
56:a1071b629aa3 | 68 | * does not need to change the structure of the GATT server attributes at |
Rohit Grover |
56:a1071b629aa3 | 69 | * runtime this adds unnecessary complexity to the interaction with peer |
Rohit Grover |
56:a1071b629aa3 | 70 | * clients. If the SoftDevice is enabled with the Service Changed |
Rohit Grover |
56:a1071b629aa3 | 71 | * Characteristics turned off, then clients are allowed to cache attribute |
Rohit Grover |
56:a1071b629aa3 | 72 | * handles making applications simpler on both sides. |
Rohit Grover |
56:a1071b629aa3 | 73 | */ |
Rohit Grover |
68:936d81c963fe | 74 | static const bool IS_SRVC_CHANGED_CHARACT_PRESENT = true; |
Rohit Grover |
56:a1071b629aa3 | 75 | ble_enable_params_t enableParams = { |
Rohit Grover |
56:a1071b629aa3 | 76 | .gatts_enable_params = { |
Rohit Grover |
56:a1071b629aa3 | 77 | .service_changed = IS_SRVC_CHANGED_CHARACT_PRESENT |
Rohit Grover |
56:a1071b629aa3 | 78 | } |
Rohit Grover |
56:a1071b629aa3 | 79 | }; |
Rohit Grover |
56:a1071b629aa3 | 80 | if (sd_ble_enable(&enableParams) != NRF_SUCCESS) { |
Rohit Grover |
56:a1071b629aa3 | 81 | return ERROR_INVALID_PARAM; |
Rohit Grover |
56:a1071b629aa3 | 82 | } |
Rohit Grover |
56:a1071b629aa3 | 83 | |
Rohit Grover |
56:a1071b629aa3 | 84 | ble_gap_addr_t addr; |
Rohit Grover |
56:a1071b629aa3 | 85 | if (sd_ble_gap_address_get(&addr) != NRF_SUCCESS) { |
Rohit Grover |
56:a1071b629aa3 | 86 | return ERROR_INVALID_PARAM; |
Rohit Grover |
56:a1071b629aa3 | 87 | } |
Rohit Grover |
56:a1071b629aa3 | 88 | if (sd_ble_gap_address_set(BLE_GAP_ADDR_CYCLE_MODE_NONE, &addr) != NRF_SUCCESS) { |
Rohit Grover |
56:a1071b629aa3 | 89 | return ERROR_INVALID_PARAM; |
Rohit Grover |
56:a1071b629aa3 | 90 | } |
Rohit Grover |
22:c6ee8136847e | 91 | |
Rohit Grover |
22:c6ee8136847e | 92 | ASSERT_STATUS( softdevice_ble_evt_handler_set(btle_handler)); |
Rohit Grover |
22:c6ee8136847e | 93 | ASSERT_STATUS( softdevice_sys_evt_handler_set(sys_evt_dispatch)); |
Rohit Grover |
22:c6ee8136847e | 94 | |
rgrover1 | 127:bd1e1fe607e0 | 95 | btle_gap_init(); |
rgrover1 | 127:bd1e1fe607e0 | 96 | |
rgrover1 | 127:bd1e1fe607e0 | 97 | return ERROR_NONE; |
rgrover1 | 127:bd1e1fe607e0 | 98 | } |
rgrover1 | 127:bd1e1fe607e0 | 99 | |
rgrover1 | 127:bd1e1fe607e0 | 100 | ble_error_t |
rgrover1 | 127:bd1e1fe607e0 | 101 | btle_initializeSecurity() |
rgrover1 | 127:bd1e1fe607e0 | 102 | { |
rgrover1 | 127:bd1e1fe607e0 | 103 | if (pstorage_init() != NRF_SUCCESS) { |
rgrover1 | 127:bd1e1fe607e0 | 104 | return BLE_ERROR_UNSPECIFIED; |
rgrover1 | 127:bd1e1fe607e0 | 105 | } |
rgrover1 | 123:e19f9f7874f9 | 106 | |
rgrover1 | 124:664d4257a9f8 | 107 | dm_init_param_t dm_init_param = { |
rgrover1 | 124:664d4257a9f8 | 108 | .clear_persistent_data = false /* Set to true in case the module should clear all persistent data. */ |
rgrover1 | 124:664d4257a9f8 | 109 | }; |
rgrover1 | 127:bd1e1fe607e0 | 110 | if (dm_init(&dm_init_param) != NRF_SUCCESS) { |
rgrover1 | 127:bd1e1fe607e0 | 111 | return BLE_ERROR_UNSPECIFIED; |
rgrover1 | 127:bd1e1fe607e0 | 112 | } |
rgrover1 | 124:664d4257a9f8 | 113 | |
rgrover1 | 125:35e4f65364bc | 114 | uint8_t applicationInstance; |
rgrover1 | 125:35e4f65364bc | 115 | const dm_application_param_t dm_param = { |
rgrover1 | 125:35e4f65364bc | 116 | .evt_handler = dm_handler, |
rgrover1 | 125:35e4f65364bc | 117 | .service_type = DM_PROTOCOL_CNTXT_GATT_CLI_ID, |
rgrover1 | 125:35e4f65364bc | 118 | .sec_param = { |
rgrover1 | 125:35e4f65364bc | 119 | .bond = 1, /**< Perform bonding. */ |
rgrover1 | 125:35e4f65364bc | 120 | .mitm = 1, /**< Man In The Middle protection required. */ |
rgrover1 | 125:35e4f65364bc | 121 | .io_caps = BLE_GAP_IO_CAPS_NONE, /**< IO capabilities, see @ref BLE_GAP_IO_CAPS. */ |
rgrover1 | 125:35e4f65364bc | 122 | .oob = 0, /**< Out Of Band data available. */ |
rgrover1 | 125:35e4f65364bc | 123 | .min_key_size = 16, /**< Minimum encryption key size in octets between 7 and 16. If 0 then not applicable in this instance. */ |
rgrover1 | 125:35e4f65364bc | 124 | .max_key_size = 16, /**< Maximum encryption key size in octets between min_key_size and 16. */ |
rgrover1 | 125:35e4f65364bc | 125 | .kdist_periph = { |
rgrover1 | 125:35e4f65364bc | 126 | .enc = 1, /**< Long Term Key and Master Identification. */ |
rgrover1 | 125:35e4f65364bc | 127 | .id = 1, /**< Identity Resolving Key and Identity Address Information. */ |
rgrover1 | 125:35e4f65364bc | 128 | .sign = 1, /**< Connection Signature Resolving Key. */ |
rgrover1 | 125:35e4f65364bc | 129 | }, /**< Key distribution bitmap: keys that the peripheral device will distribute. */ |
rgrover1 | 125:35e4f65364bc | 130 | } |
rgrover1 | 125:35e4f65364bc | 131 | }; |
rgrover1 | 125:35e4f65364bc | 132 | |
rgrover1 | 127:bd1e1fe607e0 | 133 | ret_code_t rc; |
rgrover1 | 127:bd1e1fe607e0 | 134 | if ((rc = dm_register(&applicationInstance, &dm_param)) != NRF_SUCCESS) { |
rgrover1 | 127:bd1e1fe607e0 | 135 | switch (rc) { |
rgrover1 | 127:bd1e1fe607e0 | 136 | case NRF_ERROR_INVALID_STATE: |
rgrover1 | 127:bd1e1fe607e0 | 137 | return BLE_ERROR_INVALID_STATE; |
rgrover1 | 127:bd1e1fe607e0 | 138 | case NRF_ERROR_NO_MEM: |
rgrover1 | 127:bd1e1fe607e0 | 139 | return BLE_ERROR_NO_MEM; |
rgrover1 | 127:bd1e1fe607e0 | 140 | default: |
rgrover1 | 127:bd1e1fe607e0 | 141 | return BLE_ERROR_UNSPECIFIED; |
rgrover1 | 127:bd1e1fe607e0 | 142 | } |
rgrover1 | 127:bd1e1fe607e0 | 143 | } |
Rohit Grover |
22:c6ee8136847e | 144 | |
rgrover1 | 127:bd1e1fe607e0 | 145 | return BLE_ERROR_NONE; |
Rohit Grover |
22:c6ee8136847e | 146 | } |
Rohit Grover |
22:c6ee8136847e | 147 | |
rgrover1 | 125:35e4f65364bc | 148 | ret_code_t |
rgrover1 | 125:35e4f65364bc | 149 | dm_handler(dm_handle_t const *p_handle, dm_event_t const *p_event, ret_code_t event_result) |
rgrover1 | 125:35e4f65364bc | 150 | { |
rgrover1 | 125:35e4f65364bc | 151 | printf("dm_handler: event %u\r\n", p_event->event_id); |
rgrover1 | 127:bd1e1fe607e0 | 152 | |
rgrover1 | 127:bd1e1fe607e0 | 153 | switch (p_event->event_id) { |
rgrover1 | 127:bd1e1fe607e0 | 154 | case DM_EVT_SECURITY_SETUP: /* started */ |
rgrover1 | 127:bd1e1fe607e0 | 155 | break; |
rgrover1 | 127:bd1e1fe607e0 | 156 | case DM_EVT_SECURITY_SETUP_COMPLETE: |
rgrover1 | 127:bd1e1fe607e0 | 157 | break; |
rgrover1 | 127:bd1e1fe607e0 | 158 | case DM_EVT_LINK_SECURED: |
rgrover1 | 127:bd1e1fe607e0 | 159 | break; |
rgrover1 | 127:bd1e1fe607e0 | 160 | case DM_EVT_DEVICE_CONTEXT_STORED: |
rgrover1 | 127:bd1e1fe607e0 | 161 | break; |
rgrover1 | 127:bd1e1fe607e0 | 162 | default: |
rgrover1 | 127:bd1e1fe607e0 | 163 | break; |
rgrover1 | 127:bd1e1fe607e0 | 164 | } |
rgrover1 | 125:35e4f65364bc | 165 | return NRF_SUCCESS; |
rgrover1 | 125:35e4f65364bc | 166 | } |
rgrover1 | 125:35e4f65364bc | 167 | |
Rohit Grover |
22:c6ee8136847e | 168 | static void btle_handler(ble_evt_t *p_ble_evt) |
Rohit Grover |
22:c6ee8136847e | 169 | { |
Rohit Grover |
22:c6ee8136847e | 170 | /* Library service handlers */ |
Rohit Grover |
56:a1071b629aa3 | 171 | #if SDK_CONN_PARAMS_MODULE_ENABLE |
Rohit Grover |
22:c6ee8136847e | 172 | ble_conn_params_on_ble_evt(p_ble_evt); |
Rohit Grover |
56:a1071b629aa3 | 173 | #endif |
Rohit Grover |
22:c6ee8136847e | 174 | |
rgrover1 | 125:35e4f65364bc | 175 | dm_ble_evt_handler(p_ble_evt); |
rgrover1 | 125:35e4f65364bc | 176 | |
Rohit Grover |
22:c6ee8136847e | 177 | /* Custom event handler */ |
Rohit Grover |
22:c6ee8136847e | 178 | switch (p_ble_evt->header.evt_id) { |
Rohit Grover |
41:6e66cd970659 | 179 | case BLE_GAP_EVT_CONNECTED: { |
Rohit Grover |
41:6e66cd970659 | 180 | Gap::Handle_t handle = p_ble_evt->evt.gap_evt.conn_handle; |
Rohit Grover |
41:6e66cd970659 | 181 | nRF51Gap::getInstance().setConnectionHandle(handle); |
Rohit Grover |
56:a1071b629aa3 | 182 | const Gap::ConnectionParams_t *params = reinterpret_cast<Gap::ConnectionParams_t *>(&(p_ble_evt->evt.gap_evt.params.connected.conn_params)); |
rgrover1 | 77:9886b2865631 | 183 | const ble_gap_addr_t *peer = &p_ble_evt->evt.gap_evt.params.connected.peer_addr; |
rgrover1 | 112:737b08b3b995 | 184 | const ble_gap_addr_t *own = &p_ble_evt->evt.gap_evt.params.connected.own_addr; |
rgrover1 | 112:737b08b3b995 | 185 | nRF51Gap::getInstance().processConnectionEvent(handle, |
rgrover1 | 112:737b08b3b995 | 186 | static_cast<Gap::addr_type_t>(peer->addr_type), peer->addr, |
rgrover1 | 112:737b08b3b995 | 187 | static_cast<Gap::addr_type_t>(own->addr_type), own->addr, |
rgrover1 | 112:737b08b3b995 | 188 | params); |
Rohit Grover |
22:c6ee8136847e | 189 | break; |
Rohit Grover |
41:6e66cd970659 | 190 | } |
Rohit Grover |
22:c6ee8136847e | 191 | |
Rohit Grover |
41:6e66cd970659 | 192 | case BLE_GAP_EVT_DISCONNECTED: { |
Rohit Grover |
41:6e66cd970659 | 193 | Gap::Handle_t handle = p_ble_evt->evt.gap_evt.conn_handle; |
Rohit Grover |
22:c6ee8136847e | 194 | // Since we are not in a connection and have not started advertising, |
Rohit Grover |
22:c6ee8136847e | 195 | // store bonds |
Rohit Grover |
22:c6ee8136847e | 196 | nRF51Gap::getInstance().setConnectionHandle (BLE_CONN_HANDLE_INVALID); |
Rohit Grover |
56:a1071b629aa3 | 197 | |
Rohit Grover |
65:98215c4f3a25 | 198 | Gap::DisconnectionReason_t reason; |
Rohit Grover |
65:98215c4f3a25 | 199 | switch (p_ble_evt->evt.gap_evt.params.disconnected.reason) { |
Rohit Grover |
65:98215c4f3a25 | 200 | case BLE_HCI_LOCAL_HOST_TERMINATED_CONNECTION: |
Rohit Grover |
65:98215c4f3a25 | 201 | reason = Gap::LOCAL_HOST_TERMINATED_CONNECTION; |
Rohit Grover |
65:98215c4f3a25 | 202 | break; |
Rohit Grover |
65:98215c4f3a25 | 203 | case BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION: |
Rohit Grover |
65:98215c4f3a25 | 204 | reason = Gap::REMOTE_USER_TERMINATED_CONNECTION; |
Rohit Grover |
65:98215c4f3a25 | 205 | break; |
Rohit Grover |
65:98215c4f3a25 | 206 | case BLE_HCI_CONN_INTERVAL_UNACCEPTABLE: |
Rohit Grover |
65:98215c4f3a25 | 207 | reason = Gap::CONN_INTERVAL_UNACCEPTABLE; |
Rohit Grover |
65:98215c4f3a25 | 208 | break; |
Rohit Grover |
65:98215c4f3a25 | 209 | default: |
Rohit Grover |
65:98215c4f3a25 | 210 | /* Please refer to the underlying transport library for an |
Rohit Grover |
65:98215c4f3a25 | 211 | * interpretion of this reason's value. */ |
Rohit Grover |
65:98215c4f3a25 | 212 | reason = static_cast<Gap::DisconnectionReason_t>(p_ble_evt->evt.gap_evt.params.disconnected.reason); |
Rohit Grover |
65:98215c4f3a25 | 213 | break; |
Rohit Grover |
56:a1071b629aa3 | 214 | } |
Rohit Grover |
65:98215c4f3a25 | 215 | nRF51Gap::getInstance().processDisconnectionEvent(handle, reason); |
Rohit Grover |
22:c6ee8136847e | 216 | break; |
Rohit Grover |
41:6e66cd970659 | 217 | } |
Rohit Grover |
22:c6ee8136847e | 218 | |
Rohit Grover |
22:c6ee8136847e | 219 | case BLE_GAP_EVT_SEC_PARAMS_REQUEST: { |
Rohit Grover |
22:c6ee8136847e | 220 | ble_gap_sec_params_t sec_params = {0}; |
Rohit Grover |
22:c6ee8136847e | 221 | |
rgrover1 | 112:737b08b3b995 | 222 | sec_params.bond = 1; /**< Perform bonding. */ |
rgrover1 | 112:737b08b3b995 | 223 | sec_params.mitm = CFG_BLE_SEC_PARAM_MITM; |
rgrover1 | 112:737b08b3b995 | 224 | sec_params.io_caps = CFG_BLE_SEC_PARAM_IO_CAPABILITIES; |
rgrover1 | 112:737b08b3b995 | 225 | sec_params.oob = CFG_BLE_SEC_PARAM_OOB; |
rgrover1 | 112:737b08b3b995 | 226 | sec_params.min_key_size = CFG_BLE_SEC_PARAM_MIN_KEY_SIZE; |
rgrover1 | 112:737b08b3b995 | 227 | sec_params.max_key_size = CFG_BLE_SEC_PARAM_MAX_KEY_SIZE; |
Rohit Grover |
22:c6ee8136847e | 228 | |
rgrover1 | 112:737b08b3b995 | 229 | ble_gap_sec_keyset_t sec_keyset = {0}; |
rgrover1 | 112:737b08b3b995 | 230 | |
rgrover1 | 112:737b08b3b995 | 231 | ASSERT_STATUS_RET_VOID(sd_ble_gap_sec_params_reply(nRF51Gap::getInstance().getConnectionHandle(), BLE_GAP_SEC_STATUS_SUCCESS, &sec_params, &sec_keyset)); |
Rohit Grover |
22:c6ee8136847e | 232 | } |
Rohit Grover |
22:c6ee8136847e | 233 | break; |
Rohit Grover |
22:c6ee8136847e | 234 | |
Rohit Grover |
22:c6ee8136847e | 235 | case BLE_GAP_EVT_TIMEOUT: |
rgrover1 | 112:737b08b3b995 | 236 | if (p_ble_evt->evt.gap_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_ADVERTISING) { |
Rohit Grover |
41:6e66cd970659 | 237 | nRF51Gap::getInstance().processEvent(GapEvents::GAP_EVENT_TIMEOUT); |
Rohit Grover |
22:c6ee8136847e | 238 | } |
Rohit Grover |
22:c6ee8136847e | 239 | break; |
Rohit Grover |
22:c6ee8136847e | 240 | |
Rohit Grover |
22:c6ee8136847e | 241 | case BLE_GATTC_EVT_TIMEOUT: |
Rohit Grover |
22:c6ee8136847e | 242 | case BLE_GATTS_EVT_TIMEOUT: |
Rohit Grover |
22:c6ee8136847e | 243 | // Disconnect on GATT Server and Client timeout events. |
Rohit Grover |
22:c6ee8136847e | 244 | // ASSERT_STATUS_RET_VOID (sd_ble_gap_disconnect(m_conn_handle, |
Rohit Grover |
22:c6ee8136847e | 245 | // BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION)); |
Rohit Grover |
22:c6ee8136847e | 246 | break; |
Rohit Grover |
22:c6ee8136847e | 247 | |
Rohit Grover |
22:c6ee8136847e | 248 | default: |
Rohit Grover |
22:c6ee8136847e | 249 | break; |
Rohit Grover |
22:c6ee8136847e | 250 | } |
Rohit Grover |
22:c6ee8136847e | 251 | |
Rohit Grover |
22:c6ee8136847e | 252 | nRF51GattServer::getInstance().hwCallback(p_ble_evt); |
Rohit Grover |
22:c6ee8136847e | 253 | } |
Rohit Grover |
22:c6ee8136847e | 254 | |
Rohit Grover |
22:c6ee8136847e | 255 | /**************************************************************************/ |
Rohit Grover |
22:c6ee8136847e | 256 | /*! |
Rohit Grover |
22:c6ee8136847e | 257 | @brief Callback when an error occurs inside the SoftDevice |
Rohit Grover |
22:c6ee8136847e | 258 | |
Rohit Grover |
22:c6ee8136847e | 259 | @param[in] line_num |
Rohit Grover |
22:c6ee8136847e | 260 | @param[in] p-file_name |
Rohit Grover |
22:c6ee8136847e | 261 | |
Rohit Grover |
22:c6ee8136847e | 262 | @returns |
Rohit Grover |
22:c6ee8136847e | 263 | */ |
Rohit Grover |
22:c6ee8136847e | 264 | /**************************************************************************/ |
Rohit Grover |
22:c6ee8136847e | 265 | void assert_nrf_callback(uint16_t line_num, const uint8_t *p_file_name) |
Rohit Grover |
22:c6ee8136847e | 266 | { |
Rohit Grover |
22:c6ee8136847e | 267 | ASSERT(false, (void) 0); |
Rohit Grover |
22:c6ee8136847e | 268 | } |
Rohit Grover |
22:c6ee8136847e | 269 | |
Rohit Grover |
22:c6ee8136847e | 270 | /**************************************************************************/ |
Rohit Grover |
22:c6ee8136847e | 271 | /*! |
Rohit Grover |
22:c6ee8136847e | 272 | @brief Handler for general errors above the SoftDevice layer. |
Rohit Grover |
22:c6ee8136847e | 273 | Typically we can' recover from this so we do a reset. |
Rohit Grover |
22:c6ee8136847e | 274 | |
Rohit Grover |
22:c6ee8136847e | 275 | @param[in] error_code |
Rohit Grover |
22:c6ee8136847e | 276 | @param[in] line_num |
Rohit Grover |
22:c6ee8136847e | 277 | @param[in] p-file_name |
Rohit Grover |
22:c6ee8136847e | 278 | |
Rohit Grover |
22:c6ee8136847e | 279 | @returns |
Rohit Grover |
22:c6ee8136847e | 280 | */ |
Rohit Grover |
22:c6ee8136847e | 281 | /**************************************************************************/ |
Rohit Grover |
22:c6ee8136847e | 282 | void app_error_handler(uint32_t error_code, |
Rohit Grover |
22:c6ee8136847e | 283 | uint32_t line_num, |
Rohit Grover |
22:c6ee8136847e | 284 | const uint8_t *p_file_name) |
Rohit Grover |
22:c6ee8136847e | 285 | { |
Rohit Grover |
22:c6ee8136847e | 286 | ASSERT_STATUS_RET_VOID( error_code ); |
Rohit Grover |
22:c6ee8136847e | 287 | NVIC_SystemReset(); |
rgrover1 | 77:9886b2865631 | 288 | } |