mirror of
https://github.com/google/bumble.git
synced 2026-04-18 00:45:32 +00:00
Replace legacy transport and role constants
This commit is contained in:
@@ -28,8 +28,7 @@ import click
|
|||||||
|
|
||||||
from bumble import l2cap
|
from bumble import l2cap
|
||||||
from bumble.core import (
|
from bumble.core import (
|
||||||
BT_BR_EDR_TRANSPORT,
|
PhysicalTransport,
|
||||||
BT_LE_TRANSPORT,
|
|
||||||
BT_L2CAP_PROTOCOL_ID,
|
BT_L2CAP_PROTOCOL_ID,
|
||||||
BT_RFCOMM_PROTOCOL_ID,
|
BT_RFCOMM_PROTOCOL_ID,
|
||||||
UUID,
|
UUID,
|
||||||
@@ -42,8 +41,7 @@ from bumble.hci import (
|
|||||||
HCI_LE_1M_PHY,
|
HCI_LE_1M_PHY,
|
||||||
HCI_LE_2M_PHY,
|
HCI_LE_2M_PHY,
|
||||||
HCI_LE_CODED_PHY,
|
HCI_LE_CODED_PHY,
|
||||||
HCI_CENTRAL_ROLE,
|
Role,
|
||||||
HCI_PERIPHERAL_ROLE,
|
|
||||||
HCI_Constant,
|
HCI_Constant,
|
||||||
HCI_Error,
|
HCI_Error,
|
||||||
HCI_StatusError,
|
HCI_StatusError,
|
||||||
@@ -113,7 +111,7 @@ def print_connection_phy(phy):
|
|||||||
|
|
||||||
def print_connection(connection):
|
def print_connection(connection):
|
||||||
params = []
|
params = []
|
||||||
if connection.transport == BT_LE_TRANSPORT:
|
if connection.transport == PhysicalTransport.LE:
|
||||||
params.append(
|
params.append(
|
||||||
'DL=('
|
'DL=('
|
||||||
f'TX:{connection.data_length[0]}/{connection.data_length[1]},'
|
f'TX:{connection.data_length[0]}/{connection.data_length[1]},'
|
||||||
@@ -189,7 +187,7 @@ def log_stats(title, stats, precision=2):
|
|||||||
|
|
||||||
|
|
||||||
async def switch_roles(connection, role):
|
async def switch_roles(connection, role):
|
||||||
target_role = HCI_CENTRAL_ROLE if role == "central" else HCI_PERIPHERAL_ROLE
|
target_role = Role.CENTRAL if role == "central" else Role.PERIPHERAL
|
||||||
if connection.role != target_role:
|
if connection.role != target_role:
|
||||||
logging.info(f'{color("### Switching roles to:", "cyan")} {role}')
|
logging.info(f'{color("### Switching roles to:", "cyan")} {role}')
|
||||||
try:
|
try:
|
||||||
@@ -1275,7 +1273,11 @@ class Central(Connection.Listener):
|
|||||||
self.connection = await self.device.connect(
|
self.connection = await self.device.connect(
|
||||||
self.peripheral_address,
|
self.peripheral_address,
|
||||||
connection_parameters_preferences=self.connection_parameter_preferences,
|
connection_parameters_preferences=self.connection_parameter_preferences,
|
||||||
transport=BT_BR_EDR_TRANSPORT if self.classic else BT_LE_TRANSPORT,
|
transport=(
|
||||||
|
PhysicalTransport.BR_EDR
|
||||||
|
if self.classic
|
||||||
|
else PhysicalTransport.LE
|
||||||
|
),
|
||||||
)
|
)
|
||||||
except CommandTimeoutError:
|
except CommandTimeoutError:
|
||||||
logging.info(color('!!! Connection timed out', 'red'))
|
logging.info(color('!!! Connection timed out', 'red'))
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ from prompt_toolkit.layout import (
|
|||||||
from bumble import __version__
|
from bumble import __version__
|
||||||
import bumble.core
|
import bumble.core
|
||||||
from bumble import colors
|
from bumble import colors
|
||||||
from bumble.core import UUID, AdvertisingData, BT_LE_TRANSPORT
|
from bumble.core import UUID, AdvertisingData, PhysicalTransport
|
||||||
from bumble.device import (
|
from bumble.device import (
|
||||||
ConnectionParametersPreferences,
|
ConnectionParametersPreferences,
|
||||||
ConnectionPHY,
|
ConnectionPHY,
|
||||||
|
|||||||
@@ -31,8 +31,7 @@ from bumble.keys import JsonKeyStore
|
|||||||
from bumble.core import (
|
from bumble.core import (
|
||||||
AdvertisingData,
|
AdvertisingData,
|
||||||
ProtocolError,
|
ProtocolError,
|
||||||
BT_LE_TRANSPORT,
|
PhysicalTransport,
|
||||||
BT_BR_EDR_TRANSPORT,
|
|
||||||
)
|
)
|
||||||
from bumble.gatt import (
|
from bumble.gatt import (
|
||||||
GATT_DEVICE_NAME_CHARACTERISTIC,
|
GATT_DEVICE_NAME_CHARACTERISTIC,
|
||||||
@@ -422,7 +421,9 @@ async def pair(
|
|||||||
print(color(f'=== Connecting to {address_or_name}...', 'green'))
|
print(color(f'=== Connecting to {address_or_name}...', 'green'))
|
||||||
connection = await device.connect(
|
connection = await device.connect(
|
||||||
address_or_name,
|
address_or_name,
|
||||||
transport=BT_LE_TRANSPORT if mode == 'le' else BT_BR_EDR_TRANSPORT,
|
transport=(
|
||||||
|
PhysicalTransport.LE if mode == 'le' else PhysicalTransport.BR_EDR
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
if not request:
|
if not request:
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ from bumble.core import (
|
|||||||
AdvertisingData,
|
AdvertisingData,
|
||||||
ConnectionError as BumbleConnectionError,
|
ConnectionError as BumbleConnectionError,
|
||||||
DeviceClass,
|
DeviceClass,
|
||||||
BT_BR_EDR_TRANSPORT,
|
PhysicalTransport,
|
||||||
)
|
)
|
||||||
from bumble.device import Connection, Device, DeviceConfiguration
|
from bumble.device import Connection, Device, DeviceConfiguration
|
||||||
from bumble.hci import Address, HCI_CONNECTION_ALREADY_EXISTS_ERROR, HCI_Constant
|
from bumble.hci import Address, HCI_CONNECTION_ALREADY_EXISTS_ERROR, HCI_Constant
|
||||||
@@ -286,7 +286,7 @@ class Player:
|
|||||||
|
|
||||||
async def connect(self, device: Device, address: str) -> Connection:
|
async def connect(self, device: Device, address: str) -> Connection:
|
||||||
print(color(f"Connecting to {address}...", "green"))
|
print(color(f"Connecting to {address}...", "green"))
|
||||||
connection = await device.connect(address, transport=BT_BR_EDR_TRANSPORT)
|
connection = await device.connect(address, transport=PhysicalTransport.BR_EDR)
|
||||||
|
|
||||||
# Request authentication
|
# Request authentication
|
||||||
if self.authenticate:
|
if self.authenticate:
|
||||||
@@ -402,7 +402,7 @@ class Player:
|
|||||||
|
|
||||||
async def pair(self, device: Device, address: str) -> None:
|
async def pair(self, device: Device, address: str) -> None:
|
||||||
print(color(f"Connecting to {address}...", "green"))
|
print(color(f"Connecting to {address}...", "green"))
|
||||||
connection = await device.connect(address, transport=BT_BR_EDR_TRANSPORT)
|
connection = await device.connect(address, transport=PhysicalTransport.BR_EDR)
|
||||||
|
|
||||||
print(color("Pairing...", "magenta"))
|
print(color("Pairing...", "magenta"))
|
||||||
await connection.authenticate()
|
await connection.authenticate()
|
||||||
|
|||||||
@@ -271,7 +271,7 @@ class ClientBridge:
|
|||||||
print(color(f"@@@ Connecting to Bluetooth {self.address}", "blue"))
|
print(color(f"@@@ Connecting to Bluetooth {self.address}", "blue"))
|
||||||
assert self.device
|
assert self.device
|
||||||
self.connection = await self.device.connect(
|
self.connection = await self.device.connect(
|
||||||
self.address, transport=core.BT_BR_EDR_TRANSPORT
|
self.address, transport=core.PhysicalTransport.BR_EDR
|
||||||
)
|
)
|
||||||
print(color(f"@@@ Bluetooth connection: {self.connection}", "blue"))
|
print(color(f"@@@ Bluetooth connection: {self.connection}", "blue"))
|
||||||
self.connection.on("disconnection", self.on_disconnection)
|
self.connection.on("disconnection", self.on_disconnection)
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ from aiohttp import web
|
|||||||
|
|
||||||
import bumble
|
import bumble
|
||||||
from bumble.colors import color
|
from bumble.colors import color
|
||||||
from bumble.core import BT_BR_EDR_TRANSPORT, CommandTimeoutError
|
from bumble.core import PhysicalTransport, CommandTimeoutError
|
||||||
from bumble.device import Connection, Device, DeviceConfiguration
|
from bumble.device import Connection, Device, DeviceConfiguration
|
||||||
from bumble.hci import HCI_StatusError
|
from bumble.hci import HCI_StatusError
|
||||||
from bumble.pairing import PairingConfig
|
from bumble.pairing import PairingConfig
|
||||||
@@ -568,7 +568,9 @@ class Speaker:
|
|||||||
async def connect(self, address):
|
async def connect(self, address):
|
||||||
# Connect to the source
|
# Connect to the source
|
||||||
print(f'=== Connecting to {address}...')
|
print(f'=== Connecting to {address}...')
|
||||||
connection = await self.device.connect(address, transport=BT_BR_EDR_TRANSPORT)
|
connection = await self.device.connect(
|
||||||
|
address, transport=PhysicalTransport.BR_EDR
|
||||||
|
)
|
||||||
print(f'=== Connected to {connection.peer_address}')
|
print(f'=== Connected to {connection.peer_address}')
|
||||||
|
|
||||||
# Request authentication
|
# Request authentication
|
||||||
|
|||||||
@@ -25,8 +25,7 @@ import random
|
|||||||
import struct
|
import struct
|
||||||
from bumble.colors import color
|
from bumble.colors import color
|
||||||
from bumble.core import (
|
from bumble.core import (
|
||||||
BT_LE_TRANSPORT,
|
PhysicalTransport,
|
||||||
BT_BR_EDR_TRANSPORT,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
from bumble.hci import (
|
from bumble.hci import (
|
||||||
@@ -392,7 +391,7 @@ class Controller:
|
|||||||
role=Role.PERIPHERAL,
|
role=Role.PERIPHERAL,
|
||||||
peer_address=peer_address,
|
peer_address=peer_address,
|
||||||
link=self.link,
|
link=self.link,
|
||||||
transport=BT_LE_TRANSPORT,
|
transport=PhysicalTransport.LE,
|
||||||
link_type=HCI_Connection_Complete_Event.ACL_LINK_TYPE,
|
link_type=HCI_Connection_Complete_Event.ACL_LINK_TYPE,
|
||||||
)
|
)
|
||||||
self.peripheral_connections[peer_address] = connection
|
self.peripheral_connections[peer_address] = connection
|
||||||
@@ -452,7 +451,7 @@ class Controller:
|
|||||||
role=Role.CENTRAL,
|
role=Role.CENTRAL,
|
||||||
peer_address=peer_address,
|
peer_address=peer_address,
|
||||||
link=self.link,
|
link=self.link,
|
||||||
transport=BT_LE_TRANSPORT,
|
transport=PhysicalTransport.LE,
|
||||||
link_type=HCI_Connection_Complete_Event.ACL_LINK_TYPE,
|
link_type=HCI_Connection_Complete_Event.ACL_LINK_TYPE,
|
||||||
)
|
)
|
||||||
self.central_connections[peer_address] = connection
|
self.central_connections[peer_address] = connection
|
||||||
@@ -530,7 +529,7 @@ class Controller:
|
|||||||
|
|
||||||
def on_link_acl_data(self, sender_address, transport, data):
|
def on_link_acl_data(self, sender_address, transport, data):
|
||||||
# Look for the connection to which this data belongs
|
# Look for the connection to which this data belongs
|
||||||
if transport == BT_LE_TRANSPORT:
|
if transport == PhysicalTransport.LE:
|
||||||
connection = self.find_le_connection_by_address(sender_address)
|
connection = self.find_le_connection_by_address(sender_address)
|
||||||
else:
|
else:
|
||||||
connection = self.find_classic_connection_by_address(sender_address)
|
connection = self.find_classic_connection_by_address(sender_address)
|
||||||
@@ -695,7 +694,7 @@ class Controller:
|
|||||||
role=Role.CENTRAL,
|
role=Role.CENTRAL,
|
||||||
peer_address=peer_address,
|
peer_address=peer_address,
|
||||||
link=self.link,
|
link=self.link,
|
||||||
transport=BT_BR_EDR_TRANSPORT,
|
transport=PhysicalTransport.BR_EDR,
|
||||||
link_type=HCI_Connection_Complete_Event.ACL_LINK_TYPE,
|
link_type=HCI_Connection_Complete_Event.ACL_LINK_TYPE,
|
||||||
)
|
)
|
||||||
self.classic_connections[peer_address] = connection
|
self.classic_connections[peer_address] = connection
|
||||||
@@ -763,7 +762,7 @@ class Controller:
|
|||||||
role=Role.CENTRAL,
|
role=Role.CENTRAL,
|
||||||
peer_address=peer_address,
|
peer_address=peer_address,
|
||||||
link=self.link,
|
link=self.link,
|
||||||
transport=BT_BR_EDR_TRANSPORT,
|
transport=PhysicalTransport.BR_EDR,
|
||||||
link_type=link_type,
|
link_type=link_type,
|
||||||
)
|
)
|
||||||
self.classic_connections[peer_address] = connection
|
self.classic_connections[peer_address] = connection
|
||||||
|
|||||||
@@ -57,8 +57,7 @@ from .gatt import Attribute, Characteristic, Descriptor, Service
|
|||||||
from .host import DataPacketQueue, Host
|
from .host import DataPacketQueue, Host
|
||||||
from .profiles.gap import GenericAccessService
|
from .profiles.gap import GenericAccessService
|
||||||
from .core import (
|
from .core import (
|
||||||
BT_BR_EDR_TRANSPORT,
|
PhysicalTransport,
|
||||||
BT_LE_TRANSPORT,
|
|
||||||
AdvertisingData,
|
AdvertisingData,
|
||||||
BaseBumbleError,
|
BaseBumbleError,
|
||||||
ConnectionParameterUpdateError,
|
ConnectionParameterUpdateError,
|
||||||
@@ -1660,7 +1659,7 @@ class Connection(CompositeEventEmitter):
|
|||||||
return cls(
|
return cls(
|
||||||
device,
|
device,
|
||||||
None,
|
None,
|
||||||
BT_BR_EDR_TRANSPORT,
|
PhysicalTransport.BR_EDR,
|
||||||
device.public_address,
|
device.public_address,
|
||||||
None,
|
None,
|
||||||
peer_address,
|
peer_address,
|
||||||
@@ -1675,7 +1674,7 @@ class Connection(CompositeEventEmitter):
|
|||||||
Finish an incomplete connection upon completion.
|
Finish an incomplete connection upon completion.
|
||||||
"""
|
"""
|
||||||
assert self.handle is None
|
assert self.handle is None
|
||||||
assert self.transport == BT_BR_EDR_TRANSPORT
|
assert self.transport == PhysicalTransport.BR_EDR
|
||||||
self.handle = handle
|
self.handle = handle
|
||||||
self.parameters = parameters
|
self.parameters = parameters
|
||||||
|
|
||||||
@@ -1830,7 +1829,7 @@ class Connection(CompositeEventEmitter):
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
if self.transport == BT_LE_TRANSPORT:
|
if self.transport == PhysicalTransport.LE:
|
||||||
return (
|
return (
|
||||||
f'Connection(transport=LE, handle=0x{self.handle:04X}, '
|
f'Connection(transport=LE, handle=0x{self.handle:04X}, '
|
||||||
f'role={self.role_name}, '
|
f'role={self.role_name}, '
|
||||||
@@ -3397,7 +3396,7 @@ class Device(CompositeEventEmitter):
|
|||||||
async def connect(
|
async def connect(
|
||||||
self,
|
self,
|
||||||
peer_address: Union[hci.Address, str],
|
peer_address: Union[hci.Address, str],
|
||||||
transport: core.PhysicalTransport = BT_LE_TRANSPORT,
|
transport: core.PhysicalTransport = PhysicalTransport.LE,
|
||||||
connection_parameters_preferences: Optional[
|
connection_parameters_preferences: Optional[
|
||||||
dict[hci.Phy, ConnectionParametersPreferences]
|
dict[hci.Phy, ConnectionParametersPreferences]
|
||||||
] = None,
|
] = None,
|
||||||
@@ -3447,23 +3446,23 @@ class Device(CompositeEventEmitter):
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
# Check parameters
|
# Check parameters
|
||||||
if transport not in (BT_LE_TRANSPORT, BT_BR_EDR_TRANSPORT):
|
if transport not in (PhysicalTransport.LE, PhysicalTransport.BR_EDR):
|
||||||
raise InvalidArgumentError('invalid transport')
|
raise InvalidArgumentError('invalid transport')
|
||||||
transport = core.PhysicalTransport(transport)
|
transport = core.PhysicalTransport(transport)
|
||||||
|
|
||||||
# Adjust the transport automatically if we need to
|
# Adjust the transport automatically if we need to
|
||||||
if transport == BT_LE_TRANSPORT and not self.le_enabled:
|
if transport == PhysicalTransport.LE and not self.le_enabled:
|
||||||
transport = BT_BR_EDR_TRANSPORT
|
transport = PhysicalTransport.BR_EDR
|
||||||
elif transport == BT_BR_EDR_TRANSPORT and not self.classic_enabled:
|
elif transport == PhysicalTransport.BR_EDR and not self.classic_enabled:
|
||||||
transport = BT_LE_TRANSPORT
|
transport = PhysicalTransport.LE
|
||||||
|
|
||||||
# Check that there isn't already a pending connection
|
# Check that there isn't already a pending connection
|
||||||
if transport == BT_LE_TRANSPORT and self.is_le_connecting:
|
if transport == PhysicalTransport.LE and self.is_le_connecting:
|
||||||
raise InvalidStateError('connection already pending')
|
raise InvalidStateError('connection already pending')
|
||||||
|
|
||||||
if isinstance(peer_address, str):
|
if isinstance(peer_address, str):
|
||||||
try:
|
try:
|
||||||
if transport == BT_LE_TRANSPORT and peer_address.endswith('@'):
|
if transport == PhysicalTransport.LE and peer_address.endswith('@'):
|
||||||
peer_address = hci.Address.from_string_for_transport(
|
peer_address = hci.Address.from_string_for_transport(
|
||||||
peer_address[:-1], transport
|
peer_address[:-1], transport
|
||||||
)
|
)
|
||||||
@@ -3483,21 +3482,21 @@ class Device(CompositeEventEmitter):
|
|||||||
else:
|
else:
|
||||||
# All BR/EDR addresses should be public addresses
|
# All BR/EDR addresses should be public addresses
|
||||||
if (
|
if (
|
||||||
transport == BT_BR_EDR_TRANSPORT
|
transport == PhysicalTransport.BR_EDR
|
||||||
and peer_address.address_type != hci.Address.PUBLIC_DEVICE_ADDRESS
|
and peer_address.address_type != hci.Address.PUBLIC_DEVICE_ADDRESS
|
||||||
):
|
):
|
||||||
raise InvalidArgumentError('BR/EDR addresses must be PUBLIC')
|
raise InvalidArgumentError('BR/EDR addresses must be PUBLIC')
|
||||||
|
|
||||||
assert isinstance(peer_address, hci.Address)
|
assert isinstance(peer_address, hci.Address)
|
||||||
|
|
||||||
if transport == BT_LE_TRANSPORT and always_resolve:
|
if transport == PhysicalTransport.LE and always_resolve:
|
||||||
logger.debug('resolving address')
|
logger.debug('resolving address')
|
||||||
peer_address = await self.find_peer_by_identity_address(
|
peer_address = await self.find_peer_by_identity_address(
|
||||||
peer_address
|
peer_address
|
||||||
) # TODO: timeout
|
) # TODO: timeout
|
||||||
|
|
||||||
def on_connection(connection):
|
def on_connection(connection):
|
||||||
if transport == BT_LE_TRANSPORT or (
|
if transport == PhysicalTransport.LE or (
|
||||||
# match BR/EDR connection event against peer address
|
# match BR/EDR connection event against peer address
|
||||||
connection.transport == transport
|
connection.transport == transport
|
||||||
and connection.peer_address == peer_address
|
and connection.peer_address == peer_address
|
||||||
@@ -3505,7 +3504,7 @@ class Device(CompositeEventEmitter):
|
|||||||
pending_connection.set_result(connection)
|
pending_connection.set_result(connection)
|
||||||
|
|
||||||
def on_connection_failure(error):
|
def on_connection_failure(error):
|
||||||
if transport == BT_LE_TRANSPORT or (
|
if transport == PhysicalTransport.LE or (
|
||||||
# match BR/EDR connection failure event against peer address
|
# match BR/EDR connection failure event against peer address
|
||||||
error.transport == transport
|
error.transport == transport
|
||||||
and error.peer_address == peer_address
|
and error.peer_address == peer_address
|
||||||
@@ -3519,7 +3518,7 @@ class Device(CompositeEventEmitter):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
# Tell the controller to connect
|
# Tell the controller to connect
|
||||||
if transport == BT_LE_TRANSPORT:
|
if transport == PhysicalTransport.LE:
|
||||||
if connection_parameters_preferences is None:
|
if connection_parameters_preferences is None:
|
||||||
if connection_parameters_preferences is None:
|
if connection_parameters_preferences is None:
|
||||||
connection_parameters_preferences = {
|
connection_parameters_preferences = {
|
||||||
@@ -3664,7 +3663,7 @@ class Device(CompositeEventEmitter):
|
|||||||
raise hci.HCI_StatusError(result)
|
raise hci.HCI_StatusError(result)
|
||||||
|
|
||||||
# Wait for the connection process to complete
|
# Wait for the connection process to complete
|
||||||
if transport == BT_LE_TRANSPORT:
|
if transport == PhysicalTransport.LE:
|
||||||
self.le_connecting = True
|
self.le_connecting = True
|
||||||
|
|
||||||
if timeout is None:
|
if timeout is None:
|
||||||
@@ -3675,7 +3674,7 @@ class Device(CompositeEventEmitter):
|
|||||||
asyncio.shield(pending_connection), timeout
|
asyncio.shield(pending_connection), timeout
|
||||||
)
|
)
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
if transport == BT_LE_TRANSPORT:
|
if transport == PhysicalTransport.LE:
|
||||||
await self.send_command(
|
await self.send_command(
|
||||||
hci.HCI_LE_Create_Connection_Cancel_Command()
|
hci.HCI_LE_Create_Connection_Cancel_Command()
|
||||||
)
|
)
|
||||||
@@ -3691,7 +3690,7 @@ class Device(CompositeEventEmitter):
|
|||||||
finally:
|
finally:
|
||||||
self.remove_listener('connection', on_connection)
|
self.remove_listener('connection', on_connection)
|
||||||
self.remove_listener('connection_failure', on_connection_failure)
|
self.remove_listener('connection_failure', on_connection_failure)
|
||||||
if transport == BT_LE_TRANSPORT:
|
if transport == PhysicalTransport.LE:
|
||||||
self.le_connecting = False
|
self.le_connecting = False
|
||||||
self.connect_own_address_type = None
|
self.connect_own_address_type = None
|
||||||
else:
|
else:
|
||||||
@@ -3721,7 +3720,7 @@ class Device(CompositeEventEmitter):
|
|||||||
# If the address is not parsable, assume it is a name instead
|
# If the address is not parsable, assume it is a name instead
|
||||||
logger.debug('looking for peer by name')
|
logger.debug('looking for peer by name')
|
||||||
peer_address = await self.find_peer_by_name(
|
peer_address = await self.find_peer_by_name(
|
||||||
peer_address, BT_BR_EDR_TRANSPORT
|
peer_address, PhysicalTransport.BR_EDR
|
||||||
) # TODO: timeout
|
) # TODO: timeout
|
||||||
|
|
||||||
assert isinstance(peer_address, hci.Address)
|
assert isinstance(peer_address, hci.Address)
|
||||||
@@ -3771,14 +3770,14 @@ class Device(CompositeEventEmitter):
|
|||||||
|
|
||||||
def on_connection(connection):
|
def on_connection(connection):
|
||||||
if (
|
if (
|
||||||
connection.transport == BT_BR_EDR_TRANSPORT
|
connection.transport == PhysicalTransport.BR_EDR
|
||||||
and connection.peer_address == peer_address
|
and connection.peer_address == peer_address
|
||||||
):
|
):
|
||||||
pending_connection.set_result(connection)
|
pending_connection.set_result(connection)
|
||||||
|
|
||||||
def on_connection_failure(error):
|
def on_connection_failure(error):
|
||||||
if (
|
if (
|
||||||
error.transport == BT_BR_EDR_TRANSPORT
|
error.transport == PhysicalTransport.BR_EDR
|
||||||
and error.peer_address == peer_address
|
and error.peer_address == peer_address
|
||||||
):
|
):
|
||||||
pending_connection.set_exception(error)
|
pending_connection.set_exception(error)
|
||||||
@@ -3848,7 +3847,7 @@ class Device(CompositeEventEmitter):
|
|||||||
# If the address is not parsable, assume it is a name instead
|
# If the address is not parsable, assume it is a name instead
|
||||||
logger.debug('looking for peer by name')
|
logger.debug('looking for peer by name')
|
||||||
peer_address = await self.find_peer_by_name(
|
peer_address = await self.find_peer_by_name(
|
||||||
peer_address, BT_BR_EDR_TRANSPORT
|
peer_address, PhysicalTransport.BR_EDR
|
||||||
) # TODO: timeout
|
) # TODO: timeout
|
||||||
|
|
||||||
await self.send_command(
|
await self.send_command(
|
||||||
@@ -4031,7 +4030,7 @@ class Device(CompositeEventEmitter):
|
|||||||
check_result=True,
|
check_result=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def find_peer_by_name(self, name, transport=BT_LE_TRANSPORT):
|
async def find_peer_by_name(self, name, transport=PhysicalTransport.LE):
|
||||||
"""
|
"""
|
||||||
Scan for a peer with a given name and return its address.
|
Scan for a peer with a given name and return its address.
|
||||||
"""
|
"""
|
||||||
@@ -4050,7 +4049,7 @@ class Device(CompositeEventEmitter):
|
|||||||
was_scanning = self.scanning
|
was_scanning = self.scanning
|
||||||
was_discovering = self.discovering
|
was_discovering = self.discovering
|
||||||
try:
|
try:
|
||||||
if transport == BT_LE_TRANSPORT:
|
if transport == PhysicalTransport.LE:
|
||||||
event_name = 'advertisement'
|
event_name = 'advertisement'
|
||||||
listener = self.on(
|
listener = self.on(
|
||||||
event_name,
|
event_name,
|
||||||
@@ -4062,7 +4061,7 @@ class Device(CompositeEventEmitter):
|
|||||||
if not self.scanning:
|
if not self.scanning:
|
||||||
await self.start_scanning(filter_duplicates=True)
|
await self.start_scanning(filter_duplicates=True)
|
||||||
|
|
||||||
elif transport == BT_BR_EDR_TRANSPORT:
|
elif transport == PhysicalTransport.BR_EDR:
|
||||||
event_name = 'inquiry_result'
|
event_name = 'inquiry_result'
|
||||||
listener = self.on(
|
listener = self.on(
|
||||||
event_name,
|
event_name,
|
||||||
@@ -4081,9 +4080,9 @@ class Device(CompositeEventEmitter):
|
|||||||
if listener is not None:
|
if listener is not None:
|
||||||
self.remove_listener(event_name, listener)
|
self.remove_listener(event_name, listener)
|
||||||
|
|
||||||
if transport == BT_LE_TRANSPORT and not was_scanning:
|
if transport == PhysicalTransport.LE and not was_scanning:
|
||||||
await self.stop_scanning()
|
await self.stop_scanning()
|
||||||
elif transport == BT_BR_EDR_TRANSPORT and not was_discovering:
|
elif transport == PhysicalTransport.BR_EDR and not was_discovering:
|
||||||
await self.stop_discovery()
|
await self.stop_discovery()
|
||||||
|
|
||||||
async def find_peer_by_identity_address(
|
async def find_peer_by_identity_address(
|
||||||
@@ -4238,7 +4237,7 @@ class Device(CompositeEventEmitter):
|
|||||||
)
|
)
|
||||||
|
|
||||||
async def encrypt(self, connection, enable=True):
|
async def encrypt(self, connection, enable=True):
|
||||||
if not enable and connection.transport == BT_LE_TRANSPORT:
|
if not enable and connection.transport == PhysicalTransport.LE:
|
||||||
raise InvalidArgumentError('`enable` parameter is classic only.')
|
raise InvalidArgumentError('`enable` parameter is classic only.')
|
||||||
|
|
||||||
# Set up event handlers
|
# Set up event handlers
|
||||||
@@ -4255,7 +4254,7 @@ class Device(CompositeEventEmitter):
|
|||||||
|
|
||||||
# Request the encryption
|
# Request the encryption
|
||||||
try:
|
try:
|
||||||
if connection.transport == BT_LE_TRANSPORT:
|
if connection.transport == PhysicalTransport.LE:
|
||||||
# Look for a key in the key store
|
# Look for a key in the key store
|
||||||
if self.keystore is None:
|
if self.keystore is None:
|
||||||
raise InvalidOperationError('no key store')
|
raise InvalidOperationError('no key store')
|
||||||
@@ -4276,7 +4275,7 @@ class Device(CompositeEventEmitter):
|
|||||||
else:
|
else:
|
||||||
raise InvalidOperationError('no LTK found for peer')
|
raise InvalidOperationError('no LTK found for peer')
|
||||||
|
|
||||||
if connection.role != hci.HCI_CENTRAL_ROLE:
|
if connection.role != hci.Role.CENTRAL:
|
||||||
raise InvalidStateError('only centrals can start encryption')
|
raise InvalidStateError('only centrals can start encryption')
|
||||||
|
|
||||||
result = await self.send_command(
|
result = await self.send_command(
|
||||||
@@ -4932,7 +4931,7 @@ class Device(CompositeEventEmitter):
|
|||||||
self.abort_on('flush', self.update_keys(str(bd_addr), pairing_keys))
|
self.abort_on('flush', self.update_keys(str(bd_addr), pairing_keys))
|
||||||
|
|
||||||
if connection := self.find_connection_by_bd_addr(
|
if connection := self.find_connection_by_bd_addr(
|
||||||
bd_addr, transport=BT_BR_EDR_TRANSPORT
|
bd_addr, transport=PhysicalTransport.BR_EDR
|
||||||
):
|
):
|
||||||
connection.link_key_type = key_type
|
connection.link_key_type = key_type
|
||||||
|
|
||||||
@@ -5232,7 +5231,7 @@ class Device(CompositeEventEmitter):
|
|||||||
'new connection reuses the same handle as a previous connection'
|
'new connection reuses the same handle as a previous connection'
|
||||||
)
|
)
|
||||||
|
|
||||||
if transport == BT_BR_EDR_TRANSPORT:
|
if transport == PhysicalTransport.BR_EDR:
|
||||||
# Create a new connection
|
# Create a new connection
|
||||||
connection = self.pending_connections.pop(peer_address)
|
connection = self.pending_connections.pop(peer_address)
|
||||||
connection.complete(connection_handle, connection_parameters)
|
connection.complete(connection_handle, connection_parameters)
|
||||||
@@ -5255,7 +5254,7 @@ class Device(CompositeEventEmitter):
|
|||||||
|
|
||||||
self_address = None
|
self_address = None
|
||||||
own_address_type: Optional[hci.OwnAddressType] = None
|
own_address_type: Optional[hci.OwnAddressType] = None
|
||||||
if role == hci.HCI_CENTRAL_ROLE:
|
if role == hci.Role.CENTRAL:
|
||||||
own_address_type = self.connect_own_address_type
|
own_address_type = self.connect_own_address_type
|
||||||
assert own_address_type is not None
|
assert own_address_type is not None
|
||||||
else:
|
else:
|
||||||
@@ -5302,7 +5301,7 @@ class Device(CompositeEventEmitter):
|
|||||||
)
|
)
|
||||||
self.connections[connection_handle] = connection
|
self.connections[connection_handle] = connection
|
||||||
|
|
||||||
if role == hci.HCI_PERIPHERAL_ROLE and self.legacy_advertiser:
|
if role == hci.Role.PERIPHERAL and self.legacy_advertiser:
|
||||||
if self.legacy_advertiser.auto_restart:
|
if self.legacy_advertiser.auto_restart:
|
||||||
advertiser = self.legacy_advertiser
|
advertiser = self.legacy_advertiser
|
||||||
connection.once(
|
connection.once(
|
||||||
@@ -5312,12 +5311,12 @@ class Device(CompositeEventEmitter):
|
|||||||
else:
|
else:
|
||||||
self.legacy_advertiser = None
|
self.legacy_advertiser = None
|
||||||
|
|
||||||
if role == hci.HCI_CENTRAL_ROLE or not self.supports_le_extended_advertising:
|
if role == hci.Role.CENTRAL or not self.supports_le_extended_advertising:
|
||||||
# We can emit now, we have all the info we need
|
# We can emit now, we have all the info we need
|
||||||
self.emit('connection', connection)
|
self.emit('connection', connection)
|
||||||
return
|
return
|
||||||
|
|
||||||
if role == hci.HCI_PERIPHERAL_ROLE and self.supports_le_extended_advertising:
|
if role == hci.Role.PERIPHERAL and self.supports_le_extended_advertising:
|
||||||
if advertising_set := self.connecting_extended_advertising_sets.pop(
|
if advertising_set := self.connecting_extended_advertising_sets.pop(
|
||||||
connection_handle, None
|
connection_handle, None
|
||||||
):
|
):
|
||||||
@@ -5334,7 +5333,7 @@ class Device(CompositeEventEmitter):
|
|||||||
|
|
||||||
# For directed advertising, this means a timeout
|
# For directed advertising, this means a timeout
|
||||||
if (
|
if (
|
||||||
transport == BT_LE_TRANSPORT
|
transport == PhysicalTransport.LE
|
||||||
and self.legacy_advertiser
|
and self.legacy_advertiser
|
||||||
and self.legacy_advertiser.advertising_type.is_directed
|
and self.legacy_advertiser.advertising_type.is_directed
|
||||||
):
|
):
|
||||||
@@ -5361,7 +5360,7 @@ class Device(CompositeEventEmitter):
|
|||||||
hci.HCI_Connection_Complete_Event.ESCO_LINK_TYPE,
|
hci.HCI_Connection_Complete_Event.ESCO_LINK_TYPE,
|
||||||
):
|
):
|
||||||
if connection := self.find_connection_by_bd_addr(
|
if connection := self.find_connection_by_bd_addr(
|
||||||
bd_addr, transport=BT_BR_EDR_TRANSPORT
|
bd_addr, transport=PhysicalTransport.BR_EDR
|
||||||
):
|
):
|
||||||
self.emit('sco_request', connection, link_type)
|
self.emit('sco_request', connection, link_type)
|
||||||
else:
|
else:
|
||||||
@@ -5812,14 +5811,14 @@ class Device(CompositeEventEmitter):
|
|||||||
connection.encryption = encryption
|
connection.encryption = encryption
|
||||||
if (
|
if (
|
||||||
not connection.authenticated
|
not connection.authenticated
|
||||||
and connection.transport == BT_BR_EDR_TRANSPORT
|
and connection.transport == PhysicalTransport.BR_EDR
|
||||||
and encryption == hci.HCI_Encryption_Change_Event.AES_CCM
|
and encryption == hci.HCI_Encryption_Change_Event.AES_CCM
|
||||||
):
|
):
|
||||||
connection.authenticated = True
|
connection.authenticated = True
|
||||||
connection.sc = True
|
connection.sc = True
|
||||||
if (
|
if (
|
||||||
not connection.authenticated
|
not connection.authenticated
|
||||||
and connection.transport == BT_LE_TRANSPORT
|
and connection.transport == PhysicalTransport.LE
|
||||||
and encryption == hci.HCI_Encryption_Change_Event.E0_OR_AES_CCM
|
and encryption == hci.HCI_Encryption_Change_Event.E0_OR_AES_CCM
|
||||||
):
|
):
|
||||||
connection.authenticated = True
|
connection.authenticated = True
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ from typing_extensions import Self
|
|||||||
from bumble import crypto
|
from bumble import crypto
|
||||||
from bumble.colors import color
|
from bumble.colors import color
|
||||||
from bumble.core import (
|
from bumble.core import (
|
||||||
BT_BR_EDR_TRANSPORT,
|
PhysicalTransport,
|
||||||
AdvertisingData,
|
AdvertisingData,
|
||||||
DeviceClass,
|
DeviceClass,
|
||||||
InvalidArgumentError,
|
InvalidArgumentError,
|
||||||
@@ -1976,7 +1976,7 @@ class Address:
|
|||||||
def from_string_for_transport(
|
def from_string_for_transport(
|
||||||
cls: type[Self], string: str, transport: PhysicalTransport
|
cls: type[Self], string: str, transport: PhysicalTransport
|
||||||
) -> Self:
|
) -> Self:
|
||||||
if transport == BT_BR_EDR_TRANSPORT:
|
if transport == PhysicalTransport.BR_EDR:
|
||||||
address_type = Address.PUBLIC_DEVICE_ADDRESS
|
address_type = Address.PUBLIC_DEVICE_ADDRESS
|
||||||
else:
|
else:
|
||||||
address_type = Address.RANDOM_DEVICE_ADDRESS
|
address_type = Address.RANDOM_DEVICE_ADDRESS
|
||||||
|
|||||||
@@ -42,8 +42,7 @@ from bumble.snoop import Snooper
|
|||||||
from bumble import drivers
|
from bumble import drivers
|
||||||
from bumble import hci
|
from bumble import hci
|
||||||
from bumble.core import (
|
from bumble.core import (
|
||||||
BT_BR_EDR_TRANSPORT,
|
PhysicalTransport,
|
||||||
BT_LE_TRANSPORT,
|
|
||||||
PhysicalTransport,
|
PhysicalTransport,
|
||||||
ConnectionPHY,
|
ConnectionPHY,
|
||||||
ConnectionParameters,
|
ConnectionParameters,
|
||||||
@@ -200,7 +199,7 @@ class Connection:
|
|||||||
self.transport = transport
|
self.transport = transport
|
||||||
acl_packet_queue: Optional[DataPacketQueue] = (
|
acl_packet_queue: Optional[DataPacketQueue] = (
|
||||||
host.le_acl_packet_queue
|
host.le_acl_packet_queue
|
||||||
if transport == BT_LE_TRANSPORT
|
if transport == PhysicalTransport.LE
|
||||||
else host.acl_packet_queue
|
else host.acl_packet_queue
|
||||||
)
|
)
|
||||||
assert acl_packet_queue
|
assert acl_packet_queue
|
||||||
@@ -967,7 +966,7 @@ class Host(AbortableEventEmitter):
|
|||||||
self,
|
self,
|
||||||
event.connection_handle,
|
event.connection_handle,
|
||||||
event.peer_address,
|
event.peer_address,
|
||||||
BT_LE_TRANSPORT,
|
PhysicalTransport.LE,
|
||||||
)
|
)
|
||||||
self.connections[event.connection_handle] = connection
|
self.connections[event.connection_handle] = connection
|
||||||
|
|
||||||
@@ -980,7 +979,7 @@ class Host(AbortableEventEmitter):
|
|||||||
self.emit(
|
self.emit(
|
||||||
'connection',
|
'connection',
|
||||||
event.connection_handle,
|
event.connection_handle,
|
||||||
BT_LE_TRANSPORT,
|
PhysicalTransport.LE,
|
||||||
event.peer_address,
|
event.peer_address,
|
||||||
getattr(event, 'local_resolvable_private_address', None),
|
getattr(event, 'local_resolvable_private_address', None),
|
||||||
getattr(event, 'peer_resolvable_private_address', None),
|
getattr(event, 'peer_resolvable_private_address', None),
|
||||||
@@ -992,7 +991,10 @@ class Host(AbortableEventEmitter):
|
|||||||
|
|
||||||
# Notify the listeners
|
# Notify the listeners
|
||||||
self.emit(
|
self.emit(
|
||||||
'connection_failure', BT_LE_TRANSPORT, event.peer_address, event.status
|
'connection_failure',
|
||||||
|
PhysicalTransport.LE,
|
||||||
|
event.peer_address,
|
||||||
|
event.status,
|
||||||
)
|
)
|
||||||
|
|
||||||
def on_hci_le_enhanced_connection_complete_event(self, event):
|
def on_hci_le_enhanced_connection_complete_event(self, event):
|
||||||
@@ -1017,7 +1019,7 @@ class Host(AbortableEventEmitter):
|
|||||||
self,
|
self,
|
||||||
event.connection_handle,
|
event.connection_handle,
|
||||||
event.bd_addr,
|
event.bd_addr,
|
||||||
BT_BR_EDR_TRANSPORT,
|
PhysicalTransport.BR_EDR,
|
||||||
)
|
)
|
||||||
self.connections[event.connection_handle] = connection
|
self.connections[event.connection_handle] = connection
|
||||||
|
|
||||||
@@ -1025,7 +1027,7 @@ class Host(AbortableEventEmitter):
|
|||||||
self.emit(
|
self.emit(
|
||||||
'connection',
|
'connection',
|
||||||
event.connection_handle,
|
event.connection_handle,
|
||||||
BT_BR_EDR_TRANSPORT,
|
PhysicalTransport.BR_EDR,
|
||||||
event.bd_addr,
|
event.bd_addr,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
@@ -1037,7 +1039,10 @@ class Host(AbortableEventEmitter):
|
|||||||
|
|
||||||
# Notify the client
|
# Notify the client
|
||||||
self.emit(
|
self.emit(
|
||||||
'connection_failure', BT_BR_EDR_TRANSPORT, event.bd_addr, event.status
|
'connection_failure',
|
||||||
|
PhysicalTransport.BR_EDR,
|
||||||
|
event.bd_addr,
|
||||||
|
event.status,
|
||||||
)
|
)
|
||||||
|
|
||||||
def on_hci_disconnection_complete_event(self, event):
|
def on_hci_disconnection_complete_event(self, event):
|
||||||
|
|||||||
@@ -20,8 +20,7 @@ import asyncio
|
|||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from bumble.core import (
|
from bumble.core import (
|
||||||
BT_BR_EDR_TRANSPORT,
|
PhysicalTransport,
|
||||||
BT_LE_TRANSPORT,
|
|
||||||
InvalidStateError,
|
InvalidStateError,
|
||||||
)
|
)
|
||||||
from bumble.colors import color
|
from bumble.colors import color
|
||||||
@@ -116,10 +115,10 @@ class LocalLink:
|
|||||||
|
|
||||||
def send_acl_data(self, sender_controller, destination_address, transport, data):
|
def send_acl_data(self, sender_controller, destination_address, transport, data):
|
||||||
# Send the data to the first controller with a matching address
|
# Send the data to the first controller with a matching address
|
||||||
if transport == BT_LE_TRANSPORT:
|
if transport == PhysicalTransport.LE:
|
||||||
destination_controller = self.find_controller(destination_address)
|
destination_controller = self.find_controller(destination_address)
|
||||||
source_address = sender_controller.random_address
|
source_address = sender_controller.random_address
|
||||||
elif transport == BT_BR_EDR_TRANSPORT:
|
elif transport == PhysicalTransport.BR_EDR:
|
||||||
destination_controller = self.find_classic_controller(destination_address)
|
destination_controller = self.find_classic_controller(destination_address)
|
||||||
source_address = sender_controller.public_address
|
source_address = sender_controller.public_address
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -23,8 +23,7 @@ import struct
|
|||||||
from . import utils
|
from . import utils
|
||||||
from .config import Config
|
from .config import Config
|
||||||
from bumble.core import (
|
from bumble.core import (
|
||||||
BT_BR_EDR_TRANSPORT,
|
PhysicalTransport,
|
||||||
BT_LE_TRANSPORT,
|
|
||||||
UUID,
|
UUID,
|
||||||
AdvertisingData,
|
AdvertisingData,
|
||||||
Appearance,
|
Appearance,
|
||||||
@@ -185,7 +184,7 @@ class HostService(HostServicer):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
connection = await self.device.connect(
|
connection = await self.device.connect(
|
||||||
address, transport=BT_BR_EDR_TRANSPORT
|
address, transport=PhysicalTransport.BR_EDR
|
||||||
)
|
)
|
||||||
except ConnectionError as e:
|
except ConnectionError as e:
|
||||||
if e.error_code == HCI_PAGE_TIMEOUT_ERROR:
|
if e.error_code == HCI_PAGE_TIMEOUT_ERROR:
|
||||||
@@ -218,7 +217,7 @@ class HostService(HostServicer):
|
|||||||
self.log.debug(f"WaitConnection from {address}...")
|
self.log.debug(f"WaitConnection from {address}...")
|
||||||
|
|
||||||
connection = self.device.find_connection_by_bd_addr(
|
connection = self.device.find_connection_by_bd_addr(
|
||||||
address, transport=BT_BR_EDR_TRANSPORT
|
address, transport=PhysicalTransport.BR_EDR
|
||||||
)
|
)
|
||||||
if connection and id(connection) in self.waited_connections:
|
if connection and id(connection) in self.waited_connections:
|
||||||
# this connection was already returned: wait for a new one.
|
# this connection was already returned: wait for a new one.
|
||||||
@@ -250,7 +249,7 @@ class HostService(HostServicer):
|
|||||||
try:
|
try:
|
||||||
connection = await self.device.connect(
|
connection = await self.device.connect(
|
||||||
address,
|
address,
|
||||||
transport=BT_LE_TRANSPORT,
|
transport=PhysicalTransport.LE,
|
||||||
own_address_type=OwnAddressType(request.own_address_type),
|
own_address_type=OwnAddressType(request.own_address_type),
|
||||||
)
|
)
|
||||||
except ConnectionError as e:
|
except ConnectionError as e:
|
||||||
@@ -378,7 +377,7 @@ class HostService(HostServicer):
|
|||||||
|
|
||||||
def on_connection(connection: bumble.device.Connection) -> None:
|
def on_connection(connection: bumble.device.Connection) -> None:
|
||||||
if (
|
if (
|
||||||
connection.transport == BT_LE_TRANSPORT
|
connection.transport == PhysicalTransport.LE
|
||||||
and connection.role == Role.PERIPHERAL
|
and connection.role == Role.PERIPHERAL
|
||||||
):
|
):
|
||||||
connections.put_nowait(connection)
|
connections.put_nowait(connection)
|
||||||
@@ -496,7 +495,7 @@ class HostService(HostServicer):
|
|||||||
|
|
||||||
def on_connection(connection: bumble.device.Connection) -> None:
|
def on_connection(connection: bumble.device.Connection) -> None:
|
||||||
if (
|
if (
|
||||||
connection.transport == BT_LE_TRANSPORT
|
connection.transport == PhysicalTransport.LE
|
||||||
and connection.role == Role.PERIPHERAL
|
and connection.role == Role.PERIPHERAL
|
||||||
):
|
):
|
||||||
connections.put_nowait(connection)
|
connections.put_nowait(connection)
|
||||||
|
|||||||
@@ -22,8 +22,7 @@ from . import utils
|
|||||||
from .config import Config
|
from .config import Config
|
||||||
from bumble import hci
|
from bumble import hci
|
||||||
from bumble.core import (
|
from bumble.core import (
|
||||||
BT_BR_EDR_TRANSPORT,
|
PhysicalTransport,
|
||||||
BT_LE_TRANSPORT,
|
|
||||||
ProtocolError,
|
ProtocolError,
|
||||||
)
|
)
|
||||||
from bumble.device import Connection as BumbleConnection, Device
|
from bumble.device import Connection as BumbleConnection, Device
|
||||||
@@ -94,7 +93,7 @@ class PairingDelegate(BasePairingDelegate):
|
|||||||
else:
|
else:
|
||||||
# In BR/EDR, connection may not be complete,
|
# In BR/EDR, connection may not be complete,
|
||||||
# use address instead
|
# use address instead
|
||||||
assert self.connection.transport == BT_BR_EDR_TRANSPORT
|
assert self.connection.transport == PhysicalTransport.BR_EDR
|
||||||
ev.address = bytes(reversed(bytes(self.connection.peer_address)))
|
ev.address = bytes(reversed(bytes(self.connection.peer_address)))
|
||||||
|
|
||||||
return ev
|
return ev
|
||||||
@@ -173,7 +172,7 @@ class PairingDelegate(BasePairingDelegate):
|
|||||||
|
|
||||||
async def display_number(self, number: int, digits: int = 6) -> None:
|
async def display_number(self, number: int, digits: int = 6) -> None:
|
||||||
if (
|
if (
|
||||||
self.connection.transport == BT_BR_EDR_TRANSPORT
|
self.connection.transport == PhysicalTransport.BR_EDR
|
||||||
and self.io_capability == BasePairingDelegate.DISPLAY_OUTPUT_ONLY
|
and self.io_capability == BasePairingDelegate.DISPLAY_OUTPUT_ONLY
|
||||||
):
|
):
|
||||||
return
|
return
|
||||||
@@ -286,7 +285,7 @@ class SecurityService(SecurityServicer):
|
|||||||
|
|
||||||
oneof = request.WhichOneof('level')
|
oneof = request.WhichOneof('level')
|
||||||
level = getattr(request, oneof)
|
level = getattr(request, oneof)
|
||||||
assert {BT_BR_EDR_TRANSPORT: 'classic', BT_LE_TRANSPORT: 'le'}[
|
assert {PhysicalTransport.BR_EDR: 'classic', PhysicalTransport.LE: 'le'}[
|
||||||
connection.transport
|
connection.transport
|
||||||
] == oneof
|
] == oneof
|
||||||
|
|
||||||
@@ -316,7 +315,7 @@ class SecurityService(SecurityServicer):
|
|||||||
security_result.set_result('connection_died')
|
security_result.set_result('connection_died')
|
||||||
|
|
||||||
if (
|
if (
|
||||||
connection.transport == BT_LE_TRANSPORT
|
connection.transport == PhysicalTransport.LE
|
||||||
and connection.role == Role.PERIPHERAL
|
and connection.role == Role.PERIPHERAL
|
||||||
):
|
):
|
||||||
connection.request_pairing()
|
connection.request_pairing()
|
||||||
@@ -378,7 +377,7 @@ class SecurityService(SecurityServicer):
|
|||||||
|
|
||||||
assert request.level
|
assert request.level
|
||||||
level = request.level
|
level = request.level
|
||||||
assert {BT_BR_EDR_TRANSPORT: 'classic', BT_LE_TRANSPORT: 'le'}[
|
assert {PhysicalTransport.BR_EDR: 'classic', PhysicalTransport.LE: 'le'}[
|
||||||
connection.transport
|
connection.transport
|
||||||
] == request.level_variant()
|
] == request.level_variant()
|
||||||
|
|
||||||
@@ -426,7 +425,7 @@ class SecurityService(SecurityServicer):
|
|||||||
self.log.debug('Wait for security: done')
|
self.log.debug('Wait for security: done')
|
||||||
wait_for_security.set_result('success')
|
wait_for_security.set_result('success')
|
||||||
elif (
|
elif (
|
||||||
connection.transport == BT_BR_EDR_TRANSPORT
|
connection.transport == PhysicalTransport.BR_EDR
|
||||||
and self.need_authentication(connection, level)
|
and self.need_authentication(connection, level)
|
||||||
):
|
):
|
||||||
nonlocal authenticate_task
|
nonlocal authenticate_task
|
||||||
@@ -504,12 +503,12 @@ class SecurityService(SecurityServicer):
|
|||||||
return BR_LEVEL_REACHED[level](connection)
|
return BR_LEVEL_REACHED[level](connection)
|
||||||
|
|
||||||
def need_pairing(self, connection: BumbleConnection, level: int) -> bool:
|
def need_pairing(self, connection: BumbleConnection, level: int) -> bool:
|
||||||
if connection.transport == BT_LE_TRANSPORT:
|
if connection.transport == PhysicalTransport.LE:
|
||||||
return level >= LE_LEVEL3 and not connection.authenticated
|
return level >= LE_LEVEL3 and not connection.authenticated
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def need_authentication(self, connection: BumbleConnection, level: int) -> bool:
|
def need_authentication(self, connection: BumbleConnection, level: int) -> bool:
|
||||||
if connection.transport == BT_LE_TRANSPORT:
|
if connection.transport == PhysicalTransport.LE:
|
||||||
return False
|
return False
|
||||||
if level == LEVEL2 and connection.encryption != 0:
|
if level == LEVEL2 and connection.encryption != 0:
|
||||||
return not connection.authenticated
|
return not connection.authenticated
|
||||||
@@ -517,7 +516,7 @@ class SecurityService(SecurityServicer):
|
|||||||
|
|
||||||
def need_encryption(self, connection: BumbleConnection, level: int) -> bool:
|
def need_encryption(self, connection: BumbleConnection, level: int) -> bool:
|
||||||
# TODO(abel): need to support MITM
|
# TODO(abel): need to support MITM
|
||||||
if connection.transport == BT_LE_TRANSPORT:
|
if connection.transport == PhysicalTransport.LE:
|
||||||
return level == LE_LEVEL2 and not connection.encryption
|
return level == LE_LEVEL2 and not connection.encryption
|
||||||
return level >= LEVEL2 and not connection.encryption
|
return level >= LEVEL2 and not connection.encryption
|
||||||
|
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ class CoordinatedSetIdentificationService(gatt.TemplateService):
|
|||||||
else:
|
else:
|
||||||
assert connection
|
assert connection
|
||||||
|
|
||||||
if connection.transport == core.BT_LE_TRANSPORT:
|
if connection.transport == core.PhysicalTransport.LE:
|
||||||
key = await connection.device.get_long_term_key(
|
key = await connection.device.get_long_term_key(
|
||||||
connection_handle=connection.handle, rand=b'', ediv=0
|
connection_handle=connection.handle, rand=b'', ediv=0
|
||||||
)
|
)
|
||||||
@@ -242,7 +242,7 @@ class CoordinatedSetIdentificationProxy(gatt_client.ProfileServiceProxy):
|
|||||||
else:
|
else:
|
||||||
connection = self.service_proxy.client.connection
|
connection = self.service_proxy.client.connection
|
||||||
device = connection.device
|
device = connection.device
|
||||||
if connection.transport == core.BT_LE_TRANSPORT:
|
if connection.transport == core.PhysicalTransport.LE:
|
||||||
key = await device.get_long_term_key(
|
key = await device.get_long_term_key(
|
||||||
connection_handle=connection.handle, rand=b'', ediv=0
|
connection_handle=connection.handle, rand=b'', ediv=0
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ from .colors import color
|
|||||||
from .core import (
|
from .core import (
|
||||||
UUID,
|
UUID,
|
||||||
BT_RFCOMM_PROTOCOL_ID,
|
BT_RFCOMM_PROTOCOL_ID,
|
||||||
BT_BR_EDR_TRANSPORT,
|
PhysicalTransport,
|
||||||
BT_L2CAP_PROTOCOL_ID,
|
BT_L2CAP_PROTOCOL_ID,
|
||||||
InvalidArgumentError,
|
InvalidArgumentError,
|
||||||
InvalidStateError,
|
InvalidStateError,
|
||||||
@@ -845,7 +845,7 @@ class Multiplexer(EventEmitter):
|
|||||||
self.open_result.set_exception(
|
self.open_result.set_exception(
|
||||||
core.ConnectionError(
|
core.ConnectionError(
|
||||||
core.ConnectionError.CONNECTION_REFUSED,
|
core.ConnectionError.CONNECTION_REFUSED,
|
||||||
BT_BR_EDR_TRANSPORT,
|
PhysicalTransport.BR_EDR,
|
||||||
self.l2cap_channel.connection.peer_address,
|
self.l2cap_channel.connection.peer_address,
|
||||||
'rfcomm',
|
'rfcomm',
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -52,8 +52,7 @@ from .hci import (
|
|||||||
key_with_value,
|
key_with_value,
|
||||||
)
|
)
|
||||||
from .core import (
|
from .core import (
|
||||||
BT_BR_EDR_TRANSPORT,
|
PhysicalTransport,
|
||||||
BT_LE_TRANSPORT,
|
|
||||||
AdvertisingData,
|
AdvertisingData,
|
||||||
InvalidArgumentError,
|
InvalidArgumentError,
|
||||||
ProtocolError,
|
ProtocolError,
|
||||||
@@ -857,7 +856,7 @@ class Session:
|
|||||||
initiator_io_capability: int,
|
initiator_io_capability: int,
|
||||||
responder_io_capability: int,
|
responder_io_capability: int,
|
||||||
) -> None:
|
) -> None:
|
||||||
if self.connection.transport == BT_BR_EDR_TRANSPORT:
|
if self.connection.transport == PhysicalTransport.BR_EDR:
|
||||||
self.pairing_method = PairingMethod.CTKD_OVER_CLASSIC
|
self.pairing_method = PairingMethod.CTKD_OVER_CLASSIC
|
||||||
return
|
return
|
||||||
if (not self.mitm) and (auth_req & SMP_MITM_AUTHREQ == 0):
|
if (not self.mitm) and (auth_req & SMP_MITM_AUTHREQ == 0):
|
||||||
@@ -1170,7 +1169,7 @@ class Session:
|
|||||||
if self.is_initiator:
|
if self.is_initiator:
|
||||||
# CTKD: Derive LTK from LinkKey
|
# CTKD: Derive LTK from LinkKey
|
||||||
if (
|
if (
|
||||||
self.connection.transport == BT_BR_EDR_TRANSPORT
|
self.connection.transport == PhysicalTransport.BR_EDR
|
||||||
and self.initiator_key_distribution & SMP_ENC_KEY_DISTRIBUTION_FLAG
|
and self.initiator_key_distribution & SMP_ENC_KEY_DISTRIBUTION_FLAG
|
||||||
):
|
):
|
||||||
self.ctkd_task = self.connection.abort_on(
|
self.ctkd_task = self.connection.abort_on(
|
||||||
@@ -1209,7 +1208,7 @@ class Session:
|
|||||||
else:
|
else:
|
||||||
# CTKD: Derive LTK from LinkKey
|
# CTKD: Derive LTK from LinkKey
|
||||||
if (
|
if (
|
||||||
self.connection.transport == BT_BR_EDR_TRANSPORT
|
self.connection.transport == PhysicalTransport.BR_EDR
|
||||||
and self.responder_key_distribution & SMP_ENC_KEY_DISTRIBUTION_FLAG
|
and self.responder_key_distribution & SMP_ENC_KEY_DISTRIBUTION_FLAG
|
||||||
):
|
):
|
||||||
self.ctkd_task = self.connection.abort_on(
|
self.ctkd_task = self.connection.abort_on(
|
||||||
@@ -1248,7 +1247,7 @@ class Session:
|
|||||||
def compute_peer_expected_distributions(self, key_distribution_flags: int) -> None:
|
def compute_peer_expected_distributions(self, key_distribution_flags: int) -> None:
|
||||||
# Set our expectations for what to wait for in the key distribution phase
|
# Set our expectations for what to wait for in the key distribution phase
|
||||||
self.peer_expected_distributions = []
|
self.peer_expected_distributions = []
|
||||||
if not self.sc and self.connection.transport == BT_LE_TRANSPORT:
|
if not self.sc and self.connection.transport == PhysicalTransport.LE:
|
||||||
if key_distribution_flags & SMP_ENC_KEY_DISTRIBUTION_FLAG != 0:
|
if key_distribution_flags & SMP_ENC_KEY_DISTRIBUTION_FLAG != 0:
|
||||||
self.peer_expected_distributions.append(
|
self.peer_expected_distributions.append(
|
||||||
SMP_Encryption_Information_Command
|
SMP_Encryption_Information_Command
|
||||||
@@ -1365,7 +1364,7 @@ class Session:
|
|||||||
keys = PairingKeys()
|
keys = PairingKeys()
|
||||||
keys.address_type = peer_address.address_type
|
keys.address_type = peer_address.address_type
|
||||||
authenticated = self.pairing_method != PairingMethod.JUST_WORKS
|
authenticated = self.pairing_method != PairingMethod.JUST_WORKS
|
||||||
if self.sc or self.connection.transport == BT_BR_EDR_TRANSPORT:
|
if self.sc or self.connection.transport == PhysicalTransport.BR_EDR:
|
||||||
keys.ltk = PairingKeys.Key(value=self.ltk, authenticated=authenticated)
|
keys.ltk = PairingKeys.Key(value=self.ltk, authenticated=authenticated)
|
||||||
else:
|
else:
|
||||||
our_ltk_key = PairingKeys.Key(
|
our_ltk_key = PairingKeys.Key(
|
||||||
@@ -1506,7 +1505,7 @@ class Session:
|
|||||||
# CTKD over BR/EDR should happen after the connection has been encrypted,
|
# CTKD over BR/EDR should happen after the connection has been encrypted,
|
||||||
# so when receiving pairing requests, responder should start distributing keys
|
# so when receiving pairing requests, responder should start distributing keys
|
||||||
if (
|
if (
|
||||||
self.connection.transport == BT_BR_EDR_TRANSPORT
|
self.connection.transport == PhysicalTransport.BR_EDR
|
||||||
and self.connection.is_encrypted
|
and self.connection.is_encrypted
|
||||||
and self.is_responder
|
and self.is_responder
|
||||||
and accepted
|
and accepted
|
||||||
@@ -1950,7 +1949,9 @@ class Manager(EventEmitter):
|
|||||||
f'>>> Sending SMP Command on connection [0x{connection.handle:04X}] '
|
f'>>> Sending SMP Command on connection [0x{connection.handle:04X}] '
|
||||||
f'{connection.peer_address}: {command}'
|
f'{connection.peer_address}: {command}'
|
||||||
)
|
)
|
||||||
cid = SMP_BR_CID if connection.transport == BT_BR_EDR_TRANSPORT else SMP_CID
|
cid = (
|
||||||
|
SMP_BR_CID if connection.transport == PhysicalTransport.BR_EDR else SMP_CID
|
||||||
|
)
|
||||||
connection.send_l2cap_pdu(cid, bytes(command))
|
connection.send_l2cap_pdu(cid, bytes(command))
|
||||||
|
|
||||||
def on_smp_security_request_command(
|
def on_smp_security_request_command(
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ from bumble.colors import color
|
|||||||
from bumble.device import Device
|
from bumble.device import Device
|
||||||
from bumble.transport import open_transport_or_link
|
from bumble.transport import open_transport_or_link
|
||||||
from bumble.core import (
|
from bumble.core import (
|
||||||
BT_BR_EDR_TRANSPORT,
|
PhysicalTransport,
|
||||||
BT_AVDTP_PROTOCOL_ID,
|
BT_AVDTP_PROTOCOL_ID,
|
||||||
BT_AUDIO_SINK_SERVICE,
|
BT_AUDIO_SINK_SERVICE,
|
||||||
BT_L2CAP_PROTOCOL_ID,
|
BT_L2CAP_PROTOCOL_ID,
|
||||||
@@ -165,7 +165,9 @@ async def main() -> None:
|
|||||||
# Connect to a peer
|
# Connect to a peer
|
||||||
target_address = sys.argv[3]
|
target_address = sys.argv[3]
|
||||||
print(f'=== Connecting to {target_address}...')
|
print(f'=== Connecting to {target_address}...')
|
||||||
connection = await device.connect(target_address, transport=BT_BR_EDR_TRANSPORT)
|
connection = await device.connect(
|
||||||
|
target_address, transport=PhysicalTransport.BR_EDR
|
||||||
|
)
|
||||||
print(f'=== Connected to {connection.peer_address}!')
|
print(f'=== Connected to {connection.peer_address}!')
|
||||||
|
|
||||||
# Request authentication
|
# Request authentication
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ from typing import Any, Dict
|
|||||||
|
|
||||||
from bumble.device import Device
|
from bumble.device import Device
|
||||||
from bumble.transport import open_transport_or_link
|
from bumble.transport import open_transport_or_link
|
||||||
from bumble.core import BT_BR_EDR_TRANSPORT
|
from bumble.core import PhysicalTransport
|
||||||
from bumble.avdtp import (
|
from bumble.avdtp import (
|
||||||
AVDTP_AUDIO_MEDIA_TYPE,
|
AVDTP_AUDIO_MEDIA_TYPE,
|
||||||
Protocol,
|
Protocol,
|
||||||
@@ -145,7 +145,7 @@ async def main() -> None:
|
|||||||
target_address = sys.argv[4]
|
target_address = sys.argv[4]
|
||||||
print(f'=== Connecting to {target_address}...')
|
print(f'=== Connecting to {target_address}...')
|
||||||
connection = await device.connect(
|
connection = await device.connect(
|
||||||
target_address, transport=BT_BR_EDR_TRANSPORT
|
target_address, transport=PhysicalTransport.BR_EDR
|
||||||
)
|
)
|
||||||
print(f'=== Connected to {connection.peer_address}!')
|
print(f'=== Connected to {connection.peer_address}!')
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import logging
|
|||||||
from bumble.colors import color
|
from bumble.colors import color
|
||||||
from bumble.device import Device
|
from bumble.device import Device
|
||||||
from bumble.transport import open_transport_or_link
|
from bumble.transport import open_transport_or_link
|
||||||
from bumble.core import BT_BR_EDR_TRANSPORT
|
from bumble.core import PhysicalTransport
|
||||||
from bumble.avdtp import (
|
from bumble.avdtp import (
|
||||||
find_avdtp_service_with_connection,
|
find_avdtp_service_with_connection,
|
||||||
AVDTP_AUDIO_MEDIA_TYPE,
|
AVDTP_AUDIO_MEDIA_TYPE,
|
||||||
@@ -146,7 +146,7 @@ async def main() -> None:
|
|||||||
target_address = sys.argv[4]
|
target_address = sys.argv[4]
|
||||||
print(f'=== Connecting to {target_address}...')
|
print(f'=== Connecting to {target_address}...')
|
||||||
connection = await device.connect(
|
connection = await device.connect(
|
||||||
target_address, transport=BT_BR_EDR_TRANSPORT
|
target_address, transport=PhysicalTransport.BR_EDR
|
||||||
)
|
)
|
||||||
print(f'=== Connected to {connection.peer_address}!')
|
print(f'=== Connected to {connection.peer_address}!')
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import websockets
|
|||||||
|
|
||||||
from bumble.device import Device
|
from bumble.device import Device
|
||||||
from bumble.transport import open_transport_or_link
|
from bumble.transport import open_transport_or_link
|
||||||
from bumble.core import BT_BR_EDR_TRANSPORT
|
from bumble.core import PhysicalTransport
|
||||||
from bumble import avc
|
from bumble import avc
|
||||||
from bumble import avrcp
|
from bumble import avrcp
|
||||||
from bumble import avdtp
|
from bumble import avdtp
|
||||||
@@ -379,7 +379,7 @@ async def main() -> None:
|
|||||||
target_address = sys.argv[4]
|
target_address = sys.argv[4]
|
||||||
print(f'=== Connecting to {target_address}...')
|
print(f'=== Connecting to {target_address}...')
|
||||||
connection = await device.connect(
|
connection = await device.connect(
|
||||||
target_address, transport=BT_BR_EDR_TRANSPORT
|
target_address, transport=PhysicalTransport.BR_EDR
|
||||||
)
|
)
|
||||||
print(f'=== Connected to {connection.peer_address}!')
|
print(f'=== Connected to {connection.peer_address}!')
|
||||||
|
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ async def main() -> None:
|
|||||||
|
|
||||||
print(f'<<< Connecting to {target_address}')
|
print(f'<<< Connecting to {target_address}')
|
||||||
connection = await device.connect(
|
connection = await device.connect(
|
||||||
target_address, transport=core.BT_LE_TRANSPORT
|
target_address, transport=core.PhysicalTransport.LE
|
||||||
)
|
)
|
||||||
print('<<< ACL Connected')
|
print('<<< ACL Connected')
|
||||||
if not (await device.get_long_term_key(connection.handle, b'', 0)):
|
if not (await device.get_long_term_key(connection.handle, b'', 0)):
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ from bumble.colors import color
|
|||||||
|
|
||||||
from bumble.device import Device
|
from bumble.device import Device
|
||||||
from bumble.transport import open_transport_or_link
|
from bumble.transport import open_transport_or_link
|
||||||
from bumble.core import BT_BR_EDR_TRANSPORT, BT_L2CAP_PROTOCOL_ID, CommandTimeoutError
|
from bumble.core import PhysicalTransport, BT_L2CAP_PROTOCOL_ID, CommandTimeoutError
|
||||||
from bumble.sdp import (
|
from bumble.sdp import (
|
||||||
Client as SDP_Client,
|
Client as SDP_Client,
|
||||||
SDP_PUBLIC_BROWSE_ROOT,
|
SDP_PUBLIC_BROWSE_ROOT,
|
||||||
@@ -57,7 +57,7 @@ async def main() -> None:
|
|||||||
print(f'=== Connecting to {target_address}...')
|
print(f'=== Connecting to {target_address}...')
|
||||||
try:
|
try:
|
||||||
connection = await device.connect(
|
connection = await device.connect(
|
||||||
target_address, transport=BT_BR_EDR_TRANSPORT
|
target_address, transport=PhysicalTransport.BR_EDR
|
||||||
)
|
)
|
||||||
except CommandTimeoutError:
|
except CommandTimeoutError:
|
||||||
print('!!! Connection timed out')
|
print('!!! Connection timed out')
|
||||||
|
|||||||
@@ -16,11 +16,10 @@
|
|||||||
# Imports
|
# Imports
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
import asyncio
|
import asyncio
|
||||||
import dataclasses
|
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
from bumble.core import BT_BR_EDR_TRANSPORT
|
from bumble.core import PhysicalTransport
|
||||||
from bumble.device import Device, ScoLink
|
from bumble.device import Device, ScoLink
|
||||||
from bumble.hci import HCI_Enhanced_Setup_Synchronous_Connection_Command
|
from bumble.hci import HCI_Enhanced_Setup_Synchronous_Connection_Command
|
||||||
from bumble.hfp import DefaultCodecParameters, ESCO_PARAMETERS
|
from bumble.hfp import DefaultCodecParameters, ESCO_PARAMETERS
|
||||||
@@ -61,7 +60,9 @@ async def main() -> None:
|
|||||||
|
|
||||||
connections = await asyncio.gather(
|
connections = await asyncio.gather(
|
||||||
devices[0].accept(devices[1].public_address),
|
devices[0].accept(devices[1].public_address),
|
||||||
devices[1].connect(devices[0].public_address, transport=BT_BR_EDR_TRANSPORT),
|
devices[1].connect(
|
||||||
|
devices[0].public_address, transport=PhysicalTransport.BR_EDR
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
def on_sco(sco_link: ScoLink):
|
def on_sco(sco_link: ScoLink):
|
||||||
|
|||||||
@@ -28,9 +28,7 @@ import websockets
|
|||||||
import bumble.core
|
import bumble.core
|
||||||
from bumble.device import Device, ScoLink
|
from bumble.device import Device, ScoLink
|
||||||
from bumble.transport import open_transport_or_link
|
from bumble.transport import open_transport_or_link
|
||||||
from bumble.core import (
|
from bumble.core import PhysicalTransport
|
||||||
BT_BR_EDR_TRANSPORT,
|
|
||||||
)
|
|
||||||
from bumble import hci, rfcomm, hfp
|
from bumble import hci, rfcomm, hfp
|
||||||
|
|
||||||
|
|
||||||
@@ -234,7 +232,7 @@ async def main() -> None:
|
|||||||
target_address = sys.argv[3]
|
target_address = sys.argv[3]
|
||||||
print(f'=== Connecting to {target_address}...')
|
print(f'=== Connecting to {target_address}...')
|
||||||
connection = await device.connect(
|
connection = await device.connect(
|
||||||
target_address, transport=BT_BR_EDR_TRANSPORT
|
target_address, transport=PhysicalTransport.BR_EDR
|
||||||
)
|
)
|
||||||
print(f'=== Connected to {connection.peer_address}!')
|
print(f'=== Connected to {connection.peer_address}!')
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import struct
|
|||||||
from bumble.device import Device
|
from bumble.device import Device
|
||||||
from bumble.transport import open_transport_or_link
|
from bumble.transport import open_transport_or_link
|
||||||
from bumble.core import (
|
from bumble.core import (
|
||||||
BT_BR_EDR_TRANSPORT,
|
PhysicalTransport,
|
||||||
BT_L2CAP_PROTOCOL_ID,
|
BT_L2CAP_PROTOCOL_ID,
|
||||||
BT_HUMAN_INTERFACE_DEVICE_SERVICE,
|
BT_HUMAN_INTERFACE_DEVICE_SERVICE,
|
||||||
BT_HIDP_PROTOCOL_ID,
|
BT_HIDP_PROTOCOL_ID,
|
||||||
@@ -721,7 +721,7 @@ async def main() -> None:
|
|||||||
elif choice == '9':
|
elif choice == '9':
|
||||||
hid_host_bd_addr = str(hid_device.remote_device_bd_address)
|
hid_host_bd_addr = str(hid_device.remote_device_bd_address)
|
||||||
connection = await device.connect(
|
connection = await device.connect(
|
||||||
hid_host_bd_addr, transport=BT_BR_EDR_TRANSPORT
|
hid_host_bd_addr, transport=PhysicalTransport.BR_EDR
|
||||||
)
|
)
|
||||||
await connection.authenticate()
|
await connection.authenticate()
|
||||||
await connection.encrypt()
|
await connection.encrypt()
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ from bumble.device import Device
|
|||||||
from bumble.transport import open_transport_or_link
|
from bumble.transport import open_transport_or_link
|
||||||
from bumble.core import (
|
from bumble.core import (
|
||||||
BT_HUMAN_INTERFACE_DEVICE_SERVICE,
|
BT_HUMAN_INTERFACE_DEVICE_SERVICE,
|
||||||
BT_BR_EDR_TRANSPORT,
|
PhysicalTransport,
|
||||||
)
|
)
|
||||||
from bumble.hci import Address
|
from bumble.hci import Address
|
||||||
from bumble.hid import Host, Message
|
from bumble.hid import Host, Message
|
||||||
@@ -349,7 +349,9 @@ async def main() -> None:
|
|||||||
# Connect to a peer
|
# Connect to a peer
|
||||||
target_address = sys.argv[3]
|
target_address = sys.argv[3]
|
||||||
print(f'=== Connecting to {target_address}...')
|
print(f'=== Connecting to {target_address}...')
|
||||||
connection = await device.connect(target_address, transport=BT_BR_EDR_TRANSPORT)
|
connection = await device.connect(
|
||||||
|
target_address, transport=PhysicalTransport.BR_EDR
|
||||||
|
)
|
||||||
print(f'=== Connected to {connection.peer_address}!')
|
print(f'=== Connected to {connection.peer_address}!')
|
||||||
|
|
||||||
# Request authentication
|
# Request authentication
|
||||||
@@ -519,10 +521,10 @@ async def main() -> None:
|
|||||||
|
|
||||||
elif choice == '13':
|
elif choice == '13':
|
||||||
peer_address = Address.from_string_for_transport(
|
peer_address = Address.from_string_for_transport(
|
||||||
target_address, transport=BT_BR_EDR_TRANSPORT
|
target_address, transport=PhysicalTransport.BR_EDR
|
||||||
)
|
)
|
||||||
connection = device.find_connection_by_bd_addr(
|
connection = device.find_connection_by_bd_addr(
|
||||||
peer_address, transport=BT_BR_EDR_TRANSPORT
|
peer_address, transport=PhysicalTransport.BR_EDR
|
||||||
)
|
)
|
||||||
if connection is not None:
|
if connection is not None:
|
||||||
await connection.disconnect()
|
await connection.disconnect()
|
||||||
@@ -538,7 +540,7 @@ async def main() -> None:
|
|||||||
|
|
||||||
elif choice == '15':
|
elif choice == '15':
|
||||||
connection = await device.connect(
|
connection = await device.connect(
|
||||||
target_address, transport=BT_BR_EDR_TRANSPORT
|
target_address, transport=PhysicalTransport.BR_EDR
|
||||||
)
|
)
|
||||||
await connection.authenticate()
|
await connection.authenticate()
|
||||||
await connection.encrypt()
|
await connection.encrypt()
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ from bumble.transport import open_transport_or_link
|
|||||||
from bumble.core import (
|
from bumble.core import (
|
||||||
BT_L2CAP_PROTOCOL_ID,
|
BT_L2CAP_PROTOCOL_ID,
|
||||||
BT_RFCOMM_PROTOCOL_ID,
|
BT_RFCOMM_PROTOCOL_ID,
|
||||||
BT_BR_EDR_TRANSPORT,
|
PhysicalTransport,
|
||||||
)
|
)
|
||||||
from bumble.rfcomm import Client
|
from bumble.rfcomm import Client
|
||||||
from bumble.sdp import (
|
from bumble.sdp import (
|
||||||
@@ -191,7 +191,9 @@ async def main() -> None:
|
|||||||
# Connect to a peer
|
# Connect to a peer
|
||||||
target_address = sys.argv[3]
|
target_address = sys.argv[3]
|
||||||
print(f'=== Connecting to {target_address}...')
|
print(f'=== Connecting to {target_address}...')
|
||||||
connection = await device.connect(target_address, transport=BT_BR_EDR_TRANSPORT)
|
connection = await device.connect(
|
||||||
|
target_address, transport=PhysicalTransport.BR_EDR
|
||||||
|
)
|
||||||
print(f'=== Connected to {connection.peer_address}!')
|
print(f'=== Connected to {connection.peer_address}!')
|
||||||
|
|
||||||
channel_str = sys.argv[4]
|
channel_str = sys.argv[4]
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import os
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from bumble.controller import Controller
|
from bumble.controller import Controller
|
||||||
from bumble.core import BT_BR_EDR_TRANSPORT
|
from bumble.core import PhysicalTransport
|
||||||
from bumble.link import LocalLink
|
from bumble.link import LocalLink
|
||||||
from bumble.device import Device
|
from bumble.device import Device
|
||||||
from bumble.host import Host
|
from bumble.host import Host
|
||||||
@@ -106,7 +106,7 @@ async def test_self_connection():
|
|||||||
# Connect the two devices
|
# Connect the two devices
|
||||||
await asyncio.gather(
|
await asyncio.gather(
|
||||||
two_devices.devices[0].connect(
|
two_devices.devices[0].connect(
|
||||||
two_devices.devices[1].public_address, transport=BT_BR_EDR_TRANSPORT
|
two_devices.devices[1].public_address, transport=PhysicalTransport.BR_EDR
|
||||||
),
|
),
|
||||||
two_devices.devices[1].accept(two_devices.devices[0].public_address),
|
two_devices.devices[1].accept(two_devices.devices[0].public_address),
|
||||||
)
|
)
|
||||||
@@ -190,7 +190,7 @@ async def test_source_sink_1():
|
|||||||
async def make_connection():
|
async def make_connection():
|
||||||
connections = await asyncio.gather(
|
connections = await asyncio.gather(
|
||||||
two_devices.devices[0].connect(
|
two_devices.devices[0].connect(
|
||||||
two_devices.devices[1].public_address, BT_BR_EDR_TRANSPORT
|
two_devices.devices[1].public_address, PhysicalTransport.BR_EDR
|
||||||
),
|
),
|
||||||
two_devices.devices[1].accept(two_devices.devices[0].public_address),
|
two_devices.devices[1].accept(two_devices.devices[0].public_address),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ class TwoDevices:
|
|||||||
|
|
||||||
self.connections = await asyncio.gather(
|
self.connections = await asyncio.gather(
|
||||||
self.devices[0].connect(
|
self.devices[0].connect(
|
||||||
self.devices[1].public_address, core.BT_BR_EDR_TRANSPORT
|
self.devices[1].public_address, core.PhysicalTransport.BR_EDR
|
||||||
),
|
),
|
||||||
self.devices[1].accept(self.devices[0].public_address),
|
self.devices[1].accept(self.devices[0].public_address),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -22,8 +22,7 @@ import os
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from bumble.core import (
|
from bumble.core import (
|
||||||
BT_BR_EDR_TRANSPORT,
|
PhysicalTransport,
|
||||||
BT_LE_TRANSPORT,
|
|
||||||
ConnectionParameters,
|
ConnectionParameters,
|
||||||
)
|
)
|
||||||
from bumble.device import (
|
from bumble.device import (
|
||||||
@@ -229,10 +228,10 @@ async def test_device_connect_parallel():
|
|||||||
[c01, c02, a10, a20] = await asyncio.gather(
|
[c01, c02, a10, a20] = await asyncio.gather(
|
||||||
*[
|
*[
|
||||||
asyncio.create_task(
|
asyncio.create_task(
|
||||||
d0.connect(d1.public_address, transport=BT_BR_EDR_TRANSPORT)
|
d0.connect(d1.public_address, transport=PhysicalTransport.BR_EDR)
|
||||||
),
|
),
|
||||||
asyncio.create_task(
|
asyncio.create_task(
|
||||||
d0.connect(d2.public_address, transport=BT_BR_EDR_TRANSPORT)
|
d0.connect(d2.public_address, transport=PhysicalTransport.BR_EDR)
|
||||||
),
|
),
|
||||||
d1_accept_task,
|
d1_accept_task,
|
||||||
d2_accept_task,
|
d2_accept_task,
|
||||||
@@ -291,7 +290,7 @@ async def test_legacy_advertising_disconnection(auto_restart):
|
|||||||
await device.start_advertising(auto_restart=auto_restart)
|
await device.start_advertising(auto_restart=auto_restart)
|
||||||
device.on_connection(
|
device.on_connection(
|
||||||
0x0001,
|
0x0001,
|
||||||
BT_LE_TRANSPORT,
|
PhysicalTransport.LE,
|
||||||
peer_address,
|
peer_address,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
@@ -349,7 +348,7 @@ async def test_extended_advertising_connection(own_address_type):
|
|||||||
)
|
)
|
||||||
device.on_connection(
|
device.on_connection(
|
||||||
0x0001,
|
0x0001,
|
||||||
BT_LE_TRANSPORT,
|
PhysicalTransport.LE,
|
||||||
peer_address,
|
peer_address,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
@@ -393,7 +392,7 @@ async def test_extended_advertising_connection_out_of_order(own_address_type):
|
|||||||
)
|
)
|
||||||
device.on_connection(
|
device.on_connection(
|
||||||
0x0001,
|
0x0001,
|
||||||
BT_LE_TRANSPORT,
|
PhysicalTransport.LE,
|
||||||
Address('F0:F1:F2:F3:F4:F5'),
|
Address('F0:F1:F2:F3:F4:F5'),
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
|
|||||||
@@ -522,7 +522,7 @@ async def test_sco_setup():
|
|||||||
|
|
||||||
connections = await asyncio.gather(
|
connections = await asyncio.gather(
|
||||||
devices[0].connect(
|
devices[0].connect(
|
||||||
devices[1].public_address, transport=core.BT_BR_EDR_TRANSPORT
|
devices[1].public_address, transport=core.PhysicalTransport.BR_EDR
|
||||||
),
|
),
|
||||||
devices[1].accept(devices[0].public_address),
|
devices[1].accept(devices[0].public_address),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import pytest
|
|||||||
from unittest.mock import AsyncMock, MagicMock, patch
|
from unittest.mock import AsyncMock, MagicMock, patch
|
||||||
|
|
||||||
from bumble.controller import Controller
|
from bumble.controller import Controller
|
||||||
from bumble.core import BT_BR_EDR_TRANSPORT, BT_LE_TRANSPORT
|
from bumble.core import PhysicalTransport
|
||||||
from bumble.link import LocalLink
|
from bumble.link import LocalLink
|
||||||
from bumble.device import Device, Peer
|
from bumble.device import Device, Peer
|
||||||
from bumble.host import Host
|
from bumble.host import Host
|
||||||
@@ -137,7 +137,7 @@ async def test_self_classic_connection(responder_role):
|
|||||||
# Connect the two devices
|
# Connect the two devices
|
||||||
await asyncio.gather(
|
await asyncio.gather(
|
||||||
two_devices.devices[0].connect(
|
two_devices.devices[0].connect(
|
||||||
two_devices.devices[1].public_address, transport=BT_BR_EDR_TRANSPORT
|
two_devices.devices[1].public_address, transport=PhysicalTransport.BR_EDR
|
||||||
),
|
),
|
||||||
two_devices.devices[1].accept(
|
two_devices.devices[1].accept(
|
||||||
two_devices.devices[0].public_address, responder_role
|
two_devices.devices[0].public_address, responder_role
|
||||||
@@ -507,7 +507,7 @@ async def test_self_smp_over_classic():
|
|||||||
# Connect the two devices
|
# Connect the two devices
|
||||||
await asyncio.gather(
|
await asyncio.gather(
|
||||||
two_devices.devices[0].connect(
|
two_devices.devices[0].connect(
|
||||||
two_devices.devices[1].public_address, transport=BT_BR_EDR_TRANSPORT
|
two_devices.devices[1].public_address, transport=PhysicalTransport.BR_EDR
|
||||||
),
|
),
|
||||||
two_devices.devices[1].accept(two_devices.devices[0].public_address),
|
two_devices.devices[1].accept(two_devices.devices[0].public_address),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import enum
|
|||||||
import logging
|
import logging
|
||||||
from typing import Dict, List
|
from typing import Dict, List
|
||||||
|
|
||||||
from bumble.core import BT_BR_EDR_TRANSPORT, CommandTimeoutError
|
from bumble.core import PhysicalTransport, CommandTimeoutError
|
||||||
from bumble.device import Device, DeviceConfiguration
|
from bumble.device import Device, DeviceConfiguration
|
||||||
from bumble.pairing import PairingConfig
|
from bumble.pairing import PairingConfig
|
||||||
from bumble.sdp import ServiceAttribute
|
from bumble.sdp import ServiceAttribute
|
||||||
@@ -229,7 +229,9 @@ class Speaker:
|
|||||||
async def connect(self, address):
|
async def connect(self, address):
|
||||||
# Connect to the source
|
# Connect to the source
|
||||||
print(f'=== Connecting to {address}...')
|
print(f'=== Connecting to {address}...')
|
||||||
connection = await self.device.connect(address, transport=BT_BR_EDR_TRANSPORT)
|
connection = await self.device.connect(
|
||||||
|
address, transport=PhysicalTransport.BR_EDR
|
||||||
|
)
|
||||||
print(f'=== Connected to {connection.peer_address}')
|
print(f'=== Connected to {connection.peer_address}')
|
||||||
|
|
||||||
# Request authentication
|
# Request authentication
|
||||||
|
|||||||
Reference in New Issue
Block a user