Skip to content

Commit e1cf516

Browse files
fix max payload and hci length values
1 parent a91dccd commit e1cf516

File tree

8 files changed

+76
-17
lines changed

8 files changed

+76
-17
lines changed

features/FEATURE_BLE/ble/gap/AdvertisingParameters.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ class AdvertisingParameters {
124124
* A range is provided to the LE subsystem, so it can adjust the advertising
125125
* interval with other transmission happening on the BLE radio.
126126
*
127+
* @note If CONNECTABLE_UNDIRECTED or CONNECTABLE_DIRECTED advertising is used
128+
* you must use legacy PDU.
129+
*
127130
* @note If values in input are out of range, they will be normalized.
128131
*/
129132
AdvertisingParameters(
@@ -162,6 +165,9 @@ class AdvertisingParameters {
162165
/**
163166
* Update the advertising type.
164167
*
168+
* @note If legacy PDU is not used then you cannot use
169+
* CONNECTABLE_UNDIRECTED nor CONNECTABLE_DIRECTED.
170+
*
165171
* @param[in] newAdvType The new advertising type.
166172
*
167173
* @return reference to this object.
@@ -448,6 +454,9 @@ class AdvertisingParameters {
448454
*
449455
* @param enable If true, legacy PDU will be used.
450456
*
457+
* @note If CONNECTABLE_UNDIRECTED or CONNECTABLE_DIRECTED advertising is used
458+
* you must use legacy PDU.
459+
*
451460
* @return A reference to this object.
452461
*/
453462
AdvertisingParameters &setUseLegacyPDU(bool enable = true)
@@ -490,6 +499,8 @@ class AdvertisingParameters {
490499
*
491500
* @param enable Advertising anonymous if true.
492501
*
502+
* @note You may not use anonymous advertising with periodic advertising on the same set.
503+
*
493504
* @return reference to this object.
494505
*/
495506
AdvertisingParameters &setAnonymousAdvertising(bool enable)

features/FEATURE_BLE/ble/gap/Gap.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,12 @@ class Gap {
538538
*/
539539
virtual uint16_t getMaxAdvertisingDataLength();
540540

541+
/** Return maximum advertising data length supported for connectable advertising.
542+
*
543+
* @return Maximum advertising data length supported for connectable advertising.
544+
*/
545+
virtual uint16_t getMaxConnectableAdvertisingDataLength();
546+
541547
/** Create an advertising set and apply the passed in parameters. The handle returned
542548
* by this function must be used for all other calls that accept an advertising handle.
543549
* When done with advertising, remove from the system using destroyAdvertisingSet().

features/FEATURE_BLE/ble/generic/GenericGap.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ class GenericGap :
5050
public:
5151
/* TODO: move to config */
5252
static const uint8_t MAX_ADVERTISING_SETS = 15;
53-
static const size_t MAX_HCI_DATA_LENGTH = 251;
5453

5554
/**
5655
* Construct a GenericGap.
@@ -92,6 +91,10 @@ class GenericGap :
9291
*/
9392
virtual uint16_t getMaxAdvertisingDataLength();
9493

94+
/** @copydoc Gap::getMaxConnectableAdvertisingDataLength
95+
*/
96+
virtual uint16_t getMaxConnectableAdvertisingDataLength();
97+
9598
/** @copydoc Gap::createAdvertisingSet
9699
*/
97100
virtual ble_error_t createAdvertisingSet(

features/FEATURE_BLE/ble/pal/PalGap.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,23 @@ struct Gap {
764764
*/
765765
virtual uint16_t get_maximum_advertising_data_length() = 0;
766766

767+
/**
768+
* Query the maximum data length the controller supports in an advertising set
769+
* using connectable advertising.
770+
*
771+
* @return The length in byte the controller can support in an advertising set
772+
* for connectable advertising.
773+
*/
774+
virtual uint16_t get_maximum_connectable_advertising_data_length() = 0;
775+
776+
/**
777+
* Query the maximum payload length for a single HCI packet carrying partial
778+
* (or complete if it fits) data for advertising set.
779+
*
780+
* @return Max size of the HCI packet transporting the data.
781+
*/
782+
virtual uint8_t get_max_hci_advertising_data_length() = 0;
783+
767784
/**
768785
* Query the maximum number of concurrent advertising sets that is supported
769786
* by the controller.

features/FEATURE_BLE/source/gap/Gap.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ uint16_t Gap::getMaxAdvertisingDataLength()
3636
return LEGACY_ADVERTISING_MAX_SIZE;
3737
}
3838

39+
uint16_t Gap::getMaxConnectableAdvertisingDataLength()
40+
{
41+
/* Requesting action from porter(s): override this API if this capability is supported. */
42+
return LEGACY_ADVERTISING_MAX_SIZE;
43+
}
44+
3945
ble_error_t Gap::createAdvertisingSet(
4046
advertising_handle_t *handle,
4147
const AdvertisingParameters &parameters

features/FEATURE_BLE/source/generic/GenericGap.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1989,8 +1989,6 @@ void GenericGap::set_connection_event_handler(pal::ConnectionEventMonitor::Event
19891989

19901990
const uint8_t GenericGap::MAX_ADVERTISING_SETS;
19911991

1992-
const size_t GenericGap::MAX_HCI_DATA_LENGTH;
1993-
19941992
uint8_t GenericGap::getMaxAdvertisingSetNumber()
19951993
{
19961994
useVersionTwoAPI();
@@ -2009,6 +2007,12 @@ uint16_t GenericGap::getMaxAdvertisingDataLength()
20092007
return _pal_gap.get_maximum_advertising_data_length();
20102008
}
20112009

2010+
uint16_t GenericGap::getMaxConnectableAdvertisingDataLength()
2011+
{
2012+
useVersionTwoAPI();
2013+
return _pal_gap.get_maximum_connectable_advertising_data_length();
2014+
}
2015+
20122016
ble_error_t GenericGap::createAdvertisingSet(
20132017
advertising_handle_t *handle,
20142018
const AdvertisingParameters &parameters
@@ -2259,24 +2263,23 @@ ble_error_t GenericGap::setAdvertisingData(
22592263
&pal::Gap::set_extended_scan_response_data :
22602264
&pal::Gap::set_extended_advertising_data;
22612265

2262-
for (size_t i = 0, end = payload.size();
2263-
(i < end) || (i == 0 && end == 0);
2264-
i += MAX_HCI_DATA_LENGTH)
2265-
{
2266+
const size_t hci_length = _pal_gap.get_max_hci_advertising_data_length();
2267+
2268+
for (size_t i = 0, end = payload.size(); (i < end) || (i == 0 && end == 0); i += hci_length) {
22662269
// select the operation based on the index
22672270
op_t op(op_t::INTERMEDIATE_FRAGMENT);
2268-
if (end < MAX_HCI_DATA_LENGTH) {
2271+
if (end < hci_length) {
22692272
op = op_t::COMPLETE_FRAGMENT;
22702273
} else if (i == 0) {
22712274
op = op_t::FIRST_FRAGMENT;
2272-
} else if ((end - i) <= MAX_HCI_DATA_LENGTH) {
2275+
} else if ((end - i) <= hci_length) {
22732276
op = op_t::LAST_FRAGMENT;
22742277
}
22752278

22762279
// extract the payload
22772280
mbed::Span<const uint8_t> sub_payload = payload.subspan(
22782281
i,
2279-
std::min(MAX_HCI_DATA_LENGTH, (end - i))
2282+
std::min(hci_length, (end - i))
22802283
);
22812284

22822285
// set the payload
@@ -2467,24 +2470,23 @@ ble_error_t GenericGap::setPeriodicAdvertisingPayload(
24672470

24682471
typedef pal::advertising_fragment_description_t op_t;
24692472

2470-
for (size_t i = 0, end = payload.size();
2471-
(i < end) || (i == 0 && end == 0);
2472-
i += MAX_HCI_DATA_LENGTH
2473-
) {
2473+
const size_t hci_length = _pal_gap.get_max_hci_advertising_data_length();
2474+
2475+
for (size_t i = 0, end = payload.size(); (i < end) || (i == 0 && end == 0); i += hci_length) {
24742476
// select the operation based on the index
24752477
op_t op(op_t::INTERMEDIATE_FRAGMENT);
2476-
if (end < MAX_HCI_DATA_LENGTH) {
2478+
if (end < hci_length) {
24772479
op = op_t::COMPLETE_FRAGMENT;
24782480
} else if (i == 0) {
24792481
op = op_t::FIRST_FRAGMENT;
2480-
} else if ((end - i) <= MAX_HCI_DATA_LENGTH) {
2482+
} else if ((end - i) <= hci_length) {
24812483
op = op_t::LAST_FRAGMENT;
24822484
}
24832485

24842486
// extract the payload
24852487
mbed::Span<const uint8_t> sub_payload = payload.subspan(
24862488
i,
2487-
std::min(MAX_HCI_DATA_LENGTH, (end - i))
2489+
std::min(hci_length, (end - i))
24882490
);
24892491

24902492
ble_error_t err = _pal_gap.set_periodic_advertising_data(

features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalGap.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ class Gap : public ::ble::pal::Gap {
221221

222222
virtual uint16_t get_maximum_advertising_data_length();
223223

224+
virtual uint16_t get_maximum_connectable_advertising_data_length();
225+
226+
virtual uint8_t get_max_hci_advertising_data_length();
227+
224228
virtual uint8_t get_max_number_of_advertising_sets();
225229

226230
virtual ble_error_t remove_advertising_set(

features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioPalGap.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,16 @@ uint16_t Gap::get_maximum_advertising_data_length()
921921
return HciGetMaxAdvDataLen();
922922
}
923923

924+
uint16_t Gap::get_maximum_connectable_advertising_data_length()
925+
{
926+
return HCI_EXT_ADV_CONN_DATA_LEN;
927+
}
928+
929+
uint8_t Gap::get_max_hci_advertising_data_length()
930+
{
931+
return HCI_EXT_ADV_DATA_LEN;
932+
}
933+
924934
uint8_t Gap::get_max_number_of_advertising_sets()
925935
{
926936
return std::min(HciGetNumSupAdvSets(), (uint8_t) DM_NUM_ADV_SETS);

0 commit comments

Comments
 (0)