1// Copyright 2016 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Next MinVersion: 17
6
7module arc.mojom;
8
9import "mojo/public/mojom/base/values.mojom";
10
11[Extensible]
12enum BluetoothAdapterState {
13  OFF = 0,
14  ON
15};
16
17[Extensible]
18enum BluetoothDiscoveryState {
19  STOPPED,
20  STARTED
21};
22
23[Extensible]
24enum BluetoothAclState {
25  CONNECTED,
26  DISCONNECTED
27};
28
29[Extensible]
30enum BluetoothStatus {
31  SUCCESS = 0,
32  FAIL,
33  NOT_READY,
34  NOMEM,
35  BUSY,
36  DONE,
37  UNSUPPORTED,
38  PARM_INVALID,
39  UNHANDLED,
40  AUTH_FAILURE,
41  RMT_DEV_DOWN,
42  AUTH_REJECTED
43};
44
45struct BluetoothAddress {
46  array<uint8, 6> address;
47};
48
49struct BluetoothUUID {
50  array<uint8, 16> uuid;
51};
52
53struct BluetoothServiceRecord {
54  BluetoothUUID uuid;
55  uint16 channel;
56  string name;
57};
58
59struct BluetoothLocalLEFeatures {
60  uint16 version_supported;
61  uint8 local_privacy_enabled;
62  uint8 max_adv_instance;
63  uint8 rpa_offload_supported;
64  uint8 max_irk_list_size;
65  uint8 max_adv_filter_supported;
66  uint8 activity_energy_info_supported;
67  uint16 scan_result_storage_size;
68  uint16 total_trackable_advertisers;
69  bool extended_scan_support;
70  bool debug_logging_supported;
71};
72
73[Extensible]
74enum BluetoothPropertyType {
75  ALL = 0,
76  BDNAME = 1,
77  BDADDR,
78  UUIDS,
79  CLASS_OF_DEVICE,
80  TYPE_OF_DEVICE,
81  SERVICE_RECORD,
82  ADAPTER_SCAN_MODE,
83  ADAPTER_BONDED_DEVICES,
84  ADAPTER_DISCOVERY_TIMEOUT,
85  REMOTE_FRIENDLY_NAME,
86  REMOTE_RSSI,
87  REMOTE_VERSION_INFO,
88  LOCAL_LE_FEATURES,
89  REMOTE_DEVICE_TIMESTAMP = 0xFF,
90};
91
92[Extensible]
93enum BluetoothScanMode {
94  NONE = 0x0,
95  CONNECTABLE,
96  CONNECTABLE_DISCOVERABLE
97};
98
99[Extensible]
100enum BluetoothDeviceType {
101  BREDR = 0x1,
102  BLE,
103  DUAL
104};
105
106[Extensible]
107enum BluetoothBondState {
108  NONE = 0,
109  BONDING,
110  BONDED
111};
112
113struct BluetoothRemoteVersion {
114  int32 version;
115  int32 sub_ver;
116  int32 manufacturer;
117};
118
119union BluetoothProperty {
120  string bdname;
121  BluetoothAddress bdaddr;
122  array<BluetoothUUID> uuids;
123  uint32 device_class;
124  BluetoothDeviceType device_type;
125  BluetoothServiceRecord service_record;
126  BluetoothScanMode adapter_scan_mode;
127  array<BluetoothAddress> bonded_devices;
128  uint32 discovery_timeout;
129  string remote_friendly_name;
130  int32 remote_rssi;
131  BluetoothRemoteVersion remote_version;
132  BluetoothLocalLEFeatures local_le_features;
133};
134
135// Bluetooth GATT types
136// Copy from Android API
137// https://developer.android.com/reference/android/bluetooth/BluetoothGatt.html
138[Extensible]
139enum BluetoothGattStatus {
140  GATT_SUCCESS = 0,
141  GATT_READ_NOT_PERMITTED = 0x2,
142  GATT_WRITE_NOT_PERMITTED = 0x3,
143  GATT_INSUFFICIENT_AUTHENTICATION = 0x5,
144  GATT_REQUEST_NOT_SUPPORTED = 0x6,
145  GATT_INVALID_OFFSET = 0x7,
146  GATT_INVALID_ATTRIBUTE_LENGTH = 0xd,
147  GATT_INSUFFICIENT_ENCRYPTION = 0xf,
148  GATT_CONNECTION_CONGESTED = 0x8f,
149  GATT_FAILURE = 0x101,
150};
151
152// Copy from Android API
153// https://source.android.com/devices/halref/structbtgatt__gatt__id__t.html
154struct BluetoothGattID {
155  BluetoothUUID uuid;
156  uint8 inst_id;
157};
158
159// Copy from Android API
160// is_primary is not a boolean because Android defines it as uint8_t.
161// https://source.android.com/devices/halref/structbtgatt__srvc__id__t.html
162struct BluetoothGattServiceID {
163  BluetoothGattID id;
164  uint8 is_primary;
165};
166
167struct BluetoothGattValue {
168  BluetoothGattStatus status;
169  array<uint8> value;
170};
171
172const int8 kUnknownPower = 127;
173
174// Copied from Android Bluetooth package. See AdvertiseManager$AdvertiseNative
175// http://goo.gl/UnKC5N
176enum BluetoothAdvertisementType {
177  ADV_TYPE_CONNECTABLE = 0,
178  ADV_TYPE_SCANNABLE = 2,
179  ADV_TYPE_NON_CONNECTABLE = 3,
180};
181
182// Copy from Bluetooth Assigned Numbers Document, Generic Access Profile
183// https://www.bluetooth.com/specifications/assigned-numbers/generic-access-profile
184[Extensible]
185enum BluetoothAdvertisingDataType {
186  DATA_TYPE_FLAGS = 0x01,
187  DATA_TYPE_SERVICE_UUIDS_16_BIT_COMPLETE = 0x03,
188  DATA_TYPE_SERVICE_UUIDS_128_BIT_COMPLETE = 0x07,
189  DATA_TYPE_LOCAL_NAME_COMPLETE = 0x09,
190  DATA_TYPE_TX_POWER_LEVEL = 0x0A,
191  DATA_TYPE_SERVICE_DATA = 0x16,
192  DATA_TYPE_MANUFACTURER_SPECIFIC_DATA = 0xff,
193};
194
195// Copy from Bluetooth Core v4.2 Volume 3 Part C Chapter 11
196// and Bluetooth Core Specification Supplement v6 Part A Chapter 1
197// https://www.bluetooth.com/specifications/adopted-specifications
198union BluetoothAdvertisingData {
199  uint8 flags;
200  array<uint16> service_uuids_16;
201  array<BluetoothUUID> service_uuids;
202  string local_name;
203  uint8 tx_power_level;
204  BluetoothServiceData service_data;
205  array<uint8> manufacturer_data;
206  array<uint8> other_data;
207};
208
209struct BluetoothServiceData {
210  uint16 uuid_16bit;
211  array<uint8> data;
212};
213
214struct BluetoothAdvertisement {
215  BluetoothAdvertisementType type;
216  bool include_tx_power;
217  array<BluetoothAdvertisingData> data;
218  // Add more here as Chrome supports it.
219};
220
221[Extensible]
222enum BluetoothGattDBAttributeType {
223  BTGATT_DB_PRIMARY_SERVICE = 0,
224  BTGATT_DB_SECONDARY_SERVICE,
225  BTGATT_DB_INCLUDED_SERVICE,
226  BTGATT_DB_CHARACTERISTIC,
227  BTGATT_DB_DESCRIPTOR,
228};
229
230struct BluetoothGattDBElement {
231  uint8 id;
232  BluetoothUUID uuid;
233  BluetoothGattDBAttributeType type;
234  uint16 attribute_handle;
235
236  /*
237   * If |type| is |BTGATT_DB_PRIMARY_SERVICE|, or
238   * |BTGATT_DB_SECONDARY_SERVICE|, this contains the start and end attribute
239   * handles.
240   */
241  uint16 start_handle;
242  uint16 end_handle;
243
244  /*
245   * If |type| is |BTGATT_DB_CHARACTERISTIC|, this contains the properties of
246   * the characteristic.
247   */
248  uint8 properties;
249};
250
251// Bluetooth SDP types
252[Extensible]
253enum BluetoothSdpAttributeType {
254  NULLTYPE = 0,
255  UINT,
256  INT,
257  UUID,
258  STRING,
259  BOOL,
260  SEQUENCE,
261  URL,
262};
263
264/*
265 * A BluetoothSdpAttribute contains either a value or a sequence, where a
266 * sequence is an array of BluetoothSdpAttribute. A multi-layered attribute
267 * design is intended. Note BluetoothSdpAttribute supports up to depth 32 for
268 * the attribute with multi-layer sequences. The attributes within a sequence
269 * which has the depth beyond the maximum supported depth will be invalidated
270 * and ignored.
271 */
272struct BluetoothSdpAttribute {
273  BluetoothSdpAttributeType type;
274  uint32 type_size;
275  array<BluetoothSdpAttribute> sequence;
276  string? deprecated_json_value@3;
277  [MinVersion=14] mojo_base.mojom.Value? value;
278};
279
280struct BluetoothSdpRecord {
281  map<uint16, BluetoothSdpAttribute> attrs;
282};
283
284struct BluetoothCreateSdpRecordResult {
285  BluetoothStatus status;
286  uint32 service_handle;
287};
288
289// BluetoothRfcommConnection contains the information for a new RFCOMM
290// connection. Since we cannot get socket (or peer) name on the transferred
291// socket on Android side, we also need to pass the peer address and channel
292// number.
293struct BluetoothRfcommConnection {
294  handle sock;
295  BluetoothAddress addr;
296  int32 channel;
297};
298
299// The mojo connection represents a listening socket.
300// Next Method ID: 1
301interface RfcommListeningSocketClient {
302  // Called when accept() succeeds. |channel| in |connection| is the peer
303  // channel number.
304  OnAccepted@0(BluetoothRfcommConnection connection);
305};
306
307// The mojo connection represents a connecting (not connected yet) socket.
308// After connect() either succeeds or fails, Android is responsible for closing
309// this mojo connection.
310// Next Method ID: 2
311interface RfcommConnectingSocketClient {
312  // Called when connect() succeeds. |channel| in |connection| is the channel
313  // number on our side.
314  OnConnected@0(BluetoothRfcommConnection connection);
315  // Called when connect() fails.
316  OnConnectFailed@1();
317};
318
319// Next Method ID: 47
320// Deprecated Method ID: 4, 5, 6, 7, 20, 21
321interface BluetoothHost {
322  EnableAdapter@0() => (BluetoothAdapterState state);
323  DisableAdapter@1() => (BluetoothAdapterState state);
324  GetAdapterProperty@2(BluetoothPropertyType type);
325  SetAdapterProperty@3(BluetoothProperty property);
326  StartDiscovery@8();
327  CancelDiscovery@9();
328  CreateBond@10(BluetoothAddress addr, int32 transport);
329  RemoveBond@11(BluetoothAddress addr);
330  CancelBond@12(BluetoothAddress addr);
331
332  GetConnectionState@13(BluetoothAddress addr) => (bool connected);
333
334  // Bluetooth Gatt Client functions
335  [MinVersion=1] StartLEScan@14();
336  [MinVersion=1] StopLEScan@15();
337  [MinVersion=1] ConnectLEDevice@16(BluetoothAddress remote_addr);
338  [MinVersion=1] DisconnectLEDevice@17(BluetoothAddress remote_addr);
339  [MinVersion=1] SearchService@18(BluetoothAddress remote_addr);
340  [MinVersion=1] GetGattDB@19(BluetoothAddress remote_addr);
341  [MinVersion=1] ReadGattCharacteristic@22(BluetoothAddress remote_addr,
342                                           BluetoothGattServiceID service_id,
343                                           BluetoothGattID char_id)
344      => (BluetoothGattValue value);
345  [MinVersion=1] WriteGattCharacteristic@23(BluetoothAddress remote_addr,
346                                            BluetoothGattServiceID service_id,
347                                            BluetoothGattID char_id,
348                                            BluetoothGattValue value,
349                                            [MinVersion=11] bool prepare)
350      => (BluetoothGattStatus status);
351  [MinVersion=1] ReadGattDescriptor@24(BluetoothAddress remote_addr,
352                                       BluetoothGattServiceID service_id,
353                                       BluetoothGattID char_id,
354                                       BluetoothGattID desc_id)
355      => (BluetoothGattValue value);
356  [MinVersion=1] WriteGattDescriptor@25(BluetoothAddress remote_addr,
357                                        BluetoothGattServiceID service_id,
358                                        BluetoothGattID char_id,
359                                        BluetoothGattID desc_id,
360                                        BluetoothGattValue value)
361      => (BluetoothGattStatus status);
362  [MinVersion=11] ExecuteWrite@44(BluetoothAddress remote_addr,
363                                  bool execute)
364      => (BluetoothGattStatus status);
365  [MinVersion=1] RegisterForGattNotification@26(
366      BluetoothAddress remote_addr,
367      BluetoothGattServiceID service_id,
368      BluetoothGattID char_id)
369      => (BluetoothGattStatus status);
370  [MinVersion=1] DeregisterForGattNotification@27(
371      BluetoothAddress remote_addr,
372      BluetoothGattServiceID service_id,
373      BluetoothGattID char_id)
374      => (BluetoothGattStatus status);
375  [MinVersion=1] ReadRemoteRssi@28(BluetoothAddress remote_addr)
376      => (int32 rssi);
377
378  [MinVersion=2] OpenBluetoothSocket@29()
379      => (handle sock);
380
381  // Bluetooth Gatt Server functions
382  // Copied from Android API
383  // https://source.android.com/devices/halref/bt__gatt__server_8h.html
384  [MinVersion=3] AddService@30(BluetoothGattServiceID service_id,
385                               int32 num_handles)
386      => (int32 service_handle);
387  [MinVersion=3] AddCharacteristic@31(int32 service_handle,
388                                      BluetoothUUID uuid,
389                                      int32 properties,
390                                      int32 permissions)
391      => (int32 characteristic_handle);
392  [MinVersion=3] AddDescriptor@32(int32 service_handle,
393                                  BluetoothUUID uuid,
394                                  int32 permissions)
395      => (int32 descriptor_handle);
396  [MinVersion=3] StartService@33(int32 service_handle)
397      => (BluetoothGattStatus status);
398  [MinVersion=3] StopService@34(int32 service_handle)
399      => (BluetoothGattStatus status);
400  [MinVersion=3] DeleteService@35(int32 service_handle)
401      => (BluetoothGattStatus status);
402  [MinVersion=3] SendIndication@36(int32 attribute_handle,
403                                   BluetoothAddress address,
404                                   bool confirm,
405                                   array<uint8> value)
406      => (BluetoothGattStatus status);
407
408  // Bluetooth SDP functions
409  [MinVersion=5] GetSdpRecords@37(BluetoothAddress remote_addr,
410                                  BluetoothUUID target_uuid);
411  [MinVersion=5] CreateSdpRecord@38(BluetoothSdpRecord record)
412      => (BluetoothCreateSdpRecordResult result);
413  [MinVersion=5] RemoveSdpRecord@39(uint32 service_handle)
414      => (BluetoothStatus status);
415
416  // Multi-advertisement functions
417  [MinVersion=6] ReserveAdvertisementHandle@40()
418      => (BluetoothGattStatus status, int32 adv_handle);
419  [MinVersion=6] EnableAdvertisement@41(int32 adv_handle,
420                                        BluetoothAdvertisement adv)
421      => (BluetoothGattStatus status);
422  [MinVersion=6] ReleaseAdvertisementHandle@42(int32 adv_handle)
423      => (BluetoothGattStatus status);
424  [MinVersion=8] DisableAdvertisement@43(int32 adv_handle)
425      => (BluetoothGattStatus status);
426
427  // RFCOMM functions
428  // Opens a bluetooth socket with socket option |optval|, and then bind() and
429  // listen() with the requested RFCOMM |channel| number. When |channel| = 0,
430  // we will select a channel number automatically.  If this process succeeds,
431  // returns SUCCESS in |status|, the actual listening channel in |channel|,
432  // and a new mojo connection which represents the listening socket.
433  [MinVersion=15] RfcommListen@45(int32 channel, int32 optval)
434      => (BluetoothStatus status, int32 channel,
435          RfcommListeningSocketClient&? client);
436  // Opens a bluetooth socket with socket option |optval|, and then connect()
437  // to (|remote_addr|, |channel|). If this process succeeds, returns SUCCESS
438  // in |status| and a new mojo connection which holds the connecting socket.
439  // Unlike in RfcommListen(), |channel| here could not be 0, since this is the
440  // peer channel number.
441  [MinVersion=15] RfcommConnect@46(BluetoothAddress remote_addr,
442                                   int32 channel, int32 optval)
443      => (BluetoothStatus status, RfcommConnectingSocketClient&? client);
444};
445
446// Next Method ID: 23
447// Deprecated Method ID: 2, 6, 11, 12
448interface BluetoothInstance {
449  // DEPRECATED: Please use Init@18 instead.
450  InitDeprecated@0(BluetoothHost host_ptr);
451
452  // Establishes full-duplex communication with the host.
453  [MinVersion=7] Init@18(BluetoothHost host_ptr) => ();
454
455  OnAdapterProperties@1(BluetoothStatus status,
456                        array<BluetoothProperty> properties);
457  OnDeviceFound@3(array<BluetoothProperty> properties);
458  [MinVersion=16] OnDevicePropertiesChanged@22(
459      BluetoothAddress remote_addr, array<BluetoothProperty> properties);
460  OnDiscoveryStateChanged@4(BluetoothDiscoveryState state);
461  OnBondStateChanged@5(BluetoothStatus status,
462                       BluetoothAddress remote_addr,
463                       BluetoothBondState state);
464
465  // Bluetooth Gatt Client callbacks
466  // TODO(b/111367421): Remove this when no active device running Android N.
467  [MinVersion=1] OnLEDeviceFoundForN@7(
468      BluetoothAddress addr,
469      int32 rssi,
470      array<BluetoothAdvertisingData> adv_data);
471  [MinVersion=13] OnLEDeviceFound@21(BluetoothAddress addr,
472                                     int32 rssi,
473                                     array<uint8> eir);
474  [MinVersion=1] OnLEConnectionStateChange@8(BluetoothAddress remote_addr,
475                                             bool connected);
476  [MinVersion=4] OnLEDeviceAddressChange@16(BluetoothAddress old_addr,
477                                            BluetoothAddress new_addr);
478  [MinVersion=1] OnSearchComplete@9(BluetoothAddress remote_addr,
479                                    BluetoothGattStatus status);
480  [MinVersion=1] OnGetGattDB@10(BluetoothAddress remote_addr,
481                                array<BluetoothGattDBElement> db);
482  [MinVersion=2] OnGattNotify@13(BluetoothAddress remote_addr,
483                                 BluetoothGattServiceID service_id,
484                                 BluetoothGattID char_id,
485                                 bool is_notify,
486                                 array<uint8> value);
487
488  // Bluetooth Gatt Server functions
489  [MinVersion=3] RequestGattRead@14(
490      BluetoothAddress address,
491      int32 attribute_handle,
492      int32 offset,
493      bool is_long,
494      [MinVersion=9] BluetoothGattDBAttributeType attribute_type)
495      => (BluetoothGattStatus status, array<uint8> value);
496  [MinVersion=3] RequestGattWrite@15(
497      BluetoothAddress address,
498      int32 attribute_handle,
499      int32 offset,
500      array<uint8> value,
501      [MinVersion=9] BluetoothGattDBAttributeType attribute_type,
502      [MinVersion=12] bool is_prepare)
503      => (BluetoothGattStatus status);
504  [MinVersion=12] RequestGattExecuteWrite@20(
505      BluetoothAddress address,
506      bool execute)
507      => (BluetoothGattStatus status);
508  [MinVersion=10] OnMTUReceived@19(BluetoothAddress remote_addr, uint16 mtu);
509
510  // Bluetooth SDP function
511  [MinVersion=5] OnGetSdpRecords@17(BluetoothStatus status,
512                                    BluetoothAddress remote_addr,
513                                    BluetoothUUID target_uuid,
514                                    array<BluetoothSdpRecord> records);
515};
516