From e6226c1ddf56d778af13d1e8b11544f1a9afe01c Mon Sep 17 00:00:00 2001 From: Alex Moon Date: Mon, 6 Jan 2025 10:32:54 -0700 Subject: [PATCH 1/5] Fix static mut ref warnings in rust 1.83+ --- nrf-softdevice/src/ble/central.rs | 2 +- nrf-softdevice/src/ble/connection.rs | 2 +- nrf-softdevice/src/softdevice.rs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/nrf-softdevice/src/ble/central.rs b/nrf-softdevice/src/ble/central.rs index 0418aeb..a27772c 100644 --- a/nrf-softdevice/src/ble/central.rs +++ b/nrf-softdevice/src/ble/central.rs @@ -183,7 +183,7 @@ where // has been dropped and the scanning has been stopped. static mut BUF: [u8; BUF_LEN] = [0u8; BUF_LEN]; static mut BUF_DATA: raw::ble_data_t = raw::ble_data_t { - p_data: unsafe { BUF.as_mut_ptr() }, + p_data: unsafe { (&mut *(&raw mut BUF)).as_mut_ptr() }, len: BUF_LEN as u16, }; diff --git a/nrf-softdevice/src/ble/connection.rs b/nrf-softdevice/src/ble/connection.rs index fe492ec..78db407 100644 --- a/nrf-softdevice/src/ble/connection.rs +++ b/nrf-softdevice/src/ble/connection.rs @@ -825,7 +825,7 @@ pub(crate) fn with_state(index: u8, f: impl FnOnce(&mut ConnectionState) -> T fn allocate_index(f: impl FnOnce(u8, &mut ConnectionState) -> T) -> Result { unsafe { - for (i, s) in STATES.iter().enumerate() { + for (i, s) in (&*(&raw const STATES)).iter().enumerate() { let state = &mut *s.get(); if state.refcount == 0 && !state.conn_handle.is_connected() { return Ok(f(i as u8, state)); diff --git a/nrf-softdevice/src/softdevice.rs b/nrf-softdevice/src/softdevice.rs index 682f947..f9cf961 100644 --- a/nrf-softdevice/src/softdevice.rs +++ b/nrf-softdevice/src/softdevice.rs @@ -287,7 +287,7 @@ impl Softdevice { }; unsafe { - let p = SOFTDEVICE.as_mut_ptr(); + let p = (&mut *(&raw mut SOFTDEVICE)).as_mut_ptr(); p.write(sd); &mut *p } @@ -298,7 +298,7 @@ impl Softdevice { /// (a call to [`enable`] has returned without error) and no `&mut` references /// to the softdevice are active pub unsafe fn steal() -> &'static Softdevice { - &*SOFTDEVICE.as_ptr() + &*(&*(&raw const SOFTDEVICE)).as_ptr() } /// Runs the softdevice event handling loop. From 3481e5a4ecaa66d0110a59201c8fa443fbbb58d2 Mon Sep 17 00:00:00 2001 From: Peter Hansen Date: Fri, 30 Dec 2022 15:50:16 -0500 Subject: [PATCH 2/5] unable to build with default feature std in uuid --- nrf-softdevice-macro/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nrf-softdevice-macro/Cargo.toml b/nrf-softdevice-macro/Cargo.toml index 929ee60..3cbc435 100644 --- a/nrf-softdevice-macro/Cargo.toml +++ b/nrf-softdevice-macro/Cargo.toml @@ -15,7 +15,7 @@ quote = "1.0.7" darling = "0.13.4" proc-macro2 = "1.0.18" Inflector = "0.11.4" -uuid = "1.2.2" +uuid = { version = "1.2.2", default-features = false } [lib] proc-macro = true From 22e0d2b7bcc4d66f74da0ef64f01e60ad129fa23 Mon Sep 17 00:00:00 2001 From: Peter Hansen Date: Tue, 3 Dec 2024 12:44:03 -0500 Subject: [PATCH 3/5] fix for #281, no longer panic if disconnect() called while already disconnecting --- nrf-softdevice/src/ble/connection.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/nrf-softdevice/src/ble/connection.rs b/nrf-softdevice/src/ble/connection.rs index 78db407..6c0950c 100644 --- a/nrf-softdevice/src/ble/connection.rs +++ b/nrf-softdevice/src/ble/connection.rs @@ -301,6 +301,12 @@ impl ConnectionState { } let ret = unsafe { raw::sd_ble_gap_disconnect(conn_handle, reason.into()) }; + // This case can occur in normal operation if e.g. the connection was + // already being disconnected when disconnect() is called, so + // return as error instead of a panic. + if ret == raw::NRF_ERROR_INVALID_STATE { + return Err(DisconnectedError); + } unwrap!(RawError::convert(ret), "sd_ble_gap_disconnect"); self.disconnecting = true; From 82a09dd3fd6c0a83ca1ea8dd78c0700936f9cdd8 Mon Sep 17 00:00:00 2001 From: Peter Hansen Date: Tue, 3 Dec 2024 12:47:28 -0500 Subject: [PATCH 4/5] back to original, maybe was never required --- nrf-softdevice-macro/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nrf-softdevice-macro/Cargo.toml b/nrf-softdevice-macro/Cargo.toml index 3cbc435..929ee60 100644 --- a/nrf-softdevice-macro/Cargo.toml +++ b/nrf-softdevice-macro/Cargo.toml @@ -15,7 +15,7 @@ quote = "1.0.7" darling = "0.13.4" proc-macro2 = "1.0.18" Inflector = "0.11.4" -uuid = { version = "1.2.2", default-features = false } +uuid = "1.2.2" [lib] proc-macro = true From 6f68edb3a28a81b704c575ea24666d3dda3bef64 Mon Sep 17 00:00:00 2001 From: nazo6 Date: Mon, 6 Jan 2025 17:40:44 +0900 Subject: [PATCH 5/5] Disable default feature of Inflector --- nrf-softdevice-macro/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nrf-softdevice-macro/Cargo.toml b/nrf-softdevice-macro/Cargo.toml index 929ee60..d816051 100644 --- a/nrf-softdevice-macro/Cargo.toml +++ b/nrf-softdevice-macro/Cargo.toml @@ -14,7 +14,7 @@ syn = { version = "1.0.39", features = ["full", "extra-traits"] } quote = "1.0.7" darling = "0.13.4" proc-macro2 = "1.0.18" -Inflector = "0.11.4" +Inflector = { version = "0.11.4", default-features = false } uuid = "1.2.2" [lib]