forked from auracaster/bumble_mirror
Merge pull request #103 from google/uael/device-fixes
Misc device fixes
This commit is contained in:
@@ -2237,8 +2237,7 @@ class Device(CompositeEventEmitter):
|
|||||||
result = await self.send_command(
|
result = await self.send_command(
|
||||||
HCI_Remote_Name_Request_Command(
|
HCI_Remote_Name_Request_Command(
|
||||||
bd_addr=peer_address,
|
bd_addr=peer_address,
|
||||||
# TODO investigate other options
|
page_scan_repetition_mode=HCI_Remote_Name_Request_Command.R2,
|
||||||
page_scan_repetition_mode=HCI_Remote_Name_Request_Command.R0,
|
|
||||||
reserved=0,
|
reserved=0,
|
||||||
clock_offset=0, # TODO investigate non-0 values
|
clock_offset=0, # TODO investigate non-0 values
|
||||||
)
|
)
|
||||||
@@ -2369,50 +2368,51 @@ class Device(CompositeEventEmitter):
|
|||||||
self.advertising_own_address_type = None
|
self.advertising_own_address_type = None
|
||||||
self.advertising = False
|
self.advertising = False
|
||||||
|
|
||||||
# Create and notify of the new connection asynchronously
|
if own_address_type in (
|
||||||
async def new_connection():
|
OwnAddressType.PUBLIC,
|
||||||
# Figure out which PHY we're connected with
|
OwnAddressType.RESOLVABLE_OR_PUBLIC,
|
||||||
if self.host.supports_command(HCI_LE_READ_PHY_COMMAND):
|
):
|
||||||
result = await asyncio.shield(
|
self_address = self.public_address
|
||||||
self.send_command(
|
else:
|
||||||
HCI_LE_Read_PHY_Command(
|
self_address = self.random_address
|
||||||
connection_handle=connection_handle
|
|
||||||
),
|
# Create a new connection
|
||||||
check_result=True,
|
connection = Connection(
|
||||||
)
|
self,
|
||||||
|
connection_handle,
|
||||||
|
transport,
|
||||||
|
self_address,
|
||||||
|
peer_address,
|
||||||
|
peer_resolvable_address,
|
||||||
|
role,
|
||||||
|
connection_parameters,
|
||||||
|
ConnectionPHY(HCI_LE_1M_PHY, HCI_LE_1M_PHY),
|
||||||
|
)
|
||||||
|
self.connections[connection_handle] = connection
|
||||||
|
|
||||||
|
# If supported, read which PHY we're connected with before
|
||||||
|
# notifying listeners of the new connection.
|
||||||
|
if self.host.supports_command(HCI_LE_READ_PHY_COMMAND):
|
||||||
|
async def read_phy():
|
||||||
|
result = await self.send_command(
|
||||||
|
HCI_LE_Read_PHY_Command(
|
||||||
|
connection_handle=connection_handle
|
||||||
|
),
|
||||||
|
check_result=True,
|
||||||
)
|
)
|
||||||
phy = ConnectionPHY(
|
connection.phy = ConnectionPHY(
|
||||||
result.return_parameters.tx_phy, result.return_parameters.rx_phy
|
result.return_parameters.tx_phy, result.return_parameters.rx_phy
|
||||||
)
|
)
|
||||||
else:
|
# Emit an event to notify listeners of the new connection
|
||||||
phy = ConnectionPHY(HCI_LE_1M_PHY, HCI_LE_1M_PHY)
|
self.emit('connection', connection)
|
||||||
|
|
||||||
self_address = self.random_address
|
# Do so asynchronously to not block the current event handler
|
||||||
if own_address_type in (
|
connection.abort_on('disconnection', read_phy())
|
||||||
OwnAddressType.PUBLIC,
|
|
||||||
OwnAddressType.RESOLVABLE_OR_PUBLIC,
|
|
||||||
):
|
|
||||||
self_address = self.public_address
|
|
||||||
|
|
||||||
# Create a new connection
|
|
||||||
connection = Connection(
|
|
||||||
self,
|
|
||||||
connection_handle,
|
|
||||||
transport,
|
|
||||||
self_address,
|
|
||||||
peer_address,
|
|
||||||
peer_resolvable_address,
|
|
||||||
role,
|
|
||||||
connection_parameters,
|
|
||||||
phy,
|
|
||||||
)
|
|
||||||
self.connections[connection_handle] = connection
|
|
||||||
|
|
||||||
|
else:
|
||||||
# Emit an event to notify listeners of the new connection
|
# Emit an event to notify listeners of the new connection
|
||||||
self.emit('connection', connection)
|
self.emit('connection', connection)
|
||||||
|
|
||||||
self.abort_on('flush', new_connection())
|
|
||||||
|
|
||||||
@host_event_handler
|
@host_event_handler
|
||||||
def on_connection_failure(self, transport, peer_address, error_code):
|
def on_connection_failure(self, transport, peer_address, error_code):
|
||||||
logger.debug(f'*** Connection failed: {HCI_Constant.error_name(error_code)}')
|
logger.debug(f'*** Connection failed: {HCI_Constant.error_name(error_code)}')
|
||||||
|
|||||||
Reference in New Issue
Block a user