@@ -123,13 +123,20 @@ class AdvertisingParameters {
123
123
* @param[in] minInterval, maxInterval Time interval between two advertisement.
124
124
* A range is provided to the LE subsystem, so it can adjust the advertising
125
125
* interval with other transmission happening on the BLE radio.
126
+ * @param[in] useLegacyPDU If true legacy PDU shall be used for advertising.
127
+ *
128
+ * @note If CONNECTABLE_UNDIRECTED or CONNECTABLE_DIRECTED advertising is used
129
+ * you must use legacy PDU.
126
130
*
127
131
* @note If values in input are out of range, they will be normalized.
132
+ *
133
+ * @note If type selected is incompatible with non legacy PDU, legacy PDU will be used.
128
134
*/
129
135
AdvertisingParameters (
130
136
advertising_type_t advType = advertising_type_t ::CONNECTABLE_UNDIRECTED,
131
137
adv_interval_t minInterval = adv_interval_t (DEFAULT_ADVERTISING_INTERVAL_MIN),
132
- adv_interval_t maxInterval = adv_interval_t (DEFAULT_ADVERTISING_INTERVAL_MAX)
138
+ adv_interval_t maxInterval = adv_interval_t (DEFAULT_ADVERTISING_INTERVAL_MAX),
139
+ bool useLegacyPDU = true
133
140
) :
134
141
_advType (advType),
135
142
_minInterval (minInterval),
@@ -147,27 +154,91 @@ class AdvertisingParameters {
147
154
_channel39 (true ),
148
155
_anonymous (false ),
149
156
_notifyOnScan (false ),
150
- _legacyPDU (true ),
157
+ _legacyPDU (useLegacyPDU ),
151
158
_includeHeaderTxPower (false )
152
159
{
153
- /* Min interval is slightly larger than in other modes. */
154
- if (_advType == advertising_type_t ::NON_CONNECTABLE_UNDIRECTED) {
155
- _minInterval = adv_interval_t (std::max (_minInterval.value (), GAP_ADV_PARAMS_INTERVAL_MIN_NONCON));
156
- _maxInterval = adv_interval_t (std::max (_maxInterval.value (), GAP_ADV_PARAMS_INTERVAL_MIN_NONCON));
157
- }
160
+ normalize ();
161
+ }
162
+
163
+ /* *
164
+ * Construct an instance of GapAdvertisingParams.
165
+ *
166
+ * @param[in] advType Type of advertising.
167
+ * @param[in] useLegacyPDU If true legacy PDU shall be used for advertising.
168
+ *
169
+ * @note If CONNECTABLE_UNDIRECTED or CONNECTABLE_DIRECTED advertising is used
170
+ * you must use legacy PDU.
171
+ *
172
+ * @note If type selected is incompatible with non legacy PDU, legacy PDU will be used.
173
+ */
174
+ AdvertisingParameters (
175
+ advertising_type_t advType,
176
+ bool useLegacyPDU
177
+ ) :
178
+ _advType (advType),
179
+ _minInterval (adv_interval_t (DEFAULT_ADVERTISING_INTERVAL_MIN)),
180
+ _maxInterval (adv_interval_t (DEFAULT_ADVERTISING_INTERVAL_MAX)),
181
+ _peerAddressType (target_peer_address_type_t ::PUBLIC),
182
+ _ownAddressType (own_address_type_t ::RANDOM),
183
+ _policy (advertising_filter_policy_t ::NO_FILTER),
184
+ _primaryPhy (phy_t ::LE_1M),
185
+ _secondaryPhy (phy_t ::LE_1M),
186
+ _peerAddress (),
187
+ _txPower (127 ),
188
+ _maxSkip (0 ),
189
+ _channel37 (true ),
190
+ _channel38 (true ),
191
+ _channel39 (true ),
192
+ _anonymous (false ),
193
+ _notifyOnScan (false ),
194
+ _legacyPDU (useLegacyPDU),
195
+ _includeHeaderTxPower (false )
196
+ {
197
+ normalize ();
158
198
}
159
199
160
200
public:
201
+ /* *
202
+ * Update the advertising type and whether to use legacy PDU.
203
+ *
204
+ * @note If legacy PDU is not used then you cannot use
205
+ * CONNECTABLE_UNDIRECTED nor CONNECTABLE_DIRECTED.
206
+ *
207
+ * @param[in] newAdvType The new advertising type.
208
+ *
209
+ * @param[in] legacy If true, legacy PDU will be used.
210
+ *
211
+ * @return reference to this object.
212
+ */
213
+ AdvertisingParameters &setType (advertising_type_t newAdvType, bool legacy)
214
+ {
215
+ if (newAdvType == advertising_type_t ::CONNECTABLE_UNDIRECTED ||
216
+ newAdvType == advertising_type_t ::CONNECTABLE_DIRECTED) {
217
+ /* these types can only be used with legacy PDUs */
218
+ MBED_ASSERT (legacy);
219
+ }
220
+ _advType = newAdvType;
221
+ _legacyPDU = legacy;
222
+ return *this ;
223
+ }
161
224
162
225
/* *
163
226
* Update the advertising type.
164
227
*
228
+ * @note If legacy PDU is not used then you cannot use
229
+ * CONNECTABLE_UNDIRECTED nor CONNECTABLE_DIRECTED.
230
+ *
165
231
* @param[in] newAdvType The new advertising type.
166
232
*
167
233
* @return reference to this object.
168
234
*/
169
235
AdvertisingParameters &setType (advertising_type_t newAdvType)
170
236
{
237
+ if (newAdvType == advertising_type_t ::CONNECTABLE_UNDIRECTED ||
238
+ newAdvType == advertising_type_t ::CONNECTABLE_DIRECTED) {
239
+ /* these types can only be used with legacy PDUs */
240
+ MBED_ASSERT (_legacyPDU);
241
+ }
171
242
_advType = newAdvType;
172
243
return *this ;
173
244
}
@@ -448,10 +519,19 @@ class AdvertisingParameters {
448
519
*
449
520
* @param enable If true, legacy PDU will be used.
450
521
*
522
+ * @note If CONNECTABLE_UNDIRECTED or CONNECTABLE_DIRECTED advertising is used
523
+ * you must use legacy PDU.
524
+ *
451
525
* @return A reference to this object.
452
526
*/
453
527
AdvertisingParameters &setUseLegacyPDU (bool enable = true )
454
528
{
529
+ if (!enable) {
530
+ /* these types can only be used with legacy PDUs */
531
+ MBED_ASSERT ((_advType != advertising_type_t ::CONNECTABLE_UNDIRECTED) &&
532
+ (_advType != advertising_type_t ::CONNECTABLE_DIRECTED));
533
+ }
534
+
455
535
_legacyPDU = enable;
456
536
return *this ;
457
537
}
@@ -490,6 +570,8 @@ class AdvertisingParameters {
490
570
*
491
571
* @param enable Advertising anonymous if true.
492
572
*
573
+ * @note You may not use anonymous advertising with periodic advertising on the same set.
574
+ *
493
575
* @return reference to this object.
494
576
*/
495
577
AdvertisingParameters &setAnonymousAdvertising (bool enable)
@@ -507,6 +589,23 @@ class AdvertisingParameters {
507
589
return _anonymous;
508
590
}
509
591
592
+ private:
593
+ /* *
594
+ * Enforce limits on parameters.
595
+ */
596
+ void normalize ()
597
+ {
598
+ /* Min interval is slightly larger than in other modes. */
599
+ if (_advType == advertising_type_t ::NON_CONNECTABLE_UNDIRECTED) {
600
+ _minInterval = adv_interval_t (std::max (_minInterval.value (), GAP_ADV_PARAMS_INTERVAL_MIN_NONCON));
601
+ _maxInterval = adv_interval_t (std::max (_maxInterval.value (), GAP_ADV_PARAMS_INTERVAL_MIN_NONCON));
602
+ }
603
+ if (_advType == advertising_type_t ::CONNECTABLE_DIRECTED ||
604
+ _advType == advertising_type_t ::CONNECTABLE_UNDIRECTED) {
605
+ _legacyPDU = true ;
606
+ }
607
+ }
608
+
510
609
private:
511
610
advertising_type_t _advType;
512
611
/* The advertising interval in ADV duration units (in other words, 0.625ms). */
0 commit comments