@@ -1729,15 +1729,12 @@ pub struct BluetoothIdentity {
17291729 pub bdaddr : String ,
17301730 /// Bluetooth device type (DUN or PANU)
17311731 pub bt_device_type : BluetoothNetworkRole ,
1732+ /// BlueZ adapter name (e.g. `"hci0"`, `"hci1"`). Defaults to `"hci0"` when `None`.
1733+ pub adapter : Option < String > ,
17321734}
17331735
17341736impl BluetoothIdentity {
1735- /// Creates a new `BluetoothIdentity`.
1736- ///
1737- /// # Arguments
1738- ///
1739- /// * `bdaddr` - Bluetooth MAC address (e.g., "00:1A:7D:DA:71:13")
1740- /// * `bt_device_type` - Bluetooth network role (PanU or Dun)
1737+ /// Creates a new `BluetoothIdentity` using the default adapter.
17411738 ///
17421739 /// # Errors
17431740 ///
@@ -1762,6 +1759,38 @@ impl BluetoothIdentity {
17621759 Ok ( Self {
17631760 bdaddr,
17641761 bt_device_type,
1762+ adapter : None ,
1763+ } )
1764+ }
1765+
1766+ /// Creates a new `BluetoothIdentity` targeting a specific adapter.
1767+ ///
1768+ /// # Errors
1769+ ///
1770+ /// Returns a `ConnectionError` if the provided `bdaddr` is not a
1771+ /// valid Bluetooth MAC address format.
1772+ ///
1773+ /// # Example
1774+ ///
1775+ /// ```rust
1776+ /// use nmrs::models::{BluetoothIdentity, BluetoothNetworkRole};
1777+ ///
1778+ /// let identity = BluetoothIdentity::with_adapter(
1779+ /// "00:1A:7D:DA:71:13".into(),
1780+ /// BluetoothNetworkRole::PanU,
1781+ /// "hci1".into(),
1782+ /// ).unwrap();
1783+ /// ```
1784+ pub fn with_adapter (
1785+ bdaddr : String ,
1786+ bt_device_type : BluetoothNetworkRole ,
1787+ adapter : String ,
1788+ ) -> Result < Self , ConnectionError > {
1789+ validate_bluetooth_address ( & bdaddr) ?;
1790+ Ok ( Self {
1791+ bdaddr,
1792+ bt_device_type,
1793+ adapter : Some ( adapter) ,
17651794 } )
17661795 }
17671796}
@@ -1776,8 +1805,6 @@ impl BluetoothIdentity {
17761805///
17771806/// # Example
17781807///
1779- /// # Example
1780- ///
17811808/// ```rust
17821809/// use nmrs::models::{BluetoothDevice, BluetoothNetworkRole, DeviceState};
17831810///
@@ -1788,6 +1815,7 @@ impl BluetoothIdentity {
17881815/// Some("Phone".into()),
17891816/// role,
17901817/// DeviceState::Activated,
1818+ /// Some("hci0".into()),
17911819/// );
17921820/// ```
17931821#[ non_exhaustive]
@@ -1803,19 +1831,13 @@ pub struct BluetoothDevice {
18031831 pub bt_caps : u32 ,
18041832 /// Current device state
18051833 pub state : DeviceState ,
1834+ /// BlueZ adapter name (e.g. `"hci0"`)
1835+ pub adapter : Option < String > ,
18061836}
18071837
18081838impl BluetoothDevice {
18091839 /// Creates a new `BluetoothDevice`.
18101840 ///
1811- /// # Arguments
1812- ///
1813- /// * `bdaddr` - Bluetooth MAC address
1814- /// * `name` - Friendly device name from BlueZ
1815- /// * `alias` - Device alias from BlueZ
1816- /// * `bt_caps` - Bluetooth device capabilities/type
1817- /// * `state` - Current device state
1818- ///
18191841 /// # Example
18201842 ///
18211843 /// ```rust
@@ -1828,6 +1850,7 @@ impl BluetoothDevice {
18281850 /// Some("Phone".into()),
18291851 /// role,
18301852 /// DeviceState::Activated,
1853+ /// Some("hci0".into()),
18311854 /// );
18321855 /// ```
18331856 #[ must_use]
@@ -1837,13 +1860,15 @@ impl BluetoothDevice {
18371860 alias : Option < String > ,
18381861 bt_caps : u32 ,
18391862 state : DeviceState ,
1863+ adapter : Option < String > ,
18401864 ) -> Self {
18411865 Self {
18421866 bdaddr,
18431867 name,
18441868 alias,
18451869 bt_caps,
18461870 state,
1871+ adapter,
18471872 }
18481873 }
18491874}
@@ -2972,13 +2997,15 @@ mod tests {
29722997 Some ( "Phone" . into ( ) ) ,
29732998 role,
29742999 DeviceState :: Activated ,
3000+ Some ( "hci0" . into ( ) ) ,
29753001 ) ;
29763002
29773003 assert_eq ! ( device. bdaddr, "00:1A:7D:DA:71:13" ) ;
29783004 assert_eq ! ( device. name, Some ( "MyPhone" . into( ) ) ) ;
29793005 assert_eq ! ( device. alias, Some ( "Phone" . into( ) ) ) ;
29803006 assert ! ( matches!( device. bt_caps, _role) ) ;
29813007 assert_eq ! ( device. state, DeviceState :: Activated ) ;
3008+ assert_eq ! ( device. adapter, Some ( "hci0" . into( ) ) ) ;
29823009 }
29833010
29843011 #[ test]
@@ -2990,6 +3017,7 @@ mod tests {
29903017 Some ( "Phone" . into ( ) ) ,
29913018 role,
29923019 DeviceState :: Activated ,
3020+ None ,
29933021 ) ;
29943022
29953023 let display_str = format ! ( "{}" , device) ;
@@ -3007,6 +3035,7 @@ mod tests {
30073035 None ,
30083036 role,
30093037 DeviceState :: Disconnected ,
3038+ None ,
30103039 ) ;
30113040
30123041 let display_str = format ! ( "{}" , device) ;
0 commit comments