Skip to content

gh-85302: Add support for BTPROTO_SCO on FreeBSD #131981

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 11, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Doc/library/socket.rst
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,10 @@ created. Socket addresses are represented as follows:

- :const:`BTPROTO_SCO` accepts ``bdaddr`` where ``bdaddr`` is a
:class:`bytes` object containing the Bluetooth address in a
string format. (ex. ``b'12:23:34:45:56:67'``) This protocol is not
supported under FreeBSD.
string format. (ex. ``b'12:23:34:45:56:67'``)

.. versionchanged:: next
FreeBSD support added.

- :const:`AF_ALG` is a Linux-only socket based interface to Kernel
cryptography. An algorithm socket is configured with a tuple of two to four
Expand Down
7 changes: 2 additions & 5 deletions Lib/test/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -2619,9 +2619,7 @@ def testBluetoothConstants(self):
socket.BTPROTO_HCI
socket.SOL_HCI
socket.BTPROTO_L2CAP

if not sys.platform.startswith("freebsd"):
socket.BTPROTO_SCO
socket.BTPROTO_SCO

def testCreateRfcommSocket(self):
with socket.socket(socket.AF_BLUETOOTH, socket.SOCK_STREAM, socket.BTPROTO_RFCOMM) as s:
Expand All @@ -2637,8 +2635,7 @@ def testCreateHciSocket(self):
with socket.socket(socket.AF_BLUETOOTH, socket.SOCK_RAW, socket.BTPROTO_HCI) as s:
pass

@unittest.skipIf(sys.platform == "win32" or sys.platform.startswith("freebsd"),
"windows and freebsd do not support SCO sockets")
@unittest.skipIf(sys.platform == "win32", "windows does not support SCO sockets")
def testCreateScoSocket(self):
with socket.socket(socket.AF_BLUETOOTH, socket.SOCK_SEQPACKET, socket.BTPROTO_SCO) as s:
pass
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for :data:`~socket.BTPROTO_SCO` in sockets on FreeBSD.
16 changes: 8 additions & 8 deletions Modules/socketmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1536,15 +1536,15 @@ makesockaddr(SOCKET_T sockfd, struct sockaddr *addr, size_t addrlen, int proto)
return ret;
#endif
}
#endif /* BTPROTO_HCI */

#if !defined(__FreeBSD__)
#ifdef BTPROTO_SCO
case BTPROTO_SCO:
{
struct sockaddr_sco *a = (struct sockaddr_sco *) addr;
return makebdaddr(&_BT_SCO_MEMB(a, bdaddr));
}
#endif /* !__FreeBSD__ */
#endif /* BTPROTO_HCI */
#endif /* BTPROTO_SCO */

default:
PyErr_SetString(PyExc_ValueError,
Expand Down Expand Up @@ -2149,7 +2149,8 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
*len_ret = sizeof *addr;
return 1;
}
#if !defined(__FreeBSD__)
#endif /* BTPROTO_HCI */
#ifdef BTPROTO_SCO
case BTPROTO_SCO:
{
const char *straddr;
Expand All @@ -2168,8 +2169,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
*len_ret = sizeof *addr;
return 1;
}
#endif /* !__FreeBSD__ */
#endif /* BTPROTO_HCI */
#endif /* BTPROTO_SCO */
default:
PyErr_Format(PyExc_OSError,
"%s(): unknown Bluetooth protocol", caller);
Expand Down Expand Up @@ -2719,11 +2719,11 @@ getsockaddrlen(PySocketSockObject *s, socklen_t *len_ret)
case BTPROTO_HCI:
*len_ret = sizeof (struct sockaddr_hci);
return 1;
#if !defined(__FreeBSD__)
#endif /* BTPROTO_HCI */
#ifdef BTPROTO_SCO
case BTPROTO_SCO:
*len_ret = sizeof (struct sockaddr_sco);
return 1;
#endif /* !__FreeBSD__ */
#endif /* BTPROTO_HCI */
default:
PyErr_SetString(PyExc_OSError, "getsockaddrlen: "
Expand Down
Loading