Exemplo n.º 1
0
int
main(int argc, char *argv[])
{
  int s, s2;
  char *node = "ubt0hci";
  int has_bdaddr = 0;
  int peer_addr_type = 0;
  bdaddr_t bd;
  int ch;

  while((ch = getopt(argc, argv, "a:n:pr")) != -1){
    switch(ch){
    case 'a':
      has_bdaddr = bt_aton(optarg, &bd);
      break;
    case 'n':
      node = strdup(optarg);
      break;
    case 'p':
      peer_addr_type = 0;
      break;
    case 'r':
      peer_addr_type = 1;
      break;
    case '?':
    default:
      usage();
    }
  }
  s = open_socket(node);

  /* Vol.6 Part D 2.1 INITIAL SETUP */
  le_read_local_supported_features(s);
  set_event_mask(s,0x20001fffffffffff);
  le_set_event_mask(s, 0x1f);
  le_read_buffer_size(s);
  le_read_supported_status(s);
  read_bd_addr(s, NULL);

  /* Vol.6 Part D 4.1 PASSIVE SCANNING */
  le_set_scan_param(s, 0, 0x12, 0x12, peer_addr_type, 0);

  le_set_scan_enable(s,1);
  le_scan_result(s);
  le_set_scan_enable(s,0);

  if(has_bdaddr){
    s2 = le_l2connect(&bd, peer_addr_type);
    /* some code here*/
    close(s2);
  }
  close(s);
  return 0;
}
Exemplo n.º 2
0
int main(int argc, char *argv[])
{

	ng_hci_le_set_event_mask_cp lemc;
	char buf[NG_HCI_ADVERTISING_DATA_SIZE];
	char hname[NG_HCI_ADVERTISING_DATA_SIZE-10];
	int s;
	int ch;
	char *node="ubt0hci";
	int len,addr_valid = 0;
	bdaddr_t bd;
	int sflag = 0;
	int res = -1,handle = -1;
	while((ch = getopt(argc, argv, "s") )!= -1){
		switch(ch){
		case 's':
			sflag = 1;
			break;
		default:
			fprintf(stderr, "Usage: %s [-s] bdaddr\n", argv[0]);
			exit(-1);
			break;
		}
	}
	argc -= optind;
	argv += optind;
	if(argc>0){
	  addr_valid = bt_aton(argv[0],&bd);
	}
	s = open_socket("ubt0hci");
	
	set_event_mask(s,0x20001fffffffffff);
	set_le_event_mask(s, 0x1f);
	read_le_buffer_size(s);
	le_read_local_supported_features(s);
	le_set_scan_param(s, 0, 0x12, 0x12, 0, 0);
	buf[0] = 2;
	buf[1] = 1;
	buf[2] = 0;
	buf[3] = 8;
	
	gethostname(hname, sizeof(hname));
	len = strlen(hname);
#if 1
	memcpy(&buf[5], hname, len);
	buf[4] = len - 1;
	le_set_scan_response(s, sizeof(buf), buf);
	le_read_supported_status(s);
	le_set_scan_enable(s,1);
	le_scan_result(s);
	le_set_scan_enable(s,0);
#endif
	if(addr_valid){
#if 0
	  res = 1;
	  res = le_connect(s, &bd);
	  if(res == 0){
		  handle = le_connect_result(s);
	  }else{
		  printf("CONNECT FAILED\n");
		  return -1;
	  }
	  printf("Handle %x\n", handle);
#endif
	  le_l2connect(&bd, s, sflag);
	  //le_smpconnect(&bd, s);
	  
	}
	
	return 0;
}