diff options
Diffstat (limited to 'src/reset.c')
-rw-r--r-- | src/reset.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/reset.c b/src/reset.c new file mode 100644 index 0000000..4b2c88a --- /dev/null +++ b/src/reset.c | |||
@@ -0,0 +1,40 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2018 Yubico AB. All rights reserved. | ||
3 | * Use of this source code is governed by a BSD-style | ||
4 | * license that can be found in the LICENSE file. | ||
5 | */ | ||
6 | |||
7 | #include <stdlib.h> | ||
8 | #include "fido.h" | ||
9 | |||
10 | static int | ||
11 | fido_dev_reset_tx(fido_dev_t *dev) | ||
12 | { | ||
13 | const unsigned char cbor[] = { CTAP_CBOR_RESET }; | ||
14 | const uint8_t cmd = CTAP_FRAME_INIT | CTAP_CMD_CBOR; | ||
15 | |||
16 | if (fido_tx(dev, cmd, cbor, sizeof(cbor)) < 0) { | ||
17 | fido_log_debug("%s: fido_tx", __func__); | ||
18 | return (FIDO_ERR_TX); | ||
19 | } | ||
20 | |||
21 | return (FIDO_OK); | ||
22 | } | ||
23 | |||
24 | static int | ||
25 | fido_dev_reset_wait(fido_dev_t *dev, int ms) | ||
26 | { | ||
27 | int r; | ||
28 | |||
29 | if ((r = fido_dev_reset_tx(dev)) != FIDO_OK || | ||
30 | (r = fido_rx_cbor_status(dev, ms)) != FIDO_OK) | ||
31 | return (r); | ||
32 | |||
33 | return (FIDO_OK); | ||
34 | } | ||
35 | |||
36 | int | ||
37 | fido_dev_reset(fido_dev_t *dev) | ||
38 | { | ||
39 | return (fido_dev_reset_wait(dev, -1)); | ||
40 | } | ||