Go to most recent revision |
Blame |
Last modification |
View Log
| RSS feed
#include "bluetooth_handler.h"
int bt_device_count
=0;
char names
[MAX_BT_DEVICES
][248];
char addrs
[MAX_BT_DEVICES
][19];
int scan_bt
()
{
inquiry_info
*ii
= NULL
;
int dev_id
, sock
, len
, flags
;
int i
;
char addr
[19] = { 0 };
char name
[248] = { 0 };
dev_id
= hci_get_route
(NULL
);
sock
= hci_open_dev
( dev_id
);
if (dev_id
< 0 || sock
< 0) {
perror("opening socket");
return 0;
}
len
= 8;
flags
= IREQ_CACHE_FLUSH
;
ii
= (inquiry_info
*)malloc(MAX_BT_DEVICES
* sizeof(inquiry_info
));
bt_device_count
= hci_inquiry
(dev_id
, len
, MAX_BT_DEVICES
, NULL
, &ii
, flags
);
if( bt_device_count
< 0 ) perror("hci_inquiry");
for (i
= 0; i
< bt_device_count
; i
++) {
ba2str
(&(ii
+i
)->bdaddr
, addr
);
sprintf(addrs
[i
],"%s",addr
);
memset(name
, 0, sizeof(name
));
if (hci_read_remote_name
(sock
, &(ii
+i
)->bdaddr
, sizeof(name
),
name
, 0) < 0)
sprintf(names
[i
],"[unknown]");
else
sprintf(names
[i
],"%s",name
);
}
free( ii
);
close
( sock
);
return 1;
}