Dump details for Bluetooth socket operations

* configure.ac (AC_CHECK_HEADERS): Add bluetooth/bluetooth.h.
* xlat/bt_protocols.in: New file.
* net.c [AF_BLUETOOTH && HAVE_BLUETOOTH_BLUETOOTH_H]: Include bluetooth
headers.
[PF_BLUETOOTH && HAVE_BLUETOOTH_BLUETOOTH_H]: Include "xlat/bt_protocols.h".
(printsock) [AF_BLUETOOTH && HAVE_BLUETOOTH_BLUETOOTH_H]: Dump details
for AF_BLUETOOTH sockets.
(sys_socket) [PF_BLUETOOTH && HAVE_BLUETOOTH_BLUETOOTH_H]: Decode
protocol for PF_BLUETOOTH sockets.

Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
diff --git a/configure.ac b/configure.ac
index 54e9941..98669fa 100644
--- a/configure.ac
+++ b/configure.ac
@@ -227,6 +227,7 @@
 AC_CHECK_HEADERS(m4_normalize([
 	asm/cachectl.h
 	asm/sysmips.h
+	bluetooth/bluetooth.h
 	elf.h
 	inttypes.h
 	ioctls.h
diff --git a/net.c b/net.c
index a0e90a8..c38b110 100644
--- a/net.c
+++ b/net.c
@@ -90,6 +90,13 @@
 #if defined(HAVE_LINUX_ICMP_H)
 # include <linux/icmp.h>
 #endif
+#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
+# include <bluetooth/bluetooth.h>
+# include <bluetooth/hci.h>
+# include <bluetooth/l2cap.h>
+# include <bluetooth/rfcomm.h>
+# include <bluetooth/sco.h>
+#endif
 #ifndef PF_UNSPEC
 # define PF_UNSPEC AF_UNSPEC
 #endif
@@ -110,6 +117,10 @@
 #include "xlat/netlink_protocols.h"
 #endif
 
+#if defined(HAVE_BLUETOOTH_BLUETOOTH_H)
+# include "xlat/bt_protocols.h"
+#endif
+
 #include "xlat/msg_flags.h"
 #include "xlat/sockoptions.h"
 
@@ -177,6 +188,12 @@
 #ifdef AF_NETLINK
 		struct sockaddr_nl nl;
 #endif
+#ifdef HAVE_BLUETOOTH_BLUETOOTH_H
+		struct sockaddr_hci hci;
+		struct sockaddr_l2 l2;
+		struct sockaddr_rc rc;
+		struct sockaddr_sco sco;
+#endif
 	} addrbuf;
 	char string_addr[100];
 
@@ -288,6 +305,26 @@
 		tprintf("pid=%d, groups=%08x", addrbuf.nl.nl_pid, addrbuf.nl.nl_groups);
 		break;
 #endif /* AF_NETLINK */
+#if defined(AF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
+	case AF_BLUETOOTH:
+		tprintf("{sco_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X} or "
+			"{rc_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, rc_channel=%d} or "
+			"{l2_psm=htobs(%d), l2_bdaddr=%02X:%02X:%02X:%02X:%02X:%02X, l2_cid=htobs(%d)} or "
+			"{hci_dev=htobs(%d)}",
+			addrbuf.sco.sco_bdaddr.b[0], addrbuf.sco.sco_bdaddr.b[1],
+			addrbuf.sco.sco_bdaddr.b[2], addrbuf.sco.sco_bdaddr.b[3],
+			addrbuf.sco.sco_bdaddr.b[4], addrbuf.sco.sco_bdaddr.b[5],
+			addrbuf.rc.rc_bdaddr.b[0], addrbuf.rc.rc_bdaddr.b[1],
+			addrbuf.rc.rc_bdaddr.b[2], addrbuf.rc.rc_bdaddr.b[3],
+			addrbuf.rc.rc_bdaddr.b[4], addrbuf.rc.rc_bdaddr.b[5],
+			addrbuf.rc.rc_channel,
+			btohs(addrbuf.l2.l2_psm), addrbuf.l2.l2_bdaddr.b[0],
+			addrbuf.l2.l2_bdaddr.b[1], addrbuf.l2.l2_bdaddr.b[2],
+			addrbuf.l2.l2_bdaddr.b[3], addrbuf.l2.l2_bdaddr.b[4],
+			addrbuf.l2.l2_bdaddr.b[5], btohs(addrbuf.l2.l2_cid),
+			btohs(addrbuf.hci.hci_dev));
+		break;
+#endif /* AF_BLUETOOTH && HAVE_BLUETOOTH_BLUETOOTH_H */
 	/* AF_AX25 AF_APPLETALK AF_NETROM AF_BRIDGE AF_AAL5
 	AF_X25 AF_ROSE etc. still need to be done */
 
@@ -547,6 +584,11 @@
 			printxval(netlink_protocols, tcp->u_arg[2], "NETLINK_???");
 			break;
 #endif
+#if defined(PF_BLUETOOTH) && defined(HAVE_BLUETOOTH_BLUETOOTH_H)
+		case PF_BLUETOOTH:
+			printxval(bt_protocols, tcp->u_arg[2], "BTPROTO_???");
+			break;
+#endif
 		default:
 			tprintf("%lu", tcp->u_arg[2]);
 			break;
diff --git a/xlat/bt_protocols.in b/xlat/bt_protocols.in
new file mode 100644
index 0000000..1f7f348
--- /dev/null
+++ b/xlat/bt_protocols.in
@@ -0,0 +1,8 @@
+BTPROTO_L2CAP
+BTPROTO_HCI
+BTPROTO_SCO
+BTPROTO_RFCOMM
+BTPROTO_BNEP
+BTPROTO_CMTP
+BTPROTO_HIDP
+BTPROTO_AVDTP