pub struct Connection<'stack, P: PacketPool> { /* private fields */ }
Expand description
Handle to a BLE connection.
When the last reference to a connection is dropped, the connection is automatically disconnected.
Implementations§
Source§impl<'stack, P: PacketPool> Connection<'stack, P>
impl<'stack, P: PacketPool> Connection<'stack, P>
Sourcepub async fn next(&self) -> ConnectionEvent
pub async fn next(&self) -> ConnectionEvent
Wait for next connection event.
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Check if still connected
Sourcepub fn handle(&self) -> ConnHandle
pub fn handle(&self) -> ConnHandle
Connection handle of this connection.
Sourcepub fn role(&self) -> LeConnRole
pub fn role(&self) -> LeConnRole
The connection role for this connection.
Sourcepub fn peer_address(&self) -> BdAddr
pub fn peer_address(&self) -> BdAddr
The peer address for this connection.
Sourcepub fn peer_identity(&self) -> Identity
pub fn peer_identity(&self) -> Identity
The peer identity key for this connection.
Sourcepub fn request_security(&self) -> Result<(), Error>
pub fn request_security(&self) -> Result<(), Error>
Request a certain security level
For a peripheral this may cause the peripheral to send a security request. For a central this may cause the central to send a pairing request.
If the link is already encrypted then this will always generate an error.
Sourcepub fn security_level(&self) -> Result<SecurityLevel, Error>
pub fn security_level(&self) -> Result<SecurityLevel, Error>
Get the encrypted state of the connection
Sourcepub fn bondable(&self) -> Result<bool, Error>
pub fn bondable(&self) -> Result<bool, Error>
Get whether the connection is set as bondable or not.
This is only relevant before pairing has started.
Sourcepub fn set_bondable(&self, bondable: bool) -> Result<(), Error>
pub fn set_bondable(&self, bondable: bool) -> Result<(), Error>
Set whether the connection is bondable or not.
By default a connection is not bondable.
This must be set before pairing is initiated. Once the pairing procedure has started this field is ignored.
If both peripheral and central are bondable then the [ConnectionEvent::PairingComplete
]
event contains the bond information for the pairing. This bond information should be stored
in non-volatile memory and restored on reboot using [Stack::add_bond_information()
].
If any party in a pairing is not bondable the [ConnectionEvent::PairingComplete
] contains
a None
entry for the bond
member.
Sourcepub fn pass_key_confirm(&self) -> Result<(), Error>
pub fn pass_key_confirm(&self) -> Result<(), Error>
Confirm that the displayed pass key matches the one displayed on the other party
Sourcepub fn pass_key_cancel(&self) -> Result<(), Error>
pub fn pass_key_cancel(&self) -> Result<(), Error>
The displayed pass key does not match the one displayed on the other party
Sourcepub fn disconnect(&self)
pub fn disconnect(&self)
Request connection to be disconnected.
Sourcepub async fn rssi<T>(
&self,
stack: &Stack<'_, T, P>,
) -> Result<i8, BleHostError<T::Error>>where
T: ControllerCmdSync<ReadRssi>,
pub async fn rssi<T>(
&self,
stack: &Stack<'_, T, P>,
) -> Result<i8, BleHostError<T::Error>>where
T: ControllerCmdSync<ReadRssi>,
The RSSI value for this connection.
Sourcepub async fn set_phy<T>(
&self,
stack: &Stack<'_, T, P>,
phy: PhyKind,
) -> Result<(), BleHostError<T::Error>>where
T: ControllerCmdAsync<LeSetPhy>,
pub async fn set_phy<T>(
&self,
stack: &Stack<'_, T, P>,
phy: PhyKind,
) -> Result<(), BleHostError<T::Error>>where
T: ControllerCmdAsync<LeSetPhy>,
Update phy for this connection.
This updates both TX and RX phy of the connection. For more fine grained control, use the LeSetPhy HCI command directly.
Sourcepub async fn read_phy<T>(
&self,
stack: &Stack<'_, T, P>,
) -> Result<(PhyKind, PhyKind), BleHostError<T::Error>>where
T: ControllerCmdSync<LeReadPhy>,
pub async fn read_phy<T>(
&self,
stack: &Stack<'_, T, P>,
) -> Result<(PhyKind, PhyKind), BleHostError<T::Error>>where
T: ControllerCmdSync<LeReadPhy>,
Read the current phy used for the connection.
Sourcepub async fn update_data_length<T>(
&self,
stack: &Stack<'_, T, P>,
length: u16,
time_us: u16,
) -> Result<(), BleHostError<T::Error>>
pub async fn update_data_length<T>( &self, stack: &Stack<'_, T, P>, length: u16, time_us: u16, ) -> Result<(), BleHostError<T::Error>>
Update data length for this connection.
Sourcepub async fn update_connection_params<T>(
&self,
stack: &Stack<'_, T, P>,
params: &ConnectParams,
) -> Result<(), BleHostError<T::Error>>
pub async fn update_connection_params<T>( &self, stack: &Stack<'_, T, P>, params: &ConnectParams, ) -> Result<(), BleHostError<T::Error>>
Update connection parameters for this connection.
Sourcepub async fn accept_connection_params<T>(
&self,
stack: &Stack<'_, T, P>,
params: &ConnectParams,
) -> Result<(), BleHostError<T::Error>>where
T: ControllerCmdAsync<LeConnUpdate>,
pub async fn accept_connection_params<T>(
&self,
stack: &Stack<'_, T, P>,
params: &ConnectParams,
) -> Result<(), BleHostError<T::Error>>where
T: ControllerCmdAsync<LeConnUpdate>,
Respond to updated parameters.
Sourcepub fn with_attribute_server<'values, 'server, M: RawMutex, const ATT_MAX: usize, const CCCD_MAX: usize, const CONN_MAX: usize>(
self,
server: &'server AttributeServer<'values, M, P, ATT_MAX, CCCD_MAX, CONN_MAX>,
) -> Result<GattConnection<'stack, 'server, P>, Error>
pub fn with_attribute_server<'values, 'server, M: RawMutex, const ATT_MAX: usize, const CCCD_MAX: usize, const CONN_MAX: usize>( self, server: &'server AttributeServer<'values, M, P, ATT_MAX, CCCD_MAX, CONN_MAX>, ) -> Result<GattConnection<'stack, 'server, P>, Error>
Transform BLE connection into a GattConnection