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
|
$NetBSD: patch-ao,v 1.3 2011/03/20 19:56:48 plunky Exp $
--- src/hcidump.c.orig 2011-01-27 04:11:41.000000000 +0000
+++ src/hcidump.c
@@ -50,6 +50,10 @@
#include "parser/parser.h"
#include "parser/sdp.h"
+#ifndef AI_ADDRCONFIG
+#define AI_ADDRCONFIG 0
+#endif
+
#if __BYTE_ORDER == __LITTLE_ENDIAN
static inline uint64_t ntoh64(uint64_t n)
{
@@ -162,7 +166,7 @@ static inline int write_n(int fd, char *
return t;
}
-static int process_frames(int dev, int sock, int fd, unsigned long flags)
+static int process_frames(char *dev, int sock, int fd, unsigned long flags)
{
struct cmsghdr *cmsg;
struct msghdr msg;
@@ -204,7 +208,7 @@ static int process_frames(int dev, int s
if (dev == HCI_DEV_NONE)
printf("system: ");
else
- printf("device: hci%d ", dev);
+ printf("device: %s ", dev);
printf("snap_len: %d filter: 0x%lx\n", snap_len, parser.filter);
@@ -299,7 +303,8 @@ static int process_frames(int dev, int s
while (cmsg) {
switch (cmsg->cmsg_type) {
case HCI_CMSG_DIR:
- memcpy(&frm.in, CMSG_DATA(cmsg), sizeof(int));
+ memcpy(&i, CMSG_DATA(cmsg), sizeof(int));
+ frm.in = (uint8_t)i;
break;
case HCI_CMSG_TSTAMP:
memcpy(&frm.ts, CMSG_DATA(cmsg),
@@ -544,10 +549,13 @@ static int open_file(char *file, int mod
return fd;
}
-static int open_socket(int dev, unsigned long flags)
+static int open_socket(char *dev, unsigned long flags)
{
- struct sockaddr_hci addr;
+ struct sockaddr_bt addr;
struct hci_filter flt;
+#if 1
+ int sk, opt;
+#else
struct hci_dev_info di;
int sk, dd, opt;
@@ -573,6 +581,7 @@ static int open_socket(int dev, unsigned
hci_close_dev(dd);
}
+#endif
/* Create HCI socket */
sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
@@ -588,12 +597,13 @@ static int open_socket(int dev, unsigned
}
opt = 1;
- if (setsockopt(sk, SOL_HCI, HCI_TIME_STAMP, &opt, sizeof(opt)) < 0) {
+ if (setsockopt(sk, SOL_SOCKET, SO_TIMESTAMP, &opt, sizeof(opt)) < 0) {
perror("Can't enable time stamp");
return -1;
}
/* Setup filter */
+#if 0
hci_filter_clear(&flt);
hci_filter_all_ptypes(&flt);
hci_filter_all_events(&flt);
@@ -601,13 +611,34 @@ static int open_socket(int dev, unsigned
perror("Can't set filter");
return -1;
}
+#else
+ memset(&flt, 0xff, sizeof(flt));
+ if (setsockopt(sk, BTPROTO_HCI, SO_HCI_EVT_FILTER, &flt, sizeof(flt)) < 0) {
+ perror("Can't set event filter");
+ exit(1);
+ }
+
+ if (setsockopt(sk, BTPROTO_HCI, SO_HCI_PKT_FILTER, &flt, sizeof(flt)) < 0) {
+ perror("Can't set packet filter");
+ exit(1);
+ }
+#endif
/* Bind socket to the HCI device */
memset(&addr, 0, sizeof(addr));
+#if 0
addr.hci_family = AF_BLUETOOTH;
addr.hci_dev = dev;
+#else
+ addr.bt_len = sizeof(addr);
+ addr.bt_family = AF_BLUETOOTH;
+ if (dev != HCI_DEV_NONE && !bt_devaddr(dev, &addr.bt_bdaddr)) {
+ perror("device");
+ exit(1);
+ }
+#endif
if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
- printf("Can't attach to device hci%d. %s(%d)\n",
+ printf("Can't attach to device %s. %s(%d)\n",
dev, strerror(errno), errno);
return -1;
}
@@ -784,7 +815,7 @@ static int wait_connection(char *addr, c
return -1;
}
-static int run_server(int dev, char *addr, char *port, unsigned long flags)
+static int run_server(char *dev, char *addr, char *port, unsigned long flags)
{
while (1) {
int dd, sk;
@@ -914,7 +945,7 @@ int main(int argc, char *argv[])
{
unsigned long flags = 0;
unsigned long filter = 0;
- int device = 0;
+ char *device = HCI_DEV_NONE;
int defpsm = 0;
int defcompid = DEFAULT_COMPID;
int opt, pppdump_fd = -1, audio_fd = -1;
@@ -923,7 +954,7 @@ int main(int argc, char *argv[])
switch(opt) {
case 'i':
if (strcasecmp(optarg, "none") && strcasecmp(optarg, "system"))
- device = atoi(optarg + 3);
+ device = optarg;
else
device = HCI_DEV_NONE;
break;
|