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[]) { inquiry_info *ii = NULL; int i, opt, dev_id, sock, len, flags, max_rsp, num_rsp, lap, timeout = 20; uint8_t extended = 0; uint8_t scan = 0; char ubertooth_device = -1; char *bt_dev = "hci0"; char addr[19] = { 0 }; char name[248] = { 0 }; struct libusb_device_handle *devh = NULL; btbb_piconet *pn; bdaddr_t bdaddr; while ((opt=getopt(argc,argv,"ht:xsb:")) != EOF) { switch(opt) { case 'b': bt_dev = optarg; if (bt_dev == NULL) { perror(optarg); return 1; } break; case 't': timeout = atoi(optarg); break; case 'x': extended = 1; break; case 's': scan = 1; break; case 'h': default: usage(); return 1; } } dev_id = hci_devid(bt_dev); sock = hci_open_dev( dev_id ); if (dev_id < 0 || sock < 0) { perror("opening socket"); return 1; } devh = ubertooth_start(ubertooth_device); if (devh == NULL) { usage(); return 1; } /* Set sweep mode - otherwise AFH map is useless */ cmd_set_channel(devh, 9999); if (scan) { len = 8; max_rsp = 255; flags = IREQ_CACHE_FLUSH; ii = (inquiry_info*)malloc(max_rsp * sizeof(inquiry_info)); num_rsp = hci_inquiry(dev_id, len, max_rsp, NULL, &ii, flags); if( num_rsp < 0 ) perror("hci_inquiry"); /* Equivalent to "hcitool scan" */ printf("HCI scan\n"); for (i = 0; i < num_rsp; i++) { ba2str(&(ii+i)->bdaddr, addr); memset(name, 0, sizeof(name)); if (hci_read_remote_name(sock, &(ii+i)->bdaddr, sizeof(name), name, 0) < 0) strcpy(name, "[unknown]"); printf("%s %s\n", addr, name); } free(ii); } /* Now find hidden piconets with Ubertooth */ printf("\nUbertooth scan\n"); btbb_init_survey(); rx_live(devh, NULL, timeout); ubertooth_stop(devh); while((pn=btbb_next_survey_result()) != NULL) { lap = btbb_piconet_get_lap(pn); if (btbb_piconet_get_flag(pn, BTBB_UAP_VALID)) { lap = btbb_piconet_get_lap(pn); sprintf(addr, "00:00:%02X:%02X:%02X:%02X", btbb_piconet_get_uap(pn), (lap >> 16) & 0xFF, (lap >> 8) & 0xFF, lap & 0xFF); str2ba(addr, &bdaddr); memset(name, 0, sizeof(name)); if (hci_read_remote_name(sock, &bdaddr, sizeof(name), name, 0) < 0) strcpy(name, "[unknown]"); printf("%s %s\n", addr, name); if (extended) extra_info(sock, dev_id, &bdaddr); } else printf("00:00:00:%02X:%02X:%02X\n", (lap >> 16) & 0xFF, (lap >> 8) & 0xFF, lap & 0xFF); btbb_print_afh_map(pn); }
int main(int argc, char *argv[]) { inquiry_info *ii = NULL; int i, opt, dev_id, dev_handle, len, flags, max_rsp, num_rsp, lap, timeout = 20; uint8_t uap, extended = 0; uint8_t scan = 0; char ubertooth_device = -1; char *bt_dev = "hci0"; char addr[19] = { 0 }; ubertooth_t* ut = NULL; btbb_piconet* pn; bdaddr_t bdaddr; while ((opt=getopt(argc,argv,"hU:t:e:xsb:")) != EOF) { switch(opt) { case 'U': ubertooth_device = atoi(optarg); break; case 'b': bt_dev = optarg; if (bt_dev == NULL) { perror(optarg); return 1; } break; case 't': timeout = atoi(optarg); break; case 'e': max_ac_errors = atoi(optarg); break; case 'x': extended = 1; break; case 's': scan = 1; break; case 'h': default: usage(); return 1; } } dev_id = hci_devid(bt_dev); if (dev_id < 0) { printf("error: Unable to find %s (%d)\n", bt_dev, dev_id); return 1; } dev_handle = hci_open_dev( dev_id ); if (dev_handle < 0) { perror("HCI device open failed"); return 1; } ut = ubertooth_start(ubertooth_device); if (ut == NULL) { usage(); return 1; } /* Set sweep mode - otherwise AFH map is useless */ cmd_set_channel(ut->devh, 9999); if (scan) { /* Equivalent to "hcitool scan" */ printf("HCI scan\n"); len = 8; max_rsp = 255; flags = IREQ_CACHE_FLUSH; ii = (inquiry_info*)malloc(max_rsp * sizeof(inquiry_info)); num_rsp = hci_inquiry(dev_id, len, max_rsp, NULL, &ii, flags); if( num_rsp < 0 ) perror("hci_inquiry"); for (i = 0; i < num_rsp; i++) { ba2str(&(ii+i)->bdaddr, addr); print_name_and_class(dev_handle, dev_id, &(ii+i)->bdaddr, addr, extended); } free(ii); } /* Now find hidden piconets with Ubertooth */ printf("\nUbertooth scan\n"); btbb_init_survey(); rx_live(ut, NULL, timeout); ubertooth_stop(ut); while((pn=btbb_next_survey_result()) != NULL) { lap = btbb_piconet_get_lap(pn); if (btbb_piconet_get_flag(pn, BTBB_UAP_VALID)) { uap = btbb_piconet_get_uap(pn); sprintf(addr, "00:00:%02X:%02X:%02X:%02X", uap, (lap >> 16) & 0xFF, (lap >> 8) & 0xFF, lap & 0xFF); str2ba(addr, &bdaddr); /* Printable version showing that the NAP is unknown */ sprintf(addr, "??:??:%02X:%02X:%02X:%02X", uap, (lap >> 16) & 0xFF, (lap >> 8) & 0xFF, lap & 0xFF); print_name_and_class(dev_handle, dev_id, &bdaddr, addr, extended); } else printf("??:??:??:%02X:%02X:%02X\n", (lap >> 16) & 0xFF, (lap >> 8) & 0xFF, lap & 0xFF); btbb_print_afh_map(pn); }
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; }