[Python-checkins] r53774 - in python/trunk: Misc/NEWS Modules/socketmodule.c Modules/socketmodule.h

martin.v.loewis python-checkins at python.org
Wed Feb 14 11:07:39 CET 2007


Author: martin.v.loewis
Date: Wed Feb 14 11:07:37 2007
New Revision: 53774

Modified:
   python/trunk/Misc/NEWS
   python/trunk/Modules/socketmodule.c
   python/trunk/Modules/socketmodule.h
Log:
Patch #1432399: Add HCI sockets.


Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Wed Feb 14 11:07:37 2007
@@ -366,6 +366,8 @@
 Extension Modules
 -----------------
 
+- Patch #1432399: Support the HCI protocol for bluetooth sockets
+
 - Patch #1657276: Make NETLINK_DNRTMSG conditional.
 
 - Bug #1653736: Complain about keyword arguments to time.isoformat.

Modified: python/trunk/Modules/socketmodule.c
==============================================================================
--- python/trunk/Modules/socketmodule.c	(original)
+++ python/trunk/Modules/socketmodule.c	Wed Feb 14 11:07:37 2007
@@ -362,20 +362,25 @@
 #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 @@
 			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 @@
 			*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 @@
 		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 @@
 #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

Modified: python/trunk/Modules/socketmodule.h
==============================================================================
--- python/trunk/Modules/socketmodule.h	(original)
+++ python/trunk/Modules/socketmodule.h	Wed Feb 14 11:07:37 2007
@@ -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 @@
 	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;


More information about the Python-checkins mailing list