summaryrefslogtreecommitdiff
path: root/chromium/components/arc/common/bluetooth.mojom
blob: f22585f8ec11c43bbd57bb738d574449c3d87131 (plain)
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Next MinVersion: 8

module arc.mojom;

[Extensible]
enum BluetoothAdapterState {
  OFF = 0,
  ON
};

[Extensible]
enum BluetoothDiscoveryState {
  STOPPED,
  STARTED
};

[Extensible]
enum BluetoothAclState {
  CONNECTED,
  DISCONNECTED
};

[Extensible]
enum BluetoothStatus {
  SUCCESS = 0,
  FAIL,
  NOT_READY,
  NOMEM,
  BUSY,
  DONE,
  UNSUPPORTED,
  PARM_INVALID,
  UNHANDLED,
  AUTH_FAILURE,
  RMT_DEV_DOWN,
  AUTH_REJECTED
};

struct BluetoothAddress {
  array<uint8, 6> address;
};

struct BluetoothUUID {
  array<uint8, 16> uuid;
};

struct BluetoothServiceRecord {
  BluetoothUUID uuid;
  uint16 channel;
  string name;
};

struct BluetoothLocalLEFeatures {
  uint16 version_supported;
  uint8 local_privacy_enabled;
  uint8 max_adv_instance;
  uint8 rpa_offload_supported;
  uint8 max_irk_list_size;
  uint8 max_adv_filter_supported;
  uint8 activity_energy_info_supported;
  uint16 scan_result_storage_size;
  uint16 total_trackable_advertisers;
  bool extended_scan_support;
  bool debug_logging_supported;
};

[Extensible]
enum BluetoothPropertyType {
  ALL = 0,
  BDNAME = 1,
  BDADDR,
  UUIDS,
  CLASS_OF_DEVICE,
  TYPE_OF_DEVICE,
  SERVICE_RECORD,
  ADAPTER_SCAN_MODE,
  ADAPTER_BONDED_DEVICES,
  ADAPTER_DISCOVERY_TIMEOUT,
  REMOTE_FRIENDLY_NAME,
  REMOTE_RSSI,
  REMOTE_VERSION_INFO,
  LOCAL_LE_FEATURES,
  REMOTE_DEVICE_TIMESTAMP = 0xFF,
};

[Extensible]
enum BluetoothScanMode {
  NONE = 0x0,
  CONNECTABLE,
  CONNECTABLE_DISCOVERABLE
};

[Extensible]
enum BluetoothDeviceType {
  BREDR = 0x1,
  BLE,
  DUAL
};

[Extensible]
enum BluetoothBondState {
  NONE = 0,
  BONDING,
  BONDED
};

struct BluetoothRemoteVersion {
  int32 version;
  int32 sub_ver;
  int32 manufacturer;
};

union BluetoothProperty {
  string bdname;
  BluetoothAddress bdaddr;
  array<BluetoothUUID> uuids;
  uint32 device_class;
  BluetoothDeviceType device_type;
  BluetoothServiceRecord service_record;
  BluetoothScanMode adapter_scan_mode;
  array<BluetoothAddress> bonded_devices;
  uint32 discovery_timeout;
  string remote_friendly_name;
  int32 remote_rssi;
  BluetoothRemoteVersion remote_version;
  BluetoothLocalLEFeatures local_le_features;
};

// Bluetooth GATT types
// Copy from Android API
// https://developer.android.com/reference/android/bluetooth/BluetoothGatt.html
[Extensible]
enum BluetoothGattStatus {
  GATT_SUCCESS = 0,
  GATT_READ_NOT_PERMITTED = 0x2,
  GATT_WRITE_NOT_PERMITTED = 0x3,
  GATT_INSUFFICIENT_AUTHENTICATION = 0x5,
  GATT_REQUEST_NOT_SUPPORTED = 0x6,
  GATT_INVALID_OFFSET = 0x7,
  GATT_INVALID_ATTRIBUTE_LENGTH = 0xd,
  GATT_INSUFFICIENT_ENCRYPTION = 0xf,
  GATT_CONNECTION_CONGESTED = 0x8f,
  GATT_FAILURE = 0x101,
};

// Copy from Android API
// https://source.android.com/devices/halref/structbtgatt__gatt__id__t.html
struct BluetoothGattID {
  BluetoothUUID uuid;
  uint8 inst_id;
};

