2015-05-06 10:37:01 +00:00
|
|
|
/* mbed Microcontroller Library
|
|
|
|
* Copyright (c) 2006-2013 ARM Limited
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2015-07-06 13:17:22 +00:00
|
|
|
#include "nRF5xServiceDiscovery.h"
|
2015-11-13 14:53:46 +00:00
|
|
|
#include "nRF5xCharacteristicDescriptorDiscoverer.h"
|
2015-07-06 13:17:22 +00:00
|
|
|
#include "nRF5xGattClient.h"
|
Modify shutdown due to BLE API change
The module is updated to comply with the changes to BLE API regarding correct
shutdown functionality. The following changes are introduced to ble-nrf51822:
* Calls to the old static function shutdown in Gap, GattClient, GattServer and
SecurityManager are removed.
* The cleanup function in Gap, GattClient, GattServer and SecurityManager is
renamed to `reset()` and made public.
* The static references inside nRF5xGap, nRF5xGattClient, nRF5xGattServer and
nRF5xSecurityManager to objects of their own class are moved to nRF5xn.
* The static getInstance accessors in nRF5xGap, nRF5xGattClient,
nRF5xGattServer and nRF5xSecurityManager are removed and their functionality is
moved to the implemented virtual accessors in nRF5xn i.e. getGap(),
getGattClient, etc.
* A static function Instance is added to nRF5xn class to make the transport
object accessible across the module.
2015-12-14 15:15:35 +00:00
|
|
|
#include "nRF5xn.h"
|
2015-05-06 13:32:05 +00:00
|
|
|
|
2015-10-05 12:15:35 +00:00
|
|
|
#if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
|
2015-05-06 10:37:01 +00:00
|
|
|
void bleGattcEventHandler(const ble_evt_t *p_ble_evt)
|
|
|
|
{
|
Modify shutdown due to BLE API change
The module is updated to comply with the changes to BLE API regarding correct
shutdown functionality. The following changes are introduced to ble-nrf51822:
* Calls to the old static function shutdown in Gap, GattClient, GattServer and
SecurityManager are removed.
* The cleanup function in Gap, GattClient, GattServer and SecurityManager is
renamed to `reset()` and made public.
* The static references inside nRF5xGap, nRF5xGattClient, nRF5xGattServer and
nRF5xSecurityManager to objects of their own class are moved to nRF5xn.
* The static getInstance accessors in nRF5xGap, nRF5xGattClient,
nRF5xGattServer and nRF5xSecurityManager are removed and their functionality is
moved to the implemented virtual accessors in nRF5xn i.e. getGap(),
getGattClient, etc.
* A static function Instance is added to nRF5xn class to make the transport
object accessible across the module.
2015-12-14 15:15:35 +00:00
|
|
|
nRF5xn &ble = nRF5xn::Instance(BLE::DEFAULT_INSTANCE);
|
|
|
|
nRF5xGap &gap = (nRF5xGap &) ble.getGap();
|
|
|
|
nRF5xGattClient &gattClient = (nRF5xGattClient &) ble.getGattClient();
|
2015-12-22 17:53:52 +00:00
|
|
|
nRF5xServiceDiscovery &sdSingleton = gattClient.discovery();
|
|
|
|
nRF5xCharacteristicDescriptorDiscoverer &characteristicDescriptorDiscoverer =
|
|
|
|
gattClient.characteristicDescriptorDiscoverer();
|
2015-06-04 13:44:44 +00:00
|
|
|
|
2015-05-06 10:37:01 +00:00
|
|
|
switch (p_ble_evt->header.evt_id) {
|
|
|
|
case BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP:
|
|
|
|
switch (p_ble_evt->evt.gattc_evt.gatt_status) {
|
|
|
|
case BLE_GATT_STATUS_SUCCESS:
|
2015-05-22 08:10:29 +00:00
|
|
|
sdSingleton.setupDiscoveredServices(&p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp);
|
2015-05-06 10:37:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_FOUND:
|
|
|
|
default:
|
2015-05-22 08:10:29 +00:00
|
|
|
sdSingleton.terminate();
|
2015-05-06 10:37:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BLE_GATTC_EVT_CHAR_DISC_RSP:
|
|
|
|
switch (p_ble_evt->evt.gattc_evt.gatt_status) {
|
|
|
|
case BLE_GATT_STATUS_SUCCESS:
|
2015-05-22 08:10:29 +00:00
|
|
|
sdSingleton.setupDiscoveredCharacteristics(&p_ble_evt->evt.gattc_evt.params.char_disc_rsp);
|
2015-05-06 10:37:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_FOUND:
|
|
|
|
default:
|
2015-11-17 14:20:17 +00:00
|
|
|
sdSingleton.terminateCharacteristicDiscovery(BLE_ERROR_NONE);
|
2015-05-06 10:37:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2015-05-28 07:23:12 +00:00
|
|
|
|
|
|
|
case BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP:
|
2015-05-26 10:32:51 +00:00
|
|
|
if (sdSingleton.isActive()) {
|
|
|
|
sdSingleton.processDiscoverUUIDResponse(&p_ble_evt->evt.gattc_evt.params.char_val_by_uuid_read_rsp);
|
|
|
|
}
|
|
|
|
break;
|
2015-06-02 08:08:03 +00:00
|
|
|
|
2015-07-01 07:18:38 +00:00
|
|
|
case BLE_GATTC_EVT_READ_RSP: {
|
2015-06-05 10:16:31 +00:00
|
|
|
GattReadCallbackParams response = {
|
2015-07-15 09:58:21 +00:00
|
|
|
.connHandle = p_ble_evt->evt.gattc_evt.conn_handle,
|
|
|
|
.handle = p_ble_evt->evt.gattc_evt.params.read_rsp.handle,
|
|
|
|
.offset = p_ble_evt->evt.gattc_evt.params.read_rsp.offset,
|
|
|
|
.len = p_ble_evt->evt.gattc_evt.params.read_rsp.len,
|
|
|
|
.data = p_ble_evt->evt.gattc_evt.params.read_rsp.data,
|
2015-06-02 08:08:03 +00:00
|
|
|
};
|
Modify shutdown due to BLE API change
The module is updated to comply with the changes to BLE API regarding correct
shutdown functionality. The following changes are introduced to ble-nrf51822:
* Calls to the old static function shutdown in Gap, GattClient, GattServer and
SecurityManager are removed.
* The cleanup function in Gap, GattClient, GattServer and SecurityManager is
renamed to `reset()` and made public.
* The static references inside nRF5xGap, nRF5xGattClient, nRF5xGattServer and
nRF5xSecurityManager to objects of their own class are moved to nRF5xn.
* The static getInstance accessors in nRF5xGap, nRF5xGattClient,
nRF5xGattServer and nRF5xSecurityManager are removed and their functionality is
moved to the implemented virtual accessors in nRF5xn i.e. getGap(),
getGattClient, etc.
* A static function Instance is added to nRF5xn class to make the transport
object accessible across the module.
2015-12-14 15:15:35 +00:00
|
|
|
gattClient.processReadResponse(&response);
|
2015-06-02 08:08:03 +00:00
|
|
|
}
|
|
|
|
break;
|
2015-06-05 12:30:48 +00:00
|
|
|
|
2015-07-01 07:18:38 +00:00
|
|
|
case BLE_GATTC_EVT_WRITE_RSP: {
|
2015-06-05 12:30:48 +00:00
|
|
|
GattWriteCallbackParams response = {
|
2015-07-15 09:58:21 +00:00
|
|
|
.connHandle = p_ble_evt->evt.gattc_evt.conn_handle,
|
|
|
|
.handle = p_ble_evt->evt.gattc_evt.params.write_rsp.handle,
|
|
|
|
.writeOp = (GattWriteCallbackParams::WriteOp_t)(p_ble_evt->evt.gattc_evt.params.write_rsp.write_op),
|
|
|
|
.offset = p_ble_evt->evt.gattc_evt.params.write_rsp.offset,
|
|
|
|
.len = p_ble_evt->evt.gattc_evt.params.write_rsp.len,
|
|
|
|
.data = p_ble_evt->evt.gattc_evt.params.write_rsp.data,
|
2015-06-05 12:30:48 +00:00
|
|
|
};
|
Modify shutdown due to BLE API change
The module is updated to comply with the changes to BLE API regarding correct
shutdown functionality. The following changes are introduced to ble-nrf51822:
* Calls to the old static function shutdown in Gap, GattClient, GattServer and
SecurityManager are removed.
* The cleanup function in Gap, GattClient, GattServer and SecurityManager is
renamed to `reset()` and made public.
* The static references inside nRF5xGap, nRF5xGattClient, nRF5xGattServer and
nRF5xSecurityManager to objects of their own class are moved to nRF5xn.
* The static getInstance accessors in nRF5xGap, nRF5xGattClient,
nRF5xGattServer and nRF5xSecurityManager are removed and their functionality is
moved to the implemented virtual accessors in nRF5xn i.e. getGap(),
getGattClient, etc.
* A static function Instance is added to nRF5xn class to make the transport
object accessible across the module.
2015-12-14 15:15:35 +00:00
|
|
|
gattClient.processWriteResponse(&response);
|
2015-06-05 12:30:48 +00:00
|
|
|
}
|
|
|
|
break;
|
2015-07-06 08:09:34 +00:00
|
|
|
|
|
|
|
case BLE_GATTC_EVT_HVX: {
|
|
|
|
GattHVXCallbackParams params;
|
2015-07-15 09:58:21 +00:00
|
|
|
params.connHandle = p_ble_evt->evt.gattc_evt.conn_handle;
|
|
|
|
params.handle = p_ble_evt->evt.gattc_evt.params.hvx.handle;
|
|
|
|
params.type = static_cast<HVXType_t>(p_ble_evt->evt.gattc_evt.params.hvx.type);
|
|
|
|
params.len = p_ble_evt->evt.gattc_evt.params.hvx.len;
|
|
|
|
params.data = p_ble_evt->evt.gattc_evt.params.hvx.data;
|
2015-07-06 08:09:34 +00:00
|
|
|
|
Modify shutdown due to BLE API change
The module is updated to comply with the changes to BLE API regarding correct
shutdown functionality. The following changes are introduced to ble-nrf51822:
* Calls to the old static function shutdown in Gap, GattClient, GattServer and
SecurityManager are removed.
* The cleanup function in Gap, GattClient, GattServer and SecurityManager is
renamed to `reset()` and made public.
* The static references inside nRF5xGap, nRF5xGattClient, nRF5xGattServer and
nRF5xSecurityManager to objects of their own class are moved to nRF5xn.
* The static getInstance accessors in nRF5xGap, nRF5xGattClient,
nRF5xGattServer and nRF5xSecurityManager are removed and their functionality is
moved to the implemented virtual accessors in nRF5xn i.e. getGap(),
getGattClient, etc.
* A static function Instance is added to nRF5xn class to make the transport
object accessible across the module.
2015-12-14 15:15:35 +00:00
|
|
|
gattClient.processHVXEvent(¶ms);
|
2015-07-06 08:09:34 +00:00
|
|
|
}
|
|
|
|
break;
|
2015-11-13 14:53:46 +00:00
|
|
|
|
|
|
|
case BLE_GATTC_EVT_DESC_DISC_RSP: {
|
|
|
|
uint16_t conn_handle = p_ble_evt->evt.gattc_evt.conn_handle;
|
2015-11-17 10:24:57 +00:00
|
|
|
uint16_t status = p_ble_evt->evt.gattc_evt.gatt_status;
|
2015-11-18 12:45:43 +00:00
|
|
|
const ble_gattc_evt_desc_disc_rsp_t& discovered_descriptors = p_ble_evt->evt.gattc_evt.params.desc_disc_rsp;
|
2015-11-13 14:53:46 +00:00
|
|
|
|
2015-12-22 17:53:52 +00:00
|
|
|
switch(status) {
|
2015-11-17 10:24:57 +00:00
|
|
|
case BLE_GATT_STATUS_SUCCESS:
|
|
|
|
characteristicDescriptorDiscoverer.process(
|
2015-12-22 17:53:52 +00:00
|
|
|
conn_handle,
|
2015-11-17 10:24:57 +00:00
|
|
|
discovered_descriptors
|
2015-12-22 17:53:52 +00:00
|
|
|
);
|
2015-11-17 10:24:57 +00:00
|
|
|
break;
|
|
|
|
case BLE_GATT_STATUS_ATTERR_ATTRIBUTE_NOT_FOUND:
|
2015-12-22 17:53:52 +00:00
|
|
|
// end of discovery
|
2015-11-17 10:24:57 +00:00
|
|
|
characteristicDescriptorDiscoverer.terminate(conn_handle, BLE_ERROR_NONE);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
characteristicDescriptorDiscoverer.terminate(conn_handle, BLE_ERROR_UNSPECIFIED);
|
|
|
|
break;
|
2015-11-13 14:53:46 +00:00
|
|
|
}
|
|
|
|
} break;
|
2015-05-06 10:37:01 +00:00
|
|
|
}
|
|
|
|
|
2015-05-22 08:10:29 +00:00
|
|
|
sdSingleton.progressCharacteristicDiscovery();
|
|
|
|
sdSingleton.progressServiceDiscovery();
|
2015-05-06 10:37:01 +00:00
|
|
|
}
|
2015-08-11 11:55:15 +00:00
|
|
|
#endif
|
2015-06-04 13:44:44 +00:00
|
|
|
|