fix tests

This commit is contained in:
Gilles Boccon-Gibod
2022-10-17 14:32:20 -07:00
parent 9c429ec75a
commit ce25cdc223
2 changed files with 75 additions and 41 deletions

View File

@@ -583,13 +583,15 @@ class Controller:
'''
See Bluetooth spec Vol 2, Part E - 7.4.1 Read Local Version Information Command
'''
return struct.pack('<BBHBHH',
HCI_SUCCESS,
self.hci_version,
self.hci_revision,
self.lmp_version,
self.manufacturer_name,
self.lmp_subversion)
return struct.pack(
'<BBHBHH',
HCI_SUCCESS,
self.hci_version,
self.hci_revision,
self.lmp_version,
self.manufacturer_name,
self.lmp_subversion
)
def on_hci_read_local_supported_commands_command(self, command):
'''
@@ -876,12 +878,26 @@ class Controller:
'''
See Bluetooth spec Vol 2, Part E - 7.8.46 LE Read Maximum Data Length Command
'''
return struct.pack('<BHHHH',
HCI_SUCCESS,
self.supported_max_tx_octets,
self.supported_max_tx_time,
self.supported_max_rx_octets,
self.supported_max_rx_time)
return struct.pack(
'<BHHHH',
HCI_SUCCESS,
self.supported_max_tx_octets,
self.supported_max_tx_time,
self.supported_max_rx_octets,
self.supported_max_rx_time
)
def on_hci_le_read_phy_command(self, command):
'''
See Bluetooth spec Vol 2, Part E - 7.8.47 LE Read PHY command
'''
return struct.pack(
'<BHBB',
HCI_SUCCESS,
command.connection_handle,
HCI_LE_1M_PHY,
HCI_LE_1M_PHY
)
def on_hci_le_set_default_phy_command(self, command):
'''
@@ -893,3 +909,4 @@ class Controller:
'rx_phys': command.rx_phys
}
return bytes([HCI_SUCCESS])

View File

@@ -271,8 +271,8 @@ class Peer:
async def request_mtu(self, mtu):
mtu = await self.gatt_client.request_mtu(mtu)
self.connection.att_mtu = mtu
self.connection.emit('connection_att_mtu_update')
return mtu
async def discover_service(self, uuid):
return await self.gatt_client.discover_service(uuid)
@@ -1052,7 +1052,7 @@ class Device(CompositeEventEmitter):
lap = HCI_GENERAL_INQUIRY_LAP,
inquiry_length = DEVICE_DEFAULT_INQUIRY_LENGTH,
num_responses = 0 # Unlimited number of responses.
), check_result=True)
))
if response.status != HCI_Command_Status_Event.PENDING:
self.discovering = False
raise HCI_StatusError(response)
@@ -1644,30 +1644,7 @@ class Device(CompositeEventEmitter):
if connection_handle in self.connections:
logger.warn('new connection reuses the same handle as a previous connection')
# Resolve the peer address if we can
if self.address_resolver:
if peer_address.is_resolvable:
resolved_address = self.address_resolver.resolve(peer_address)
if resolved_address is not None:
logger.debug(f'*** Address resolved as {resolved_address}')
peer_resolvable_address = peer_address
peer_address = resolved_address
# We are no longer advertising
self.advertising = False
# Create and notify of the new connection asynchronously
async def new_connection():
# Figure out which PHY we're connected with
if self.host.supports_command(HCI_LE_READ_PHY_COMMAND):
result = await self.send_command(
HCI_LE_Read_PHY_Command(connection_handle=connection_handle),
check_result=True
)
phy = ConnectionPHY(result.return_parameters.tx_phy, result.return_parameters.rx_phy)
else:
phy = ConnectionPHY(HCI_LE_1M_PHY, HCI_LE_1M_PHY)
if transport == BT_BR_EDR_TRANSPORT:
# Create a new connection
connection = Connection(
self,
@@ -1677,14 +1654,54 @@ class Device(CompositeEventEmitter):
peer_resolvable_address,
role,
connection_parameters,
phy
phy=None
)
self.connections[connection_handle] = connection
# Emit an event to notify listeners of the new connection
self.emit('connection', connection)
else:
# Resolve the peer address if we can
if self.address_resolver:
if peer_address.is_resolvable:
resolved_address = self.address_resolver.resolve(peer_address)
if resolved_address is not None:
logger.debug(f'*** Address resolved as {resolved_address}')
peer_resolvable_address = peer_address
peer_address = resolved_address
asyncio.create_task(new_connection())
# We are no longer advertising
self.advertising = False
# Create and notify of the new connection asynchronously
async def new_connection():
# Figure out which PHY we're connected with
if self.host.supports_command(HCI_LE_READ_PHY_COMMAND):
result = await self.send_command(
HCI_LE_Read_PHY_Command(connection_handle=connection_handle),
check_result=True
)
phy = ConnectionPHY(result.return_parameters.tx_phy, result.return_parameters.rx_phy)
else:
phy = ConnectionPHY(HCI_LE_1M_PHY, HCI_LE_1M_PHY)
# Create a new connection
connection = Connection(
self,
connection_handle,
transport,
peer_address,
peer_resolvable_address,
role,
connection_parameters,
phy
)
self.connections[connection_handle] = connection
# Emit an event to notify listeners of the new connection
self.emit('connection', connection)
asyncio.create_task(new_connection())
@host_event_handler
def on_connection_failure(self, connection_handle, error_code):