aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Wu <joshwu@google.com>2022-07-20 20:42:30 +0800
committerJosh Wu <joshwu@google.com>2022-07-21 03:14:34 +0800
commitce61d1af9fe485f66681b481a30b12a0f2cf28fb (patch)
treeff8c98c7bf3384fcbf3a335a0ec47e6196a7806e
parentc6d743da8370a3db45a9f1b21d58dae5acc38669 (diff)
downloadavatar-ce61d1af9fe485f66681b481a30b12a0f2cf28fb.tar.gz
Implement Bumble Disconnect and GetConnection
Change-Id: Ib124843993551dc6279563522df7c69b35e8f747
-rw-r--r--avatar/bumble_server/host.py31
1 files changed, 29 insertions, 2 deletions
diff --git a/avatar/bumble_server/host.py b/avatar/bumble_server/host.py
index 0c64779..c426872 100644
--- a/avatar/bumble_server/host.py
+++ b/avatar/bumble_server/host.py
@@ -1,11 +1,11 @@
import logging
from bumble.core import BT_BR_EDR_TRANSPORT
-from bumble.hci import Address
+from bumble.hci import Address, HCI_REMOTE_USER_TERMINATED_CONNECTION_ERROR
from bumble.smp import PairingConfig
from pandora.host_pb2 import ReadLocalAddressResponse, ConnectResponse, \
- Connection
+ Connection, DisconnectResponse, GetConnectionResponse
from pandora.host_grpc import HostServicer
@@ -47,3 +47,30 @@ class HostService(HostServicer):
except Exception as error:
logging.error(error)
return ConnectResponse()
+
+ async def Disconnect(self, request, context):
+ # Need to reverse bytes order since Bumble Address is using MSB.
+ connection_handle = int.from_bytes(request.connection.cookie,'big')
+ logging.info(f"Disconnect: {connection_handle}")
+
+ try:
+ logging.info("Disconnecting...")
+ connection = self.device.lookup_connection(connection_handle)
+ await connection.disconnect(HCI_REMOTE_USER_TERMINATED_CONNECTION_ERROR)
+ except Exception as error:
+ logging.error(error)
+
+ return DisconnectResponse()
+
+ async def GetConnection(self, request, context):
+ address = Address(bytes(reversed(request.address)))
+ logging.info(f"GetConnection: {address}")
+
+ try:
+ connection_handle = self.device.find_connection_by_bd_addr(
+ address).handle.to_bytes(4, 'big')
+ return GetConnectionResponse(connection=Connection(cookie=connection_handle))
+
+ except Exception as error:
+ logging.error(error)
+ return GetConnectionResponse()