1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/// Represents a Bluetooth agent that handles authentication requests.
/// This struct manages PIN codes and passkeys for pairing operations.
pub struct Agent {
/// The PIN code used for pairing.
pincode: String,
/// The passkey used for authentication.
passkey: u32,
}
impl Agent {
/// Creates a new agent with a given PIN code and passkey.
///
/// # Arguments
/// * `pincode` - A string representing the PIN code.
/// * `passkey` - A 32-bit unsigned integer representing the passkey.
///
/// # Returns
/// A new `Agent` instance.
pub fn new(pincode: String, passkey: u32) -> Self {
Self { pincode, passkey }
}
/// Releases the agent, indicating it is no longer in use.
///
/// # Returns
/// A `Result` indicating success or failure.
pub async fn release(&self) -> zbus::fdo::Result<()> {
println!("Agent Released");
Ok(())
}
/// Handles a request for a PIN code from a Bluetooth device.
///
/// # Arguments
/// * `device` - The D-Bus object path of the requesting device.
///
/// # Returns
/// The PIN code as a string.
pub async fn request_pin_code(
&self,
device: &zbus::zvariant::OwnedObjectPath,
) -> zbus::fdo::Result<String> {
println!(
"RequestPinCode -> device: {}, pincode: {}",
device, self.pincode
);
Ok(self.pincode.clone())
}
/// Displays a PIN code on the device for user verification.
///
/// # Arguments
/// * `device` - The D-Bus object path of the device.
/// * `pincode` - The PIN code to display.
pub async fn display_pin_code(
&self,
device: &zbus::zvariant::OwnedObjectPath,
pincode: &str,
) -> zbus::fdo::Result<()> {
println!("DisplayPinCode -> dev: {}, pincode: {}", device, pincode);
Ok(())
}
/// Handles a request for a passkey from a Bluetooth device.
///
/// # Arguments
/// * `device` - The D-Bus object path of the requesting device.
///
/// # Returns
/// The passkey as a 32-bit unsigned integer.
pub async fn request_passkey(
&self,
device: &zbus::zvariant::OwnedObjectPath,
) -> zbus::fdo::Result<u32> {
println!(
"RequestPasskey -> dev: {}, passkey: {}",
device, self.passkey
);
Ok(self.passkey)
}
/// Displays the passkey and entered digits on the device.
///
/// # Arguments
/// * `device` - The D-Bus object path of the device.
/// * `passkey` - The passkey to display.
/// * `entered` - The number of entered digits.
pub async fn display_passkey(
&self,
device: &zbus::zvariant::OwnedObjectPath,
passkey: u32,
entered: u16,
) -> zbus::fdo::Result<()> {
println!(
"DisplayPasskey -> dev: {}, passkey: {}, entered: {}",
device, passkey, entered
);
Ok(())
}
/// Requests user confirmation for pairing based on the passkey.
///
/// # Arguments
/// * `device` - The D-Bus object path of the device.
/// * `passkey` - The passkey for verification.
pub fn request_confirmation(
&self,
device: &zbus::zvariant::OwnedObjectPath,
passkey: u32,
) -> zbus::fdo::Result<()> {
println!(
"RequestConfirmation -> dev: {}, passkey: {}",
device, passkey
);
Ok(())
}
/// Requests user authorization for a connection.
///
/// # Arguments
/// * `device` - The D-Bus object path of the device.
pub async fn request_authorization(
&self,
device: &zbus::zvariant::OwnedObjectPath,
) -> zbus::fdo::Result<()> {
println!("RequestAuthorization -> dev: {}", device);
Ok(())
}
/// Authorizes a service request from a Bluetooth device.
///
/// # Arguments
/// * `device` - The D-Bus object path of the device.
/// * `uuid` - The UUID of the requested service.
pub async fn authorize_service(
&self,
device: &zbus::zvariant::OwnedObjectPath,
uuid: &str,
) -> zbus::fdo::Result<()> {
println!("AuthorizeService -> dev: {}, uuid: {}", device, uuid);
Ok(())
}
/// Cancels an ongoing pairing or authentication process.
pub async fn cancel(&self) -> zbus::fdo::Result<()> {
println!("Cancel");
Ok(())
}
}