Mistake on this page?
Report an issue in GitHub or email us
Gap.h
1 /* mbed Microcontroller Library
2  * Copyright (c) 2006-2020 ARM Limited
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #ifndef BLE_GAP_GAP_H
20 #define BLE_GAP_GAP_H
21 
22 #include "ble/common/CallChainOfFunctionPointersWithContext.h"
23 
24 #include "ble/common/BLERoles.h"
25 #include "ble/common/BLETypes.h"
26 #include "ble/gap/AdvertisingDataBuilder.h"
27 #include "ble/gap/AdvertisingDataParser.h"
28 #include "ble/gap/AdvertisingDataSimpleBuilder.h"
29 #include "ble/gap/AdvertisingDataTypes.h"
30 #include "ble/gap/AdvertisingParameters.h"
31 #include "ble/gap/ConnectionParameters.h"
32 #include "ble/gap/ScanParameters.h"
33 #include "ble/gap/Events.h"
34 #include "ble/gap/Types.h"
35 
36 namespace ble {
37 
38 #if !defined(DOXYGEN_ONLY)
39 namespace impl {
40 class Gap;
41 }
42 #endif // !defined(DOXYGEN_ONLY)
43 
44 /**
45  * @addtogroup ble
46  * @{
47  * @addtogroup gap
48  * @{
49  */
50 
51 /**
52  * Define device discovery, connection and link management procedures.
53  *
54  * - Device discovery: A device can advertise to nearby peers its existence,
55  * identity and capabilities. Similarly, a device can scan its environment to
56  * find advertising peers. The information acquired during the scan helps to
57  * identify peers and understand their use. A scanner may acquire more information
58  * about an advertising peer by sending a scan request. If the peer accepts scan
59  * requests, it may reply with additional information about its state.
60  *
61  * - Connection: A bluetooth device can establish a connection to a connectable
62  * advertising peer. Once the connection is established, both devices can
63  * communicate using the GATT protocol. The GATT protocol allows connected
64  * devices to expose a set of states that the other peer can discover, read and write.
65  *
66  * - Link Management: Connected devices may drop the connection and may adjust
67  * connection parameters according to the power envelop needed for their
68  * application.
69  *
70  * @par Accessing gap
71  *
72  * Instance of a Gap class for a given BLE device should be accessed using
73  * BLE::gap(). The reference returned remains valid until the BLE instance
74  * shut down (see BLE::shutdown()).
75  *
76  * @code
77  * // assuming ble_device has been initialized
78  * BLE& ble_device;
79  *
80  * ble::Gap& gap = ble_device.gap();
81  * @endcode
82  *
83  * @par Advertising
84  *
85  * Advertising consists of broadcasting at a regular interval a small amount of
86  * data containing valuable information about the device. These packets may be
87  * scanned by peer devices listening on BLE advertising channels.
88  *
89  * Scanners may also request additional information from a device advertising by
90  * sending a scan request. If the broadcaster accepts scan requests, it can reply
91  * with a scan response packet containing additional information.
92  *
93  * Advertising parameters are updated using setAdvertisingParams(). The main
94  * advertising payload is updated using setAdvertisingPayload(), and the scan response
95  * is updated using setAdvertisingScanResponse(). If the advertising is already
96  * updated, the data will take effect from the next advertising event.
97  *
98  * To create a valid advertising payload and scan response, you may use
99  * AdvertisingDataBuilder. You must first allocate memory and create an mbed::Span and
100  * pass that into the AdvertisingDataBuilder, which will only be able to add as much
101  * data as fits in the provided buffer. The builder accepts any size of the buffer,
102  * but for the created data to be usable, it must be smaller than the maximum data
103  * length returned from getMaxAdvertisingDataLength().
104  *
105  * Another option is to use AdvertisingDataSimpleBuilder, which allocates memory
106  * on the stack and offers a fluent interface at the expense of a reduced set of
107  * APIs and error management options.
108  *
109  * @note Prior to Bluetooth 5, advertising and scanning payload size were limited
110  * to LEGACY_ADVERTISING_MAX_SIZE. It changed with Bluetooth 5, and now the maximum
111  * size of data that can be advertised depends on the controller. If you wish
112  * to be compatible with older devices, you may wish to advertise with the
113  * LEGACY_ADVERTISING_HANDLE. This uses payloads no larger than LEGACY_ADVERTISING_MAX_SIZE
114  * with that advertising set.
115  *
116  * @par Extended advertising
117  *
118  * Extended advertising allows for a wider choice of options than legacy advertising.
119  * You can send bigger payloads and use different PHYs. This allows for bigger throughput
120  * or longer range.
121  *
122  * Extended advertising may be split across many packets and takes place on both the
123  * regular advertising channels and the rest of the 37 channels normally used by
124  * connected devices.
125  *
126  * The 3 channels used in legacy advertising are called primary advertisement channels.
127  * The remaining 37 channels are used for secondary advertising. Unlike sending data
128  * during a connection, this allows the device to broadcast data to multiple devices.
129  *
130  * The advertising starts on the primary channels (which you may select) and continues
131  * on the secondary channels as indicated in the packet sent on the primary channel.
132  * This way, the advertising can send large payloads without saturating the advertising
133  * channels. Primary channels are limited to 1M and coded PHYs, but secondary channels
134  * may use the increased throughput 2M PHY.
135  *
136  * @par Periodic advertising
137  *
138  * Similarly, you can use periodic advertising to transfer regular data to multiple
139  * devices.
140  *
141  * The advertiser uses primary channels to advertise the information needed to
142  * listen to the periodic advertisements on secondary channels. This sync information
143  * will be used by the scanner who can now optimize for power consumption and only
144  * listen for the periodic advertisements at specified times.
145  *
146  * Like extended advertising, periodic advertising offers extra PHY options of 2M
147  * and coded. The payload may be updated at any time and will be updated on the next
148  * advertisement event when the periodic advertising is active.
149  *
150  * @par Advertising sets
151  *
152  * Advertisers may advertise multiple payloads at the same time. The configuration
153  * and identification of these is done through advertising sets. Use a handle
154  * obtained from createAvertisingSet() for advertising operations. After ending
155  * all advertising operations, remove the handle from the system using
156  * destroyAdvertisingHandle().
157  *
158  * Extended advertising and periodic advertising is an optional feature, and not all
159  * devices support it. Some will only be able to see the now-called legacy advertising.
160  *
161  * Legacy advertising is available through a special handle, LEGACY_ADVERTISING_HANDLE.
162  * This handle is always available, doesn't need to be created and can't be
163  * destroyed.
164  *
165  * There is a limited number of advertising sets available because they require support
166  * from the controller. Their availability is dynamic and may be queried at any time
167  * using getMaxAdvertisingSetNumber(). Advertising sets take up resources even if
168  * they are not actively advertising right now, so it's important to destroy the set
169  * when you're done with it (or reuse it in the next advertisement).
170  *
171  * Periodic advertising and extended advertising share the same set but not the same
172  * data. Extended advertising carries out periodic advertising synchronization
173  * information. Therefore, to let other devices be aware that your device
174  * exposes periodic advertising, you should start extended advertising of the set.
175  * Subsequently, you may disable extended advertising, and the periodic advertising
176  * will continue. If you start periodic advertising while extended advertising is
177  * inactive, periodic advertising won't start until you start extended advertising
178  * at a later time.
179  *
180  * @par Privacy
181  *
182  * Privacy is a feature that allows a device to avoid being tracked by other
183  * (untrusted) devices. The device achieves it by periodically generating a
184  * new random address. The random address may be a resolvable random address,
185  * enabling trusted devices to recognize it as belonging to the same
186  * device. These trusted devices receive an Identity Resolution Key (IRK)
187  * during pairing. This is handled by the SecurityManager and relies on the
188  * other device accepting and storing the IRK.
189  *
190  * You need to enable privacy by calling enablePrivacy() after having
191  * initialized the SecurityManager because privacy requires SecurityManager
192  * to handle IRKs. The behavior of privacy enabled devices is set by
193  * using setCentralPrivacyConfiguration(), which specifies what the device
194  * should be with devices using random addresses. Random addresses
195  * generated by privacy enabled devices can be of two types: resolvable
196  * (by devices who have the IRK) and unresolvable. Unresolvable addresses
197  * can't be used for connecting and connectable advertising. Therefore, a
198  * resolvable one will be used for these regardless of the privacy
199  * configuration.
200  *
201  * @par Scanning
202  *
203  * Scanning consists of listening for peer advertising packets. From a scan, a
204  * device can identify devices available in its environment.
205  *
206  * If the device scans actively, then it will send scan request to scannable
207  * advertisers and collect their scan responses.
208  *
209  * Scanning is done by creating ScanParameters and applying them with
210  * setScanParameters(). One configured, you may call startScan().
211  *
212  * When a scanning device receives an advertising packet, it will call
213  * onAdvertisingReport() in the registered event handler. A whitelist may be used
214  * to limit the advertising reports by setting the correct policy in the scan
215  * parameters.
216  *
217  * @par Connection event handling
218  *
219  * A peer may connect device advertising connectable packets. The advertising
220  * procedure ends as soon as the device is connected. If an advertising timeout
221  * has been set in the advertising parameters then onAdvertisingEnd will be called
222  * in the registered eventHandler when it runs out.
223  *
224  * A device accepting a connection request from a peer is named a peripheral,
225  * and the device initiating the connection is named a central.
226  *
227  * Connection is initiated by central devices. A call to connect() will result in
228  * the device scanning on any PHYs set in ConectionParamters passed in.
229  *
230  * Peripheral and central receive a connection event when the connection is
231  * effective. If successful will result in a call to onConnectionComplete in the
232  * EventHandler registered with the Gap.
233  *
234  * It the connection attempt fails it will result in onConnectionComplete called
235  * on the central device with the event carrying the error flag.
236  *
237  * @par Changing the PHYsical transport of a connection
238  *
239  * Once a connection has been established, it is possible to change the physical
240  * transport used between the local and the distant device. Changing the transport
241  * can either increase the bandwidth or increase the communication range.
242  * An increased bandwidth equals a better power consumption but also a loss in
243  * sensibility and therefore a degraded range.
244  *
245  * Symmetrically an increased range means a lowered bandwidth and a degraded power
246  * consumption.
247  *
248  * Applications can change the PHY used by calling the function setPhy. Once the
249  * update has been made the result is forwarded to the application by calling the
250  * function onPhyUpdateComplete of the event handler registered.
251  *
252  * @par disconnection
253  *
254  * The application code initiates a disconnection when it calls the
255  * disconnect(Handle_t, DisconnectionReason_t) function.
256  *
257  * Disconnection may also be initiated by the remote peer or the local
258  * controller/stack. To catch all disconnection events, application code may
259  * set up an handler taking care of disconnection events by calling
260  * onDisconnection().
261  *
262  * @par Modulation Schemes
263  *
264  * When supported by the host and controller you can select different modulation
265  * schemes (@see BLUETOOTH SPECIFICATION Version 5.0 | Vol 1, Part A - 1.2):
266  * - LE 1M PHY
267  * - LE 2M PHY
268  * - LE coded PHY
269  *
270  * You may set preferred PHYs (separately for RX and TX) using setPreferredPhys().
271  * You may also set the currently used PHYs on a selected connection using setPhy().
272  * Both of these settings are only advisory and the controller is allowed to make
273  * its own decision on the best PHY to use based on your request, the peer's
274  * supported features and the connection's physical conditions.
275  *
276  * You may query the currently used PHY using readPhy() which will return the
277  * result through a call to the registered event handler. You may register the
278  * handler with setEventHandler(). The events inform about the currently used
279  * PHY and of any changes to PHYs which may be triggered autonomously by the
280  * controller or by the peer.
281  */
282 class Gap {
283 public:
284  /**
285  * Gap shutdown event handler.
286  *
287  * @see Gap::onShutdown().
288  */
290 
291  /**
292  * Callchain of gap shutdown event handler.
293  *
294  * @see Gap::onShutdown().
295  */
298 
299 public:
300  /**
301  * Definition of the general handler of Gap related events.
302  */
303  struct EventHandler {
304  /**
305  * Called when an advertising device receive a scan request.
306  *
307  * @param event Scan request event.
308  *
309  * @version: 5+.
310  *
311  * @see AdvertisingParameters::setScanRequestNotification().
312  */
313  virtual void onScanRequestReceived(const ScanRequestEvent &event)
314  {
315  }
316 
317  /**
318  * Called when advertising starts.
319  *
320  * @param event Advertising start event.
321  *
322  * @note Check event.getStatus() to see if advertising started successfully
323  *
324  * @see startAdvertising()
325  */
326  virtual void onAdvertisingStart(const AdvertisingStartEvent &event)
327  {
328  }
329 
330  /**
331  * Called when advertising ends.
332  *
333  * Advertising ends when the process timeout or if it is stopped by the
334  * application or if the local device accepts a connection request.
335  *
336  * @param event Advertising end event.
337  *
338  * @note Check event.getStatus() to see if advertising ended successfully
339  *
340  * @see stopAdvertising()
341  * @see onConnectionComplete()
342  */
343  virtual void onAdvertisingEnd(const AdvertisingEndEvent &event)
344  {
345  }
346 
347  /**
348  * Called when a scanner receives an advertising or a scan response packet.
349  *
350  * @param event Advertising report.
351  *
352  * @see startScan()
353  */
354  virtual void onAdvertisingReport(const AdvertisingReportEvent &event)
355  {
356  }
357 
358  /**
359  * Called when scan times out.
360  *
361  * @param event Associated event.
362  *
363  * @see startScan()
364  */
365  virtual void onScanTimeout(const ScanTimeoutEvent &event)
366  {
367  }
368 
369  /**
370  * Called when first advertising packet in periodic advertising is received.
371  *
372  * @param event Periodic advertising sync event.
373  *
374  * @version: 5+.
375  *
376  * @see createSync()
377  */
380  )
381  {
382  }
383 
384  /**
385  * Called when a periodic advertising packet is received.
386  *
387  * @param event Periodic advertisement event.
388  *
389  * @version: 5+.
390  *
391  * @see createSync()
392  */
394  const PeriodicAdvertisingReportEvent &event
395  )
396  {
397  }
398 
399  /**
400  * Called when a periodic advertising sync has been lost.
401  *
402  * @param event Details of the event.
403  *
404  * @version: 5+.
405  *
406  * @see createSync()
407  */
409  const PeriodicAdvertisingSyncLoss &event
410  )
411  {
412  }
413 
414  /**
415  * Called when connection attempt ends. Check event.getStatus() to see if connection
416  * was established. If this device is the peripheral and it was advertising this will
417  * end the advertising set which will also create the onAdvertisingEnd event.
418  *
419  * @see startAdvertising()
420  * @see connect()
421  *
422  * @param event Connection event.
423  */
425  {
426  }
427 
428  /**
429  * Called when the peer request connection parameters updates.
430  *
431  * Application must accept the update with acceptConnectionParametersUpdate()
432  * or reject it with rejectConnectionParametersUpdate().
433  *
434  * @param event The connection parameters requested by the peer.
435  *
436  * @version 4.1+.
437  *
438  * @note This event will only be produced if manageConnectionParametersUpdateRequest() was called
439  * with true. Otherwise the stack will handle the request and no event will be generated.
440  *
441  * @see manageConnectionParametersUpdateRequest()
442  * @see acceptConnectionParametersUpdate()
443  * @see rejectConnectionParametersUpdate()
444  */
447  )
448  {
449  }
450 
451  /**
452  * Called when connection parameters have been updated.
453  *
454  * @param event The new connection parameters.
455  *
456  * @see updateConnectionParameters()
457  * @see acceptConnectionParametersUpdate()
458  */
461  )
462  {
463  }
464 
465  /**
466  * Called when a connection has been disconnected.
467  *
468  * @param event Details of the event.
469  *
470  * @see disconnect()
471  */
473  {
474  }
475 
476  /**
477  * Function invoked when the current transmitter and receiver PHY have
478  * been read for a given connection.
479  *
480  * @param status Status of the operation: BLE_ERROR_NONE in case of
481  * success or an appropriate error code.
482  *
483  * @param connectionHandle: The handle of the connection for which the
484  * PHYs have been read.
485  *
486  * @param txPhy PHY used by the transmitter.
487  *
488  * @param rxPhy PHY used by the receiver.
489  *
490  * @see readPhy().
491  *
492  * @version: 5+.
493  */
494  virtual void onReadPhy(
495  ble_error_t status,
496  connection_handle_t connectionHandle,
497  phy_t txPhy,
498  phy_t rxPhy
499  )
500  {
501  }
502 
503  /**
504  * Function invoked when the update process of the PHY has been completed.
505  *
506  * The process can be initiated by a call to the function setPhy, the
507  * local bluetooth subsystem or the peer.
508  *
509  * @param status Status of the operation: BLE_ERROR_NONE in case of
510  * success or an appropriate error code.
511  *
512  * @param connectionHandle: The handle of the connection on which the
513  * operation was made.
514  *
515  * @param txPhy PHY used by the transmitter.
516  *
517  * @param rxPhy PHY used by the receiver.
518  *
519  * @note Success doesn't mean the PHY has been updated it means both
520  * ends have negotiated the best PHY according to their configuration and
521  * capabilities. The PHY currently used are present in the txPhy and
522  * rxPhy parameters.
523  *
524  * @see setPhy()
525  *
526  * @version: 5+.
527  */
528  virtual void onPhyUpdateComplete(
529  ble_error_t status,
530  connection_handle_t connectionHandle,
531  phy_t txPhy,
532  phy_t rxPhy
533  )
534  {
535  }
536 
537  /**
538  * Function invoked when the connections changes the maximum number of octets
539  * that can be sent or received by the controller in a single packet. A single
540  * L2CAP packet can be fragmented across many such packets.
541  *
542  * @note This only triggers if controller supports data length extension and
543  * negotiated data length is longer than the default 23.
544  *
545  * @param connectionHandle The handle of the connection that changed the size.
546  * @param txSize Number of octets we can send on this connection in a single packet.
547  * @param rxSize Number of octets we can receive on this connection in a single packet.
548  */
549  virtual void onDataLengthChange(
550  connection_handle_t connectionHandle,
551  uint16_t txSize,
552  uint16_t rxSize
553  )
554  {
555  }
556 
557  /**
558  * Function invoked when the privacy subsystem has been enabled and is
559  * ready to be used.
560  *
561  * @see enablePrivacy()
562  */
563  virtual void onPrivacyEnabled()
564  {
565  }
566  protected:
567  /**
568  * Prevent polymorphic deletion and avoid unnecessary virtual destructor
569  * as the Gap class will never delete the instance it contains.
570  */
571  ~EventHandler() = default;
572  };
573 
574  /**
575  * Preferred connection parameter display in Generic Access Service.
576  */
577  typedef struct {
578  /**
579  * Minimum interval between two connection events allowed for a
580  * connection.
581  *
582  * It shall be less than or equal to maxConnectionInterval. This value,
583  * in units of 1.25ms, is included in the range [0x0006 : 0x0C80].
584  */
586 
587  /**
588  * Maximum interval between two connection events allowed for a
589  * connection.
590  *
591  * It shall be greater than or equal to minConnectionInterval. This
592  * value is in unit of 1.25ms and is in the range [0x0006 : 0x0C80].
593  */
595 
596  /**
597  * Number of connection events the slave can drop if it has nothing to
598  * communicate to the master.
599  *
600  * This value shall be in the range [0x0000 : 0x01F3].
601  */
602  uint16_t slaveLatency;
603 
604  /**
605  * Link supervision timeout for the connection.
606  *
607  * Time after which the connection is considered lost if the device
608  * didn't receive a packet from its peer.
609  *
610  * It is larger than:
611  * (1 + slaveLatency) * maxConnectionInterval * 2
612  *
613  * This value is in the range [0x000A : 0x0C80] and is in unit of
614  * 10 ms.
615  *
616  * @note maxConnectionInterval is in ms in the formulae above.
617  */
620 
621  /**
622  * Assign the event handler implementation that will be used by the gap
623  * module to signal events back to the application.
624  *
625  * @param handler Application implementation of an EventHandler.
626  *
627  * @note Multiple discrete EventHandler instances may be used by adding them
628  * to a ChainableGapEventHandler and then setting the chain as the primary
629  * Gap EventHandler using this function.
630  *
631  * @see ChainableGapEventHandler
632  */
633  void setEventHandler(EventHandler *handler);
634 
635  /** Check controller support for a specific feature.
636  *
637  * @param feature Feature to check.
638  * @return True if feature is supported.
639  */
640  bool isFeatureSupported(controller_supported_features_t feature);
641 
642  /* advertising */
643 #if BLE_ROLE_BROADCASTER
644  /** Return currently available number of supported advertising sets.
645  * This may change at runtime.
646  *
647  * @note Devices that do not support Bluetooth 5 still offers one advertising
648  * set that has the handle LEGACY_ADVERTISING_HANDLE.
649  *
650  * @return Number of advertising sets that may be created at the same time.
651  */
652  uint8_t getMaxAdvertisingSetNumber();
653 
654  /** Return maximum advertising data length supported.
655  *
656  * @return Maximum advertising data length supported.
657  */
658  uint16_t getMaxAdvertisingDataLength();
659 
660  /** Return maximum advertising data length supported for connectable advertising.
661  *
662  * @return Maximum advertising data length supported for connectable advertising.
663  */
664  uint16_t getMaxConnectableAdvertisingDataLength();
665 
666  /** Return maximum advertising data length you may set if advertising set is active.
667  *
668  * @return Maximum advertising data length you may set if advertising set is active.
669  */
670  uint16_t getMaxActiveSetAdvertisingDataLength();
671 
672 #if BLE_FEATURE_EXTENDED_ADVERTISING
673  /** Create an advertising set and apply the passed in parameters. The handle returned
674  * by this function must be used for all other calls that accept an advertising handle.
675  * When done with advertising, remove from the system using destroyAdvertisingSet().
676  *
677  * @note The exception is the LEGACY_ADVERTISING_HANDLE which may be used at any time.
678  *
679  * @param[out] handle Advertising handle returned, valid only if function returned success.
680  * @param parameters Advertising parameters for the newly created set.
681  * @return BLE_ERROR_NONE on success.
682  *
683  * @version 5+
684  */
685  ble_error_t createAdvertisingSet(
686  advertising_handle_t *handle,
687  const AdvertisingParameters &parameters
688  );
689 
690  /** Remove the advertising set (resets its set parameters). The advertising set must not
691  * be active.
692  *
693  * @note LEGACY_ADVERTISING_HANDLE may not be destroyed.
694  *
695  * @param handle Advertising set handle.
696  * @return BLE_ERROR_NONE on success.
697  *
698  * @version 5+
699  */
700  ble_error_t destroyAdvertisingSet(advertising_handle_t handle);
701 #endif // BLE_FEATURE_EXTENDED_ADVERTISING
702 
703  /** Set advertising parameters of an existing set.
704  *
705  * @param handle Advertising set handle.
706  * @param params New advertising parameters.
707  * @return BLE_ERROR_NONE on success.
708  */
709  ble_error_t setAdvertisingParameters(
710  advertising_handle_t handle,
711  const AdvertisingParameters &params
712  );
713 
714  /** Set new advertising payload for a given advertising set.
715  *
716  * @param handle Advertising set handle.
717  * @param payload Advertising payload.
718  *
719  * @note If advertising set is active you may only set payload of length equal or less
720  * than getMaxActiveSetAdvertisingDataLength(). If you require a longer payload you must
721  * stop the advertising set, set the payload and restart the set.
722  *
723  * @return BLE_ERROR_NONE on success.
724  *
725  * @see ble::AdvertisingDataBuilder to build a payload.
726  */
727  ble_error_t setAdvertisingPayload(
728  advertising_handle_t handle,
730  );
731 
732  /** Set new advertising scan response for a given advertising set. This will be sent to
733  * device who perform active scanning.
734  *
735  * @param handle Advertising set handle.
736  * @param response Advertising scan response.
737  *
738  * @note If advertising set is active you may only set payload of length equal or less
739  * than getMaxActiveSetAdvertisingDataLength(). If you require a longer payload you must
740  * stop the advertising set, set the payload and restart the set.
741  *
742  * @return BLE_ERROR_NONE on success.
743  *
744  * @see ble::AdvertisingDataBuilder to build a payload.
745  */
746  ble_error_t setAdvertisingScanResponse(
747  advertising_handle_t handle,
749  );
750 
751  /** Start advertising using the given advertising set.
752  *
753  * @param handle Advertising set handle.
754  * @param maxDuration Max duration for advertising (in units of 10ms) - 0 means no limit.
755  * @param maxEvents Max number of events produced during advertising - 0 means no limit.
756  * @return BLE_ERROR_NONE on success. This does not guarantee the set has started if
757  * extended advertising is enabled. Register an event handler and wait for onAdvertisingStart
758  * event. An (unlikely) failed start the status of the event will contain an error.
759  *
760  * @see EventHandler::onAdvertisingStart when the advertising starts.
761  * @see EventHandler::onScanRequestReceived when a scan request is received.
762  * @see EventHandler::onAdvertisingEnd when the advertising ends.
763  * @see EventHandler::onConnectionComplete when the device gets connected
764  * by a peer.
765  */
766  ble_error_t startAdvertising(
767  advertising_handle_t handle,
768  adv_duration_t maxDuration = adv_duration_t::forever(),
769  uint8_t maxEvents = 0
770  );
771 
772  /** Stop advertising given advertising set. This is separate from periodic advertising
773  * which will not be affected.
774  *
775  * @param handle Advertising set handle.
776  * @return BLE_ERROR_NONE on success. For extented advertising this does not guarantee
777  * the set is stopped if. Register an event handler and wait for onAdvertisingEnd event.
778  * An (unlikely) failed stop the event status will contain the error code.
779  */
780  ble_error_t stopAdvertising(advertising_handle_t handle);
781 
782  /** Check if advertising is active for a given advertising set.
783  *
784  * @param handle Advertising set handle.
785  * @return True if advertising is active on this set.
786  */
787  bool isAdvertisingActive(advertising_handle_t handle);
788 #endif // BLE_ROLE_BROADCASTER
789 
790 #if BLE_ROLE_BROADCASTER
791 #if BLE_FEATURE_PERIODIC_ADVERTISING
792  /** Set periodic advertising parameters for a given advertising set.
793  *
794  * @param handle Advertising set handle.
795  * @param periodicAdvertisingIntervalMin Minimum interval for periodic advertising.
796  * @param periodicAdvertisingIntervalMax Maximum interval for periodic advertising.
797  * @param advertiseTxPower Include transmission power in the advertisements.
798  * @return BLE_ERROR_NONE on success.
799  *
800  * @version 5+
801  */
802  ble_error_t setPeriodicAdvertisingParameters(
803  advertising_handle_t handle,
804  periodic_interval_t periodicAdvertisingIntervalMin,
805  periodic_interval_t periodicAdvertisingIntervalMax,
806  bool advertiseTxPower = true
807  );
808 
809  /** Set new periodic advertising payload for a given advertising set.
810  *
811  * @param handle Advertising set handle.
812  * @param payload Advertising payload.
813  * @return BLE_ERROR_NONE on success.
814  *
815  * @note If advertising set is active you may only set payload of length equal or less
816  * than getMaxActiveSetAdvertisingDataLength(). If you require a longer payload you must
817  * stop the advertising set, set the payload and restart the set. Stopping the set will
818  * cause peers to lose sync on the periodic set.
819  *
820  * @see ble::AdvertisingDataBuilder to build a payload.
821  *
822  * @version 5+
823  */
824  ble_error_t setPeriodicAdvertisingPayload(
825  advertising_handle_t handle,
827  );
828 
829  /** Start periodic advertising for a given set. Periodic advertising will not start until
830  * normal advertising is running but will continue to run after normal advertising has stopped.
831  *
832  * @param handle Advertising set handle.
833  * @return BLE_ERROR_NONE on success.
834  *
835  * @version 5+
836  */
837  ble_error_t startPeriodicAdvertising(advertising_handle_t handle);
838 
839  /** Stop periodic advertising for a given set.
840  *
841  * @param handle Advertising set handle.
842  * @return BLE_ERROR_NONE on success.
843  *
844  * @version 5+
845  */
846  ble_error_t stopPeriodicAdvertising(advertising_handle_t handle);
847 
848  /** Check if periodic advertising is active for a given advertising set.
849  *
850  * @param handle Advertising set handle.
851  * @return True if periodic advertising is active on this set.
852  *
853  * @version 5+
854  */
855  bool isPeriodicAdvertisingActive(advertising_handle_t handle);
856 #endif // BLE_ROLE_BROADCASTER
857 #endif // BLE_FEATURE_PERIODIC_ADVERTISING
858 
859  /* scanning */
860 #if BLE_ROLE_OBSERVER
861  /** Set new scan parameters.
862  *
863  * @param params Scan parameters, @see GapScanParameters for details.
864  * @return BLE_ERROR_NONE on success.
865  */
866  ble_error_t setScanParameters(const ScanParameters &params);
867 
868  /** Start scanning.
869  *
870  * @param duration How long to scan for. Special value 0 means scan forever.
871  * @param filtering Filtering policy.
872  * @param period How long to scan for in single period. If the period is 0 and duration
873  * is nonzero the scan will last for single duration.
874  *
875  * @note When the duration and period parameters are non-zero scanning will last for
876  * the duration within the period. After the scan period has expired a new scan period
877  * will begin and scanning. This will repeat until stopScan() is called.
878  *
879  * @return BLE_ERROR_NONE on success.
880  *
881  * @see EventHandler::onAdvertisingReport to collect advertising reports.
882  * @see EventHandler::onScanTimeout when scanning timeout.
883  */
884  ble_error_t startScan(
885  scan_duration_t duration = scan_duration_t::forever(),
886  duplicates_filter_t filtering = duplicates_filter_t::DISABLE,
887  scan_period_t period = scan_period_t(0)
888  );
889 
890  /**
891  * Stop the ongoing scanning procedure.
892  *
893  * The current scanning parameters remain in effect.
894  *
895  * @retval BLE_ERROR_NONE if successfully stopped scanning procedure.
896  */
897  ble_error_t stopScan();
898 #endif // BLE_ROLE_OBSERVER
899 
900 #if BLE_ROLE_OBSERVER
901 #if BLE_FEATURE_PERIODIC_ADVERTISING
902  /** Synchronize with periodic advertising from an advertiser and begin receiving periodic
903  * advertising packets.
904  *
905  * @param peerAddressType Peer address type.
906  * @param peerAddress Peer address.
907  * @param sid Advertiser set identifier.
908  * @param maxPacketSkip Number of consecutive periodic advertising packets that the receiver
909  * may skip after successfully receiving a periodic advertising packet.
910  * @param timeout Maximum permitted time between successful receptions. If this time is
911  * exceeded, synchronisation is lost.
912  * @return BLE_ERROR_NONE on success.
913  *
914  * @see EventHandler::onPeriodicAdvertisingSyncEstablished when the sync is
915  * effective.
916  * @see EventHandler::onPeriodicAdvertisingReport when data are issued by the
917  * peer.
918  * @see EventHandler::onPeriodicAdvertisingSyncLoss when the sync has been
919  * loss.
920  *
921  * @version 5+
922  */
923  ble_error_t createSync(
924  peer_address_type_t peerAddressType,
925  const address_t &peerAddress,
926  uint8_t sid,
927  slave_latency_t maxPacketSkip,
928  sync_timeout_t timeout
929  );
930 
931  /** Synchronize with periodic advertising from an advertiser and begin receiving periodic
932  * advertising packets. Use periodic advertising sync list to determine who to sync with.
933  *
934  * @param maxPacketSkip Number of consecutive periodic advertising packets that the receiver
935  * may skip after successfully receiving a periodic advertising packet.
936  * @param timeout Maximum permitted time between successful receives.
937  * If this time is exceeded, synchronisation is lost.
938  * @return BLE_ERROR_NONE on success.
939  *
940  * @see EventHandler::onPeriodicAdvertisingSyncEstablished when the sync is
941  * effective.
942  * @see EventHandler::onPeriodicAdvertisingReport when data are issued by the
943  * peer.
944  * @see EventHandler::onPeriodicAdvertisingSyncLoss when the sync has been
945  * loss.
946  *
947  * @version 5+
948  */
949  ble_error_t createSync(
950  slave_latency_t maxPacketSkip,
951  sync_timeout_t timeout
952  );
953 
954  /** Cancel sync attempt.
955  *
956  * @return BLE_ERROR_NONE on success.
957  */
958  ble_error_t cancelCreateSync();
959 
960  /** Stop reception of the periodic advertising identified by the handle.
961  *
962  * @param handle Periodic advertising synchronisation handle.
963  * @return BLE_ERROR_NONE on success.
964  */
965  ble_error_t terminateSync(periodic_sync_handle_t handle);
966 
967  /** Add device to the periodic advertiser list. Cannot be called when sync is ongoing.
968  *
969  * @param peerAddressType Peer address type.
970  * @param peerAddress Peer address.
971  * @param sid Advertiser set identifier.
972  * @return BLE_ERROR_NONE on success.
973  */
974  ble_error_t addDeviceToPeriodicAdvertiserList(
975  peer_address_type_t peerAddressType,
976  const address_t &peerAddress,
977  advertising_sid_t sid
978  );
979 
980  /** Remove device from the periodic advertiser list. Cannot be called when sync is ongoing.
981  *
982  * @param peerAddressType Peer address type.
983  * @param peerAddress Peer address.
984  * @param sid Advertiser set identifier.
985  * @return BLE_ERROR_NONE on success.
986  */
987  ble_error_t removeDeviceFromPeriodicAdvertiserList(
988  peer_address_type_t peerAddressType,
989  const address_t &peerAddress,
990  advertising_sid_t sid
991  );
992 
993  /** Remove all devices from periodic advertiser list.
994  *
995  * @return BLE_ERROR_NONE on success.
996  */
997  ble_error_t clearPeriodicAdvertiserList();
998 
999  /** Get number of devices that can be added to the periodic advertiser list.
1000  * @return Number of devices that can be added to the periodic advertiser list.
1001  */
1002  uint8_t getMaxPeriodicAdvertiserListSize();
1003 #endif // BLE_ROLE_OBSERVER
1004 #endif // BLE_FEATURE_PERIODIC_ADVERTISING
1005 
1006 #if BLE_ROLE_CENTRAL
1007  /**
1008  * Initiate a connection to a peer.
1009  *
1010  * Once the connection is established an onConnectionComplete in the event handler
1011  * will be called.
1012  *
1013  * @param peerAddressType
1014  * @param peerAddress
1015  * @param connectionParams
1016  *
1017  * @return BLE_ERROR_NONE if connection establishment procedure is started
1018  * successfully. The connectionCallChain (if set) is invoked upon
1019  * a connection event.
1020  *
1021  * @see EventHandler::onConnectionComplete will be called whether the
1022  * connection process succeed or fail.
1023  * @see EventHandler::onDisconnectionComplete is called when the connection
1024  * ends.
1025  */
1026  ble_error_t connect(
1027  peer_address_type_t peerAddressType,
1028  const address_t &peerAddress,
1029  const ConnectionParameters &connectionParams
1030  );
1031 
1032  /** Cancel the connection attempt. This is not guaranteed to succeed. As a result
1033  * onConnectionComplete in the event handler will be called. Check the success parameter
1034  * to see if the connection was created.
1035  *
1036  * @return BLE_ERROR_NONE if the connection attempt has been requested to be cancelled.
1037  * Returns BLE_ERROR_OPERATION_NOT_PERMITTED if no ongoing connection for last used address found.
1038  */
1039  ble_error_t cancelConnect();
1040 #endif // BLE_ROLE_CENTRAL
1041 
1042 #if BLE_FEATURE_CONNECTABLE
1043  /**
1044  * Update connection parameters of an existing connection.
1045  *
1046  * In the central role, this initiates a Link Layer connection parameter
1047  * update procedure. In the peripheral role, this sends the corresponding
1048  * L2CAP request and waits for the central to accept or reject the requested
1049  * connection parameters.
1050  *
1051  * @param connectionHandle The handle of the connection to update.
1052  * @param minConnectionInterval The minimum connection interval requested.
1053  * @param maxConnectionInterval The maximum connection interval requested.
1054  * @param slaveLatency The slave latency requested.
1055  * @param supervision_timeout The supervision timeout requested.
1056  * @param minConnectionEventLength The minimum connection event length requested.
1057  * @param maxConnectionEventLength The maximum connection event length requested.
1058  *
1059  * @return BLE_ERROR_NONE if the request has been sent and false otherwise.
1060  *
1061  * @see EventHandler::onUpdateConnectionParametersRequest when a central
1062  * receives a request to update the connection parameters.
1063  * @see EventHandler::onConnectionParametersUpdateComplete when connection
1064  * parameters have been updated.
1065  *
1066  * @version 4.0+ for central
1067  * @version 4.1+ for peripheral
1068  */
1069  ble_error_t updateConnectionParameters(
1070  connection_handle_t connectionHandle,
1071  conn_interval_t minConnectionInterval,
1072  conn_interval_t maxConnectionInterval,
1073  slave_latency_t slaveLatency,
1074  supervision_timeout_t supervision_timeout,
1075  conn_event_length_t minConnectionEventLength = conn_event_length_t(0),
1076  conn_event_length_t maxConnectionEventLength = conn_event_length_t(0)
1077  );
1078 
1079  /**
1080  * Allows the application to accept or reject a connection parameters update
1081  * request.
1082  *
1083  * If this process is managed by the middleware; new connection parameters
1084  * from a slave are always accepted.
1085  *
1086  * @param userManageConnectionUpdateRequest true to let the application
1087  * manage the process and false to let the middleware manage it.
1088  *
1089  * @return BLE_ERROR_NONE in case of success or an appropriate error code.
1090  *
1091  * @version 4.1+
1092  *
1093  * @see EventHandler::onUpdateConnectionParametersRequest when a central
1094  * receives a request to update the connection parameters.
1095  *
1096  * @see onUpdateConnectionParametersRequest
1097  * @see acceptConnectionParametersUpdate to accept the request.
1098  * @see rejectConnectionParametersUpdate to reject the request.
1099  */
1100  ble_error_t manageConnectionParametersUpdateRequest(
1101  bool userManageConnectionUpdateRequest
1102  );
1103 
1104  /**
1105  * Accept update of the connection parameters.
1106  *
1107  * The central can adjust the new connection parameters.
1108  *
1109  * @param connectionHandle The handle of the connection that has initiated
1110  * the request.
1111  * @param minConnectionInterval The minimum connection interval to be applied.
1112  * @param maxConnectionInterval The maximum connection interval to be applied.
1113  * @param slaveLatency The slave latency to be applied.
1114  * @param supervision_timeout The supervision timeout to be applied.
1115  * @param minConnectionEventLength The minimum connection event length to be
1116  * applied.
1117  * @param maxConnectionEventLength The maximum connection event length to be
1118  * applied.
1119  *
1120  * @return BLE_ERROR_NONE in case of success or an appropriate error code.
1121  *
1122  * @version 4.1+
1123  *
1124  * @see manageConnectionParametersUpdateRequest To let the application
1125  * manage the process.
1126  *
1127  * @see EventHandler::onUpdateConnectionParametersRequest Called when a
1128  * request to update the connection parameters is received.
1129  *
1130  * @see EventHandler::onConnectionParametersUpdateComplete Called when the
1131  * new connection parameters are effective.
1132  */
1133  ble_error_t acceptConnectionParametersUpdate(
1134  connection_handle_t connectionHandle,
1135  conn_interval_t minConnectionInterval,
1136  conn_interval_t maxConnectionInterval,
1137  slave_latency_t slaveLatency,
1138  supervision_timeout_t supervision_timeout,
1139  conn_event_length_t minConnectionEventLength = conn_event_length_t(0),
1140  conn_event_length_t maxConnectionEventLength = conn_event_length_t(0)
1141  );
1142 
1143  /**
1144  * Reject a request to change the connection parameters.
1145  *
1146  * @param connectionHandle The handle of the connection that has initiated
1147  * the request.
1148  *
1149  * @return BLE_ERROR_NONE in case of success or an appropriate error code.
1150  *
1151  * @version 4.1+
1152  *
1153  * @see manageConnectionParametersUpdateRequest To let the application
1154  * manage the process.
1155  *
1156  * @see EventHandler::onUpdateConnectionParametersRequest Called when a
1157  * request to update the connection parameters is received.
1158  */
1159  ble_error_t rejectConnectionParametersUpdate(
1160  connection_handle_t connectionHandle
1161  );
1162 
1163  /**
1164  * Initiate a disconnection procedure.
1165  *
1166  * Once the disconnection procedure has completed a
1167  * DisconnectionCallbackParams_t, the event is emitted to handlers that
1168  * have been registered with onDisconnection().
1169  *
1170  * @param[in] reason Reason of the disconnection transmitted to the peer.
1171  * @param[in] connectionHandle Handle of the connection to end.
1172  *
1173  * @return BLE_ERROR_NONE if the disconnection procedure successfully
1174  * started.
1175  *
1176  * @see EventHandler::onDisconnectionComplete when the disconnection is
1177  * effective.
1178  */
1179  ble_error_t disconnect(
1180  connection_handle_t connectionHandle,
1181  local_disconnection_reason_t reason
1182  );
1183 #endif // BLE_FEATURE_CONNECTABLE
1184 #if BLE_FEATURE_PHY_MANAGEMENT
1185  /**
1186  * Read the PHY used by the transmitter and the receiver on a connection.
1187  *
1188  * Once the PHY has been read, it is reported back via the function onPhyRead
1189  * of the event handler registered by the application.
1190  *
1191  * @param connection Handle of the connection for which the PHY being used is
1192  * queried.
1193  *
1194  * @return BLE_ERROR_NONE if the read PHY procedure has been started or an
1195  * appropriate error code.
1196  *
1197  * @version 5+
1198  *
1199  * @see EventHandler::onReadPhy is called when the phy has been read.
1200  */
1201  ble_error_t readPhy(connection_handle_t connection);
1202 
1203  /**
1204  * Set the preferred PHYs to use in a connection.
1205  *
1206  * @param txPhys: Set of PHYs preferred for tx operations. If NULL then no
1207  * preferred PHYs are set and the default value of the subsystem is used.
1208  *
1209  * @param rxPhys: Set of PHYs preferred for rx operations. If NULL then no
1210  * preferred PHYs are set and the default value of the subsystem is used.
1211  *
1212  * @return BLE_ERROR_NONE if the preferences have been set or an appropriate
1213  * error code.
1214  *
1215  * @version 5+
1216  */
1217  ble_error_t setPreferredPhys(
1218  const phy_set_t *txPhys,
1219  const phy_set_t *rxPhys
1220  );
1221 
1222  /**
1223  * Update the PHY used by a connection.
1224  *
1225  * Once the update process has been completed, it is reported back to the
1226  * application via the function onPhyUpdateComplete of the event handler
1227  * registered by the application.
1228  *
1229  * @param connection Handle of the connection to update.
1230  *
1231  * @param txPhys Set of PHYs preferred for tx operations. If NULL then the
1232  * choice is up to the Bluetooth subsystem.
1233  *
1234  * @param rxPhys Set of PHYs preferred for rx operations. If NULL then the
1235  * choice is up to the Bluetooth subsystem.
1236  *
1237  * @param codedSymbol Number of symbols used to code a bit when le coded is
1238  * used. If the value is UNDEFINED then the choice is up to the Bluetooth
1239  * subsystem.
1240  *
1241  * @return BLE_ERROR_NONE if the update PHY procedure has been successfully
1242  * started or an error code.
1243  *
1244  * @see EventHandler::onPhyUpdateComplete is called when the phy used by the
1245  * connection has been updated.
1246  */
1247  ble_error_t setPhy(
1248  connection_handle_t connection,
1249  const phy_set_t *txPhys,
1250  const phy_set_t *rxPhys,
1251  coded_symbol_per_bit_t codedSymbol
1252  );
1253 #endif // BLE_FEATURE_PHY_MANAGEMENT
1254 
1255 #if BLE_FEATURE_PRIVACY
1256  /**
1257  * Enable or disable privacy mode of the local device.
1258  *
1259  * When privacy is enabled, the system use private addresses while it scans,
1260  * advertises or initiate a connection. The device private address is
1261  * renewed every 15 minutes.
1262  *
1263  * @par Configuration
1264  *
1265  * The privacy feature can be configured with the help of the functions
1266  * setPeripheralPrivacyConfiguration and setCentralPrivacyConfiguration
1267  * which respectively set the privacy configuration of the peripheral and
1268  * central role.
1269  *
1270  * @par Default configuration of peripheral role
1271  *
1272  * By default private resolvable addresses are used for all procedures;
1273  * including advertisement of nonconnectable packets. Connection request
1274  * from an unknown initiator with a private resolvable address triggers the
1275  * pairing procedure.
1276  *
1277  * @par Default configuration of central role
1278  *
1279  * By default private resolvable addresses are used for all procedures;
1280  * including active scanning. Addresses present in advertisement packet are
1281  * resolved and advertisement packets are forwarded to the application
1282  * even if the advertiser private address is unknown.
1283  *
1284  * @par Initialization of the privacy subsystem
1285  *
1286  * When privacy is enabled, the system generates new resolvable and non
1287  * resolvable private addresses. Scan, Advertising and Connecting to a peer
1288  * won't be available until the generation process completes. When addresses
1289  * have been generated, the application is notified that privacy
1290  * initialisation as completed with a call to EventHandler::onPrivacyEnabled .
1291  *
1292  * @param[in] enable Should be set to true to enable the privacy mode and
1293  * false to disable it.
1294  *
1295  * @return BLE_ERROR_NONE in case of success or an appropriate error code.
1296  *
1297  * @see EventHandler::onPrivacyEnabled()
1298  */
1299  ble_error_t enablePrivacy(bool enable);
1300 
1301 #if BLE_ROLE_BROADCASTER
1302  /**
1303  * Set the privacy configuration used by the peripheral role.
1304  *
1305  * @param[in] configuration The configuration to set.
1306  *
1307  * @return BLE_ERROR_NONE in case of success or an appropriate error code.
1308  */
1309  ble_error_t setPeripheralPrivacyConfiguration(
1310  const peripheral_privacy_configuration_t *configuration
1311  );
1312 
1313  /**
1314  * Get the privacy configuration used by the peripheral role.
1315  *
1316  * @param[out] configuration The variable filled with the current
1317  * configuration.
1318  *
1319  * @return BLE_ERROR_NONE in case of success or an appropriate error code.
1320  */
1321  ble_error_t getPeripheralPrivacyConfiguration(
1322  peripheral_privacy_configuration_t *configuration
1323  );
1324 #endif // BLE_ROLE_BROADCASTER
1325 
1326 #if BLE_ROLE_OBSERVER
1327  /**
1328  * Set the privacy configuration used by the central role.
1329  *
1330  * @param[in] configuration The configuration to set.
1331  *
1332  * @return BLE_ERROR_NONE in case of success or an appropriate error code.
1333  */
1334  ble_error_t setCentralPrivacyConfiguration(
1335  const central_privacy_configuration_t *configuration
1336  );
1337 
1338  /**
1339  * Get the privacy configuration used by the central role.
1340  *
1341  * @param[out] configuration The variable filled with the current
1342  * configuration.
1343  *
1344  * @return BLE_ERROR_NONE in case of success or an appropriate error code.
1345  */
1346  ble_error_t getCentralPrivacyConfiguration(
1347  central_privacy_configuration_t *configuration
1348  );
1349 #endif // BLE_ROLE_OBSERVER
1350 #endif // BLE_FEATURE_PRIVACY
1351 
1352 #if BLE_FEATURE_WHITELIST
1353  /**
1354  * Get the maximum size of the whitelist.
1355  *
1356  * @return Maximum size of the whitelist.
1357  */
1358  uint8_t getMaxWhitelistSize() const;
1359 
1360  /**
1361  * Get the Link Layer to use the internal whitelist when scanning,
1362  * advertising or initiating a connection depending on the filter policies.
1363  *
1364  * @param[in,out] whitelist Define the whitelist instance which is used
1365  * to store the whitelist requested. In input, the caller provisions memory.
1366  *
1367  * @return BLE_ERROR_NONE if the implementation's whitelist was successfully
1368  * copied into the supplied reference.
1369  */
1370  ble_error_t getWhitelist(whitelist_t &whitelist) const;
1371 
1372  /**
1373  * Set the value of the whitelist to be used during GAP procedures.
1374  *
1375  * @param[in] whitelist A reference to a whitelist containing the addresses
1376  * to be copied to the internal whitelist.
1377  *
1378  * @return BLE_ERROR_NONE if the implementation's whitelist was successfully
1379  * populated with the addresses in the given whitelist.
1380  *
1381  * @note The whitelist must not contain non-resolvable addresses. This
1382  * results in a @ref BLE_ERROR_INVALID_PARAM because the remote peer might
1383  * change its private address at any time, and it is not possible to resolve
1384  * it.
1385  *
1386  * @note If the input whitelist is larger than @ref getMaxWhitelistSize(),
1387  * then @ref BLE_ERROR_PARAM_OUT_OF_RANGE is returned.
1388  */
1389  ble_error_t setWhitelist(const whitelist_t &whitelist);
1390 
1391 #endif // BLE_FEATURE_WHITELIST
1392 
1393  /**
1394  * Fetch the current address and its type.
1395  *
1396  * @param[out] typeP Type of the current address set.
1397  * @param[out] address Value of the current address.
1398  *
1399  * @note If privacy is enabled the device address may be unavailable to
1400  * application code.
1401  *
1402  * @return BLE_ERROR_NONE on success.
1403  */
1404  ble_error_t getAddress(
1405  own_address_type_t &typeP,
1406  address_t &address
1407  );
1408 
1409  /**
1410  * Return the type of a random address.
1411  *
1412  * @param[in] address The random address to retrieve the type from. The
1413  * address must be ordered in little endian.
1414  *
1415  * @param[out] addressType Type of the address to fill.
1416  *
1417  * @return BLE_ERROR_NONE in case of success or BLE_ERROR_INVALID_PARAM if
1418  * the address in input was not identifiable as a random address.
1419  */
1420  static ble_error_t getRandomAddressType(
1421  ble::address_t address,
1422  ble::random_address_type_t *addressType
1423  );
1424 
1425  /**
1426  * Reset the Gap instance.
1427  *
1428  * Reset process starts by notifying all registered shutdown event handlers
1429  * that the Gap instance is about to be shut down. Then, it clears all Gap state
1430  * of the associated object and then cleans the state present in the vendor
1431  * implementation.
1432  *
1433  * This function is meant to be overridden in the platform-specific
1434  * subclass. Nevertheless, the subclass only resets its
1435  * state and not the data held in Gap members. This is achieved by a
1436  * call to Gap::reset() from the subclass' reset() implementation.
1437  *
1438  * @return BLE_ERROR_NONE on success.
1439  *
1440  * @note Currently, a call to reset() does not reset the advertising and
1441  * scan parameters to default values.
1442  */
1443  ble_error_t reset();
1444 
1445  /**
1446  * Register a Gap shutdown event handler.
1447  *
1448  * The handler is called when the Gap instance is about to shut down.
1449  * It is usually issued after a call to BLE::shutdown().
1450  *
1451  * @param[in] callback Shutdown event handler to register.
1452  *
1453  * @note To unregister a shutdown event handler, use
1454  * onShutdown().detach(callback).
1455  */
1456  void onShutdown(const GapShutdownCallback_t &callback);
1457 
1458  /**
1459  * Register a Gap shutdown event handler.
1460  *
1461  * @param[in] objPtr Instance used to invoke @p memberPtr.
1462  * @param[in] memberPtr Shutdown event handler to register.
1463  */
1464  template<typename T>
1465  void onShutdown(T *objPtr, void (T::*memberPtr)(const Gap *)) {
1466  onShutdown(GapShutdownCallback_t(objPtr, memberPtr));
1467  }
1468 
1469  /**
1470  * Access the callchain of shutdown event handler.
1471  *
1472  * @note To register callbacks, use onShutdown().add(callback).
1473  *
1474  * @note To unregister callbacks, use onShutdown().detach(callback).
1475  *
1476  * @return A reference to the shutdown event callback chain.
1477  */
1478  GapShutdownCallbackChain_t &onShutdown();
1479 
1480 #if !defined(DOXYGEN_ONLY)
1481  /*
1482  * Constructor from the private implementation.
1483  */
1484  Gap(impl::Gap* impl) : impl(impl) {}
1485 
1486  /*
1487  * Restrict copy and move.
1488  */
1489  Gap(const Gap&) = delete;
1490  Gap& operator=(const Gap&) = delete;
1491 
1492  /*
1493  * API reserved for the controller driver to set the random static address.
1494  * Setting a new random static address while the controller is operating is
1495  * forbidden by the Bluetooth specification.
1496  */
1497  ble_error_t setRandomStaticAddress(const ble::address_t& address);
1498 
1499  ble::address_t getRandomStaticAddress();
1500 #endif // !defined(DOXYGEN_ONLY)
1501 
1502 private:
1503  impl::Gap* impl;
1504 };
1505 
1506 /**
1507  * @}
1508  * @}
1509  */
1510 
1511 } // namespace ble
1512 
1513 /** @deprecated Use the namespaced ble::Gap instead of the global Gap. */
1514 using ble::Gap;
1515 
1516 #endif // BLE_GAP_GAP_H
Event generated when a connection initiation ends (successfully or not).
Definition: Events.h:211
Function like object adapter over freestanding and member functions.
Event produced when advertising ends.
Definition: Events.h:624
virtual void onPrivacyEnabled()
Function invoked when the privacy subsystem has been enabled and is ready to be used.
Definition: Gap.h:563
virtual void onScanRequestReceived(const ScanRequestEvent &event)
Called when an advertising device receive a scan request.
Definition: Gap.h:313
Define device discovery, connection and link management procedures.
Definition: Gap.h:282
Event received when connection parameters have been updated.
Definition: Events.h:888
Event generated when periodic advertising sync is lost.
Definition: Events.h:545
uintptr_t connection_handle_t
Opaque reference to a connection.
virtual void onReadPhy(ble_error_t status, connection_handle_t connectionHandle, phy_t txPhy, phy_t rxPhy)
Function invoked when the current transmitter and receiver PHY have been read for a given connection...
Definition: Gap.h:494
Event produced when advertising start.
Definition: Events.h:583
Event generated when an advertising packet is seen during passive scanning or a scan response is rece...
Definition: Events.h:40
virtual void onUpdateConnectionParametersRequest(const UpdateConnectionParametersRequestEvent &event)
Called when the peer request connection parameters updates.
Definition: Gap.h:445
Type that describes a random device address type.
Type describing the number of symbols per bit in le coded PHY.
virtual void onConnectionComplete(const ConnectionCompleteEvent &event)
Called when connection attempt ends.
Definition: Gap.h:424
virtual void onDataLengthChange(connection_handle_t connectionHandle, uint16_t txSize, uint16_t rxSize)
Function invoked when the connections changes the maximum number of octets that can be sent or receiv...
Definition: Gap.h:549
Representation of a whitelist of addresses.
virtual void onAdvertisingStart(const AdvertisingStartEvent &event)
Called when advertising starts.
Definition: Gap.h:326
Callback< R(ArgTs...)> callback(R(*func)(ArgTs...)=nullptr) noexcept
Create a callback class with type inferred from the arguments.
Definition: Callback.h:678
Parameters defining the scan process.
MAC address data type.
Type that describes a bluetooth PHY(sical) transport.
uint16_t maxConnectionInterval
Maximum interval between two connection events allowed for a connection.
Definition: Gap.h:594
Parameters defining the connection initiation process.
virtual void onAdvertisingEnd(const AdvertisingEndEvent &event)
Called when advertising ends.
Definition: Gap.h:343
CallChainOfFunctionPointersWithContext< const Gap * > GapShutdownCallbackChain_t
Callchain of gap shutdown event handler.
Definition: Gap.h:297
virtual void onScanTimeout(const ScanTimeoutEvent &event)
Called when scan times out.
Definition: Gap.h:365
virtual void onConnectionParametersUpdateComplete(const ConnectionParametersUpdateCompleteEvent &event)
Called when connection parameters have been updated.
Definition: Gap.h:459
uint16_t slaveLatency
Number of connection events the slave can drop if it has nothing to communicate to the master...
Definition: Gap.h:602
Event generated when you first receive a periodic advertisement.
Definition: Events.h:373
Preferred connection parameter display in Generic Access Service.
Definition: Gap.h:577
FunctionPointerWithContext< const Gap * > GapShutdownCallback_t
Gap shutdown event handler.
Definition: Gap.h:289
uint16_t connectionSupervisionTimeout
Link supervision timeout for the connection.
Definition: Gap.h:618
Type that describes a peer device address type.
Event generated when scan times out.
Definition: Events.h:576
Event produced when a disconnection is complete.
Definition: Events.h:776
uint16_t minConnectionInterval
Minimum interval between two connection events allowed for a connection.
Definition: Gap.h:585
Type that describe a set of PHY(sical) transports.
Parameters defining the advertising process.
Definition of the general handler of Gap related events.
Definition: Gap.h:303
virtual void onDisconnectionComplete(const DisconnectionCompleteEvent &event)
Called when a connection has been disconnected.
Definition: Gap.h:472
Function like object hosting a list of FunctionPointerWithContext.
Event generated when periodic advertising packet is received.
Definition: Events.h:474
void onShutdown(T *objPtr, void(T::*memberPtr)(const Gap *))
Register a Gap shutdown event handler.
Definition: Gap.h:1465
Event received when a peer wants to change the connection parameters.
Definition: Events.h:815
virtual void onPeriodicAdvertisingSyncLoss(const PeriodicAdvertisingSyncLoss &event)
Called when a periodic advertising sync has been lost.
Definition: Gap.h:408
virtual void onPeriodicAdvertisingReport(const PeriodicAdvertisingReportEvent &event)
Called when a periodic advertising packet is received.
Definition: Gap.h:393
virtual void onAdvertisingReport(const AdvertisingReportEvent &event)
Called when a scanner receives an advertising or a scan response packet.
Definition: Gap.h:354
virtual void onPhyUpdateComplete(ble_error_t status, connection_handle_t connectionHandle, phy_t txPhy, phy_t rxPhy)
Function invoked when the update process of the PHY has been completed.
Definition: Gap.h:528
Entry namespace for all BLE API definitions.
Features supported by the controller.
Event produced when a peer requests a scan response from the advertiser.
Definition: Events.h:725
virtual void onPeriodicAdvertisingSyncEstablished(const PeriodicAdvertisingSyncEstablishedEvent &event)
Called when first advertising packet in periodic advertising is received.
Definition: Gap.h:378
ble_error_t
Error codes for the BLE API.
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.