summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2007-02-14 10:07:37 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2007-02-14 10:07:37 (GMT)
commit45423a7571e7041bf4b6ee6238c4719139ebe1cb (patch)
treee3d7748a2bd50adea3941e882782cdedff12446f /Modules
parentf19c1b5e0e753c85f6df8a2dec5f4bb75743fc10 (diff)
downloadcpython-45423a7571e7041bf4b6ee6238c4719139ebe1cb.zip
cpython-45423a7571e7041bf4b6ee6238c4719139ebe1cb.tar.gz
cpython-45423a7571e7041bf4b6ee6238c4719139ebe1cb.tar.bz2
Patch #1432399: Add HCI sockets.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/socketmodule.c34
-rw-r--r--Modules/socketmodule.h2
2 files changed, 36 insertions, 0 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 7ef2e04..d79db27 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -362,20 +362,25 @@ const char *inet_ntop(int af, const void *src, char *dst, socklen_t size);
#if defined(__FreeBSD__)
#define BTPROTO_L2CAP BLUETOOTH_PROTO_L2CAP
#define BTPROTO_RFCOMM BLUETOOTH_PROTO_RFCOMM
+#define BTPROTO_HCI BLUETOOTH_PROTO_HCI
#define sockaddr_l2 sockaddr_l2cap
#define sockaddr_rc sockaddr_rfcomm
#define _BT_L2_MEMB(sa, memb) ((sa)->l2cap_##memb)
#define _BT_RC_MEMB(sa, memb) ((sa)->rfcomm_##memb)
+#define _BT_HCI_MEMB(sa, memb) ((sa)->hci_##memb)
#elif defined(__NetBSD__)
#define sockaddr_l2 sockaddr_bt
#define sockaddr_rc sockaddr_bt
+#define sockaddr_hci sockaddr_bt
#define sockaddr_sco sockaddr_bt
#define _BT_L2_MEMB(sa, memb) ((sa)->bt_##memb)
#define _BT_RC_MEMB(sa, memb) ((sa)->bt_##memb)
+#define _BT_HCI_MEMB(sa, memb) ((sa)->bt_##memb)
#define _BT_SCO_MEMB(sa, memb) ((sa)->bt_##memb)
#else
#define _BT_L2_MEMB(sa, memb) ((sa)->l2_##memb)
#define _BT_RC_MEMB(sa, memb) ((sa)->rc_##memb)
+#define _BT_HCI_MEMB(sa, memb) ((sa)->hci_##memb)
#define _BT_SCO_MEMB(sa, memb) ((sa)->sco_##memb)
#endif
#endif
@@ -1119,6 +1124,14 @@ makesockaddr(int sockfd, struct sockaddr *addr, int addrlen, int proto)
return ret;
}
+ case BTPROTO_HCI:
+ {
+ struct sockaddr_hci *a = (struct sockaddr_hci *) addr;
+ PyObject *ret = NULL;
+ ret = Py_BuildValue("i", _BT_HCI_MEMB(a, dev));
+ return ret;
+ }
+
#if !defined(__FreeBSD__)
case BTPROTO_SCO:
{
@@ -1347,6 +1360,19 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
*len_ret = sizeof *addr;
return 1;
}
+ case BTPROTO_HCI:
+ {
+ struct sockaddr_hci *addr = (struct sockaddr_hci *) _BT_SOCKADDR_MEMB(s, hci);
+ _BT_HCI_MEMB(addr, family) = AF_BLUETOOTH;
+ if (!PyArg_ParseTuple(args, "i", &_BT_HCI_MEMB(addr, dev))) {
+ PyErr_SetString(socket_error, "getsockaddrarg: "
+ "wrong format");
+ return 0;
+ }
+ *addr_ret = (struct sockaddr *) addr;
+ *len_ret = sizeof *addr;
+ return 1;
+ }
#if !defined(__FreeBSD__)
case BTPROTO_SCO:
{
@@ -1485,6 +1511,9 @@ getsockaddrlen(PySocketSockObject *s, socklen_t *len_ret)
case BTPROTO_RFCOMM:
*len_ret = sizeof (struct sockaddr_rc);
return 1;
+ case BTPROTO_HCI:
+ *len_ret = sizeof (struct sockaddr_hci);
+ return 1;
#if !defined(__FreeBSD__)
case BTPROTO_SCO:
*len_ret = sizeof (struct sockaddr_sco);
@@ -4430,6 +4459,11 @@ init_socket(void)
#ifdef USE_BLUETOOTH
PyModule_AddIntConstant(m, "AF_BLUETOOTH", AF_BLUETOOTH);
PyModule_AddIntConstant(m, "BTPROTO_L2CAP", BTPROTO_L2CAP);
+ PyModule_AddIntConstant(m, "BTPROTO_HCI", BTPROTO_HCI);
+ PyModule_AddIntConstant(m, "SOL_HCI", SOL_HCI);
+ PyModule_AddIntConstant(m, "HCI_TIME_STAMP", HCI_TIME_STAMP);
+ PyModule_AddIntConstant(m, "HCI_DATA_DIR", HCI_DATA_DIR);
+ PyModule_AddIntConstant(m, "HCI_FILTER", HCI_FILTER);
#if !defined(__FreeBSD__)
PyModule_AddIntConstant(m, "BTPROTO_SCO", BTPROTO_SCO);
#endif
diff --git a/Modules/socketmodule.h b/Modules/socketmodule.h
index 84f2422..a4382ab 100644
--- a/Modules/socketmodule.h
+++ b/Modules/socketmodule.h
@@ -46,6 +46,7 @@
#include <bluetooth/rfcomm.h>
#include <bluetooth/l2cap.h>
#include <bluetooth/sco.h>
+#include <bluetooth/hci.h>
#endif
#ifdef HAVE_BLUETOOTH_H
@@ -98,6 +99,7 @@ typedef union sock_addr {
struct sockaddr_l2 bt_l2;
struct sockaddr_rc bt_rc;
struct sockaddr_sco bt_sco;
+ struct sockaddr_hci bt_hci;
#endif
#ifdef HAVE_NETPACKET_PACKET_H
struct sockaddr_ll ll;