diff options
Diffstat (limited to 'host')
-rw-r--r-- | host/Makefile | 17 | ||||
-rw-r--r-- | host/hexdump.c | 60 | ||||
-rw-r--r-- | host/main.c | 101 | ||||
-rw-r--r-- | host/project.h | 38 |
4 files changed, 216 insertions, 0 deletions
diff --git a/host/Makefile b/host/Makefile new file mode 100644 index 0000000..667d094 --- /dev/null +++ b/host/Makefile @@ -0,0 +1,17 @@ +INCLUDES=$(shell pkg-config --cflags libusb-1.0) +LIBS=$(shell pkg-config --libs libusb-1.0) + +PROG=cryptopad +CSRCS=main.c hexdump.c + +OBJS=${CSRCS:%.c=%.o} + +CFLAGS=${OPT} +CPPFLAGS=${INCLUDES} ${DEFINES} + +${PROG}:${OBJS} + ${CC} ${CPPFLAGS} ${CFLAGS} ${LDFLAGS} -o $@ ${OBJS} ${LIBS} + +clean: + /bin/rm -f *~ *.d ${PROG} ${OBJS} + diff --git a/host/hexdump.c b/host/hexdump.c new file mode 100644 index 0000000..127faab --- /dev/null +++ b/host/hexdump.c @@ -0,0 +1,60 @@ +/* + * hexdump.c + * + * Copyright (c) 2011 Citrix Sysmtes Inc., + * All rights reserved. + * + */ + +#include "project.h" + +void +hexdump (char *prefix, void *_d, int len) +{ + uint8_t *d = (uint8_t *) _d; + int i, j, k; + int e; + + printf ("%s %d bytes from %p\n", prefix, len, d); + + if (!d || len < 0) + return; + + e = len + 15; + e &= ~15; + + for (i = 0; i < e; i += 16) + { + printf ("%s %05x:", prefix, i); + for (j = 0; j < 16; ++j) + { + k = i + j; + + if (k < len) + printf (" %02x", d[k]); + else + printf (" "); + + if (j == 7) + printf (" "); + } + + printf (" "); + for (j = 0; j < 16; ++j) + { + k = i + j; + if (k < len) + { + uint8_t c = d[k]; + if (c < 33) + c = '.'; + if (c > 126) + c = '.'; + printf ("%c", c); + } + if (j == 7) + printf (" "); + } + printf ("\n"); + } +} diff --git a/host/main.c b/host/main.c new file mode 100644 index 0000000..a779cc1 --- /dev/null +++ b/host/main.c @@ -0,0 +1,101 @@ +#include "project.h" + + + +static void poke(libusb_device_handle *devh) +{ +uint32_t timeout=4000; +char buf[128]; +int len; + +len= libusb_control_transfer( devh, + /* bmRequestType */ LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_INTERFACE, + /* bRequest */ 0x34, + /* wValue */ 0x1234, + /* wIndex */ 0x5678, + /* Data */ buf, + /* wLength */ sizeof(buf), timeout ); + + + + +if (len>=0) +hexdump(">",buf,len); + + +} + + + +static void poke_device(libusb_device *dev, struct libusb_device_descriptor *desc) +{ +int ret; +libusb_device_handle *devh; + +ret=libusb_open(dev, &devh); + +if (ret) { + warn("unable to open device: %i",ret); + return; +} + +printf("poke\n"); + +poke(devh); + +libusb_close(devh); + +} + +void probe_devices(libusb_context *ctx) +{ + libusb_device **list; + ssize_t num_devs; + ssize_t i; + + num_devs = libusb_get_device_list(ctx, &list); + for (i = 0; i < num_devs; ++i) { + struct libusb_device_descriptor desc; + struct libusb_device *dev = list[i]; + + if (libusb_get_device_descriptor(dev, &desc)) + continue; + + + if (desc.idVendor!=0x1d6b) continue; + if (desc.idProduct!=0x1932) continue; + + poke_device(dev,&desc); + + } + libusb_free_device_list(list, 0); +} + + + + + +int main(int argc,char *argv) +{ + int ret; + + libusb_context *ctx; + + + ret = libusb_init(&ctx); + if (ret) + errx(EX_IOERR, "unable to initialize libusb: %i", ret); + + + libusb_set_debug(ctx, 255); + + probe_devices(ctx); + + return 0; +} + + + + + + diff --git a/host/project.h b/host/project.h new file mode 100644 index 0000000..2302570 --- /dev/null +++ b/host/project.h @@ -0,0 +1,38 @@ +#include <libusb.h> +#include <stdio.h> +#include <malloc.h> +#include <fcntl.h> +#include <unistd.h> +#include <stdlib.h> +#include <libusb.h> + +#ifdef HAVE_ERR +# include <err.h> +#else +# include <errno.h> +# include <string.h> +# define warnx(...) do {\ + fprintf(stderr, __VA_ARGS__);\ + fprintf(stderr, "\n"); } while (0) +# define errx(eval, ...) do {\ + warnx(__VA_ARGS__);\ + exit(eval); } while (0) +# define warn(...) do {\ + fprintf(stderr, "%s: ", strerror(errno));\ + warnx(__VA_ARGS__); } while (0) +# define err(eval, ...) do {\ + warn(__VA_ARGS__);\ + exit(eval); } while (0) +#endif /* HAVE_ERR */ + + +#ifdef HAVE_SYSEXITS_H +# include <sysexits.h> +#else +# define EX_OK 0 /* successful termination */ +# define EX_USAGE 64 /* command line usage error */ +# define EX_SOFTWARE 70 /* internal software error */ +# define EX_IOERR 74 /* input/output error */ +#endif /* HAVE_SYSEXITS_H */ + + |