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>
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 */
37 /* Generated from http://standards.ieee.org/regauth/oui/oui.txt */
39 typedef char bluez_prefix
[9];
41 const bluez_prefix at_prefixes
[] = {
350 const bluez_prefix nokia_prefixes
[] = {
457 int find_list(const char *match
, const bluez_prefix
*list
)
461 for (pos
= 0; list
[pos
][0] != 0; pos
++) {
462 if (strncasecmp(list
[pos
], match
, 8) == 0) {
469 void bluez_detect(void)
471 inquiry_info
*ii
= NULL
;
472 int max_rsp
, num_rsp
;
473 int dev_id
, sock
, len
, flags
;
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");
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
);
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]");
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");
513 /* How should editor hadle tabs in this file? Add editor commands here.
514 * vim: noexpandtab sw=8 ts=8 sts=8: