summaryrefslogtreecommitdiff
path: root/src/reset.c
blob: 4b2c88a0915fd9a446016d24867383348494b9d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
 * Copyright (c) 2018 Yubico AB. All rights reserved.
 * Use of this source code is governed by a BSD-style
 * license that can be found in the LICENSE file.
 */

#include <stdlib.h>
#include "fido.h"

static int
fido_dev_reset_tx(fido_dev_t *dev)
{
	const unsigned char	cbor[] = { CTAP_CBOR_RESET };
	const uint8_t		cmd = CTAP_FRAME_INIT | CTAP_CMD_CBOR;

	if (fido_tx(dev, cmd, cbor, sizeof(cbor)) < 0) {
		fido_log_debug("%s: fido_tx", __func__);
		return (FIDO_ERR_TX);
	}

	return (FIDO_OK);
}

static int
fido_dev_reset_wait(fido_dev_t *dev, int ms)
{
	int r;

	if ((r = fido_dev_reset_tx(dev)) != FIDO_OK ||
	    (r = fido_rx_cbor_status(dev, ms)) != FIDO_OK)
		return (r);

	return (FIDO_OK);
}

int
fido_dev_reset(fido_dev_t *dev)
{
	return (fido_dev_reset_wait(dev, -1));
}