// Copy from Android API
// is_primary is not a boolean because Android defines it as uint8_t.
// https://source.android.com/devices/halref/structbtgatt__srvc__id__t.html
struct BluetoothGattServiceID {
  BluetoothGattID id;
  uint8 is_primary;
};

struct BluetoothGattValue {
  BluetoothGattStatus status;
  array<uint8> value;
};

const int8 kUnknownPower = 127;

// Copied from Android Bluetooth package. See AdvertiseManager$AdvertiseNative
// http://goo.gl/UnKC5N
enum BluetoothAdvertisementType {
  ADV_TYPE_CONNECTABLE = 0,
  ADV_TYPE_SCANNABLE = 2,
  ADV_TYPE_NON_CONNECTABLE = 3,
};

// Copy from Bluetooth Assigned Numbers Document, Generic Access Profile
// https://www.bluetooth.com/specifications/assigned-numbers/generic-access-profile
[Extensible]
enum BluetoothAdvertisingDataType {
  DATA_TYPE_FLAGS = 0x01,
  DATA_TYPE_SERVICE_UUIDS_16_BIT_COMPLETE = 0x03,
  DATA_TYPE_SERVICE_UUIDS_128_BIT_COMPLETE = 0x07,
  DATA_TYPE_LOCAL_NAME_COMPLETE = 0x09,
  DATA_TYPE_TX_POWER_LEVEL = 0x0A,
  DATA_TYPE_SERVICE_DATA = 0x16,
  DATA_TYPE_MANUFACTURER_SPECIFIC_DATA = 0xff,
};

// Copy from Bluetooth Core v4.2 Volume 3 Part C Chapter 11
// and Bluetooth Core Specification Supplement v6 Part A Chapter 1
// https://www.bluetooth.com/specifications/adopted-specifications
union BluetoothAdvertisingData {
  uint8 flags;
  array<uint16> service_uuids_16;
  array<BluetoothUUID> service_uuids;
  string local_name;
  uint8 tx_power_level;
  BluetoothServiceData service_data;
  array<uint8> manufacturer_data;
  array<uint8> other_data;
};

struct BluetoothServiceData {
  uint16 uuid_16bit;
  array<uint8> data;
};

struct BluetoothAdvertisement {
  BluetoothAdvertisementType type;
  bool include_tx_power;
  array<BluetoothAdvertisingData> data;
  // Add more here as Chrome supports it.
};

[Extensible]
enum BluetoothGattDBAttributeType {
  BTGATT_DB_PRIMARY_SERVICE = 0,
  BTGATT_DB_SECONDARY_SERVICE,
  BTGATT_DB_INCLUDED_SERVICE,
  BTGATT_DB_CHARACTERISTIC,
  BTGATT_DB_DESCRIPTOR,
};

struct BluetoothGattDBElement {
  uint8 id;
  BluetoothUUID uuid;
  BluetoothGattDBAttributeType type;
  uint16 attribute_handle;

  /*
   * If |type| is |BTGATT_DB_PRIMARY_SERVICE|, or
   * |BTGATT_DB_SECONDARY_SERVICE|, this contains the start and end attribute
   * handles.
   */
  uint16 start_handle;
  uint16 end_handle;

  /*
   * If |type| is |BTGATT_DB_CHARACTERISTIC|, this contains the properties of
   * the characteristic.
   */
  uint8 properties;
};

// Bluetooth SDP types
[Extensible]
enum BluetoothSdpAttributeType {
  NULLTYPE = 0,
  UINT,
  INT,
  UUID,
  STRING,
  BOOL,
  SEQUENCE,
  URL,
};

/*
 * A BluetoothSdpAttribute contains either a value or a sequence, where a
 * sequence is an array of BluetoothSdpAttribute. A multi-layered attribute
 * design is intended. Note BluetoothSdpAttribute supports up to depth 32 for
 * the attribute with multi-layer sequences. The attributes within a sequence
 * which has the depth beyond the maximum supported depth will be invalidated
 * and ignored.
 */
struct BluetoothSdpAttribute {
  BluetoothSdpAttributeType type;
  uint32 type_size;
  array<BluetoothSdpAttribute> sequence;

  // Holds the stringified JSON value of this attribute.
  // If the type is NULLTYPE or SEQUENCE, this is empty.
  // Explicitly specify the ordinal @3, because introducing this is a breaking
  // change. This field is introduced between version 7 and 8, though
  // MinVersion is not annotated because of breaking change, too.
  // See details in the bug linked below.
  // TODO(crbug.com/767313): Use mojo/common/values.mojom, when new libmojo
  // (440057 or later) is rolled to ARC repository.
  string? json_value@3;
};

