goto out;
}
- ret = libusb_get_string_descriptor_ascii(handle, desc.iSerialNumber, device_serial, match_len + 1);
+ ret = libusb_get_string_descriptor_ascii(handle, desc.iSerialNumber, (unsigned char *) device_serial, match_len + 1);
if (ret < 0) {
fprintf(stderr, "failed to get serial number: %s\n", libusb_strerror(ret));
int ret;
ssize_t num;
libusb_device **list;
- libusb_device *device = NULL;
int d;
ck = calloc(sizeof (struct chaoskey), 1);
free(ck);
}
-void
-chaoskey_transfer_callback(struct libusb_transfer *transfer)
-{
- struct chaoskey *ck = transfer->user_data;
-}
-
-#define ENDPOINT 0x86
+#define COOKED_ENDPOINT 0x85
+#define RAW_ENDPOINT 0x86
int
-chaoskey_read(struct chaoskey *ck, void *buffer, int len)
+chaoskey_read(struct chaoskey *ck, int endpoint, void *buffer, int len)
{
uint8_t *buf = buffer;
int total = 0;
int ret;
int transferred;
- ret = libusb_bulk_transfer(ck->handle, ENDPOINT, buf, len, &transferred, 10000);
+ ret = libusb_bulk_transfer(ck->handle, endpoint, buf, len, &transferred, 10000);
if (ret) {
if (total)
return total;
}
len -= transferred;
buf += transferred;
+ total += transferred;
}
+ return total;
}
static const struct option options[] = {
{ .name = "length", .has_arg = 1, .val = 'l' },
{ .name = "infinite", .has_arg = 0, .val = 'i' },
{ .name = "bytes", .has_arg = 0, .val = 'b' },
+ { .name = "cooked", .has_arg = 0, .val = 'c' },
+ { .name = "raw", .has_arg = 0, .val = 'r' },
{ 0, 0, 0, 0},
};
static void usage(char *program)
{
- fprintf(stderr, "usage: %s [--serial=<serial>] [--length=<length>[kMG]] [--infinite] [--bytes]\n", program);
+ fprintf(stderr, "usage: %s [--serial=<serial>] [--length=<length>[kMG]] [--infinite] [--bytes] [--cooked] [--raw]\n", program);
exit(1);
}
int this_time;
int infinite = 0;
int bytes = 0;
+ int endpoint = RAW_ENDPOINT;
- while ((c = getopt_long(argc, argv, "s:l:", options, NULL)) != -1) {
+ while ((c = getopt_long(argc, argv, "s:l:ibcr", options, NULL)) != -1) {
switch (c) {
case 's':
serial = optarg;
case 'b':
bytes = 1;
break;
+ case 'c':
+ endpoint = COOKED_ENDPOINT;
+ break;
+ case 'r':
+ endpoint = RAW_ENDPOINT;
+ break;
default:
usage(argv[0]);
break;
this_time = sizeof(buf);
if (!infinite && length < sizeof(buf))
this_time = (int) length;
- got = chaoskey_read(ck, buf, this_time);
+ got = chaoskey_read(ck, endpoint, buf, this_time);
if (got < 0) {
perror("read");
exit(1);
int i;
for (i = 0; i < got / 2; i++)
putchar((buf[i] >> 1 & 0xff));
- } else
- write(1, buf, got);
+ } else {
+ int i;
+ int ret;
+ for (i = 0; i < got; i += ret) {
+ ret = write(1, ((char *) buf) + i, got - i);
+ if (ret <= 0) {
+ perror("write");
+ exit(1);
+ }
+ }
+ }
length -= got;
}
exit(0);