1 // Copyright 2014 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.
5 // Messages for Web Bluetooth API.
6 // Multiply-included message file, hence no include guard.
8 // Web Bluetooth Security
9 // The security mechanisms of Bluetooth are described in the specification:
10 // https://webbluetoothcg.github.io/web-bluetooth
14 // From: Security and privacy considerations
15 // http://webbluetoothcg.github.io/web-bluetooth/#security-and-privacy-considerations
17 // When a website requests access to devices using requestDevice, it gets the
18 // ability to access all GATT services mentioned in the call. The UA must inform
19 // the user what capabilities these services give the website before asking
20 // which devices to entrust to it. If any services in the list aren't known to
21 // the UA, the UA must assume they give the site complete control over the
22 // device and inform the user of this risk. The UA must also allow the user to
23 // inspect what sites have access to what devices and revoke these pairings.
25 // The UA must not allow the user to pair entire classes of devices with a
26 // website. It is possible to construct a class of devices for which each
27 // individual device sends the same Bluetooth-level identifying information. UAs
28 // are not required to attempt to detect this sort of forgery and may let a user
29 // pair this pseudo-device with a website.
31 // To help ensure that only the entity the user approved for access actually has
32 // access, this specification requires that only authenticated environments can
33 // access Bluetooth devices (requestDevice).
36 // From: Per-origin Bluetooth device properties:
38 // For each origin, the UA must maintain an allowed devices map, whose keys are
39 // the Bluetooth devices the origin is allowed to access, and whose values are
40 // pairs of a DOMString device id and an allowed services list consisting of
41 // UUIDs for GATT Primary Services the origin is allowed to access on the
44 // The UA may remove devices from the allowed devices map at any time based on
45 // signals from the user. This needs a definition involving removing
46 // BluetoothDevice instances from device instance maps and clearing out their
47 // [[representedDevice]] fields. For example, if the user chooses not to
48 // remember access, the UA might remove a device when the tab that was granted
49 // access to it is closed. Or the UA might provide a revocation UI that allows
50 // the user to explicitly remove a device even while a tab is actively using
51 // that device. If a device is removed from this list while a Promise is pending
52 // to do something with the device, it must be treated the same as if the device
53 // moved out of Bluetooth range.
56 // From: Device Discovery: requestDevice
57 // http://webbluetoothcg.github.io/web-bluetooth/#device-discovery
59 // Even if scanResult is empty, display a prompt to the user requesting that the
60 // user select a device from it. The UA should show the user the human-readable
61 // name of each device. If this name is not available because the UA's Bluetooth
62 // system doesn't support privacy-enabled scans, the UA should allow the user to
63 // indicate interest and then perform a privacy-disabled scan to retrieve the
66 // The UA may allow the user to select a nearby device that does not match
69 // Wait for the user to have selected a device or cancelled the prompt.
71 // If the user cancels the prompt, reject promise with a NotFoundError and abort
74 // Add device to the origin's allowed devices map. with the union of the service
75 // UUIDs from filters and options.optionalServices as allowed services.
77 // Get the BluetoothDevice representing device and resolve promise with the
81 #include "ipc/ipc_message_macros.h"
82 #include "content/common/bluetooth/bluetooth_device.h"
83 #include "content/common/bluetooth/bluetooth_error.h"
85 #define IPC_MESSAGE_START BluetoothMsgStart
87 IPC_ENUM_TRAITS_MAX_VALUE(
88 device::BluetoothDevice::VendorIDSource
,
89 device::BluetoothDevice::VendorIDSource::VENDOR_ID_MAX_VALUE
)
91 IPC_STRUCT_TRAITS_BEGIN(content::BluetoothDevice
)
92 IPC_STRUCT_TRAITS_MEMBER(instance_id
)
93 IPC_STRUCT_TRAITS_MEMBER(name
)
94 IPC_STRUCT_TRAITS_MEMBER(device_class
)
95 IPC_STRUCT_TRAITS_MEMBER(vendor_id_source
)
96 IPC_STRUCT_TRAITS_MEMBER(vendor_id
)
97 IPC_STRUCT_TRAITS_MEMBER(product_id
)
98 IPC_STRUCT_TRAITS_MEMBER(product_version
)
99 IPC_STRUCT_TRAITS_MEMBER(paired
)
100 IPC_STRUCT_TRAITS_MEMBER(uuids
)
101 IPC_STRUCT_TRAITS_END()
103 IPC_ENUM_TRAITS_MAX_VALUE(content::BluetoothError
,
104 content::BluetoothError::ENUM_MAX_VALUE
)
106 // Messages sent from the browser to the renderer.
108 // Informs the renderer that the device request |request_id| succeeded.
109 IPC_MESSAGE_CONTROL3(BluetoothMsg_RequestDeviceSuccess
,
111 int /* request_id */,
112 content::BluetoothDevice
/* device */)
114 // Informs the renderer that the device request |request_id| failed.
115 IPC_MESSAGE_CONTROL4(BluetoothMsg_RequestDeviceError
,
117 int /* request_id */,
118 content::BluetoothError
/* result */,
119 std::string
/* error_message */)
121 // Informs the renderer that the connection request |request_id| succeeded.
122 IPC_MESSAGE_CONTROL3(BluetoothMsg_ConnectGATTSuccess
,
124 int /* request_id */,
125 std::string
/* device_instance_id */)
127 // Informs the renderer that the connection request |request_id| failed.
128 IPC_MESSAGE_CONTROL4(BluetoothMsg_ConnectGATTError
,
130 int /* request_id */,
131 content::BluetoothError
/* result */,
132 std::string
/* error_message */)
134 // Informs the renderer that primary service request |request_id| succeeded.
135 IPC_MESSAGE_CONTROL3(BluetoothMsg_GetPrimaryServiceSuccess
,
137 int /* request_id */,
138 std::string
/* service_instance_id */)
140 // Informs the renderer that the primary service request |request_id| failed.
141 IPC_MESSAGE_CONTROL4(BluetoothMsg_GetPrimaryServiceError
,
143 int /* request_id */,
144 content::BluetoothError
/* result */,
145 std::string
/* error_message */)
147 // Informs the renderer that characteristic request |request_id| succeeded.
148 IPC_MESSAGE_CONTROL3(BluetoothMsg_GetCharacteristicSuccess
,
150 int /* request_id */,
151 std::string
/* characteristic_instance_id */)
153 // Informs the renderer that the characteristic request |request_id| failed.
154 IPC_MESSAGE_CONTROL4(BluetoothMsg_GetCharacteristicError
,
156 int /* request_id */,
157 content::BluetoothError
/* result */,
158 std::string
/* error_message */)
160 // Informs the renderer that the value has been read.
161 IPC_MESSAGE_CONTROL3(BluetoothMsg_ReadCharacteristicValueSuccess
,
163 int /* request_id */,
164 std::vector
<uint8_t> /* value */)
166 // Informs the renderer that an error occurred while reading the value.
167 IPC_MESSAGE_CONTROL4(BluetoothMsg_ReadCharacteristicValueError
,
169 int /* request_id */,
170 content::BluetoothError
/* result */,
171 std::string
/* error_message */)
173 // Messages sent from the renderer to the browser.
175 // Requests a bluetooth device from the browser.
176 // TODO(scheib): UI to select and permit access to a device crbug.com/436280.
177 // This will include refactoring messages to be associated with an origin
178 // and making this initial requestDevice call with an associated frame.
179 // This work is deferred to simplify initial prototype patches.
180 // The Bluetooth feature, and the BluetoothDispatcherHost are behind
181 // the --enable-experimental-web-platform-features flag.
182 IPC_MESSAGE_CONTROL2(BluetoothHostMsg_RequestDevice
,
184 int /* request_id */)
186 // Connects to a bluetooth device.
187 IPC_MESSAGE_CONTROL3(BluetoothHostMsg_ConnectGATT
,
189 int /* request_id */,
190 std::string
/* device_instance_id */)
192 // Gets primary service from bluetooth device.
193 IPC_MESSAGE_CONTROL4(BluetoothHostMsg_GetPrimaryService
,
195 int /* request_id */,
196 std::string
/* device_instance_id */,
197 std::string
/* service_uuid */)
199 // Gets a GATT Characteristic within a GATT Service.
200 IPC_MESSAGE_CONTROL4(BluetoothHostMsg_GetCharacteristic
,
202 int /* request_id */,
203 std::string
/* service_instance_id */,
204 std::string
/* characteristic_uuid */)
206 // Reads the characteristics value from a bluetooth device.
207 IPC_MESSAGE_CONTROL3(BluetoothHostMsg_ReadValue
,
209 int /* request_id */,
210 std::string
/* characteristic_instance_id */)