1pub mod blocklist;
6pub mod scanfilter;
7
8use base::generic_channel::{GenericCallback, GenericSender};
9use serde::{Deserialize, Serialize};
10
11use crate::scanfilter::{BluetoothScanfilterSequence, RequestDeviceoptions};
12
13#[derive(Debug, Deserialize, Serialize)]
14pub enum BluetoothError {
15 Type(String),
16 Network,
17 NotFound,
18 NotSupported,
19 Security,
20 InvalidState,
21}
22
23#[derive(Debug, Deserialize, Serialize)]
24pub enum GATTType {
25 PrimaryService,
26 Characteristic,
27 IncludedService,
28 Descriptor,
29}
30
31#[derive(Debug, Deserialize, Serialize)]
32pub struct BluetoothDeviceMsg {
33 pub id: String,
35 pub name: Option<String>,
36}
37
38#[derive(Debug, Deserialize, Serialize)]
39pub struct BluetoothServiceMsg {
40 pub uuid: String,
41 pub is_primary: bool,
42 pub instance_id: String,
43}
44
45#[derive(Debug, Deserialize, Serialize)]
46pub struct BluetoothCharacteristicMsg {
47 pub uuid: String,
49 pub instance_id: String,
50 pub broadcast: bool,
52 pub read: bool,
53 pub write_without_response: bool,
54 pub write: bool,
55 pub notify: bool,
56 pub indicate: bool,
57 pub authenticated_signed_writes: bool,
58 pub reliable_write: bool,
59 pub writable_auxiliaries: bool,
60}
61
62#[derive(Debug, Deserialize, Serialize)]
63pub struct BluetoothDescriptorMsg {
64 pub uuid: String,
65 pub instance_id: String,
66}
67
68pub type BluetoothServicesMsg = Vec<BluetoothServiceMsg>;
69
70pub type BluetoothCharacteristicsMsg = Vec<BluetoothCharacteristicMsg>;
71
72pub type BluetoothDescriptorsMsg = Vec<BluetoothDescriptorMsg>;
73
74pub type BluetoothResult<T> = Result<T, BluetoothError>;
75
76pub type BluetoothResponseResult = Result<BluetoothResponse, BluetoothError>;
77
78#[derive(Debug, Deserialize, Serialize)]
79pub enum BluetoothRequest {
80 RequestDevice(
81 RequestDeviceoptions,
82 GenericCallback<BluetoothResponseResult>,
83 ),
84 GATTServerConnect(String, GenericCallback<BluetoothResponseResult>),
85 GATTServerDisconnect(String, GenericSender<BluetoothResult<()>>),
86 GetGATTChildren(
87 String,
88 Option<String>,
89 bool,
90 GATTType,
91 GenericCallback<BluetoothResponseResult>,
92 ),
93 ReadValue(String, GenericCallback<BluetoothResponseResult>),
94 WriteValue(String, Vec<u8>, GenericCallback<BluetoothResponseResult>),
95 EnableNotification(String, bool, GenericCallback<BluetoothResponseResult>),
96 WatchAdvertisements(String, GenericCallback<BluetoothResponseResult>),
97 SetRepresentedToNull(Vec<String>, Vec<String>, Vec<String>),
98 IsRepresentedDeviceNull(String, GenericSender<bool>),
99 GetAvailability(GenericCallback<BluetoothResponseResult>),
100 MatchesFilter(
101 String,
102 BluetoothScanfilterSequence,
103 GenericSender<BluetoothResult<bool>>,
104 ),
105 Test(String, GenericSender<BluetoothResult<()>>),
106 Exit,
107}
108
109#[derive(Debug, Deserialize, Serialize)]
110pub enum BluetoothResponse {
111 RequestDevice(BluetoothDeviceMsg),
112 GATTServerConnect(bool),
113 GetPrimaryServices(BluetoothServicesMsg, bool),
114 GetIncludedServices(BluetoothServicesMsg, bool),
115 GetCharacteristics(BluetoothCharacteristicsMsg, bool),
116 GetDescriptors(BluetoothDescriptorsMsg, bool),
117 ReadValue(Vec<u8>),
118 WriteValue(Vec<u8>),
119 EnableNotification(()),
120 WatchAdvertisements(()),
121 GetAvailability(bool),
122}