Skip to content
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

bpo-36590: Add Bluetooth RFCOMM support for Windows. #12767

Merged
merged 1 commit into from Aug 2, 2019

Conversation

topnotcher
Copy link
Contributor

@topnotcher topnotcher commented Apr 10, 2019

The change was pretty straightforward. The only difficulty was that
Windows' SOCKADDR_BTH contains member names incompatible with the
_BT_RC_MEMB() macros. To workaround this, a new struct,
SOCKADDR_BTH_REDEF was defined and contains unions with both the Windows
and Linux member names.

pair: Nate Duarte slacknate@gmail.com

https://bugs.python.org/issue36590

@the-knights-who-say-ni
Copy link

the-knights-who-say-ni commented Apr 10, 2019

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).

Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA (this might be simply due to a missing "GitHub Name" entry in your b.p.o account settings). This is necessary for legal reasons before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

You can check yourself to see if the CLA has been received.

Thanks again for your contribution, we look forward to reviewing it!

@ZackerySpytz
Copy link
Contributor

ZackerySpytz commented Apr 11, 2019

I believe unit tests are certainly needed for such a change.

Copy link
Member

@zooba zooba left a comment

Agreed it needs some kind of test (at least to validate the address parsing/rendering, if not actual functionality).

Also a couple of comments about testing for macro existence rather than platform. I didn't put comments on every instance, but it applies to all of them.

@@ -518,6 +518,15 @@ remove_unusable_flags(PyObject *m)
#endif
#endif

#if defined(MS_WINDOWS) && defined(AF_BTH)
Copy link
Member

@zooba zooba Apr 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like AF_BTH is defined in all supported versions of Windows, so no need for the second part of the test.

Copy link
Contributor Author

@topnotcher topnotcher Jun 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done -- only checks for MS_WINDOWS now.

@@ -1877,6 +1916,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
case AF_BLUETOOTH:
{
switch (s->sock_proto) {
#ifndef MS_WINDOWS
Copy link
Member

@zooba zooba Apr 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we test whether macros are defined rather than checking for platform? (Also, is BTHPROTO_L2CAP the same as BTPROTO_L2CAP here?)

Copy link
Contributor Author

@topnotcher topnotcher Jun 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed all of the ifndef MS_WINDOWS tests to ifdef BTPROTO_X and added/changed such tests in other cases (e.g. ifdef BTPROTO_SCO instead of checking for not FreeBSD).

BTHPROTO_L2CAP is the same as BTPROTO_L2CAP. Windows defines the constant, but winsock does not implement L2CAP support. I was able to build with this, but creating a socket with BTPROTO_L2CAP with winsock fails.

@topnotcher
Copy link
Contributor Author

topnotcher commented Jun 27, 2019

Added some basic unittests that check for some constants and try to create sockets with various protocols.

I did not add any tests for the address parsing/rendering as I wasn't sure if there is a good way to do so. The only way to hit makebdaddr() and setbdaddr() is via methods such as connect() and bind(), but we can't necessarily expect those to work without a Bluetooth controller present (I did try on windows and the results were unfavorable).

The change was pretty straightforward. The only difficulty was that
Windows' SOCKADDR_BTH contains member names incompatible with the
_BT_RC_MEMB() macros. To workaround this, a new struct,
SOCKADDR_BTH_REDEF was defined and contains unions with both the Windows
and Linux member names.

Support for RFCOMM, L2CAP, HCI, SCO is based on the BTPROTO_* macros
being defined. Winsock only supports RFCOMM, even though it has a
BTHPROTO_L2CAP macro. L2CAP support would build on windows, but not
necessarily work.

This also adds some basic unittests for constants (all of which existed
prior to this commit, just not on windows) and creating sockets.

pair: Nate Duarte <slacknate@gmail.com>
@zooba
Copy link
Member

zooba commented Aug 2, 2019

LGTM. Sorry for the delay in getting it merged

@zooba zooba merged commit 8fbece1 into python:master Aug 2, 2019
lisroach pushed a commit to lisroach/cpython that referenced this pull request Sep 10, 2019
)

Support for RFCOMM, L2CAP, HCI, SCO is based on the BTPROTO_* macros
being defined. Winsock only supports RFCOMM, even though it has a
BTHPROTO_L2CAP macro. L2CAP support would build on windows, but not
necessarily work.

This also adds some basic unittests for constants (all of which existed
prior to this commit, just not on windows) and creating sockets.

pair: Nate Duarte <slacknate@gmail.com>
DinoV pushed a commit to DinoV/cpython that referenced this pull request Jan 14, 2020
)

Support for RFCOMM, L2CAP, HCI, SCO is based on the BTPROTO_* macros
being defined. Winsock only supports RFCOMM, even though it has a
BTHPROTO_L2CAP macro. L2CAP support would build on windows, but not
necessarily work.

This also adds some basic unittests for constants (all of which existed
prior to this commit, just not on windows) and creating sockets.

pair: Nate Duarte <slacknate@gmail.com>
websurfer5 pushed a commit to websurfer5/cpython that referenced this pull request Jul 20, 2020
)

Support for RFCOMM, L2CAP, HCI, SCO is based on the BTPROTO_* macros
being defined. Winsock only supports RFCOMM, even though it has a
BTHPROTO_L2CAP macro. L2CAP support would build on windows, but not
necessarily work.

This also adds some basic unittests for constants (all of which existed
prior to this commit, just not on windows) and creating sockets.

pair: Nate Duarte <slacknate@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants