projects
/
fw
/
altos
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
doc: add flash-force instructions for TeleBT v3.0
[fw/altos]
/
ao-tools
/
ao-chaosread
/
ao-chaosread.c
diff --git
a/ao-tools/ao-chaosread/ao-chaosread.c
b/ao-tools/ao-chaosread/ao-chaosread.c
index ca7b65a7c89074d5e75ac6b11490dacd5fe78f5b..b0a6168aa71e991fc7f7e7ee86f55d299c4d2074 100644
(file)
--- a/
ao-tools/ao-chaosread/ao-chaosread.c
+++ b/
ao-tools/ao-chaosread/ao-chaosread.c
@@
-36,7
+36,7
@@
struct chaoskey {
int kernel_active;
};
int kernel_active;
};
-libusb_device_handle *
+
static
libusb_device_handle *
chaoskey_match(libusb_device *dev, char *match_serial)
{
struct libusb_device_descriptor desc;
chaoskey_match(libusb_device *dev, char *match_serial)
{
struct libusb_device_descriptor desc;
@@
-74,7
+74,7
@@
chaoskey_match(libusb_device *dev, char *match_serial)
goto out;
}
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));
if (ret < 0) {
fprintf(stderr, "failed to get serial number: %s\n", libusb_strerror(ret));
@@
-91,20
+91,18
@@
chaoskey_match(libusb_device *dev, char *match_serial)
return handle;
out:
return handle;
out:
- free(device_serial);
if (handle)
libusb_close(handle);
return 0;
}
if (handle)
libusb_close(handle);
return 0;
}
-struct chaoskey *
+st
atic st
ruct chaoskey *
chaoskey_open(char *serial)
{
struct chaoskey *ck;
int ret;
ssize_t num;
libusb_device **list;
chaoskey_open(char *serial)
{
struct chaoskey *ck;
int ret;
ssize_t num;
libusb_device **list;
- libusb_device *device = NULL;
int d;
ck = calloc(sizeof (struct chaoskey), 1);
int d;
ck = calloc(sizeof (struct chaoskey), 1);
@@
-163,27
+161,12
@@
out:
return NULL;
}
return NULL;
}
-void
-chaoskey_close(struct chaoskey *ck)
-{
- libusb_release_interface(ck->handle, 0);
- if (ck->kernel_active)
- libusb_attach_kernel_driver(ck->handle, 0);
- libusb_close(ck->handle);
- libusb_exit(ck->ctx);
- free(ck);
-}
+#define COOKED_ENDPOINT 0x85
+#define RAW_ENDPOINT 0x86
+#define FLASH_ENDPOINT 0x87
-void
-chaoskey_transfer_callback(struct libusb_transfer *transfer)
-{
- struct chaoskey *ck = transfer->user_data;
-}
-
-#define ENDPOINT 0x86
-
-int
-chaoskey_read(struct chaoskey *ck, void *buffer, int len)
+static int
+chaoskey_read(struct chaoskey *ck, int endpoint, void *buffer, int len)
{
uint8_t *buf = buffer;
int total = 0;
{
uint8_t *buf = buffer;
int total = 0;
@@
-192,7
+175,7
@@
chaoskey_read(struct chaoskey *ck, void *buffer, int len)
int ret;
int transferred;
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;
if (ret) {
if (total)
return total;
@@
-203,7
+186,9
@@
chaoskey_read(struct chaoskey *ck, void *buffer, int len)
}
len -= transferred;
buf += transferred;
}
len -= transferred;
buf += transferred;
+ total += transferred;
}
}
+ return total;
}
static const struct option options[] = {
}
static const struct option options[] = {
@@
-211,12
+196,15
@@
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 = "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' },
+ { .name = "flash", .has_arg = 0, .val = 'f' },
{ 0, 0, 0, 0},
};
static void usage(char *program)
{
{ 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] [--flash]
\n", program);
exit(1);
}
exit(1);
}
@@
-234,8
+222,9
@@
main (int argc, char **argv)
int this_time;
int infinite = 0;
int bytes = 0;
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:
ibcrf
", options, NULL)) != -1) {
switch (c) {
case 's':
serial = optarg;
switch (c) {
case 's':
serial = optarg;
@@
-258,6
+247,15
@@
main (int argc, char **argv)
case 'b':
bytes = 1;
break;
case 'b':
bytes = 1;
break;
+ case 'c':
+ endpoint = COOKED_ENDPOINT;
+ break;
+ case 'r':
+ endpoint = RAW_ENDPOINT;
+ break;
+ case 'f':
+ endpoint = FLASH_ENDPOINT;
+ break;
default:
usage(argv[0]);
break;
default:
usage(argv[0]);
break;
@@
-275,7
+273,7
@@
main (int argc, char **argv)
this_time = sizeof(buf);
if (!infinite && length < sizeof(buf))
this_time = (int) length;
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);
if (got < 0) {
perror("read");
exit(1);
@@
-284,8
+282,17
@@
main (int argc, char **argv)
int i;
for (i = 0; i < got / 2; i++)
putchar((buf[i] >> 1 & 0xff));
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);
length -= got;
}
exit(0);