bpo-36590: Add Bluetooth RFCOMM and support for Windows. (GH-12767)

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>
This commit is contained in:
Greg Bowser 2019-08-02 16:29:52 -04:00 committed by Steve Dower
parent cb65b3a4f4
commit 8fbece135d
4 changed files with 158 additions and 6 deletions

43
Modules/socketmodule.h Normal file → Executable file
View file

@ -14,6 +14,47 @@
#else /* MS_WINDOWS */
# include <winsock2.h>
/*
* If Windows has bluetooth support, include bluetooth constants.
*/
#ifdef AF_BTH
# include <ws2bth.h>
# include <pshpack1.h>
/*
* The current implementation assumes the bdaddr in the sockaddr structs
* will be a bdaddr_t. We treat this as an opaque type: on *nix systems, it
* will be a struct with a single member (an array of six bytes). On windows,
* we typedef this to ULONGLONG to match the Windows definition.
*/
typedef ULONGLONG bdaddr_t;
/*
* Redefine SOCKADDR_BTH to provide names compatible with _BT_RC_MEMB() macros.
*/
struct SOCKADDR_BTH_REDEF {
union {
USHORT addressFamily;
USHORT family;
};
union {
ULONGLONG btAddr;
bdaddr_t bdaddr;
};
GUID serviceClassId;
union {
ULONG port;
ULONG channel;
};
};
# include <poppack.h>
#endif
/* Windows 'supports' CMSG_LEN, but does not follow the POSIX standard
* interface at all, so there is no point including the code that
* attempts to use it.
@ -199,6 +240,8 @@ typedef union sock_addr {
struct sockaddr_rc bt_rc;
struct sockaddr_sco bt_sco;
struct sockaddr_hci bt_hci;
#elif defined(MS_WINDOWS)
struct SOCKADDR_BTH_REDEF bt_rc;
#endif
#ifdef HAVE_NETPACKET_PACKET_H
struct sockaddr_ll ll;