struct BluetoothSdpRecord {
  map<uint16, BluetoothSdpAttribute> attrs;
};

struct BluetoothCreateSdpRecordResult {
  BluetoothStatus status;
  uint32 service_handle;
};

// Next Method ID: 43
interface BluetoothHost {
  EnableAdapter@0() => (BluetoothAdapterState state);
  DisableAdapter@1() => (BluetoothAdapterState state);
  GetAdapterProperty@2(BluetoothPropertyType type);
  SetAdapterProperty@3(BluetoothProperty property);
  GetRemoteDeviceProperty@4(BluetoothAddress remote_addr,
                            BluetoothPropertyType type);
  SetRemoteDeviceProperty@5(BluetoothAddress remote_addr,
                            BluetoothProperty property);
  GetRemoteServiceRecord@6(BluetoothAddress remote_addr,
                           BluetoothUUID uuid);
  GetRemoteServices@7(BluetoothAddress remote_addr);
  StartDiscovery@8();
  CancelDiscovery@9();
  CreateBond@10(BluetoothAddress addr, int32 transport);
  RemoveBond@11(BluetoothAddress addr);
  CancelBond@12(BluetoothAddress addr);

  GetConnectionState@13(BluetoothAddress addr) => (bool connected);

  // Bluetooth Gatt Client functions
  [MinVersion=1] StartLEScan@14();
  [MinVersion=1] StopLEScan@15();
  [MinVersion=1] ConnectLEDevice@16(BluetoothAddress remote_addr);
  [MinVersion=1] DisconnectLEDevice@17(BluetoothAddress remote_addr);
  [MinVersion=1] SearchService@18(BluetoothAddress remote_addr);
  [MinVersion=1] GetGattDB@19(BluetoothAddress remote_addr);
  [MinVersion=1] StartLEListen@20() => (BluetoothGattStatus status);
  [MinVersion=1] StopLEListen@21() => (BluetoothGattStatus status);
  [MinVersion=1] ReadGattCharacteristic@22(BluetoothAddress remote_addr,
                                           BluetoothGattServiceID service_id,
                                           BluetoothGattID char_id)
      => (BluetoothGattValue value);
  [MinVersion=1] WriteGattCharacteristic@23(BluetoothAddress remote_addr,
                                            BluetoothGattServiceID service_id,
                                            BluetoothGattID char_id,
                                            BluetoothGattValue value)
      => (BluetoothGattStatus status);
  [MinVersion=1] ReadGattDescriptor@24(BluetoothAddress remote_addr,
                                       BluetoothGattServiceID service_id,
                                       BluetoothGattID char_id,
                                       BluetoothGattID desc_id)
      => (BluetoothGattValue value);
  [MinVersion=1] WriteGattDescriptor@25(BluetoothAddress remote_addr,
                                        BluetoothGattServiceID service_id,
                                        BluetoothGattID char_id,
                                        BluetoothGattID desc_id,
                                        BluetoothGattValue value)
      => (BluetoothGattStatus status);
  [MinVersion=1] RegisterForGattNotification@26(
      BluetoothAddress remote_addr,
      BluetoothGattServiceID service_id,
      BluetoothGattID char_id)
      => (BluetoothGattStatus status);
  [MinVersion=1] DeregisterForGattNotification@27(
      BluetoothAddress remote_addr,
      BluetoothGattServiceID service_id,
      BluetoothGattID char_id)
      => (BluetoothGattStatus status);
  [MinVersion=1] ReadRemoteRssi@28(BluetoothAddress remote_addr)
      => (int32 rssi);

  [MinVersion=2] OpenBluetoothSocket@29()
      => (handle sock);

  // Bluetooth Gatt Server functions
  // Copied from Android API
  // https://source.android.com/devices/halref/bt__gatt__server_8h.html
  [MinVersion=3] AddService@30(BluetoothGattServiceID service_id,
                               int32 num_handles)
      => (int32 service_handle);
  [MinVersion=3] AddCharacteristic@31(int32 service_handle,
                                      BluetoothUUID uuid,
                                      int32 properties,
                                      int32 permissions)
      => (int32 characteristic_handle);
  [MinVersion=3] AddDescriptor@32(int32 service_handle,
                                  BluetoothUUID uuid,
                                  int32 permissions)
      => (int32 descriptor_handle);
  [MinVersion=3] StartService@33(int32 service_handle)
      => (BluetoothGattStatus status);
  [MinVersion=3] StopService@34(int32 service_handle)
      => (BluetoothGattStatus status);
  [MinVersion=3] DeleteService@35(int32 service_handle)
      => (BluetoothGattStatus status);
  [MinVersion=3] SendIndication@36(int32 attribute_handle,
                                   BluetoothAddress address,
                                   bool confirm,
                                   array<uint8> value)
      => (BluetoothGattStatus status);

