[PATCH] Bluetooth support.

David Woodhouse dwmw2 at infradead.org
Mon Nov 23 20:58:32 EST 2009


This is just the first part -- it adds support for correctly reporting
incoming connections when there's an external dæmon accepting the
connections and invoking 'sshd -i' with them, like inetd does.

In later patches I'll extend sshd to listen on a Bluetooth socket (and
advertise the service in SDP) for itself, and extend the ssh client to
make the connection directly. For now, I'm testing with
http://david.woodhou.se/btserv.c and
ssh -o 'ProxyCommand socat stdio SOCKET-CONNECT:31:3:x1ec1e4e21f000100' root at bluetooth

Index: canohost.c
===================================================================
RCS file: /cvs/openssh/canohost.c,v
retrieving revision 1.75
diff -u -p -r1.75 canohost.c
--- canohost.c	21 Jun 2009 08:13:58 -0000	1.75
+++ canohost.c	23 Nov 2009 09:50:32 -0000
@@ -20,6 +20,11 @@
 #include <netinet/in.h>
 #include <arpa/inet.h>
 
+#ifdef HAVE_BLUETOOTH
+#include <bluetooth/bluetooth.h>
+#include <bluetooth/rfcomm.h>
+#endif
+
 #include <ctype.h>
 #include <errno.h>
 #include <netdb.h>
@@ -60,6 +65,16 @@ get_remote_hostname(int sock, int use_dn
 		cleanup_exit(255);
 	}
 
+#ifdef HAVE_BLUETOOTH
+	if (from.ss_family == AF_BLUETOOTH) {
+		struct sockaddr_rc *from_rc = (void *)&from;
+		char ba[28];
+
+		sprintf(ba, "Bluetooth:");
+		ba2str(&from_rc->rc_bdaddr, ba + 10);
+		return xstrdup(ba);
+	}
+#endif
 	if (from.ss_family == AF_INET)
 		check_ip_options(sock, ntop);
 
@@ -264,6 +279,16 @@ get_socket_address(int sock, int remote,
 			return NULL;
 	}
 
+#ifdef HAVE_BLUETOOTH
+	if (addr.ss_family == AF_BLUETOOTH) {
+		struct sockaddr_rc *from_rc = (void *)&addr;
+		char ba[28];
+
+		sprintf(ba, "Bluetooth:");
+		ba2str(&from_rc->rc_bdaddr, ba + 10);
+		return xstrdup(ba);
+	}
+#endif
 	/* Work around Linux IPv6 weirdness */
 	if (addr.ss_family == AF_INET6)
 		addrlen = sizeof(struct sockaddr_in6);
@@ -375,6 +400,13 @@ get_sock_port(int sock, int local)
 		}
 	}
 
+#ifdef HAVE_BLUETOOTH
+	if (from.ss_family == AF_BLUETOOTH) {
+		struct sockaddr_rc *from_rc = (void *)&from;
+
+		return from_rc->rc_channel;
+	}
+#endif
 	/* Work around Linux IPv6 weirdness */
 	if (from.ss_family == AF_INET6)
 		fromlen = sizeof(struct sockaddr_in6);
Index: configure.ac
===================================================================
RCS file: /cvs/openssh/configure.ac,v
retrieving revision 1.430
diff -u -p -r1.430 configure.ac
--- configure.ac	11 Oct 2009 10:50:20 -0000	1.430
+++ configure.ac	23 Nov 2009 09:50:35 -0000
@@ -3636,6 +3636,27 @@ else
 fi
 AC_SUBST(mansubdir)
 
+# Check whether to support Bluetooth
+BLUETOOTH_MSG="no"
+AC_ARG_ENABLE(bluetooth,
+	[  --disable-bluetooth     disable Bluetooth support if detected [no]],
+	[
+		if test "x$enableval" = "xno" ; then
+			disable_bluetooth=yes
+		fi
+	]
+)
+if test -z "$disable_bluetooth" ; then
+	AC_CHECK_HEADERS(bluetooth/bluetooth.h,
+		[ AC_CHECK_LIB(bluetooth, ba2str,
+			[ LIBS="$LIBS -lbluetooth"
+			  AC_DEFINE(HAVE_BLUETOOTH)
+			  BLUETOOTH_MSG="yes"
+			])
+		]
+	)
+fi
+
 # Check whether to enable MD5 passwords
 MD5_MSG="no"
 AC_ARG_WITH(md5-passwords,
@@ -4231,6 +4252,7 @@ echo "                     S/KEY support
 echo "              TCP Wrappers support: $TCPW_MSG"
 echo "              MD5 password support: $MD5_MSG"
 echo "                   libedit support: $LIBEDIT_MSG"
+echo "                 Bluetooth support: $BLUETOOTH_MSG"
 echo "  Solaris process contract support: $SPC_MSG"
 echo "       IP address in \$DISPLAY hack: $DISPLAY_HACK_MSG"
 echo "           Translate v4 in v6 hack: $IPV4_IN6_HACK_MSG"
Index: packet.c
===================================================================
RCS file: /cvs/openssh/packet.c,v
retrieving revision 1.169
diff -u -p -r1.169 packet.c
--- packet.c	2 Oct 2009 01:49:04 -0000	1.169
+++ packet.c	23 Nov 2009 09:50:36 -0000
@@ -308,6 +308,10 @@ packet_connection_is_on_socket(void)
 		return 0;
 	if (fromlen != tolen || memcmp(&from, &to, fromlen) != 0)
 		return 0;
+#ifdef HAVE_BLUETOOTH
+	if (from.ss_family == AF_BLUETOOTH)
+		return 1;
+#endif
 	if (from.ss_family != AF_INET && from.ss_family != AF_INET6)
 		return 0;
 	return 1;


-- 
dwmw2



More information about the openssh-unix-dev mailing list