From b55240eb43a92c552003b8b324a385e041f84f12 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 1 Dec 2015 02:10:53 +0000 Subject: fish --- app/crypto.c | 144 ++++++++++++++++------------------------------------------- 1 file changed, 38 insertions(+), 106 deletions(-) (limited to 'app/crypto.c') diff --git a/app/crypto.c b/app/crypto.c index 4a0098d..494e5ab 100644 --- a/app/crypto.c +++ b/app/crypto.c @@ -1,116 +1,48 @@ #include "project.h" +#include "../common/vendor_req.h" -static const uint8_t crypto_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)) crypto_function = +int +crypto_control (uint8_t request, uint16_t value, uint16_t index, void *buf, + size_t len) { - .hid_descriptor = - { - .bLength = sizeof (crypto_function),.bDescriptorType = - USB_DT_HID,.bcdHID = 0x0100,.bCountryCode = 0,.bNumDescriptors = 1,} - ,.hid_report = - { - .bReportDescriptorType = USB_DT_REPORT,.wDescriptorLength = - sizeof (crypto_report_descriptor),} -,}; - -const struct usb_endpoint_descriptor crypto_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 crypto_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, /* crypto */ - .iInterface = 5, - .endpoint = &crypto_endpoint, - .extra = &crypto_function, - .extralen = sizeof (crypto_function), -}; - - -void -crypto_get_descriptor (uint8_t ** buf, uint16_t * len) -{ - - /* Handle the HID report descriptor. */ - *buf = (uint8_t *) crypto_report_descriptor; - *len = sizeof (crypto_report_descriptor); + (void) index; + (void) buf; + (void) len; + + + switch (request) + { + + case VENDOR_REQ_KEYPRESS: + send_ascii (value); + return 1; + case VENDOR_REQ_SET_KEY: + key_set (buf, len); + return 1; + case VENDOR_REQ_SEND_KEY: + key_send (); + return 1; + case VENDOR_REQ_CLEAR_KEY: + key_wipe (); + return 1; + } + + return 0; } -void -crypto_test (void) +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)) { - static int c = 0; - uint8_t buf[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - - - buf[0] = (c >> 1) & 7; - - buf[2] = (c & 1) ? 12 : 0; + (void) usbd_dev; + (void) complete; - c++; + if (req->bmRequestType != + (USB_REQ_TYPE_OUT | USB_REQ_TYPE_VENDOR | USB_REQ_TYPE_DEVICE)) + return 0; - usbd_ep_write_packet (usbd_dev, 0x81, buf, 9); + return crypto_control (req->bRequest, req->wValue, req->wIndex, *buf, *len); } -- cgit v1.2.3