This is an example of BLE GATT Client, which receives broadcast data from BLE_Server_BME280 ( a GATT server) , then transfers values up to mbed Device Connector (cloud).
Please refer details about BLEClient_mbedDevConn below. https://github.com/soramame21/BLEClient_mbedDevConn
The location of required BLE GATT server, BLE_Server_BME280, is at here. https://developer.mbed.org/users/edamame22/code/BLE_Server_BME280/
shields/TARGET_ST_BLUENRG/source/BlueNRGGap.cpp@2:b894b3508057, 2017-09-05 (annotated)
- Committer:
- Ren Boting
- Date:
- Tue Sep 05 11:56:13 2017 +0900
- Revision:
- 2:b894b3508057
- Parent:
- 0:29983394c6b6
Update all libraries and reform main.cpp
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
edamame22 | 0:29983394c6b6 | 1 | /* mbed Microcontroller Library |
edamame22 | 0:29983394c6b6 | 2 | * Copyright (c) 2006-2013 ARM Limited |
edamame22 | 0:29983394c6b6 | 3 | * |
edamame22 | 0:29983394c6b6 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
edamame22 | 0:29983394c6b6 | 5 | * you may not use this file except in compliance with the License. |
edamame22 | 0:29983394c6b6 | 6 | * You may obtain a copy of the License at |
edamame22 | 0:29983394c6b6 | 7 | * |
edamame22 | 0:29983394c6b6 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
edamame22 | 0:29983394c6b6 | 9 | * |
edamame22 | 0:29983394c6b6 | 10 | * Unless required by applicable law or agreed to in writing, software |
edamame22 | 0:29983394c6b6 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
edamame22 | 0:29983394c6b6 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
edamame22 | 0:29983394c6b6 | 13 | * See the License for the specific language governing permissions and |
edamame22 | 0:29983394c6b6 | 14 | * limitations under the License. |
edamame22 | 0:29983394c6b6 | 15 | */ |
edamame22 | 0:29983394c6b6 | 16 | |
edamame22 | 0:29983394c6b6 | 17 | |
edamame22 | 0:29983394c6b6 | 18 | /** |
edamame22 | 0:29983394c6b6 | 19 | ****************************************************************************** |
edamame22 | 0:29983394c6b6 | 20 | * @file BlueNRGGap.cpp |
edamame22 | 0:29983394c6b6 | 21 | * @author STMicroelectronics |
edamame22 | 0:29983394c6b6 | 22 | * @brief Implementation of BLE_API Gap Class |
edamame22 | 0:29983394c6b6 | 23 | ****************************************************************************** |
edamame22 | 0:29983394c6b6 | 24 | * @copy |
edamame22 | 0:29983394c6b6 | 25 | * |
edamame22 | 0:29983394c6b6 | 26 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS |
edamame22 | 0:29983394c6b6 | 27 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE |
edamame22 | 0:29983394c6b6 | 28 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY |
edamame22 | 0:29983394c6b6 | 29 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING |
edamame22 | 0:29983394c6b6 | 30 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE |
edamame22 | 0:29983394c6b6 | 31 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. |
edamame22 | 0:29983394c6b6 | 32 | * |
edamame22 | 0:29983394c6b6 | 33 | * <h2><center>© COPYRIGHT 2013 STMicroelectronics</center></h2> |
edamame22 | 0:29983394c6b6 | 34 | */ |
edamame22 | 0:29983394c6b6 | 35 | |
edamame22 | 0:29983394c6b6 | 36 | /** @defgroup BlueNRGGap |
edamame22 | 0:29983394c6b6 | 37 | * @brief BlueNRG BLE_API GAP Adaptation |
edamame22 | 0:29983394c6b6 | 38 | * @{ |
edamame22 | 0:29983394c6b6 | 39 | */ |
edamame22 | 0:29983394c6b6 | 40 | |
edamame22 | 0:29983394c6b6 | 41 | #include "BlueNRGDevice.h" |
edamame22 | 0:29983394c6b6 | 42 | #ifdef YOTTA_CFG_MBED_OS |
edamame22 | 0:29983394c6b6 | 43 | #include "mbed-drivers/mbed.h" |
edamame22 | 0:29983394c6b6 | 44 | #else |
edamame22 | 0:29983394c6b6 | 45 | #include "mbed.h" |
edamame22 | 0:29983394c6b6 | 46 | #endif |
edamame22 | 0:29983394c6b6 | 47 | #include "ble_payload.h" |
edamame22 | 0:29983394c6b6 | 48 | #include "ble_utils.h" |
edamame22 | 0:29983394c6b6 | 49 | #include "ble_debug.h" |
edamame22 | 0:29983394c6b6 | 50 | |
edamame22 | 0:29983394c6b6 | 51 | /* |
edamame22 | 0:29983394c6b6 | 52 | * Utility to process GAP specific events (e.g., Advertising timeout) |
edamame22 | 0:29983394c6b6 | 53 | */ |
edamame22 | 0:29983394c6b6 | 54 | void BlueNRGGap::Process(void) |
edamame22 | 0:29983394c6b6 | 55 | { |
edamame22 | 0:29983394c6b6 | 56 | if(AdvToFlag) { |
edamame22 | 0:29983394c6b6 | 57 | stopAdvertising(); |
edamame22 | 0:29983394c6b6 | 58 | } |
edamame22 | 0:29983394c6b6 | 59 | |
edamame22 | 0:29983394c6b6 | 60 | } |
edamame22 | 0:29983394c6b6 | 61 | |
edamame22 | 0:29983394c6b6 | 62 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 63 | /*! |
edamame22 | 0:29983394c6b6 | 64 | @brief Sets the advertising parameters and payload for the device. |
edamame22 | 0:29983394c6b6 | 65 | Note: Some data types give error when their adv data is updated using aci_gap_update_adv_data() API |
edamame22 | 0:29983394c6b6 | 66 | |
edamame22 | 0:29983394c6b6 | 67 | @params[in] advData |
edamame22 | 0:29983394c6b6 | 68 | The primary advertising data payload |
edamame22 | 0:29983394c6b6 | 69 | @params[in] scanResponse |
edamame22 | 0:29983394c6b6 | 70 | The optional Scan Response payload if the advertising |
edamame22 | 0:29983394c6b6 | 71 | type is set to \ref GapAdvertisingParams::ADV_SCANNABLE_UNDIRECTED |
edamame22 | 0:29983394c6b6 | 72 | in \ref GapAdveritinngParams |
edamame22 | 0:29983394c6b6 | 73 | |
edamame22 | 0:29983394c6b6 | 74 | @returns \ref ble_error_t |
edamame22 | 0:29983394c6b6 | 75 | |
edamame22 | 0:29983394c6b6 | 76 | @retval BLE_ERROR_NONE |
edamame22 | 0:29983394c6b6 | 77 | Everything executed properly |
edamame22 | 0:29983394c6b6 | 78 | |
edamame22 | 0:29983394c6b6 | 79 | @retval BLE_ERROR_BUFFER_OVERFLOW |
edamame22 | 0:29983394c6b6 | 80 | The proposed action would cause a buffer overflow. All |
edamame22 | 0:29983394c6b6 | 81 | advertising payloads must be <= 31 bytes, for example. |
edamame22 | 0:29983394c6b6 | 82 | |
edamame22 | 0:29983394c6b6 | 83 | @retval BLE_ERROR_NOT_IMPLEMENTED |
edamame22 | 0:29983394c6b6 | 84 | A feature was requested that is not yet supported in the |
edamame22 | 0:29983394c6b6 | 85 | nRF51 firmware or hardware. |
edamame22 | 0:29983394c6b6 | 86 | |
edamame22 | 0:29983394c6b6 | 87 | @retval BLE_ERROR_PARAM_OUT_OF_RANGE |
edamame22 | 0:29983394c6b6 | 88 | One of the proposed values is outside the valid range. |
edamame22 | 0:29983394c6b6 | 89 | |
edamame22 | 0:29983394c6b6 | 90 | @section EXAMPLE |
edamame22 | 0:29983394c6b6 | 91 | |
edamame22 | 0:29983394c6b6 | 92 | @code |
edamame22 | 0:29983394c6b6 | 93 | |
edamame22 | 0:29983394c6b6 | 94 | @endcode |
edamame22 | 0:29983394c6b6 | 95 | */ |
edamame22 | 0:29983394c6b6 | 96 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 97 | ble_error_t BlueNRGGap::setAdvertisingData(const GapAdvertisingData &advData, const GapAdvertisingData &scanResponse) |
edamame22 | 0:29983394c6b6 | 98 | { |
edamame22 | 0:29983394c6b6 | 99 | PRINTF("BlueNRGGap::setAdvertisingData\n\r"); |
edamame22 | 0:29983394c6b6 | 100 | /* Make sure we don't exceed the advertising payload length */ |
edamame22 | 0:29983394c6b6 | 101 | if (advData.getPayloadLen() > GAP_ADVERTISING_DATA_MAX_PAYLOAD) { |
edamame22 | 0:29983394c6b6 | 102 | PRINTF("Exceeded the advertising payload length\n\r"); |
edamame22 | 0:29983394c6b6 | 103 | return BLE_ERROR_BUFFER_OVERFLOW; |
edamame22 | 0:29983394c6b6 | 104 | } |
edamame22 | 0:29983394c6b6 | 105 | |
edamame22 | 0:29983394c6b6 | 106 | /* Make sure we have a payload! */ |
edamame22 | 0:29983394c6b6 | 107 | if (advData.getPayloadLen() != 0) { |
edamame22 | 0:29983394c6b6 | 108 | PayloadPtr loadPtr(advData.getPayload(), advData.getPayloadLen()); |
edamame22 | 0:29983394c6b6 | 109 | |
edamame22 | 0:29983394c6b6 | 110 | /* Align the GAP Service Appearance Char value coherently |
edamame22 | 0:29983394c6b6 | 111 | This setting is duplicate (see below GapAdvertisingData::APPEARANCE) |
edamame22 | 0:29983394c6b6 | 112 | since BLE API has an overloaded function for appearance |
edamame22 | 0:29983394c6b6 | 113 | */ |
edamame22 | 0:29983394c6b6 | 114 | STORE_LE_16(deviceAppearance, advData.getAppearance()); |
edamame22 | 0:29983394c6b6 | 115 | setAppearance((GapAdvertisingData::Appearance)(deviceAppearance[1]<<8|deviceAppearance[0])); |
edamame22 | 0:29983394c6b6 | 116 | |
edamame22 | 0:29983394c6b6 | 117 | |
edamame22 | 0:29983394c6b6 | 118 | for(uint8_t index=0; index<loadPtr.getPayloadUnitCount(); index++) { |
edamame22 | 0:29983394c6b6 | 119 | loadPtr.getUnitAtIndex(index); |
edamame22 | 0:29983394c6b6 | 120 | |
edamame22 | 0:29983394c6b6 | 121 | PRINTF("adData[%d].length=%d\n\r", index,(uint8_t)(*loadPtr.getUnitAtIndex(index).getLenPtr())); |
edamame22 | 0:29983394c6b6 | 122 | PRINTF("adData[%d].AdType=0x%x\n\r", index,(uint8_t)(*loadPtr.getUnitAtIndex(index).getAdTypePtr())); |
edamame22 | 0:29983394c6b6 | 123 | |
edamame22 | 0:29983394c6b6 | 124 | switch(*loadPtr.getUnitAtIndex(index).getAdTypePtr()) { |
edamame22 | 0:29983394c6b6 | 125 | /**< TX Power Level (in dBm) */ |
edamame22 | 0:29983394c6b6 | 126 | case GapAdvertisingData::TX_POWER_LEVEL: |
edamame22 | 0:29983394c6b6 | 127 | { |
edamame22 | 0:29983394c6b6 | 128 | PRINTF("Advertising type: TX_POWER_LEVEL\n\r"); |
edamame22 | 0:29983394c6b6 | 129 | int8_t enHighPower = 0; |
edamame22 | 0:29983394c6b6 | 130 | int8_t paLevel = 0; |
edamame22 | 0:29983394c6b6 | 131 | |
edamame22 | 0:29983394c6b6 | 132 | int8_t dbm = *loadPtr.getUnitAtIndex(index).getDataPtr(); |
edamame22 | 0:29983394c6b6 | 133 | tBleStatus ret = getHighPowerAndPALevelValue(dbm, enHighPower, paLevel); |
edamame22 | 0:29983394c6b6 | 134 | #ifdef DEBUG |
edamame22 | 0:29983394c6b6 | 135 | PRINTF("dbm=%d, ret=%d\n\r", dbm, ret); |
edamame22 | 0:29983394c6b6 | 136 | PRINTF("enHighPower=%d, paLevel=%d\n\r", enHighPower, paLevel); |
edamame22 | 0:29983394c6b6 | 137 | #endif |
edamame22 | 0:29983394c6b6 | 138 | if(ret == BLE_STATUS_SUCCESS) { |
edamame22 | 0:29983394c6b6 | 139 | aci_hal_set_tx_power_level(enHighPower, paLevel); |
edamame22 | 0:29983394c6b6 | 140 | } |
edamame22 | 0:29983394c6b6 | 141 | break; |
edamame22 | 0:29983394c6b6 | 142 | } |
edamame22 | 0:29983394c6b6 | 143 | /**< Appearance */ |
edamame22 | 0:29983394c6b6 | 144 | case GapAdvertisingData::APPEARANCE: |
edamame22 | 0:29983394c6b6 | 145 | { |
edamame22 | 0:29983394c6b6 | 146 | PRINTF("Advertising type: APPEARANCE\n\r"); |
edamame22 | 0:29983394c6b6 | 147 | |
edamame22 | 0:29983394c6b6 | 148 | GapAdvertisingData::Appearance appearanceP; |
edamame22 | 0:29983394c6b6 | 149 | memcpy(deviceAppearance, loadPtr.getUnitAtIndex(index).getDataPtr(), 2); |
edamame22 | 0:29983394c6b6 | 150 | |
edamame22 | 0:29983394c6b6 | 151 | PRINTF("input: deviceAppearance= 0x%x 0x%x\n\r", deviceAppearance[1], deviceAppearance[0]); |
edamame22 | 0:29983394c6b6 | 152 | |
edamame22 | 0:29983394c6b6 | 153 | appearanceP = (GapAdvertisingData::Appearance)(deviceAppearance[1]<<8|deviceAppearance[0]); |
edamame22 | 0:29983394c6b6 | 154 | /* Align the GAP Service Appearance Char value coherently */ |
edamame22 | 0:29983394c6b6 | 155 | setAppearance(appearanceP); |
edamame22 | 0:29983394c6b6 | 156 | break; |
edamame22 | 0:29983394c6b6 | 157 | } |
edamame22 | 0:29983394c6b6 | 158 | |
edamame22 | 0:29983394c6b6 | 159 | } // end switch |
edamame22 | 0:29983394c6b6 | 160 | |
edamame22 | 0:29983394c6b6 | 161 | } //end for |
edamame22 | 0:29983394c6b6 | 162 | |
edamame22 | 0:29983394c6b6 | 163 | } |
edamame22 | 0:29983394c6b6 | 164 | |
edamame22 | 0:29983394c6b6 | 165 | // update the advertising data in the shield if advertising is running |
edamame22 | 0:29983394c6b6 | 166 | if (state.advertising == 1) { |
edamame22 | 0:29983394c6b6 | 167 | tBleStatus ret = hci_le_set_scan_resp_data(scanResponse.getPayloadLen(), scanResponse.getPayload()); |
edamame22 | 0:29983394c6b6 | 168 | |
edamame22 | 0:29983394c6b6 | 169 | if(BLE_STATUS_SUCCESS != ret) { |
edamame22 | 0:29983394c6b6 | 170 | PRINTF(" error while setting scan response data (ret=0x%x)\n", ret); |
edamame22 | 0:29983394c6b6 | 171 | switch (ret) { |
edamame22 | 0:29983394c6b6 | 172 | case BLE_STATUS_TIMEOUT: |
edamame22 | 0:29983394c6b6 | 173 | return BLE_STACK_BUSY; |
edamame22 | 0:29983394c6b6 | 174 | default: |
edamame22 | 0:29983394c6b6 | 175 | return BLE_ERROR_UNSPECIFIED; |
edamame22 | 0:29983394c6b6 | 176 | } |
edamame22 | 0:29983394c6b6 | 177 | } |
edamame22 | 0:29983394c6b6 | 178 | |
edamame22 | 0:29983394c6b6 | 179 | ret = hci_le_set_advertising_data(advData.getPayloadLen(), advData.getPayload()); |
edamame22 | 0:29983394c6b6 | 180 | if (ret) { |
edamame22 | 0:29983394c6b6 | 181 | PRINTF("error while setting the payload\r\n"); |
edamame22 | 0:29983394c6b6 | 182 | return BLE_ERROR_UNSPECIFIED; |
edamame22 | 0:29983394c6b6 | 183 | } |
edamame22 | 0:29983394c6b6 | 184 | } |
edamame22 | 0:29983394c6b6 | 185 | |
edamame22 | 0:29983394c6b6 | 186 | _advData = advData; |
edamame22 | 0:29983394c6b6 | 187 | _scanResponse = scanResponse; |
edamame22 | 0:29983394c6b6 | 188 | |
edamame22 | 0:29983394c6b6 | 189 | return BLE_ERROR_NONE; |
edamame22 | 0:29983394c6b6 | 190 | } |
edamame22 | 0:29983394c6b6 | 191 | |
edamame22 | 0:29983394c6b6 | 192 | /* |
edamame22 | 0:29983394c6b6 | 193 | * Utility to set ADV timeout flag |
edamame22 | 0:29983394c6b6 | 194 | */ |
edamame22 | 0:29983394c6b6 | 195 | void BlueNRGGap::setAdvToFlag(void) { |
edamame22 | 0:29983394c6b6 | 196 | AdvToFlag = true; |
edamame22 | 0:29983394c6b6 | 197 | } |
edamame22 | 0:29983394c6b6 | 198 | |
edamame22 | 0:29983394c6b6 | 199 | /* |
edamame22 | 0:29983394c6b6 | 200 | * ADV timeout callback |
edamame22 | 0:29983394c6b6 | 201 | */ |
edamame22 | 0:29983394c6b6 | 202 | #ifdef AST_FOR_MBED_OS |
edamame22 | 0:29983394c6b6 | 203 | static void advTimeoutCB(void) |
edamame22 | 0:29983394c6b6 | 204 | { |
edamame22 | 0:29983394c6b6 | 205 | Gap::GapState_t state; |
edamame22 | 0:29983394c6b6 | 206 | |
edamame22 | 0:29983394c6b6 | 207 | state = BlueNRGGap::getInstance().getState(); |
edamame22 | 0:29983394c6b6 | 208 | if (state.advertising == 1) { |
edamame22 | 0:29983394c6b6 | 209 | |
edamame22 | 0:29983394c6b6 | 210 | BlueNRGGap::getInstance().stopAdvertising(); |
edamame22 | 0:29983394c6b6 | 211 | |
edamame22 | 0:29983394c6b6 | 212 | } |
edamame22 | 0:29983394c6b6 | 213 | } |
edamame22 | 0:29983394c6b6 | 214 | #else |
edamame22 | 0:29983394c6b6 | 215 | static void advTimeoutCB(void) |
edamame22 | 0:29983394c6b6 | 216 | { |
edamame22 | 0:29983394c6b6 | 217 | Gap::GapState_t state; |
edamame22 | 0:29983394c6b6 | 218 | |
edamame22 | 0:29983394c6b6 | 219 | state = BlueNRGGap::getInstance().getState(); |
edamame22 | 0:29983394c6b6 | 220 | if (state.advertising == 1) { |
edamame22 | 0:29983394c6b6 | 221 | |
edamame22 | 0:29983394c6b6 | 222 | BlueNRGGap::getInstance().setAdvToFlag(); |
edamame22 | 0:29983394c6b6 | 223 | |
edamame22 | 0:29983394c6b6 | 224 | Timeout t = BlueNRGGap::getInstance().getAdvTimeout(); |
edamame22 | 0:29983394c6b6 | 225 | t.detach(); /* disable the callback from the timeout */ |
edamame22 | 0:29983394c6b6 | 226 | |
edamame22 | 0:29983394c6b6 | 227 | } |
edamame22 | 0:29983394c6b6 | 228 | } |
edamame22 | 0:29983394c6b6 | 229 | #endif /* AST_FOR_MBED_OS */ |
edamame22 | 0:29983394c6b6 | 230 | |
edamame22 | 0:29983394c6b6 | 231 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 232 | /*! |
edamame22 | 0:29983394c6b6 | 233 | @brief Starts the BLE HW, initialising any services that were |
edamame22 | 0:29983394c6b6 | 234 | added before this function was called. |
edamame22 | 0:29983394c6b6 | 235 | |
edamame22 | 0:29983394c6b6 | 236 | @param[in] params |
edamame22 | 0:29983394c6b6 | 237 | Basic advertising details, including the advertising |
edamame22 | 0:29983394c6b6 | 238 | delay, timeout and how the device should be advertised |
edamame22 | 0:29983394c6b6 | 239 | |
edamame22 | 0:29983394c6b6 | 240 | @note All services must be added before calling this function! |
edamame22 | 0:29983394c6b6 | 241 | |
edamame22 | 0:29983394c6b6 | 242 | @returns ble_error_t |
edamame22 | 0:29983394c6b6 | 243 | |
edamame22 | 0:29983394c6b6 | 244 | @retval BLE_ERROR_NONE |
edamame22 | 0:29983394c6b6 | 245 | Everything executed properly |
edamame22 | 0:29983394c6b6 | 246 | |
edamame22 | 0:29983394c6b6 | 247 | @section EXAMPLE |
edamame22 | 0:29983394c6b6 | 248 | |
edamame22 | 0:29983394c6b6 | 249 | @code |
edamame22 | 0:29983394c6b6 | 250 | |
edamame22 | 0:29983394c6b6 | 251 | @endcode |
edamame22 | 0:29983394c6b6 | 252 | */ |
edamame22 | 0:29983394c6b6 | 253 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 254 | |
edamame22 | 0:29983394c6b6 | 255 | ble_error_t BlueNRGGap::startAdvertising(const GapAdvertisingParams ¶ms) |
edamame22 | 0:29983394c6b6 | 256 | { |
edamame22 | 0:29983394c6b6 | 257 | tBleStatus ret; |
edamame22 | 0:29983394c6b6 | 258 | int err; |
edamame22 | 0:29983394c6b6 | 259 | |
edamame22 | 0:29983394c6b6 | 260 | /* Make sure we support the advertising type */ |
edamame22 | 0:29983394c6b6 | 261 | if (params.getAdvertisingType() == GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED) { |
edamame22 | 0:29983394c6b6 | 262 | /* ToDo: This requires a proper security implementation, etc. */ |
edamame22 | 0:29983394c6b6 | 263 | return BLE_ERROR_NOT_IMPLEMENTED; |
edamame22 | 0:29983394c6b6 | 264 | } |
edamame22 | 0:29983394c6b6 | 265 | |
edamame22 | 0:29983394c6b6 | 266 | /* Check interval range */ |
edamame22 | 0:29983394c6b6 | 267 | if (params.getAdvertisingType() == GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED) { |
edamame22 | 0:29983394c6b6 | 268 | /* Min delay is slightly longer for unconnectable devices */ |
edamame22 | 0:29983394c6b6 | 269 | if ((params.getIntervalInADVUnits() < GapAdvertisingParams::GAP_ADV_PARAMS_INTERVAL_MIN_NONCON) || |
edamame22 | 0:29983394c6b6 | 270 | (params.getIntervalInADVUnits() > GapAdvertisingParams::GAP_ADV_PARAMS_INTERVAL_MAX)) { |
edamame22 | 0:29983394c6b6 | 271 | return BLE_ERROR_PARAM_OUT_OF_RANGE; |
edamame22 | 0:29983394c6b6 | 272 | } |
edamame22 | 0:29983394c6b6 | 273 | } else { |
edamame22 | 0:29983394c6b6 | 274 | if ((params.getIntervalInADVUnits() < GapAdvertisingParams::GAP_ADV_PARAMS_INTERVAL_MIN) || |
edamame22 | 0:29983394c6b6 | 275 | (params.getIntervalInADVUnits() > GapAdvertisingParams::GAP_ADV_PARAMS_INTERVAL_MAX)) { |
edamame22 | 0:29983394c6b6 | 276 | return BLE_ERROR_PARAM_OUT_OF_RANGE; |
edamame22 | 0:29983394c6b6 | 277 | } |
edamame22 | 0:29983394c6b6 | 278 | } |
edamame22 | 0:29983394c6b6 | 279 | |
edamame22 | 0:29983394c6b6 | 280 | /* Check timeout is zero for Connectable Directed */ |
edamame22 | 0:29983394c6b6 | 281 | if ((params.getAdvertisingType() == GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED) && (params.getTimeout() != 0)) { |
edamame22 | 0:29983394c6b6 | 282 | /* Timeout must be 0 with this type, although we'll never get here */ |
edamame22 | 0:29983394c6b6 | 283 | /* since this isn't implemented yet anyway */ |
edamame22 | 0:29983394c6b6 | 284 | return BLE_ERROR_PARAM_OUT_OF_RANGE; |
edamame22 | 0:29983394c6b6 | 285 | } |
edamame22 | 0:29983394c6b6 | 286 | |
edamame22 | 0:29983394c6b6 | 287 | /* Check timeout for other advertising types */ |
edamame22 | 0:29983394c6b6 | 288 | if ((params.getAdvertisingType() != GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED) && |
edamame22 | 0:29983394c6b6 | 289 | (params.getTimeout() > GapAdvertisingParams::GAP_ADV_PARAMS_TIMEOUT_MAX)) { |
edamame22 | 0:29983394c6b6 | 290 | return BLE_ERROR_PARAM_OUT_OF_RANGE; |
edamame22 | 0:29983394c6b6 | 291 | } |
edamame22 | 0:29983394c6b6 | 292 | |
edamame22 | 0:29983394c6b6 | 293 | /* |
edamame22 | 0:29983394c6b6 | 294 | * Advertising filter policy setting |
edamame22 | 0:29983394c6b6 | 295 | * FIXME: the Security Manager should be implemented |
edamame22 | 0:29983394c6b6 | 296 | */ |
edamame22 | 0:29983394c6b6 | 297 | AdvertisingPolicyMode_t mode = getAdvertisingPolicyMode(); |
edamame22 | 0:29983394c6b6 | 298 | if(mode != ADV_POLICY_IGNORE_WHITELIST) { |
edamame22 | 0:29983394c6b6 | 299 | ret = aci_gap_configure_whitelist(); |
edamame22 | 0:29983394c6b6 | 300 | if(ret != BLE_STATUS_SUCCESS) { |
edamame22 | 0:29983394c6b6 | 301 | PRINTF("aci_gap_configure_whitelist ret=0x%x\n\r", ret); |
edamame22 | 0:29983394c6b6 | 302 | return BLE_ERROR_OPERATION_NOT_PERMITTED; |
edamame22 | 0:29983394c6b6 | 303 | } |
edamame22 | 0:29983394c6b6 | 304 | } |
edamame22 | 0:29983394c6b6 | 305 | |
edamame22 | 0:29983394c6b6 | 306 | uint8_t advFilterPolicy = NO_WHITE_LIST_USE; |
edamame22 | 0:29983394c6b6 | 307 | switch(mode) { |
edamame22 | 0:29983394c6b6 | 308 | case ADV_POLICY_FILTER_SCAN_REQS: |
edamame22 | 0:29983394c6b6 | 309 | advFilterPolicy = WHITE_LIST_FOR_ONLY_SCAN; |
edamame22 | 0:29983394c6b6 | 310 | break; |
edamame22 | 0:29983394c6b6 | 311 | case ADV_POLICY_FILTER_CONN_REQS: |
edamame22 | 0:29983394c6b6 | 312 | advFilterPolicy = WHITE_LIST_FOR_ONLY_CONN; |
edamame22 | 0:29983394c6b6 | 313 | break; |
edamame22 | 0:29983394c6b6 | 314 | case ADV_POLICY_FILTER_ALL_REQS: |
edamame22 | 0:29983394c6b6 | 315 | advFilterPolicy = WHITE_LIST_FOR_ALL; |
edamame22 | 0:29983394c6b6 | 316 | break; |
edamame22 | 0:29983394c6b6 | 317 | default: |
edamame22 | 0:29983394c6b6 | 318 | advFilterPolicy = NO_WHITE_LIST_USE; |
edamame22 | 0:29983394c6b6 | 319 | break; |
edamame22 | 0:29983394c6b6 | 320 | } |
edamame22 | 0:29983394c6b6 | 321 | |
edamame22 | 0:29983394c6b6 | 322 | /* Check the ADV type before setting scan response data */ |
edamame22 | 0:29983394c6b6 | 323 | if (params.getAdvertisingType() == GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED || |
edamame22 | 0:29983394c6b6 | 324 | params.getAdvertisingType() == GapAdvertisingParams::ADV_SCANNABLE_UNDIRECTED) { |
edamame22 | 0:29983394c6b6 | 325 | |
edamame22 | 0:29983394c6b6 | 326 | /* set scan response data */ |
edamame22 | 0:29983394c6b6 | 327 | PRINTF(" setting scan response data (_scanResponseLen=%u)\n", _scanResponse.getPayloadLen()); |
edamame22 | 0:29983394c6b6 | 328 | ret = hci_le_set_scan_resp_data(_scanResponse.getPayloadLen(), _scanResponse.getPayload()); |
edamame22 | 0:29983394c6b6 | 329 | |
edamame22 | 0:29983394c6b6 | 330 | if(BLE_STATUS_SUCCESS!=ret) { |
edamame22 | 0:29983394c6b6 | 331 | PRINTF(" error while setting scan response data (ret=0x%x)\n", ret); |
edamame22 | 0:29983394c6b6 | 332 | switch (ret) { |
edamame22 | 0:29983394c6b6 | 333 | case BLE_STATUS_TIMEOUT: |
edamame22 | 0:29983394c6b6 | 334 | return BLE_STACK_BUSY; |
edamame22 | 0:29983394c6b6 | 335 | default: |
edamame22 | 0:29983394c6b6 | 336 | return BLE_ERROR_UNSPECIFIED; |
edamame22 | 0:29983394c6b6 | 337 | } |
edamame22 | 0:29983394c6b6 | 338 | } |
edamame22 | 0:29983394c6b6 | 339 | } else { |
edamame22 | 0:29983394c6b6 | 340 | hci_le_set_scan_resp_data(0, NULL); |
edamame22 | 0:29983394c6b6 | 341 | } |
edamame22 | 0:29983394c6b6 | 342 | |
edamame22 | 0:29983394c6b6 | 343 | setAdvParameters(); |
edamame22 | 0:29983394c6b6 | 344 | PRINTF("advInterval=%d advType=%d\n\r", advInterval, params.getAdvertisingType()); |
edamame22 | 0:29983394c6b6 | 345 | |
edamame22 | 0:29983394c6b6 | 346 | err = hci_le_set_advertising_data(_advData.getPayloadLen(), _advData.getPayload()); |
edamame22 | 0:29983394c6b6 | 347 | |
edamame22 | 0:29983394c6b6 | 348 | if (err) { |
edamame22 | 0:29983394c6b6 | 349 | PRINTF("error while setting the payload\r\n"); |
edamame22 | 0:29983394c6b6 | 350 | return BLE_ERROR_UNSPECIFIED; |
edamame22 | 0:29983394c6b6 | 351 | } |
edamame22 | 0:29983394c6b6 | 352 | |
edamame22 | 0:29983394c6b6 | 353 | tBDAddr dummy_addr = { 0 }; |
edamame22 | 0:29983394c6b6 | 354 | uint16_t advIntervalMin = advInterval == GapAdvertisingParams::GAP_ADV_PARAMS_INTERVAL_MAX ? advInterval - 1 : advInterval; |
edamame22 | 0:29983394c6b6 | 355 | uint16_t advIntervalMax = advIntervalMin + 1; |
edamame22 | 0:29983394c6b6 | 356 | |
edamame22 | 0:29983394c6b6 | 357 | err = hci_le_set_advertising_parameters( |
edamame22 | 0:29983394c6b6 | 358 | advIntervalMin, |
edamame22 | 0:29983394c6b6 | 359 | advIntervalMax, |
edamame22 | 0:29983394c6b6 | 360 | params.getAdvertisingType(), |
edamame22 | 0:29983394c6b6 | 361 | addr_type, |
edamame22 | 0:29983394c6b6 | 362 | 0x00, |
edamame22 | 0:29983394c6b6 | 363 | dummy_addr, |
edamame22 | 0:29983394c6b6 | 364 | /* all channels */ 7, |
edamame22 | 0:29983394c6b6 | 365 | advFilterPolicy |
edamame22 | 0:29983394c6b6 | 366 | ); |
edamame22 | 0:29983394c6b6 | 367 | |
edamame22 | 0:29983394c6b6 | 368 | if (err) { |
edamame22 | 0:29983394c6b6 | 369 | PRINTF("impossible to set advertising parameters\n\r"); |
edamame22 | 0:29983394c6b6 | 370 | PRINTF("advInterval min: %u, advInterval max: %u\n\r", advInterval, advInterval + 1); |
edamame22 | 0:29983394c6b6 | 371 | PRINTF("advType: %u, advFilterPolicy: %u\n\r", params.getAdvertisingType(), advFilterPolicy); |
edamame22 | 0:29983394c6b6 | 372 | return BLE_ERROR_INVALID_PARAM; |
edamame22 | 0:29983394c6b6 | 373 | } |
edamame22 | 0:29983394c6b6 | 374 | |
edamame22 | 0:29983394c6b6 | 375 | err = hci_le_set_advertise_enable(0x01); |
edamame22 | 0:29983394c6b6 | 376 | if (err) { |
edamame22 | 0:29983394c6b6 | 377 | PRINTF("impossible to start advertising\n\r"); |
edamame22 | 0:29983394c6b6 | 378 | return BLE_ERROR_UNSPECIFIED; |
edamame22 | 0:29983394c6b6 | 379 | } |
edamame22 | 0:29983394c6b6 | 380 | |
edamame22 | 0:29983394c6b6 | 381 | state.advertising = 1; |
edamame22 | 0:29983394c6b6 | 382 | |
edamame22 | 0:29983394c6b6 | 383 | AdvToFlag = false; |
edamame22 | 0:29983394c6b6 | 384 | if(params.getTimeout() != 0) { |
edamame22 | 0:29983394c6b6 | 385 | PRINTF("!!! attaching to!!!\n"); |
edamame22 | 0:29983394c6b6 | 386 | #ifdef AST_FOR_MBED_OS |
edamame22 | 0:29983394c6b6 | 387 | minar::Scheduler::postCallback(advTimeoutCB).delay(minar::milliseconds(params.getTimeout() * 1000)); |
edamame22 | 0:29983394c6b6 | 388 | #else |
edamame22 | 0:29983394c6b6 | 389 | advTimeout.attach(advTimeoutCB, params.getTimeout() * 1000); |
edamame22 | 0:29983394c6b6 | 390 | #endif |
edamame22 | 0:29983394c6b6 | 391 | } |
edamame22 | 0:29983394c6b6 | 392 | |
edamame22 | 0:29983394c6b6 | 393 | return BLE_ERROR_NONE; |
edamame22 | 0:29983394c6b6 | 394 | |
edamame22 | 0:29983394c6b6 | 395 | } |
edamame22 | 0:29983394c6b6 | 396 | |
edamame22 | 0:29983394c6b6 | 397 | |
edamame22 | 0:29983394c6b6 | 398 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 399 | /*! |
edamame22 | 0:29983394c6b6 | 400 | @brief Stops the BLE HW and disconnects from any devices |
edamame22 | 0:29983394c6b6 | 401 | |
edamame22 | 0:29983394c6b6 | 402 | @returns ble_error_t |
edamame22 | 0:29983394c6b6 | 403 | |
edamame22 | 0:29983394c6b6 | 404 | @retval BLE_ERROR_NONE |
edamame22 | 0:29983394c6b6 | 405 | Everything executed properly |
edamame22 | 0:29983394c6b6 | 406 | |
edamame22 | 0:29983394c6b6 | 407 | @section EXAMPLE |
edamame22 | 0:29983394c6b6 | 408 | |
edamame22 | 0:29983394c6b6 | 409 | @code |
edamame22 | 0:29983394c6b6 | 410 | |
edamame22 | 0:29983394c6b6 | 411 | @endcode |
edamame22 | 0:29983394c6b6 | 412 | */ |
edamame22 | 0:29983394c6b6 | 413 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 414 | ble_error_t BlueNRGGap::stopAdvertising(void) |
edamame22 | 0:29983394c6b6 | 415 | { |
edamame22 | 0:29983394c6b6 | 416 | |
edamame22 | 0:29983394c6b6 | 417 | if(state.advertising == 1) { |
edamame22 | 0:29983394c6b6 | 418 | |
edamame22 | 0:29983394c6b6 | 419 | int err = hci_le_set_advertise_enable(0); |
edamame22 | 0:29983394c6b6 | 420 | if (err) { |
edamame22 | 0:29983394c6b6 | 421 | return BLE_ERROR_OPERATION_NOT_PERMITTED; |
edamame22 | 0:29983394c6b6 | 422 | } |
edamame22 | 0:29983394c6b6 | 423 | |
edamame22 | 0:29983394c6b6 | 424 | PRINTF("Advertisement stopped!!\n\r") ; |
edamame22 | 0:29983394c6b6 | 425 | //Set GapState_t::advertising state |
edamame22 | 0:29983394c6b6 | 426 | state.advertising = 0; |
edamame22 | 0:29983394c6b6 | 427 | } |
edamame22 | 0:29983394c6b6 | 428 | |
edamame22 | 0:29983394c6b6 | 429 | return BLE_ERROR_NONE; |
edamame22 | 0:29983394c6b6 | 430 | } |
edamame22 | 0:29983394c6b6 | 431 | |
edamame22 | 0:29983394c6b6 | 432 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 433 | /*! |
edamame22 | 0:29983394c6b6 | 434 | @brief Disconnects if we are connected to a central device |
edamame22 | 0:29983394c6b6 | 435 | |
edamame22 | 0:29983394c6b6 | 436 | @param[in] reason |
edamame22 | 0:29983394c6b6 | 437 | Disconnection Reason |
edamame22 | 0:29983394c6b6 | 438 | |
edamame22 | 0:29983394c6b6 | 439 | @returns ble_error_t |
edamame22 | 0:29983394c6b6 | 440 | |
edamame22 | 0:29983394c6b6 | 441 | @retval BLE_ERROR_NONE |
edamame22 | 0:29983394c6b6 | 442 | Everything executed properly |
edamame22 | 0:29983394c6b6 | 443 | |
edamame22 | 0:29983394c6b6 | 444 | @section EXAMPLE |
edamame22 | 0:29983394c6b6 | 445 | |
edamame22 | 0:29983394c6b6 | 446 | @code |
edamame22 | 0:29983394c6b6 | 447 | |
edamame22 | 0:29983394c6b6 | 448 | @endcode |
edamame22 | 0:29983394c6b6 | 449 | */ |
edamame22 | 0:29983394c6b6 | 450 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 451 | ble_error_t BlueNRGGap::disconnect(Handle_t connectionHandle, Gap::DisconnectionReason_t reason) |
edamame22 | 0:29983394c6b6 | 452 | { |
edamame22 | 0:29983394c6b6 | 453 | tBleStatus ret; |
edamame22 | 0:29983394c6b6 | 454 | |
edamame22 | 0:29983394c6b6 | 455 | ret = aci_gap_terminate(connectionHandle, reason); |
edamame22 | 0:29983394c6b6 | 456 | |
edamame22 | 0:29983394c6b6 | 457 | if (BLE_STATUS_SUCCESS != ret){ |
edamame22 | 0:29983394c6b6 | 458 | PRINTF("Error in GAP termination (ret=0x%x)!!\n\r", ret) ; |
edamame22 | 0:29983394c6b6 | 459 | switch (ret) { |
edamame22 | 0:29983394c6b6 | 460 | case ERR_COMMAND_DISALLOWED: |
edamame22 | 0:29983394c6b6 | 461 | return BLE_ERROR_OPERATION_NOT_PERMITTED; |
edamame22 | 0:29983394c6b6 | 462 | case BLE_STATUS_TIMEOUT: |
edamame22 | 0:29983394c6b6 | 463 | return BLE_STACK_BUSY; |
edamame22 | 0:29983394c6b6 | 464 | default: |
edamame22 | 0:29983394c6b6 | 465 | return BLE_ERROR_UNSPECIFIED; |
edamame22 | 0:29983394c6b6 | 466 | } |
edamame22 | 0:29983394c6b6 | 467 | } |
edamame22 | 0:29983394c6b6 | 468 | |
edamame22 | 0:29983394c6b6 | 469 | return BLE_ERROR_NONE; |
edamame22 | 0:29983394c6b6 | 470 | } |
edamame22 | 0:29983394c6b6 | 471 | |
edamame22 | 0:29983394c6b6 | 472 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 473 | /*! |
edamame22 | 0:29983394c6b6 | 474 | @brief Disconnects if we are connected to a central device |
edamame22 | 0:29983394c6b6 | 475 | |
edamame22 | 0:29983394c6b6 | 476 | @param[in] reason |
edamame22 | 0:29983394c6b6 | 477 | Disconnection Reason |
edamame22 | 0:29983394c6b6 | 478 | |
edamame22 | 0:29983394c6b6 | 479 | @returns ble_error_t |
edamame22 | 0:29983394c6b6 | 480 | |
edamame22 | 0:29983394c6b6 | 481 | @retval BLE_ERROR_NONE |
edamame22 | 0:29983394c6b6 | 482 | Everything executed properly |
edamame22 | 0:29983394c6b6 | 483 | |
edamame22 | 0:29983394c6b6 | 484 | @section EXAMPLE |
edamame22 | 0:29983394c6b6 | 485 | |
edamame22 | 0:29983394c6b6 | 486 | @code |
edamame22 | 0:29983394c6b6 | 487 | |
edamame22 | 0:29983394c6b6 | 488 | @endcode |
edamame22 | 0:29983394c6b6 | 489 | */ |
edamame22 | 0:29983394c6b6 | 490 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 491 | ble_error_t BlueNRGGap::disconnect(Gap::DisconnectionReason_t reason) |
edamame22 | 0:29983394c6b6 | 492 | { |
edamame22 | 0:29983394c6b6 | 493 | return disconnect(m_connectionHandle, reason); |
edamame22 | 0:29983394c6b6 | 494 | } |
edamame22 | 0:29983394c6b6 | 495 | |
edamame22 | 0:29983394c6b6 | 496 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 497 | /*! |
edamame22 | 0:29983394c6b6 | 498 | @brief Sets the 16-bit connection handle |
edamame22 | 0:29983394c6b6 | 499 | |
edamame22 | 0:29983394c6b6 | 500 | @param[in] conn_handle |
edamame22 | 0:29983394c6b6 | 501 | Connection Handle which is set in the Gap Instance |
edamame22 | 0:29983394c6b6 | 502 | |
edamame22 | 0:29983394c6b6 | 503 | @returns void |
edamame22 | 0:29983394c6b6 | 504 | */ |
edamame22 | 0:29983394c6b6 | 505 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 506 | void BlueNRGGap::setConnectionHandle(uint16_t conn_handle) |
edamame22 | 0:29983394c6b6 | 507 | { |
edamame22 | 0:29983394c6b6 | 508 | m_connectionHandle = conn_handle; |
edamame22 | 0:29983394c6b6 | 509 | } |
edamame22 | 0:29983394c6b6 | 510 | |
edamame22 | 0:29983394c6b6 | 511 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 512 | /*! |
edamame22 | 0:29983394c6b6 | 513 | @brief Gets the 16-bit connection handle |
edamame22 | 0:29983394c6b6 | 514 | |
edamame22 | 0:29983394c6b6 | 515 | @param[in] void |
edamame22 | 0:29983394c6b6 | 516 | |
edamame22 | 0:29983394c6b6 | 517 | @returns uint16_t |
edamame22 | 0:29983394c6b6 | 518 | Connection Handle of the Gap Instance |
edamame22 | 0:29983394c6b6 | 519 | */ |
edamame22 | 0:29983394c6b6 | 520 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 521 | uint16_t BlueNRGGap::getConnectionHandle(void) |
edamame22 | 0:29983394c6b6 | 522 | { |
edamame22 | 0:29983394c6b6 | 523 | return m_connectionHandle; |
edamame22 | 0:29983394c6b6 | 524 | } |
edamame22 | 0:29983394c6b6 | 525 | |
edamame22 | 0:29983394c6b6 | 526 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 527 | /*! |
edamame22 | 0:29983394c6b6 | 528 | @brief Sets the BLE device address. SetAddress will reset the BLE |
edamame22 | 0:29983394c6b6 | 529 | device and re-initialize BTLE. Will not start advertising. |
edamame22 | 0:29983394c6b6 | 530 | |
edamame22 | 0:29983394c6b6 | 531 | @param[in] type |
edamame22 | 0:29983394c6b6 | 532 | Type of Address |
edamame22 | 0:29983394c6b6 | 533 | |
edamame22 | 0:29983394c6b6 | 534 | @param[in] address[6] |
edamame22 | 0:29983394c6b6 | 535 | Value of the Address to be set |
edamame22 | 0:29983394c6b6 | 536 | |
edamame22 | 0:29983394c6b6 | 537 | @returns ble_error_t |
edamame22 | 0:29983394c6b6 | 538 | |
edamame22 | 0:29983394c6b6 | 539 | @section EXAMPLE |
edamame22 | 0:29983394c6b6 | 540 | |
edamame22 | 0:29983394c6b6 | 541 | @code |
edamame22 | 0:29983394c6b6 | 542 | |
edamame22 | 0:29983394c6b6 | 543 | @endcode |
edamame22 | 0:29983394c6b6 | 544 | */ |
edamame22 | 0:29983394c6b6 | 545 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 546 | ble_error_t BlueNRGGap::setAddress(AddressType_t type, const BLEProtocol::AddressBytes_t address) |
edamame22 | 0:29983394c6b6 | 547 | { |
edamame22 | 0:29983394c6b6 | 548 | if (type > BLEProtocol::AddressType::RANDOM_PRIVATE_NON_RESOLVABLE) { |
edamame22 | 0:29983394c6b6 | 549 | return BLE_ERROR_PARAM_OUT_OF_RANGE; |
edamame22 | 0:29983394c6b6 | 550 | } |
edamame22 | 0:29983394c6b6 | 551 | |
edamame22 | 0:29983394c6b6 | 552 | if(type == BLEProtocol::AddressType::PUBLIC){ |
edamame22 | 0:29983394c6b6 | 553 | tBleStatus ret = aci_hal_write_config_data( |
edamame22 | 0:29983394c6b6 | 554 | CONFIG_DATA_PUBADDR_OFFSET, |
edamame22 | 0:29983394c6b6 | 555 | CONFIG_DATA_PUBADDR_LEN, |
edamame22 | 0:29983394c6b6 | 556 | address |
edamame22 | 0:29983394c6b6 | 557 | ); |
edamame22 | 0:29983394c6b6 | 558 | if(ret != BLE_STATUS_SUCCESS) { |
edamame22 | 0:29983394c6b6 | 559 | return BLE_ERROR_OPERATION_NOT_PERMITTED; |
edamame22 | 0:29983394c6b6 | 560 | } |
edamame22 | 0:29983394c6b6 | 561 | } else if (type == BLEProtocol::AddressType::RANDOM_STATIC) { |
edamame22 | 0:29983394c6b6 | 562 | // ensure that the random static address is well formed |
edamame22 | 0:29983394c6b6 | 563 | if ((address[5] & 0xC0) != 0xC0) { |
edamame22 | 0:29983394c6b6 | 564 | return BLE_ERROR_PARAM_OUT_OF_RANGE; |
edamame22 | 0:29983394c6b6 | 565 | } |
edamame22 | 0:29983394c6b6 | 566 | |
edamame22 | 0:29983394c6b6 | 567 | // thanks to const correctness of the API ... |
edamame22 | 0:29983394c6b6 | 568 | tBDAddr random_address = { 0 }; |
edamame22 | 0:29983394c6b6 | 569 | memcpy(random_address, address, sizeof(random_address)); |
edamame22 | 0:29983394c6b6 | 570 | int err = hci_le_set_random_address(random_address); |
edamame22 | 0:29983394c6b6 | 571 | if (err) { |
edamame22 | 0:29983394c6b6 | 572 | return BLE_ERROR_OPERATION_NOT_PERMITTED; |
edamame22 | 0:29983394c6b6 | 573 | } |
edamame22 | 0:29983394c6b6 | 574 | |
edamame22 | 0:29983394c6b6 | 575 | // It is not possible to get the bluetooth address when it is set |
edamame22 | 0:29983394c6b6 | 576 | // store it locally in class data member |
edamame22 | 0:29983394c6b6 | 577 | memcpy(bdaddr, address, sizeof(bdaddr)); |
edamame22 | 0:29983394c6b6 | 578 | } else { |
edamame22 | 0:29983394c6b6 | 579 | // FIXME random addresses are not supported yet |
edamame22 | 0:29983394c6b6 | 580 | // BLEProtocol::AddressType::RANDOM_PRIVATE_NON_RESOLVABLE |
edamame22 | 0:29983394c6b6 | 581 | // BLEProtocol::AddressType::RANDOM_PRIVATE_RESOLVABLE |
edamame22 | 0:29983394c6b6 | 582 | return BLE_ERROR_NOT_IMPLEMENTED; |
edamame22 | 0:29983394c6b6 | 583 | } |
edamame22 | 0:29983394c6b6 | 584 | |
edamame22 | 0:29983394c6b6 | 585 | // if we're here then the address was correctly set |
edamame22 | 0:29983394c6b6 | 586 | // commit it inside the addr_type |
edamame22 | 0:29983394c6b6 | 587 | addr_type = type; |
edamame22 | 0:29983394c6b6 | 588 | isSetAddress = true; |
edamame22 | 0:29983394c6b6 | 589 | return BLE_ERROR_NONE; |
edamame22 | 0:29983394c6b6 | 590 | } |
edamame22 | 0:29983394c6b6 | 591 | |
edamame22 | 0:29983394c6b6 | 592 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 593 | /*! |
edamame22 | 0:29983394c6b6 | 594 | @brief Returns boolean if the address of the device has been set |
edamame22 | 0:29983394c6b6 | 595 | or not |
edamame22 | 0:29983394c6b6 | 596 | |
edamame22 | 0:29983394c6b6 | 597 | @returns bool |
edamame22 | 0:29983394c6b6 | 598 | |
edamame22 | 0:29983394c6b6 | 599 | @section EXAMPLE |
edamame22 | 0:29983394c6b6 | 600 | |
edamame22 | 0:29983394c6b6 | 601 | @code |
edamame22 | 0:29983394c6b6 | 602 | |
edamame22 | 0:29983394c6b6 | 603 | @endcode |
edamame22 | 0:29983394c6b6 | 604 | */ |
edamame22 | 0:29983394c6b6 | 605 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 606 | bool BlueNRGGap::getIsSetAddress() |
edamame22 | 0:29983394c6b6 | 607 | { |
edamame22 | 0:29983394c6b6 | 608 | return isSetAddress; |
edamame22 | 0:29983394c6b6 | 609 | } |
edamame22 | 0:29983394c6b6 | 610 | |
edamame22 | 0:29983394c6b6 | 611 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 612 | /*! |
edamame22 | 0:29983394c6b6 | 613 | @brief Returns the address of the device if set |
edamame22 | 0:29983394c6b6 | 614 | |
edamame22 | 0:29983394c6b6 | 615 | @returns Pointer to the address if Address is set else NULL |
edamame22 | 0:29983394c6b6 | 616 | |
edamame22 | 0:29983394c6b6 | 617 | @section EXAMPLE |
edamame22 | 0:29983394c6b6 | 618 | |
edamame22 | 0:29983394c6b6 | 619 | @code |
edamame22 | 0:29983394c6b6 | 620 | |
edamame22 | 0:29983394c6b6 | 621 | @endcode |
edamame22 | 0:29983394c6b6 | 622 | */ |
edamame22 | 0:29983394c6b6 | 623 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 624 | ble_error_t BlueNRGGap::getAddress(BLEProtocol::AddressType_t *typeP, BLEProtocol::AddressBytes_t address) |
edamame22 | 0:29983394c6b6 | 625 | { |
edamame22 | 0:29983394c6b6 | 626 | uint8_t bdaddr[BDADDR_SIZE]; |
edamame22 | 0:29983394c6b6 | 627 | uint8_t data_len_out; |
edamame22 | 0:29983394c6b6 | 628 | |
edamame22 | 0:29983394c6b6 | 629 | // precondition, check that pointers in input are valid |
edamame22 | 0:29983394c6b6 | 630 | if (typeP == NULL || address == NULL) { |
edamame22 | 0:29983394c6b6 | 631 | return BLE_ERROR_INVALID_PARAM; |
edamame22 | 0:29983394c6b6 | 632 | } |
edamame22 | 0:29983394c6b6 | 633 | |
edamame22 | 0:29983394c6b6 | 634 | if (addr_type == BLEProtocol::AddressType::PUBLIC) { |
edamame22 | 0:29983394c6b6 | 635 | tBleStatus ret = aci_hal_read_config_data(CONFIG_DATA_PUBADDR_OFFSET, BDADDR_SIZE, &data_len_out, bdaddr); |
edamame22 | 0:29983394c6b6 | 636 | if(ret != BLE_STATUS_SUCCESS || data_len_out != BDADDR_SIZE) { |
edamame22 | 0:29983394c6b6 | 637 | return BLE_ERROR_UNSPECIFIED; |
edamame22 | 0:29983394c6b6 | 638 | } |
edamame22 | 0:29983394c6b6 | 639 | } else if (addr_type == BLEProtocol::AddressType::RANDOM_STATIC) { |
edamame22 | 0:29983394c6b6 | 640 | // FIXME hci_read_bd_addr and |
edamame22 | 0:29983394c6b6 | 641 | // aci_hal_read_config_data CONFIG_DATA_RANDOM_ADDRESS_IDB05A1 |
edamame22 | 0:29983394c6b6 | 642 | // does not work, use the address stored in class data member |
edamame22 | 0:29983394c6b6 | 643 | memcpy(bdaddr, this->bdaddr, sizeof(bdaddr)); |
edamame22 | 0:29983394c6b6 | 644 | } else { |
edamame22 | 0:29983394c6b6 | 645 | // FIXME: should be implemented with privacy features |
edamame22 | 0:29983394c6b6 | 646 | // BLEProtocol::AddressType::RANDOM_PRIVATE_NON_RESOLVABLE |
edamame22 | 0:29983394c6b6 | 647 | // BLEProtocol::AddressType::RANDOM_PRIVATE_RESOLVABLE |
edamame22 | 0:29983394c6b6 | 648 | return BLE_ERROR_NOT_IMPLEMENTED; |
edamame22 | 0:29983394c6b6 | 649 | } |
edamame22 | 0:29983394c6b6 | 650 | |
edamame22 | 0:29983394c6b6 | 651 | *typeP = addr_type; |
edamame22 | 0:29983394c6b6 | 652 | memcpy(address, bdaddr, BDADDR_SIZE); |
edamame22 | 0:29983394c6b6 | 653 | |
edamame22 | 0:29983394c6b6 | 654 | return BLE_ERROR_NONE; |
edamame22 | 0:29983394c6b6 | 655 | } |
edamame22 | 0:29983394c6b6 | 656 | |
edamame22 | 0:29983394c6b6 | 657 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 658 | /*! |
edamame22 | 0:29983394c6b6 | 659 | @brief obtains preferred connection params |
edamame22 | 0:29983394c6b6 | 660 | |
edamame22 | 0:29983394c6b6 | 661 | @returns ble_error_t |
edamame22 | 0:29983394c6b6 | 662 | |
edamame22 | 0:29983394c6b6 | 663 | @section EXAMPLE |
edamame22 | 0:29983394c6b6 | 664 | |
edamame22 | 0:29983394c6b6 | 665 | @code |
edamame22 | 0:29983394c6b6 | 666 | |
edamame22 | 0:29983394c6b6 | 667 | @endcode |
edamame22 | 0:29983394c6b6 | 668 | */ |
edamame22 | 0:29983394c6b6 | 669 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 670 | ble_error_t BlueNRGGap::getPreferredConnectionParams(ConnectionParams_t *params) |
edamame22 | 0:29983394c6b6 | 671 | { |
edamame22 | 0:29983394c6b6 | 672 | static const size_t parameter_size = 2; |
edamame22 | 0:29983394c6b6 | 673 | |
edamame22 | 0:29983394c6b6 | 674 | if (!g_preferred_connection_parameters_char_handle) { |
edamame22 | 0:29983394c6b6 | 675 | return BLE_ERROR_OPERATION_NOT_PERMITTED; |
edamame22 | 0:29983394c6b6 | 676 | } |
edamame22 | 0:29983394c6b6 | 677 | |
edamame22 | 0:29983394c6b6 | 678 | // Peripheral preferred connection parameters are an array of 4 uint16_t |
edamame22 | 0:29983394c6b6 | 679 | uint8_t parameters_packed[parameter_size * 4]; |
edamame22 | 0:29983394c6b6 | 680 | uint16_t bytes_read = 0; |
edamame22 | 0:29983394c6b6 | 681 | |
edamame22 | 0:29983394c6b6 | 682 | tBleStatus err = aci_gatt_read_handle_value( |
edamame22 | 0:29983394c6b6 | 683 | g_preferred_connection_parameters_char_handle + BlueNRGGattServer::CHAR_VALUE_HANDLE, |
edamame22 | 0:29983394c6b6 | 684 | sizeof(parameters_packed), |
edamame22 | 0:29983394c6b6 | 685 | &bytes_read, |
edamame22 | 0:29983394c6b6 | 686 | parameters_packed |
edamame22 | 0:29983394c6b6 | 687 | ); |
edamame22 | 0:29983394c6b6 | 688 | |
edamame22 | 0:29983394c6b6 | 689 | PRINTF("getPreferredConnectionParams err=0x%02x (bytes_read=%u)\n\r", err, bytes_read); |
edamame22 | 0:29983394c6b6 | 690 | |
edamame22 | 0:29983394c6b6 | 691 | // check that the read succeed and the result have the expected length |
edamame22 | 0:29983394c6b6 | 692 | if (err || bytes_read != sizeof(parameters_packed)) { |
edamame22 | 0:29983394c6b6 | 693 | return BLE_ERROR_UNSPECIFIED; |
edamame22 | 0:29983394c6b6 | 694 | } |
edamame22 | 0:29983394c6b6 | 695 | |
edamame22 | 0:29983394c6b6 | 696 | // memcpy field by field |
edamame22 | 0:29983394c6b6 | 697 | memcpy(¶ms->minConnectionInterval, parameters_packed, parameter_size); |
edamame22 | 0:29983394c6b6 | 698 | memcpy(¶ms->maxConnectionInterval, ¶meters_packed[parameter_size], parameter_size); |
edamame22 | 0:29983394c6b6 | 699 | memcpy(¶ms->slaveLatency, ¶meters_packed[2 * parameter_size], parameter_size); |
edamame22 | 0:29983394c6b6 | 700 | memcpy(¶ms->connectionSupervisionTimeout, ¶meters_packed[3 * parameter_size], parameter_size); |
edamame22 | 0:29983394c6b6 | 701 | |
edamame22 | 0:29983394c6b6 | 702 | return BLE_ERROR_NONE; |
edamame22 | 0:29983394c6b6 | 703 | } |
edamame22 | 0:29983394c6b6 | 704 | |
edamame22 | 0:29983394c6b6 | 705 | |
edamame22 | 0:29983394c6b6 | 706 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 707 | /*! |
edamame22 | 0:29983394c6b6 | 708 | @brief sets preferred connection params |
edamame22 | 0:29983394c6b6 | 709 | |
edamame22 | 0:29983394c6b6 | 710 | @returns ble_error_t |
edamame22 | 0:29983394c6b6 | 711 | |
edamame22 | 0:29983394c6b6 | 712 | @section EXAMPLE |
edamame22 | 0:29983394c6b6 | 713 | |
edamame22 | 0:29983394c6b6 | 714 | @code |
edamame22 | 0:29983394c6b6 | 715 | |
edamame22 | 0:29983394c6b6 | 716 | @endcode |
edamame22 | 0:29983394c6b6 | 717 | */ |
edamame22 | 0:29983394c6b6 | 718 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 719 | ble_error_t BlueNRGGap::setPreferredConnectionParams(const ConnectionParams_t *params) |
edamame22 | 0:29983394c6b6 | 720 | { |
edamame22 | 0:29983394c6b6 | 721 | static const size_t parameter_size = 2; |
edamame22 | 0:29983394c6b6 | 722 | uint8_t parameters_packed[parameter_size * 4]; |
edamame22 | 0:29983394c6b6 | 723 | |
edamame22 | 0:29983394c6b6 | 724 | // ensure that parameters are correct |
edamame22 | 0:29983394c6b6 | 725 | // see BLUETOOTH SPECIFICATION Version 4.2 [Vol 3, Part C] |
edamame22 | 0:29983394c6b6 | 726 | // section 12.3 PERIPHERAL PREFERRED CONNECTION PARAMETERS CHARACTERISTIC |
edamame22 | 0:29983394c6b6 | 727 | if (((0x0006 > params->minConnectionInterval) || (params->minConnectionInterval > 0x0C80)) && |
edamame22 | 0:29983394c6b6 | 728 | params->minConnectionInterval != 0xFFFF) { |
edamame22 | 0:29983394c6b6 | 729 | return BLE_ERROR_PARAM_OUT_OF_RANGE; |
edamame22 | 0:29983394c6b6 | 730 | } |
edamame22 | 0:29983394c6b6 | 731 | |
edamame22 | 0:29983394c6b6 | 732 | if (((params->minConnectionInterval > params->maxConnectionInterval) || (params->maxConnectionInterval > 0x0C80)) && |
edamame22 | 0:29983394c6b6 | 733 | params->maxConnectionInterval != 0xFFFF) { |
edamame22 | 0:29983394c6b6 | 734 | return BLE_ERROR_PARAM_OUT_OF_RANGE; |
edamame22 | 0:29983394c6b6 | 735 | } |
edamame22 | 0:29983394c6b6 | 736 | |
edamame22 | 0:29983394c6b6 | 737 | if (params->slaveLatency > 0x01F3) { |
edamame22 | 0:29983394c6b6 | 738 | return BLE_ERROR_PARAM_OUT_OF_RANGE; |
edamame22 | 0:29983394c6b6 | 739 | } |
edamame22 | 0:29983394c6b6 | 740 | |
edamame22 | 0:29983394c6b6 | 741 | if (((0x000A > params->connectionSupervisionTimeout) || (params->connectionSupervisionTimeout > 0x0C80)) && |
edamame22 | 0:29983394c6b6 | 742 | params->connectionSupervisionTimeout != 0xFFFF) { |
edamame22 | 0:29983394c6b6 | 743 | return BLE_ERROR_PARAM_OUT_OF_RANGE; |
edamame22 | 0:29983394c6b6 | 744 | } |
edamame22 | 0:29983394c6b6 | 745 | |
edamame22 | 0:29983394c6b6 | 746 | // copy the parameters inside the byte array |
edamame22 | 0:29983394c6b6 | 747 | memcpy(parameters_packed, ¶ms->minConnectionInterval, parameter_size); |
edamame22 | 0:29983394c6b6 | 748 | memcpy(¶meters_packed[parameter_size], ¶ms->maxConnectionInterval, parameter_size); |
edamame22 | 0:29983394c6b6 | 749 | memcpy(¶meters_packed[2 * parameter_size], ¶ms->slaveLatency, parameter_size); |
edamame22 | 0:29983394c6b6 | 750 | memcpy(¶meters_packed[3 * parameter_size], ¶ms->connectionSupervisionTimeout, parameter_size); |
edamame22 | 0:29983394c6b6 | 751 | |
edamame22 | 0:29983394c6b6 | 752 | tBleStatus err = aci_gatt_update_char_value( |
edamame22 | 0:29983394c6b6 | 753 | g_gap_service_handle, |
edamame22 | 0:29983394c6b6 | 754 | g_preferred_connection_parameters_char_handle, |
edamame22 | 0:29983394c6b6 | 755 | /* offset */ 0, |
edamame22 | 0:29983394c6b6 | 756 | sizeof(parameters_packed), |
edamame22 | 0:29983394c6b6 | 757 | parameters_packed |
edamame22 | 0:29983394c6b6 | 758 | ); |
edamame22 | 0:29983394c6b6 | 759 | |
edamame22 | 0:29983394c6b6 | 760 | if (err) { |
edamame22 | 0:29983394c6b6 | 761 | PRINTF("setPreferredConnectionParams failed (err=0x%x)!!\n\r", err) ; |
edamame22 | 0:29983394c6b6 | 762 | switch (err) { |
edamame22 | 0:29983394c6b6 | 763 | case BLE_STATUS_INVALID_HANDLE: |
edamame22 | 0:29983394c6b6 | 764 | case BLE_STATUS_INVALID_PARAMETER: |
edamame22 | 0:29983394c6b6 | 765 | return BLE_ERROR_INVALID_PARAM; |
edamame22 | 0:29983394c6b6 | 766 | case BLE_STATUS_INSUFFICIENT_RESOURCES: |
edamame22 | 0:29983394c6b6 | 767 | return BLE_ERROR_NO_MEM; |
edamame22 | 0:29983394c6b6 | 768 | case BLE_STATUS_TIMEOUT: |
edamame22 | 0:29983394c6b6 | 769 | return BLE_STACK_BUSY; |
edamame22 | 0:29983394c6b6 | 770 | default: |
edamame22 | 0:29983394c6b6 | 771 | return BLE_ERROR_UNSPECIFIED; |
edamame22 | 0:29983394c6b6 | 772 | } |
edamame22 | 0:29983394c6b6 | 773 | } |
edamame22 | 0:29983394c6b6 | 774 | |
edamame22 | 0:29983394c6b6 | 775 | return BLE_ERROR_NONE; |
edamame22 | 0:29983394c6b6 | 776 | } |
edamame22 | 0:29983394c6b6 | 777 | |
edamame22 | 0:29983394c6b6 | 778 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 779 | /*! |
edamame22 | 0:29983394c6b6 | 780 | @brief updates preferred connection params |
edamame22 | 0:29983394c6b6 | 781 | |
edamame22 | 0:29983394c6b6 | 782 | @returns ble_error_t |
edamame22 | 0:29983394c6b6 | 783 | |
edamame22 | 0:29983394c6b6 | 784 | @section EXAMPLE |
edamame22 | 0:29983394c6b6 | 785 | |
edamame22 | 0:29983394c6b6 | 786 | @code |
edamame22 | 0:29983394c6b6 | 787 | |
edamame22 | 0:29983394c6b6 | 788 | @endcode |
edamame22 | 0:29983394c6b6 | 789 | */ |
edamame22 | 0:29983394c6b6 | 790 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 791 | ble_error_t BlueNRGGap::updateConnectionParams(Handle_t handle, const ConnectionParams_t *params) |
edamame22 | 0:29983394c6b6 | 792 | { |
edamame22 | 0:29983394c6b6 | 793 | tBleStatus ret = BLE_STATUS_SUCCESS; |
edamame22 | 0:29983394c6b6 | 794 | |
edamame22 | 0:29983394c6b6 | 795 | if(gapRole == Gap::CENTRAL) { |
edamame22 | 0:29983394c6b6 | 796 | ret = aci_gap_start_connection_update(handle, |
edamame22 | 0:29983394c6b6 | 797 | params->minConnectionInterval, |
edamame22 | 0:29983394c6b6 | 798 | params->maxConnectionInterval, |
edamame22 | 0:29983394c6b6 | 799 | params->slaveLatency, |
edamame22 | 0:29983394c6b6 | 800 | params->connectionSupervisionTimeout, |
edamame22 | 0:29983394c6b6 | 801 | CONN_L1, CONN_L2); |
edamame22 | 0:29983394c6b6 | 802 | } else { |
edamame22 | 0:29983394c6b6 | 803 | ret = aci_l2cap_connection_parameter_update_request(handle, |
edamame22 | 0:29983394c6b6 | 804 | params->minConnectionInterval, |
edamame22 | 0:29983394c6b6 | 805 | params->maxConnectionInterval, |
edamame22 | 0:29983394c6b6 | 806 | params->slaveLatency, |
edamame22 | 0:29983394c6b6 | 807 | params->connectionSupervisionTimeout); |
edamame22 | 0:29983394c6b6 | 808 | } |
edamame22 | 0:29983394c6b6 | 809 | |
edamame22 | 0:29983394c6b6 | 810 | if (BLE_STATUS_SUCCESS != ret){ |
edamame22 | 0:29983394c6b6 | 811 | PRINTF("updateConnectionParams failed (ret=0x%x)!!\n\r", ret) ; |
edamame22 | 0:29983394c6b6 | 812 | switch (ret) { |
edamame22 | 0:29983394c6b6 | 813 | case ERR_INVALID_HCI_CMD_PARAMS: |
edamame22 | 0:29983394c6b6 | 814 | case BLE_STATUS_INVALID_PARAMETER: |
edamame22 | 0:29983394c6b6 | 815 | return BLE_ERROR_INVALID_PARAM; |
edamame22 | 0:29983394c6b6 | 816 | case ERR_COMMAND_DISALLOWED: |
edamame22 | 0:29983394c6b6 | 817 | case BLE_STATUS_NOT_ALLOWED: |
edamame22 | 0:29983394c6b6 | 818 | return BLE_ERROR_OPERATION_NOT_PERMITTED; |
edamame22 | 0:29983394c6b6 | 819 | default: |
edamame22 | 0:29983394c6b6 | 820 | return BLE_ERROR_UNSPECIFIED; |
edamame22 | 0:29983394c6b6 | 821 | } |
edamame22 | 0:29983394c6b6 | 822 | } |
edamame22 | 0:29983394c6b6 | 823 | |
edamame22 | 0:29983394c6b6 | 824 | return BLE_ERROR_NONE; |
edamame22 | 0:29983394c6b6 | 825 | } |
edamame22 | 0:29983394c6b6 | 826 | |
edamame22 | 0:29983394c6b6 | 827 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 828 | /*! |
edamame22 | 0:29983394c6b6 | 829 | @brief Sets the Device Name Characteristic |
edamame22 | 0:29983394c6b6 | 830 | |
edamame22 | 0:29983394c6b6 | 831 | @param[in] deviceName |
edamame22 | 0:29983394c6b6 | 832 | pointer to device name to be set |
edamame22 | 0:29983394c6b6 | 833 | |
edamame22 | 0:29983394c6b6 | 834 | @returns ble_error_t |
edamame22 | 0:29983394c6b6 | 835 | |
edamame22 | 0:29983394c6b6 | 836 | @retval BLE_ERROR_NONE |
edamame22 | 0:29983394c6b6 | 837 | Everything executed properly |
edamame22 | 0:29983394c6b6 | 838 | |
edamame22 | 0:29983394c6b6 | 839 | @section EXAMPLE |
edamame22 | 0:29983394c6b6 | 840 | |
edamame22 | 0:29983394c6b6 | 841 | @code |
edamame22 | 0:29983394c6b6 | 842 | |
edamame22 | 0:29983394c6b6 | 843 | @endcode |
edamame22 | 0:29983394c6b6 | 844 | */ |
edamame22 | 0:29983394c6b6 | 845 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 846 | ble_error_t BlueNRGGap::setDeviceName(const uint8_t *deviceName) |
edamame22 | 0:29983394c6b6 | 847 | { |
edamame22 | 0:29983394c6b6 | 848 | tBleStatus ret; |
edamame22 | 0:29983394c6b6 | 849 | uint8_t nameLen = 0; |
edamame22 | 0:29983394c6b6 | 850 | |
edamame22 | 0:29983394c6b6 | 851 | nameLen = strlen((const char*)deviceName); |
edamame22 | 0:29983394c6b6 | 852 | PRINTF("DeviceName Size=%d\n\r", nameLen); |
edamame22 | 0:29983394c6b6 | 853 | |
edamame22 | 0:29983394c6b6 | 854 | ret = aci_gatt_update_char_value(g_gap_service_handle, |
edamame22 | 0:29983394c6b6 | 855 | g_device_name_char_handle, |
edamame22 | 0:29983394c6b6 | 856 | 0, |
edamame22 | 0:29983394c6b6 | 857 | nameLen, |
edamame22 | 0:29983394c6b6 | 858 | deviceName); |
edamame22 | 0:29983394c6b6 | 859 | |
edamame22 | 0:29983394c6b6 | 860 | if (BLE_STATUS_SUCCESS != ret){ |
edamame22 | 0:29983394c6b6 | 861 | PRINTF("device set name failed (ret=0x%x)!!\n\r", ret) ; |
edamame22 | 0:29983394c6b6 | 862 | switch (ret) { |
edamame22 | 0:29983394c6b6 | 863 | case BLE_STATUS_INVALID_HANDLE: |
edamame22 | 0:29983394c6b6 | 864 | case BLE_STATUS_INVALID_PARAMETER: |
edamame22 | 0:29983394c6b6 | 865 | return BLE_ERROR_INVALID_PARAM; |
edamame22 | 0:29983394c6b6 | 866 | case BLE_STATUS_INSUFFICIENT_RESOURCES: |
edamame22 | 0:29983394c6b6 | 867 | return BLE_ERROR_NO_MEM; |
edamame22 | 0:29983394c6b6 | 868 | case BLE_STATUS_TIMEOUT: |
edamame22 | 0:29983394c6b6 | 869 | return BLE_STACK_BUSY; |
edamame22 | 0:29983394c6b6 | 870 | default: |
edamame22 | 0:29983394c6b6 | 871 | return BLE_ERROR_UNSPECIFIED; |
edamame22 | 0:29983394c6b6 | 872 | } |
edamame22 | 0:29983394c6b6 | 873 | } |
edamame22 | 0:29983394c6b6 | 874 | |
edamame22 | 0:29983394c6b6 | 875 | return BLE_ERROR_NONE; |
edamame22 | 0:29983394c6b6 | 876 | } |
edamame22 | 0:29983394c6b6 | 877 | |
edamame22 | 0:29983394c6b6 | 878 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 879 | /*! |
edamame22 | 0:29983394c6b6 | 880 | @brief Gets the Device Name Characteristic |
edamame22 | 0:29983394c6b6 | 881 | |
edamame22 | 0:29983394c6b6 | 882 | @param[in] deviceName |
edamame22 | 0:29983394c6b6 | 883 | pointer to device name |
edamame22 | 0:29983394c6b6 | 884 | |
edamame22 | 0:29983394c6b6 | 885 | @param[in] lengthP |
edamame22 | 0:29983394c6b6 | 886 | pointer to device name length |
edamame22 | 0:29983394c6b6 | 887 | |
edamame22 | 0:29983394c6b6 | 888 | @returns ble_error_t |
edamame22 | 0:29983394c6b6 | 889 | |
edamame22 | 0:29983394c6b6 | 890 | @retval BLE_ERROR_NONE |
edamame22 | 0:29983394c6b6 | 891 | Everything executed properly |
edamame22 | 0:29983394c6b6 | 892 | |
edamame22 | 0:29983394c6b6 | 893 | @section EXAMPLE |
edamame22 | 0:29983394c6b6 | 894 | |
edamame22 | 0:29983394c6b6 | 895 | @code |
edamame22 | 0:29983394c6b6 | 896 | |
edamame22 | 0:29983394c6b6 | 897 | @endcode |
edamame22 | 0:29983394c6b6 | 898 | */ |
edamame22 | 0:29983394c6b6 | 899 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 900 | ble_error_t BlueNRGGap::getDeviceName(uint8_t *deviceName, unsigned *lengthP) |
edamame22 | 0:29983394c6b6 | 901 | { |
edamame22 | 0:29983394c6b6 | 902 | tBleStatus ret; |
edamame22 | 0:29983394c6b6 | 903 | |
edamame22 | 0:29983394c6b6 | 904 | ret = aci_gatt_read_handle_value(g_device_name_char_handle+BlueNRGGattServer::CHAR_VALUE_HANDLE, |
edamame22 | 0:29983394c6b6 | 905 | *lengthP, |
edamame22 | 0:29983394c6b6 | 906 | (uint16_t *)lengthP, |
edamame22 | 0:29983394c6b6 | 907 | deviceName); |
edamame22 | 0:29983394c6b6 | 908 | PRINTF("getDeviceName ret=0x%02x (lengthP=%d)\n\r", ret, *lengthP); |
edamame22 | 0:29983394c6b6 | 909 | if (ret == BLE_STATUS_SUCCESS) { |
edamame22 | 0:29983394c6b6 | 910 | return BLE_ERROR_NONE; |
edamame22 | 0:29983394c6b6 | 911 | } else { |
edamame22 | 0:29983394c6b6 | 912 | return BLE_ERROR_PARAM_OUT_OF_RANGE; |
edamame22 | 0:29983394c6b6 | 913 | } |
edamame22 | 0:29983394c6b6 | 914 | } |
edamame22 | 0:29983394c6b6 | 915 | |
edamame22 | 0:29983394c6b6 | 916 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 917 | /*! |
edamame22 | 0:29983394c6b6 | 918 | @brief Sets the Device Appearance Characteristic |
edamame22 | 0:29983394c6b6 | 919 | |
edamame22 | 0:29983394c6b6 | 920 | @param[in] appearance |
edamame22 | 0:29983394c6b6 | 921 | device appearance |
edamame22 | 0:29983394c6b6 | 922 | |
edamame22 | 0:29983394c6b6 | 923 | @returns ble_error_t |
edamame22 | 0:29983394c6b6 | 924 | |
edamame22 | 0:29983394c6b6 | 925 | @retval BLE_ERROR_NONE |
edamame22 | 0:29983394c6b6 | 926 | Everything executed properly |
edamame22 | 0:29983394c6b6 | 927 | |
edamame22 | 0:29983394c6b6 | 928 | @section EXAMPLE |
edamame22 | 0:29983394c6b6 | 929 | |
edamame22 | 0:29983394c6b6 | 930 | @code |
edamame22 | 0:29983394c6b6 | 931 | |
edamame22 | 0:29983394c6b6 | 932 | @endcode |
edamame22 | 0:29983394c6b6 | 933 | */ |
edamame22 | 0:29983394c6b6 | 934 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 935 | ble_error_t BlueNRGGap::setAppearance(GapAdvertisingData::Appearance appearance) |
edamame22 | 0:29983394c6b6 | 936 | { |
edamame22 | 0:29983394c6b6 | 937 | tBleStatus ret; |
edamame22 | 0:29983394c6b6 | 938 | uint8_t deviceAppearance[2]; |
edamame22 | 0:29983394c6b6 | 939 | |
edamame22 | 0:29983394c6b6 | 940 | STORE_LE_16(deviceAppearance, appearance); |
edamame22 | 0:29983394c6b6 | 941 | PRINTF("setAppearance= 0x%x 0x%x\n\r", deviceAppearance[1], deviceAppearance[0]); |
edamame22 | 0:29983394c6b6 | 942 | |
edamame22 | 0:29983394c6b6 | 943 | ret = aci_gatt_update_char_value(g_gap_service_handle, |
edamame22 | 0:29983394c6b6 | 944 | g_appearance_char_handle, |
edamame22 | 0:29983394c6b6 | 945 | 0, 2, (uint8_t *)deviceAppearance); |
edamame22 | 0:29983394c6b6 | 946 | if (BLE_STATUS_SUCCESS == ret){ |
edamame22 | 0:29983394c6b6 | 947 | return BLE_ERROR_NONE; |
edamame22 | 0:29983394c6b6 | 948 | } |
edamame22 | 0:29983394c6b6 | 949 | |
edamame22 | 0:29983394c6b6 | 950 | PRINTF("setAppearance failed (ret=0x%x)!!\n\r", ret); |
edamame22 | 0:29983394c6b6 | 951 | switch (ret) { |
edamame22 | 0:29983394c6b6 | 952 | case BLE_STATUS_INVALID_HANDLE: |
edamame22 | 0:29983394c6b6 | 953 | case BLE_STATUS_INVALID_PARAMETER: |
edamame22 | 0:29983394c6b6 | 954 | return BLE_ERROR_INVALID_PARAM; |
edamame22 | 0:29983394c6b6 | 955 | case BLE_STATUS_INSUFFICIENT_RESOURCES: |
edamame22 | 0:29983394c6b6 | 956 | return BLE_ERROR_NO_MEM; |
edamame22 | 0:29983394c6b6 | 957 | case BLE_STATUS_TIMEOUT: |
edamame22 | 0:29983394c6b6 | 958 | return BLE_STACK_BUSY; |
edamame22 | 0:29983394c6b6 | 959 | default: |
edamame22 | 0:29983394c6b6 | 960 | return BLE_ERROR_UNSPECIFIED; |
edamame22 | 0:29983394c6b6 | 961 | } |
edamame22 | 0:29983394c6b6 | 962 | } |
edamame22 | 0:29983394c6b6 | 963 | |
edamame22 | 0:29983394c6b6 | 964 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 965 | /*! |
edamame22 | 0:29983394c6b6 | 966 | @brief Gets the Device Appearance Characteristic |
edamame22 | 0:29983394c6b6 | 967 | |
edamame22 | 0:29983394c6b6 | 968 | @param[in] appearance |
edamame22 | 0:29983394c6b6 | 969 | pointer to device appearance value |
edamame22 | 0:29983394c6b6 | 970 | |
edamame22 | 0:29983394c6b6 | 971 | @returns ble_error_t |
edamame22 | 0:29983394c6b6 | 972 | |
edamame22 | 0:29983394c6b6 | 973 | @retval BLE_ERROR_NONE |
edamame22 | 0:29983394c6b6 | 974 | Everything executed properly |
edamame22 | 0:29983394c6b6 | 975 | |
edamame22 | 0:29983394c6b6 | 976 | @section EXAMPLE |
edamame22 | 0:29983394c6b6 | 977 | |
edamame22 | 0:29983394c6b6 | 978 | @code |
edamame22 | 0:29983394c6b6 | 979 | |
edamame22 | 0:29983394c6b6 | 980 | @endcode |
edamame22 | 0:29983394c6b6 | 981 | */ |
edamame22 | 0:29983394c6b6 | 982 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 983 | ble_error_t BlueNRGGap::getAppearance(GapAdvertisingData::Appearance *appearanceP) |
edamame22 | 0:29983394c6b6 | 984 | { |
edamame22 | 0:29983394c6b6 | 985 | tBleStatus ret; |
edamame22 | 0:29983394c6b6 | 986 | uint16_t lengthP = 2; |
edamame22 | 0:29983394c6b6 | 987 | |
edamame22 | 0:29983394c6b6 | 988 | ret = aci_gatt_read_handle_value(g_appearance_char_handle+BlueNRGGattServer::CHAR_VALUE_HANDLE, |
edamame22 | 0:29983394c6b6 | 989 | lengthP, |
edamame22 | 0:29983394c6b6 | 990 | &lengthP, |
edamame22 | 0:29983394c6b6 | 991 | (uint8_t*)appearanceP); |
edamame22 | 0:29983394c6b6 | 992 | PRINTF("getAppearance ret=0x%02x (lengthP=%d)\n\r", ret, lengthP); |
edamame22 | 0:29983394c6b6 | 993 | if (ret == BLE_STATUS_SUCCESS) { |
edamame22 | 0:29983394c6b6 | 994 | return BLE_ERROR_NONE; |
edamame22 | 0:29983394c6b6 | 995 | } else { |
edamame22 | 0:29983394c6b6 | 996 | return BLE_ERROR_PARAM_OUT_OF_RANGE; |
edamame22 | 0:29983394c6b6 | 997 | } |
edamame22 | 0:29983394c6b6 | 998 | |
edamame22 | 0:29983394c6b6 | 999 | } |
edamame22 | 0:29983394c6b6 | 1000 | |
edamame22 | 0:29983394c6b6 | 1001 | GapScanningParams* BlueNRGGap::getScanningParams(void) |
edamame22 | 0:29983394c6b6 | 1002 | { |
edamame22 | 0:29983394c6b6 | 1003 | return &_scanningParams; |
edamame22 | 0:29983394c6b6 | 1004 | } |
edamame22 | 0:29983394c6b6 | 1005 | |
edamame22 | 0:29983394c6b6 | 1006 | static void makeConnection(void) |
edamame22 | 0:29983394c6b6 | 1007 | { |
edamame22 | 0:29983394c6b6 | 1008 | BlueNRGGap::getInstance().createConnection(); |
edamame22 | 0:29983394c6b6 | 1009 | } |
edamame22 | 0:29983394c6b6 | 1010 | |
edamame22 | 0:29983394c6b6 | 1011 | void BlueNRGGap::Discovery_CB(Reason_t reason, |
edamame22 | 0:29983394c6b6 | 1012 | uint8_t adv_type, |
edamame22 | 0:29983394c6b6 | 1013 | uint8_t addr_type, |
edamame22 | 0:29983394c6b6 | 1014 | uint8_t *addr, |
edamame22 | 0:29983394c6b6 | 1015 | uint8_t *data_length, |
edamame22 | 0:29983394c6b6 | 1016 | uint8_t *data, |
edamame22 | 0:29983394c6b6 | 1017 | uint8_t *RSSI) |
edamame22 | 0:29983394c6b6 | 1018 | { |
edamame22 | 0:29983394c6b6 | 1019 | switch (reason) { |
edamame22 | 0:29983394c6b6 | 1020 | case DEVICE_FOUND: |
edamame22 | 0:29983394c6b6 | 1021 | { |
edamame22 | 0:29983394c6b6 | 1022 | GapAdvertisingParams::AdvertisingType_t type; |
edamame22 | 0:29983394c6b6 | 1023 | bool isScanResponse = false; |
edamame22 | 0:29983394c6b6 | 1024 | |
edamame22 | 0:29983394c6b6 | 1025 | /* |
edamame22 | 0:29983394c6b6 | 1026 | * Whitelisting (scan policy): |
edamame22 | 0:29983394c6b6 | 1027 | * SCAN_POLICY_FILTER_ALL_ADV (ADV packets only from devs in the White List) && |
edamame22 | 0:29983394c6b6 | 1028 | * Private Random Address |
edamame22 | 0:29983394c6b6 | 1029 | * => scan_results = FALSE |
edamame22 | 0:29983394c6b6 | 1030 | * FIXME: the Security Manager should be implemented |
edamame22 | 0:29983394c6b6 | 1031 | */ |
edamame22 | 0:29983394c6b6 | 1032 | ScanningPolicyMode_t mode = getScanningPolicyMode(); |
edamame22 | 0:29983394c6b6 | 1033 | PRINTF("mode=%u addr_type=%u\n\r", mode, addr_type); |
edamame22 | 0:29983394c6b6 | 1034 | if(mode == Gap::SCAN_POLICY_FILTER_ALL_ADV || |
edamame22 | 0:29983394c6b6 | 1035 | (addr_type == RESOLVABLE_PRIVATE_ADDR || |
edamame22 | 0:29983394c6b6 | 1036 | addr_type == NON_RESOLVABLE_PRIVATE_ADDR)) { |
edamame22 | 0:29983394c6b6 | 1037 | return; |
edamame22 | 0:29983394c6b6 | 1038 | } |
edamame22 | 0:29983394c6b6 | 1039 | |
edamame22 | 0:29983394c6b6 | 1040 | switch(adv_type) { |
edamame22 | 0:29983394c6b6 | 1041 | case ADV_IND: |
edamame22 | 0:29983394c6b6 | 1042 | type = GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED; |
edamame22 | 0:29983394c6b6 | 1043 | break; |
edamame22 | 0:29983394c6b6 | 1044 | case ADV_DIRECT_IND: |
edamame22 | 0:29983394c6b6 | 1045 | type = GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED; |
edamame22 | 0:29983394c6b6 | 1046 | break; |
edamame22 | 0:29983394c6b6 | 1047 | case ADV_SCAN_IND: |
edamame22 | 0:29983394c6b6 | 1048 | case SCAN_RSP: |
edamame22 | 0:29983394c6b6 | 1049 | type = GapAdvertisingParams::ADV_SCANNABLE_UNDIRECTED; |
edamame22 | 0:29983394c6b6 | 1050 | isScanResponse = true; |
edamame22 | 0:29983394c6b6 | 1051 | break; |
edamame22 | 0:29983394c6b6 | 1052 | case ADV_NONCONN_IND: |
edamame22 | 0:29983394c6b6 | 1053 | type = GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED; |
edamame22 | 0:29983394c6b6 | 1054 | break; |
edamame22 | 0:29983394c6b6 | 1055 | default: |
edamame22 | 0:29983394c6b6 | 1056 | type = GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED; |
edamame22 | 0:29983394c6b6 | 1057 | } |
edamame22 | 0:29983394c6b6 | 1058 | |
edamame22 | 0:29983394c6b6 | 1059 | PRINTF("data_length=%d adv peerAddr[%02x %02x %02x %02x %02x %02x] \r\n", |
edamame22 | 0:29983394c6b6 | 1060 | *data_length, addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]); |
edamame22 | 0:29983394c6b6 | 1061 | if(!_connecting) { |
edamame22 | 0:29983394c6b6 | 1062 | processAdvertisementReport(addr, *RSSI, isScanResponse, type, *data_length, data); |
edamame22 | 0:29983394c6b6 | 1063 | } |
edamame22 | 0:29983394c6b6 | 1064 | PRINTF("!!!After processAdvertisementReport\n\r"); |
edamame22 | 0:29983394c6b6 | 1065 | } |
edamame22 | 0:29983394c6b6 | 1066 | break; |
edamame22 | 0:29983394c6b6 | 1067 | |
edamame22 | 0:29983394c6b6 | 1068 | case DISCOVERY_COMPLETE: |
edamame22 | 0:29983394c6b6 | 1069 | // The discovery is complete. If this is due to a stop scanning (i.e., the device |
edamame22 | 0:29983394c6b6 | 1070 | // we are interested in has been found) and a connection has been requested |
edamame22 | 0:29983394c6b6 | 1071 | // then we start the device connection. |
edamame22 | 0:29983394c6b6 | 1072 | PRINTF("DISCOVERY_COMPLETE\n\r"); |
edamame22 | 0:29983394c6b6 | 1073 | _scanning = false; |
edamame22 | 0:29983394c6b6 | 1074 | |
edamame22 | 0:29983394c6b6 | 1075 | // Since the DISCOVERY_COMPLETE event can be received during the scanning interval, |
edamame22 | 0:29983394c6b6 | 1076 | // we need to delay the starting of connection |
edamame22 | 0:29983394c6b6 | 1077 | uint16_t delay = 2*(_scanningParams.getInterval()); |
edamame22 | 0:29983394c6b6 | 1078 | |
edamame22 | 0:29983394c6b6 | 1079 | #ifdef AST_FOR_MBED_OS |
edamame22 | 0:29983394c6b6 | 1080 | if(_connecting) { |
edamame22 | 0:29983394c6b6 | 1081 | minar::Scheduler::postCallback(makeConnection).delay(minar::milliseconds(delay)); |
edamame22 | 0:29983394c6b6 | 1082 | } |
edamame22 | 0:29983394c6b6 | 1083 | #else |
edamame22 | 0:29983394c6b6 | 1084 | Clock_Wait(delay); |
edamame22 | 0:29983394c6b6 | 1085 | if(_connecting) { |
edamame22 | 0:29983394c6b6 | 1086 | makeConnection(); |
edamame22 | 0:29983394c6b6 | 1087 | } |
edamame22 | 0:29983394c6b6 | 1088 | #endif /* AST_FOR_MBED_OS */ |
edamame22 | 0:29983394c6b6 | 1089 | |
edamame22 | 0:29983394c6b6 | 1090 | break; |
edamame22 | 0:29983394c6b6 | 1091 | } |
edamame22 | 0:29983394c6b6 | 1092 | } |
edamame22 | 0:29983394c6b6 | 1093 | |
edamame22 | 0:29983394c6b6 | 1094 | ble_error_t BlueNRGGap::startRadioScan(const GapScanningParams &scanningParams) |
edamame22 | 0:29983394c6b6 | 1095 | { |
edamame22 | 0:29983394c6b6 | 1096 | |
edamame22 | 0:29983394c6b6 | 1097 | tBleStatus ret = BLE_STATUS_SUCCESS; |
edamame22 | 0:29983394c6b6 | 1098 | |
edamame22 | 0:29983394c6b6 | 1099 | // Stop ADV before scanning |
edamame22 | 0:29983394c6b6 | 1100 | /* |
edamame22 | 0:29983394c6b6 | 1101 | if (state.advertising == 1) { |
edamame22 | 0:29983394c6b6 | 1102 | stopAdvertising(); |
edamame22 | 0:29983394c6b6 | 1103 | } |
edamame22 | 0:29983394c6b6 | 1104 | */ |
edamame22 | 0:29983394c6b6 | 1105 | |
edamame22 | 0:29983394c6b6 | 1106 | /* |
edamame22 | 0:29983394c6b6 | 1107 | * Whitelisting (scan policy): |
edamame22 | 0:29983394c6b6 | 1108 | * SCAN_POLICY_FILTER_ALL_ADV (ADV packets only from devs in the White List) && |
edamame22 | 0:29983394c6b6 | 1109 | * White List is empty |
edamame22 | 0:29983394c6b6 | 1110 | * => scan operation = FAILURE |
edamame22 | 0:29983394c6b6 | 1111 | * FIXME: the Security Manager should be implemented |
edamame22 | 0:29983394c6b6 | 1112 | */ |
edamame22 | 0:29983394c6b6 | 1113 | ScanningPolicyMode_t mode = getScanningPolicyMode(); |
edamame22 | 0:29983394c6b6 | 1114 | uint8_t whiteListSize = whitelistAddresses.size; |
edamame22 | 0:29983394c6b6 | 1115 | if(whiteListSize == 0 && mode == Gap::SCAN_POLICY_FILTER_ALL_ADV) { |
edamame22 | 0:29983394c6b6 | 1116 | return BLE_ERROR_OPERATION_NOT_PERMITTED; |
edamame22 | 0:29983394c6b6 | 1117 | } |
edamame22 | 0:29983394c6b6 | 1118 | |
edamame22 | 0:29983394c6b6 | 1119 | ret = btleStartRadioScan(scanningParams.getActiveScanning(), |
edamame22 | 0:29983394c6b6 | 1120 | scanningParams.getInterval(), |
edamame22 | 0:29983394c6b6 | 1121 | scanningParams.getWindow(), |
edamame22 | 0:29983394c6b6 | 1122 | addr_type); |
edamame22 | 0:29983394c6b6 | 1123 | |
edamame22 | 0:29983394c6b6 | 1124 | PRINTF("Scanning...\n\r"); |
edamame22 | 0:29983394c6b6 | 1125 | PRINTF("scanningParams.getInterval()=%u[msec]\r\n",(scanningParams.getInterval()*625)/1000); |
edamame22 | 0:29983394c6b6 | 1126 | PRINTF("scanningParams.getWindow()=%u[msec]\r\n",(scanningParams.getWindow()*625)/1000); |
edamame22 | 0:29983394c6b6 | 1127 | //PRINTF("_advParams.getInterval()=%u\r\n",_advParams.getInterval()); |
edamame22 | 0:29983394c6b6 | 1128 | //PRINTF("CONN_P1=%u\r\n",(unsigned)CONN_P1); |
edamame22 | 0:29983394c6b6 | 1129 | //PRINTF("CONN_P2=%u\r\n",(unsigned)CONN_P2); |
edamame22 | 0:29983394c6b6 | 1130 | if (BLE_STATUS_SUCCESS == ret){ |
edamame22 | 0:29983394c6b6 | 1131 | PRINTF("Observation Procedure Started\n"); |
edamame22 | 0:29983394c6b6 | 1132 | _scanning = true; |
edamame22 | 0:29983394c6b6 | 1133 | return BLE_ERROR_NONE; |
edamame22 | 0:29983394c6b6 | 1134 | } |
edamame22 | 0:29983394c6b6 | 1135 | |
edamame22 | 0:29983394c6b6 | 1136 | // Observer role is not supported by X-NUCLEO-IDB04A1, return BLE_ERROR_NOT_IMPLEMENTED |
edamame22 | 0:29983394c6b6 | 1137 | switch (ret) { |
edamame22 | 0:29983394c6b6 | 1138 | case BLE_STATUS_INVALID_CID: |
edamame22 | 0:29983394c6b6 | 1139 | PRINTF("Observation Procedure not implemented!!!\n\r"); |
edamame22 | 0:29983394c6b6 | 1140 | return BLE_ERROR_NOT_IMPLEMENTED; |
edamame22 | 0:29983394c6b6 | 1141 | default: |
edamame22 | 0:29983394c6b6 | 1142 | PRINTF("Observation Procedure failed (0x%02X)\n\r", ret); |
edamame22 | 0:29983394c6b6 | 1143 | return BLE_ERROR_UNSPECIFIED; |
edamame22 | 0:29983394c6b6 | 1144 | } |
edamame22 | 0:29983394c6b6 | 1145 | |
edamame22 | 0:29983394c6b6 | 1146 | } |
edamame22 | 0:29983394c6b6 | 1147 | |
edamame22 | 0:29983394c6b6 | 1148 | ble_error_t BlueNRGGap::stopScan() { |
edamame22 | 0:29983394c6b6 | 1149 | tBleStatus ret = BLE_STATUS_SUCCESS; |
edamame22 | 0:29983394c6b6 | 1150 | |
edamame22 | 0:29983394c6b6 | 1151 | PRINTF("stopScan\n\r"); |
edamame22 | 0:29983394c6b6 | 1152 | ret = aci_gap_terminate_gap_procedure(GAP_OBSERVATION_PROC); |
edamame22 | 0:29983394c6b6 | 1153 | |
edamame22 | 0:29983394c6b6 | 1154 | if (ret != BLE_STATUS_SUCCESS) { |
edamame22 | 0:29983394c6b6 | 1155 | PRINTF("GAP Terminate Gap Procedure failed(ret=0x%x)\n", ret); |
edamame22 | 0:29983394c6b6 | 1156 | return BLE_ERROR_UNSPECIFIED; |
edamame22 | 0:29983394c6b6 | 1157 | } else { |
edamame22 | 0:29983394c6b6 | 1158 | PRINTF("Discovery Procedure Terminated\n"); |
edamame22 | 0:29983394c6b6 | 1159 | return BLE_ERROR_NONE; |
edamame22 | 0:29983394c6b6 | 1160 | } |
edamame22 | 0:29983394c6b6 | 1161 | } |
edamame22 | 0:29983394c6b6 | 1162 | |
edamame22 | 0:29983394c6b6 | 1163 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 1164 | /*! |
edamame22 | 0:29983394c6b6 | 1165 | @brief set Tx power level |
edamame22 | 0:29983394c6b6 | 1166 | @param[in] txPower Transmission Power level |
edamame22 | 0:29983394c6b6 | 1167 | @returns ble_error_t |
edamame22 | 0:29983394c6b6 | 1168 | */ |
edamame22 | 0:29983394c6b6 | 1169 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 1170 | ble_error_t BlueNRGGap::setTxPower(int8_t txPower) |
edamame22 | 0:29983394c6b6 | 1171 | { |
edamame22 | 0:29983394c6b6 | 1172 | tBleStatus ret; |
edamame22 | 0:29983394c6b6 | 1173 | |
edamame22 | 0:29983394c6b6 | 1174 | int8_t enHighPower = 0; |
edamame22 | 0:29983394c6b6 | 1175 | int8_t paLevel = 0; |
edamame22 | 0:29983394c6b6 | 1176 | |
edamame22 | 0:29983394c6b6 | 1177 | ret = getHighPowerAndPALevelValue(txPower, enHighPower, paLevel); |
edamame22 | 0:29983394c6b6 | 1178 | if(ret!=BLE_STATUS_SUCCESS) { |
edamame22 | 0:29983394c6b6 | 1179 | return BLE_ERROR_PARAM_OUT_OF_RANGE; |
edamame22 | 0:29983394c6b6 | 1180 | } |
edamame22 | 0:29983394c6b6 | 1181 | |
edamame22 | 0:29983394c6b6 | 1182 | PRINTF("enHighPower=%d, paLevel=%d\n\r", enHighPower, paLevel); |
edamame22 | 0:29983394c6b6 | 1183 | ret = aci_hal_set_tx_power_level(enHighPower, paLevel); |
edamame22 | 0:29983394c6b6 | 1184 | if(ret!=BLE_STATUS_SUCCESS) { |
edamame22 | 0:29983394c6b6 | 1185 | return BLE_ERROR_PARAM_OUT_OF_RANGE; |
edamame22 | 0:29983394c6b6 | 1186 | } |
edamame22 | 0:29983394c6b6 | 1187 | |
edamame22 | 0:29983394c6b6 | 1188 | return BLE_ERROR_NONE; |
edamame22 | 0:29983394c6b6 | 1189 | } |
edamame22 | 0:29983394c6b6 | 1190 | |
edamame22 | 0:29983394c6b6 | 1191 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 1192 | /*! |
edamame22 | 0:29983394c6b6 | 1193 | @brief get permitted Tx power values |
edamame22 | 0:29983394c6b6 | 1194 | @param[in] values pointer to pointer to permitted power values |
edamame22 | 0:29983394c6b6 | 1195 | @param[in] num number of values |
edamame22 | 0:29983394c6b6 | 1196 | */ |
edamame22 | 0:29983394c6b6 | 1197 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 1198 | void BlueNRGGap::getPermittedTxPowerValues(const int8_t **valueArrayPP, size_t *countP) { |
edamame22 | 0:29983394c6b6 | 1199 | static const int8_t permittedTxValues[] = { |
edamame22 | 0:29983394c6b6 | 1200 | -18, -15, -14, -12, -11, -9, -8, -6, -5, -2, 0, 2, 4, 5, 8 |
edamame22 | 0:29983394c6b6 | 1201 | }; |
edamame22 | 0:29983394c6b6 | 1202 | |
edamame22 | 0:29983394c6b6 | 1203 | *valueArrayPP = permittedTxValues; |
edamame22 | 0:29983394c6b6 | 1204 | *countP = sizeof(permittedTxValues) / sizeof(int8_t); |
edamame22 | 0:29983394c6b6 | 1205 | } |
edamame22 | 0:29983394c6b6 | 1206 | |
edamame22 | 0:29983394c6b6 | 1207 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 1208 | /*! |
edamame22 | 0:29983394c6b6 | 1209 | @brief Set advertising parameters according to the current state |
edamame22 | 0:29983394c6b6 | 1210 | Parameters value is set taking into account guidelines of the BlueNRG |
edamame22 | 0:29983394c6b6 | 1211 | time slots allocation |
edamame22 | 0:29983394c6b6 | 1212 | */ |
edamame22 | 0:29983394c6b6 | 1213 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 1214 | void BlueNRGGap::setAdvParameters(void) |
edamame22 | 0:29983394c6b6 | 1215 | { |
edamame22 | 0:29983394c6b6 | 1216 | uint32_t advIntMS; |
edamame22 | 0:29983394c6b6 | 1217 | |
edamame22 | 0:29983394c6b6 | 1218 | if(state.connected == 1) { |
edamame22 | 0:29983394c6b6 | 1219 | advIntMS = (conn_min_interval*1.25)-GUARD_INT; |
edamame22 | 0:29983394c6b6 | 1220 | advInterval = _advParams.MSEC_TO_ADVERTISEMENT_DURATION_UNITS(advIntMS); |
edamame22 | 0:29983394c6b6 | 1221 | |
edamame22 | 0:29983394c6b6 | 1222 | PRINTF("conn_min_interval is equal to %u\r\n", conn_min_interval); |
edamame22 | 0:29983394c6b6 | 1223 | } else { |
edamame22 | 0:29983394c6b6 | 1224 | advInterval = _advParams.getIntervalInADVUnits(); |
edamame22 | 0:29983394c6b6 | 1225 | } |
edamame22 | 0:29983394c6b6 | 1226 | } |
edamame22 | 0:29983394c6b6 | 1227 | |
edamame22 | 0:29983394c6b6 | 1228 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 1229 | /*! |
edamame22 | 0:29983394c6b6 | 1230 | @brief Set connection parameters according to the current state (ADV and/or SCAN) |
edamame22 | 0:29983394c6b6 | 1231 | Parameters value is set taking into account guidelines of the BlueNRG |
edamame22 | 0:29983394c6b6 | 1232 | time slots allocation |
edamame22 | 0:29983394c6b6 | 1233 | */ |
edamame22 | 0:29983394c6b6 | 1234 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 1235 | void BlueNRGGap::setConnectionParameters(void) |
edamame22 | 0:29983394c6b6 | 1236 | { |
edamame22 | 0:29983394c6b6 | 1237 | if (state.advertising == 1) { |
edamame22 | 0:29983394c6b6 | 1238 | |
edamame22 | 0:29983394c6b6 | 1239 | if (_scanningParams.getInterval() < advInterval) { |
edamame22 | 0:29983394c6b6 | 1240 | PRINTF("state.adv=1 scanInterval<advInterval\r\n"); |
edamame22 | 0:29983394c6b6 | 1241 | scanInterval = advInterval; |
edamame22 | 0:29983394c6b6 | 1242 | scanWindow = advInterval; |
edamame22 | 0:29983394c6b6 | 1243 | } else { |
edamame22 | 0:29983394c6b6 | 1244 | PRINTF("state.adv=1 scanInterval>=advInterval\r\n"); |
edamame22 | 0:29983394c6b6 | 1245 | scanInterval = _scanningParams.getInterval(); |
edamame22 | 0:29983394c6b6 | 1246 | scanWindow = _scanningParams.getWindow(); |
edamame22 | 0:29983394c6b6 | 1247 | } |
edamame22 | 0:29983394c6b6 | 1248 | |
edamame22 | 0:29983394c6b6 | 1249 | if(advInterval>(MAX_INT_CONN-(GUARD_INT/1.25))) { //(4000-GUARD_INT)ms |
edamame22 | 0:29983394c6b6 | 1250 | conn_min_interval = MAX_INT_CONN; |
edamame22 | 0:29983394c6b6 | 1251 | conn_max_interval = MAX_INT_CONN; |
edamame22 | 0:29983394c6b6 | 1252 | } else { |
edamame22 | 0:29983394c6b6 | 1253 | conn_min_interval = (_advParams.ADVERTISEMENT_DURATION_UNITS_TO_MS(advInterval)+GUARD_INT)/1.25; |
edamame22 | 0:29983394c6b6 | 1254 | conn_max_interval = (_advParams.ADVERTISEMENT_DURATION_UNITS_TO_MS(advInterval)+GUARD_INT)/1.25; |
edamame22 | 0:29983394c6b6 | 1255 | } |
edamame22 | 0:29983394c6b6 | 1256 | |
edamame22 | 0:29983394c6b6 | 1257 | } else { |
edamame22 | 0:29983394c6b6 | 1258 | |
edamame22 | 0:29983394c6b6 | 1259 | PRINTF("state.adv = 0\r\n"); |
edamame22 | 0:29983394c6b6 | 1260 | |
edamame22 | 0:29983394c6b6 | 1261 | scanInterval = _scanningParams.getInterval(); |
edamame22 | 0:29983394c6b6 | 1262 | scanWindow = _scanningParams.getWindow(); |
edamame22 | 0:29983394c6b6 | 1263 | if(SCAN_DURATION_UNITS_TO_MSEC(scanInterval)>(MAX_INT_CONN*1.25) || |
edamame22 | 0:29983394c6b6 | 1264 | SCAN_DURATION_UNITS_TO_MSEC(scanInterval)<(MIN_INT_CONN*1.25)) { //(4000)ms || (7.5)ms |
edamame22 | 0:29983394c6b6 | 1265 | conn_min_interval = DEF_INT_CONN; |
edamame22 | 0:29983394c6b6 | 1266 | conn_max_interval = DEF_INT_CONN; |
edamame22 | 0:29983394c6b6 | 1267 | } else { |
edamame22 | 0:29983394c6b6 | 1268 | conn_min_interval = SCAN_DURATION_UNITS_TO_MSEC(scanInterval)/1.25; |
edamame22 | 0:29983394c6b6 | 1269 | conn_max_interval = SCAN_DURATION_UNITS_TO_MSEC(scanInterval)/1.25; |
edamame22 | 0:29983394c6b6 | 1270 | } |
edamame22 | 0:29983394c6b6 | 1271 | } |
edamame22 | 0:29983394c6b6 | 1272 | PRINTF("scanInterval=%u[msec]\r\n",SCAN_DURATION_UNITS_TO_MSEC(scanInterval)); |
edamame22 | 0:29983394c6b6 | 1273 | PRINTF("scanWindow()=%u[msec]\r\n",SCAN_DURATION_UNITS_TO_MSEC(scanWindow)); |
edamame22 | 0:29983394c6b6 | 1274 | PRINTF("conn_min_interval=%u[msec]\r\n",(unsigned)(conn_min_interval*1.25)); |
edamame22 | 0:29983394c6b6 | 1275 | PRINTF("conn_max_interval=%u[msec]\r\n",(unsigned)(conn_max_interval*1.25)); |
edamame22 | 0:29983394c6b6 | 1276 | |
edamame22 | 0:29983394c6b6 | 1277 | } |
edamame22 | 0:29983394c6b6 | 1278 | |
edamame22 | 0:29983394c6b6 | 1279 | ble_error_t BlueNRGGap::createConnection () |
edamame22 | 0:29983394c6b6 | 1280 | { |
edamame22 | 0:29983394c6b6 | 1281 | tBleStatus ret; |
edamame22 | 0:29983394c6b6 | 1282 | |
edamame22 | 0:29983394c6b6 | 1283 | /* |
edamame22 | 0:29983394c6b6 | 1284 | Before creating connection, set parameters according |
edamame22 | 0:29983394c6b6 | 1285 | to previous or current procedure (ADV and/or SCAN) |
edamame22 | 0:29983394c6b6 | 1286 | */ |
edamame22 | 0:29983394c6b6 | 1287 | setConnectionParameters(); |
edamame22 | 0:29983394c6b6 | 1288 | |
edamame22 | 0:29983394c6b6 | 1289 | /* |
edamame22 | 0:29983394c6b6 | 1290 | Scan_Interval, Scan_Window, Peer_Address_Type, Peer_Address, Own_Address_Type, Conn_Interval_Min, |
edamame22 | 0:29983394c6b6 | 1291 | Conn_Interval_Max, Conn_Latency, Supervision_Timeout, Conn_Len_Min, Conn_Len_Max |
edamame22 | 0:29983394c6b6 | 1292 | */ |
edamame22 | 0:29983394c6b6 | 1293 | ret = aci_gap_create_connection(scanInterval, |
edamame22 | 0:29983394c6b6 | 1294 | scanWindow, |
edamame22 | 0:29983394c6b6 | 1295 | _peerAddrType, |
edamame22 | 0:29983394c6b6 | 1296 | (unsigned char*)_peerAddr, |
edamame22 | 0:29983394c6b6 | 1297 | addr_type, |
edamame22 | 0:29983394c6b6 | 1298 | conn_min_interval, conn_max_interval, 0, |
edamame22 | 0:29983394c6b6 | 1299 | SUPERV_TIMEOUT, CONN_L1, CONN_L1); |
edamame22 | 0:29983394c6b6 | 1300 | |
edamame22 | 0:29983394c6b6 | 1301 | //_connecting = false; |
edamame22 | 0:29983394c6b6 | 1302 | |
edamame22 | 0:29983394c6b6 | 1303 | if (ret != BLE_STATUS_SUCCESS) { |
edamame22 | 0:29983394c6b6 | 1304 | PRINTF("Error while starting connection (ret=0x%02X).\n\r", ret); |
edamame22 | 0:29983394c6b6 | 1305 | return BLE_ERROR_UNSPECIFIED; |
edamame22 | 0:29983394c6b6 | 1306 | } else { |
edamame22 | 0:29983394c6b6 | 1307 | PRINTF("Connection started.\n"); |
edamame22 | 0:29983394c6b6 | 1308 | _connecting = false; |
edamame22 | 0:29983394c6b6 | 1309 | return BLE_ERROR_NONE; |
edamame22 | 0:29983394c6b6 | 1310 | } |
edamame22 | 0:29983394c6b6 | 1311 | } |
edamame22 | 0:29983394c6b6 | 1312 | |
edamame22 | 0:29983394c6b6 | 1313 | ble_error_t BlueNRGGap::connect (const Gap::Address_t peerAddr, |
edamame22 | 0:29983394c6b6 | 1314 | Gap::AddressType_t peerAddrType, |
edamame22 | 0:29983394c6b6 | 1315 | const ConnectionParams_t *connectionParams, |
edamame22 | 0:29983394c6b6 | 1316 | const GapScanningParams *scanParams) |
edamame22 | 0:29983394c6b6 | 1317 | { |
edamame22 | 0:29983394c6b6 | 1318 | /* avoid compiler warnings about unused variables */ |
edamame22 | 0:29983394c6b6 | 1319 | (void)connectionParams; |
edamame22 | 0:29983394c6b6 | 1320 | |
edamame22 | 0:29983394c6b6 | 1321 | setScanParams(scanParams->getInterval(), |
edamame22 | 0:29983394c6b6 | 1322 | scanParams->getWindow(), |
edamame22 | 0:29983394c6b6 | 1323 | scanParams->getTimeout(), |
edamame22 | 0:29983394c6b6 | 1324 | scanParams->getActiveScanning() |
edamame22 | 0:29983394c6b6 | 1325 | ); |
edamame22 | 0:29983394c6b6 | 1326 | |
edamame22 | 0:29983394c6b6 | 1327 | // Save the peer address |
edamame22 | 0:29983394c6b6 | 1328 | for(int i=0; i<BDADDR_SIZE; i++) { |
edamame22 | 0:29983394c6b6 | 1329 | _peerAddr[i] = peerAddr[i]; |
edamame22 | 0:29983394c6b6 | 1330 | } |
edamame22 | 0:29983394c6b6 | 1331 | _peerAddrType = peerAddrType; |
edamame22 | 0:29983394c6b6 | 1332 | |
edamame22 | 0:29983394c6b6 | 1333 | _connecting = true; |
edamame22 | 0:29983394c6b6 | 1334 | |
edamame22 | 0:29983394c6b6 | 1335 | if(_scanning) { |
edamame22 | 0:29983394c6b6 | 1336 | stopScan(); |
edamame22 | 0:29983394c6b6 | 1337 | } else { |
edamame22 | 0:29983394c6b6 | 1338 | PRINTF("Calling createConnection from connect()\n\r"); |
edamame22 | 0:29983394c6b6 | 1339 | return createConnection(); |
edamame22 | 0:29983394c6b6 | 1340 | } |
edamame22 | 0:29983394c6b6 | 1341 | |
edamame22 | 0:29983394c6b6 | 1342 | return BLE_ERROR_NONE; |
edamame22 | 0:29983394c6b6 | 1343 | } |
edamame22 | 0:29983394c6b6 | 1344 | |
edamame22 | 0:29983394c6b6 | 1345 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 1346 | /*! |
edamame22 | 0:29983394c6b6 | 1347 | @brief Set the advertising policy filter mode that will be used in |
edamame22 | 0:29983394c6b6 | 1348 | the next call to startAdvertising(). |
edamame22 | 0:29983394c6b6 | 1349 | |
edamame22 | 0:29983394c6b6 | 1350 | @returns \ref ble_errror_t |
edamame22 | 0:29983394c6b6 | 1351 | |
edamame22 | 0:29983394c6b6 | 1352 | @retval BLE_ERROR_NONE |
edamame22 | 0:29983394c6b6 | 1353 | Everything executed properly. |
edamame22 | 0:29983394c6b6 | 1354 | |
edamame22 | 0:29983394c6b6 | 1355 | BLE_ERROR_NOT_IMPLEMENTED |
edamame22 | 0:29983394c6b6 | 1356 | This feature is currently note implemented. |
edamame22 | 0:29983394c6b6 | 1357 | */ |
edamame22 | 0:29983394c6b6 | 1358 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 1359 | ble_error_t BlueNRGGap::setAdvertisingPolicyMode(Gap::AdvertisingPolicyMode_t mode) |
edamame22 | 0:29983394c6b6 | 1360 | { |
edamame22 | 0:29983394c6b6 | 1361 | advertisingPolicyMode = mode; |
edamame22 | 0:29983394c6b6 | 1362 | |
edamame22 | 0:29983394c6b6 | 1363 | return BLE_ERROR_NONE; |
edamame22 | 0:29983394c6b6 | 1364 | } |
edamame22 | 0:29983394c6b6 | 1365 | |
edamame22 | 0:29983394c6b6 | 1366 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 1367 | /*! |
edamame22 | 0:29983394c6b6 | 1368 | @brief Set the scanning policy filter mode that will be used in |
edamame22 | 0:29983394c6b6 | 1369 | the next call to startAdvertising(). |
edamame22 | 0:29983394c6b6 | 1370 | |
edamame22 | 0:29983394c6b6 | 1371 | @returns \ref ble_errror_t |
edamame22 | 0:29983394c6b6 | 1372 | |
edamame22 | 0:29983394c6b6 | 1373 | @retval BLE_ERROR_NONE |
edamame22 | 0:29983394c6b6 | 1374 | Everything executed properly. |
edamame22 | 0:29983394c6b6 | 1375 | |
edamame22 | 0:29983394c6b6 | 1376 | BLE_ERROR_NOT_IMPLEMENTED |
edamame22 | 0:29983394c6b6 | 1377 | This feature is currently note implemented. |
edamame22 | 0:29983394c6b6 | 1378 | */ |
edamame22 | 0:29983394c6b6 | 1379 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 1380 | ble_error_t BlueNRGGap::setScanningPolicyMode(Gap::ScanningPolicyMode_t mode) |
edamame22 | 0:29983394c6b6 | 1381 | { |
edamame22 | 0:29983394c6b6 | 1382 | scanningPolicyMode = mode; |
edamame22 | 0:29983394c6b6 | 1383 | |
edamame22 | 0:29983394c6b6 | 1384 | return BLE_ERROR_NONE; |
edamame22 | 0:29983394c6b6 | 1385 | } |
edamame22 | 0:29983394c6b6 | 1386 | |
edamame22 | 0:29983394c6b6 | 1387 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 1388 | /*! |
edamame22 | 0:29983394c6b6 | 1389 | @brief Get the current advertising policy filter mode. |
edamame22 | 0:29983394c6b6 | 1390 | |
edamame22 | 0:29983394c6b6 | 1391 | @returns The advertising policy filter mode. |
edamame22 | 0:29983394c6b6 | 1392 | */ |
edamame22 | 0:29983394c6b6 | 1393 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 1394 | Gap::AdvertisingPolicyMode_t BlueNRGGap::getAdvertisingPolicyMode(void) const |
edamame22 | 0:29983394c6b6 | 1395 | { |
edamame22 | 0:29983394c6b6 | 1396 | return advertisingPolicyMode; |
edamame22 | 0:29983394c6b6 | 1397 | } |
edamame22 | 0:29983394c6b6 | 1398 | |
edamame22 | 0:29983394c6b6 | 1399 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 1400 | /*! |
edamame22 | 0:29983394c6b6 | 1401 | @brief Get the current scanning policy filter mode. |
edamame22 | 0:29983394c6b6 | 1402 | |
edamame22 | 0:29983394c6b6 | 1403 | @returns The scanning policy filter mode. |
edamame22 | 0:29983394c6b6 | 1404 | |
edamame22 | 0:29983394c6b6 | 1405 | */ |
edamame22 | 0:29983394c6b6 | 1406 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 1407 | Gap::ScanningPolicyMode_t BlueNRGGap::getScanningPolicyMode(void) const |
edamame22 | 0:29983394c6b6 | 1408 | { |
edamame22 | 0:29983394c6b6 | 1409 | return scanningPolicyMode; |
edamame22 | 0:29983394c6b6 | 1410 | } |
edamame22 | 0:29983394c6b6 | 1411 | |
edamame22 | 0:29983394c6b6 | 1412 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 1413 | /*! |
edamame22 | 0:29983394c6b6 | 1414 | @brief Clear BlueNRGGap's state. |
edamame22 | 0:29983394c6b6 | 1415 | |
edamame22 | 0:29983394c6b6 | 1416 | @returns ble_error_t |
edamame22 | 0:29983394c6b6 | 1417 | |
edamame22 | 0:29983394c6b6 | 1418 | @retval BLE_ERROR_NONE |
edamame22 | 0:29983394c6b6 | 1419 | Everything executed properly |
edamame22 | 0:29983394c6b6 | 1420 | */ |
edamame22 | 0:29983394c6b6 | 1421 | /**************************************************************************/ |
edamame22 | 0:29983394c6b6 | 1422 | ble_error_t BlueNRGGap::reset(void) |
edamame22 | 0:29983394c6b6 | 1423 | { |
edamame22 | 0:29983394c6b6 | 1424 | /* Clear all state that is from the parent, including private members */ |
edamame22 | 0:29983394c6b6 | 1425 | if (Gap::reset() != BLE_ERROR_NONE) { |
edamame22 | 0:29983394c6b6 | 1426 | return BLE_ERROR_INVALID_STATE; |
edamame22 | 0:29983394c6b6 | 1427 | } |
edamame22 | 0:29983394c6b6 | 1428 | |
edamame22 | 0:29983394c6b6 | 1429 | /* Clear derived class members */ |
edamame22 | 0:29983394c6b6 | 1430 | m_connectionHandle = BLE_CONN_HANDLE_INVALID; |
edamame22 | 0:29983394c6b6 | 1431 | |
edamame22 | 0:29983394c6b6 | 1432 | /* Set the whitelist policy filter modes to IGNORE_WHITELIST */ |
edamame22 | 0:29983394c6b6 | 1433 | advertisingPolicyMode = Gap::ADV_POLICY_IGNORE_WHITELIST; |
edamame22 | 0:29983394c6b6 | 1434 | scanningPolicyMode = Gap::SCAN_POLICY_IGNORE_WHITELIST; |
edamame22 | 0:29983394c6b6 | 1435 | |
edamame22 | 0:29983394c6b6 | 1436 | return BLE_ERROR_NONE; |
edamame22 | 0:29983394c6b6 | 1437 | } |
edamame22 | 0:29983394c6b6 | 1438 | |
edamame22 | 0:29983394c6b6 | 1439 | void BlueNRGGap::setConnectionInterval(uint16_t interval) { |
edamame22 | 0:29983394c6b6 | 1440 | conn_min_interval = interval; |
edamame22 | 0:29983394c6b6 | 1441 | conn_max_interval = interval; |
edamame22 | 0:29983394c6b6 | 1442 | } |
edamame22 | 0:29983394c6b6 | 1443 | |
edamame22 | 0:29983394c6b6 | 1444 | void BlueNRGGap::setGapRole(Role_t role) |
edamame22 | 0:29983394c6b6 | 1445 | { |
edamame22 | 0:29983394c6b6 | 1446 | gapRole = role; |
edamame22 | 0:29983394c6b6 | 1447 | } |