From 8d31e483789ee8c4b9767ed03a02529ffbbed467 Mon Sep 17 00:00:00 2001 From: Chengwei Hsieh Date: Fri, 18 Apr 2025 16:33:52 -0700 Subject: [PATCH 1/6] Add bluetooth.SimulateGattDisconnection --- index.bs | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/index.bs b/index.bs index c87a6f4..884f41e 100644 --- a/index.bs +++ b/index.bs @@ -5163,6 +5163,7 @@ BluetoothCommand = ( bluetooth.SimulatePreconnectedPeripheral // bluetooth.SimulateAdvertisement // bluetooth.SimulateGattConnectionResponse // + bluetooth.SimulateGattDisconnection // ) @@ -5510,6 +5511,55 @@ A [=local end=] could simulate a device gatt connection response of success +#### The bluetooth.simulateGattDisconnection Command #### {#bluetooth-simulategattdisconnection-command} + +
+bluetooth.SimulateGattDisconnection = (
+   method: "bluetooth.simulateGattDisconnection",
+   params: bluetooth.SimulateGattDisconnectionParameters,
+)
+
+bluetooth.SimulateGattDisconnectionParameters = {
+   context: text,
+   address: text,
+}
+
+
+ +
+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|]. + 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. If |simulatedDeviceInstance|.{{[[gatt]]}}.{{[[automatedGATTConnectionResponse]]}} is `"expected"`, + return [=error=] with [=error code=] [=invalid element state=]. +1. Clean up the disconnected device |simulatedDeviceInstance|. + +
+ +
+A [=local end=] could simulate device gatt disconnection by sending the following message: + +
+{
+  "method": "bluetooth.simulateGattDisconnection",
+  "params": {
+    "context": "cxt-d03fdd81",
+    "address": "09:09:09:09:09:09",
+  }
+}
+
+
+ ### Events ### {#bidi-events} #### The bluetooth.requestDevicePromptUpdated Event #### {#bluetooth-requestdevicepromptupdated-event} From 91a3fa64f1572dc152b314734f3f2be3671a8713 Mon Sep 17 00:00:00 2001 From: Chengwei Hsieh Date: Sat, 19 Apr 2025 00:37:38 -0700 Subject: [PATCH 2/6] simulateGattDisconnection to be a response to a connection request --- index.bs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/index.bs b/index.bs index 884f41e..4aeac77 100644 --- a/index.bs +++ b/index.bs @@ -4234,6 +4234,8 @@ To clean up the disconnected device |deviceObj|, the UA must: 1. Set deviceObj.gatt.{{BluetoothRemoteGATTServer/connected}} to `false`. 1. Clear deviceObj.gatt.{{[[activeAlgorithms]]}}. +1. Set deviceObj.gatt.{{[[automatedGATTConnectionResponse]]}} to + `"not-expected"`. 1. Let |context| be |deviceObj|.{{[[context]]}}. 1. Remove all entries from |context|.{{[[attributeInstanceMap]]}} whose keys are inside |deviceObj|.{{[[representedDevice]]}}. @@ -5541,8 +5543,8 @@ The [=remote end steps=] with command parameters |params| are: |simulatedDevice| inside |navigable|'s active window's associated Navigator's [=associated Bluetooth=]. 1. If |simulatedDeviceInstance|.{{[[gatt]]}}.{{[[automatedGATTConnectionResponse]]}} is `"expected"`, - return [=error=] with [=error code=] [=invalid element state=]. -1. Clean up the disconnected device |simulatedDeviceInstance|. + set |simulatedDeviceInstance|.{{[[gatt]]}}.{{[[automatedGATTConnectionResponse]]}} to `"disconnection-simulated"` +1. Otherwise, clean up the disconnected device |simulatedDeviceInstance|. From 710342ee4c20a2d3f8369b82f3bbaa63346b7c54 Mon Sep 17 00:00:00 2001 From: Chengwei Hsieh Date: Mon, 21 Apr 2025 14:13:39 -0700 Subject: [PATCH 3/6] Use 0x44 when simulating disconnection response --- index.bs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.bs b/index.bs index 4aeac77..2269628 100644 --- a/index.bs +++ b/index.bs @@ -5543,13 +5543,13 @@ The [=remote end steps=] with command parameters |params| are: |simulatedDevice| inside |navigable|'s active window's associated Navigator's [=associated Bluetooth=]. 1. If |simulatedDeviceInstance|.{{[[gatt]]}}.{{[[automatedGATTConnectionResponse]]}} is `"expected"`, - set |simulatedDeviceInstance|.{{[[gatt]]}}.{{[[automatedGATTConnectionResponse]]}} to `"disconnection-simulated"` + set |simulatedDeviceInstance|.{{[[gatt]]}}.{{[[automatedGATTConnectionResponse]]}} to `0x44`. 1. Otherwise, clean up the disconnected device |simulatedDeviceInstance|.
-A [=local end=] could simulate device gatt disconnection by sending the following message: +A [=local end=] could simulate device GATT disconnection by sending the following message:
 {

From 5cf88e9d35c6defe9f475eb3b1dc6e46629e95a8 Mon Sep 17 00:00:00 2001
From: Chengwei Hsieh 
Date: Mon, 21 Apr 2025 14:53:36 -0700
Subject: [PATCH 4/6] Use 0x15 for simulating disconnection

---
 index.bs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/index.bs b/index.bs
index 2269628..15996bc 100644
--- a/index.bs
+++ b/index.bs
@@ -5543,7 +5543,7 @@ The [=remote end steps=] with command parameters |params| are:
     |simulatedDevice| inside |navigable|'s active window's associated Navigator's
     [=associated Bluetooth=].
 1. If |simulatedDeviceInstance|.{{[[gatt]]}}.{{[[automatedGATTConnectionResponse]]}} is `"expected"`,
-    set |simulatedDeviceInstance|.{{[[gatt]]}}.{{[[automatedGATTConnectionResponse]]}} to `0x44`.
+    set |simulatedDeviceInstance|.{{[[gatt]]}}.{{[[automatedGATTConnectionResponse]]}} to `0x15`.
 1. Otherwise, clean up the disconnected device |simulatedDeviceInstance|.
 
 
From 33edbd729972982a955333214fb42fbd246918c5 Mon Sep 17 00:00:00 2001 From: Chengwei Hsieh Date: Mon, 21 Apr 2025 16:08:25 -0700 Subject: [PATCH 5/6] Add note for why using 0x15 --- index.bs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/index.bs b/index.bs index 15996bc..d20d1a9 100644 --- a/index.bs +++ b/index.bs @@ -5544,6 +5544,11 @@ The [=remote end steps=] with command parameters |params| are: [=associated Bluetooth=]. 1. If |simulatedDeviceInstance|.{{[[gatt]]}}.{{[[automatedGATTConnectionResponse]]}} is `"expected"`, set |simulatedDeviceInstance|.{{[[gatt]]}}.{{[[automatedGATTConnectionResponse]]}} to `0x15`. +
+ `0x15` represents `"Remote Device Terminated Connection due to Power Off"` according to the + List of Error Codes. This allows a simulation scenario where the Bluetooth device is + not able to respond to a GATT connection attempt. +
1. Otherwise, clean up the disconnected device |simulatedDeviceInstance|. From 2e5191f78fa1047f782467027f49839c50e9ecdc Mon Sep 17 00:00:00 2001 From: Chengwei Hsieh Date: Mon, 21 Apr 2025 16:11:32 -0700 Subject: [PATCH 6/6] Slightly change wording for note --- index.bs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.bs b/index.bs index d20d1a9..28bce08 100644 --- a/index.bs +++ b/index.bs @@ -5546,8 +5546,8 @@ The [=remote end steps=] with command parameters |params| are: set |simulatedDeviceInstance|.{{[[gatt]]}}.{{[[automatedGATTConnectionResponse]]}} to `0x15`.
`0x15` represents `"Remote Device Terminated Connection due to Power Off"` according to the - List of Error Codes. This allows a simulation scenario where the Bluetooth device is - not able to respond to a GATT connection attempt. + List of Error Codes. This simulates a scenario where the Bluetooth device is not able to + respond to a GATT connection attempt.
1. Otherwise, clean up the disconnected device |simulatedDeviceInstance|.