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