From ac7ef468ba2f10c35c2615898a6d6f43350beb0d Mon Sep 17 00:00:00 2001 From: taks <857tn859@gmail.com> Date: Wed, 17 Jul 2024 20:06:43 +0900 Subject: [PATCH] Added BLEDevice::set_preferred_mtu, BLEDevice::get_preferred_mtu --- src/ble_device.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/ble_device.rs b/src/ble_device.rs index dab6001..545c4e7 100644 --- a/src/ble_device.rs +++ b/src/ble_device.rs @@ -183,6 +183,23 @@ impl BLEDevice { unsafe { core::mem::transmute(esp_idf_sys::esp_ble_tx_power_get(power_type as _)) } } + /// Sets the preferred ATT MTU; the device will indicate this value in all subsequent ATT MTU exchanges. + /// The ATT MTU of a connection is equal to the lower of the two peers’preferred MTU values. + /// The ATT MTU is what dictates the maximum size of any message sent during a GATT procedure. + /// + /// The specified MTU must be within the following range: [23, BLE_ATT_MTU_MAX]. + /// 23 is a minimum imposed by the Bluetooth specification; + /// BLE_ATT_MTU_MAX is a NimBLE compile-time setting. + pub fn set_preferred_mtu(&self, mtu: u16) -> Result<(), BLEError> { + unsafe { ble!(esp_idf_sys::ble_att_set_preferred_mtu(mtu)) } + } + + /// Retrieves the preferred ATT MTU. + /// This is the value indicated by the device during an ATT MTU exchange. + pub fn get_preferred_mtu(&self) -> u16 { + unsafe { esp_idf_sys::ble_att_preferred_mtu() } + } + /// Get the addresses of all bonded peer device. pub fn bonded_addresses(&self) -> Result, BLEError> { let mut peer_id_addrs =