summaryrefslogtreecommitdiff
path: root/sysutils/hcidump/patches/patch-ab
blob: f10792dbb8d16d29d03a6e4c379d5458dcd68e1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
$NetBSD: patch-ab,v 1.1.1.1 2006/07/25 16:28:47 salo Exp $

fix NetBSD compiler warnings, and convert to NetBSD
bluetooth compatibility

--- hcidump/hcidump.c.orig	2004-03-03 19:52:10.000000000 +0100
+++ hcidump/hcidump.c
@@ -34,12 +34,13 @@
 #include <getopt.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <sys/ioctl.h>
 #include <string.h>
 #include <unistd.h>
 
-#include <netgraph/bluetooth/include/ng_hci.h>
-#include <netgraph/bluetooth/include/ng_l2cap.h>
-#include <netgraph/bluetooth/include/ng_btsocket.h>
+#include <netbt/bluetooth.h>
+#include <netbt/hci.h>
+#include <netbt/l2cap.h>
 
 #include "parser.h"
 #include "hcidump.h"
@@ -104,7 +105,7 @@ static void process_frames(char *dev, in
 		exit(1);
 	}
 	dh = (void *) buf;
-	frm.data = buf + DUMP_HDR_SIZE;
+	frm.data = (uint8_t *)(buf + DUMP_HDR_SIZE);
 	
 	if (!(ctrl = malloc(100))) {
 		perror("Can't allocate control buffer");
@@ -139,8 +140,8 @@ static void process_frames(char *dev, in
 		frm.in = 0;
 		cmsg = CMSG_FIRSTHDR(&msg);
 		while (cmsg) {
-			if (cmsg->cmsg_level == SOL_HCI_RAW &&
-			    cmsg->cmsg_type == SCM_HCI_RAW_DIRECTION)
+			if (cmsg->cmsg_level == BTPROTO_HCI &&
+			    cmsg->cmsg_type == SCM_HCI_DIRECTION)
 				memcpy(&frm.in,CMSG_DATA(cmsg),sizeof(frm.in));
 
 			if (cmsg->cmsg_level == SOL_SOCKET &&
@@ -192,7 +193,7 @@ static void read_dump(int file)
 		
 		frm.data_len = le16toh(dh.len);
 
-		if ((err = read_n(file, frm.data, frm.data_len)) < 0)
+		if ((err = read_n(file, (char *)frm.data, frm.data_len)) < 0)
 			goto failed;
 		if (!err) return;
 
@@ -210,16 +211,16 @@ failed:
 	exit(1);
 }
 
-static int open_file(char *file, int mode)
+static int open_file(char *file, int m)
 {
-	int f, flags;
+	int f, fl;
 
-	if (mode == WRITE)
-		flags = O_WRONLY | O_CREAT | O_APPEND;
+	if (m == WRITE)
+		fl = O_WRONLY | O_CREAT | O_APPEND;
 	else
-		flags = O_RDONLY;
+		fl = O_RDONLY;
 
-	if ((f = open(file, flags, 0600)) < 0) {
+	if ((f = open(file, fl, 0600)) < 0) {
 		perror("Can't open output file");
 		exit(1);
 	}
@@ -228,12 +229,12 @@ static int open_file(char *file, int mod
 
 static int open_socket(char *dev)
 {
-	struct sockaddr_hci addr;
-	struct ng_btsocket_hci_raw_filter flt;
+	struct sockaddr_bt addr;
+	struct hci_filter flt;
 	int s, opt;
 
 	/* Create HCI socket */
-	if ((s=socket(AF_BLUETOOTH, SOCK_RAW, BLUETOOTH_PROTO_HCI)) < 0) {
+	if ((s=socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI)) < 0) {
 		perror("Can't create HCI socket");
 		exit(1);
 	}
@@ -245,37 +246,60 @@ static int open_socket(char *dev)
 	}
 
 	opt = 1;
-	if (setsockopt(s, SOL_HCI_RAW, SO_HCI_RAW_DIRECTION, &opt, sizeof(opt)) < 0) {
-		perror("Can't enable data direction info");
+	if (setsockopt(s, SOL_SOCKET, SO_TIMESTAMP, &opt, sizeof(opt)) < 0) {
+		perror("Can't enable time stamp");
 		exit(1);
 	}
 
 	opt = 1;
-	if (setsockopt(s, SOL_SOCKET, SO_TIMESTAMP, &opt, sizeof(opt)) < 0) {
-		perror("Can't enable time stamp");
+	if (setsockopt(s, BTPROTO_HCI, SO_HCI_DIRECTION, &opt, sizeof(opt)) < 0) {
+		perror("Can't enable data direction info");
+		exit(1);
+	}
+
+	/* Setup filters */
+	memset(&flt, 0xff, sizeof(flt));
+	if (setsockopt(s, BTPROTO_HCI, SO_HCI_EVT_FILTER, (void const *) &flt, sizeof(flt)) < 0) {
+		perror("Can't set HCI Event filter");
 		exit(1);
 	}
 
-	/* Setup filter */
 	memset(&flt, 0xff, sizeof(flt));
-	if (setsockopt(s, SOL_HCI_RAW, SO_HCI_RAW_FILTER, (void const *) &flt, sizeof(flt)) < 0) {
-		perror("Can't set HCI filter");
+	if (setsockopt(s, BTPROTO_HCI, SO_HCI_PKT_FILTER, (void const *) &flt, sizeof(flt)) < 0) {
+		perror("Can't set HCI Packet filter");
 		exit(1);
 	}
 
 	/* Bind socket to the HCI device */
 	memset(&addr, 0, sizeof(addr));
-	addr.hci_len = sizeof(addr);
-	addr.hci_family = AF_BLUETOOTH;
+	addr.bt_len = sizeof(addr);
+	addr.bt_family = AF_BLUETOOTH;
 	if (dev != NULL) {
-		strncpy(addr.hci_node, dev, sizeof(addr.hci_node));
+		struct btreq btr;
 
-		if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
-			printf("Can't attach to device %s. %s(%d)\n", 
-					dev, strerror(errno), errno);
+		memset(&btr, 0, sizeof(btr));
+		strlcpy(btr.btr_name, dev, HCI_DEVNAME_SIZE);
+
+		if (ioctl(s, SIOCGBTINFO, &btr) < 0) {
+			printf("Can't get device info for '%s': %s(%d)\n",
+				dev, strerror(errno), errno);
 			exit(1);
 		}
+
+		if ((btr.btr_flags & (BTF_UP|BTF_RUNNING)) != (BTF_UP|BTF_RUNNING)) {
+			printf("Can't get BDADDR for '%s' (not running).\n", dev);
+			exit(1);
+		}
+
+		bdaddr_copy(&addr.bt_bdaddr, &btr.btr_bdaddr);
 	}
+
+    	if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
+		printf("Can't bind to device %s. %s(%d)\n", 
+			dev, strerror(errno), errno);
+		exit(1);
+	}
+
 	return s;
 }