Skip to content

Commit

Permalink
gh-129288: Add optional bdaddr_type in BTPROTO_L2CAP socket address t…
Browse files Browse the repository at this point in the history
…uple

To be able to connect L2CAP sockets to Bluetooth LE devices, the l2_bdaddr_type must be set to BDADDR_LE_PUBLIC or BDADDR_LE_RANDOM.
This change adds support for providing the l2_bdaddr_type as an optional, traliing element in the address tuple passed to connect()
  • Loading branch information
themadinventor committed Jan 25, 2025
1 parent e635bf2 commit 702f477
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions Modules/socketmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1493,9 +1493,17 @@ makesockaddr(SOCKET_T sockfd, struct sockaddr *addr, size_t addrlen, int proto)
PyObject *addrobj = makebdaddr(&_BT_L2_MEMB(a, bdaddr));
PyObject *ret = NULL;
if (addrobj) {
ret = Py_BuildValue("Oi",
addrobj,
_BT_L2_MEMB(a, psm));
// Retain old format for non-LE address
if (_BT_L2_MEMB(a, bdaddr_type) == BDADDR_BREDR) {
ret = Py_BuildValue("Oi",
addrobj,
_BT_L2_MEMB(a, psm));
} else {
ret = Py_BuildValue("OiB",
addrobj,
_BT_L2_MEMB(a, psm),
_BT_L2_MEMB(a, bdaddr_type));
}
Py_DECREF(addrobj);
}
return ret;
Expand Down Expand Up @@ -2045,8 +2053,10 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
struct sockaddr_l2 *addr = &addrbuf->bt_l2;
memset(addr, 0, sizeof(struct sockaddr_l2));
_BT_L2_MEMB(addr, family) = AF_BLUETOOTH;
if (!PyArg_ParseTuple(args, "si", &straddr,
&_BT_L2_MEMB(addr, psm))) {
_BT_L2_MEMB(addr, bdaddr_type) = BDADDR_BREDR;
if (!PyArg_ParseTuple(args, "si|B", &straddr,
&_BT_L2_MEMB(addr, psm),
&_BT_L2_MEMB(addr, bdaddr_type))) {
PyErr_Format(PyExc_OSError,
"%s(): wrong format", caller);
return 0;
Expand Down Expand Up @@ -7743,6 +7753,9 @@ socket_exec(PyObject *m)
#ifdef BTPROTO_SCO
ADD_INT_MACRO(m, BTPROTO_SCO);
#endif /* BTPROTO_SCO */
ADD_INT_MACRO(m, BDADDR_BREDR);

Check failure on line 7756 in Modules/socketmodule.c

View workflow job for this annotation

GitHub Actions / Windows / build and test (arm64)

'BDADDR_BREDR': undeclared identifier [D:\a\cpython\cpython\PCbuild\_socket.vcxproj]

Check failure on line 7756 in Modules/socketmodule.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build and test (arm64)

'BDADDR_BREDR': undeclared identifier [D:\a\cpython\cpython\PCbuild\_socket.vcxproj]

Check failure on line 7756 in Modules/socketmodule.c

View workflow job for this annotation

GitHub Actions / Windows / build and test (x64)

'BDADDR_BREDR': undeclared identifier [D:\a\cpython\cpython\PCbuild\_socket.vcxproj]

Check failure on line 7756 in Modules/socketmodule.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build and test (x64)

'BDADDR_BREDR': undeclared identifier [D:\a\cpython\cpython\PCbuild\_socket.vcxproj]
ADD_INT_MACRO(m, BDADDR_LE_PUBLIC);

Check failure on line 7757 in Modules/socketmodule.c

View workflow job for this annotation

GitHub Actions / Windows / build and test (arm64)

'BDADDR_LE_PUBLIC': undeclared identifier [D:\a\cpython\cpython\PCbuild\_socket.vcxproj]

Check failure on line 7757 in Modules/socketmodule.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build and test (arm64)

'BDADDR_LE_PUBLIC': undeclared identifier [D:\a\cpython\cpython\PCbuild\_socket.vcxproj]

Check failure on line 7757 in Modules/socketmodule.c

View workflow job for this annotation

GitHub Actions / Windows / build and test (x64)

'BDADDR_LE_PUBLIC': undeclared identifier [D:\a\cpython\cpython\PCbuild\_socket.vcxproj]

Check failure on line 7757 in Modules/socketmodule.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build and test (x64)

'BDADDR_LE_PUBLIC': undeclared identifier [D:\a\cpython\cpython\PCbuild\_socket.vcxproj]
ADD_INT_MACRO(m, BDADDR_LE_RANDOM);

Check failure on line 7758 in Modules/socketmodule.c

View workflow job for this annotation

GitHub Actions / Windows / build and test (arm64)

'BDADDR_LE_RANDOM': undeclared identifier [D:\a\cpython\cpython\PCbuild\_socket.vcxproj]

Check failure on line 7758 in Modules/socketmodule.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build and test (arm64)

'BDADDR_LE_RANDOM': undeclared identifier [D:\a\cpython\cpython\PCbuild\_socket.vcxproj]

Check failure on line 7758 in Modules/socketmodule.c

View workflow job for this annotation

GitHub Actions / Windows / build and test (x64)

'BDADDR_LE_RANDOM': undeclared identifier [D:\a\cpython\cpython\PCbuild\_socket.vcxproj]

Check failure on line 7758 in Modules/socketmodule.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / build and test (x64)

'BDADDR_LE_RANDOM': undeclared identifier [D:\a\cpython\cpython\PCbuild\_socket.vcxproj]
#endif /* USE_BLUETOOTH */

#ifdef AF_CAN
Expand Down

0 comments on commit 702f477

Please sign in to comment.