Skip to content

Commit 67db321

Browse files
check illegal adv params combimnation
1 parent ff0a2a9 commit 67db321

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

features/FEATURE_BLE/ble/gap/AdvertisingParameters.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,29 @@ class AdvertisingParameters {
161161
}
162162

163163
public:
164+
/**
165+
* Update the advertising type and whether to use legacy PDU.
166+
*
167+
* @note If legacy PDU is not used then you cannot use
168+
* CONNECTABLE_UNDIRECTED nor CONNECTABLE_DIRECTED.
169+
*
170+
* @param[in] newAdvType The new advertising type.
171+
*
172+
* @param[in] legacy If true, legacy PDU will be used.
173+
*
174+
* @return reference to this object.
175+
*/
176+
AdvertisingParameters &setType(advertising_type_t newAdvType, bool legacy)
177+
{
178+
if (newAdvType == advertising_type_t::CONNECTABLE_UNDIRECTED ||
179+
newAdvType == advertising_type_t::CONNECTABLE_DIRECTED) {
180+
/* these types can only be used with legacy PDUs */
181+
MBED_ASSERT(legacy);
182+
}
183+
_advType = newAdvType;
184+
_legacyPDU = legacy;
185+
return *this;
186+
}
164187

165188
/**
166189
* Update the advertising type.

features/FEATURE_BLE/source/generic/GenericGap.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2150,6 +2150,14 @@ ble_error_t GenericGap::setExtendedAdvertisingParameters(
21502150
return BLE_ERROR_OPERATION_NOT_PERMITTED;
21512151
}
21522152

2153+
/* check for illegal parameter combination */
2154+
if ((params.getType() == advertising_type_t::CONNECTABLE_UNDIRECTED ||
2155+
params.getType() == advertising_type_t::CONNECTABLE_DIRECTED) &&
2156+
params.getUseLegacyPDU() == false) {
2157+
/* these types can only be used with legacy PDUs */
2158+
return BLE_ERROR_INVALID_PARAM;
2159+
}
2160+
21532161
pal::advertising_event_properties_t event_properties(params.getType());
21542162
event_properties.include_tx_power = params.getTxPowerInHeader();
21552163
event_properties.omit_advertiser_address = params.getAnonymousAdvertising();

0 commit comments

Comments
 (0)