Skip to content

Commit 5ffa065

Browse files
pan-Cruz Monrreal II
authored andcommitted
BLE: Fix conversion of advertising type
Previously, we were passing the event_properties as defined by the Bluetooth spec which is not what DmAdvConfig expect as the advertising type passed to DmAdvConfig is Cordio tailored (and incomplete).
1 parent ef08465 commit 5ffa065

File tree

1 file changed

+71
-1
lines changed

1 file changed

+71
-1
lines changed

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

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,76 @@ ble_error_t Gap::set_extended_advertising_parameters(
670670
bool scan_request_notification
671671
)
672672
{
673+
uint8_t adv_type;
674+
675+
if (event_properties.use_legacy_pdu) {
676+
if (event_properties.directed == false) {
677+
if (event_properties.high_duty_cycle) {
678+
return BLE_ERROR_INVALID_PARAM;
679+
}
680+
681+
if (event_properties.connectable && event_properties.scannable == false) {
682+
return BLE_ERROR_INVALID_PARAM;
683+
}
684+
685+
if (event_properties.connectable && event_properties.scannable) {
686+
adv_type = DM_ADV_CONN_UNDIRECT;
687+
} else if (event_properties.scannable) {
688+
adv_type = DM_ADV_SCAN_UNDIRECT;
689+
} else {
690+
adv_type = DM_ADV_NONCONN_UNDIRECT;
691+
}
692+
} else {
693+
if (event_properties.scannable) {
694+
return BLE_ERROR_INVALID_PARAM;
695+
}
696+
697+
if (event_properties.connectable == false) {
698+
return BLE_ERROR_INVALID_PARAM;
699+
}
700+
701+
if (event_properties.high_duty_cycle) {
702+
adv_type = DM_ADV_CONN_DIRECT;
703+
} else {
704+
adv_type = DM_ADV_CONN_DIRECT_LO_DUTY;
705+
}
706+
}
707+
} else {
708+
if (event_properties.directed == false) {
709+
if (event_properties.high_duty_cycle) {
710+
return BLE_ERROR_INVALID_PARAM;
711+
}
712+
713+
if (event_properties.connectable && event_properties.scannable) {
714+
adv_type = DM_ADV_CONN_UNDIRECT;
715+
} else if (event_properties.scannable) {
716+
adv_type = DM_ADV_SCAN_UNDIRECT;
717+
} else if (event_properties.connectable) {
718+
adv_type = DM_EXT_ADV_CONN_UNDIRECT;
719+
} else {
720+
adv_type = DM_ADV_NONCONN_UNDIRECT;
721+
}
722+
} else {
723+
// note: not sure how to act with the high duty cycle in scannable
724+
// and non connectable mode. These cases looks correct from a Bluetooth
725+
// standpoint
726+
727+
if (event_properties.connectable && event_properties.scannable) {
728+
return BLE_ERROR_INVALID_PARAM;
729+
} else if (event_properties.connectable) {
730+
if (event_properties.high_duty_cycle) {
731+
adv_type = DM_ADV_CONN_DIRECT;
732+
} else {
733+
adv_type = DM_ADV_CONN_DIRECT_LO_DUTY;
734+
}
735+
} else if (event_properties.scannable) {
736+
adv_type = DM_EXT_ADV_SCAN_DIRECT;
737+
} else {
738+
adv_type = DM_EXT_ADV_NONCONN_DIRECT;
739+
}
740+
}
741+
}
742+
673743
DmAdvSetInterval(
674744
advertising_handle,
675745
primary_advertising_interval_min,
@@ -709,7 +779,7 @@ ble_error_t Gap::set_extended_advertising_parameters(
709779

710780
DmAdvConfig(
711781
advertising_handle,
712-
event_properties.value(), // TODO: use the raw value here ???
782+
adv_type,
713783
peer_address_type.value(),
714784
const_cast<uint8_t *>(peer_address.data())
715785
);

0 commit comments

Comments
 (0)