Skip to main content

cdp_driver/protocol/
bluetooth_emulation.rs

1// @generated by `just generate-methods` from protocol/*.json.
2// Do not edit by hand; edit xtask/ and regenerate.
3
4//! This domain allows configuring virtual Bluetooth devices to test the
5//! web-bluetooth API.
6//!
7//! Types, command parameters and event payloads for the `BluetoothEmulation`
8//! domain. The method-name constants for the same domain are in
9//! [`crate::methods`].
10//!
11//! This domain is experimental and may change without notice.
12
13use serde::{Deserialize, Serialize};
14
15/// Indicates the various states of Central.
16#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
17pub enum CentralState {
18    /// `absent`
19    #[serde(rename = "absent")]
20    Absent,
21    /// `powered-off`
22    #[serde(rename = "powered-off")]
23    PoweredOff,
24    /// `powered-on`
25    #[serde(rename = "powered-on")]
26    PoweredOn,
27    /// A value this vendored schema does not list. Chrome adds values ahead of
28    /// the published protocol, so an unrecognised one is kept as it arrived
29    /// rather than failing the payload it came in.
30    #[serde(untagged)]
31    Unrecognized(String),
32}
33
34/// Indicates the various types of GATT event.
35#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
36pub enum GattOperationType {
37    /// `connection`
38    #[serde(rename = "connection")]
39    Connection,
40    /// `discovery`
41    #[serde(rename = "discovery")]
42    Discovery,
43    /// A value this vendored schema does not list. Chrome adds values ahead of
44    /// the published protocol, so an unrecognised one is kept as it arrived
45    /// rather than failing the payload it came in.
46    #[serde(untagged)]
47    Unrecognized(String),
48}
49
50/// Indicates the various types of characteristic write.
51#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
52pub enum CharacteristicWriteType {
53    /// `write-default-deprecated`
54    #[serde(rename = "write-default-deprecated")]
55    WriteDefaultDeprecated,
56    /// `write-with-response`
57    #[serde(rename = "write-with-response")]
58    WriteWithResponse,
59    /// `write-without-response`
60    #[serde(rename = "write-without-response")]
61    WriteWithoutResponse,
62    /// A value this vendored schema does not list. Chrome adds values ahead of
63    /// the published protocol, so an unrecognised one is kept as it arrived
64    /// rather than failing the payload it came in.
65    #[serde(untagged)]
66    Unrecognized(String),
67}
68
69/// Indicates the various types of characteristic operation.
70#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
71pub enum CharacteristicOperationType {
72    /// `read`
73    #[serde(rename = "read")]
74    Read,
75    /// `write`
76    #[serde(rename = "write")]
77    Write,
78    /// `subscribe-to-notifications`
79    #[serde(rename = "subscribe-to-notifications")]
80    SubscribeToNotifications,
81    /// `unsubscribe-from-notifications`
82    #[serde(rename = "unsubscribe-from-notifications")]
83    UnsubscribeFromNotifications,
84    /// A value this vendored schema does not list. Chrome adds values ahead of
85    /// the published protocol, so an unrecognised one is kept as it arrived
86    /// rather than failing the payload it came in.
87    #[serde(untagged)]
88    Unrecognized(String),
89}
90
91/// Indicates the various types of descriptor operation.
92#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
93pub enum DescriptorOperationType {
94    /// `read`
95    #[serde(rename = "read")]
96    Read,
97    /// `write`
98    #[serde(rename = "write")]
99    Write,
100    /// A value this vendored schema does not list. Chrome adds values ahead of
101    /// the published protocol, so an unrecognised one is kept as it arrived
102    /// rather than failing the payload it came in.
103    #[serde(untagged)]
104    Unrecognized(String),
105}
106
107/// Stores the manufacturer data
108#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
109pub struct ManufacturerData {
110    /// Company identifier
111    /// <https://bitbucket.org/bluetooth-SIG/public/src/main/assigned_numbers/company_identifiers/company_identifiers.yaml>
112    /// <https://usb.org/developers>
113    pub key: i64,
114    /// Manufacturer-specific data (Encoded as a base64 string when passed over
115    /// JSON)
116    pub data: String,
117}
118
119/// Stores the byte data of the advertisement packet sent by a Bluetooth
120/// device.
121#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
122pub struct ScanRecord {
123    #[serde(default, skip_serializing_if = "Option::is_none")]
124    pub name: Option<String>,
125    #[serde(default, skip_serializing_if = "Option::is_none")]
126    pub uuids: Option<Vec<String>>,
127    /// Stores the external appearance description of the device.
128    #[serde(default, skip_serializing_if = "Option::is_none")]
129    pub appearance: Option<i64>,
130    /// Stores the transmission power of a broadcasting device.
131    #[serde(rename = "txPower", default, skip_serializing_if = "Option::is_none")]
132    pub tx_power: Option<i64>,
133    /// Key is the company identifier and the value is an array of bytes of
134    /// manufacturer specific data.
135    #[serde(
136        rename = "manufacturerData",
137        default,
138        skip_serializing_if = "Option::is_none"
139    )]
140    pub manufacturer_data: Option<Vec<ManufacturerData>>,
141}
142
143/// Stores the advertisement packet information that is sent by a Bluetooth
144/// device.
145#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
146pub struct ScanEntry {
147    #[serde(rename = "deviceAddress")]
148    pub device_address: String,
149    pub rssi: i64,
150    #[serde(rename = "scanRecord")]
151    pub scan_record: ScanRecord,
152}
153
154/// Describes the properties of a characteristic. This follows Bluetooth Core
155/// Specification BT 4.2 Vol 3 Part G 3.3.1. Characteristic Properties.
156#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
157pub struct CharacteristicProperties {
158    #[serde(default, skip_serializing_if = "Option::is_none")]
159    pub broadcast: Option<bool>,
160    #[serde(default, skip_serializing_if = "Option::is_none")]
161    pub read: Option<bool>,
162    #[serde(
163        rename = "writeWithoutResponse",
164        default,
165        skip_serializing_if = "Option::is_none"
166    )]
167    pub write_without_response: Option<bool>,
168    #[serde(default, skip_serializing_if = "Option::is_none")]
169    pub write: Option<bool>,
170    #[serde(default, skip_serializing_if = "Option::is_none")]
171    pub notify: Option<bool>,
172    #[serde(default, skip_serializing_if = "Option::is_none")]
173    pub indicate: Option<bool>,
174    #[serde(
175        rename = "authenticatedSignedWrites",
176        default,
177        skip_serializing_if = "Option::is_none"
178    )]
179    pub authenticated_signed_writes: Option<bool>,
180    #[serde(
181        rename = "extendedProperties",
182        default,
183        skip_serializing_if = "Option::is_none"
184    )]
185    pub extended_properties: Option<bool>,
186}
187
188/// Enable the BluetoothEmulation domain.
189///
190/// Parameters of `BluetoothEmulation.enable`.
191#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
192pub struct EnableParams {
193    /// State of the simulated central.
194    pub state: CentralState,
195    /// If the simulated central supports low-energy.
196    #[serde(rename = "leSupported")]
197    pub le_supported: bool,
198}
199
200impl crate::typed::Command for EnableParams {
201    const METHOD: &'static str = "BluetoothEmulation.enable";
202    type Returns = crate::typed::NoReturns;
203}
204
205/// Set the state of the simulated central.
206///
207/// Parameters of `BluetoothEmulation.setSimulatedCentralState`.
208#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
209pub struct SetSimulatedCentralStateParams {
210    /// State of the simulated central.
211    pub state: CentralState,
212}
213
214impl crate::typed::Command for SetSimulatedCentralStateParams {
215    const METHOD: &'static str = "BluetoothEmulation.setSimulatedCentralState";
216    type Returns = crate::typed::NoReturns;
217}
218
219/// Disable the BluetoothEmulation domain.
220///
221/// Parameters of `BluetoothEmulation.disable`.
222#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
223pub struct DisableParams {}
224
225impl crate::typed::Command for DisableParams {
226    const METHOD: &'static str = "BluetoothEmulation.disable";
227    type Returns = crate::typed::NoReturns;
228}
229
230/// Simulates a peripheral with |address|, |name| and |knownServiceUuids| that
231/// has already been connected to the system.
232///
233/// Parameters of `BluetoothEmulation.simulatePreconnectedPeripheral`.
234#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
235pub struct SimulatePreconnectedPeripheralParams {
236    pub address: String,
237    pub name: String,
238    #[serde(rename = "manufacturerData")]
239    pub manufacturer_data: Vec<ManufacturerData>,
240    #[serde(rename = "knownServiceUuids")]
241    pub known_service_uuids: Vec<String>,
242}
243
244impl crate::typed::Command for SimulatePreconnectedPeripheralParams {
245    const METHOD: &'static str = "BluetoothEmulation.simulatePreconnectedPeripheral";
246    type Returns = crate::typed::NoReturns;
247}
248
249/// Simulates an advertisement packet described in |entry| being received by
250/// the central.
251///
252/// Parameters of `BluetoothEmulation.simulateAdvertisement`.
253#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
254pub struct SimulateAdvertisementParams {
255    pub entry: ScanEntry,
256}
257
258impl crate::typed::Command for SimulateAdvertisementParams {
259    const METHOD: &'static str = "BluetoothEmulation.simulateAdvertisement";
260    type Returns = crate::typed::NoReturns;
261}
262
263/// Simulates the response code from the peripheral with |address| for a GATT
264/// operation of |type|. The |code| value follows the HCI Error Codes from
265/// Bluetooth Core Specification Vol 2 Part D 1.3 List Of Error Codes.
266///
267/// Parameters of `BluetoothEmulation.simulateGATTOperationResponse`.
268#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
269pub struct SimulateGattOperationResponseParams {
270    pub address: String,
271    pub r#type: GattOperationType,
272    pub code: i64,
273}
274
275impl crate::typed::Command for SimulateGattOperationResponseParams {
276    const METHOD: &'static str = "BluetoothEmulation.simulateGATTOperationResponse";
277    type Returns = crate::typed::NoReturns;
278}
279
280/// Simulates the response from the characteristic with |characteristicId| for
281/// a characteristic operation of |type|. The |code| value follows the Error
282/// Codes from Bluetooth Core Specification Vol 3 Part F 3.4.1.1 Error
283/// Response. The |data| is expected to exist when simulating a successful
284/// read operation response.
285///
286/// Parameters of `BluetoothEmulation.simulateCharacteristicOperationResponse`.
287#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
288pub struct SimulateCharacteristicOperationResponseParams {
289    #[serde(rename = "characteristicId")]
290    pub characteristic_id: String,
291    pub r#type: CharacteristicOperationType,
292    pub code: i64,
293    #[serde(default, skip_serializing_if = "Option::is_none")]
294    pub data: Option<String>,
295}
296
297impl crate::typed::Command for SimulateCharacteristicOperationResponseParams {
298    const METHOD: &'static str = "BluetoothEmulation.simulateCharacteristicOperationResponse";
299    type Returns = crate::typed::NoReturns;
300}
301
302/// Simulates the response from the descriptor with |descriptorId| for a
303/// descriptor operation of |type|. The |code| value follows the Error Codes
304/// from Bluetooth Core Specification Vol 3 Part F 3.4.1.1 Error Response. The
305/// |data| is expected to exist when simulating a successful read operation
306/// response.
307///
308/// Parameters of `BluetoothEmulation.simulateDescriptorOperationResponse`.
309#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
310pub struct SimulateDescriptorOperationResponseParams {
311    #[serde(rename = "descriptorId")]
312    pub descriptor_id: String,
313    pub r#type: DescriptorOperationType,
314    pub code: i64,
315    #[serde(default, skip_serializing_if = "Option::is_none")]
316    pub data: Option<String>,
317}
318
319impl crate::typed::Command for SimulateDescriptorOperationResponseParams {
320    const METHOD: &'static str = "BluetoothEmulation.simulateDescriptorOperationResponse";
321    type Returns = crate::typed::NoReturns;
322}
323
324/// Adds a service with |serviceUuid| to the peripheral with |address|.
325///
326/// Parameters of `BluetoothEmulation.addService`.
327#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
328pub struct AddServiceParams {
329    pub address: String,
330    #[serde(rename = "serviceUuid")]
331    pub service_uuid: String,
332}
333
334/// What `BluetoothEmulation.addService` answers with.
335#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
336pub struct AddServiceReturns {
337    /// An identifier that uniquely represents this service.
338    #[serde(rename = "serviceId")]
339    pub service_id: String,
340}
341
342impl crate::typed::Command for AddServiceParams {
343    const METHOD: &'static str = "BluetoothEmulation.addService";
344    type Returns = AddServiceReturns;
345}
346
347/// Removes the service respresented by |serviceId| from the simulated
348/// central.
349///
350/// Parameters of `BluetoothEmulation.removeService`.
351#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
352pub struct RemoveServiceParams {
353    #[serde(rename = "serviceId")]
354    pub service_id: String,
355}
356
357impl crate::typed::Command for RemoveServiceParams {
358    const METHOD: &'static str = "BluetoothEmulation.removeService";
359    type Returns = crate::typed::NoReturns;
360}
361
362/// Adds a characteristic with |characteristicUuid| and |properties| to the
363/// service represented by |serviceId|.
364///
365/// Parameters of `BluetoothEmulation.addCharacteristic`.
366#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
367pub struct AddCharacteristicParams {
368    #[serde(rename = "serviceId")]
369    pub service_id: String,
370    #[serde(rename = "characteristicUuid")]
371    pub characteristic_uuid: String,
372    pub properties: CharacteristicProperties,
373}
374
375/// What `BluetoothEmulation.addCharacteristic` answers with.
376#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
377pub struct AddCharacteristicReturns {
378    /// An identifier that uniquely represents this characteristic.
379    #[serde(rename = "characteristicId")]
380    pub characteristic_id: String,
381}
382
383impl crate::typed::Command for AddCharacteristicParams {
384    const METHOD: &'static str = "BluetoothEmulation.addCharacteristic";
385    type Returns = AddCharacteristicReturns;
386}
387
388/// Removes the characteristic respresented by |characteristicId| from the
389/// simulated central.
390///
391/// Parameters of `BluetoothEmulation.removeCharacteristic`.
392#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
393pub struct RemoveCharacteristicParams {
394    #[serde(rename = "characteristicId")]
395    pub characteristic_id: String,
396}
397
398impl crate::typed::Command for RemoveCharacteristicParams {
399    const METHOD: &'static str = "BluetoothEmulation.removeCharacteristic";
400    type Returns = crate::typed::NoReturns;
401}
402
403/// Adds a descriptor with |descriptorUuid| to the characteristic respresented
404/// by |characteristicId|.
405///
406/// Parameters of `BluetoothEmulation.addDescriptor`.
407#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
408pub struct AddDescriptorParams {
409    #[serde(rename = "characteristicId")]
410    pub characteristic_id: String,
411    #[serde(rename = "descriptorUuid")]
412    pub descriptor_uuid: String,
413}
414
415/// What `BluetoothEmulation.addDescriptor` answers with.
416#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
417pub struct AddDescriptorReturns {
418    /// An identifier that uniquely represents this descriptor.
419    #[serde(rename = "descriptorId")]
420    pub descriptor_id: String,
421}
422
423impl crate::typed::Command for AddDescriptorParams {
424    const METHOD: &'static str = "BluetoothEmulation.addDescriptor";
425    type Returns = AddDescriptorReturns;
426}
427
428/// Removes the descriptor with |descriptorId| from the simulated central.
429///
430/// Parameters of `BluetoothEmulation.removeDescriptor`.
431#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
432pub struct RemoveDescriptorParams {
433    #[serde(rename = "descriptorId")]
434    pub descriptor_id: String,
435}
436
437impl crate::typed::Command for RemoveDescriptorParams {
438    const METHOD: &'static str = "BluetoothEmulation.removeDescriptor";
439    type Returns = crate::typed::NoReturns;
440}
441
442/// Simulates a GATT disconnection from the peripheral with |address|.
443///
444/// Parameters of `BluetoothEmulation.simulateGATTDisconnection`.
445#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
446pub struct SimulateGattDisconnectionParams {
447    pub address: String,
448}
449
450impl crate::typed::Command for SimulateGattDisconnectionParams {
451    const METHOD: &'static str = "BluetoothEmulation.simulateGATTDisconnection";
452    type Returns = crate::typed::NoReturns;
453}
454
455/// Event for when a GATT operation of |type| to the peripheral with |address|
456/// happened.
457///
458/// Payload of the `BluetoothEmulation.gattOperationReceived` event.
459#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
460pub struct GattOperationReceivedEvent {
461    pub address: String,
462    pub r#type: GattOperationType,
463}
464
465impl crate::typed::Event for GattOperationReceivedEvent {
466    const METHOD: &'static str = "BluetoothEmulation.gattOperationReceived";
467}
468
469/// Event for when a characteristic operation of |type| to the characteristic
470/// respresented by |characteristicId| happened. |data| and |writeType| is
471/// expected to exist when |type| is write.
472///
473/// Payload of the `BluetoothEmulation.characteristicOperationReceived` event.
474#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
475pub struct CharacteristicOperationReceivedEvent {
476    #[serde(rename = "characteristicId")]
477    pub characteristic_id: String,
478    pub r#type: CharacteristicOperationType,
479    #[serde(default, skip_serializing_if = "Option::is_none")]
480    pub data: Option<String>,
481    #[serde(rename = "writeType", default, skip_serializing_if = "Option::is_none")]
482    pub write_type: Option<CharacteristicWriteType>,
483}
484
485impl crate::typed::Event for CharacteristicOperationReceivedEvent {
486    const METHOD: &'static str = "BluetoothEmulation.characteristicOperationReceived";
487}
488
489/// Event for when a descriptor operation of |type| to the descriptor
490/// respresented by |descriptorId| happened. |data| is expected to exist when
491/// |type| is write.
492///
493/// Payload of the `BluetoothEmulation.descriptorOperationReceived` event.
494#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
495pub struct DescriptorOperationReceivedEvent {
496    #[serde(rename = "descriptorId")]
497    pub descriptor_id: String,
498    pub r#type: DescriptorOperationType,
499    #[serde(default, skip_serializing_if = "Option::is_none")]
500    pub data: Option<String>,
501}
502
503impl crate::typed::Event for DescriptorOperationReceivedEvent {
504    const METHOD: &'static str = "BluetoothEmulation.descriptorOperationReceived";
505}