gh-70145: Add support for channels in Bluetooth HCI protocol (GH-132481)

This commit is contained in:
Serhiy Storchaka 2025-04-14 20:09:16 +03:00 committed by GitHub
parent d22604a6d1
commit 61638418a7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 73 additions and 10 deletions

View file

@ -1541,7 +1541,14 @@ makesockaddr(SOCKET_T sockfd, struct sockaddr *addr, size_t addrlen, int proto)
struct sockaddr_hci *a = (struct sockaddr_hci *) addr;
#if defined(HAVE_BLUETOOTH_BLUETOOTH_H)
PyObject *ret = NULL;
ret = Py_BuildValue("i", _BT_HCI_MEMB(a, dev));
if (_BT_HCI_MEMB(a, channel) == HCI_CHANNEL_RAW) {
return Py_BuildValue("i", _BT_HCI_MEMB(a, dev));
}
else {
return Py_BuildValue("ii",
_BT_HCI_MEMB(a, dev),
_BT_HCI_MEMB(a, channel));
}
return ret;
#elif defined(__FreeBSD__)
const char *node = _BT_HCI_MEMB(a, node);
@ -2138,13 +2145,15 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
memset(addr, 0, sizeof(struct sockaddr_hci));
_BT_HCI_MEMB(addr, family) = AF_BLUETOOTH;
#if defined(HAVE_BLUETOOTH_BLUETOOTH_H)
unsigned short dev = _BT_HCI_MEMB(addr, dev);
if (!PyArg_ParseTuple(args, "H", &dev)) {
unsigned short dev;
unsigned short channel = HCI_CHANNEL_RAW;
if (!PyArg_ParseTuple(args, "H|H", &dev, &channel)) {
PyErr_Format(PyExc_OSError,
"%s(): wrong format", caller);
return 0;
}
_BT_HCI_MEMB(addr, dev) = dev;
_BT_HCI_MEMB(addr, channel) = channel;
#else
const char *straddr;
if (!PyArg_Parse(args, "s", &straddr)) {
@ -7874,6 +7883,13 @@ socket_exec(PyObject *m)
#ifdef BTPROTO_HCI
ADD_INT_MACRO(m, BTPROTO_HCI);
ADD_INT_MACRO(m, SOL_HCI);
#if defined(HCI_CHANNEL_RAW)
ADD_INT_MACRO(m, HCI_CHANNEL_RAW);
ADD_INT_MACRO(m, HCI_CHANNEL_USER);
ADD_INT_MACRO(m, HCI_CHANNEL_MONITOR);
ADD_INT_MACRO(m, HCI_CHANNEL_CONTROL);
ADD_INT_MACRO(m, HCI_CHANNEL_LOGGING);
#endif
#if defined(HCI_FILTER)
ADD_INT_MACRO(m, HCI_FILTER);
#endif