1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

sys/fido2: use ztimer instead of xtimer

- for ctap hid timeouts xtimer was used, use ztimer64_msec instead
  since the code is using absolute times, an already using ztimer_msec
- use event_timeout_ztimer instead of event_timeout to not pull in
  xtimer
This commit is contained in:
Francisco Molina 2022-03-04 16:57:20 +01:00
parent 5bf52118ba
commit 8e3422781d
6 changed files with 24 additions and 20 deletions

View File

@ -874,6 +874,7 @@ ifneq (,$(filter fido2_ctap_%,$(USEMODULE)))
USEMODULE += fido2_ctap_transport
USEMODULE += fido2_ctap
ifneq (,$(filter fido2_ctap_transport_hid,$(USEMODULE)))
USEMODULE += ztimer64_msec
USEMODULE += usbus_hid
DISABLE_MODULE += auto_init_usbus
endif
@ -891,7 +892,7 @@ ifneq (,$(filter fido2_ctap,$(USEMODULE)))
USEMODULE += mtd_write_page
USEMODULE += ztimer_msec
USEMODULE += event
USEMODULE += event_timeout
USEMODULE += event_timeout_ztimer
USEMODULE += cipher_modes
USEMODULE += crypto_aes_256
USEMODULE += hashes

View File

@ -17,7 +17,7 @@ menuconfig MODULE_FIDO2_CTAP
select MODULE_PERIPH_GPIO
select MODULE_PERIPH_GPIO_IRQ
select MODULE_EVENT
select MODULE_EVENT_TIMEOUT
select MODULE_EVENT_TIMEOUT_ZTIMER
select MODULE_ZTIMER
select MODULE_ZTIMER_MSEC
select MODULE_MTD

View File

@ -69,8 +69,9 @@ static void *_event_loop(void *arg)
event_queue_init(&_queue);
#if IS_USED(MODULE_FIDO2_CTAP_TRANSPORT_HID)
event_timeout_init(&_ctap_hid_event_timeout, &_queue, &_ctap_hid_timeout_event);
event_timeout_set(&_ctap_hid_event_timeout, CTAP_HID_TRANSACTION_TIMEOUT);
event_timeout_ztimer_init(&_ctap_hid_event_timeout, ZTIMER_MSEC, &_queue,
&_ctap_hid_timeout_event);
event_timeout_set(&_ctap_hid_event_timeout, CTAP_HID_TRANSACTION_TIMEOUT_MS);
#endif
event_loop(&_queue);
@ -83,7 +84,7 @@ static void _ctap_hid_timeout_cb(event_t *arg)
{
(void)arg;
fido2_ctap_transport_hid_check_timeouts();
event_timeout_set(&_ctap_hid_event_timeout, CTAP_HID_TRANSACTION_TIMEOUT);
event_timeout_set(&_ctap_hid_event_timeout, CTAP_HID_TRANSACTION_TIMEOUT_MS);
}
#endif

View File

@ -10,6 +10,8 @@ menuconfig MODULE_FIDO2_CTAP_TRANSPORT_HID
depends on TEST_KCONFIG
select MODULE_ISRPIPE
select MODULE_USBUS_HID
select MODULE_ZTIMER64
select MODULE_ZTIMER64_MSEC
help
Configure a FIDO2 CTAP authenticator via KConfig.

View File

@ -17,7 +17,8 @@
#include <string.h>
#include "xtimer.h"
#include "ztimer.h"
#include "ztimer64.h"
#include "usb/usbus.h"
#include "usb/usbus/hid.h"
#include "usb/usbus/hid_io.h"
@ -528,12 +529,12 @@ bool fido2_ctap_transport_hid_should_cancel(void)
void fido2_ctap_transport_hid_check_timeouts(void)
{
uint64_t now = xtimer_now_usec64();
uint64_t now = ztimer64_now(ZTIMER64_MSEC);
for (uint8_t i = 0; i < CTAP_HID_CIDS_MAX; i++) {
/* transaction timed out because cont packets didn't arrive in time */
if (_is_busy && g_cids[i].taken &&
(now - g_cids[i].last_used) >= CTAP_HID_TRANSACTION_TIMEOUT &&
(now - g_cids[i].last_used) >= CTAP_HID_TRANSACTION_TIMEOUT_MS &&
_state.cid == g_cids[i].cid && !_state.is_locked) {
_send_error_response(g_cids[i].cid, CTAP_HID_ERR_MSG_TIMEOUT);
@ -547,14 +548,14 @@ void fido2_ctap_transport_hid_check_timeouts(void)
static int8_t _add_cid(uint32_t cid)
{
uint64_t oldest = xtimer_now_usec64();
uint64_t oldest = ztimer64_now(ZTIMER64_MSEC);
int8_t index_oldest = -1;
for (int i = 0; i < CTAP_HID_CIDS_MAX; i++) {
if (!g_cids[i].taken) {
g_cids[i].taken = true;
g_cids[i].cid = cid;
g_cids[i].last_used = xtimer_now_usec64();
g_cids[i].last_used = ztimer64_now(ZTIMER64_MSEC);
return CTAP_HID_OK;
}
@ -569,7 +570,7 @@ static int8_t _add_cid(uint32_t cid)
if (index_oldest > -1) {
g_cids[index_oldest].taken = true;
g_cids[index_oldest].cid = cid;
g_cids[index_oldest].last_used = xtimer_now_usec64();
g_cids[index_oldest].last_used = ztimer64_now(ZTIMER64_MSEC);
return CTAP_HID_OK;
}
@ -580,7 +581,7 @@ static int8_t _refresh_cid(uint32_t cid)
{
for (int i = 0; i < CTAP_HID_CIDS_MAX; i++) {
if (g_cids[i].cid == cid) {
g_cids[i].last_used = xtimer_now_usec64();
g_cids[i].last_used = ztimer64_now(ZTIMER64_MSEC);
return CTAP_HID_OK;
}
}
@ -622,19 +623,19 @@ static void _wink(uint32_t cid, uint8_t cmd)
for (int i = 1; i <= 8; i++) {
#ifdef LED0_TOGGLE
LED0_TOGGLE;
xtimer_msleep(delay);
ztimer_sleep(ZTIMER_MSEC, delay);
#endif
#ifdef LED1_TOGGLE
LED1_TOGGLE;
xtimer_msleep(delay);
ztimer_sleep(ZTIMER_MSEC, delay);
#endif
#ifdef LED2_TOGGLE
LED2_TOGGLE;
xtimer_msleep(delay);
ztimer_sleep(ZTIMER_MSEC, delay);
#endif
#ifdef LED3_TOGGLE
LED3_TOGGLE;
xtimer_msleep(delay);
ztimer_sleep(ZTIMER_MSEC, delay);
#endif
delay /= 2;
}

View File

@ -62,10 +62,9 @@ extern "C" {
* @brief CTAP_HID transaction timeout in microseconds
*/
#ifdef CONFIG_FIDO2_CTAP_TRANSPORT_HID_TRANSACTION_TIMEOUT
#define CTAP_HID_TRANSACTION_TIMEOUT (CONFIG_FIDO2_CTAP_TRANSPORT_HID_TRANSACTION_TIMEOUT * \
US_PER_MS)
#define CTAP_HID_TRANSACTION_TIMEOUT_MS (CONFIG_FIDO2_CTAP_TRANSPORT_HID_TRANSACTION_TIMEOUT)
#else
#define CTAP_HID_TRANSACTION_TIMEOUT (500 * US_PER_MS)
#define CTAP_HID_TRANSACTION_TIMEOUT_MS (500)
#endif
/**
@ -237,7 +236,7 @@ void fido2_ctap_transport_hid_handle_packet(void *pkt_raw);
*
* CTAP specification (version 20190130) section 5.6
*
* @ref CTAP_HID_TRANSACTION_TIMEOUT
* @ref CTAP_HID_TRANSACTION_TIMEOUT_MS
*/
void fido2_ctap_transport_hid_check_timeouts(void);