Translation update done using Pootle.
[gammu.git] / gammu-detect / bluez.c
blobcd1f9b38921807f374cf227e60a02b84e85c8874
1 /* This program is free software; you can redistribute it and/or modify
2 * it under the terms of the GNU General Public License as published by
3 * the Free Software Foundation; either version 2 of the License, or
4 * (at your option) any later version.
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
11 * You should have received a copy of the GNU General Public License along
12 * with this program; if not, write to the Free Software Foundation, Inc.,
13 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15 * Copyright (c) 2010 Michal Cihar <michal@cihar.com>
18 #include <glib.h>
20 #include <stdio.h>
21 #include <string.h>
22 #include <stdlib.h>
23 #include <stdarg.h>
24 #include <sys/socket.h>
25 #include <bluetooth/bluetooth.h>
26 #include <bluetooth/hci.h>
27 #include <bluetooth/hci_lib.h>
29 #include <gammu.h> /* For PRINTF_STYLE and locales */
30 #include "../helper/locales.h" /* For gettext */
32 #include "config.h"
34 #include "bluez.h"
35 #include "main.h"
37 /* Generated from http://standards.ieee.org/regauth/oui/oui.txt */
39 typedef char bluez_prefix[9];
41 const bluez_prefix at_prefixes[] = {
42 /* Sony-Ericsson */
43 "00:01:EC",
44 "00:0A:D9",
45 "00:0E:07",
46 "00:0F:DE",
47 "00:12:EE",
48 "00:15:E0",
49 "00:16:20",
50 "00:16:B8",
51 "00:18:13",
52 "00:19:63",
53 "00:1A:75",
54 "00:1B:59",
55 "00:1C:A4",
56 "00:1D:28",
57 "00:1E:45",
58 "00:1E:DC",
59 "00:1F:E4",
60 "00:21:9E",
61 "00:22:98",
62 "00:23:45",
63 "00:23:F1",
64 "00:24:EF",
65 "00:25:E7",
66 "00:80:37",
67 "24:21:AB",
68 "30:17:C8",
69 "40:2B:A1",
70 "58:17:0C",
71 "6C:0E:0D",
72 "6C:23:B9",
73 "90:55:AE",
74 "B4:0E:DC",
75 "B8:F9:34",
76 "C8:35:B8",
77 "D0:F0:DB",
78 /* Siemens */
79 "00:01:E3",
80 "00:05:19",
81 "00:0B:23",
82 "00:0B:A3",
83 "00:0D:41",
84 "00:0E:8C",
85 "00:0F:BB",
86 "00:11:06",
87 "00:11:33",
88 "00:13:A3",
89 "00:18:65",
90 "00:18:D1",
91 "00:19:28",
92 "00:1A:E8",
93 "00:1B:1B",
94 "00:1C:06",
95 "00:1F:F8",
96 "00:23:41",
97 "00:30:05",
98 "00:40:43",
99 "00:50:07",
100 "00:90:40",
101 "00:A0:03",
102 "00:C0:E4",
103 "08:00:06",
104 "40:EC:F8",
105 "88:4B:39",
106 /* Samsung */
107 "00:00:F0",
108 "00:02:78",
109 "00:09:18",
110 "00:0D:AE",
111 "00:0D:E5",
112 "00:12:47",
113 "00:12:FB",
114 "00:13:77",
115 "00:15:99",
116 "00:15:B9",
117 "00:16:32",
118 "00:16:6B",
119 "00:16:6C",
120 "00:16:DB",
121 "00:17:C9",
122 "00:17:D5",
123 "00:18:AF",
124 "00:1A:8A",
125 "00:1B:98",
126 "00:1C:43",
127 "00:1D:25",
128 "00:1D:F6",
129 "00:1E:7D",
130 "00:1E:E1",
131 "00:1E:E2",
132 "00:1F:CC",
133 "00:1F:CD",
134 "00:21:19",
135 "00:21:4C",
136 "00:21:D1",
137 "00:21:D2",
138 "00:23:39",
139 "00:23:3A",
140 "00:23:99",
141 "00:23:C2",
142 "00:23:D6",
143 "00:23:D7",
144 "00:24:54",
145 "00:24:90",
146 "00:24:91",
147 "00:24:E9",
148 "00:25:38",
149 "00:25:66",
150 "00:25:67",
151 "00:26:37",
152 "00:26:5D",
153 "00:26:5F",
154 "00:E0:64",
155 "10:1D:C0",
156 "34:C3:AC",
157 "38:01:97",
158 "3C:8B:FE",
159 "44:4E:1A",
160 "44:F4:59",
161 "54:92:BE",
162 "60:A1:0A",
163 "60:D0:A9",
164 "68:EB:AE",
165 "78:25:AD",
166 "A0:07:98",
167 "A0:0B:BA",
168 "A8:F2:74",
169 "B4:07:F9",
170 "BC:47:60",
171 "C8:7E:75",
172 "D4:88:90",
173 "D4:E8:B2",
174 "E4:7C:F9",
175 "E4:E0:C5",
176 "E8:11:32",
177 "E8:E5:D6",
178 "EC:E0:9B",
179 "F4:9F:54",
180 "FC:A1:3E",
181 /* LG */
182 "00:1C:62",
183 "00:1E:75",
184 "00:1F:6B",
185 "00:1F:E3",
186 "00:21:FB",
187 "00:22:A9",
188 "00:24:83",
189 "00:25:E5",
190 "00:26:E2",
191 "00:E0:91",
192 "20:21:A5",
193 "6C:D6:8A",
194 "E8:5B:5B",
195 /* BenQ */
196 "00:03:9D",
197 "00:17:CA",
198 "00:1E:21",
199 /* Motorola */
200 "00:03:E0",
201 "00:04:56",
202 "00:04:BD",
203 "00:08:0E",
204 "00:0A:28",
205 "00:0B:06",
206 "00:0C:E5",
207 "00:0E:5C",
208 "00:0E:C7",
209 "00:0F:9F",
210 "00:11:1A",
211 "00:11:80",
212 "00:11:AE",
213 "00:12:25",
214 "00:12:8A",
215 "00:12:C9",
216 "00:13:71",
217 "00:14:04",
218 "00:14:9A",
219 "00:14:E8",
220 "00:15:2F",
221 "00:15:70",
222 "00:15:9A",
223 "00:15:A8",
224 "00:16:26",
225 "00:16:75",
226 "00:16:B5",
227 "00:17:00",
228 "00:17:84",
229 "00:17:E2",
230 "00:17:EE",
231 "00:18:A4",
232 "00:18:C0",
233 "00:19:2C",
234 "00:19:5E",
235 "00:19:A6",
236 "00:19:C0",
237 "00:1A:1B",
238 "00:1A:66",
239 "00:1A:77",
240 "00:1A:AD",
241 "00:1A:DB",
242 "00:1A:DE",
243 "00:1B:52",
244 "00:1B:DD",
245 "00:1C:11",
246 "00:1C:12",
247 "00:1C:C1",
248 "00:1C:FB",
249 "00:1D:6B",
250 "00:1D:BE",
251 "00:1E:46",
252 "00:1E:5A",
253 "00:1E:8D",
254 "00:1F:7E",
255 "00:1F:C4",
256 "00:20:40",
257 "00:20:75",
258 "00:21:1E",
259 "00:21:36",
260 "00:21:43",
261 "00:21:80",
262 "00:22:10",
263 "00:22:B4",
264 "00:23:0B",
265 "00:23:68",
266 "00:23:74",
267 "00:23:75",
268 "00:23:95",
269 "00:23:A2",
270 "00:23:A3",
271 "00:23:AF",
272 "00:23:ED",
273 "00:23:EE",
274 "00:24:37",
275 "00:24:92",
276 "00:24:93",
277 "00:24:95",
278 "00:24:A0",
279 "00:24:A1",
280 "00:24:C1",
281 "00:25:F1",
282 "00:25:F2",
283 "00:26:36",
284 "00:26:41",
285 "00:26:42",
286 "00:26:BA",
287 "00:50:E3",
288 "00:90:9C",
289 "00:A0:BF",
290 "00:D0:88",
291 "00:E0:0C",
292 "00:E0:6F",
293 "2C:9E:5F",
294 "3C:75:4A",
295 "40:83:DE",
296 "40:FC:89",
297 "48:2C:EA",
298 "5C:0E:8B",
299 "64:ED:57",
300 "74:E7:C6",
301 "74:F6:12",
302 "A4:ED:4E",
303 "E4:64:49",
304 "E4:83:99",
305 "F8:7B:7A",
306 /* Alcatel */
307 "00:07:72",
308 "00:08:9A",
309 "00:0E:86",
310 "00:0F:62",
311 "00:11:3F",
312 "00:11:8B",
313 "00:15:3F",
314 "00:16:4D",
315 "00:17:CC",
316 "00:19:8F",
317 "00:1A:F0",
318 "00:1C:8E",
319 "00:1D:4C",
320 "00:20:32",
321 "00:20:60",
322 "00:20:DA",
323 "00:21:05",
324 "00:21:35",
325 "00:21:AE",
326 "00:23:3E",
327 "00:25:BA",
328 "00:80:21",
329 "00:80:39",
330 "00:80:9F",
331 "00:A0:81",
332 "00:C0:BE",
333 "00:D0:95",
334 "00:D0:F6",
335 "00:E0:B1",
336 "00:E0:DA",
337 "0C:A4:02",
338 "18:42:2F",
339 "18:80:F5",
340 "24:AF:4A",
341 "38:52:1A",
342 "48:F8:E1",
343 "68:59:7F",
344 "6C:BE:E9",
345 "7C:20:64",
346 "8C:90:D3",
347 "90:67:B5",
350 const bluez_prefix nokia_prefixes[] = {
351 /* Nokia */
352 "00:02:EE",
353 "00:0B:E1",
354 "00:0E:ED",
355 "00:0F:BB",
356 "00:10:B3",
357 "00:11:9F",
358 "00:12:62",
359 "00:13:70",
360 "00:13:FD",
361 "00:14:A7",
362 "00:15:2A",
363 "00:15:A0",
364 "00:15:DE",
365 "00:16:4E",
366 "00:16:BC",
367 "00:17:4B",
368 "00:17:B0",
369 "00:18:0F",
370 "00:18:42",
371 "00:18:8D",
372 "00:18:C5",
373 "00:19:2D",
374 "00:19:4F",
375 "00:19:79",
376 "00:19:B7",
377 "00:1A:16",
378 "00:1A:89",
379 "00:1A:DC",
380 "00:1B:33",
381 "00:1B:AF",
382 "00:1B:EE",
383 "00:1C:35",
384 "00:1C:9A",
385 "00:1C:D4",
386 "00:1C:D6",
387 "00:1D:3B",
388 "00:1D:6E",
389 "00:1D:98",
390 "00:1D:E9",
391 "00:1D:FD",
392 "00:1E:3A",
393 "00:1E:3B",
394 "00:1E:A3",
395 "00:1E:A4",
396 "00:1F:00",
397 "00:1F:01",
398 "00:1F:5C",
399 "00:1F:5D",
400 "00:1F:DE",
401 "00:1F:DF",
402 "00:21:08",
403 "00:21:09",
404 "00:21:AA",
405 "00:21:AB",
406 "00:21:FC",
407 "00:21:FE",
408 "00:22:65",
409 "00:22:66",
410 "00:22:FC",
411 "00:22:FD",
412 "00:23:B4",
413 "00:24:03",
414 "00:24:04",
415 "00:24:7C",
416 "00:24:7D",
417 "00:25:47",
418 "00:25:48",
419 "00:25:CF",
420 "00:25:D0",
421 "00:26:68",
422 "00:26:69",
423 "00:26:CC",
424 "00:40:43",
425 "00:A0:8E",
426 "00:BD:3A",
427 "00:E0:03",
428 "0C:DD:EF",
429 "18:14:56",
430 "18:86:AC",
431 "20:D6:07",
432 "2C:D2:E7",
433 "30:38:55",
434 "34:7E:39",
435 "3C:F7:2A",
436 "5C:57:C8",
437 "6C:9B:02",
438 "80:50:1B",
439 "94:20:53",
440 "9C:18:74",
441 "9C:4A:7B",
442 "A0:4E:04",
443 "A8:7B:39",
444 "A8:7E:33",
445 "C0:38:F9",
446 "C8:97:9F",
447 "C8:DF:7C",
448 "D4:CB:AF",
449 "D8:75:33",
450 "E0:A6:70",
451 "E4:EC:10",
452 "EC:9B:5B",
453 "FC:E5:57",
457 int find_list(const char *match, const bluez_prefix *list)
459 int pos;
461 for (pos = 0; list[pos][0] != 0; pos++) {
462 if (strncasecmp(list[pos], match, 8) == 0) {
463 return 1;
466 return 0;
469 void bluez_detect(void)
471 inquiry_info *ii = NULL;
472 int max_rsp, num_rsp;
473 int dev_id, sock, len, flags;
474 int i;
475 char addr[19] = { 0 };
476 char name[248] = { 0 };
478 dev_id = hci_get_route(NULL);
479 sock = hci_open_dev(dev_id);
480 if (dev_id < 0 || sock < 0) {
481 perror("opening socket");
482 exit(1);
485 len = 8;
486 max_rsp = 255;
487 flags = IREQ_CACHE_FLUSH;
488 ii = (inquiry_info *) malloc(max_rsp * sizeof(inquiry_info));
490 num_rsp = hci_inquiry(dev_id, len, max_rsp, NULL, &ii, flags);
491 if (num_rsp < 0)
492 perror("hci_inquiry");
494 for (i = 0; i < num_rsp; i++) {
495 ba2str(&(ii + i)->bdaddr, addr);
496 memset(name, 0, sizeof(name));
497 if (hci_read_remote_name(sock, &(ii + i)->bdaddr, sizeof(name), name, 0) < 0)
498 strcpy(name, "[unknown]");
499 if (debug)
500 printf("; %s %s\n", addr, name);
501 if (find_list(addr, at_prefixes)) {
502 print_config(addr, name, "blueat");
504 if (find_list(addr, nokia_prefixes)) {
505 print_config(addr, name, "bluephonet");
509 free(ii);
510 close(sock);
513 /* How should editor hadle tabs in this file? Add editor commands here.
514 * vim: noexpandtab sw=8 ts=8 sts=8: