summaryrefslogtreecommitdiffstats
path: root/app/crypto.c
diff options
context:
space:
mode:
authorroot <root@new-selene.erebei.org>2015-12-01 10:51:56 +0000
committerroot <root@new-selene.erebei.org>2015-12-01 10:51:56 +0000
commitbc832d6d342922a828aebb997d1d9c6626898487 (patch)
tree655249961aa9abdc64e9a0227ddb0d114d4b7fd5 /app/crypto.c
parent15f6f34fe239b0b71cb2ef4fd16f278a23b52506 (diff)
downloadcandlestick-bc832d6d342922a828aebb997d1d9c6626898487.tar.gz
candlestick-bc832d6d342922a828aebb997d1d9c6626898487.tar.bz2
candlestick-bc832d6d342922a828aebb997d1d9c6626898487.zip
fish
Diffstat (limited to 'app/crypto.c')
-rw-r--r--app/crypto.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/app/crypto.c b/app/crypto.c
index 494e5ab..a725def 100644
--- a/app/crypto.c
+++ b/app/crypto.c
@@ -2,6 +2,9 @@
#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)
@@ -18,10 +21,15 @@ crypto_control (uint8_t request, uint16_t value, uint16_t index, void *buf,
send_ascii (value);
return 1;
case VENDOR_REQ_SET_KEY:
+ state_init ();
key_set (buf, len);
return 1;
case VENDOR_REQ_SEND_KEY:
- key_send ();
+
+ if (!value)
+ start_key_send = 1;
+ else
+ key_send_timer = value;
return 1;
case VENDOR_REQ_CLEAR_KEY:
key_wipe ();
@@ -46,3 +54,24 @@ vendor_control_request (usbd_device * usbd_dev, struct usb_setup_data *req,
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 ();
+ }
+}