summaryrefslogtreecommitdiffstats
path: root/app/crypto.c
diff options
context:
space:
mode:
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 ();
+ }
+}