Skip to content

Commit ae3aba8

Browse files
authored
BT: Advertising does not work with ESP-IDF 5.5+ (#670)
* Fix typo in the version guard; properly map extended advertising events; BLE 5.0 features mapping * Update changelog * Log mode configs came and went out shortly
1 parent 27b061a commit ae3aba8

3 files changed

Lines changed: 196 additions & 14 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ remote_component = { name = "espressif/lan87xx", version = "1.*" }
3535
```
3636

3737
### Fixed
38+
- BT/BLE: Advertising was not working with ESP-IDF 5.5+ and esp32, esp32c3 and esp32s3
39+
- BT/BLE: Extended advertising exvets were mis-mapped as `BleGapEvent::Other`
3840
- WiFi: receiving any of the six new events listed above on ESP-IDF v5.3+ / v5.5+ no longer causes a panic (fixes #618)
3941
- WebSocket: `EspWebSocketClient::drop()` no longer panics when `esp_websocket_client_close` returns `ESP_FAIL` (e.g. after a network disconnection); errors are now logged instead of unwrapped
4042
- MQTT: MQTT 5.0 CONNECT properties can now be set on `EspMqttClient` without deadlocking on `MQTT_API_LOCK`; they are applied inside the library between `esp_mqtt_client_init` and `esp_mqtt_client_start` via the new [`MqttClientConfiguration::mqtt5_connection_property`] field.

src/bt.rs

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ where
495495
esp_idf_version_patch_at_least_5_2_6,
496496
esp_idf_version_patch_at_least_5_3_3,
497497
esp_idf_version_patch_at_least_5_4_1,
498-
esp_idf_version_least_5_5_0,
498+
esp_idf_version_at_least_5_5_0,
499499
))]
500500
enc_key_sz_min: crate::sys::CONFIG_BTDM_CTRL_BR_EDR_MIN_ENC_KEY_SZ_DFT_EFF as _,
501501
dup_list_refresh_period: crate::sys::SCAN_DUPL_CACHE_REFRESH_PERIOD as _,
@@ -557,33 +557,55 @@ where
557557
esp_idf_version_patch_at_least_5_2_6,
558558
esp_idf_version_patch_at_least_5_3_4,
559559
esp_idf_version_patch_at_least_5_4_2,
560-
esp_idf_version_least_5_5_0,
560+
esp_idf_version_at_least_5_5_0,
561561
))]
562562
connect_en: crate::sys::BT_CTRL_BLE_MASTER != 0,
563563
scan_en: crate::sys::BT_CTRL_BLE_SCAN != 0,
564564
ble_aa_check: crate::sys::BLE_CTRL_CHECK_CONNECT_IND_ACCESS_ADDRESS_ENABLED != 0,
565565
#[cfg(any(
566-
esp_idf_version_patch_at_least_5_1_7,
567-
esp_idf_version_patch_at_least_5_2_6,
568-
esp_idf_version_patch_at_least_5_3_3,
569-
esp_idf_version_patch_at_least_5_4_2,
570-
esp_idf_version_least_5_5_0,
566+
all(
567+
esp_idf_version_patch_at_least_5_2_6,
568+
esp_idf_version_patch_at_most_5_2_6
569+
),
570+
all(
571+
esp_idf_version_patch_at_least_5_3_3,
572+
esp_idf_version_patch_at_most_5_3_4
573+
),
574+
all(
575+
esp_idf_version_patch_at_least_5_4_2,
576+
esp_idf_version_patch_at_most_5_4_3
577+
),
578+
all(
579+
esp_idf_version_patch_at_least_5_5_0,
580+
esp_idf_version_patch_at_most_5_5_1
581+
),
571582
))]
572583
ble_log_mode_en: crate::sys::BLE_LOG_MODE_EN,
573584
#[cfg(any(
574-
esp_idf_version_patch_at_least_5_1_7,
575-
esp_idf_version_patch_at_least_5_2_6,
576-
esp_idf_version_patch_at_least_5_3_3,
577-
esp_idf_version_patch_at_least_5_4_2,
578-
esp_idf_version_least_5_5_0,
585+
all(
586+
esp_idf_version_patch_at_least_5_2_6,
587+
esp_idf_version_patch_at_most_5_2_6
588+
),
589+
all(
590+
esp_idf_version_patch_at_least_5_3_3,
591+
esp_idf_version_patch_at_most_5_3_4
592+
),
593+
all(
594+
esp_idf_version_patch_at_least_5_4_2,
595+
esp_idf_version_patch_at_most_5_4_3
596+
),
597+
all(
598+
esp_idf_version_patch_at_least_5_5_0,
599+
esp_idf_version_patch_at_most_5_5_1
600+
),
579601
))]
580602
ble_log_level: crate::sys::BLE_LOG_LEVEL as _,
581603
#[cfg(any(
582604
esp_idf_version_patch_at_least_5_1_7,
583605
esp_idf_version_patch_at_least_5_2_6,
584606
esp_idf_version_patch_at_least_5_3_4,
585607
esp_idf_version_patch_at_least_5_4_2,
586-
esp_idf_version_least_5_5_0,
608+
esp_idf_version_at_least_5_5_0,
587609
))]
588610
adv_en: crate::sys::BT_CTRL_BLE_ADV != 0,
589611
..Default::default()

src/bt/ble/gap.rs

Lines changed: 159 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ pub enum ScanDuplicate {
321321
#[default]
322322
Disable = esp_ble_scan_duplicate_t_BLE_SCAN_DUPLICATE_DISABLE,
323323
Enable = esp_ble_scan_duplicate_t_BLE_SCAN_DUPLICATE_ENABLE,
324-
#[cfg(esp_idf_ble_50_feature_support)]
324+
#[cfg(esp_idf_bt_ble_50_features_supported)]
325325
Reset = esp_ble_scan_duplicate_t_BLE_SCAN_DUPLICATE_ENABLE_RESET,
326326
Max = esp_ble_scan_duplicate_t_BLE_SCAN_DUPLICATE_MAX,
327327
}
@@ -727,6 +727,164 @@ impl<'a> From<(esp_gap_ble_cb_event_t, &'a esp_ble_gap_cb_param_t)> for BleGapEv
727727
esp_gap_ble_cb_event_t_ESP_GAP_BLE_SET_CHANNELS_EVT => {
728728
Self::ChannelsConfigured(param.ble_set_channels.stat.try_into().unwrap())
729729
}
730+
// BLE 5.0 - PHY
731+
#[cfg(esp_idf_bt_ble_50_features_supported)]
732+
esp_gap_ble_cb_event_t_ESP_GAP_BLE_READ_PHY_COMPLETE_EVT => {
733+
Self::ReadFeaturesConfigured(param.read_phy)
734+
}
735+
// The `SET_PREFERED_*` events were renamed to `SET_PREFERRED_*` after ESP-IDF 4.4
736+
#[cfg(all(esp_idf_bt_ble_50_features_supported, esp_idf_version_major = "4"))]
737+
esp_gap_ble_cb_event_t_ESP_GAP_BLE_SET_PREFERED_DEFAULT_PHY_COMPLETE_EVT => {
738+
Self::PreferredDefaultPhyConfigured(
739+
param.set_perf_def_phy.status.try_into().unwrap(),
740+
)
741+
}
742+
#[cfg(all(esp_idf_bt_ble_50_features_supported, not(esp_idf_version_major = "4")))]
743+
esp_gap_ble_cb_event_t_ESP_GAP_BLE_SET_PREFERRED_DEFAULT_PHY_COMPLETE_EVT => {
744+
Self::PreferredDefaultPhyConfigured(
745+
param.set_perf_def_phy.status.try_into().unwrap(),
746+
)
747+
}
748+
#[cfg(all(esp_idf_bt_ble_50_features_supported, esp_idf_version_major = "4"))]
749+
esp_gap_ble_cb_event_t_ESP_GAP_BLE_SET_PREFERED_PHY_COMPLETE_EVT => {
750+
Self::PreferredPhyConfigured(param.set_perf_phy.status.try_into().unwrap())
751+
}
752+
#[cfg(all(esp_idf_bt_ble_50_features_supported, not(esp_idf_version_major = "4")))]
753+
esp_gap_ble_cb_event_t_ESP_GAP_BLE_SET_PREFERRED_PHY_COMPLETE_EVT => {
754+
Self::PreferredPhyConfigured(param.set_perf_phy.status.try_into().unwrap())
755+
}
756+
// BLE 5.0 - Extended advertising (needs the extended-advertising sub-feature, as the
757+
// corresponding fields of the callback param union are only present in that case)
758+
#[cfg(all(esp_idf_bt_ble_50_features_supported, esp_idf_bt_ble_50_extend_adv_en))]
759+
esp_gap_ble_cb_event_t_ESP_GAP_BLE_EXT_ADV_SET_RAND_ADDR_COMPLETE_EVT => {
760+
Self::ExtendedAdvertisingRandomAddressConfigured(
761+
param.ext_adv_set_rand_addr.status.try_into().unwrap(),
762+
)
763+
}
764+
#[cfg(all(esp_idf_bt_ble_50_features_supported, esp_idf_bt_ble_50_extend_adv_en))]
765+
esp_gap_ble_cb_event_t_ESP_GAP_BLE_EXT_ADV_SET_PARAMS_COMPLETE_EVT => {
766+
Self::ExtendedAdvertisingParametersConfigured(
767+
param.ext_adv_set_params.status.try_into().unwrap(),
768+
)
769+
}
770+
#[cfg(all(esp_idf_bt_ble_50_features_supported, esp_idf_bt_ble_50_extend_adv_en))]
771+
esp_gap_ble_cb_event_t_ESP_GAP_BLE_EXT_ADV_DATA_SET_COMPLETE_EVT => {
772+
Self::ExtendedAdvertisingConfigured(
773+
param.ext_adv_data_set.status.try_into().unwrap(),
774+
)
775+
}
776+
#[cfg(all(esp_idf_bt_ble_50_features_supported, esp_idf_bt_ble_50_extend_adv_en))]
777+
esp_gap_ble_cb_event_t_ESP_GAP_BLE_EXT_SCAN_RSP_DATA_SET_COMPLETE_EVT => {
778+
Self::ExtendedAdvertisingScanResponseConfigured(
779+
param.scan_rsp_set.status.try_into().unwrap(),
780+
)
781+
}
782+
#[cfg(all(esp_idf_bt_ble_50_features_supported, esp_idf_bt_ble_50_extend_adv_en))]
783+
esp_gap_ble_cb_event_t_ESP_GAP_BLE_EXT_ADV_START_COMPLETE_EVT => {
784+
Self::ExtendedAdvertisingStarted(param.ext_adv_start.status.try_into().unwrap())
785+
}
786+
#[cfg(all(esp_idf_bt_ble_50_features_supported, esp_idf_bt_ble_50_extend_adv_en))]
787+
esp_gap_ble_cb_event_t_ESP_GAP_BLE_EXT_ADV_STOP_COMPLETE_EVT => {
788+
Self::ExtendedAdvertisingStopped(param.ext_adv_stop.status.try_into().unwrap())
789+
}
790+
#[cfg(all(esp_idf_bt_ble_50_features_supported, esp_idf_bt_ble_50_extend_adv_en))]
791+
esp_gap_ble_cb_event_t_ESP_GAP_BLE_EXT_ADV_SET_REMOVE_COMPLETE_EVT => {
792+
Self::ExtendedAdvertisingRemoved(
793+
param.ext_adv_remove.status.try_into().unwrap(),
794+
)
795+
}
796+
#[cfg(all(esp_idf_bt_ble_50_features_supported, esp_idf_bt_ble_50_extend_adv_en))]
797+
esp_gap_ble_cb_event_t_ESP_GAP_BLE_EXT_ADV_SET_CLEAR_COMPLETE_EVT => {
798+
Self::ExtendedAdvertisingCleared(param.ext_adv_clear.status.try_into().unwrap())
799+
}
800+
// BLE 5.0 - Periodic advertising
801+
#[cfg(esp_idf_bt_ble_50_features_supported)]
802+
esp_gap_ble_cb_event_t_ESP_GAP_BLE_PERIODIC_ADV_SET_PARAMS_COMPLETE_EVT => {
803+
// Note: the field name is misspelled as `peroid_adv_set_params` in ESP-IDF
804+
Self::PeriodicAdvertisingParametersConfigured(
805+
param.peroid_adv_set_params.status.try_into().unwrap(),
806+
)
807+
}
808+
#[cfg(esp_idf_bt_ble_50_features_supported)]
809+
esp_gap_ble_cb_event_t_ESP_GAP_BLE_PERIODIC_ADV_DATA_SET_COMPLETE_EVT => {
810+
Self::PeriodicAdvertisingDataSetComplete(
811+
param.period_adv_data_set.status.try_into().unwrap(),
812+
)
813+
}
814+
#[cfg(esp_idf_bt_ble_50_features_supported)]
815+
esp_gap_ble_cb_event_t_ESP_GAP_BLE_PERIODIC_ADV_START_COMPLETE_EVT => {
816+
Self::PeriodicAdvertisingStarted(
817+
param.period_adv_start.status.try_into().unwrap(),
818+
)
819+
}
820+
#[cfg(esp_idf_bt_ble_50_features_supported)]
821+
esp_gap_ble_cb_event_t_ESP_GAP_BLE_PERIODIC_ADV_STOP_COMPLETE_EVT => {
822+
Self::PeriodicAdvertisingStopped(
823+
param.period_adv_stop.status.try_into().unwrap(),
824+
)
825+
}
826+
#[cfg(esp_idf_bt_ble_50_features_supported)]
827+
esp_gap_ble_cb_event_t_ESP_GAP_BLE_PERIODIC_ADV_CREATE_SYNC_COMPLETE_EVT => {
828+
Self::PeriodicAdvertisingSyncCreated(
829+
param.period_adv_create_sync.status.try_into().unwrap(),
830+
)
831+
}
832+
#[cfg(esp_idf_bt_ble_50_features_supported)]
833+
esp_gap_ble_cb_event_t_ESP_GAP_BLE_PERIODIC_ADV_SYNC_CANCEL_COMPLETE_EVT => {
834+
Self::PeriodicAdvertisingSyncCanceled(
835+
param.period_adv_sync_cancel.status.try_into().unwrap(),
836+
)
837+
}
838+
#[cfg(esp_idf_bt_ble_50_features_supported)]
839+
esp_gap_ble_cb_event_t_ESP_GAP_BLE_PERIODIC_ADV_SYNC_TERMINATE_COMPLETE_EVT => {
840+
Self::PeriodicAdvertisingSyncTerminated(
841+
param.period_adv_sync_term.status.try_into().unwrap(),
842+
)
843+
}
844+
#[cfg(esp_idf_bt_ble_50_features_supported)]
845+
esp_gap_ble_cb_event_t_ESP_GAP_BLE_PERIODIC_ADV_ADD_DEV_COMPLETE_EVT => {
846+
Self::PeriodicAdvertisingDeviceListAdded(
847+
param.period_adv_add_dev.status.try_into().unwrap(),
848+
)
849+
}
850+
#[cfg(esp_idf_bt_ble_50_features_supported)]
851+
esp_gap_ble_cb_event_t_ESP_GAP_BLE_PERIODIC_ADV_REMOVE_DEV_COMPLETE_EVT => {
852+
Self::PeriodicAdvertisingDeviceListRemoved(
853+
param.period_adv_remove_dev.status.try_into().unwrap(),
854+
)
855+
}
856+
#[cfg(esp_idf_bt_ble_50_features_supported)]
857+
esp_gap_ble_cb_event_t_ESP_GAP_BLE_PERIODIC_ADV_CLEAR_DEV_COMPLETE_EVT => {
858+
Self::PeriodicAdvertisingDeviceListCleared(
859+
param.period_adv_clear_dev.status.try_into().unwrap(),
860+
)
861+
}
862+
// BLE 5.0 - Extended scanning
863+
#[cfg(esp_idf_bt_ble_50_features_supported)]
864+
esp_gap_ble_cb_event_t_ESP_GAP_BLE_SET_EXT_SCAN_PARAMS_COMPLETE_EVT => {
865+
Self::ExtendedAdvertisingScanParametersConfigured(
866+
param.set_ext_scan_params.status.try_into().unwrap(),
867+
)
868+
}
869+
#[cfg(esp_idf_bt_ble_50_features_supported)]
870+
esp_gap_ble_cb_event_t_ESP_GAP_BLE_EXT_SCAN_START_COMPLETE_EVT => {
871+
Self::ExtendedAdvertisingScanStarted(
872+
param.ext_scan_start.status.try_into().unwrap(),
873+
)
874+
}
875+
#[cfg(esp_idf_bt_ble_50_features_supported)]
876+
esp_gap_ble_cb_event_t_ESP_GAP_BLE_EXT_SCAN_STOP_COMPLETE_EVT => {
877+
Self::ExtendedAdvertisingScanStopped(
878+
param.ext_scan_stop.status.try_into().unwrap(),
879+
)
880+
}
881+
// BLE 5.0 - Extended connection
882+
#[cfg(esp_idf_bt_ble_50_features_supported)]
883+
esp_gap_ble_cb_event_t_ESP_GAP_BLE_PREFER_EXT_CONN_PARAMS_SET_COMPLETE_EVT => {
884+
Self::ExtendedAdvertisingExtendedConnectionParamsConfigured(
885+
param.ext_conn_params_set.status.try_into().unwrap(),
886+
)
887+
}
730888
_ => Self::Other {
731889
raw_event: event,
732890
raw_data: EventRawData(param),

0 commit comments

Comments
 (0)