Skip to content

Commit

Permalink
pythongh-129288: Add optional CID field in BTPROTO_L2CAP socket addre…
Browse files Browse the repository at this point in the history
…ss tuple

This change adds support for the CID field in the socket address tuple. This allows e.g raw LE ATT connections.
  • Loading branch information
themadinventor committed Jan 26, 2025
1 parent d45523c commit e9b2a54
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Modules/socketmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1493,15 +1493,16 @@ 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) {
// Retain old format for non-LE address
/* 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",
ret = Py_BuildValue("OiiB",
addrobj,
_BT_L2_MEMB(a, psm),
_BT_L2_MEMB(a, cid),
_BT_L2_MEMB(a, bdaddr_type));
}
Py_DECREF(addrobj);
Expand Down Expand Up @@ -2054,8 +2055,9 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
memset(addr, 0, sizeof(struct sockaddr_l2));
_BT_L2_MEMB(addr, family) = AF_BLUETOOTH;
_BT_L2_MEMB(addr, bdaddr_type) = BDADDR_BREDR;
if (!PyArg_ParseTuple(args, "si|B", &straddr,
if (!PyArg_ParseTuple(args, "si|iB", &straddr,
&_BT_L2_MEMB(addr, psm),
&_BT_L2_MEMB(addr, cid),
&_BT_L2_MEMB(addr, bdaddr_type))) {
PyErr_Format(PyExc_OSError,
"%s(): wrong format", caller);
Expand Down

0 comments on commit e9b2a54

Please sign in to comment.