Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
127 ligi 1
#include "bluetooth_handler.h" 
2
 
3
int bt_device_count=0;
4
 
5
char names[MAX_BT_DEVICES][248];
6
char addrs[MAX_BT_DEVICES][19];
7
 
8
int scan_bt()
9
{
10
  inquiry_info *ii = NULL;
11
 
12
  int dev_id, sock, len, flags;
13
  int i;
14
  char addr[19] = { 0 };
15
  char name[248] = { 0 };
16
 
17
  dev_id = hci_get_route(NULL);
18
  sock = hci_open_dev( dev_id );
19
  if (dev_id < 0 || sock < 0) {
20
    perror("opening socket");
21
    return 0;
22
  }
23
 
24
  len  = 8;
25
 
26
  flags = IREQ_CACHE_FLUSH;
27
  ii = (inquiry_info*)malloc(MAX_BT_DEVICES * sizeof(inquiry_info));
28
 
29
  bt_device_count = hci_inquiry(dev_id, len, MAX_BT_DEVICES, NULL, &ii, flags);
30
  if(  bt_device_count < 0 ) perror("hci_inquiry");
31
 
32
  for (i = 0; i <  bt_device_count; i++) {
33
    ba2str(&(ii+i)->bdaddr, addr);
34
    sprintf(addrs[i],"%s",addr);
35
 
36
    memset(name, 0, sizeof(name));
37
 
38
    if (hci_read_remote_name(sock, &(ii+i)->bdaddr, sizeof(name),
39
                             name, 0) < 0)
40
      sprintf(names[i],"[unknown]");
41
    else
42
      sprintf(names[i],"%s",name);
43
 
44
  }
45
 
46
 
47
  free( ii );
48
  close( sock );
49
  return 1;
50
}