Skip to content

Commit

Permalink
Merge pull request #229 from alexmoon/mtu-exchange-panic
Browse files Browse the repository at this point in the history
Add MTU exchange error to connect
  • Loading branch information
Dirbaio authored Feb 12, 2024
2 parents da232c8 + e5602a3 commit 00eb525
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion nrf-softdevice/src/ble/central.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,27 @@ use crate::ble::{Address, Connection};
use crate::util::{get_union_field, OnDrop, Portal};
use crate::{raw, RawError, Softdevice};

#[cfg(feature = "ble-gatt-client")]
use crate::ble::gatt_client::MtuExchangeError;

#[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum ConnectError {
Timeout,
NoAddresses,
NoFreeConn,
#[cfg(feature = "ble-gatt-client")]
MtuExchange(MtuExchangeError),
Raw(RawError),
}

#[cfg(feature = "ble-gatt-client")]
impl From<MtuExchangeError> for ConnectError {
fn from(err: MtuExchangeError) -> Self {
ConnectError::MtuExchange(err)
}
}

impl From<RawError> for ConnectError {
fn from(err: RawError) -> Self {
ConnectError::Raw(err)
Expand Down Expand Up @@ -93,7 +105,7 @@ pub async fn connect(_sd: &Softdevice, config: &ConnectConfig<'_>) -> Result<Con
#[cfg(feature = "ble-gatt-client")]
{
let mtu = config.att_mtu.unwrap_or(_sd.att_mtu);
unwrap!(crate::ble::gatt_client::att_mtu_exchange(&conn, mtu).await);
crate::ble::gatt_client::att_mtu_exchange(&conn, mtu).await?;
}

Ok(conn)
Expand Down

0 comments on commit 00eb525

Please sign in to comment.