@@ -1380,6 +1380,8 @@ ble_error_t GenericGap::reset(void)
1380
1380
_existing_sets.clear ();
1381
1381
_active_sets.clear ();
1382
1382
_active_periodic_sets.clear ();
1383
+ _connectable_payload_size_exceeded.clear ();
1384
+ _set_is_connectable.clear ();
1383
1385
1384
1386
/* clear advertising set data on the controller */
1385
1387
_pal_gap.clear_advertising_sets ();
@@ -2033,6 +2035,8 @@ ble_error_t GenericGap::createAdvertisingSet(
2033
2035
uint8_t new_handle = LEGACY_ADVERTISING_HANDLE + 1 ;
2034
2036
uint8_t end = getMaxAdvertisingSetNumber ();
2035
2037
2038
+ *handle = INVALID_ADVERTISING_HANDLE;
2039
+
2036
2040
for (; new_handle < end; ++new_handle) {
2037
2041
if (!_existing_sets.get (new_handle)) {
2038
2042
ble_error_t err = setExtendedAdvertisingParameters (
@@ -2045,11 +2049,11 @@ ble_error_t GenericGap::createAdvertisingSet(
2045
2049
2046
2050
_existing_sets.set (new_handle);
2047
2051
*handle = new_handle;
2052
+
2048
2053
return BLE_ERROR_NONE;
2049
2054
}
2050
2055
}
2051
2056
2052
- *handle = INVALID_ADVERTISING_HANDLE;
2053
2057
return BLE_ERROR_NO_MEM;
2054
2058
}
2055
2059
@@ -2086,6 +2090,8 @@ ble_error_t GenericGap::destroyAdvertisingSet(advertising_handle_t handle)
2086
2090
return err;
2087
2091
}
2088
2092
2093
+ _connectable_payload_size_exceeded.clear (handle);
2094
+ _set_is_connectable.clear (handle);
2089
2095
_existing_sets.clear (handle);
2090
2096
return BLE_ERROR_NONE;
2091
2097
}
@@ -2140,6 +2146,10 @@ ble_error_t GenericGap::setExtendedAdvertisingParameters(
2140
2146
return BLE_ERROR_INVALID_PARAM;
2141
2147
}
2142
2148
2149
+ if (_active_sets.get (handle)) {
2150
+ return BLE_ERROR_OPERATION_NOT_PERMITTED;
2151
+ }
2152
+
2143
2153
pal::advertising_event_properties_t event_properties (params.getType ());
2144
2154
event_properties.include_tx_power = params.getTxPowerInHeader ();
2145
2155
event_properties.omit_advertiser_address = params.getAnonymousAdvertising ();
@@ -2173,6 +2183,12 @@ ble_error_t GenericGap::setExtendedAdvertisingParameters(
2173
2183
return err;
2174
2184
}
2175
2185
2186
+ if (event_properties.connectable ) {
2187
+ _set_is_connectable.set (handle);
2188
+ } else {
2189
+ _set_is_connectable.clear (handle);
2190
+ }
2191
+
2176
2192
return _pal_gap.set_advertising_set_random_address (
2177
2193
handle,
2178
2194
_random_static_identity_address
@@ -2261,9 +2277,30 @@ ble_error_t GenericGap::setAdvertisingData(
2261
2277
}
2262
2278
2263
2279
if (payload.size () > getMaxAdvertisingDataLength ()) {
2280
+ MBED_WARNING (MBED_ERROR_INVALID_SIZE, " Payload size exceeds getMaxAdvertisingDataLength()." );
2264
2281
return BLE_ERROR_INVALID_PARAM;
2265
2282
}
2266
2283
2284
+ if (!_active_sets.get (handle) && payload.size () > getMaxActiveSetAdvertisingDataLength ()) {
2285
+ MBED_WARNING (MBED_ERROR_INVALID_SIZE, " Payload size for active sets needs to fit in a single operation"
2286
+ " - not greater than getMaxActiveSetAdvertisingDataLength()." );
2287
+ return BLE_ERROR_INVALID_PARAM;
2288
+ }
2289
+
2290
+ if (!scan_response) {
2291
+ if (payload.size () > getMaxConnectableAdvertisingDataLength ()) {
2292
+ if (_active_sets.get (handle) && _set_is_connectable.get (handle)) {
2293
+ MBED_WARNING (MBED_ERROR_INVALID_SIZE, " Payload size for connectable advertising"
2294
+ " exceeds getMaxAdvertisingDataLength()." );
2295
+ return BLE_ERROR_INVALID_PARAM;
2296
+ } else {
2297
+ _connectable_payload_size_exceeded.set (handle);
2298
+ }
2299
+ } else {
2300
+ _connectable_payload_size_exceeded.clear (handle);
2301
+ }
2302
+ }
2303
+
2267
2304
// select the pal function
2268
2305
set_data_fn_t set_data = scan_response ?
2269
2306
&pal::Gap::set_extended_scan_response_data :
@@ -2322,6 +2359,11 @@ ble_error_t GenericGap::startAdvertising(
2322
2359
return BLE_ERROR_INVALID_PARAM;
2323
2360
}
2324
2361
2362
+ if (_connectable_payload_size_exceeded.get (handle) && _set_is_connectable.get (handle)) {
2363
+ MBED_WARNING (MBED_ERROR_INVALID_SIZE, " Payload size exceeds size allowed for connectable advertising." );
2364
+ return BLE_ERROR_INVALID_STATE;
2365
+ }
2366
+
2325
2367
if (is_extended_advertising_available ()) {
2326
2368
error = _pal_gap.extended_advertising_enable (
2327
2369
/* enable */ true ,
0 commit comments