Skip to content

Commit

Permalink
Merge pull request #17753 from fjmolinas/pr_fido2_all_ztimer
Browse files Browse the repository at this point in the history
sys/fido2: use ztimer instead of xtimer
  • Loading branch information
fjmolinas committed Mar 10, 2022
2 parents 9896071 + 8e34227 commit 8fa2687
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 20 deletions.
3 changes: 2 additions & 1 deletion sys/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,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
Expand All @@ -900,7 +901,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
Expand Down
2 changes: 1 addition & 1 deletion sys/fido2/ctap/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions sys/fido2/ctap/transport/ctap_transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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

Expand Down
2 changes: 2 additions & 0 deletions sys/fido2/ctap/transport/hid/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
23 changes: 12 additions & 11 deletions sys/fido2/ctap/transport/hid/ctap_hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
Expand All @@ -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;
}

Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
Expand Down
7 changes: 3 additions & 4 deletions sys/include/fido2/ctap/transport/hid/ctap_hid.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 8fa2687

Please sign in to comment.