Mistake on this page?
Report an issue in GitHub or email us
BLEProtocol.h
1 /* mbed Microcontroller Library
2  * Copyright (c) 2006-2013 ARM Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef MBED_BLE_PROTOCOL_H__
18 #define MBED_BLE_PROTOCOL_H__
19 
20 #include <stddef.h>
21 #include <stdint.h>
22 #include <algorithm>
23 
24 /**
25  * @addtogroup ble
26  * @{
27  * @addtogroup common
28  * @{
29  */
30 
31 /**
32  * Common namespace for types and constants used everywhere in BLE API.
33  */
34 namespace BLEProtocol {
35 
36  /**
37  * Container for the enumeration of BLE address types.
38  *
39  * @note Adding a struct to encapsulate the contained enumeration prevents
40  * polluting the BLEProtocol namespace with the enumerated values. It also
41  * allows type-aliases for the enumeration while retaining the enumerated
42  * values. i.e. doing:
43  *
44  * @code
45  * typedef AddressType AliasedType;
46  * @endcode
47  *
48  * would allow the use of AliasedType::PUBLIC in code.
49  *
50  * @note see Bluetooth Standard version 4.2 [Vol 6, Part B] section 1.3 .
51  */
52  struct AddressType {
53  /**
54  * Address-types for Protocol addresses.
55  */
56  enum Type {
57  /**
58  * Public device address.
59  */
60  PUBLIC = 0,
61 
62  /**
63  * Random static device address.
64  *
65  * @deprecated This enumeration value is not relevant anymore.
66  * Advertising reporting and the connection procedure should rely
67  * on RANDOM instead. Use Gap::getRandomAddressType to retrieve the
68  * type of the random address.
69  */
71 
72  /**
73  * Private resolvable device address.
74  *
75  * @deprecated This enumeration value is not relevant anymore.
76  * Advertising reporting and the connection procedure should rely
77  * on RANDOM instead. Use Gap::getRandomAddressType to retrieve the
78  * type of the random address.
79  */
81 
82  /**
83  * Private non-resolvable device address.
84  *
85  * @deprecated This enumeration value is not relevant anymore.
86  * Advertising reporting and the connection procedure should rely
87  * on RANDOM instead. Use Gap::getRandomAddressType to retrieve the
88  * type of the random address.
89  */
91  };
92  };
93 
94  /**
95  * Alias for AddressType::Type
96  */
98 
99  /**
100  * Length (in octets) of the BLE MAC address.
101  */
102  static const size_t ADDR_LEN = 6;
103 
104  /**
105  * 48-bit address, in LSB format.
106  */
107  typedef uint8_t AddressBytes_t[ADDR_LEN];
108 
109  /**
110  * BLE address representation.
111  *
112  * It contains an address-type (::AddressType_t) and the address value
113  * (::AddressBytes_t).
114  */
115  struct Address_t {
116  /**
117  * Construct an Address_t object with the supplied type and address.
118  *
119  * @param[in] typeIn The BLE address type.
120  * @param[in] addressIn The BLE address.
121  *
122  * @post type is equal to typeIn and address is equal to the content
123  * present in addressIn.
124  */
125  Address_t(AddressType_t typeIn, const AddressBytes_t &addressIn) :
126  type(typeIn) {
127  std::copy(addressIn, addressIn + ADDR_LEN, address);
128  }
129 
130  /**
131  * Empty constructor.
132  *
133  * @note The address constructed with the empty constructor is not
134  * valid.
135  *
136  * @post type is equal to PUBLIC and the address value is equal to
137  * 00:00:00:00:00:00
138  */
139  Address_t(void) : type(), address() { }
140 
141  /**
142  * Type of the BLE device address.
143  */
144  AddressType_t type;
145 
146  /**
147  * Value of the device address.
148  */
149  AddressBytes_t address;
150  };
151 };
152 
153 /**
154  * @}
155  * @}
156  */
157 
158 #endif /* MBED_BLE_PROTOCOL_H__ */
BLE address representation.
Definition: BLEProtocol.h:115
Address_t(void)
Empty constructor.
Definition: BLEProtocol.h:139
Common namespace for types and constants used everywhere in BLE API.
Definition: BLEProtocol.h:34
Container for the enumeration of BLE address types.
Definition: BLEProtocol.h:52
Random static device address.
Definition: BLEProtocol.h:70
Private resolvable device address.
Definition: BLEProtocol.h:80
static const size_t ADDR_LEN
Length (in octets) of the BLE MAC address.
Definition: BLEProtocol.h:102
Address_t(AddressType_t typeIn, const AddressBytes_t &addressIn)
Construct an Address_t object with the supplied type and address.
Definition: BLEProtocol.h:125
AddressType::Type AddressType_t
Alias for AddressType::Type.
Definition: BLEProtocol.h:97
AddressBytes_t address
Value of the device address.
Definition: BLEProtocol.h:149
AddressType_t type
Type of the BLE device address.
Definition: BLEProtocol.h:144
Private non-resolvable device address.
Definition: BLEProtocol.h:90
Public device address.
Definition: BLEProtocol.h:60
uint8_t AddressBytes_t[ADDR_LEN]
48-bit address, in LSB format.
Definition: BLEProtocol.h:107
Type
Address-types for Protocol addresses.
Definition: BLEProtocol.h:56
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.