  // Bluetooth SDP functions
  [MinVersion=5] GetSdpRecords@37(BluetoothAddress remote_addr,
                                  BluetoothUUID target_uuid);
  [MinVersion=5] CreateSdpRecord@38(BluetoothSdpRecord record)
      => (BluetoothCreateSdpRecordResult result);
  [MinVersion=5] RemoveSdpRecord@39(uint32 service_handle)
      => (BluetoothStatus status);

  // Multi-advertisement functions
  [MinVersion=6] ReserveAdvertisementHandle@40()
      => (BluetoothGattStatus status, int32 adv_handle);
  [MinVersion=6] BroadcastAdvertisement@41(int32 adv_handle,
                                           BluetoothAdvertisement adv)
      => (BluetoothGattStatus status);
  [MinVersion=6] ReleaseAdvertisementHandle@42(int32 adv_handle)
      => (BluetoothGattStatus status);
};

// Next Method ID: 19
interface BluetoothInstance {
  // DEPRECATED: Please use Init@18 instead.
  InitDeprecated@0(BluetoothHost host_ptr);

  // Establishes full-duplex communication with the host.
  [MinVersion=7] Init@18(BluetoothHost host_ptr) => ();

  OnAdapterProperties@1(BluetoothStatus status,
                        array<BluetoothProperty> properties);
  OnRemoteDeviceProperties@2(BluetoothStatus status,
                             BluetoothAddress address,
                             array<BluetoothProperty> properties);
  OnDeviceFound@3(array<BluetoothProperty> properties);
  OnDiscoveryStateChanged@4(BluetoothDiscoveryState state);
  OnBondStateChanged@5(BluetoothStatus status,
                       BluetoothAddress remote_addr,
                       BluetoothBondState state);
  OnAclStateChanged@6(BluetoothStatus status,
                      BluetoothAddress remote_addr,
                      BluetoothAclState state);

  // Bluetooth Gatt Client callbacks
  [MinVersion=1] OnLEDeviceFound@7(BluetoothAddress addr,
                                   int32 rssi,
                                   array<BluetoothAdvertisingData> adv_data);
  [MinVersion=1] OnLEConnectionStateChange@8(BluetoothAddress remote_addr,
                                             bool connected);
  [MinVersion=4] OnLEDeviceAddressChange@16(BluetoothAddress old_addr,
                                            BluetoothAddress new_addr);
  [MinVersion=1] OnSearchComplete@9(BluetoothAddress remote_addr,
                                    BluetoothGattStatus status);
  [MinVersion=1] OnGetGattDB@10(BluetoothAddress remote_addr,
                                array<BluetoothGattDBElement> db);
  [MinVersion=1] OnServicesRemoved@11(BluetoothAddress remote_addr,
                                      uint16 start_handle,
                                      uint16 end_handle);
  [MinVersion=1] OnServicesAdded@12(BluetoothAddress remote_addr,
                                    array<BluetoothGattDBElement> db);
  [MinVersion=2] OnGattNotify@13(BluetoothAddress remote_addr,
                                 BluetoothGattServiceID service_id,
                                 BluetoothGattID char_id,
                                 bool is_notify,
                                 array<uint8> value);

  // Bluetooth Gatt Server functions
  [MinVersion=3] RequestGattRead@14(BluetoothAddress address,
                                    int32 attribute_handle,
                                    int32 offset,
                                    bool is_long)
      => (BluetoothGattStatus status, array<uint8> value);
  [MinVersion=3] RequestGattWrite@15(BluetoothAddress address,
                                     int32 attribute_handle,
                                     int32 offset,
                                     array<uint8> value)
      => (BluetoothGattStatus status);

  // Bluetooth SDP function
  [MinVersion=5] OnGetSdpRecords@17(BluetoothStatus status,
                                    BluetoothAddress remove_addr,
                                    BluetoothUUID target_uuid,
                                    array<BluetoothSdpRecord> records);
};