static struct libusb_device_handle* find_ubertooth_device(int ubertooth_device) { struct libusb_context *ctx = NULL; struct libusb_device **usb_list = NULL; struct libusb_device_handle *devh = NULL; struct libusb_device_descriptor desc; int usb_devs, i, r, ret, ubertooths = 0; int ubertooth_devs[] = {0,0,0,0,0,0,0,0}; usb_devs = libusb_get_device_list(ctx, &usb_list); for(i = 0 ; i < usb_devs ; ++i) { r = libusb_get_device_descriptor(usb_list[i], &desc); if(r < 0) fprintf(stderr, "couldn't get usb descriptor for dev #%d!\n", i); if ((desc.idVendor == TC13_VENDORID && desc.idProduct == TC13_PRODUCTID) || (desc.idVendor == U0_VENDORID && desc.idProduct == U0_PRODUCTID) || (desc.idVendor == U1_VENDORID && desc.idProduct == U1_PRODUCTID)) { ubertooth_devs[ubertooths] = i; ubertooths++; } } if(ubertooths == 1) { ret = libusb_open(usb_list[ubertooth_devs[0]], &devh); if (ret) show_libusb_error(ret); } else if (ubertooths == 0) return NULL; else { if (ubertooth_device < 0) { fprintf(stderr, "multiple Ubertooth devices found! Use '-U' to specify device number\n"); u8 serial[17], r; for(i = 0 ; i < ubertooths ; ++i) { libusb_get_device_descriptor(usb_list[ubertooth_devs[i]], &desc); ret = libusb_open(usb_list[ubertooth_devs[i]], &devh); if (ret) { fprintf(stderr, " Device %d: ", i); show_libusb_error(ret); } else { r = cmd_get_serial(devh, serial); if(r==0) { fprintf(stderr, " Device %d: ", i); print_serial(serial, stderr); } libusb_close(devh); } } devh = NULL; } else { ret = libusb_open(usb_list[ubertooth_devs[ubertooth_device]], &devh); if (ret) { show_libusb_error(ret); devh = NULL; } } } return devh; }
int cmd_get_rangeresult(struct libusb_device_handle* devh, rangetest_result *rr) { u8 result[5]; int r; r = libusb_control_transfer(devh, CTRL_IN, UBERTOOTH_RANGE_CHECK, 0, 0, result, sizeof(result), 3000); if (r < LIBUSB_SUCCESS) { if (r == LIBUSB_ERROR_PIPE) { fprintf(stderr, "control message unsupported\n"); } else { show_libusb_error(r); } return r; } rr->valid = result[0]; rr->request_pa = result[1]; rr->request_num = result[2]; rr->reply_pa = result[3]; rr->reply_num = result[4]; return 0; }
static void callback(struct libusb_transfer* transfer) { if(transfer->status != 0) { show_libusb_error(transfer->status); } libusb_free_transfer(transfer); }
int cmd_specan(struct libusb_device_handle* devh, u16 low_freq, u16 high_freq) { int r; r = libusb_control_transfer(devh, CTRL_OUT, UBERTOOTH_SPECAN, low_freq, high_freq, NULL, 0, 1000); if (r < 0) { show_libusb_error(r); return r; } return 0; }
int cmd_rx_syms(struct libusb_device_handle* devh, u16 num) { int r; r = libusb_control_transfer(devh, CTRL_OUT, UBERTOOTH_RX_SYMBOLS, num, 0, NULL, 0, 1000); if (r < 0) { show_libusb_error(r); return r; } return 0; }
int cmd_ping(struct libusb_device_handle* devh) { int r; r = libusb_control_transfer(devh, CTRL_IN, UBERTOOTH_PING, 0, 0, NULL, 0, 1000); if (r < 0) { show_libusb_error(r); return r; } return 0; }
int cmd_led_specan(struct libusb_device_handle* devh, u16 rssi_threshold) { int r; r = libusb_control_transfer(devh, CTRL_OUT, UBERTOOTH_LED_SPECAN, rssi_threshold, 0, NULL, 0, 1000); if (r < 0) { show_libusb_error(r); return r; } return 0; }
int cmd_set_txled(struct libusb_device_handle* devh, u16 state) { int r; r = libusb_control_transfer(devh, CTRL_OUT, UBERTOOTH_SET_TXLED, state, 0, NULL, 0, 1000); if (r < 0) { show_libusb_error(r); return r; } return 0; }
int cmd_get_squelch(struct libusb_device_handle* devh) { u8 level; int r; r = libusb_control_transfer(devh, CTRL_IN, UBERTOOTH_GET_SQUELCH, 0, 0, &level, 1, 3000); if (r < 0) { show_libusb_error(r); return r; } return level; }
void ubertooth_bulk_wait(ubertooth_t* ut) { int r; while (!ut->usb_really_full) { r = libusb_handle_events(NULL); if (r < 0) { if (r == LIBUSB_ERROR_INTERRUPTED) break; show_libusb_error(r); } } }
int cmd_reset(struct libusb_device_handle* devh) { int r; r = libusb_control_transfer(devh, CTRL_OUT, UBERTOOTH_RESET, 0, 0, NULL, 0, 1000); /* LIBUSB_ERROR_PIPE or LIBUSB_ERROR_OTHER is expected */ if ((r != LIBUSB_ERROR_PIPE) && (r != LIBUSB_ERROR_OTHER)) { show_libusb_error(r); return r; } return 0; }
int cmd_get_txled(struct libusb_device_handle* devh) { u8 state; int r; r = libusb_control_transfer(devh, CTRL_IN, UBERTOOTH_GET_TXLED, 0, 0, &state, 1, 1000); if (r < 0) { show_libusb_error(r); return r; } return state; }
int cmd_get_modulation(struct libusb_device_handle* devh) { u8 modulation; int r; r = libusb_control_transfer(devh, CTRL_IN, UBERTOOTH_GET_MOD, 0, 0, &modulation, 1, 1000); if (r < 0) { show_libusb_error(r); return r; } return modulation; }
static inline int handle_events_wrapper() { int r = LIBUSB_ERROR_INTERRUPTED; while (r == LIBUSB_ERROR_INTERRUPTED) { r = libusb_handle_events(NULL); if (r < 0) { if (r != LIBUSB_ERROR_INTERRUPTED) { show_libusb_error(r); return -1; } } else return r; } return 0; }
int cmd_tx_test(struct libusb_device_handle* devh) { int r; r = libusb_control_transfer(devh, CTRL_OUT, UBERTOOTH_TX_TEST, 0, 0, NULL, 0, 1000); if (r == LIBUSB_ERROR_PIPE) { fprintf(stderr, "control message unsupported\n"); return r; } else if (r < 0) { show_libusb_error(r); return r; } return 0; }
int cmd_set_paen(struct libusb_device_handle* devh, u16 state) { int r; r = libusb_control_transfer(devh, CTRL_OUT, UBERTOOTH_SET_PAEN, state, 0, NULL, 0, 1000); if (r == LIBUSB_ERROR_PIPE) { fprintf(stderr, "control message unsupported\n"); return r; } else if (r < 0) { show_libusb_error(r); return r; } return 0; }
int cmd_set_squelch(struct libusb_device_handle* devh, u16 level) { int r; r = libusb_control_transfer(devh, CTRL_OUT, UBERTOOTH_SET_SQUELCH, level, 0, NULL, 0, 3000); if (r != LIBUSB_SUCCESS) { if (r == LIBUSB_ERROR_PIPE) { fprintf(stderr, "control message unsupported\n"); } else { show_libusb_error(r); } return r; } return 0; }
int cmd_get_channel(struct libusb_device_handle* devh) { u8 result[2]; int r; r = libusb_control_transfer(devh, CTRL_IN, UBERTOOTH_GET_CHANNEL, 0, 0, result, 2, 1000); if (r == LIBUSB_ERROR_PIPE) { fprintf(stderr, "control message unsupported\n"); return r; } else if (r < 0) { show_libusb_error(r); return r; } return result[0] | (result[1] << 8); }
int cmd_repeater(struct libusb_device_handle* devh) { int r; r = libusb_control_transfer(devh, CTRL_OUT, UBERTOOTH_REPEATER, 0, 0, NULL, 0, 1000); if (r != LIBUSB_SUCCESS) { if (r == LIBUSB_ERROR_PIPE) { fprintf(stderr, "control message unsupported\n"); } else { show_libusb_error(r); } return r; } return 0; }
int cmd_get_board_id(struct libusb_device_handle* devh) { u8 board_id; int r; r = libusb_control_transfer(devh, CTRL_IN, UBERTOOTH_GET_BOARD_ID, 0, 0, &board_id, 1, 1000); if (r == LIBUSB_ERROR_PIPE) { fprintf(stderr, "control message unsupported\n"); return r; } else if (r < 0) { show_libusb_error(r); return r; } return board_id; }
int cmd_get_partnum(struct libusb_device_handle* devh) { u8 result[5]; int r; r = libusb_control_transfer(devh, CTRL_IN, UBERTOOTH_GET_PARTNUM, 0, 0, result, 5, 1000); if (r < 0) { show_libusb_error(r); return r; } if (result[0] != 0) { fprintf(stderr, "result not zero: %d\n", result[0]); return 0; } return result[1] | (result[2] << 8) | (result[3] << 16) | (result[4] << 24); }
int cmd_get_serial(struct libusb_device_handle* devh) { u8 result[17]; int r; r = libusb_control_transfer(devh, CTRL_IN, UBERTOOTH_GET_SERIAL, 0, 0, result, 17, 1000); if (r < 0) { show_libusb_error(r); return r; } if (result[0] != 0) { fprintf(stderr, "result not zero: %d\n", result[0]); return 0; } /* FIXME shouldn't print to stdout, should return complete serial number */ printf("%08x", result[1] | (result[2] << 8) | (result[3] << 16) | (result[4] << 24)); printf("%08x", result[5] | (result[6] << 8) | (result[7] << 16) | (result[8] << 24)); printf("%08x", result[9] | (result[10] << 8) | (result[11] << 16) | (result[12] << 24)); printf("%08x\n", result[13] | (result[14] << 8) | (result[15] << 16) | (result[16] << 24)); return result[1] | (result[2] << 8) | (result[3] << 16) | (result[4] << 24); }