Line 0
Link Here
|
|
|
1 |
--- common/devices/unixbluetooth.c.orig 2008-10-05 12:14:31.000000000 +0200 |
2 |
+++ common/devices/unixbluetooth.c 2008-11-08 20:01:59.000000000 +0100 |
3 |
@@ -50,56 +50,293 @@ |
4 |
|
5 |
#ifdef HAVE_BLUETOOTH_NETGRAPH /* FreeBSD / netgraph */ |
6 |
|
7 |
-#include <bitstring.h> |
8 |
-#include <netgraph/bluetooth/include/ng_hci.h> |
9 |
-#include <netgraph/bluetooth/include/ng_l2cap.h> |
10 |
-#include <netgraph/bluetooth/include/ng_btsocket.h> |
11 |
+#include <bluetooth.h> |
12 |
+#include <sdp.h> |
13 |
|
14 |
#define BTPROTO_RFCOMM BLUETOOTH_PROTO_RFCOMM |
15 |
#define BDADDR_ANY NG_HCI_BDADDR_ANY |
16 |
+#define GNOKII_SERIAL_PORT_CLASS SDP_SERVICE_CLASS_SERIAL_PORT |
17 |
+#define GNOKII_DIALUP_NETWORK_CLASS SDP_SERVICE_CLASS_DIALUP_NETWORKING |
18 |
#define sockaddr_rc sockaddr_rfcomm |
19 |
#define rc_family rfcomm_family |
20 |
#define rc_bdaddr rfcomm_bdaddr |
21 |
#define rc_channel rfcomm_channel |
22 |
-#define bacpy(dst, src) memcpy((dst), (src), sizeof(bdaddr_t)) |
23 |
|
24 |
-#ifndef HAVE_BT_ATON |
25 |
+#else /* Linux / BlueZ support */ |
26 |
|
27 |
-static int bt_aton(const char *str, bdaddr_t *ba) |
28 |
-{ |
29 |
- char ch; |
30 |
- unsigned int b[6]; |
31 |
+#include <bluetooth/bluetooth.h> |
32 |
+#include <bluetooth/rfcomm.h> |
33 |
+#include <bluetooth/sdp.h> |
34 |
+#include <bluetooth/sdp_lib.h> |
35 |
|
36 |
- memset(ba, 0, sizeof(*ba)); |
37 |
- if (sscanf(str, "%x:%x:%x:%x:%x:%x%c", b + 0, b + 1, b + 2, b + 3, b + 4, b + 5, &ch) != 6) return 0; |
38 |
- if ((b[0] | b[1] | b[2] | b[3] | b[4] | b[5]) > 0xff) return 0; |
39 |
- |
40 |
- ba->b[0] = b[0]; |
41 |
- ba->b[1] = b[1]; |
42 |
- ba->b[2] = b[2]; |
43 |
- ba->b[3] = b[3]; |
44 |
- ba->b[4] = b[4]; |
45 |
- ba->b[5] = b[5]; |
46 |
+#define GNOKII_SERIAL_PORT_CLASS SERIAL_PORT_SVCLASS_ID |
47 |
+#define GNOKII_DIALUP_NETWORK_CLASS DIALUP_NET_SVCLASS_ID |
48 |
|
49 |
- return 1; |
50 |
-} |
51 |
+#endif |
52 |
+ |
53 |
+#ifdef HAVE_BLUETOOTH_NETGRAPH /* FreeBSD / netgraph */ |
54 |
|
55 |
-#endif /* HAVE_BT_ATON */ |
56 |
+/* |
57 |
+** FreeBSD version of the find_service_channel function. |
58 |
+** Written by Guido Falsi <mad@madpilot.net>. |
59 |
+** Contains code taken from FreeBSD's sdpcontrol and rfcomm_sppd |
60 |
+** programs, which are Copyright (c) 2001-2003 Maksim Yevmenkin |
61 |
+** <m_evmenkin@yahoo.com>. |
62 |
+** |
63 |
+** Also thanks to Iain Hibbert for his suggestions. |
64 |
+*/ |
65 |
|
66 |
-static int str2ba(const char *str, bdaddr_t *ba) |
67 |
+static int find_service_channel(bdaddr_t *adapter, bdaddr_t *device, int only_gnapplet, uint16_t svclass_id) |
68 |
{ |
69 |
- return !bt_aton(str, ba); |
70 |
-} |
71 |
+ int i, channel = -1; |
72 |
+ char name[64]; |
73 |
+ void *ss = NULL; |
74 |
|
75 |
-#else /* Linux / BlueZ support */ |
76 |
+ uint32_t attrs[] = |
77 |
+ { |
78 |
+ SDP_ATTR_RANGE( SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST, |
79 |
+ SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST), |
80 |
+ SDP_ATTR_RANGE( SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID + SDP_ATTR_SERVICE_NAME_OFFSET, |
81 |
+ SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID + SDP_ATTR_SERVICE_NAME_OFFSET), |
82 |
+ }; |
83 |
+ #define attrs_len (sizeof(attrs)/sizeof(attrs[0])) |
84 |
+ |
85 |
+ /* Buffer for the attributes */ |
86 |
+ #define NRECS 25 /* request this much records from the SDP server */ |
87 |
+ #define BSIZE 256 /* one attribute buffer size */ |
88 |
+ static uint8_t buffer[NRECS * attrs_len][BSIZE]; |
89 |
+ |
90 |
+ /* SDP attributes */ |
91 |
+ static sdp_attr_t values[NRECS * attrs_len]; |
92 |
+ #define values_len (sizeof(values)/sizeof(values[0])) |
93 |
+ |
94 |
+ /* Initialize attribute values array */ |
95 |
+ for (i = 0; i < values_len; i ++) { |
96 |
+ values[i].flags = SDP_ATTR_INVALID; |
97 |
+ values[i].attr = 0; |
98 |
+ values[i].vlen = BSIZE; |
99 |
+ values[i].value = buffer[i]; |
100 |
+ } |
101 |
|
102 |
-#include <bluetooth/bluetooth.h> |
103 |
-#include <bluetooth/rfcomm.h> |
104 |
-#include <bluetooth/sdp.h> |
105 |
-#include <bluetooth/sdp_lib.h> |
106 |
+ if ((ss = sdp_open(adapter, device)) == NULL) |
107 |
+ return -1; |
108 |
|
109 |
-#endif |
110 |
+ if (sdp_error(ss) != 0) |
111 |
+ goto end; |
112 |
+ |
113 |
+ if (sdp_search(ss, 1, &svclass_id, attrs_len, attrs, values_len, values) != 0) |
114 |
+ goto end; |
115 |
+ |
116 |
+ for (i = 0; i < values_len; i++) |
117 |
+ { |
118 |
+ if (values[i].flags != SDP_ATTR_OK) |
119 |
+ break; |
120 |
+ |
121 |
+ union { |
122 |
+ uint8_t uint8; |
123 |
+ uint16_t uint16; |
124 |
+ uint32_t uint32; |
125 |
+ uint64_t uint64; |
126 |
+ int128_t int128; |
127 |
+ } value; |
128 |
+ uint8_t *start, *end; |
129 |
+ uint32_t type, len; |
130 |
+ |
131 |
+ start = values[i].value; |
132 |
+ end = values[i].value + values[i].vlen; |
133 |
+ |
134 |
+ switch (values[i].attr) { |
135 |
+ case SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST: |
136 |
+ SDP_GET8(type, start); |
137 |
+ switch (type) { |
138 |
+ case SDP_DATA_SEQ8: |
139 |
+ SDP_GET8(len, start); |
140 |
+ break; |
141 |
+ |
142 |
+ case SDP_DATA_SEQ16: |
143 |
+ SDP_GET16(len, start); |
144 |
+ break; |
145 |
+ |
146 |
+ case SDP_DATA_SEQ32: |
147 |
+ SDP_GET32(len, start); |
148 |
+ break; |
149 |
+ |
150 |
+ default: |
151 |
+ goto end; |
152 |
+ break; |
153 |
+ } |
154 |
+ |
155 |
+ SDP_GET8(type, start); |
156 |
+ switch (type) { |
157 |
+ case SDP_DATA_SEQ8: |
158 |
+ SDP_GET8(len, start); |
159 |
+ break; |
160 |
+ |
161 |
+ case SDP_DATA_SEQ16: |
162 |
+ SDP_GET16(len, start); |
163 |
+ break; |
164 |
+ |
165 |
+ case SDP_DATA_SEQ32: |
166 |
+ SDP_GET32(len, start); |
167 |
+ break; |
168 |
+ |
169 |
+ default: |
170 |
+ goto end; |
171 |
+ break; |
172 |
+ } |
173 |
+ |
174 |
+ while (start < end) { |
175 |
+ SDP_GET8(type, start); |
176 |
+ switch (type) { |
177 |
+ case SDP_DATA_UUID16: |
178 |
+ SDP_GET16(value.uint16, start); |
179 |
+ break; |
180 |
+ |
181 |
+ case SDP_DATA_UUID32: |
182 |
+ SDP_GET32(value.uint32, start); |
183 |
+ break; |
184 |
+ |
185 |
+ case SDP_DATA_UUID128: |
186 |
+ SDP_GET_UUID128(&value.int128, start); |
187 |
+ break; |
188 |
+ |
189 |
+ default: |
190 |
+ goto end; |
191 |
+ break; |
192 |
+ } |
193 |
+ if(value.uint16 == 3) { |
194 |
+ SDP_GET8(type, start); |
195 |
+ switch (type) { |
196 |
+ case SDP_DATA_UINT8: |
197 |
+ case SDP_DATA_INT8: |
198 |
+ SDP_GET8(value.uint8, start); |
199 |
+ channel = value.uint8; |
200 |
+ break; |
201 |
+ |
202 |
+ case SDP_DATA_UINT16: |
203 |
+ case SDP_DATA_INT16: |
204 |
+ SDP_GET16(value.uint16, start); |
205 |
+ channel = value.uint16; |
206 |
+ break; |
207 |
+ |
208 |
+ case SDP_DATA_UINT32: |
209 |
+ case SDP_DATA_INT32: |
210 |
+ SDP_GET32(value.uint32, start); |
211 |
+ channel = value.uint32; |
212 |
+ break; |
213 |
+ |
214 |
+ default: |
215 |
+ goto end; |
216 |
+ break; |
217 |
+ } |
218 |
+ } else { |
219 |
+ SDP_GET8(type, start); |
220 |
+ switch (type) { |
221 |
+ case SDP_DATA_SEQ8: |
222 |
+ case SDP_DATA_UINT8: |
223 |
+ case SDP_DATA_INT8: |
224 |
+ case SDP_DATA_BOOL: |
225 |
+ SDP_GET8(value.uint8, start); |
226 |
+ break; |
227 |
+ |
228 |
+ case SDP_DATA_SEQ16: |
229 |
+ case SDP_DATA_UINT16: |
230 |
+ case SDP_DATA_INT16: |
231 |
+ case SDP_DATA_UUID16: |
232 |
+ SDP_GET16(value.uint16, start); |
233 |
+ break; |
234 |
+ |
235 |
+ case SDP_DATA_SEQ32: |
236 |
+ case SDP_DATA_UINT32: |
237 |
+ case SDP_DATA_INT32: |
238 |
+ case SDP_DATA_UUID32: |
239 |
+ SDP_GET32(value.uint32, start); |
240 |
+ break; |
241 |
+ |
242 |
+ case SDP_DATA_UINT64: |
243 |
+ case SDP_DATA_INT64: |
244 |
+ SDP_GET64(value.uint64, start); |
245 |
+ break; |
246 |
+ |
247 |
+ case SDP_DATA_UINT128: |
248 |
+ case SDP_DATA_INT128: |
249 |
+ SDP_GET128(&value.int128, start); |
250 |
+ break; |
251 |
+ |
252 |
+ default: |
253 |
+ goto end; |
254 |
+ break; |
255 |
+ } |
256 |
+ } |
257 |
+ } |
258 |
+ start += len; |
259 |
+ break; |
260 |
+ |
261 |
+ case SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID + SDP_ATTR_SERVICE_NAME_OFFSET: |
262 |
+ if (channel == -1) |
263 |
+ break; |
264 |
+ |
265 |
+ SDP_GET8(type, start); |
266 |
+ switch (type) { |
267 |
+ case SDP_DATA_STR8: |
268 |
+ case SDP_DATA_URL8: |
269 |
+ SDP_GET8(len, start); |
270 |
+ snprintf(name, sizeof(name), "%*.*s", len, len, (char *) start); |
271 |
+ start += len; |
272 |
+ break; |
273 |
+ |
274 |
+ case SDP_DATA_STR16: |
275 |
+ case SDP_DATA_URL16: |
276 |
+ SDP_GET16(len, start); |
277 |
+ snprintf(name, sizeof(name), "%*.*s", len, len, (char *) start); |
278 |
+ start += len; |
279 |
+ break; |
280 |
+ |
281 |
+ case SDP_DATA_STR32: |
282 |
+ case SDP_DATA_URL32: |
283 |
+ SDP_GET32(len, start); |
284 |
+ snprintf(name, sizeof(name), "%*.*s", len, len, (char *) start); |
285 |
+ start += len; |
286 |
+ break; |
287 |
+ |
288 |
+ default: |
289 |
+ goto end; |
290 |
+ break; |
291 |
+ } |
292 |
+ if (name == NULL) |
293 |
+ break; |
294 |
+ |
295 |
+ if (strcmp(name, "gnapplet") == 0) { |
296 |
+ if (only_gnapplet != 0) |
297 |
+ return channel; |
298 |
+ break; |
299 |
+ } |
300 |
+ |
301 |
+ if (strstr(name, "Nokia PC Suite") != NULL) { |
302 |
+ channel = -1; |
303 |
+ break; |
304 |
+ } |
305 |
+ |
306 |
+ if (strstr(name, "Bluetooth Serial Port") != NULL) { |
307 |
+ channel = -1; |
308 |
+ break; |
309 |
+ } |
310 |
+ |
311 |
+ if (strstr(name, "m-Router Connectivity") != NULL) { |
312 |
+ channel = -1; |
313 |
+ break; |
314 |
+ } |
315 |
+ |
316 |
+ goto end; |
317 |
+ } |
318 |
+ } |
319 |
|
320 |
+end: |
321 |
+ sdp_close(ss); |
322 |
+ return channel; |
323 |
+} |
324 |
+ |
325 |
+#else |
326 |
/* |
327 |
* Taken from gnome-phone-manager |
328 |
*/ |
329 |
@@ -204,6 +441,8 @@ |
330 |
return channel; |
331 |
} |
332 |
|
333 |
+#endif |
334 |
+ |
335 |
static int get_serial_channel(bdaddr_t *device) |
336 |
{ |
337 |
bdaddr_t src; |
338 |
@@ -211,9 +450,9 @@ |
339 |
|
340 |
bacpy(&src, BDADDR_ANY); |
341 |
|
342 |
- channel = find_service_channel(&src, device, 0, SERIAL_PORT_SVCLASS_ID); |
343 |
+ channel = find_service_channel(&src, device, 0, GNOKII_SERIAL_PORT_CLASS); |
344 |
if (channel < 0) |
345 |
- channel = find_service_channel(&src, device, 0, DIALUP_NET_SVCLASS_ID); |
346 |
+ channel = find_service_channel(&src, device, 0, GNOKII_DIALUP_NETWORK_CLASS); |
347 |
|
348 |
return channel; |
349 |
} |