Skip to content

Commit

Permalink
Merge pull request #565 from zxzxwu/controller
Browse files Browse the repository at this point in the history
Add codecs info in controller info app
  • Loading branch information
zxzxwu authored Oct 1, 2024
2 parents 46ec39c + 347fe8b commit e5666c0
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 5 deletions.
60 changes: 60 additions & 0 deletions apps/controller_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from bumble.core import name_or_number
from bumble.hci import (
map_null_terminated_utf8_string,
CodecID,
LeFeature,
HCI_SUCCESS,
HCI_VERSION_NAMES,
Expand All @@ -50,6 +51,8 @@
HCI_LE_Read_Maximum_Advertising_Data_Length_Command,
HCI_LE_READ_SUGGESTED_DEFAULT_DATA_LENGTH_COMMAND,
HCI_LE_Read_Suggested_Default_Data_Length_Command,
HCI_Read_Local_Supported_Codecs_Command,
HCI_Read_Local_Supported_Codecs_V2_Command,
HCI_Read_Local_Version_Information_Command,
)
from bumble.host import Host
Expand Down Expand Up @@ -168,6 +171,60 @@ async def get_acl_flow_control_info(host: Host) -> None:
)


# -----------------------------------------------------------------------------
async def get_codecs_info(host: Host) -> None:
print()

if host.supports_command(HCI_Read_Local_Supported_Codecs_V2_Command.op_code):
response = await host.send_command(
HCI_Read_Local_Supported_Codecs_V2_Command(), check_result=True
)
print(color('Codecs:', 'yellow'))

for codec_id, transport in zip(
response.return_parameters.standard_codec_ids,
response.return_parameters.standard_codec_transports,
):
transport_name = HCI_Read_Local_Supported_Codecs_V2_Command.Transport(
transport
).name
codec_name = CodecID(codec_id).name
print(f' {codec_name} - {transport_name}')

for codec_id, transport in zip(
response.return_parameters.vendor_specific_codec_ids,
response.return_parameters.vendor_specific_codec_transports,
):
transport_name = HCI_Read_Local_Supported_Codecs_V2_Command.Transport(
transport
).name
company = name_or_number(COMPANY_IDENTIFIERS, codec_id >> 16)
print(f' {company} / {codec_id & 0xFFFF} - {transport_name}')

if not response.return_parameters.standard_codec_ids:
print(' No standard codecs')
if not response.return_parameters.vendor_specific_codec_ids:
print(' No Vendor-specific codecs')

if host.supports_command(HCI_Read_Local_Supported_Codecs_Command.op_code):
response = await host.send_command(
HCI_Read_Local_Supported_Codecs_Command(), check_result=True
)
print(color('Codecs (BR/EDR):', 'yellow'))
for codec_id in response.return_parameters.standard_codec_ids:
codec_name = CodecID(codec_id).name
print(f' {codec_name}')

for codec_id in response.return_parameters.vendor_specific_codec_ids:
company = name_or_number(COMPANY_IDENTIFIERS, codec_id >> 16)
print(f' {company} / {codec_id & 0xFFFF}')

if not response.return_parameters.standard_codec_ids:
print(' No standard codecs')
if not response.return_parameters.vendor_specific_codec_ids:
print(' No Vendor-specific codecs')


# -----------------------------------------------------------------------------
async def async_main(latency_probes, transport):
print('<<< connecting to HCI...')
Expand Down Expand Up @@ -220,6 +277,9 @@ async def async_main(latency_probes, transport):
# Print the ACL flow control info
await get_acl_flow_control_info(host)

# Get codec info
await get_codecs_info(host)

# Print the list of commands supported by the controller
print()
print(color('Supported Commands:', 'yellow'))
Expand Down
10 changes: 5 additions & 5 deletions bumble/hci.py
Original file line number Diff line number Diff line change
Expand Up @@ -3440,11 +3440,11 @@ class HCI_Read_Local_Supported_Codecs_V2_Command(HCI_Command):
See Bluetooth spec @ 7.4.8 Read Local Supported Codecs Command
'''

class Transport(OpenIntEnum):
BR_EDR_ACL = 0x00
BR_EDR_SCO = 0x01
LE_CIS = 0x02
LE_BIS = 0x03
class Transport(enum.IntFlag):
BR_EDR_ACL = 1 << 0
BR_EDR_SCO = 1 << 1
LE_CIS = 1 << 2
LE_BIS = 1 << 3


# -----------------------------------------------------------------------------
Expand Down

0 comments on commit e5666c0

Please sign in to comment.