summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorroot <root@lamia.panaceas.james.local>2016-08-20 14:04:59 +0100
committerroot <root@lamia.panaceas.james.local>2016-08-20 14:04:59 +0100
commitb063a2da3024a2e3175e1ba9b0a87cb6c7470765 (patch)
treef5c90c4119b091876a3f53acf4e581316eec4926
parentbc832d6d342922a828aebb997d1d9c6626898487 (diff)
downloadcandlestick-b063a2da3024a2e3175e1ba9b0a87cb6c7470765.tar.gz
candlestick-b063a2da3024a2e3175e1ba9b0a87cb6c7470765.tar.bz2
candlestick-b063a2da3024a2e3175e1ba9b0a87cb6c7470765.zip
candlestick
-rw-r--r--Makefile.include2
-rw-r--r--app/Makefile14
-rw-r--r--app/adc.c51
-rw-r--r--app/candlestick.ld (renamed from app/crypto.ld)3
-rw-r--r--app/cdc.c154
-rw-r--r--app/code.c71
-rw-r--r--app/crypto.c77
-rw-r--r--app/dfu.c4
-rw-r--r--app/key.c61
-rw-r--r--app/keyboard.c129
-rw-r--r--app/led.c39
-rw-r--r--app/main.c8
-rw-r--r--app/map.c410
-rw-r--r--app/project.h2
-rw-r--r--app/prototypes.h40
-rw-r--r--app/state.c99
-rw-r--r--app/ticker.c16
-rw-r--r--app/usb.c61
-rw-r--r--board/STM32F103C8T6_BOARD.cfg (renamed from board/STM32F101C8T6_BOARD.cfg)0
-rw-r--r--boot/usbdfu.c8
-rw-r--r--boot/usbdfu.ld4
-rw-r--r--host/Makefile23
-rw-r--r--host/cryptopad.c122
-rw-r--r--host/hexdump.c60
-rw-r--r--host/project.h39
25 files changed, 235 insertions, 1262 deletions
diff --git a/Makefile.include b/Makefile.include
index ff799bd..1301f18 100644
--- a/Makefile.include
+++ b/Makefile.include
@@ -35,7 +35,7 @@ OOCD ?= openocd
#OOCD_INTERFACE ?= ../interface/j-link.cfg
OOCD_INTERFACE ?= ../interface/stlink-v2.cfg
#OOCD_BOARD ?= ../board/st_link_v2.cfg
-OOCD_BOARD ?= ../board/STM32F101C8T6_BOARD.cfg
+OOCD_BOARD ?= ../board/STM32F103C8T6_BOARD.cfg
################################################################################
# Black Magic Probe specific variables
diff --git a/app/Makefile b/app/Makefile
index b9606ca..afb5bc1 100644
--- a/app/Makefile
+++ b/app/Makefile
@@ -18,14 +18,14 @@
##
CPROTO=cproto
-PROG=crypto
+PROG=candlestick
V=1
default: ${PROG}.elf
-CSRCS=dfu.c main.c usb.c led.c ticker.c i2c.c lcd.c adc.c state.c key.c keyboard.c crypto.c map.c
+CSRCS=dfu.c main.c usb.c led.c ticker.c i2c.c lcd.c cdc.c
BINARY = ${PROG}
@@ -39,7 +39,14 @@ include ../Makefile.include
INCLUDES += -I../include
dfu:${PROG}.dfu
- dfu-util -R -a 0 -d 1d6b:1932 -s 0x08002000:leave -D $<
+ dfu-util -R -a 0 -d 1d6b:cad5 -s 0x08002000:leave -D $<
+
+server:
+ $(Q)$(OOCD) -f $(OOCD_INTERFACE) -f $(OOCD_BOARD)
+
+debug: ${PROG}.elf
+ echo "target remote localhost:3333" > debug.start
+ ${GDB} ${PROG}.elf -x debug.start
program: ${PROG}.elf
echo halt | nc -t localhost 4444
@@ -51,3 +58,4 @@ protos:
${CPROTO} $(INCLUDES) $(DEFINES) -e -v ${CSRCS} > prototypes.h.tmp
mv -f prototypes.h.tmp prototypes.h
+EXTRA_CLEAN=debug.start
diff --git a/app/adc.c b/app/adc.c
deleted file mode 100644
index 1565af5..0000000
--- a/app/adc.c
+++ /dev/null
@@ -1,51 +0,0 @@
-#include "project.h"
-
-int host_has_power;
-
-void
-adc_tick (void)
-{
- uint16_t v;
-
- if (adc_eoc (ADC1))
- {
- v = adc_read_regular (ADC1);
-
- host_has_power = ! !(v > 1000);
-
- }
-
- adc_start_conversion_direct (ADC1);
-}
-
-
-
-static uint8_t channels[] = { ADC_CHANNEL0 };
-
-#define n_channels (sizeof(channels)/sizeof(channels[0]))
-
-void
-adc_init (void)
-{
-
- rcc_periph_clock_enable (RCC_ADC1);
-
- //gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_DOWN, GPIO0);
- gpio_set_mode (GPIOA, GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, GPIO0);
-
- adc_off (ADC1);
- adc_disable_scan_mode (ADC1);
- adc_set_single_conversion_mode (ADC1);
- adc_disable_external_trigger_regular (ADC1);
- adc_set_right_aligned (ADC1);
- adc_set_sample_time_on_all_channels (ADC1, ADC_SMPR_SMP_28DOT5CYC);
-
- adc_power_on (ADC1);
-
- adc_reset_calibration (ADC1);
- adc_calibration (ADC1);
- adc_set_regular_sequence (ADC1, n_channels, channels);
- adc_start_conversion_direct (ADC1);
-
- host_has_power = 0;
-}
diff --git a/app/crypto.ld b/app/candlestick.ld
index 829da07..76cebfb 100644
--- a/app/crypto.ld
+++ b/app/candlestick.ld
@@ -22,7 +22,7 @@
/* Define memory regions. */
MEMORY
{
- rom (rx) : ORIGIN = 0x08002000, LENGTH = 120K
+ rom (rx) : ORIGIN = 0x08002000, LENGTH = 56K
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K
}
@@ -37,7 +37,6 @@ SECTIONS
{
.dfu_shared dfu_shared_location :{
dfu_flag = .;
- bkp_moo = 4 + dfu_flag;
}
}
diff --git a/app/cdc.c b/app/cdc.c
new file mode 100644
index 0000000..4088b6c
--- /dev/null
+++ b/app/cdc.c
@@ -0,0 +1,154 @@
+#include "project.h"
+
+static const struct usb_endpoint_descriptor comm_endp[] = {
+ {
+ .bLength = USB_DT_ENDPOINT_SIZE,
+ .bDescriptorType = USB_DT_ENDPOINT,
+ .bEndpointAddress = 0x83,
+ .bmAttributes = USB_ENDPOINT_ATTR_INTERRUPT,
+ .wMaxPacketSize = 16,
+ .bInterval = 255,
+ }
+};
+
+static const struct usb_endpoint_descriptor data_endp[] = {
+ {
+ .bLength = USB_DT_ENDPOINT_SIZE,
+ .bDescriptorType = USB_DT_ENDPOINT,
+ .bEndpointAddress = 0x01,
+ .bmAttributes = USB_ENDPOINT_ATTR_BULK,
+ .wMaxPacketSize = 64,
+ .bInterval = 1,
+ },
+ {
+ .bLength = USB_DT_ENDPOINT_SIZE,
+ .bDescriptorType = USB_DT_ENDPOINT,
+ .bEndpointAddress = 0x82,
+ .bmAttributes = USB_ENDPOINT_ATTR_BULK,
+ .wMaxPacketSize = 64,
+ .bInterval = 1,
+ }
+};
+
+static const struct {
+ struct usb_cdc_header_descriptor header;
+ struct usb_cdc_call_management_descriptor call_mgmt;
+ struct usb_cdc_acm_descriptor acm;
+ struct usb_cdc_union_descriptor cdc_union;
+} __attribute__((packed)) cdcacm_functional_descriptors = {
+ .header = {
+ .bFunctionLength = sizeof(struct usb_cdc_header_descriptor),
+ .bDescriptorType = CS_INTERFACE,
+ .bDescriptorSubtype = USB_CDC_TYPE_HEADER,
+ .bcdCDC = 0x0110,
+ },
+ .call_mgmt = {
+ .bFunctionLength =
+ sizeof(struct usb_cdc_call_management_descriptor),
+ .bDescriptorType = CS_INTERFACE,
+ .bDescriptorSubtype = USB_CDC_TYPE_CALL_MANAGEMENT,
+ .bmCapabilities = 0,
+ .bDataInterface = 1,
+ },
+ .acm = {
+ .bFunctionLength = sizeof(struct usb_cdc_acm_descriptor),
+ .bDescriptorType = CS_INTERFACE,
+ .bDescriptorSubtype = USB_CDC_TYPE_ACM,
+ .bmCapabilities = 0,
+ },
+ .cdc_union = {
+ .bFunctionLength = sizeof(struct usb_cdc_union_descriptor),
+ .bDescriptorType = CS_INTERFACE,
+ .bDescriptorSubtype = USB_CDC_TYPE_UNION,
+ .bControlInterface = 0,
+ .bSubordinateInterface0 = 1,
+ }
+};
+
+const struct usb_interface_descriptor comm_iface[] = {
+ {
+ .bLength = USB_DT_INTERFACE_SIZE,
+ .bDescriptorType = USB_DT_INTERFACE,
+ .bInterfaceNumber = 0,
+ .bAlternateSetting = 0,
+ .bNumEndpoints = 1,
+ .bInterfaceClass = USB_CLASS_CDC,
+ .bInterfaceSubClass = USB_CDC_SUBCLASS_ACM,
+ .bInterfaceProtocol = USB_CDC_PROTOCOL_AT,
+ .iInterface = 0,
+ .endpoint = comm_endp,
+ .extra = &cdcacm_functional_descriptors,
+ .extralen = sizeof(cdcacm_functional_descriptors)
+ }
+};
+
+const struct usb_interface_descriptor data_iface[] = {
+ {
+ .bLength = USB_DT_INTERFACE_SIZE,
+ .bDescriptorType = USB_DT_INTERFACE,
+ .bInterfaceNumber = 1,
+ .bAlternateSetting = 0,
+ .bNumEndpoints = 2,
+ .bInterfaceClass = USB_CLASS_DATA,
+ .bInterfaceSubClass = 0,
+ .bInterfaceProtocol = 0,
+ .iInterface = 0,
+ .endpoint = data_endp,
+ }
+};
+
+
+int cdcacm_control_request(usbd_device *usbd_dev,
+ struct usb_setup_data *req,
+ uint8_t **buf,
+ uint16_t *len,
+ int (**complete)(usbd_device *usbd_dev,
+ struct usb_setup_data *req))
+{
+ (void)complete;
+ (void)buf;
+ (void)usbd_dev;
+
+ switch(req->bRequest) {
+ case USB_CDC_REQ_SET_CONTROL_LINE_STATE: {
+ /*
+ * This Linux cdc_acm driver requires this to be implemented
+ * even though it's optional in the CDC spec, and we don't
+ * advertise it in the ACM functional descriptor.
+ */
+ char local_buf[10];
+ struct usb_cdc_notification *notif = (void *)local_buf;
+
+ /* We echo signals back to host as notification. */
+ notif->bmRequestType = 0xA1;
+ notif->bNotification = USB_CDC_NOTIFY_SERIAL_STATE;
+ notif->wValue = 0;
+ notif->wIndex = 0;
+ notif->wLength = 2;
+ local_buf[8] = req->wValue & 3;
+ local_buf[9] = 0;
+ // usbd_ep_write_packet(0x83, buf, 10);
+ return 1;
+ }
+ case USB_CDC_REQ_SET_LINE_CODING:
+ if(*len < sizeof(struct usb_cdc_line_coding)) {
+ return 0;
+ }
+ return 1;
+ }
+ return 0;
+}
+
+void cdcacm_data_rx_cb(usbd_device *usbd_dev, uint8_t ep)
+{
+ (void)ep;
+ char buf[64];
+ int len = usbd_ep_read_packet(usbd_dev, 0x01, buf, 64);
+
+
+ if (len) {
+ buf[0]^=32;
+ usbd_ep_write_packet(usbd_dev, 0x82, buf, len);
+ buf[len] = 0;
+ }
+}
diff --git a/app/code.c b/app/code.c
deleted file mode 100644
index 3f4862a..0000000
--- a/app/code.c
+++ /dev/null
@@ -1,71 +0,0 @@
-#include "project.h"
-
-
-static uint8_t code[16];
-static int code_len;
-static int hide;
-static int show;
-
-
-void
-code_display (void)
-{
- size_t i;
-
-#if 1
- lcd_erase_line (0, 16);
-
- if (code_len != 16)
- lcd_write ("Enter code:", 0, 0);
- else
- lcd_write ("Code entered:", 0, 0);
-#endif
-
- for (i = 0; i < sizeof (code); ++i)
- lcd_write_char (hide ? '*' : (code[i] ? code[i] : ' '), i, 1);
-
-
- lcd_backlight (!hide);
-}
-
-
-void
-code_tick (void)
-{
- if (!show)
- return;
- show--;
- if (!show)
- {
- hide++;
- code_display ();
- }
-
-}
-
-
-
-
-void
-key_event (uint8_t v, int ud)
-{
- if (!ud)
- return;
-
- if (code_len == sizeof (code))
- {
- code_len = 0;
- memset (code, ' ', sizeof (code));
- }
-
-
- show = 5000;
- hide = 0;
-
- code[code_len++] = v;
-
-
- code_display ();
-
-
-}
diff --git a/app/crypto.c b/app/crypto.c
deleted file mode 100644
index a725def..0000000
--- a/app/crypto.c
+++ /dev/null
@@ -1,77 +0,0 @@
-#include "project.h"
-#include "../common/vendor_req.h"
-
-
-static int key_send_timer = 0;
-static int start_key_send = 0;
-
-int
-crypto_control (uint8_t request, uint16_t value, uint16_t index, void *buf,
- size_t len)
-{
- (void) index;
- (void) buf;
- (void) len;
-
-
- switch (request)
- {
-
- case VENDOR_REQ_KEYPRESS:
- send_ascii (value);
- return 1;
- case VENDOR_REQ_SET_KEY:
- state_init ();
- key_set (buf, len);
- return 1;
- case VENDOR_REQ_SEND_KEY:
-
- if (!value)
- start_key_send = 1;
- else
- key_send_timer = value;
- return 1;
- case VENDOR_REQ_CLEAR_KEY:
- key_wipe ();
- return 1;
- }
-
- return 0;
-}
-
-int
-vendor_control_request (usbd_device * usbd_dev, struct usb_setup_data *req,
- uint8_t ** buf, uint16_t * len,
- int (**complete) (usbd_device * usbd_dev,
- struct usb_setup_data * req))
-{
- (void) usbd_dev;
- (void) complete;
-
- if (req->bmRequestType !=
- (USB_REQ_TYPE_OUT | USB_REQ_TYPE_VENDOR | USB_REQ_TYPE_DEVICE))
- return 0;
-
- return crypto_control (req->bRequest, req->wValue, req->wIndex, *buf, *len);
-}
-
-void
-crypto_tick (void)
-{
- if (!key_send_timer)
- return;
- key_send_timer--;
-
- if (!key_send_timer)
- start_key_send = 1;
-}
-
-void
-crypto_poll (void)
-{
- if (start_key_send)
- {
- start_key_send = 0;
- key_send ();
- }
-}
diff --git a/app/dfu.c b/app/dfu.c
index 8a4a3cc..2606ac7 100644
--- a/app/dfu.c
+++ b/app/dfu.c
@@ -15,13 +15,13 @@ const struct usb_dfu_descriptor dfu_function = {
const struct usb_interface_descriptor dfu_iface = {
.bLength = USB_DT_INTERFACE_SIZE,
.bDescriptorType = USB_DT_INTERFACE,
- .bInterfaceNumber = 1,
+ .bInterfaceNumber = 2,
.bAlternateSetting = 0,
.bNumEndpoints = 0,
.bInterfaceClass = 0xFE,
.bInterfaceSubClass = 1,
.bInterfaceProtocol = 1,
- .iInterface = 7,
+ .iInterface = 8,
.extra = &dfu_function,
.extralen = sizeof (dfu_function),
diff --git a/app/key.c b/app/key.c
deleted file mode 100644
index 6449216..0000000
--- a/app/key.c
+++ /dev/null
@@ -1,61 +0,0 @@
-#include "project.h"
-
-
-int have_key;
-
-static size_t key_len;
-
-static uint8_t key[512];
-
-
-void
-key_wipe (void)
-{
- have_key = 0;
- locked = 0;
- memset (key, 0, sizeof (key));
-}
-
-
-void
-key_set (char *in, size_t len)
-{
- if (len > sizeof (key))
- len = sizeof (key);
- memcpy (key, in, len);
- key_len = len;
- locked = 0;
- have_key = 1;
-}
-
-
-void
-key_send (void)
-{
- size_t i;
- if (!have_key)
- {
- send_str ("*no key*\n");
- return;
- }
- if (locked)
- {
- send_str ("*locked*\n");
- return;
- }
-
- for (i = 0; i < key_len; ++i)
- {
- send_ascii (key[i]);
- }
-
- locked++;
-}
-
-
-void
-key_init (void)
-{
- key_wipe ();
- have_key = 0;
-}
diff --git a/app/keyboard.c b/app/keyboard.c
deleted file mode 100644
index e3e3465..0000000
--- a/app/keyboard.c
+++ /dev/null
@@ -1,129 +0,0 @@
-#include "project.h"
-
-static const uint8_t keyboard_report_descriptor[] = {
- 0x05, 0x01, /* Usage Page (Generic Desktop) */
- 0x09, 0x06, /* Usage (Keyboard) */
- 0xA1, 0x01, /* Collection (Application) */
- 0x05, 0x07, /* Usage page (Key Codes) */
- 0x19, 0xE0, /* Usage minimum (224) */
- 0x29, 0xE7, /* Usage maximum (231) */
- 0x15, 0x00, /* Logical minimum (0) */
- 0x25, 0x01, /* Logical maximum (1) */
- 0x75, 0x01, /* Report size (1) */
- 0x95, 0x08, /* Report count (8) */
- 0x81, 0x02, /* Input (data, variable, absolute) */
- 0x95, 0x01, /* Report count (1) */
- 0x75, 0x08, /* Report size (8) */
- 0x81, 0x01, /* Input (constant) */
- 0x95, 0x06, /* Report count (6) */
- 0x75, 0x08, /* Report size (8) */
- 0x15, 0x00, /* Logical minimum (0) */
- //0x25, 0x65, /* Logical maximum (101) */
- 0x26, 0xff, 0x00, /* Logical maximum (255) */
- //0x26, 0x7f, 0x00, /* Logical maximum (255) */
- 0x05, 0x07, /* Usage page (key codes) */
- 0x19, 0x00, /* Usage minimum (0) */
- 0x2A, 0xff, 0x00, /* Usage maximum (255) */
-// 0x29, 0x65, /* Usage maximum (101) */
-// 0x2A, 0xff, 0x03, /* Usage maximum (1023) */
- 0x81, 0x00, /* Input (data, array) */
- 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */
- 0x09, 0x80, /* USAGE (System Control) */
- 0xA1, 0x01, /* COLLECTION (Application) */
- 0x75, 0x02, /* REPORT_SIZE (2) */
- 0x95, 0x01, /* REPORT_COUNT (1) */
- 0x15, 0x01, /* LOGICAL_MIN (1) */
- 0x25, 0x03, /* LOGICAL_MAX (3) */
- 0x09, 0x82, /* USAGE (System Sleep) */
- 0x09, 0x81, /* USAGE (System Power Down) */
- 0x09, 0x83, /* USAGE (System Wake Up) */
- 0x81, 0x60, /* INPUT (Data Ary Abs NPrf Null) */
- 0x75, 0x06, /* REPORT_SIZE (6) */
- 0x81, 0x03, /* INPUT (Cnst Var Abs) */
- 0xc0, /* END COLLECTION */
- 0xC0 /* End Collection */
-};
-
-
-static const struct
-{
- struct usb_hid_descriptor hid_descriptor;
- struct
- {
- uint8_t bReportDescriptorType;
- uint16_t wDescriptorLength;
- } __attribute__ ((packed)) hid_report;
-} __attribute__ ((packed)) keyboard_function =
-{
- .hid_descriptor =
- {
- .bLength = sizeof (keyboard_function),.bDescriptorType =
- USB_DT_HID,.bcdHID = 0x0100,.bCountryCode = 0,.bNumDescriptors = 1,}
- ,.hid_report =
- {
- .bReportDescriptorType = USB_DT_REPORT,.wDescriptorLength =
- sizeof (keyboard_report_descriptor),}
-,};
-
-const struct usb_endpoint_descriptor keyboard_endpoint = {
- .bLength = USB_DT_ENDPOINT_SIZE,
- .bDescriptorType = USB_DT_ENDPOINT,
- .bEndpointAddress = 0x81,
- .bmAttributes = USB_ENDPOINT_ATTR_INTERRUPT,
- .wMaxPacketSize = 9,
- .bInterval = 0x1 //0x20,
-};
-
-const struct usb_interface_descriptor keyboard_iface = {
- .bLength = USB_DT_INTERFACE_SIZE,
- .bDescriptorType = USB_DT_INTERFACE,
- .bInterfaceNumber = 0,
- .bAlternateSetting = 0,
- .bNumEndpoints = 1,
- .bInterfaceClass = USB_CLASS_HID,
- .bInterfaceSubClass = 1, /* boot */
- .bInterfaceProtocol = 1, /* keyboard */
- .iInterface = 5,
- .endpoint = &keyboard_endpoint,
- .extra = &keyboard_function,
- .extralen = sizeof (keyboard_function),
-};
-
-
-void
-keyboard_get_descriptor (uint8_t ** buf, uint16_t * len)
-{
-
- /* Handle the HID report descriptor. */
- *buf = (uint8_t *) keyboard_report_descriptor;
- *len = sizeof (keyboard_report_descriptor);
-}
-
-void
-keyboard_keypress (int m, int k)
-{
- uint8_t buf[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
-
-
- buf[0] = m;
- buf[2] = k;
- usbd_ep_write_packet (usbd_dev, 0x81, buf, 9);
-
- delay_ms (10);
-
- buf[0] = m;
- buf[2] = 0;
- usbd_ep_write_packet (usbd_dev, 0x81, buf, 9);
-
- delay_ms (10);
-
- if (m)
- {
- buf[0] = 0;
- buf[2] = 0;
- usbd_ep_write_packet (usbd_dev, 0x81, buf, 9);
-
- delay_ms (10);
- }
-
-}
diff --git a/app/led.c b/app/led.c
index dfa343e..bda76ea 100644
--- a/app/led.c
+++ b/app/led.c
@@ -9,48 +9,39 @@ static int led_cycle = 0;
void
led_init (void)
{
- gpio_set_mode (GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
- GPIO_CNF_OUTPUT_PUSHPULL, GPIO9);
+ gpio_set_mode (GPIOC, GPIO_MODE_OUTPUT_2_MHZ,
+ GPIO_CNF_OUTPUT_PUSHPULL, GPIO13);
- gpio_set (GPIOA, GPIO9);
+ gpio_set (GPIOA, GPIO13);
}
+#if 0
void
led_blink (void)
{
- gpio_set (GPIOA, GPIO9);
+ gpio_set (GPIOC, GPIO13);
led_on = 50;
}
+#endif
void
led_tick (void)
{
- if (led_on)
- {
- led_on--;
- if (!led_on)
- gpio_clear (GPIOA, GPIO9);
- }
+ led_cycle++;
- led_cycle++;
+ if (led_cycle<500)
+ return;
- if (led_cycle == LED_PERIOD)
- {
- led_cycle = 0;
+ led_cycle=0;
+ led_on=!led_on;
+ if (led_on)
+ gpio_clear (GPIOC, GPIO13);
+ else
+ gpio_set (GPIOC, GPIO13);
- if (have_key && locked)
- led_on = 50;
- if (have_key && !locked)
- led_on = 500;
- if (!have_key)
- led_on = 1000;
-
- gpio_set (GPIOA, GPIO9);
-
- }
}
diff --git a/app/main.c b/app/main.c
index 8c51c90..4c56b55 100644
--- a/app/main.c
+++ b/app/main.c
@@ -23,17 +23,15 @@ main (void)
ticker_init ();
led_init ();
-#ifndef SLIM
+
+#if 0
i2c_bb_init ();
lcd_init ();
#endif
- adc_init ();
- key_init ();
- state_init ();
usb_init ();
-
usb_run ();
+
return 0;
}
diff --git a/app/map.c b/app/map.c
deleted file mode 100644
index d63c171..0000000
--- a/app/map.c
+++ /dev/null
@@ -1,410 +0,0 @@
-#include "project.h"
-
-
-void
-send_ascii (unsigned char a)
-{
- switch (a)
- {
-#if 0
- case '\0':
- keyboard_keypress (0x00, 0x00);
- break;
- case '\001':
- keyboard_keypress (0x00, 0x00);
- break;
- case '\002':
- keyboard_keypress (0x00, 0x00);
- break;
- case '\003':
- keyboard_keypress (0x00, 0x00);
- break;
- case '\004':
- keyboard_keypress (0x00, 0x00);
- break;
- case '\005':
- keyboard_keypress (0x00, 0x00);
- break;
- case '\006':
- keyboard_keypress (0x00, 0x00);
- break;
- case '\a':
- keyboard_keypress (0x00, 0x00);
- break;
- case '\b':
- keyboard_keypress (0x00, 0x00);
- break;
-#endif
- case '\t':
- keyboard_keypress (0x00, 0x2b);
- break;
-#if 0
- case '\n':
- keyboard_keypress (0x00, 0x00);
- break;
- case '\v':
- keyboard_keypress (0x00, 0x00);
- break;
- case '\f':
- keyboard_keypress (0x00, 0x00);
- break;
-#endif
- case '\n':
- case '\r':
- keyboard_keypress (0x00, 0x28);
- break;
-#if 0
- case '\016':
- keyboard_keypress (0x00, 0x00);
- break;
- case '\017':
- keyboard_keypress (0x00, 0x00);
- break;
- case '\020':
- keyboard_keypress (0x00, 0x00);
- break;
- case '\021':
- keyboard_keypress (0x00, 0x00);
- break;
- case '\022':
- keyboard_keypress (0x00, 0x00);
- break;
- case '\023':
- keyboard_keypress (0x00, 0x00);
- break;
- case '\024':
- keyboard_keypress (0x00, 0x00);
- break;
- case '\025':
- keyboard_keypress (0x00, 0x00);
- break;
- case '\026':
- keyboard_keypress (0x00, 0x00);
- break;
- case '\027':
- keyboard_keypress (0x00, 0x00);
- break;
- case '\030':
- keyboard_keypress (0x00, 0x00);
- break;
- case '\031':
- keyboard_keypress (0x00, 0x00);
- break;
- case '\032':
- keyboard_keypress (0x00, 0x00);
- break;
- case '\033':
- keyboard_keypress (0x00, 0x00);
- break;
- case '\034':
- keyboard_keypress (0x00, 0x00);
- break;
- case '\035':
- keyboard_keypress (0x00, 0x00);
- break;
- case '\036':
- keyboard_keypress (0x00, 0x00);
- break;
- case '\037':
- keyboard_keypress (0x00, 0x00);
- break;
-#endif
- case ' ':
- keyboard_keypress (0x00, 0x2c);
- break;
- case '!':
- keyboard_keypress (0x02, 0x1e);
- break;
- case '"':
- keyboard_keypress (0x02, 0x34);
- break;
- case '#':
- keyboard_keypress (0x02, 0x20);
- break;
- case '$':
- keyboard_keypress (0x02, 0x21);
- break;
- case '%':
- keyboard_keypress (0x02, 0x22);
- break;
- case '&':
- keyboard_keypress (0x02, 0x23);
- break;
- case '\047':
- keyboard_keypress (0x00, 0x34);
- break;
- case '(':
- keyboard_keypress (0x02, 0x26);
- break;
- case ')':
- keyboard_keypress (0x02, 0x27);
- break;
- case '*':
- keyboard_keypress (0x02, 0x25);
- break;
- case '+':
- keyboard_keypress (0x02, 0x2e);
- break;
- case ',':
- keyboard_keypress (0x00, 0x36);
- break;
- case '-':
- keyboard_keypress (0x00, 0x2d);
- break;
- case '.':
- keyboard_keypress (0x00, 0x37);
- break;
- case '/':
- keyboard_keypress (0x00, 0x38);
- break;
- case '0':
- keyboard_keypress (0x00, 0x27);
- break;
- case '1':
- keyboard_keypress (0x00, 0x1e);
- break;
- case '2':
- keyboard_keypress (0x00, 0x1f);
- break;
- case '3':
- keyboard_keypress (0x00, 0x20);
- break;
- case '4':
- keyboard_keypress (0x00, 0x21);
- break;
- case '5':
- keyboard_keypress (0x00, 0x22);
- break;
- case '6':
- keyboard_keypress (0x00, 0x23);
- break;
- case '7':
- keyboard_keypress (0x00, 0x24);
- break;
- case '8':
- keyboard_keypress (0x00, 0x25);
- break;
- case '9':
- keyboard_keypress (0x00, 0x26);
- break;
- case ':':
- keyboard_keypress (0x02, 0x33);
- break;
- case ';':
- keyboard_keypress (0x00, 0x33);
- break;
- case '<':
- keyboard_keypress (0x02, 0x36);
- break;
- case '=':
- keyboard_keypress (0x00, 0x2e);
- break;
- case '>':
- keyboard_keypress (0x02, 0x37);
- break;
- case '?':
- keyboard_keypress (0x02, 0x38);
- break;
- case '@':
- keyboard_keypress (0x02, 0x1f);
- break;
- case 'A':
- keyboard_keypress (0x02, 0x04);
- break;
- case 'B':
- keyboard_keypress (0x02, 0x05);
- break;
- case 'C':
- keyboard_keypress (0x02, 0x06);
- break;
- case 'D':
- keyboard_keypress (0x02, 0x07);
- break;
- case 'E':
- keyboard_keypress (0x02, 0x08);
- break;
- case 'F':
- keyboard_keypress (0x02, 0x09);
- break;
- case 'G':
- keyboard_keypress (0x02, 0x0a);
- break;
- case 'H':
- keyboard_keypress (0x02, 0x0b);
- break;
- case 'I':
- keyboard_keypress (0x02, 0x0c);
- break;
- case 'J':
- keyboard_keypress (0x02, 0x0d);
- break;
- case 'K':
- keyboard_keypress (0x02, 0x0e);
- break;
- case 'L':
- keyboard_keypress (0x02, 0x0f);
- break;
- case 'M':
- keyboard_keypress (0x02, 0x10);
- break;
- case 'N':
- keyboard_keypress (0x02, 0x11);
- break;
- case 'O':
- keyboard_keypress (0x02, 0x12);
- break;
- case 'P':
- keyboard_keypress (0x02, 0x13);
- break;
- case 'Q':
- keyboard_keypress (0x02, 0x14);
- break;
- case 'R':
- keyboard_keypress (0x02, 0x15);
- break;
- case 'S':
- keyboard_keypress (0x02, 0x16);
- break;
- case 'T':
- keyboard_keypress (0x02, 0x17);
- break;
- case 'U':
- keyboard_keypress (0x02, 0x18);
- break;
- case 'V':
- keyboard_keypress (0x02, 0x19);
- break;
- case 'W':
- keyboard_keypress (0x02, 0x1a);
- break;
- case 'X':
- keyboard_keypress (0x02, 0x1b);
- break;
- case 'Y':
- keyboard_keypress (0x02, 0x1c);
- break;
- case 'Z':
- keyboard_keypress (0x02, 0x1d);
- break;
- case '[':
- keyboard_keypress (0x00, 0x2f);
- break;
- case '\\':
- keyboard_keypress (0x00, 0x64);
- break;
- case ']':
- keyboard_keypress (0x00, 0x30);
- break;
- case '^':
- keyboard_keypress (0x02, 0x23);
- break;
- case '_':
- keyboard_keypress (0x02, 0x2d);
- break;
- case '`':
- keyboard_keypress (0x00, 0x32);
- break;
- case 'a':
- keyboard_keypress (0x00, 0x04);
- break;
- case 'b':
- keyboard_keypress (0x00, 0x05);
- break;
- case 'c':
- keyboard_keypress (0x00, 0x06);
- break;
- case 'd':
- keyboard_keypress (0x00, 0x07);
- break;
- case 'e':
- keyboard_keypress (0x00, 0x08);
- break;
- case 'f':
- keyboard_keypress (0x00, 0x09);
- break;
- case 'g':
- keyboard_keypress (0x00, 0x0a);
- break;
- case 'h':
- keyboard_keypress (0x00, 0x0b);
- break;
- case 'i':
- keyboard_keypress (0x00, 0x0c);
- break;
- case 'j':
- keyboard_keypress (0x00, 0x0d);
- break;
- case 'k':
- keyboard_keypress (0x00, 0x0e);
- break;
- case 'l':
- keyboard_keypress (0x00, 0x0f);
- break;
- case 'm':
- keyboard_keypress (0x00, 0x10);
- break;
- case 'n':
- keyboard_keypress (0x00, 0x11);
- break;
- case 'o':
- keyboard_keypress (0x00, 0x12);
- break;
- case 'p':
- keyboard_keypress (0x00, 0x13);
- break;
- case 'q':
- keyboard_keypress (0x00, 0x14);
- break;
- case 'r':
- keyboard_keypress (0x00, 0x15);
- break;
- case 's':
- keyboard_keypress (0x00, 0x16);
- break;
- case 't':
- keyboard_keypress (0x00, 0x17);
- break;
- case 'u':
- keyboard_keypress (0x00, 0x18);
- break;
- case 'v':
- keyboard_keypress (0x00, 0x19);
- break;
- case 'w':
- keyboard_keypress (0x00, 0x1a);
- break;
- case 'x':
- keyboard_keypress (0x00, 0x1b);
- break;
- case 'y':
- keyboard_keypress (0x00, 0x1c);
- break;
- case 'z':
- keyboard_keypress (0x00, 0x1d);
- break;
- case '{':
- keyboard_keypress (0x02, 0x2f);
- break;
- case '|':
- keyboard_keypress (0x02, 0x64);
- break;
- case '}':
- keyboard_keypress (0x02, 0x30);
- break;
- case '~':
- keyboard_keypress (0x02, 0x32);
- break;
-#if 0
- case '\177':
- keyboard_keypress (0x00, 0x00);
- break;
-#endif
- }
-}
-
-void
-send_str (const char *c)
-{
- while (*c)
- send_ascii (*(c++));
-}
diff --git a/app/project.h b/app/project.h
index 6fccdc5..0b1a26d 100644
--- a/app/project.h
+++ b/app/project.h
@@ -10,7 +10,7 @@
#include <libopencm3/cm3/systick.h>
#include <libopencm3/cm3/nvic.h>
#include <libopencm3/usb/usbd.h>
-#include <libopencm3/usb/hid.h>
+#include <libopencm3/usb/cdc.h>
#include <libopencm3/cm3/cortex.h>
#include <stm32f101cb_clock.h>
#include <string.h>
diff --git a/app/prototypes.h b/app/prototypes.h
index 2e78350..c3e7426 100644
--- a/app/prototypes.h
+++ b/app/prototypes.h
@@ -13,12 +13,13 @@ extern int usb_is_suspended;
extern int usb_running;
extern void usb_tick(void);
extern int usb_wakeup_host(void);
+extern int class_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len, int (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req));
extern void usb_set_config(usbd_device *usbd_dev, uint16_t wValue);
+extern uint8_t usbd_control_buffer[128];
extern void usb_init(void);
extern void usb_run(void);
/* led.c */
extern void led_init(void);
-extern void led_blink(void);
extern void led_tick(void);
/* ticker.c */
extern volatile uint32_t ticks;
@@ -29,35 +30,8 @@ extern int timed_out(uint32_t then, unsigned int ms);
extern void ticker_init(void);
/* i2c.c */
/* lcd.c */
-/* adc.c */
-extern int host_has_power;
-extern void adc_tick(void);
-extern void adc_init(void);
-/* state.c */
-extern uint32_t up_time;
-extern uint32_t down_time;
-extern uint32_t usb_up_time;
-extern uint32_t usb_down_time;
-extern int locked;
-extern void state_show(void);
-extern void state_tick(void);
-extern void state_init(void);
-/* key.c */
-extern int have_key;
-extern void key_wipe(void);
-extern void key_set(char *in, size_t len);
-extern void key_send(void);
-extern void key_init(void);
-/* keyboard.c */
-extern const struct usb_endpoint_descriptor keyboard_endpoint;
-extern const struct usb_interface_descriptor keyboard_iface;
-extern void keyboard_get_descriptor(uint8_t **buf, uint16_t *len);
-extern void keyboard_keypress(int m, int k);
-/* crypto.c */
-extern int crypto_control(uint8_t request, uint16_t value, uint16_t index, void *buf, size_t len);
-extern int vendor_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len, int (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req));
-extern void crypto_tick(void);
-extern void crypto_poll(void);
-/* map.c */
-extern void send_ascii(unsigned char a);
-extern void send_str(const char *c);
+/* cdc.c */
+extern const struct usb_interface_descriptor comm_iface[];
+extern const struct usb_interface_descriptor data_iface[];
+extern int cdcacm_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len, int (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req));
+extern void cdcacm_data_rx_cb(usbd_device *usbd_dev, uint8_t ep);
diff --git a/app/state.c b/app/state.c
deleted file mode 100644
index eb033ac..0000000
--- a/app/state.c
+++ /dev/null
@@ -1,99 +0,0 @@
-#include "project.h"
-
-uint32_t up_time, down_time, usb_up_time, usb_down_time;
-int locked;
-
-
-
-
-void
-state_show (void)
-{
-#ifndef SLIM
- char buf[17];
- uint32_t t;
- int d, h, m, s;
-
- t = up_time ? up_time : down_time;
-
- d = t / 86400;
- t -= d * 86400;
- h = t / 3600;
- t -= h * 3600;
- m = t / 60;
- t -= m * 60;
- s = t;
-
-
- snprintf (buf, sizeof (buf), "%4s%3d %02d:%02d:%02d",
- up_time ? "up" : "down", d, h, m, s);
-
- //lcd_write (buf, 0, 0);
-
- lcd_write (have_key ? " Key " : "No Key", 0, 1);
-
- lcd_write (locked ? " Locked " : "UnLocked", 8, 1);
-#endif
-
-}
-
-
-void
-state_tick (void)
-{
-
- if (host_has_power)
- {
- down_time = 0;
- up_time++;
- }
- else
- {
- down_time++;
- up_time = 0;
- locked = 0;
- }
-
- if ((down_time > POWER_RETENTION_TIME) && have_key)
- {
- key_wipe ();
- }
-
-
- if (usb_running)
- {
- usb_down_time = 0;
- usb_up_time++;
- }
- else
- {
- usb_down_time++;
- usb_up_time = 0;
- locked = 0;
- }
-
- if ((usb_down_time > USB_RETENTION_TIME) && have_key)
- {
- key_wipe ();
- }
-
- if ((usb_up_time > USB_LOCK_TIME) && !locked)
- locked = 1;
- if ((up_time > POWER_LOCK_TIME) && !locked)
- locked = 1;
-
-
- state_show ();
-}
-
-
-void
-state_init (void)
-{
- down_time = 0;
- up_time = 0;
- usb_down_time = 0;
- usb_up_time = 0;
- up_time = 0;
- locked = 0;
-}
diff --git a/app/ticker.c b/app/ticker.c
index 6ef8a5f..84e3e9a 100644
--- a/app/ticker.c
+++ b/app/ticker.c
@@ -17,18 +17,9 @@ delay_us (uint32_t d)
}
}
-static void
-s_tick_handler (void)
-{
- adc_tick ();
- state_tick ();
- crypto_tick ();
-}
-
void
sys_tick_handler (void)
{
- static int s_count;
if (delay_ms_count)
delay_ms_count--;
@@ -36,18 +27,13 @@ sys_tick_handler (void)
ticks++;
led_tick ();
+
#ifndef SLIM
lcd_tick ();
#endif
usb_tick ();
- s_count++;
- if (s_count >= 1000)
- {
- s_count = 0;
- s_tick_handler ();
- }
}
diff --git a/app/usb.c b/app/usb.c
index 9a84389..2bd6986 100644
--- a/app/usb.c
+++ b/app/usb.c
@@ -10,7 +10,7 @@ const struct usb_device_descriptor dev = {
.bDeviceProtocol = 0,
.bMaxPacketSize0 = 64,
.idVendor = 0x1d6b,
- .idProduct = 0x1932,
+ .idProduct = 0xcad5,
.bcdDevice = 0x0200,
.iManufacturer = 1,
.iProduct = 2,
@@ -20,9 +20,13 @@ const struct usb_device_descriptor dev = {
const struct usb_interface ifaces[] = {
{
- .num_altsetting = 1,
- .altsetting = &keyboard_iface,
- },
+ .num_altsetting = 1,
+ .altsetting = comm_iface,
+ },
+ {
+ .num_altsetting = 1,
+ .altsetting = data_iface,
+},
{
.num_altsetting = 1,
.altsetting = &dfu_iface,
@@ -33,23 +37,22 @@ const struct usb_config_descriptor config = {
.bLength = USB_DT_CONFIGURATION_SIZE,
.bDescriptorType = USB_DT_CONFIGURATION,
.wTotalLength = 0,
- .bNumInterfaces = 2,
+ .bNumInterfaces = 3,
.bConfigurationValue = 1,
.iConfiguration = 4,
.bmAttributes = 0xa0,
.bMaxPower = 0x31,
-
.interface = ifaces,
};
static const char *usb_strings[] = {
- "bootpad",
- "bootpad",
- "bootpad",
+ "candlestick",
+ "candlestick",
+ "candlestick",
"composite",
- "bootpad keyboard",
- "bootpad control",
- "bootpad dfu device",
+ "usb serial 0",
+ "usb serial 1",
+ "candlestick dfu device",
};
@@ -127,6 +130,8 @@ usb_control_request (usbd_device * usbd_dev, struct usb_setup_data *req,
(void) complete;
(void) usbd_dev;
+ (void) buf;
+ (void) len;
if ((req->bmRequestType !=
@@ -134,25 +139,32 @@ usb_control_request (usbd_device * usbd_dev, struct usb_setup_data *req,
|| (req->bRequest != USB_REQ_GET_DESCRIPTOR) || (req->wValue != 0x2200))
return 0;
- switch (req->wIndex)
- {
- case 0:
- keyboard_get_descriptor (buf, len);
- return 1;
- }
-
*len = 0;
return 0;
}
+int
+class_control_request (usbd_device * usbd_dev, struct usb_setup_data *req,
+ uint8_t ** buf, uint16_t * len,
+ int (**complete) (usbd_device * usbd_dev,
+ struct usb_setup_data * req))
+{
+
+ if (cdcacm_control_request(usbd_dev,req,buf,len,complete)) return 1;
+ if (dfu_control_request(usbd_dev,req,buf,len,complete)) return 1;
+ return 0;
+}
+
void
usb_set_config (usbd_device * usbd_dev, uint16_t wValue)
{
(void) wValue;
(void) usbd_dev;
- usbd_ep_setup (usbd_dev, 0x81, USB_ENDPOINT_ATTR_INTERRUPT, 4, NULL);
+ usbd_ep_setup(usbd_dev, 0x01, USB_ENDPOINT_ATTR_BULK, 64, cdcacm_data_rx_cb);
+ usbd_ep_setup(usbd_dev, 0x82, USB_ENDPOINT_ATTR_BULK, 64, NULL);
+ usbd_ep_setup(usbd_dev, 0x83, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL);
usbd_register_control_callback (usbd_dev,
USB_REQ_TYPE_STANDARD |
@@ -163,18 +175,14 @@ usb_set_config (usbd_device * usbd_dev, uint16_t wValue)
usbd_register_control_callback (usbd_dev,
USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE,
USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
- dfu_control_request);
+ class_control_request);
- usbd_register_control_callback (usbd_dev,
- USB_REQ_TYPE_VENDOR | USB_REQ_TYPE_DEVICE,
- USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT,
- vendor_control_request);
}
/* Buffer to be used for control requests. */
-static uint8_t usbd_control_buffer[128];
+uint8_t usbd_control_buffer[128];
void
usb_init (void)
@@ -197,6 +205,5 @@ usb_run (void)
for (;;)
{
usbd_poll (usbd_dev);
- crypto_poll ();
}
}
diff --git a/board/STM32F101C8T6_BOARD.cfg b/board/STM32F103C8T6_BOARD.cfg
index 745be89..745be89 100644
--- a/board/STM32F101C8T6_BOARD.cfg
+++ b/board/STM32F103C8T6_BOARD.cfg
diff --git a/boot/usbdfu.c b/boot/usbdfu.c
index 400fc7c..1898fc3 100644
--- a/boot/usbdfu.c
+++ b/boot/usbdfu.c
@@ -57,7 +57,7 @@ const struct usb_device_descriptor dev = {
.bDeviceProtocol = 0,
.bMaxPacketSize0 = 64,
.idVendor = 0x1d6b,
- .idProduct = 0x1932,
+ .idProduct = 0xcad5,
.bcdDevice = 0x0200,
.iManufacturer = 1,
.iProduct = 2,
@@ -111,9 +111,9 @@ const struct usb_config_descriptor config = {
};
static const char *usb_strings[] = {
- "bootpad",
- "bootpad",
- "bootpad",
+ "candlestick",
+ "candlestick",
+ "candlestick",
/* This string is used by ST Microelectronics' DfuSe utility. */
"@Internal Flash /0x08000000/8*001Ka,56*001Kg",
};
diff --git a/boot/usbdfu.ld b/boot/usbdfu.ld
index 8680dc9..d8ea622 100644
--- a/boot/usbdfu.ld
+++ b/boot/usbdfu.ld
@@ -17,12 +17,10 @@
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
-/* Linker script for Olimex STM32-H103 (STM32F103RBT6, 128K flash, 20K RAM). */
-
/* Define memory regions. */
MEMORY
{
- rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K
+ rom (rx) : ORIGIN = 0x08000000, LENGTH = 64K
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K
}
diff --git a/host/Makefile b/host/Makefile
deleted file mode 100644
index 2013f89..0000000
--- a/host/Makefile
+++ /dev/null
@@ -1,23 +0,0 @@
-INCLUDES=$(shell pkg-config --cflags libusb-1.0)
-LIBS=-Bstatic $(shell pkg-config --libs libusb-1.0) -lpthread -Bdynamic -ludev
-
-LDFLAGS=-s
-PROG=cryptopad
-SRCS=hexdump.c cryptopad.c
-
-OBJS=${SRCS:%.c=%.o}
-
-CFLAGS=${OPT}
-CPPFLAGS=${INCLUDES} ${DEFINES}
-
-default:${PROG}
-
-
-${PROG}:${OBJS}
- ${CC} ${CPPFLAGS} ${CFLAGS} ${LDFLAGS} -o $@ ${OBJS} ${LIBS}
-
-install: ${PROG}
- install -c -m 755 ${PROG} /sbin/${PROG}
-clean:
- /bin/rm -f *~ *.d ${PROG} ${OBJS}
-
diff --git a/host/cryptopad.c b/host/cryptopad.c
deleted file mode 100644
index 42b1d36..0000000
--- a/host/cryptopad.c
+++ /dev/null
@@ -1,122 +0,0 @@
-#include "project.h"
-#include "../common/vendor_req.h"
-
-#define TIMEOUT 4000
-
-struct libusb_device * find_device(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;
-
- return dev;
-
- }
- libusb_free_device_list(list, 0);
-
- return NULL;
-}
-
-
-static void usage(char *n)
-{
-fprintf(stderr,"Usage:\n"
- "%s [-g [-n secs]] [-s [-p pwd]] [-h]\n"
- " -h display this message\n"
- " -g ask cryptopad to type password\n"
- " -n secs wait secs before typing password\n"
- " -s set password in cryptopad\n"
- " -p pwd password to set, prompts otherwise\n"
- " -w wipe password from cryptopad\n",
- n);
-
-exit(1);
-}
-
-
-
-
-int main(int argc,char *argv[])
-{
- libusb_context *ctx;
- libusb_device *dev;
- libusb_device_handle *devh;
- int wflag=0,gflag=0,sflag=0;
- char *pass=NULL;
- int c,ret;
- int delay=0;
-
-
- while((c=getopt(argc,argv,"hwgsp:n:"))!=-1) {
- switch(c) {
- case 'n':
- if (optarg) delay=atoi(optarg);
- break;
- case 'g':
- gflag++;
- break;
- case 's':
- sflag++;
- break;
- case 'w':
- wflag++;
- break;
- case 'p':
- pass=optarg;
- break;
- default:
- usage(argv[0]);
- }
- }
-
- if ((ret=libusb_init(&ctx)))
- errx(EX_IOERR, "unable to initialize libusb: %i", ret);
-
- dev=find_device(ctx);
-
- if (!dev) err(1,"no cryptopad found");
-
- if ((ret=libusb_open(dev, &devh))) err(1,"unable to open usb device: %i",ret);
-
-
- if (sflag) {
- char *pwd;
- if (!pass) pass=getpass("Enter password:");
-
- pwd=malloc(strlen(pass)+2);
- strcpy(pwd,pass);
- strcat(pwd,"\n");
-
- libusb_control_transfer( devh, LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE, VENDOR_REQ_SET_KEY, 0, 0, pwd, strlen(pwd), TIMEOUT );
- }
-
-
- if (gflag)
- libusb_control_transfer( devh, LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE, VENDOR_REQ_SEND_KEY, delay, 0, NULL, 0, TIMEOUT );
-
- if (wflag)
- libusb_control_transfer( devh, LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE, VENDOR_REQ_CLEAR_KEY, 0, 0, NULL, 0, TIMEOUT );
-
-
- libusb_close(devh);
-
- return 0;
-}
-
-
-
-
-
-
diff --git a/host/hexdump.c b/host/hexdump.c
deleted file mode 100644
index 127faab..0000000
--- a/host/hexdump.c
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * 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/project.h b/host/project.h
deleted file mode 100644
index cf932b6..0000000
--- a/host/project.h
+++ /dev/null
@@ -1,39 +0,0 @@
-#include <libusb.h>
-#include <stdio.h>
-#include <malloc.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <libusb.h>
-#include <stdarg.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 */
-
-