From b75116302fcdbf44fbed66ccfbdea3a40911b347 Mon Sep 17 00:00:00 2001 From: Chengwei Hsieh Date: Wed, 23 Apr 2025 14:12:01 -0700 Subject: [PATCH 1/5] Support bluetooth.simulateService --- index.bs | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-) diff --git a/index.bs b/index.bs index 28bce08..4ea94e6 100644 --- a/index.bs +++ b/index.bs @@ -5008,7 +5008,14 @@ Each simulated Bluetooth adapter has an adapter state that is Each simulated Bluetooth adapter has a low-energy supported state that is a boolean describing if the adapter supports Bluetooth Low Energy. -A simulated Bluetooth device is a software defined [=Bluetooth device=] that behaves like a physical device, and may be attached to a simulated Bluetooth adapter, and may have associated properties like Manufacturer Specific Data and Service UUIDs. +A simulated Bluetooth device is a software defined [=Bluetooth device=] that +behaves like a physical device, may be attached to a simulated Bluetooth adapter, +may have associated properties like Manufacturer Specific Data and Service UUIDs, +and has a simulated GATT service mapping, which is an ordered map of Bluetooth +UUID {{strings}} to simulated GATT services. + +A simulated GATT service is a software defined [=Service=] that belongs to a +simulated Bluetooth device, and has a property of UUID. Issue: CDDL snippetes use the "text" type instead of "browsingContext.BrowsingContext" to allow indepedent programmatic @@ -5567,6 +5574,89 @@ A [=local end=] could simulate device GATT disconnection by sending the followin +#### The bluetooth.simulateService Command #### {#bluetooth-simulateservice-command} + +
+bluetooth.SimulateService = (
+   method: "bluetooth.simulateService",
+   params: bluetooth.simulateServiceParameters,
+)
+
+bluetooth.simulateServiceParameters = {
+   context: text,
+   address: text,
+   uuid: bluetooth.BluetoothServiceUuid,
+   type: "add" / "remove",
+}
+
+
+ +
+The [=remote end steps=] with command parameters |params| are: + +1. Let |contextId| be |params|[`"context"`]. +1. Let |navigable| be the result of [=trying=] to [=get a navigable=] with |contextId|. +1. Let |deviceAddress| be |params|[`"address"`]. +1. Let |simulatedBluetoothAdapter| be |navigable|'s simulated Bluetooth adapter. +1. If |simulatedBluetoothAdapter| is empty, return [=error=] with [=error code=] [=invalid argument=]. +1. Let |deviceMapping| be |simulatedBluetoothAdapter|'s simulated Bluetooth device mapping. +1. If |deviceMapping|[|deviceAddress|] [=map/exists=], let |simulatedDevice| be |deviceMapping|[|deviceAddress|]. +1. Otherwise, return [=error=] with [=error code=] [=invalid argument=]. +1. Let |simulatedDeviceInstance| be the result of get the BluetoothDevice representing + |simulatedDevice| inside |navigable|'s active window's associated Navigator's + [=associated Bluetooth=]. +1. Let |serviceMapping| be |simulatedDevice|'s simulated GATT service mapping. +1. If |params|[`"type"`] is `"add"`: + 1. If |serviceMapping|[|params|[`"uuid"`]] [=map/exists=], return [=error=] with [=error code=] [=invalid element state=]. + 1. Let |simulatedGattService| be a new simulated GATT service. + 1. Set |simulatedGattService|'s UUID to |params|[`"uuid"`]. + 1. Set |serviceMapping|[|params|[`"uuid"`]] to |simulatedGattService|. + 1. Create a BluetoothRemoteGATTService representing |simulatedGattService| + and add a mapping from |simulatedGattService| to the resulting {{Promise}} in + |simulatedDeviceInstance|.{{[[context]]}}.{{Bluetooth/[[attributeInstanceMap]]}}. + 1. Return [=success=] with data `null`. +1. Else if |params|[`"type"`] is `"remove"`: + 1. If |serviceMapping|[|params|[`"uuid"`]] [=map/exists=], let |simulatedGattService| be |serviceMapping|[|params|[`"uuid"`]]. + 1. Otherwise, return [=error=] with [=error code=] [=invalid element state=]. + 1. Remove |simulatedGattService| from |simulatedDeviceInstance|.{{[[context]]}}.{{Bluetooth/[[attributeInstanceMap]]}}. + 1. Remove |params|[`"uuid"`] from |serviceMapping|. + 1. Return [=success=] with data `null`. +1. Return [=error=] with [=error code=] [=invalid argument=]. + +
+ +
+A [=local end=] could simulate adding a GATT service by sending the following message: + +
+{
+  "method": "bluetooth.simulateService",
+  "params": {
+    "context": "cxt-d03fdd81",
+    "address": "09:09:09:09:09:09",
+    "uuid": "12345678-1234-5678-9abc-def123456789",
+    "type": "add"
+  }
+}
+
+
+ +
+A [=local end=] could simulate removing a GATT service by sending the following message: + +
+{
+  "method": "bluetooth.simulateService",
+  "params": {
+    "context": "cxt-d03fdd81",
+    "address": "09:09:09:09:09:09",
+    "uuid": "12345678-1234-5678-9abc-def123456789",
+    "type": "remove"
+  }
+}
+
+
+ ### Events ### {#bidi-events} #### The bluetooth.requestDevicePromptUpdated Event #### {#bluetooth-requestdevicepromptupdated-event} From ea503b9428d20bf60fe67c7ad68348bd4db262c2 Mon Sep 17 00:00:00 2001 From: Chengwei Hsieh Date: Wed, 23 Apr 2025 14:21:44 -0700 Subject: [PATCH 2/5] Add it to bluetooth.commands --- index.bs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/index.bs b/index.bs index 4ea94e6..c60d656 100644 --- a/index.bs +++ b/index.bs @@ -5173,6 +5173,7 @@ BluetoothCommand = ( bluetooth.SimulateAdvertisement // bluetooth.SimulateGattConnectionResponse // bluetooth.SimulateGattDisconnection // + bluetooth.SimulateService // ) @@ -5606,20 +5607,21 @@ The [=remote end steps=] with command parameters |params| are: |simulatedDevice| inside |navigable|'s active window's associated Navigator's [=associated Bluetooth=]. 1. Let |serviceMapping| be |simulatedDevice|'s simulated GATT service mapping. +1. Let |uuid| be |params|[`"uuid"`]. 1. If |params|[`"type"`] is `"add"`: - 1. If |serviceMapping|[|params|[`"uuid"`]] [=map/exists=], return [=error=] with [=error code=] [=invalid element state=]. + 1. If |serviceMapping|[|uuid|] [=map/exists=], return [=error=] with [=error code=] [=invalid element state=]. 1. Let |simulatedGattService| be a new simulated GATT service. - 1. Set |simulatedGattService|'s UUID to |params|[`"uuid"`]. - 1. Set |serviceMapping|[|params|[`"uuid"`]] to |simulatedGattService|. + 1. Set |simulatedGattService|'s UUID to |uuid|. + 1. Set |serviceMapping|[|uuid|] to |simulatedGattService|. 1. Create a BluetoothRemoteGATTService representing |simulatedGattService| and add a mapping from |simulatedGattService| to the resulting {{Promise}} in |simulatedDeviceInstance|.{{[[context]]}}.{{Bluetooth/[[attributeInstanceMap]]}}. 1. Return [=success=] with data `null`. 1. Else if |params|[`"type"`] is `"remove"`: - 1. If |serviceMapping|[|params|[`"uuid"`]] [=map/exists=], let |simulatedGattService| be |serviceMapping|[|params|[`"uuid"`]]. + 1. If |serviceMapping|[|uuid|] [=map/exists=], let |simulatedGattService| be |serviceMapping|[|uuid|]. 1. Otherwise, return [=error=] with [=error code=] [=invalid element state=]. 1. Remove |simulatedGattService| from |simulatedDeviceInstance|.{{[[context]]}}.{{Bluetooth/[[attributeInstanceMap]]}}. - 1. Remove |params|[`"uuid"`] from |serviceMapping|. + 1. Remove |uuid| from |serviceMapping|. 1. Return [=success=] with data `null`. 1. Return [=error=] with [=error code=] [=invalid argument=]. From c5a27e191fbd006e4af04907081f5715b6829371 Mon Sep 17 00:00:00 2001 From: Chengwei Hsieh Date: Wed, 23 Apr 2025 14:46:13 -0700 Subject: [PATCH 3/5] simulated GATT service is a Bluetooth cache --- index.bs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.bs b/index.bs index c60d656..5b2a64a 100644 --- a/index.bs +++ b/index.bs @@ -5014,8 +5014,8 @@ may have associated properties like Manufacturer Specific Data and Ser and has a simulated GATT service mapping, which is an ordered map of Bluetooth UUID {{strings}} to simulated GATT services. -A simulated GATT service is a software defined [=Service=] that belongs to a -simulated Bluetooth device, and has a property of UUID. +A simulated GATT service is a software defined and known-present Bluetooth cache +of [=Service=] that belongs to a simulated Bluetooth device, and has a property of UUID. Issue: CDDL snippetes use the "text" type instead of "browsingContext.BrowsingContext" to allow indepedent programmatic From 75707656b26753ab3fe11edeff426d72f23fef68 Mon Sep 17 00:00:00 2001 From: Jack Hsieh <97704544+chengweih001@users.noreply.github.com> Date: Fri, 2 May 2025 01:25:16 -0700 Subject: [PATCH 4/5] Fix merge error --- index.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.bs b/index.bs index e24671f..9e390dd 100644 --- a/index.bs +++ b/index.bs @@ -5649,7 +5649,7 @@ A [=local end=] could simulate adding a GATT service by sending the following me "params": { "context": "cxt-d03fdd81", "address": "09:09:09:09:09:09", - "uuid": "12345678-1234-5678-9abc-def123456789", + "uuid": "0000180d-0000-1000-8000-00805f9b34fb", "type": "add" } } From 66d15279c1eb618651ebc8ca85a0d7705a69ae24 Mon Sep 17 00:00:00 2001 From: Chengwei Hsieh Date: Fri, 2 May 2025 15:49:18 -0700 Subject: [PATCH 5/5] Fix UUID string reference and update simulated GATT service --- index.bs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/index.bs b/index.bs index 9e390dd..7ea9f6f 100644 --- a/index.bs +++ b/index.bs @@ -5012,10 +5012,11 @@ A simulated Bluetooth device is a software defined [=Bluetooth device behaves like a physical device, may be attached to a simulated Bluetooth adapter, may have associated properties like Manufacturer Specific Data and Service UUIDs, and has a simulated GATT service mapping, which is an ordered map of Bluetooth -UUID {{strings}} to simulated GATT services. +UUID strings to simulated GATT services. -A simulated GATT service is a software defined and known-present Bluetooth cache -of [=Service=] that belongs to a simulated Bluetooth device, and has a property of UUID. +A simulated GATT service is a software defined [=Service=] that belongs to a +simulated Bluetooth device, has a property of UUID, and is known-present in the +Bluetooth cache. Issue: CDDL snippetes use the "text" type instead of "browsingContext.BrowsingContext" to allow indepedent programmatic