Lightly modified version of the BLE stack, that doesn't bring up a DFUService by default... as we have our own.

Fork of BLE_API by Bluetooth Low Energy

Committer:
rgrover1
Date:
Wed Jan 21 09:32:49 2015 +0000
Revision:
260:ea7f9f14cc15
Parent:
106:a20be740075d
Synchronized with git rev bec9560c
Author: Rohit Grover
fix all line endings to be Unix style

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rgrover1 260:ea7f9f14cc15 1 /* mbed Microcontroller Library
rgrover1 260:ea7f9f14cc15 2 * Copyright (c) 2006-2013 ARM Limited
rgrover1 260:ea7f9f14cc15 3 *
rgrover1 260:ea7f9f14cc15 4 * Licensed under the Apache License, Version 2.0 (the "License");
rgrover1 260:ea7f9f14cc15 5 * you may not use this file except in compliance with the License.
rgrover1 260:ea7f9f14cc15 6 * You may obtain a copy of the License at
rgrover1 260:ea7f9f14cc15 7 *
rgrover1 260:ea7f9f14cc15 8 * http://www.apache.org/licenses/LICENSE-2.0
rgrover1 260:ea7f9f14cc15 9 *
rgrover1 260:ea7f9f14cc15 10 * Unless required by applicable law or agreed to in writing, software
rgrover1 260:ea7f9f14cc15 11 * distributed under the License is distributed on an "AS IS" BASIS,
rgrover1 260:ea7f9f14cc15 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rgrover1 260:ea7f9f14cc15 13 * See the License for the specific language governing permissions and
rgrover1 260:ea7f9f14cc15 14 * limitations under the License.
rgrover1 260:ea7f9f14cc15 15 */
rgrover1 260:ea7f9f14cc15 16
rgrover1 260:ea7f9f14cc15 17 #include <stdio.h>
rgrover1 260:ea7f9f14cc15 18 #include <string.h>
rgrover1 260:ea7f9f14cc15 19
rgrover1 260:ea7f9f14cc15 20 #include "blecommon.h"
rgrover1 260:ea7f9f14cc15 21 #include "GapAdvertisingParams.h"
rgrover1 260:ea7f9f14cc15 22
rgrover1 260:ea7f9f14cc15 23 /**************************************************************************/
rgrover1 260:ea7f9f14cc15 24 /*!
rgrover1 260:ea7f9f14cc15 25 \brief
rgrover1 260:ea7f9f14cc15 26 Instantiates a new GapAdvertisingParams instance
rgrover1 260:ea7f9f14cc15 27
rgrover1 260:ea7f9f14cc15 28 \param[in] advType
rgrover1 260:ea7f9f14cc15 29 The GAP advertising mode to use for this device. Valid
rgrover1 260:ea7f9f14cc15 30 values are defined in AdvertisingType:
rgrover1 260:ea7f9f14cc15 31
rgrover1 260:ea7f9f14cc15 32 \par ADV_NON_CONNECTABLE_UNDIRECTED
rgrover1 260:ea7f9f14cc15 33 All connections to the peripheral device will be refused.
rgrover1 260:ea7f9f14cc15 34
rgrover1 260:ea7f9f14cc15 35 \par ADV_CONNECTABLE_DIRECTED
rgrover1 260:ea7f9f14cc15 36 Only connections from a pre-defined central device will be
rgrover1 260:ea7f9f14cc15 37 accepted.
rgrover1 260:ea7f9f14cc15 38
rgrover1 260:ea7f9f14cc15 39 \par ADV_CONNECTABLE_UNDIRECTED
rgrover1 260:ea7f9f14cc15 40 Any central device can connect to this peripheral.
rgrover1 260:ea7f9f14cc15 41
rgrover1 260:ea7f9f14cc15 42 \par ADV_SCANNABLE_UNDIRECTED
rgrover1 260:ea7f9f14cc15 43 Any central device can connect to this peripheral, and
rgrover1 260:ea7f9f14cc15 44 the secondary Scan Response payload will be included or
rgrover1 260:ea7f9f14cc15 45 available to central devices.
rgrover1 260:ea7f9f14cc15 46
rgrover1 260:ea7f9f14cc15 47 \par
rgrover1 260:ea7f9f14cc15 48 See Bluetooth Core Specification 4.0 (Vol. 3), Part C,
rgrover1 260:ea7f9f14cc15 49 Section 9.3 and Core Specification 4.0 (Vol. 6), Part B,
rgrover1 260:ea7f9f14cc15 50 Section 2.3.1 for further information on GAP connection
rgrover1 260:ea7f9f14cc15 51 modes
rgrover1 260:ea7f9f14cc15 52
rgrover1 260:ea7f9f14cc15 53 \param[in] interval
rgrover1 260:ea7f9f14cc15 54 Advertising interval between 0x0020 and 0x4000 in 0.625ms units
rgrover1 260:ea7f9f14cc15 55 (20ms to 10.24s). If using non-connectable mode
rgrover1 260:ea7f9f14cc15 56 (ADV_NON_CONNECTABLE_UNDIRECTED) this min value is 0x00A0
rgrover1 260:ea7f9f14cc15 57 (100ms). To reduce the likelihood of collisions, the link layer
rgrover1 260:ea7f9f14cc15 58 perturbs this interval by a pseudo-random delay with a range of
rgrover1 260:ea7f9f14cc15 59 0 ms to 10 ms for each advertising event.
rgrover1 260:ea7f9f14cc15 60
rgrover1 260:ea7f9f14cc15 61 \par
rgrover1 260:ea7f9f14cc15 62 Decreasing this value will allow central devices to detect
rgrover1 260:ea7f9f14cc15 63 your peripheral faster at the expense of more power being
rgrover1 260:ea7f9f14cc15 64 used by the radio due to the higher data transmit rate.
rgrover1 260:ea7f9f14cc15 65
rgrover1 260:ea7f9f14cc15 66 \par
rgrover1 260:ea7f9f14cc15 67 This field must be set to 0 if connectionMode is equal
rgrover1 260:ea7f9f14cc15 68 to ADV_CONNECTABLE_DIRECTED
rgrover1 260:ea7f9f14cc15 69
rgrover1 260:ea7f9f14cc15 70 \par
rgrover1 260:ea7f9f14cc15 71 See Bluetooth Core Specification, Vol 3., Part C,
rgrover1 260:ea7f9f14cc15 72 Appendix A for suggested advertising intervals.
rgrover1 260:ea7f9f14cc15 73
rgrover1 260:ea7f9f14cc15 74 \param[in] timeout
rgrover1 260:ea7f9f14cc15 75 Advertising timeout between 0x1 and 0x3FFF (1 and 16383)
rgrover1 260:ea7f9f14cc15 76 in seconds. Enter 0 to disable the advertising timeout.
rgrover1 260:ea7f9f14cc15 77
rgrover1 260:ea7f9f14cc15 78 \par EXAMPLE
rgrover1 260:ea7f9f14cc15 79
rgrover1 260:ea7f9f14cc15 80 \code
rgrover1 260:ea7f9f14cc15 81
rgrover1 260:ea7f9f14cc15 82 \endcode
rgrover1 260:ea7f9f14cc15 83 */
rgrover1 260:ea7f9f14cc15 84 /**************************************************************************/
rgrover1 260:ea7f9f14cc15 85 GapAdvertisingParams::GapAdvertisingParams(AdvertisingType advType, uint16_t interval, uint16_t timeout)
rgrover1 260:ea7f9f14cc15 86 {
rgrover1 260:ea7f9f14cc15 87 _advType = advType;
rgrover1 260:ea7f9f14cc15 88 _interval = interval;
rgrover1 260:ea7f9f14cc15 89 _timeout = timeout;
rgrover1 260:ea7f9f14cc15 90
rgrover1 260:ea7f9f14cc15 91 /* Interval checks */
rgrover1 260:ea7f9f14cc15 92 if (_advType == ADV_CONNECTABLE_DIRECTED) {
rgrover1 260:ea7f9f14cc15 93 /* Interval must be 0 in directed connectable mode */
rgrover1 260:ea7f9f14cc15 94 _interval = 0;
rgrover1 260:ea7f9f14cc15 95 } else if (_advType == ADV_NON_CONNECTABLE_UNDIRECTED) {
rgrover1 260:ea7f9f14cc15 96 /* Min interval is slightly larger than in other modes */
rgrover1 260:ea7f9f14cc15 97 if (_interval < GAP_ADV_PARAMS_INTERVAL_MIN_NONCON) {
rgrover1 260:ea7f9f14cc15 98 _interval = GAP_ADV_PARAMS_INTERVAL_MIN_NONCON;
rgrover1 260:ea7f9f14cc15 99 }
rgrover1 260:ea7f9f14cc15 100 if (_interval > GAP_ADV_PARAMS_INTERVAL_MAX) {
rgrover1 260:ea7f9f14cc15 101 _interval = GAP_ADV_PARAMS_INTERVAL_MAX;
rgrover1 260:ea7f9f14cc15 102 }
rgrover1 260:ea7f9f14cc15 103 } else {
rgrover1 260:ea7f9f14cc15 104 /* Stay within interval limits */
rgrover1 260:ea7f9f14cc15 105 if (_interval < GAP_ADV_PARAMS_INTERVAL_MIN) {
rgrover1 260:ea7f9f14cc15 106 _interval = GAP_ADV_PARAMS_INTERVAL_MIN;
rgrover1 260:ea7f9f14cc15 107 }
rgrover1 260:ea7f9f14cc15 108 if (_interval > GAP_ADV_PARAMS_INTERVAL_MAX) {
rgrover1 260:ea7f9f14cc15 109 _interval = GAP_ADV_PARAMS_INTERVAL_MAX;
rgrover1 260:ea7f9f14cc15 110 }
rgrover1 260:ea7f9f14cc15 111 }
rgrover1 260:ea7f9f14cc15 112
rgrover1 260:ea7f9f14cc15 113 /* Timeout checks */
rgrover1 260:ea7f9f14cc15 114 if (timeout) {
rgrover1 260:ea7f9f14cc15 115 /* Stay within timeout limits */
rgrover1 260:ea7f9f14cc15 116 if (_timeout > GAP_ADV_PARAMS_TIMEOUT_MAX) {
rgrover1 260:ea7f9f14cc15 117 _timeout = GAP_ADV_PARAMS_TIMEOUT_MAX;
rgrover1 260:ea7f9f14cc15 118 }
rgrover1 260:ea7f9f14cc15 119 }
rgrover1 260:ea7f9f14cc15 120 }
rgrover1 260:ea7f9f14cc15 121
rgrover1 260:ea7f9f14cc15 122 /**************************************************************************/
rgrover1 260:ea7f9f14cc15 123 /*!
rgrover1 260:ea7f9f14cc15 124 Destructor
rgrover1 260:ea7f9f14cc15 125 */
rgrover1 260:ea7f9f14cc15 126 /**************************************************************************/
rgrover1 260:ea7f9f14cc15 127 GapAdvertisingParams::~GapAdvertisingParams(void)
rgrover1 260:ea7f9f14cc15 128 {
rgrover1 260:ea7f9f14cc15 129 }