Skip to content

Inconsistency in handling Bluetooth addresses #132099

Closed
@serhiy-storchaka

Description

@serhiy-storchaka

Bug report

  1. The format accepted by BTPROTO_HCI protocol is incorrectly documented.
    • it accepts a bytes object bdaddr, not a tuple.
    • bdaddr is a bytes object, not a string.
  2. Some protocols accept bdaddr as a string, others accept it as a bytes object. getsockname() returns it as a string or a bytes object, and this is not always consistent with the accepted type.
  3. getsockname() not always return an address in the acceptable format. It returns device_id when the acceptable format is a tuple (device_id,), can return a string when the acceptable format is a bytes object.

First problem should be solved by updating the documentation.

For second problem, I propose to make both string and bytes be accepted as a Bluetooth address. Also, if a 1-tuple is accepted, then its element should be accepted, and if bdaddr is accepted, then a 1-tuple (bdaddr,) should be accepted.

The third problem cannot be resolved in backward compatible way. The solution for the second problem formally fixes incompatibility between input and output formats, but formats are still inconsistent between protocols. And after adding support for hci_channel (see #70145), the type of the getsockname() result will depend on the hci_channel value.

Linked PRs

Metadata

Metadata

Labels

docsDocumentation in the Doc dirtype-bugAn unexpected behavior, bug, or error

Projects

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions