From e16515bb643b9329318809ecc134f74c22a86382 Mon Sep 17 00:00:00 2001 From: jaseg Date: Tue, 13 Nov 2018 21:45:24 +0900 Subject: Pairing and passthrough mostly working, except it's too slow --- src/demo.c | 34 ++++++++++++++++++++++++++-------- src/packet_interface.c | 3 ++- 2 files changed, 28 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/demo.c b/src/demo.c index 49157e9..c176f25 100644 --- a/src/demo.c +++ b/src/demo.c @@ -144,14 +144,36 @@ int pairing_check(struct NoiseState *st, const char *buf) { const char *p = buf; int idx = 0; do { + /* Skip over most special chars */ + while (*p) { + char c = *p; + if ('0' <= c && c <= '9') break; + if ('a' <= c && c <= 'z') break; + if ('A' <= c && c <= 'Z') break; + if (c == '-') break; + p++; + } + const char *found = strchr(p, ' '); size_t plen = found ? (size_t)(found - p) : strlen(p); /* p >= found */ + while (plen > 0) { + char c = p[plen]; + if ('0' <= c && c <= '9') break; + if ('a' <= c && c <= 'z') break; + if ('A' <= c && c <= 'Z') break; + if (c == '-') break; + plen--; + } + plen++; + //LOG_PRINTF("matching: \"%s\" - \"%s\" %d\n", p, p+plen, plen); + if (strncasecmp(p, "and", plen)) { /* ignore "and" */ int num = -1; /* FIXME ignore "and", ignore commata and dots */ for (int i=0; i<256; i++) { - if ((!strncasecmp(p, adjectives[i], plen)) || (!strncasecmp(p, nouns[i], plen))) { + if ((!strncasecmp(p, adjectives[i], plen) && plen == strlen(adjectives[i])) + || (!strncasecmp(p, nouns[i], plen) && plen == strlen(nouns[i] ))) { //LOG_PRINTF(" idx=%02d h=%02x i=%02x adj=%s n=%s plen=%d s=%s\n", idx, st->handshake_hash[idx], i, adjectives[i], nouns[i], plen, p); num = i; break; @@ -218,12 +240,8 @@ void pairing_input(uint8_t modbyte, uint8_t keycode) { for (size_t i=0; keycode_mapping[i].kc != KEY_NONE; i++) { if (keycode_mapping[i].kc == keycode) { ch = keycode_mapping[i].ch[level]; - if (!(('a' <= ch && ch <= 'z') || - ('A' <= ch && ch <= 'Z') || - ('0' <= ch && ch <= '9') || - (ch == ' ') || - (ch == '-'))) - break; /* ignore special chars */ + if (!ch) + break; if (pairing_buf_pos < sizeof(pairing_buf)-1) /* allow for terminating null byte */ { pairing_buf[pairing_buf_pos++] = ch; @@ -242,7 +260,7 @@ void pairing_input(uint8_t modbyte, uint8_t keycode) { } if (ch) { - LOG_PRINTF("Input: %s\n", pairing_buf); + //LOG_PRINTF("Input: %s\n", pairing_buf); struct hid_report_packet pkt = { .type = REPORT_PAIRING_INPUT, .pairing_input = { .c = ch } diff --git a/src/packet_interface.c b/src/packet_interface.c index 9c0ea5c..319ddd1 100644 --- a/src/packet_interface.c +++ b/src/packet_interface.c @@ -25,10 +25,11 @@ struct dma_usart_file usart2_out_s = { struct dma_usart_file *usart2_out = &usart2_out_s; void dma1_stream6_isr(void) { + static unsigned int fifo_errors = 0; /* debug */ if (dma_get_interrupt_flag(usart2_out->dma, usart2_out->stream, DMA_FEIF)) { /* Ignore FIFO errors as they're 100% non-critical for UART applications */ dma_clear_interrupt_flags(usart2_out->dma, usart2_out->stream, DMA_FEIF); - LOG_PRINTF("USART2 DMA FIFO error\n"); + fifo_errors++; return; } -- cgit