From c70989612be75651bdd51e87d3ef8045010dc6e0 Mon Sep 17 00:00:00 2001 From: Alex Moon Date: Mon, 25 Mar 2024 16:39:48 -0400 Subject: [PATCH] Return `ble_gap_data_length_limitation` for those error variants for which it is valid. --- nrf-softdevice/src/ble/connection.rs | 50 +++++++++++++++------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/nrf-softdevice/src/ble/connection.rs b/nrf-softdevice/src/ble/connection.rs index 3ab6c81..f373409 100644 --- a/nrf-softdevice/src/ble/connection.rs +++ b/nrf-softdevice/src/ble/connection.rs @@ -63,25 +63,22 @@ impl From for IgnoreSlaveLatencyError { } } -#[derive(Debug, PartialEq, Eq, Clone, Copy)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] +#[cfg(any(feature = "s113", feature = "s132", feature = "s140"))] +#[derive(Debug, Clone, Copy)] pub enum DataLengthUpdateError { Disconnected, + NotSupported(raw::ble_gap_data_length_limitation_t), + Resources(raw::ble_gap_data_length_limitation_t), Raw(RawError), } +#[cfg(any(feature = "s113", feature = "s132", feature = "s140"))] impl From for DataLengthUpdateError { fn from(_err: DisconnectedError) -> Self { Self::Disconnected } } -impl From for DataLengthUpdateError { - fn from(err: RawError) -> Self { - Self::Raw(err) - } -} - pub enum PhyUpdateError { Disconnected, Raw(RawError), @@ -571,7 +568,7 @@ impl Connection { pub fn data_length_update( &mut self, params: Option<&raw::ble_gap_data_length_params_t>, - ) -> Result { + ) -> Result<(), DataLengthUpdateError> { let conn_handle = self.with_state(|state| state.check_connected())?; let params = params.map(core::ptr::from_ref).unwrap_or(core::ptr::null()); @@ -580,24 +577,31 @@ impl Connection { if let Err(err) = RawError::convert(ret) { warn!("sd_ble_gap_data_length_update err {:?}", err); - return Err(err.into()); - } - if dl_limitation.tx_payload_limited_octets != 0 || dl_limitation.rx_payload_limited_octets != 0 { - warn!( - "The requested TX/RX packet length is too long by {:?}/{:?} octets.", - dl_limitation.tx_payload_limited_octets, dl_limitation.rx_payload_limited_octets - ); - } + if dl_limitation.tx_payload_limited_octets != 0 || dl_limitation.rx_payload_limited_octets != 0 { + warn!( + "The requested TX/RX packet length is too long by {:?}/{:?} octets.", + dl_limitation.tx_payload_limited_octets, dl_limitation.rx_payload_limited_octets + ); + } - if dl_limitation.tx_rx_time_limited_us != 0 { - warn!( - "The requested combination of TX and RX packet lengths is too long by {:?} us", - dl_limitation.tx_rx_time_limited_us - ); + if dl_limitation.tx_rx_time_limited_us != 0 { + warn!( + "The requested combination of TX and RX packet lengths is too long by {:?} us", + dl_limitation.tx_rx_time_limited_us + ); + } + + let err = match err { + RawError::NotSupported => DataLengthUpdateError::NotSupported(dl_limitation), + RawError::Resources => DataLengthUpdateError::Resources(dl_limitation), + err => DataLengthUpdateError::Raw(err), + }; + + return Err(err); } - Ok(dl_limitation) + Ok(()) } /// Send a request to the connected device to change the PHY.