diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/demo.c | 16 | ||||
-rw-r--r-- | src/noise.c | 9 | ||||
-rw-r--r-- | src/packet_interface.h | 1 |
3 files changed, 21 insertions, 5 deletions
@@ -61,8 +61,8 @@ static uint8_t remote_key_reference[CURVE25519_KEY_LEN]; void _fini(void);
-static inline void delay_ms_busy_loop(uint32_t ms) {
- for (volatile uint32_t i = 0; i < 14903*ms; i++);
+static inline void delay(uint32_t n) {
+ for (volatile uint32_t i = 0; i < 1490*n; i++);
}
@@ -414,10 +414,16 @@ int main(void) if (generate_identity_key(&noise_state))
LOG_PRINTF("Error generating identiy key\n");
+ int poll_ctr = 0;
while (23) {
- TRACING_SET(TR_USBH_POLL);
- usbh_poll(tim6_get_time_us());
- TRACING_CLEAR(TR_USBH_POLL);
+ delay(1);
+
+ if (++poll_ctr == 10) {
+ poll_ctr = 0;
+ TRACING_SET(TR_USBH_POLL);
+ usbh_poll(tim6_get_time_us());
+ TRACING_CLEAR(TR_USBH_POLL);
+ }
TRACING_SET(TR_HOST_PKT_HANDLER);
if (host_packet_length > 0) {
diff --git a/src/noise.c b/src/noise.c index 9f898dd..a30d338 100644 --- a/src/noise.c +++ b/src/noise.c @@ -147,9 +147,18 @@ int try_continue_noise_handshake(struct NoiseState *st, uint8_t *buf, size_t len HANDLE_NOISE_ERROR(noise_dhstate_get_public_key(remote_dh, st->remote_key, sizeof(st->remote_key)), "getting remote pubkey"); if (!memcmp(st->remote_key, st->remote_key_reference, sizeof(st->remote_key))) { /* keys match */ + uint8_t response = REPORT_PAIRING_SUCCESS; + if (send_encrypted_message(st, &response, sizeof(response))) + LOG_PRINTF("Error sending pairing response packet\n"); + uninit_handshake(st, HANDSHAKE_DONE_KNOWN_HOST); st->failed_handshakes = 0; + } else { /* keys don't match */ + uint8_t response = REPORT_PAIRING_START; + if (send_encrypted_message(st, &response, sizeof(response))) + LOG_PRINTF("Error sending pairing response packet\n"); + uninit_handshake(st, HANDSHAKE_DONE_UNKNOWN_HOST); st->failed_handshakes++; } diff --git a/src/packet_interface.h b/src/packet_interface.h index 0502325..4d1be07 100644 --- a/src/packet_interface.h +++ b/src/packet_interface.h @@ -23,6 +23,7 @@ enum packet_types { REPORT_PAIRING_INPUT = 3, REPORT_PAIRING_SUCCESS = 4, REPORT_PAIRING_ERROR = 5, + REPORT_PAIRING_START = 6, }; struct hid_report_packet { |