mirror of https://github.com/ARMmbed/mbed-os.git
fix max payload and hci length values
parent
a91dccd901
commit
e1cf516100
|
@ -124,6 +124,9 @@ public:
|
||||||
* A range is provided to the LE subsystem, so it can adjust the advertising
|
* A range is provided to the LE subsystem, so it can adjust the advertising
|
||||||
* interval with other transmission happening on the BLE radio.
|
* interval with other transmission happening on the BLE radio.
|
||||||
*
|
*
|
||||||
|
* @note If CONNECTABLE_UNDIRECTED or CONNECTABLE_DIRECTED advertising is used
|
||||||
|
* you must use legacy PDU.
|
||||||
|
*
|
||||||
* @note If values in input are out of range, they will be normalized.
|
* @note If values in input are out of range, they will be normalized.
|
||||||
*/
|
*/
|
||||||
AdvertisingParameters(
|
AdvertisingParameters(
|
||||||
|
@ -162,6 +165,9 @@ public:
|
||||||
/**
|
/**
|
||||||
* Update the advertising type.
|
* Update the advertising type.
|
||||||
*
|
*
|
||||||
|
* @note If legacy PDU is not used then you cannot use
|
||||||
|
* CONNECTABLE_UNDIRECTED nor CONNECTABLE_DIRECTED.
|
||||||
|
*
|
||||||
* @param[in] newAdvType The new advertising type.
|
* @param[in] newAdvType The new advertising type.
|
||||||
*
|
*
|
||||||
* @return reference to this object.
|
* @return reference to this object.
|
||||||
|
@ -448,6 +454,9 @@ public:
|
||||||
*
|
*
|
||||||
* @param enable If true, legacy PDU will be used.
|
* @param enable If true, legacy PDU will be used.
|
||||||
*
|
*
|
||||||
|
* @note If CONNECTABLE_UNDIRECTED or CONNECTABLE_DIRECTED advertising is used
|
||||||
|
* you must use legacy PDU.
|
||||||
|
*
|
||||||
* @return A reference to this object.
|
* @return A reference to this object.
|
||||||
*/
|
*/
|
||||||
AdvertisingParameters &setUseLegacyPDU(bool enable = true)
|
AdvertisingParameters &setUseLegacyPDU(bool enable = true)
|
||||||
|
@ -490,6 +499,8 @@ public:
|
||||||
*
|
*
|
||||||
* @param enable Advertising anonymous if true.
|
* @param enable Advertising anonymous if true.
|
||||||
*
|
*
|
||||||
|
* @note You may not use anonymous advertising with periodic advertising on the same set.
|
||||||
|
*
|
||||||
* @return reference to this object.
|
* @return reference to this object.
|
||||||
*/
|
*/
|
||||||
AdvertisingParameters &setAnonymousAdvertising(bool enable)
|
AdvertisingParameters &setAnonymousAdvertising(bool enable)
|
||||||
|
|
|
@ -538,6 +538,12 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual uint16_t getMaxAdvertisingDataLength();
|
virtual uint16_t getMaxAdvertisingDataLength();
|
||||||
|
|
||||||
|
/** Return maximum advertising data length supported for connectable advertising.
|
||||||
|
*
|
||||||
|
* @return Maximum advertising data length supported for connectable advertising.
|
||||||
|
*/
|
||||||
|
virtual uint16_t getMaxConnectableAdvertisingDataLength();
|
||||||
|
|
||||||
/** Create an advertising set and apply the passed in parameters. The handle returned
|
/** Create an advertising set and apply the passed in parameters. The handle returned
|
||||||
* by this function must be used for all other calls that accept an advertising handle.
|
* by this function must be used for all other calls that accept an advertising handle.
|
||||||
* When done with advertising, remove from the system using destroyAdvertisingSet().
|
* When done with advertising, remove from the system using destroyAdvertisingSet().
|
||||||
|
|
|
@ -50,7 +50,6 @@ class GenericGap :
|
||||||
public:
|
public:
|
||||||
/* TODO: move to config */
|
/* TODO: move to config */
|
||||||
static const uint8_t MAX_ADVERTISING_SETS = 15;
|
static const uint8_t MAX_ADVERTISING_SETS = 15;
|
||||||
static const size_t MAX_HCI_DATA_LENGTH = 251;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a GenericGap.
|
* Construct a GenericGap.
|
||||||
|
@ -92,6 +91,10 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual uint16_t getMaxAdvertisingDataLength();
|
virtual uint16_t getMaxAdvertisingDataLength();
|
||||||
|
|
||||||
|
/** @copydoc Gap::getMaxConnectableAdvertisingDataLength
|
||||||
|
*/
|
||||||
|
virtual uint16_t getMaxConnectableAdvertisingDataLength();
|
||||||
|
|
||||||
/** @copydoc Gap::createAdvertisingSet
|
/** @copydoc Gap::createAdvertisingSet
|
||||||
*/
|
*/
|
||||||
virtual ble_error_t createAdvertisingSet(
|
virtual ble_error_t createAdvertisingSet(
|
||||||
|
|
|
@ -764,6 +764,23 @@ struct Gap {
|
||||||
*/
|
*/
|
||||||
virtual uint16_t get_maximum_advertising_data_length() = 0;
|
virtual uint16_t get_maximum_advertising_data_length() = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query the maximum data length the controller supports in an advertising set
|
||||||
|
* using connectable advertising.
|
||||||
|
*
|
||||||
|
* @return The length in byte the controller can support in an advertising set
|
||||||
|
* for connectable advertising.
|
||||||
|
*/
|
||||||
|
virtual uint16_t get_maximum_connectable_advertising_data_length() = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query the maximum payload length for a single HCI packet carrying partial
|
||||||
|
* (or complete if it fits) data for advertising set.
|
||||||
|
*
|
||||||
|
* @return Max size of the HCI packet transporting the data.
|
||||||
|
*/
|
||||||
|
virtual uint8_t get_max_hci_advertising_data_length() = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query the maximum number of concurrent advertising sets that is supported
|
* Query the maximum number of concurrent advertising sets that is supported
|
||||||
* by the controller.
|
* by the controller.
|
||||||
|
|
|
@ -36,6 +36,12 @@ uint16_t Gap::getMaxAdvertisingDataLength()
|
||||||
return LEGACY_ADVERTISING_MAX_SIZE;
|
return LEGACY_ADVERTISING_MAX_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint16_t Gap::getMaxConnectableAdvertisingDataLength()
|
||||||
|
{
|
||||||
|
/* Requesting action from porter(s): override this API if this capability is supported. */
|
||||||
|
return LEGACY_ADVERTISING_MAX_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
ble_error_t Gap::createAdvertisingSet(
|
ble_error_t Gap::createAdvertisingSet(
|
||||||
advertising_handle_t *handle,
|
advertising_handle_t *handle,
|
||||||
const AdvertisingParameters ¶meters
|
const AdvertisingParameters ¶meters
|
||||||
|
|
|
@ -1989,8 +1989,6 @@ void GenericGap::set_connection_event_handler(pal::ConnectionEventMonitor::Event
|
||||||
|
|
||||||
const uint8_t GenericGap::MAX_ADVERTISING_SETS;
|
const uint8_t GenericGap::MAX_ADVERTISING_SETS;
|
||||||
|
|
||||||
const size_t GenericGap::MAX_HCI_DATA_LENGTH;
|
|
||||||
|
|
||||||
uint8_t GenericGap::getMaxAdvertisingSetNumber()
|
uint8_t GenericGap::getMaxAdvertisingSetNumber()
|
||||||
{
|
{
|
||||||
useVersionTwoAPI();
|
useVersionTwoAPI();
|
||||||
|
@ -2009,6 +2007,12 @@ uint16_t GenericGap::getMaxAdvertisingDataLength()
|
||||||
return _pal_gap.get_maximum_advertising_data_length();
|
return _pal_gap.get_maximum_advertising_data_length();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint16_t GenericGap::getMaxConnectableAdvertisingDataLength()
|
||||||
|
{
|
||||||
|
useVersionTwoAPI();
|
||||||
|
return _pal_gap.get_maximum_connectable_advertising_data_length();
|
||||||
|
}
|
||||||
|
|
||||||
ble_error_t GenericGap::createAdvertisingSet(
|
ble_error_t GenericGap::createAdvertisingSet(
|
||||||
advertising_handle_t *handle,
|
advertising_handle_t *handle,
|
||||||
const AdvertisingParameters ¶meters
|
const AdvertisingParameters ¶meters
|
||||||
|
@ -2259,24 +2263,23 @@ ble_error_t GenericGap::setAdvertisingData(
|
||||||
&pal::Gap::set_extended_scan_response_data :
|
&pal::Gap::set_extended_scan_response_data :
|
||||||
&pal::Gap::set_extended_advertising_data;
|
&pal::Gap::set_extended_advertising_data;
|
||||||
|
|
||||||
for (size_t i = 0, end = payload.size();
|
const size_t hci_length = _pal_gap.get_max_hci_advertising_data_length();
|
||||||
(i < end) || (i == 0 && end == 0);
|
|
||||||
i += MAX_HCI_DATA_LENGTH)
|
for (size_t i = 0, end = payload.size(); (i < end) || (i == 0 && end == 0); i += hci_length) {
|
||||||
{
|
|
||||||
// select the operation based on the index
|
// select the operation based on the index
|
||||||
op_t op(op_t::INTERMEDIATE_FRAGMENT);
|
op_t op(op_t::INTERMEDIATE_FRAGMENT);
|
||||||
if (end < MAX_HCI_DATA_LENGTH) {
|
if (end < hci_length) {
|
||||||
op = op_t::COMPLETE_FRAGMENT;
|
op = op_t::COMPLETE_FRAGMENT;
|
||||||
} else if (i == 0) {
|
} else if (i == 0) {
|
||||||
op = op_t::FIRST_FRAGMENT;
|
op = op_t::FIRST_FRAGMENT;
|
||||||
} else if ((end - i) <= MAX_HCI_DATA_LENGTH) {
|
} else if ((end - i) <= hci_length) {
|
||||||
op = op_t::LAST_FRAGMENT;
|
op = op_t::LAST_FRAGMENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
// extract the payload
|
// extract the payload
|
||||||
mbed::Span<const uint8_t> sub_payload = payload.subspan(
|
mbed::Span<const uint8_t> sub_payload = payload.subspan(
|
||||||
i,
|
i,
|
||||||
std::min(MAX_HCI_DATA_LENGTH, (end - i))
|
std::min(hci_length, (end - i))
|
||||||
);
|
);
|
||||||
|
|
||||||
// set the payload
|
// set the payload
|
||||||
|
@ -2467,24 +2470,23 @@ ble_error_t GenericGap::setPeriodicAdvertisingPayload(
|
||||||
|
|
||||||
typedef pal::advertising_fragment_description_t op_t;
|
typedef pal::advertising_fragment_description_t op_t;
|
||||||
|
|
||||||
for (size_t i = 0, end = payload.size();
|
const size_t hci_length = _pal_gap.get_max_hci_advertising_data_length();
|
||||||
(i < end) || (i == 0 && end == 0);
|
|
||||||
i += MAX_HCI_DATA_LENGTH
|
for (size_t i = 0, end = payload.size(); (i < end) || (i == 0 && end == 0); i += hci_length) {
|
||||||
) {
|
|
||||||
// select the operation based on the index
|
// select the operation based on the index
|
||||||
op_t op(op_t::INTERMEDIATE_FRAGMENT);
|
op_t op(op_t::INTERMEDIATE_FRAGMENT);
|
||||||
if (end < MAX_HCI_DATA_LENGTH) {
|
if (end < hci_length) {
|
||||||
op = op_t::COMPLETE_FRAGMENT;
|
op = op_t::COMPLETE_FRAGMENT;
|
||||||
} else if (i == 0) {
|
} else if (i == 0) {
|
||||||
op = op_t::FIRST_FRAGMENT;
|
op = op_t::FIRST_FRAGMENT;
|
||||||
} else if ((end - i) <= MAX_HCI_DATA_LENGTH) {
|
} else if ((end - i) <= hci_length) {
|
||||||
op = op_t::LAST_FRAGMENT;
|
op = op_t::LAST_FRAGMENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
// extract the payload
|
// extract the payload
|
||||||
mbed::Span<const uint8_t> sub_payload = payload.subspan(
|
mbed::Span<const uint8_t> sub_payload = payload.subspan(
|
||||||
i,
|
i,
|
||||||
std::min(MAX_HCI_DATA_LENGTH, (end - i))
|
std::min(hci_length, (end - i))
|
||||||
);
|
);
|
||||||
|
|
||||||
ble_error_t err = _pal_gap.set_periodic_advertising_data(
|
ble_error_t err = _pal_gap.set_periodic_advertising_data(
|
||||||
|
|
|
@ -221,6 +221,10 @@ public:
|
||||||
|
|
||||||
virtual uint16_t get_maximum_advertising_data_length();
|
virtual uint16_t get_maximum_advertising_data_length();
|
||||||
|
|
||||||
|
virtual uint16_t get_maximum_connectable_advertising_data_length();
|
||||||
|
|
||||||
|
virtual uint8_t get_max_hci_advertising_data_length();
|
||||||
|
|
||||||
virtual uint8_t get_max_number_of_advertising_sets();
|
virtual uint8_t get_max_number_of_advertising_sets();
|
||||||
|
|
||||||
virtual ble_error_t remove_advertising_set(
|
virtual ble_error_t remove_advertising_set(
|
||||||
|
|
|
@ -921,6 +921,16 @@ uint16_t Gap::get_maximum_advertising_data_length()
|
||||||
return HciGetMaxAdvDataLen();
|
return HciGetMaxAdvDataLen();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint16_t Gap::get_maximum_connectable_advertising_data_length()
|
||||||
|
{
|
||||||
|
return HCI_EXT_ADV_CONN_DATA_LEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t Gap::get_max_hci_advertising_data_length()
|
||||||
|
{
|
||||||
|
return HCI_EXT_ADV_DATA_LEN;
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t Gap::get_max_number_of_advertising_sets()
|
uint8_t Gap::get_max_number_of_advertising_sets()
|
||||||
{
|
{
|
||||||
return std::min(HciGetNumSupAdvSets(), (uint8_t) DM_NUM_ADV_SETS);
|
return std::min(HciGetNumSupAdvSets(), (uint8_t) DM_NUM_ADV_SETS);
|
||||||
|
|
Loading…
Reference in New Issue