int main(int argc, char *argv[]) { int opt, sock, dev_id, lap = 0, uap = 0, delay = 5; int have_lap = 0; int have_uap = 0; int afh_enabled = 0; uint8_t mode, afh_map[10]; char *end, ubertooth_device = -1; char *bt_dev = "hci0"; char addr[19] = { 0 }; struct libusb_device_handle *devh = NULL; uint32_t clock; uint16_t accuracy, handle, offset; bdaddr_t bdaddr; btbb_piconet *pn; struct hci_dev_info di; int cc = 0; pn = btbb_piconet_new(); while ((opt=getopt(argc,argv,"hl:u:U:e:d:ab:w:")) != EOF) { switch(opt) { case 'l': lap = strtol(optarg, &end, 16); if (end != optarg) { ++have_lap; } break; case 'u': uap = strtol(optarg, &end, 16); if (end != optarg) { ++have_uap; } break; case 'U': ubertooth_device = atoi(optarg); break; case 'e': max_ac_errors = atoi(optarg); break; case 'd': dumpfile = fopen(optarg, "w"); if (dumpfile == NULL) { perror(optarg); return 1; } break; case 'a': afh_enabled = 1; break; case 'b': bt_dev = optarg; if (bt_dev == NULL) { perror(optarg); return 1; } break; case 'w': //wait delay = atoi(optarg); break; case 'h': default: usage(); return 1; } } dev_id = hci_devid(bt_dev); sock = hci_open_dev(dev_id); hci_read_clock(sock, 0, 0, &clock, &accuracy, 0); if ((have_lap != 1) || (have_uap != 1)) { printf("No address given, reading address from device\n"); hci_read_bd_addr(sock, &bdaddr, 0); lap = bdaddr.b[0] | bdaddr.b[1] << 8 | bdaddr.b[2] << 16; btbb_init_piconet(pn, lap); uap = bdaddr.b[3]; btbb_piconet_set_uap(pn, uap); printf("LAP=%06x UAP=%02x\n", lap, uap); } else if (have_lap && have_uap) { btbb_init_piconet(pn, lap); btbb_piconet_set_uap(pn, uap); printf("Address given, assuming address is remote\n"); sprintf(addr, "00:00:%02X:%02X:%02X:%02X", uap, (lap >> 16) & 0xFF, (lap >> 8) & 0xFF, lap & 0xFF ); str2ba(addr, &bdaddr); printf("Address: %s\n", addr); if (hci_devinfo(dev_id, &di) < 0) { perror("Can't get device info"); return 1; } if (hci_create_connection(sock, &bdaddr, htobs(di.pkt_type & ACL_PTYPE_MASK), 0, 0x01, &handle, 25000) < 0) { perror("Can't create connection"); return 1; } sleep(1); cc = 1; if (hci_read_clock_offset(sock, handle, &offset, 1000) < 0) { perror("Reading clock offset failed"); } clock += offset; //Experimental AFH map reading from remote device if(afh_enabled) { if(hci_read_afh_map(sock, handle, &mode, afh_map, 1000) < 0) { perror("HCI read AFH map request failed"); //exit(1); } if(mode == 0x01) { btbb_piconet_set_afh_map(pn, afh_map); btbb_print_afh_map(pn); } else { printf("AFH disabled.\n"); afh_enabled = 0; } } if (cc) { usleep(10000); hci_disconnect(sock, handle, HCI_OE_USER_ENDED_CONNECTION, 10000); } } else {
int main(int argc, char *argv[]) { int opt, sock, dev_id, lap = 0, uap = 0, delay = 5; int have_lap = 0; int have_uap = 0; int afh_enabled = 0; uint8_t mode, afh_map[10]; char *end, ubertooth_device = -1; char *bt_dev = "hci0"; char addr[19] = { 0 }; uint32_t clock; uint16_t accuracy, handle, offset; bdaddr_t bdaddr; btbb_piconet *pn; struct hci_dev_info di; int cc = 0; pn = btbb_piconet_new(); while ((opt=getopt(argc,argv,"hl:u:U:e:d:ab:w:r:q:")) != EOF) { switch(opt) { case 'l': lap = strtol(optarg, &end, 16); if (end != optarg) { ++have_lap; } break; case 'u': uap = strtol(optarg, &end, 16); if (end != optarg) { ++have_uap; } break; case 'U': ubertooth_device = atoi(optarg); break; case 'r': if (!h_pcapng_bredr) { if (btbb_pcapng_create_file( optarg, "Ubertooth", &h_pcapng_bredr )) { err(1, "create_bredr_capture_file: "); } } else { printf("Ignoring extra capture file: %s\n", optarg); } break; #ifdef ENABLE_PCAP case 'q': if (!h_pcap_bredr) { if (btbb_pcap_create_file(optarg, &h_pcap_bredr)) { err(1, "btbb_pcap_create_file: "); } } else { printf("Ignoring extra capture file: %s\n", optarg); } break; #endif case 'e': max_ac_errors = atoi(optarg); break; case 'd': dumpfile = fopen(optarg, "w"); if (dumpfile == NULL) { perror(optarg); return 1; } break; case 'a': afh_enabled = 1; break; case 'b': bt_dev = optarg; if (bt_dev == NULL) { perror(optarg); return 1; } break; case 'w': //wait delay = atoi(optarg); break; case 'h': default: usage(); return 1; } } dev_id = hci_devid(bt_dev); sock = hci_open_dev(dev_id); hci_read_clock(sock, 0, 0, &clock, &accuracy, 0); if ((have_lap != 1) || (have_uap != 1)) { printf("No address given, reading address from device\n"); hci_read_bd_addr(sock, &bdaddr, 0); lap = bdaddr.b[0] | bdaddr.b[1] << 8 | bdaddr.b[2] << 16; btbb_init_piconet(pn, lap); uap = bdaddr.b[3]; btbb_piconet_set_uap(pn, uap); printf("LAP=%06x UAP=%02x\n", lap, uap); } else if (have_lap && have_uap) { btbb_init_piconet(pn, lap); btbb_piconet_set_uap(pn, uap); printf("Address given, assuming address is remote\n"); sprintf(addr, "00:00:%02X:%02X:%02X:%02X", uap, (lap >> 16) & 0xFF, (lap >> 8) & 0xFF, lap & 0xFF ); str2ba(addr, &bdaddr); printf("Address: %s\n", addr); if (hci_devinfo(dev_id, &di) < 0) { perror("Can't get device info"); return 1; } if (hci_create_connection(sock, &bdaddr, htobs(di.pkt_type & ACL_PTYPE_MASK), 0, 0x01, &handle, 25000) < 0) { perror("Can't create connection"); return 1; } sleep(1); cc = 1; if (hci_read_clock_offset(sock, handle, &offset, 1000) < 0) { perror("Reading clock offset failed"); } clock += offset; } else {
int main(int argc, char *argv[]) { int opt, have_lap = 0, have_uap = 0; int timeout = 0; int reset_scan = 0; char *end; char ubertooth_device = -1; btbb_piconet *pn = NULL; uint32_t lap = 0; uint8_t uap = 0; while ((opt=getopt(argc,argv,"hVi:l:u:U:d:e:r:sq:t:")) != EOF) { switch(opt) { case 'i': infile = fopen(optarg, "r"); if (infile == NULL) { printf("Could not open file %s\n", optarg); usage(); return 1; } break; case 'l': lap = strtol(optarg, &end, 16); have_lap++; break; case 'u': uap = strtol(optarg, &end, 16); have_uap++; break; case 'U': ubertooth_device = atoi(optarg); break; case 'r': if (!h_pcapng_bredr) { if (btbb_pcapng_create_file( optarg, "Ubertooth", &h_pcapng_bredr )) { err(1, "create_bredr_capture_file: "); } } else { printf("Ignoring extra capture file: %s\n", optarg); } break; #ifdef ENABLE_PCAP case 'q': if (!h_pcap_bredr) { if (btbb_pcap_create_file(optarg, &h_pcap_bredr)) { err(1, "btbb_pcap_create_file: "); } } else { printf("Ignoring extra capture file: %s\n", optarg); } break; #endif case 'd': dumpfile = fopen(optarg, "w"); if (dumpfile == NULL) { perror(optarg); return 1; } break; case 'e': max_ac_errors = atoi(optarg); break; case 's': ++reset_scan; break; case 't': timeout = atoi(optarg); break; case 'V': print_version(); return 0; case 'h': default: usage(); return 1; } } if (have_lap) { pn = btbb_piconet_new(); btbb_init_piconet(pn, lap); if (have_uap) btbb_piconet_set_uap(pn, uap); if (h_pcapng_bredr) { btbb_pcapng_record_bdaddr(h_pcapng_bredr, (((uint32_t)uap)<<24)|lap, have_uap ? 0xff : 0x00, 0); } } else if (have_uap) { printf("Error: UAP but no LAP specified\n"); usage(); return 1; } if (infile == NULL) { devh = ubertooth_start(ubertooth_device); if (devh == NULL) { usage(); return 1; } /* Scan all frequencies. Same effect as * ubertooth-utils -c9999. This is necessary after * following a piconet. */ if (reset_scan) { cmd_set_channel(devh, 9999); } /* Clean up on exit. */ register_cleanup_handler(devh); rx_live(devh, pn, timeout); // Print AFH map from piconet if we have one if (pn) btbb_print_afh_map(pn); ubertooth_stop(devh); } else { rx_file(infile, pn); fclose(infile); } return 0; }
int main(int argc, char *argv[]) { int opt, have_lap = 0, have_uap = 0; int reset_scan = 0; char *end; char ubertooth_device = -1; btbb_piconet *pn = NULL; uint32_t lap; uint8_t uap; while ((opt=getopt(argc,argv,"hi:l:u:U:d:e:sc:")) != EOF) { switch(opt) { case 'i': infile = fopen(optarg, "r"); if (infile == NULL) { printf("Could not open file %s\n", optarg); usage(); return 1; } break; case 'l': lap = strtol(optarg, &end, 16); have_lap++; break; case 'u': uap = strtol(optarg, &end, 16); have_uap++; break; case 'U': ubertooth_device = atoi(optarg); break; case 'c': #ifdef USE_PCAP pcap_dumpfile = pcap_open_dead(DLT_PPI, 128); if (pcap_dumpfile == NULL) err(1, "pcap_open_dead: "); dumper = pcap_dump_open(pcap_dumpfile, optarg); pcap_dump_flush(dumper); if (dumper == NULL) { warn("pcap_dump_open"); pcap_close(pcap_dumpfile); exit(1); } #else printf("Not compiled with 'USE_PCAP', -c ignored\n"); #endif // USE_PCAP break; case 'd': dumpfile = fopen(optarg, "w"); if (dumpfile == NULL) { perror(optarg); return 1; } break; case 'e': max_ac_errors = atoi(optarg); break; case 's': ++reset_scan; break; case 'h': default: usage(); return 1; } } if (have_lap) { pn = btbb_piconet_new(); btbb_init_piconet(pn, lap); if (have_uap) btbb_piconet_set_uap(pn, uap); } else if (have_uap) { printf("Error: UAP but no LAP specified\n"); usage(); return 1; } if (infile == NULL) { devh = ubertooth_start(ubertooth_device); if (devh == NULL) { usage(); return 1; } /* Scan all frequencies. Same effect as * ubertooth-utils -c9999. This is necessary after * following a piconet. */ if (reset_scan) { cmd_set_channel(devh, 9999); } /* Clean up on exit. */ signal(SIGINT,cleanup); signal(SIGQUIT,cleanup); signal(SIGTERM,cleanup); rx_live(devh, pn, 0); // Print AFH map from piconet if we have one if (pn) btbb_print_afh_map(pn); ubertooth_stop(devh); } else { rx_file(infile, pn); fclose(infile); } return 0; }