config changes

Fork of nRF51822 by Nordic Semiconductor

Committer:
Vincent Coubard
Date:
Wed Sep 14 14:39:43 2016 +0100
Revision:
638:c90ae1400bf2
Sync with bdab10dc0f90748b6989c8b577771bb403ca6bd8 from ARMmbed/mbed-os.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Vincent Coubard 638:c90ae1400bf2 1 /* mbed Microcontroller Library
Vincent Coubard 638:c90ae1400bf2 2 * Copyright (c) 2006-2013 ARM Limited
Vincent Coubard 638:c90ae1400bf2 3 *
Vincent Coubard 638:c90ae1400bf2 4 * Licensed under the Apache License, Version 2.0 (the "License");
Vincent Coubard 638:c90ae1400bf2 5 * you may not use this file except in compliance with the License.
Vincent Coubard 638:c90ae1400bf2 6 * You may obtain a copy of the License at
Vincent Coubard 638:c90ae1400bf2 7 *
Vincent Coubard 638:c90ae1400bf2 8 * http://www.apache.org/licenses/LICENSE-2.0
Vincent Coubard 638:c90ae1400bf2 9 *
Vincent Coubard 638:c90ae1400bf2 10 * Unless required by applicable law or agreed to in writing, software
Vincent Coubard 638:c90ae1400bf2 11 * distributed under the License is distributed on an "AS IS" BASIS,
Vincent Coubard 638:c90ae1400bf2 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Vincent Coubard 638:c90ae1400bf2 13 * See the License for the specific language governing permissions and
Vincent Coubard 638:c90ae1400bf2 14 * limitations under the License.
Vincent Coubard 638:c90ae1400bf2 15 */
Vincent Coubard 638:c90ae1400bf2 16
Vincent Coubard 638:c90ae1400bf2 17 #include "common/common.h"
Vincent Coubard 638:c90ae1400bf2 18 #include "nordic_common.h"
Vincent Coubard 638:c90ae1400bf2 19
Vincent Coubard 638:c90ae1400bf2 20 #include "btle.h"
Vincent Coubard 638:c90ae1400bf2 21 #include "btle_clock.h"
Vincent Coubard 638:c90ae1400bf2 22
Vincent Coubard 638:c90ae1400bf2 23 #include "ble_flash.h"
Vincent Coubard 638:c90ae1400bf2 24 #include "ble_conn_params.h"
Vincent Coubard 638:c90ae1400bf2 25
Vincent Coubard 638:c90ae1400bf2 26 #include "btle_gap.h"
Vincent Coubard 638:c90ae1400bf2 27 #include "btle_advertising.h"
Vincent Coubard 638:c90ae1400bf2 28 #include "custom/custom_helper.h"
Vincent Coubard 638:c90ae1400bf2 29
Vincent Coubard 638:c90ae1400bf2 30 #include "ble/GapEvents.h"
Vincent Coubard 638:c90ae1400bf2 31 #include "nRF5xn.h"
Vincent Coubard 638:c90ae1400bf2 32
Vincent Coubard 638:c90ae1400bf2 33 extern "C" {
Vincent Coubard 638:c90ae1400bf2 34 #include "pstorage.h"
Vincent Coubard 638:c90ae1400bf2 35 #include "device_manager.h"
Vincent Coubard 638:c90ae1400bf2 36 #include "softdevice_handler.h"
Vincent Coubard 638:c90ae1400bf2 37 #include "ble_stack_handler_types.h"
Vincent Coubard 638:c90ae1400bf2 38 }
Vincent Coubard 638:c90ae1400bf2 39
Vincent Coubard 638:c90ae1400bf2 40 #include "nrf_ble_hci.h"
Vincent Coubard 638:c90ae1400bf2 41 #include "btle_discovery.h"
Vincent Coubard 638:c90ae1400bf2 42
Vincent Coubard 638:c90ae1400bf2 43 #include "nRF5xGattClient.h"
Vincent Coubard 638:c90ae1400bf2 44 #include "nRF5xServiceDiscovery.h"
Vincent Coubard 638:c90ae1400bf2 45 #include "nRF5xCharacteristicDescriptorDiscoverer.h"
Vincent Coubard 638:c90ae1400bf2 46
Vincent Coubard 638:c90ae1400bf2 47 bool isEventsSignaled = false;
Vincent Coubard 638:c90ae1400bf2 48
Vincent Coubard 638:c90ae1400bf2 49 extern "C" void assert_nrf_callback(uint16_t line_num, const uint8_t *p_file_name);
Vincent Coubard 638:c90ae1400bf2 50 void app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t *p_file_name);
Vincent Coubard 638:c90ae1400bf2 51
Vincent Coubard 638:c90ae1400bf2 52 static void btle_handler(ble_evt_t *p_ble_evt);
Vincent Coubard 638:c90ae1400bf2 53
Vincent Coubard 638:c90ae1400bf2 54 #if 0
Vincent Coubard 638:c90ae1400bf2 55 #define CENTRAL_LINK_COUNT (YOTTA_CFG_NORDIC_BLE_CENTRAL_LINKS) /**<number of central links used by the application. When changing this number remember to adjust the RAM settings */
Vincent Coubard 638:c90ae1400bf2 56 /** If value for YOTTA_CFG_NORDIC_BLE_PERIPHERAL_LINKS was used, ram settings are adjusted by the yotta target module. */
Vincent Coubard 638:c90ae1400bf2 57 #define PERIPHERAL_LINK_COUNT (YOTTA_CFG_NORDIC_BLE_PERIPHERAL_LINKS) /**<number of peripheral links used by the application. When changing this number remember to adjust the RAM settings*/
Vincent Coubard 638:c90ae1400bf2 58 /** If value for YOTTA_CFG_NORDIC_BLE_CENTRAL_LINKS was used, ram settings are adjusted by the yotta target module. */
Vincent Coubard 638:c90ae1400bf2 59 #define GATTS_ATTR_TAB_SIZE (YOTTA_CFG_NORDIC_BLE_GATTS_ATTR_TAB_SIZE) /**< GATTS attribite table size. */
Vincent Coubard 638:c90ae1400bf2 60 /** If value for YOTTA_CFG_NORDIC_BLE_GATTS_ATTR_TAB_SIZE was used, ram settings are adjusted by the yotta target module. */
Vincent Coubard 638:c90ae1400bf2 61 #else
Vincent Coubard 638:c90ae1400bf2 62 #define CENTRAL_LINK_COUNT 3 /**<number of central links used by the application. When changing this number remember to adjust the RAM settings */
Vincent Coubard 638:c90ae1400bf2 63 /** If value for YOTTA_CFG_NORDIC_BLE_PERIPHERAL_LINKS was used, ram settings are adjusted by the yotta target module. */
Vincent Coubard 638:c90ae1400bf2 64 #define PERIPHERAL_LINK_COUNT 1 /**<number of peripheral links used by the application. When changing this number remember to adjust the RAM settings*/
Vincent Coubard 638:c90ae1400bf2 65 /** If value for YOTTA_CFG_NORDIC_BLE_CENTRAL_LINKS was used, ram settings are adjusted by the yotta target module. */
Vincent Coubard 638:c90ae1400bf2 66 #define GATTS_ATTR_TAB_SIZE 0x600 /**< GATTS attribite table size. */
Vincent Coubard 638:c90ae1400bf2 67 /** If value for YOTTA_CFG_NORDIC_BLE_GATTS_ATTR_TAB_SIZE was used, ram settings are adjusted by the yotta target module. */
Vincent Coubard 638:c90ae1400bf2 68
Vincent Coubard 638:c90ae1400bf2 69 #endif
Vincent Coubard 638:c90ae1400bf2 70
Vincent Coubard 638:c90ae1400bf2 71 static void sys_evt_dispatch(uint32_t sys_evt)
Vincent Coubard 638:c90ae1400bf2 72 {
Vincent Coubard 638:c90ae1400bf2 73 pstorage_sys_event_handler(sys_evt);
Vincent Coubard 638:c90ae1400bf2 74 }
Vincent Coubard 638:c90ae1400bf2 75
Vincent Coubard 638:c90ae1400bf2 76 /**
Vincent Coubard 638:c90ae1400bf2 77 * This function is called in interrupt context to handle BLE events; i.e. pull
Vincent Coubard 638:c90ae1400bf2 78 * system and user events out of the pending events-queue of the BLE stack. The
Vincent Coubard 638:c90ae1400bf2 79 * BLE stack signals the availability of events by the triggering the SWI2
Vincent Coubard 638:c90ae1400bf2 80 * interrupt, which forwards the handling to this function.
Vincent Coubard 638:c90ae1400bf2 81 *
Vincent Coubard 638:c90ae1400bf2 82 * The event processing loop is implemented in intern_softdevice_events_execute().
Vincent Coubard 638:c90ae1400bf2 83 *
Vincent Coubard 638:c90ae1400bf2 84 * This function will signal to the user code by calling signalEventsToProcess
Vincent Coubard 638:c90ae1400bf2 85 * that their is events to process and BLE::processEvents should be called.
Vincent Coubard 638:c90ae1400bf2 86 */
Vincent Coubard 638:c90ae1400bf2 87 static uint32_t signalEvent()
Vincent Coubard 638:c90ae1400bf2 88 {
Vincent Coubard 638:c90ae1400bf2 89 if(isEventsSignaled == false) {
Vincent Coubard 638:c90ae1400bf2 90 isEventsSignaled = true;
Vincent Coubard 638:c90ae1400bf2 91 nRF5xn::Instance(BLE::DEFAULT_INSTANCE).signalEventsToProcess(BLE::DEFAULT_INSTANCE);
Vincent Coubard 638:c90ae1400bf2 92 }
Vincent Coubard 638:c90ae1400bf2 93 return NRF_SUCCESS;
Vincent Coubard 638:c90ae1400bf2 94 }
Vincent Coubard 638:c90ae1400bf2 95
Vincent Coubard 638:c90ae1400bf2 96 error_t btle_init(void)
Vincent Coubard 638:c90ae1400bf2 97 {
Vincent Coubard 638:c90ae1400bf2 98 nrf_clock_lf_cfg_t clockConfiguration;
Vincent Coubard 638:c90ae1400bf2 99
Vincent Coubard 638:c90ae1400bf2 100 // Configure the LF clock according to values provided by btle_clock.h.
Vincent Coubard 638:c90ae1400bf2 101 // It is input from the chain of the yotta configuration system.
Vincent Coubard 638:c90ae1400bf2 102 clockConfiguration.source = LFCLK_CONF_SOURCE;
Vincent Coubard 638:c90ae1400bf2 103 clockConfiguration.xtal_accuracy = LFCLK_CONF_ACCURACY;
Vincent Coubard 638:c90ae1400bf2 104 clockConfiguration.rc_ctiv = LFCLK_CONF_RC_CTIV;
Vincent Coubard 638:c90ae1400bf2 105 clockConfiguration.rc_temp_ctiv = LFCLK_CONF_RC_TEMP_CTIV;
Vincent Coubard 638:c90ae1400bf2 106
Vincent Coubard 638:c90ae1400bf2 107 SOFTDEVICE_HANDLER_INIT(&clockConfiguration, signalEvent);
Vincent Coubard 638:c90ae1400bf2 108
Vincent Coubard 638:c90ae1400bf2 109 // Enable BLE stack
Vincent Coubard 638:c90ae1400bf2 110 /**
Vincent Coubard 638:c90ae1400bf2 111 * Using this call, the application can select whether to include the
Vincent Coubard 638:c90ae1400bf2 112 * Service Changed characteristic in the GATT Server. The default in all
Vincent Coubard 638:c90ae1400bf2 113 * previous releases has been to include the Service Changed characteristic,
Vincent Coubard 638:c90ae1400bf2 114 * but this affects how GATT clients behave. Specifically, it requires
Vincent Coubard 638:c90ae1400bf2 115 * clients to subscribe to this attribute and not to cache attribute handles
Vincent Coubard 638:c90ae1400bf2 116 * between connections unless the devices are bonded. If the application
Vincent Coubard 638:c90ae1400bf2 117 * does not need to change the structure of the GATT server attributes at
Vincent Coubard 638:c90ae1400bf2 118 * runtime this adds unnecessary complexity to the interaction with peer
Vincent Coubard 638:c90ae1400bf2 119 * clients. If the SoftDevice is enabled with the Service Changed
Vincent Coubard 638:c90ae1400bf2 120 * Characteristics turned off, then clients are allowed to cache attribute
Vincent Coubard 638:c90ae1400bf2 121 * handles making applications simpler on both sides.
Vincent Coubard 638:c90ae1400bf2 122 */
Vincent Coubard 638:c90ae1400bf2 123 static const bool IS_SRVC_CHANGED_CHARACT_PRESENT = true;
Vincent Coubard 638:c90ae1400bf2 124
Vincent Coubard 638:c90ae1400bf2 125 ble_enable_params_t ble_enable_params;
Vincent Coubard 638:c90ae1400bf2 126 uint32_t err_code = softdevice_enable_get_default_config(CENTRAL_LINK_COUNT,
Vincent Coubard 638:c90ae1400bf2 127 PERIPHERAL_LINK_COUNT,
Vincent Coubard 638:c90ae1400bf2 128 &ble_enable_params);
Vincent Coubard 638:c90ae1400bf2 129
Vincent Coubard 638:c90ae1400bf2 130 ble_enable_params.gatts_enable_params.attr_tab_size = GATTS_ATTR_TAB_SIZE;
Vincent Coubard 638:c90ae1400bf2 131 ble_enable_params.gatts_enable_params.service_changed = IS_SRVC_CHANGED_CHARACT_PRESENT;
Vincent Coubard 638:c90ae1400bf2 132 ble_enable_params.common_enable_params.vs_uuid_count = UUID_TABLE_MAX_ENTRIES;
Vincent Coubard 638:c90ae1400bf2 133
Vincent Coubard 638:c90ae1400bf2 134 if(err_code != NRF_SUCCESS) {
Vincent Coubard 638:c90ae1400bf2 135 return ERROR_INVALID_PARAM;
Vincent Coubard 638:c90ae1400bf2 136 }
Vincent Coubard 638:c90ae1400bf2 137
Vincent Coubard 638:c90ae1400bf2 138 if (softdevice_enable(&ble_enable_params) != NRF_SUCCESS) {
Vincent Coubard 638:c90ae1400bf2 139 return ERROR_INVALID_PARAM;
Vincent Coubard 638:c90ae1400bf2 140 }
Vincent Coubard 638:c90ae1400bf2 141
Vincent Coubard 638:c90ae1400bf2 142 ble_gap_addr_t addr;
Vincent Coubard 638:c90ae1400bf2 143 if (sd_ble_gap_address_get(&addr) != NRF_SUCCESS) {
Vincent Coubard 638:c90ae1400bf2 144 return ERROR_INVALID_PARAM;
Vincent Coubard 638:c90ae1400bf2 145 }
Vincent Coubard 638:c90ae1400bf2 146 if (sd_ble_gap_address_set(BLE_GAP_ADDR_CYCLE_MODE_NONE, &addr) != NRF_SUCCESS) {
Vincent Coubard 638:c90ae1400bf2 147 return ERROR_INVALID_PARAM;
Vincent Coubard 638:c90ae1400bf2 148 }
Vincent Coubard 638:c90ae1400bf2 149
Vincent Coubard 638:c90ae1400bf2 150 ASSERT_STATUS( softdevice_ble_evt_handler_set(btle_handler));
Vincent Coubard 638:c90ae1400bf2 151 ASSERT_STATUS( softdevice_sys_evt_handler_set(sys_evt_dispatch));
Vincent Coubard 638:c90ae1400bf2 152
Vincent Coubard 638:c90ae1400bf2 153 return btle_gap_init();
Vincent Coubard 638:c90ae1400bf2 154 }
Vincent Coubard 638:c90ae1400bf2 155
Vincent Coubard 638:c90ae1400bf2 156 static void btle_handler(ble_evt_t *p_ble_evt)
Vincent Coubard 638:c90ae1400bf2 157 {
Vincent Coubard 638:c90ae1400bf2 158 /* Library service handlers */
Vincent Coubard 638:c90ae1400bf2 159 #if SDK_CONN_PARAMS_MODULE_ENABLE
Vincent Coubard 638:c90ae1400bf2 160 ble_conn_params_on_ble_evt(p_ble_evt);
Vincent Coubard 638:c90ae1400bf2 161 #endif
Vincent Coubard 638:c90ae1400bf2 162
Vincent Coubard 638:c90ae1400bf2 163 dm_ble_evt_handler(p_ble_evt);
Vincent Coubard 638:c90ae1400bf2 164
Vincent Coubard 638:c90ae1400bf2 165 #if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
Vincent Coubard 638:c90ae1400bf2 166 bleGattcEventHandler(p_ble_evt);
Vincent Coubard 638:c90ae1400bf2 167 #endif
Vincent Coubard 638:c90ae1400bf2 168
Vincent Coubard 638:c90ae1400bf2 169 nRF5xn &ble = nRF5xn::Instance(BLE::DEFAULT_INSTANCE);
Vincent Coubard 638:c90ae1400bf2 170 nRF5xGap &gap = (nRF5xGap &) ble.getGap();
Vincent Coubard 638:c90ae1400bf2 171 nRF5xGattServer &gattServer = (nRF5xGattServer &) ble.getGattServer();
Vincent Coubard 638:c90ae1400bf2 172 nRF5xSecurityManager &securityManager = (nRF5xSecurityManager &) ble.getSecurityManager();
Vincent Coubard 638:c90ae1400bf2 173
Vincent Coubard 638:c90ae1400bf2 174 /* Custom event handler */
Vincent Coubard 638:c90ae1400bf2 175 switch (p_ble_evt->header.evt_id) {
Vincent Coubard 638:c90ae1400bf2 176 case BLE_GAP_EVT_CONNECTED: {
Vincent Coubard 638:c90ae1400bf2 177 Gap::Handle_t handle = p_ble_evt->evt.gap_evt.conn_handle;
Vincent Coubard 638:c90ae1400bf2 178 #if defined(TARGET_MCU_NRF51_16K_S110) || defined(TARGET_MCU_NRF51_32K_S110)
Vincent Coubard 638:c90ae1400bf2 179 /* Only peripheral role is supported by S110 */
Vincent Coubard 638:c90ae1400bf2 180 Gap::Role_t role = Gap::PERIPHERAL;
Vincent Coubard 638:c90ae1400bf2 181 #else
Vincent Coubard 638:c90ae1400bf2 182 Gap::Role_t role = static_cast<Gap::Role_t>(p_ble_evt->evt.gap_evt.params.connected.role);
Vincent Coubard 638:c90ae1400bf2 183 #endif
Vincent Coubard 638:c90ae1400bf2 184 gap.setConnectionHandle(handle);
Vincent Coubard 638:c90ae1400bf2 185 const Gap::ConnectionParams_t *params = reinterpret_cast<Gap::ConnectionParams_t *>(&(p_ble_evt->evt.gap_evt.params.connected.conn_params));
Vincent Coubard 638:c90ae1400bf2 186 const ble_gap_addr_t *peer = &p_ble_evt->evt.gap_evt.params.connected.peer_addr;
Vincent Coubard 638:c90ae1400bf2 187 const ble_gap_addr_t *own = &p_ble_evt->evt.gap_evt.params.connected.own_addr;
Vincent Coubard 638:c90ae1400bf2 188 gap.processConnectionEvent(handle,
Vincent Coubard 638:c90ae1400bf2 189 role,
Vincent Coubard 638:c90ae1400bf2 190 static_cast<BLEProtocol::AddressType_t>(peer->addr_type), peer->addr,
Vincent Coubard 638:c90ae1400bf2 191 static_cast<BLEProtocol::AddressType_t>(own->addr_type), own->addr,
Vincent Coubard 638:c90ae1400bf2 192 params);
Vincent Coubard 638:c90ae1400bf2 193 break;
Vincent Coubard 638:c90ae1400bf2 194 }
Vincent Coubard 638:c90ae1400bf2 195
Vincent Coubard 638:c90ae1400bf2 196 case BLE_GAP_EVT_DISCONNECTED: {
Vincent Coubard 638:c90ae1400bf2 197 Gap::Handle_t handle = p_ble_evt->evt.gap_evt.conn_handle;
Vincent Coubard 638:c90ae1400bf2 198 // Since we are not in a connection and have not started advertising,
Vincent Coubard 638:c90ae1400bf2 199 // store bonds
Vincent Coubard 638:c90ae1400bf2 200 gap.setConnectionHandle (BLE_CONN_HANDLE_INVALID);
Vincent Coubard 638:c90ae1400bf2 201
Vincent Coubard 638:c90ae1400bf2 202 Gap::DisconnectionReason_t reason;
Vincent Coubard 638:c90ae1400bf2 203 switch (p_ble_evt->evt.gap_evt.params.disconnected.reason) {
Vincent Coubard 638:c90ae1400bf2 204 case BLE_HCI_LOCAL_HOST_TERMINATED_CONNECTION:
Vincent Coubard 638:c90ae1400bf2 205 reason = Gap::LOCAL_HOST_TERMINATED_CONNECTION;
Vincent Coubard 638:c90ae1400bf2 206 break;
Vincent Coubard 638:c90ae1400bf2 207 case BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION:
Vincent Coubard 638:c90ae1400bf2 208 reason = Gap::REMOTE_USER_TERMINATED_CONNECTION;
Vincent Coubard 638:c90ae1400bf2 209 break;
Vincent Coubard 638:c90ae1400bf2 210 case BLE_HCI_CONN_INTERVAL_UNACCEPTABLE:
Vincent Coubard 638:c90ae1400bf2 211 reason = Gap::CONN_INTERVAL_UNACCEPTABLE;
Vincent Coubard 638:c90ae1400bf2 212 break;
Vincent Coubard 638:c90ae1400bf2 213 default:
Vincent Coubard 638:c90ae1400bf2 214 /* Please refer to the underlying transport library for an
Vincent Coubard 638:c90ae1400bf2 215 * interpretion of this reason's value. */
Vincent Coubard 638:c90ae1400bf2 216 reason = static_cast<Gap::DisconnectionReason_t>(p_ble_evt->evt.gap_evt.params.disconnected.reason);
Vincent Coubard 638:c90ae1400bf2 217 break;
Vincent Coubard 638:c90ae1400bf2 218 }
Vincent Coubard 638:c90ae1400bf2 219
Vincent Coubard 638:c90ae1400bf2 220 #if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
Vincent Coubard 638:c90ae1400bf2 221 // Close all pending discoveries for this connection
Vincent Coubard 638:c90ae1400bf2 222 nRF5xGattClient& gattClient = ble.getGattClient();
Vincent Coubard 638:c90ae1400bf2 223 gattClient.characteristicDescriptorDiscoverer().terminate(handle, BLE_ERROR_INVALID_STATE);
Vincent Coubard 638:c90ae1400bf2 224 gattClient.discovery().terminate(handle);
Vincent Coubard 638:c90ae1400bf2 225 #endif
Vincent Coubard 638:c90ae1400bf2 226
Vincent Coubard 638:c90ae1400bf2 227 gap.processDisconnectionEvent(handle, reason);
Vincent Coubard 638:c90ae1400bf2 228 break;
Vincent Coubard 638:c90ae1400bf2 229 }
Vincent Coubard 638:c90ae1400bf2 230
Vincent Coubard 638:c90ae1400bf2 231 case BLE_GAP_EVT_PASSKEY_DISPLAY:
Vincent Coubard 638:c90ae1400bf2 232 securityManager.processPasskeyDisplayEvent(p_ble_evt->evt.gap_evt.conn_handle, p_ble_evt->evt.gap_evt.params.passkey_display.passkey);
Vincent Coubard 638:c90ae1400bf2 233 break;
Vincent Coubard 638:c90ae1400bf2 234
Vincent Coubard 638:c90ae1400bf2 235 case BLE_GAP_EVT_TIMEOUT:
Vincent Coubard 638:c90ae1400bf2 236 gap.processTimeoutEvent(static_cast<Gap::TimeoutSource_t>(p_ble_evt->evt.gap_evt.params.timeout.src));
Vincent Coubard 638:c90ae1400bf2 237 break;
Vincent Coubard 638:c90ae1400bf2 238
Vincent Coubard 638:c90ae1400bf2 239 case BLE_GATTC_EVT_TIMEOUT:
Vincent Coubard 638:c90ae1400bf2 240 case BLE_GATTS_EVT_TIMEOUT:
Vincent Coubard 638:c90ae1400bf2 241 // Disconnect on GATT Server and Client timeout events.
Vincent Coubard 638:c90ae1400bf2 242 // ASSERT_STATUS_RET_VOID (sd_ble_gap_disconnect(m_conn_handle,
Vincent Coubard 638:c90ae1400bf2 243 // BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION));
Vincent Coubard 638:c90ae1400bf2 244 break;
Vincent Coubard 638:c90ae1400bf2 245
Vincent Coubard 638:c90ae1400bf2 246 case BLE_GAP_EVT_ADV_REPORT: {
Vincent Coubard 638:c90ae1400bf2 247 const ble_gap_evt_adv_report_t *advReport = &p_ble_evt->evt.gap_evt.params.adv_report;
Vincent Coubard 638:c90ae1400bf2 248 gap.processAdvertisementReport(advReport->peer_addr.addr,
Vincent Coubard 638:c90ae1400bf2 249 advReport->rssi,
Vincent Coubard 638:c90ae1400bf2 250 advReport->scan_rsp,
Vincent Coubard 638:c90ae1400bf2 251 static_cast<GapAdvertisingParams::AdvertisingType_t>(advReport->type),
Vincent Coubard 638:c90ae1400bf2 252 advReport->dlen,
Vincent Coubard 638:c90ae1400bf2 253 advReport->data);
Vincent Coubard 638:c90ae1400bf2 254 break;
Vincent Coubard 638:c90ae1400bf2 255 }
Vincent Coubard 638:c90ae1400bf2 256
Vincent Coubard 638:c90ae1400bf2 257 default:
Vincent Coubard 638:c90ae1400bf2 258 break;
Vincent Coubard 638:c90ae1400bf2 259 }
Vincent Coubard 638:c90ae1400bf2 260
Vincent Coubard 638:c90ae1400bf2 261 gattServer.hwCallback(p_ble_evt);
Vincent Coubard 638:c90ae1400bf2 262 }
Vincent Coubard 638:c90ae1400bf2 263
Vincent Coubard 638:c90ae1400bf2 264 /*! @brief Callback when an error occurs inside the SoftDevice */
Vincent Coubard 638:c90ae1400bf2 265 void assert_nrf_callback(uint16_t line_num, const uint8_t *p_file_name)
Vincent Coubard 638:c90ae1400bf2 266 {
Vincent Coubard 638:c90ae1400bf2 267 ASSERT(false, (void) 0);
Vincent Coubard 638:c90ae1400bf2 268 }
Vincent Coubard 638:c90ae1400bf2 269
Vincent Coubard 638:c90ae1400bf2 270 /*!
Vincent Coubard 638:c90ae1400bf2 271 @brief Handler for general errors above the SoftDevice layer.
Vincent Coubard 638:c90ae1400bf2 272 Typically we can' recover from this so we do a reset.
Vincent Coubard 638:c90ae1400bf2 273 */
Vincent Coubard 638:c90ae1400bf2 274 void app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t *p_file_name)
Vincent Coubard 638:c90ae1400bf2 275 {
Vincent Coubard 638:c90ae1400bf2 276 ASSERT_STATUS_RET_VOID( error_code );
Vincent Coubard 638:c90ae1400bf2 277 NVIC_SystemReset();
Vincent Coubard 638:c90ae1400bf2 278 }