test
Fork of nRF51822 by
source/btle/btle.cpp@616:a8f9b022d8fd, 2016-04-06 (annotated)
- Committer:
- LancasterUniversity
- Date:
- Wed Apr 06 22:39:17 2016 +0100
- Revision:
- 616:a8f9b022d8fd
- Parent:
- 615:65ea2acfc6a2
Synchronized with git rev 67d0ac73
Author: Joe Finney
microbit: Update to indicate when system attributes require intialisation
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
LancasterUniversity | 615:65ea2acfc6a2 | 1 | /* mbed Microcontroller Library |
LancasterUniversity | 615:65ea2acfc6a2 | 2 | * Copyright (c) 2006-2013 ARM Limited |
LancasterUniversity | 615:65ea2acfc6a2 | 3 | * |
LancasterUniversity | 615:65ea2acfc6a2 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
LancasterUniversity | 615:65ea2acfc6a2 | 5 | * you may not use this file except in compliance with the License. |
LancasterUniversity | 615:65ea2acfc6a2 | 6 | * You may obtain a copy of the License at |
LancasterUniversity | 615:65ea2acfc6a2 | 7 | * |
LancasterUniversity | 615:65ea2acfc6a2 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
LancasterUniversity | 615:65ea2acfc6a2 | 9 | * |
LancasterUniversity | 615:65ea2acfc6a2 | 10 | * Unless required by applicable law or agreed to in writing, software |
LancasterUniversity | 615:65ea2acfc6a2 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
LancasterUniversity | 615:65ea2acfc6a2 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
LancasterUniversity | 615:65ea2acfc6a2 | 13 | * See the License for the specific language governing permissions and |
LancasterUniversity | 615:65ea2acfc6a2 | 14 | * limitations under the License. |
LancasterUniversity | 615:65ea2acfc6a2 | 15 | */ |
LancasterUniversity | 615:65ea2acfc6a2 | 16 | |
LancasterUniversity | 615:65ea2acfc6a2 | 17 | #include "common/common.h" |
LancasterUniversity | 615:65ea2acfc6a2 | 18 | #include "nordic_common.h" |
LancasterUniversity | 615:65ea2acfc6a2 | 19 | |
LancasterUniversity | 615:65ea2acfc6a2 | 20 | #include "btle.h" |
LancasterUniversity | 615:65ea2acfc6a2 | 21 | |
LancasterUniversity | 615:65ea2acfc6a2 | 22 | #include "ble_flash.h" |
LancasterUniversity | 615:65ea2acfc6a2 | 23 | #include "ble_conn_params.h" |
LancasterUniversity | 615:65ea2acfc6a2 | 24 | |
LancasterUniversity | 615:65ea2acfc6a2 | 25 | #include "btle_gap.h" |
LancasterUniversity | 615:65ea2acfc6a2 | 26 | #include "btle_advertising.h" |
LancasterUniversity | 615:65ea2acfc6a2 | 27 | #include "custom/custom_helper.h" |
LancasterUniversity | 615:65ea2acfc6a2 | 28 | |
LancasterUniversity | 616:a8f9b022d8fd | 29 | #include "ble/GapEvents.h" |
LancasterUniversity | 616:a8f9b022d8fd | 30 | #include "nRF5xn.h" |
LancasterUniversity | 615:65ea2acfc6a2 | 31 | |
LancasterUniversity | 616:a8f9b022d8fd | 32 | extern "C" { |
LancasterUniversity | 616:a8f9b022d8fd | 33 | #include "pstorage.h" |
LancasterUniversity | 615:65ea2acfc6a2 | 34 | #include "device_manager.h" |
LancasterUniversity | 616:a8f9b022d8fd | 35 | #include "softdevice_handler.h" |
LancasterUniversity | 616:a8f9b022d8fd | 36 | #include "ble_stack_handler_types.h" |
LancasterUniversity | 616:a8f9b022d8fd | 37 | } |
LancasterUniversity | 615:65ea2acfc6a2 | 38 | |
LancasterUniversity | 615:65ea2acfc6a2 | 39 | #include "ble_hci.h" |
LancasterUniversity | 615:65ea2acfc6a2 | 40 | #include "btle_discovery.h" |
LancasterUniversity | 615:65ea2acfc6a2 | 41 | |
LancasterUniversity | 616:a8f9b022d8fd | 42 | #include "nRF5xGattClient.h" |
LancasterUniversity | 616:a8f9b022d8fd | 43 | #include "nRF5xServiceDiscovery.h" |
LancasterUniversity | 616:a8f9b022d8fd | 44 | #include "nRF5xCharacteristicDescriptorDiscoverer.h" |
LancasterUniversity | 616:a8f9b022d8fd | 45 | |
LancasterUniversity | 615:65ea2acfc6a2 | 46 | extern "C" void assert_nrf_callback(uint16_t line_num, const uint8_t *p_file_name); |
LancasterUniversity | 615:65ea2acfc6a2 | 47 | void app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t *p_file_name); |
LancasterUniversity | 615:65ea2acfc6a2 | 48 | |
LancasterUniversity | 615:65ea2acfc6a2 | 49 | static void btle_handler(ble_evt_t *p_ble_evt); |
LancasterUniversity | 616:a8f9b022d8fd | 50 | static uint32_t gatt_table_size = BLE_GATTS_ATTR_TAB_SIZE_DEFAULT; |
LancasterUniversity | 615:65ea2acfc6a2 | 51 | |
LancasterUniversity | 615:65ea2acfc6a2 | 52 | static void sys_evt_dispatch(uint32_t sys_evt) |
LancasterUniversity | 615:65ea2acfc6a2 | 53 | { |
LancasterUniversity | 615:65ea2acfc6a2 | 54 | pstorage_sys_event_handler(sys_evt); |
LancasterUniversity | 615:65ea2acfc6a2 | 55 | } |
LancasterUniversity | 615:65ea2acfc6a2 | 56 | |
LancasterUniversity | 615:65ea2acfc6a2 | 57 | /** |
LancasterUniversity | 615:65ea2acfc6a2 | 58 | * This function is called in interrupt context to handle BLE events; i.e. pull |
LancasterUniversity | 615:65ea2acfc6a2 | 59 | * system and user events out of the pending events-queue of the BLE stack. The |
LancasterUniversity | 615:65ea2acfc6a2 | 60 | * BLE stack signals the availability of events by the triggering the SWI2 |
LancasterUniversity | 615:65ea2acfc6a2 | 61 | * interrupt, which forwards the handling to this function. |
LancasterUniversity | 615:65ea2acfc6a2 | 62 | * |
LancasterUniversity | 615:65ea2acfc6a2 | 63 | * The event processing loop is implemented in intern_softdevice_events_execute(). |
LancasterUniversity | 615:65ea2acfc6a2 | 64 | * |
LancasterUniversity | 615:65ea2acfc6a2 | 65 | * In mbed OS, a callback for intern_softdevice_events_execute() is posted |
LancasterUniversity | 615:65ea2acfc6a2 | 66 | * to the scheduler, which then executes in thread mode. In mbed-classic, |
LancasterUniversity | 615:65ea2acfc6a2 | 67 | * event processing happens right-away in interrupt context (which is more |
LancasterUniversity | 615:65ea2acfc6a2 | 68 | * risk-prone). In either case, the logic of event processing is identical. |
LancasterUniversity | 615:65ea2acfc6a2 | 69 | */ |
LancasterUniversity | 615:65ea2acfc6a2 | 70 | static uint32_t eventHandler() |
LancasterUniversity | 615:65ea2acfc6a2 | 71 | { |
LancasterUniversity | 615:65ea2acfc6a2 | 72 | #ifdef YOTTA_CFG_MBED_OS |
LancasterUniversity | 615:65ea2acfc6a2 | 73 | minar::Scheduler::postCallback(intern_softdevice_events_execute); |
LancasterUniversity | 615:65ea2acfc6a2 | 74 | #else |
LancasterUniversity | 615:65ea2acfc6a2 | 75 | intern_softdevice_events_execute(); |
LancasterUniversity | 615:65ea2acfc6a2 | 76 | #endif |
LancasterUniversity | 615:65ea2acfc6a2 | 77 | |
LancasterUniversity | 615:65ea2acfc6a2 | 78 | return NRF_SUCCESS; |
LancasterUniversity | 615:65ea2acfc6a2 | 79 | } |
LancasterUniversity | 615:65ea2acfc6a2 | 80 | |
LancasterUniversity | 616:a8f9b022d8fd | 81 | error_t |
LancasterUniversity | 616:a8f9b022d8fd | 82 | btle_set_gatt_table_size(uint32_t size) |
LancasterUniversity | 616:a8f9b022d8fd | 83 | { |
LancasterUniversity | 616:a8f9b022d8fd | 84 | if (size >= BLE_GATTS_ATTR_TAB_SIZE_MIN) |
LancasterUniversity | 616:a8f9b022d8fd | 85 | { |
LancasterUniversity | 616:a8f9b022d8fd | 86 | gatt_table_size = size; |
LancasterUniversity | 616:a8f9b022d8fd | 87 | return ERROR_NONE; |
LancasterUniversity | 616:a8f9b022d8fd | 88 | } |
LancasterUniversity | 616:a8f9b022d8fd | 89 | |
LancasterUniversity | 616:a8f9b022d8fd | 90 | return ERROR_INVALID_PARAM; |
LancasterUniversity | 616:a8f9b022d8fd | 91 | } |
LancasterUniversity | 616:a8f9b022d8fd | 92 | |
LancasterUniversity | 615:65ea2acfc6a2 | 93 | error_t btle_init(void) |
LancasterUniversity | 615:65ea2acfc6a2 | 94 | { |
LancasterUniversity | 615:65ea2acfc6a2 | 95 | nrf_clock_lfclksrc_t clockSource; |
LancasterUniversity | 615:65ea2acfc6a2 | 96 | if (NRF_CLOCK->LFCLKSRC & (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos)) { |
LancasterUniversity | 615:65ea2acfc6a2 | 97 | clockSource = NRF_CLOCK_LFCLKSRC_XTAL_20_PPM; |
LancasterUniversity | 615:65ea2acfc6a2 | 98 | } else { |
LancasterUniversity | 615:65ea2acfc6a2 | 99 | clockSource = NRF_CLOCK_LFCLKSRC_RC_250_PPM_4000MS_CALIBRATION; |
LancasterUniversity | 615:65ea2acfc6a2 | 100 | } |
LancasterUniversity | 615:65ea2acfc6a2 | 101 | SOFTDEVICE_HANDLER_INIT(clockSource, eventHandler); |
LancasterUniversity | 615:65ea2acfc6a2 | 102 | |
LancasterUniversity | 615:65ea2acfc6a2 | 103 | // Enable BLE stack |
LancasterUniversity | 615:65ea2acfc6a2 | 104 | /** |
LancasterUniversity | 615:65ea2acfc6a2 | 105 | * Using this call, the application can select whether to include the |
LancasterUniversity | 615:65ea2acfc6a2 | 106 | * Service Changed characteristic in the GATT Server. The default in all |
LancasterUniversity | 615:65ea2acfc6a2 | 107 | * previous releases has been to include the Service Changed characteristic, |
LancasterUniversity | 615:65ea2acfc6a2 | 108 | * but this affects how GATT clients behave. Specifically, it requires |
LancasterUniversity | 615:65ea2acfc6a2 | 109 | * clients to subscribe to this attribute and not to cache attribute handles |
LancasterUniversity | 615:65ea2acfc6a2 | 110 | * between connections unless the devices are bonded. If the application |
LancasterUniversity | 615:65ea2acfc6a2 | 111 | * does not need to change the structure of the GATT server attributes at |
LancasterUniversity | 615:65ea2acfc6a2 | 112 | * runtime this adds unnecessary complexity to the interaction with peer |
LancasterUniversity | 615:65ea2acfc6a2 | 113 | * clients. If the SoftDevice is enabled with the Service Changed |
LancasterUniversity | 615:65ea2acfc6a2 | 114 | * Characteristics turned off, then clients are allowed to cache attribute |
LancasterUniversity | 615:65ea2acfc6a2 | 115 | * handles making applications simpler on both sides. |
LancasterUniversity | 615:65ea2acfc6a2 | 116 | */ |
LancasterUniversity | 615:65ea2acfc6a2 | 117 | static const bool IS_SRVC_CHANGED_CHARACT_PRESENT = true; |
LancasterUniversity | 615:65ea2acfc6a2 | 118 | ble_enable_params_t enableParams = { |
LancasterUniversity | 615:65ea2acfc6a2 | 119 | .gatts_enable_params = { |
LancasterUniversity | 616:a8f9b022d8fd | 120 | .service_changed = IS_SRVC_CHANGED_CHARACT_PRESENT, |
LancasterUniversity | 616:a8f9b022d8fd | 121 | .attr_tab_size = gatt_table_size |
LancasterUniversity | 615:65ea2acfc6a2 | 122 | } |
LancasterUniversity | 615:65ea2acfc6a2 | 123 | }; |
LancasterUniversity | 615:65ea2acfc6a2 | 124 | if (sd_ble_enable(&enableParams) != NRF_SUCCESS) { |
LancasterUniversity | 615:65ea2acfc6a2 | 125 | return ERROR_INVALID_PARAM; |
LancasterUniversity | 615:65ea2acfc6a2 | 126 | } |
LancasterUniversity | 615:65ea2acfc6a2 | 127 | |
LancasterUniversity | 615:65ea2acfc6a2 | 128 | ble_gap_addr_t addr; |
LancasterUniversity | 615:65ea2acfc6a2 | 129 | if (sd_ble_gap_address_get(&addr) != NRF_SUCCESS) { |
LancasterUniversity | 615:65ea2acfc6a2 | 130 | return ERROR_INVALID_PARAM; |
LancasterUniversity | 615:65ea2acfc6a2 | 131 | } |
LancasterUniversity | 615:65ea2acfc6a2 | 132 | if (sd_ble_gap_address_set(BLE_GAP_ADDR_CYCLE_MODE_NONE, &addr) != NRF_SUCCESS) { |
LancasterUniversity | 615:65ea2acfc6a2 | 133 | return ERROR_INVALID_PARAM; |
LancasterUniversity | 615:65ea2acfc6a2 | 134 | } |
LancasterUniversity | 615:65ea2acfc6a2 | 135 | |
LancasterUniversity | 615:65ea2acfc6a2 | 136 | ASSERT_STATUS( softdevice_ble_evt_handler_set(btle_handler)); |
LancasterUniversity | 615:65ea2acfc6a2 | 137 | ASSERT_STATUS( softdevice_sys_evt_handler_set(sys_evt_dispatch)); |
LancasterUniversity | 615:65ea2acfc6a2 | 138 | |
LancasterUniversity | 616:a8f9b022d8fd | 139 | return btle_gap_init(); |
LancasterUniversity | 615:65ea2acfc6a2 | 140 | } |
LancasterUniversity | 615:65ea2acfc6a2 | 141 | |
LancasterUniversity | 615:65ea2acfc6a2 | 142 | static void btle_handler(ble_evt_t *p_ble_evt) |
LancasterUniversity | 615:65ea2acfc6a2 | 143 | { |
LancasterUniversity | 615:65ea2acfc6a2 | 144 | /* Library service handlers */ |
LancasterUniversity | 615:65ea2acfc6a2 | 145 | #if SDK_CONN_PARAMS_MODULE_ENABLE |
LancasterUniversity | 615:65ea2acfc6a2 | 146 | ble_conn_params_on_ble_evt(p_ble_evt); |
LancasterUniversity | 615:65ea2acfc6a2 | 147 | #endif |
LancasterUniversity | 615:65ea2acfc6a2 | 148 | |
LancasterUniversity | 615:65ea2acfc6a2 | 149 | dm_ble_evt_handler(p_ble_evt); |
LancasterUniversity | 615:65ea2acfc6a2 | 150 | |
LancasterUniversity | 615:65ea2acfc6a2 | 151 | #if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110) |
LancasterUniversity | 615:65ea2acfc6a2 | 152 | bleGattcEventHandler(p_ble_evt); |
LancasterUniversity | 615:65ea2acfc6a2 | 153 | #endif |
LancasterUniversity | 615:65ea2acfc6a2 | 154 | |
LancasterUniversity | 616:a8f9b022d8fd | 155 | nRF5xn &ble = nRF5xn::Instance(BLE::DEFAULT_INSTANCE); |
LancasterUniversity | 616:a8f9b022d8fd | 156 | nRF5xGap &gap = (nRF5xGap &) ble.getGap(); |
LancasterUniversity | 616:a8f9b022d8fd | 157 | nRF5xGattServer &gattServer = (nRF5xGattServer &) ble.getGattServer(); |
LancasterUniversity | 616:a8f9b022d8fd | 158 | nRF5xSecurityManager &securityManager = (nRF5xSecurityManager &) ble.getSecurityManager(); |
LancasterUniversity | 616:a8f9b022d8fd | 159 | |
LancasterUniversity | 615:65ea2acfc6a2 | 160 | /* Custom event handler */ |
LancasterUniversity | 615:65ea2acfc6a2 | 161 | switch (p_ble_evt->header.evt_id) { |
LancasterUniversity | 615:65ea2acfc6a2 | 162 | case BLE_GAP_EVT_CONNECTED: { |
LancasterUniversity | 615:65ea2acfc6a2 | 163 | Gap::Handle_t handle = p_ble_evt->evt.gap_evt.conn_handle; |
LancasterUniversity | 615:65ea2acfc6a2 | 164 | #if defined(TARGET_MCU_NRF51_16K_S110) || defined(TARGET_MCU_NRF51_32K_S110) |
LancasterUniversity | 615:65ea2acfc6a2 | 165 | /* Only peripheral role is supported by S110 */ |
LancasterUniversity | 615:65ea2acfc6a2 | 166 | Gap::Role_t role = Gap::PERIPHERAL; |
LancasterUniversity | 615:65ea2acfc6a2 | 167 | #else |
LancasterUniversity | 615:65ea2acfc6a2 | 168 | Gap::Role_t role = static_cast<Gap::Role_t>(p_ble_evt->evt.gap_evt.params.connected.role); |
LancasterUniversity | 615:65ea2acfc6a2 | 169 | #endif |
LancasterUniversity | 616:a8f9b022d8fd | 170 | gap.setConnectionHandle(handle); |
LancasterUniversity | 615:65ea2acfc6a2 | 171 | const Gap::ConnectionParams_t *params = reinterpret_cast<Gap::ConnectionParams_t *>(&(p_ble_evt->evt.gap_evt.params.connected.conn_params)); |
LancasterUniversity | 615:65ea2acfc6a2 | 172 | const ble_gap_addr_t *peer = &p_ble_evt->evt.gap_evt.params.connected.peer_addr; |
LancasterUniversity | 615:65ea2acfc6a2 | 173 | const ble_gap_addr_t *own = &p_ble_evt->evt.gap_evt.params.connected.own_addr; |
LancasterUniversity | 616:a8f9b022d8fd | 174 | gap.processConnectionEvent(handle, |
LancasterUniversity | 615:65ea2acfc6a2 | 175 | role, |
LancasterUniversity | 616:a8f9b022d8fd | 176 | static_cast<BLEProtocol::AddressType_t>(peer->addr_type), peer->addr, |
LancasterUniversity | 616:a8f9b022d8fd | 177 | static_cast<BLEProtocol::AddressType_t>(own->addr_type), own->addr, |
LancasterUniversity | 615:65ea2acfc6a2 | 178 | params); |
LancasterUniversity | 615:65ea2acfc6a2 | 179 | break; |
LancasterUniversity | 615:65ea2acfc6a2 | 180 | } |
LancasterUniversity | 615:65ea2acfc6a2 | 181 | |
LancasterUniversity | 615:65ea2acfc6a2 | 182 | case BLE_GAP_EVT_DISCONNECTED: { |
LancasterUniversity | 615:65ea2acfc6a2 | 183 | Gap::Handle_t handle = p_ble_evt->evt.gap_evt.conn_handle; |
LancasterUniversity | 615:65ea2acfc6a2 | 184 | // Since we are not in a connection and have not started advertising, |
LancasterUniversity | 615:65ea2acfc6a2 | 185 | // store bonds |
LancasterUniversity | 616:a8f9b022d8fd | 186 | gap.setConnectionHandle (BLE_CONN_HANDLE_INVALID); |
LancasterUniversity | 615:65ea2acfc6a2 | 187 | |
LancasterUniversity | 615:65ea2acfc6a2 | 188 | Gap::DisconnectionReason_t reason; |
LancasterUniversity | 615:65ea2acfc6a2 | 189 | switch (p_ble_evt->evt.gap_evt.params.disconnected.reason) { |
LancasterUniversity | 615:65ea2acfc6a2 | 190 | case BLE_HCI_LOCAL_HOST_TERMINATED_CONNECTION: |
LancasterUniversity | 615:65ea2acfc6a2 | 191 | reason = Gap::LOCAL_HOST_TERMINATED_CONNECTION; |
LancasterUniversity | 615:65ea2acfc6a2 | 192 | break; |
LancasterUniversity | 615:65ea2acfc6a2 | 193 | case BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION: |
LancasterUniversity | 615:65ea2acfc6a2 | 194 | reason = Gap::REMOTE_USER_TERMINATED_CONNECTION; |
LancasterUniversity | 615:65ea2acfc6a2 | 195 | break; |
LancasterUniversity | 615:65ea2acfc6a2 | 196 | case BLE_HCI_CONN_INTERVAL_UNACCEPTABLE: |
LancasterUniversity | 615:65ea2acfc6a2 | 197 | reason = Gap::CONN_INTERVAL_UNACCEPTABLE; |
LancasterUniversity | 615:65ea2acfc6a2 | 198 | break; |
LancasterUniversity | 615:65ea2acfc6a2 | 199 | default: |
LancasterUniversity | 615:65ea2acfc6a2 | 200 | /* Please refer to the underlying transport library for an |
LancasterUniversity | 615:65ea2acfc6a2 | 201 | * interpretion of this reason's value. */ |
LancasterUniversity | 615:65ea2acfc6a2 | 202 | reason = static_cast<Gap::DisconnectionReason_t>(p_ble_evt->evt.gap_evt.params.disconnected.reason); |
LancasterUniversity | 615:65ea2acfc6a2 | 203 | break; |
LancasterUniversity | 615:65ea2acfc6a2 | 204 | } |
LancasterUniversity | 616:a8f9b022d8fd | 205 | |
LancasterUniversity | 616:a8f9b022d8fd | 206 | // Close all pending discoveries for this connection |
LancasterUniversity | 616:a8f9b022d8fd | 207 | #if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110) |
LancasterUniversity | 616:a8f9b022d8fd | 208 | nRF5xGattClient& gattClient = ble.getGattClient(); |
LancasterUniversity | 616:a8f9b022d8fd | 209 | gattClient.characteristicDescriptorDiscoverer().terminate(handle, BLE_ERROR_INVALID_STATE); |
LancasterUniversity | 616:a8f9b022d8fd | 210 | gattClient.discovery().terminate(handle); |
LancasterUniversity | 616:a8f9b022d8fd | 211 | #endif |
LancasterUniversity | 616:a8f9b022d8fd | 212 | |
LancasterUniversity | 616:a8f9b022d8fd | 213 | gap.processDisconnectionEvent(handle, reason); |
LancasterUniversity | 615:65ea2acfc6a2 | 214 | break; |
LancasterUniversity | 615:65ea2acfc6a2 | 215 | } |
LancasterUniversity | 615:65ea2acfc6a2 | 216 | |
LancasterUniversity | 615:65ea2acfc6a2 | 217 | case BLE_GAP_EVT_PASSKEY_DISPLAY: |
LancasterUniversity | 616:a8f9b022d8fd | 218 | securityManager.processPasskeyDisplayEvent(p_ble_evt->evt.gap_evt.conn_handle, p_ble_evt->evt.gap_evt.params.passkey_display.passkey); |
LancasterUniversity | 615:65ea2acfc6a2 | 219 | break; |
LancasterUniversity | 615:65ea2acfc6a2 | 220 | |
LancasterUniversity | 615:65ea2acfc6a2 | 221 | case BLE_GAP_EVT_TIMEOUT: |
LancasterUniversity | 616:a8f9b022d8fd | 222 | gap.processTimeoutEvent(static_cast<Gap::TimeoutSource_t>(p_ble_evt->evt.gap_evt.params.timeout.src)); |
LancasterUniversity | 615:65ea2acfc6a2 | 223 | break; |
LancasterUniversity | 615:65ea2acfc6a2 | 224 | |
LancasterUniversity | 615:65ea2acfc6a2 | 225 | case BLE_GATTC_EVT_TIMEOUT: |
LancasterUniversity | 615:65ea2acfc6a2 | 226 | case BLE_GATTS_EVT_TIMEOUT: |
LancasterUniversity | 615:65ea2acfc6a2 | 227 | // Disconnect on GATT Server and Client timeout events. |
LancasterUniversity | 615:65ea2acfc6a2 | 228 | // ASSERT_STATUS_RET_VOID (sd_ble_gap_disconnect(m_conn_handle, |
LancasterUniversity | 615:65ea2acfc6a2 | 229 | // BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION)); |
LancasterUniversity | 615:65ea2acfc6a2 | 230 | break; |
LancasterUniversity | 615:65ea2acfc6a2 | 231 | |
LancasterUniversity | 615:65ea2acfc6a2 | 232 | case BLE_GAP_EVT_ADV_REPORT: { |
LancasterUniversity | 615:65ea2acfc6a2 | 233 | const ble_gap_evt_adv_report_t *advReport = &p_ble_evt->evt.gap_evt.params.adv_report; |
LancasterUniversity | 616:a8f9b022d8fd | 234 | gap.processAdvertisementReport(advReport->peer_addr.addr, |
LancasterUniversity | 616:a8f9b022d8fd | 235 | advReport->rssi, |
LancasterUniversity | 616:a8f9b022d8fd | 236 | advReport->scan_rsp, |
LancasterUniversity | 616:a8f9b022d8fd | 237 | static_cast<GapAdvertisingParams::AdvertisingType_t>(advReport->type), |
LancasterUniversity | 616:a8f9b022d8fd | 238 | advReport->dlen, |
LancasterUniversity | 616:a8f9b022d8fd | 239 | advReport->data); |
LancasterUniversity | 615:65ea2acfc6a2 | 240 | break; |
LancasterUniversity | 615:65ea2acfc6a2 | 241 | } |
LancasterUniversity | 615:65ea2acfc6a2 | 242 | |
LancasterUniversity | 615:65ea2acfc6a2 | 243 | default: |
LancasterUniversity | 615:65ea2acfc6a2 | 244 | break; |
LancasterUniversity | 615:65ea2acfc6a2 | 245 | } |
LancasterUniversity | 615:65ea2acfc6a2 | 246 | |
LancasterUniversity | 616:a8f9b022d8fd | 247 | gattServer.hwCallback(p_ble_evt); |
LancasterUniversity | 615:65ea2acfc6a2 | 248 | } |
LancasterUniversity | 615:65ea2acfc6a2 | 249 | |
LancasterUniversity | 615:65ea2acfc6a2 | 250 | /*! @brief Callback when an error occurs inside the SoftDevice */ |
LancasterUniversity | 615:65ea2acfc6a2 | 251 | void assert_nrf_callback(uint16_t line_num, const uint8_t *p_file_name) |
LancasterUniversity | 615:65ea2acfc6a2 | 252 | { |
LancasterUniversity | 615:65ea2acfc6a2 | 253 | ASSERT(false, (void) 0); |
LancasterUniversity | 615:65ea2acfc6a2 | 254 | } |
LancasterUniversity | 615:65ea2acfc6a2 | 255 | |
LancasterUniversity | 615:65ea2acfc6a2 | 256 | /*! |
LancasterUniversity | 615:65ea2acfc6a2 | 257 | @brief Handler for general errors above the SoftDevice layer. |
LancasterUniversity | 615:65ea2acfc6a2 | 258 | Typically we can' recover from this so we do a reset. |
LancasterUniversity | 615:65ea2acfc6a2 | 259 | */ |
LancasterUniversity | 615:65ea2acfc6a2 | 260 | void app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t *p_file_name) |
LancasterUniversity | 615:65ea2acfc6a2 | 261 | { |
LancasterUniversity | 615:65ea2acfc6a2 | 262 | ASSERT_STATUS_RET_VOID( error_code ); |
LancasterUniversity | 615:65ea2acfc6a2 | 263 | NVIC_SystemReset(); |
rgrover1 | 77:9886b2865631 | 264 | } |