diff --git a/ctap_test.py b/ctap_test.py index 935f33b..6c5a5ca 100644 --- a/ctap_test.py +++ b/ctap_test.py @@ -80,7 +80,6 @@ class Tester(): raise RuntimeError('Cbor is supposed to have payload') except CtapError as e: assert(e.code == CtapError.ERR.INVALID_LENGTH) - pass print('PASS: no data cbor') try: @@ -88,9 +87,15 @@ class Tester(): raise RuntimeError('MSG is supposed to have payload') except CtapError as e: assert(e.code == CtapError.ERR.INVALID_LENGTH) - pass print('PASS: no data msg') + try: + r = self.send_data(CTAPHID.INIT, '') + except CtapError as e: + print('resync fail: ', e) + return + print('PASS: resync') + diff --git a/ctaphid.c b/ctaphid.c index a9f63b0..0b707dc 100644 --- a/ctaphid.c +++ b/ctaphid.c @@ -94,7 +94,7 @@ static int is_broadcast(CTAPHID_PACKET * pkt) static int is_init_pkt(CTAPHID_PACKET * pkt) { - return (pkt->pkt.init.cmd == CTAPHID_INIT) && ctaphid_packet_len(pkt) == 8; + return (pkt->pkt.init.cmd == CTAPHID_INIT); } static int is_cont_pkt(CTAPHID_PACKET * pkt) @@ -294,10 +294,19 @@ start_over: if (is_init_pkt(pkt)) { printf("received abort request from %08x\n", pkt->cid); + ctaphid_write_buffer_init(&wb); + + wb.cid = active_cid; + active_cid_timestamp = millis(); - set_next_cid(active_cid); // reuse last CID in current channel ctaphid_init(); - buffer_packet(pkt); + + active_cid = wb.cid; + wb.cmd = CTAPHID_INIT; + wb.bcnt = 0; + ctaphid_write(&wb, ctap_buffer, buffer_len()); + ctaphid_write(&wb, NULL, 0); + return; } else if (!is_cont_pkt(pkt) && buffer_status() == BUFFERING) {