You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Python cannot access hci_channel field in sockaddr_hci #80313
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=Nonecreated_at=<Date2019-02-27.11:10:31.383>labels= ['3.8', 'library']
title='Python cannot access hci_channel field in sockaddr_hci'updated_at=<Date2019-07-09.07:01:38.901>user='https://bugs.python.org/bsder'
Unfortunately, it seems like python does not allow any way to initialize hci_channel, so you can't use a user channel socket (hci_channel == 0) or a monitor channel. There is probably a larger discussion of how to enable people to use a new field that appears in a structure like this, but that's above my pay grade ...
Even worse, this appears to have been known for a while (since 2013 at least! by Chromium), but while people complained, nobody actually took the time to file it upstream with Python.
So, I'm filing it upstream. Hopefully this is easy to fix by someone who knows what's up.
classBluetoothUserSocket(SuperSocket):
desc="read/write H4 over a Bluetooth user channel"def__init__(self, adapter=0):
# s = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_RAW, socket.BTPROTO_HCI)# s.bind((0,1))
# yeah, if only
# thanks to Python's weak ass socket and bind implementations, we have
# to call down into libc with ctypes
It's up to you how you folks want to deal with this, but classifying it as a "bug" for those versions in bugfix is likely acceptable.
You already have to call bind with a tuple, so as long as it is *optional* to add an extra field to that tuple (and I can't imagine that any fix would not do that as it would break existing code), it's not going to break things.
However, since nobody seems to have felt the need to file this, fixing this in 3.8 is probably just fine.
The Bluetooth management sockets can be created by setting the hci_channel
member of struct sockaddr_hci to HCI_CHANNEL_CONTROL (3) when creating a
raw HCI socket.
The resolution of this issue would enable access to that API.
Activity
bsder commentedon Feb 27, 2019
On Linux, sockaddr_hci is:
Unfortunately, it seems like python does not allow any way to initialize hci_channel, so you can't use a user channel socket (hci_channel == 0) or a monitor channel. There is probably a larger discussion of how to enable people to use a new field that appears in a structure like this, but that's above my pay grade ...
Even worse, this appears to have been known for a while (since 2013 at least! by Chromium), but while people complained, nobody actually took the time to file it upstream with Python.
So, I'm filing it upstream. Hopefully this is easy to fix by someone who knows what's up.
Thanks.
See:
https://chromium.googlesource.com/chromiumos/platform/btsocket/+/factory-4455.B
https://github.com/w3h/isf/blob/master/lib/thirdparty/scapy/layers/bluetooth.py
matrixise commentedon Feb 27, 2019
Thank you,
I have changed the related versions of Python to 3.8 because it's a new feature and the other releases are in security mode or bugfix mode.
bsder commentedon Feb 27, 2019
It's up to you how you folks want to deal with this, but classifying it as a "bug" for those versions in bugfix is likely acceptable.
You already have to call bind with a tuple, so as long as it is *optional* to add an extra field to that tuple (and I can't imagine that any fix would not do that as it would break existing code), it's not going to break things.
However, since nobody seems to have felt the need to file this, fixing this in 3.8 is probably just fine.
ukBaz commentedon Jul 4, 2019
I was looking to control Bluetooth on Linux machines using the BlueZ Management API available at:
https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/mgmt-api.txt
The Bluetooth management sockets can be created by setting the hci_channel
member of struct sockaddr_hci to HCI_CHANNEL_CONTROL (3) when creating a
raw HCI socket.
The resolution of this issue would enable access to that API.
serhiy-storchaka commentedon Apr 1, 2025
See also #70145. These two issues can be merged.