make packetisation common

pull/8738/head
paul-szczepanek-arm 2018-11-08 16:15:10 +00:00 committed by Vincent Coubard
parent 87482b5530
commit 8794c0b43b
2 changed files with 39 additions and 36 deletions

View File

@ -88,9 +88,9 @@ public:
ble_error_t setAdvertisingParams(AdvHandle_t handle, const GapExtendedAdvertisingParams* params); ble_error_t setAdvertisingParams(AdvHandle_t handle, const GapExtendedAdvertisingParams* params);
ble_error_t setAdvertisingPayload(AdvHandle_t handle, const GapAdvertisingData* payload); ble_error_t setAdvertisingPayload(AdvHandle_t handle, const AdvertisingData* payload, bool minimiseFragmentation = false);
ble_error_t setAdvertisingScanResponse(AdvHandle_t handle, const GapAdvertisingData* response); ble_error_t setAdvertisingScanResponse(AdvHandle_t handle, const AdvertisingData* response, bool minimiseFragmentation = false);
ble_error_t startAdvertising(AdvHandle_t handle, uint8_t maxEvents = 0, uint32_t maxDuration = 0); ble_error_t startAdvertising(AdvHandle_t handle, uint8_t maxEvents = 0, uint32_t maxDuration = 0);
@ -227,12 +227,12 @@ public:
/** /**
* @see Gap::setAppearance * @see Gap::setAppearance
*/ */
virtual ble_error_t setAppearance(GapAdvertisingData::Appearance appearance); virtual ble_error_t setAppearance(AdvertisingData::Appearance appearance);
/** /**
* @see Gap::getAppearance * @see Gap::getAppearance
*/ */
virtual ble_error_t getAppearance(GapAdvertisingData::Appearance *appearanceP); virtual ble_error_t getAppearance(AdvertisingData::Appearance *appearanceP);
/** /**
* @see Gap::setTxPower * @see Gap::setTxPower
@ -376,6 +376,8 @@ public:
); );
private: private:
ble_error_t setAdvertisingData(AdvHandle_t handle, const AdvertisingData* payload, bool minimiseFragmentation, bool scan_reponse);
/** @note Implements ConnectionEventMonitor. /** @note Implements ConnectionEventMonitor.
* @copydoc ConnectionEventMonitor::set_connection_event_handler * @copydoc ConnectionEventMonitor::set_connection_event_handler
*/ */

View File

@ -733,12 +733,12 @@ ble_error_t GenericGap::getDeviceName(uint8_t *deviceName, unsigned *lengthP)
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
ble_error_t GenericGap::setAppearance(GapAdvertisingData::Appearance appearance) ble_error_t GenericGap::setAppearance(AdvertisingData::Appearance appearance)
{ {
return _gap_service.set_appearance(appearance); return _gap_service.set_appearance(appearance);
} }
ble_error_t GenericGap::getAppearance(GapAdvertisingData::Appearance *appearanceP) ble_error_t GenericGap::getAppearance(AdvertisingData::Appearance *appearanceP)
{ {
if (appearanceP == NULL) { if (appearanceP == NULL) {
return BLE_ERROR_INVALID_PARAM; return BLE_ERROR_INVALID_PARAM;
@ -1681,14 +1681,26 @@ ble_error_t GenericGap::setAdvertisingParams(AdvHandle_t handle, const GapExtend
); );
} }
ble_error_t GenericGap::setAdvertisingPayload(AdvHandle_t handle, const GapAdvertisingData* payload) { ble_error_t GenericGap::setAdvertisingPayload(AdvHandle_t handle, const AdvertisingData* payload, bool minimiseFragmentation) {
return setAdvertisingData(handle, payload, minimiseFragmentation, false);
}
ble_error_t GenericGap::setAdvertisingScanResponse(AdvHandle_t handle, const AdvertisingData* response, bool minimiseFragmentation) {
return setAdvertisingData(handle, response, minimiseFragmentation, true);
}
ble_error_t GenericGap::setAdvertisingData(AdvHandle_t handle, const GapAdvertisingData* payload, bool minimiseFragmentation, bool scan_reponse) {
if (!get_adv_set_bit(_existing_sets, handle) || !payload) { if (!get_adv_set_bit(_existing_sets, handle) || !payload) {
return BLE_ERROR_INVALID_PARAM; return BLE_ERROR_INVALID_PARAM;
} }
if (!is_extended_advertising_enabled()) { if (!is_extended_advertising_enabled()) {
if (handle == Gap::LEGACY_ADVERTISING_HANDLE) { if (handle == Gap::LEGACY_ADVERTISING_HANDLE) {
memcpy(&getLegacyAdvertisingPayload(), payload, sizeof(GapAdvertisingData)); if (scan_reponse) {
memcpy(&getLegacyAdvertisingPayload(), payload, sizeof(AdvertisingData));
} else {
memcpy(&getLegacyAdvertisingScanResponse(), payload, sizeof(AdvertisingData));
}
} }
return BLE_ERROR_NOT_IMPLEMENTED; return BLE_ERROR_NOT_IMPLEMENTED;
} }
@ -1710,13 +1722,23 @@ ble_error_t GenericGap::setAdvertisingPayload(AdvHandle_t handle, const GapAdver
operation = pal::advertising_fragment_description_t::LAST_FRAGMENT; operation = pal::advertising_fragment_description_t::LAST_FRAGMENT;
} }
_pal_gap.set_extended_advertising_data( if (scan_reponse) {
handle, _pal_gap.set_extended_advertising_data(
packet_data_length, handle,
payload->setMinimiseFragmentation, operation,
packet_data_length, minimiseFragmentation,
payload->getPayload() + index packet_data_length,
); payload->getPayload() + index
);
} else {
_pal_gap.set_extended_advertising_data(
handle,
operation,
minimiseFragmentation,
packet_data_length,
payload->getPayload() + index
);
}
index += packet_data_length; index += packet_data_length;
@ -1726,27 +1748,6 @@ ble_error_t GenericGap::setAdvertisingPayload(AdvHandle_t handle, const GapAdver
return status; return status;
} }
ble_error_t GenericGap::setAdvertisingScanResponse(AdvHandle_t handle, const GapAdvertisingData* response) {
if (!get_adv_set_bit(_existing_sets, handle) || !response) {
return BLE_ERROR_INVALID_PARAM;
}
if (!is_extended_advertising_enabled()) {
if (handle == Gap::LEGACY_ADVERTISING_HANDLE) {
memcpy(&getLegacyAdvertisingScanResponse(), response, sizeof(GapAdvertisingData));
}
return BLE_ERROR_NOT_IMPLEMENTED;
}
return _pal_gap.set_extended_scan_response_data(
handle,
/*TODO fragment*/ pal::advertising_fragment_description_t::FIRST_FRAGMENT,
response->setMinimiseFragmentation,
response->getPayloadLen(),
response->getPayload()
);
}
ble_error_t GenericGap::startAdvertising( ble_error_t GenericGap::startAdvertising(
AdvHandle_t handle, AdvHandle_t handle,
uint8_t maxEvents, uint8_t maxEvents,