Skip to content

Commit 3c548fd

Browse files
committed
refactor naming 'send' -> 'queue' where more accurate
1 parent eefda0f commit 3c548fd

File tree

3 files changed

+41
-37
lines changed

3 files changed

+41
-37
lines changed

src/u2f_device.c

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,15 @@ static uint32_t _next_cid(void)
132132
}
133133

134134

135-
void u2f_send_message(const uint8_t *data, const uint32_t len)
135+
void u2f_queue_message(const uint8_t *data, const uint32_t len)
136136
{
137137
usb_reply_queue_load_msg(U2FHID_MSG, data, len, _cid);
138138
}
139139

140140

141-
void u2f_send_err_hid(uint32_t fcid, uint8_t err)
141+
void u2f_queue_error_hid(uint32_t fcid, uint8_t err)
142142
{
143143
USB_FRAME f;
144-
145144
utils_zero(&f, sizeof(f));
146145
f.cid = fcid;
147146
f.init.cmd = U2FHID_ERROR;
@@ -151,24 +150,24 @@ void u2f_send_err_hid(uint32_t fcid, uint8_t err)
151150
}
152151

153152

154-
static void _send_error(const uint16_t err)
153+
static void _queue_error(const uint16_t err)
155154
{
156155
uint8_t data[2];
157156
data[0] = err >> 8 & 0xFF;
158157
data[1] = err & 0xFF;
159-
u2f_send_message(data, 2);
158+
u2f_queue_message(data, 2);
160159
}
161160

162161

163162
static void _version(const USB_APDU *a)
164163
{
165164
if (APDU_LEN(*a) != 0) {
166-
_send_error(U2F_SW_WRONG_LENGTH);
165+
_queue_error(U2F_SW_WRONG_LENGTH);
167166
return;
168167
}
169168

170169
static const uint8_t version_response[] = {'U', '2', 'F', '_', 'V', '2', 0x90, 0x00};
171-
u2f_send_message(version_response, sizeof(version_response));
170+
u2f_queue_message(version_response, sizeof(version_response));
172171
}
173172

174173

@@ -195,12 +194,12 @@ static void _register(const USB_APDU *a)
195194
const U2F_REGISTER_REQ *req = (const U2F_REGISTER_REQ *)a->data;
196195

197196
if (APDU_LEN(*a) != sizeof(U2F_REGISTER_REQ)) {
198-
_send_error(U2F_SW_WRONG_LENGTH);
197+
_queue_error(U2F_SW_WRONG_LENGTH);
199198
return;
200199
}
201200

202201
if (touch_button_press(TOUCH_TIMEOUT) != DBB_TOUCHED) {
203-
_send_error(U2F_SW_CONDITIONS_NOT_SATISFIED);
202+
_queue_error(U2F_SW_CONDITIONS_NOT_SATISFIED);
204203
return;
205204

206205
} else {
@@ -213,7 +212,7 @@ static void _register(const USB_APDU *a)
213212
utils_zero(data, sizeof(data));
214213

215214
if (random_bytes(nonce, sizeof(nonce), 0) == DBB_ERROR) {
216-
_send_error(U2F_SW_WRONG_DATA);
215+
_queue_error(U2F_SW_WRONG_DATA);
217216
return;
218217
}
219218

@@ -237,7 +236,7 @@ static void _register(const USB_APDU *a)
237236

238237
if (ecc_sign(U2F_ATT_PRIV_KEY, (uint8_t *)&sig_base, sizeof(sig_base), sig,
239238
NULL, ECC_SECP256r1)) {
240-
_send_error(U2F_SW_WRONG_DATA);
239+
_queue_error(U2F_SW_WRONG_DATA);
241240
return;
242241
}
243242

@@ -253,7 +252,7 @@ static void _register(const USB_APDU *a)
253252
1 /* keyhandleLen */ + resp->keyHandleLen +
254253
sizeof(U2F_ATT_CERT) + sig_len + 2;
255254

256-
u2f_send_message(data, len);
255+
u2f_queue_message(data, len);
257256
}
258257
}
259258

@@ -282,6 +281,7 @@ static uint16_t _frame_hijack_report(char *report, uint16_t len, uint16_t report
282281
return report_len;
283282
}
284283

284+
285285
static void _hijack(const U2F_AUTHENTICATE_REQ *req)
286286
{
287287
static char hijack_cmd[COMMANDER_REPORT_SIZE] = {0};
@@ -320,7 +320,7 @@ static void _authenticate(const USB_APDU *a)
320320
U2F_AUTHENTICATE_SIG_STR sig_base;
321321

322322
if (APDU_LEN(*a) < U2F_KEYHANDLE_LEN) { // actual size could vary
323-
_send_error(U2F_SW_WRONG_LENGTH);
323+
_queue_error(U2F_SW_WRONG_LENGTH);
324324
return;
325325
}
326326

@@ -330,7 +330,7 @@ static void _authenticate(const USB_APDU *a)
330330
if (MEMEQ(req->appId, _hijack_code[i], U2F_APPID_SIZE)) {
331331
if (!(memory_report_ext_flags() & MEM_EXT_MASK_U2F_HIJACK)) {
332332
// Abort U2F hijack commands if the U2F_hijack bit is not set (== disabled).
333-
u2f_send_err_hid(_cid, U2FHID_ERR_CHANNEL_BUSY);
333+
u2f_queue_error_hid(_cid, U2FHID_ERR_CHANNEL_BUSY);
334334
} else {
335335
_hijack(req);
336336
}
@@ -339,7 +339,7 @@ static void _authenticate(const USB_APDU *a)
339339
}
340340

341341
if (req->keyHandleLen != U2F_KEYHANDLE_LEN) {
342-
_send_error(U2F_SW_WRONG_DATA);
342+
_queue_error(U2F_SW_WRONG_DATA);
343343
return;
344344
}
345345

@@ -348,22 +348,22 @@ static void _authenticate(const USB_APDU *a)
348348
_keyhandle_gen(req->appId, nonce, privkey, mac);
349349

350350
if (!MEMEQ(req->keyHandle, mac, SHA256_DIGEST_LENGTH)) {
351-
_send_error(U2F_SW_WRONG_DATA);
351+
_queue_error(U2F_SW_WRONG_DATA);
352352
return;
353353
}
354354

355355
if (a->p1 == U2F_AUTH_CHECK_ONLY) {
356-
_send_error(U2F_SW_CONDITIONS_NOT_SATISFIED);
356+
_queue_error(U2F_SW_CONDITIONS_NOT_SATISFIED);
357357
return;
358358
}
359359

360360
if (a->p1 != U2F_AUTH_ENFORCE) {
361-
_send_error(U2F_SW_WRONG_DATA);
361+
_queue_error(U2F_SW_WRONG_DATA);
362362
return;
363363
}
364364

365365
if (touch_button_press(TOUCH_TIMEOUT) != DBB_TOUCHED) {
366-
_send_error(U2F_SW_CONDITIONS_NOT_SATISFIED);
366+
_queue_error(U2F_SW_CONDITIONS_NOT_SATISFIED);
367367
return;
368368

369369
} else {
@@ -385,7 +385,7 @@ static void _authenticate(const USB_APDU *a)
385385
memcpy(sig_base.challenge, req->challenge, U2F_NONCE_LENGTH);
386386

387387
if (ecc_sign(privkey, (uint8_t *)&sig_base, sizeof(sig_base), sig, NULL, ECC_SECP256r1)) {
388-
_send_error(U2F_SW_WRONG_DATA);
388+
_queue_error(U2F_SW_WRONG_DATA);
389389
return;
390390
}
391391

@@ -395,7 +395,7 @@ static void _authenticate(const USB_APDU *a)
395395
memcpy(buf + sizeof(U2F_AUTHENTICATE_RESP) - U2F_MAX_EC_SIG_SIZE + sig_len, "\x90\x00",
396396
2);
397397

398-
u2f_send_message(buf, sizeof(U2F_AUTHENTICATE_RESP) - U2F_MAX_EC_SIG_SIZE + sig_len + 2);
398+
u2f_queue_message(buf, sizeof(U2F_AUTHENTICATE_RESP) - U2F_MAX_EC_SIG_SIZE + sig_len + 2);
399399
}
400400
}
401401

@@ -418,7 +418,7 @@ static void _cmd_wink(const uint8_t *buf, uint32_t len)
418418
(void)buf;
419419

420420
if (len > 0) {
421-
u2f_send_err_hid(_cid, U2FHID_ERR_INVALID_LEN);
421+
u2f_queue_error_hid(_cid, U2FHID_ERR_INVALID_LEN);
422422
return;
423423
}
424424

@@ -456,7 +456,7 @@ static void _cmd_init(const USB_FRAME *in)
456456
U2FHID_INIT_RESP resp;
457457

458458
if (in->cid == 0) {
459-
u2f_send_err_hid(in->cid, U2FHID_ERR_INVALID_CID);
459+
u2f_queue_error_hid(in->cid, U2FHID_ERR_INVALID_CID);
460460
return;
461461
}
462462

@@ -486,7 +486,7 @@ static void _cmd_msg(const USB_APDU *a, uint32_t len)
486486
}
487487

488488
if (a->cla != 0) {
489-
_send_error(U2F_SW_CLA_NOT_SUPPORTED);
489+
_queue_error(U2F_SW_CLA_NOT_SUPPORTED);
490490
return;
491491
}
492492

@@ -501,7 +501,7 @@ static void _cmd_msg(const USB_APDU *a, uint32_t len)
501501
_version(a);
502502
break;
503503
default:
504-
_send_error(U2F_SW_INS_NOT_SUPPORTED);
504+
_queue_error(U2F_SW_INS_NOT_SUPPORTED);
505505
}
506506
}
507507

@@ -521,7 +521,7 @@ static void _continue(const USB_FRAME *f)
521521
!(memory_report_ext_flags() & MEM_EXT_MASK_U2F) ) {
522522
// Abort U2F commands if the U2F bit is not set (==U2F disabled).
523523
// Vendor specific commands are passed through.
524-
u2f_send_err_hid(_cid, U2FHID_ERR_CHANNEL_BUSY);
524+
u2f_queue_error_hid(_cid, U2FHID_ERR_CHANNEL_BUSY);
525525
} else {
526526
// Received all data
527527
switch (_reader.cmd) {
@@ -542,7 +542,7 @@ static void _continue(const USB_FRAME *f)
542542
break;
543543
}
544544
default:
545-
u2f_send_err_hid(_cid, U2FHID_ERR_INVALID_CMD);
545+
u2f_queue_error_hid(_cid, U2FHID_ERR_INVALID_CMD);
546546
break;
547547
}
548548
}
@@ -556,12 +556,12 @@ static void _continue(const USB_FRAME *f)
556556
static void _init(const USB_FRAME *f)
557557
{
558558
if (f->cid == U2FHID_CID_BROADCAST || f->cid == 0) {
559-
u2f_send_err_hid(f->cid, U2FHID_ERR_INVALID_CID);
559+
u2f_queue_error_hid(f->cid, U2FHID_ERR_INVALID_CID);
560560
return;
561561
}
562562

563563
if ((unsigned)U2FHID_MSG_LEN(*f) > sizeof(_reader.buf)) {
564-
u2f_send_err_hid(f->cid, U2FHID_ERR_INVALID_LEN);
564+
u2f_queue_error_hid(f->cid, U2FHID_ERR_INVALID_LEN);
565565
return;
566566
}
567567

@@ -593,9 +593,9 @@ void u2f_device_run(const USB_FRAME *f)
593593
if (f->cid == _cid) {
594594
usb_reply_queue_clear();
595595
_reset_state();
596-
u2f_send_err_hid(f->cid, U2FHID_ERR_INVALID_SEQ);
596+
u2f_queue_error_hid(f->cid, U2FHID_ERR_INVALID_SEQ);
597597
} else {
598-
u2f_send_err_hid(f->cid, U2FHID_ERR_CHANNEL_BUSY);
598+
u2f_queue_error_hid(f->cid, U2FHID_ERR_CHANNEL_BUSY);
599599
}
600600
} else {
601601
_init(f);
@@ -610,14 +610,14 @@ void u2f_device_run(const USB_FRAME *f)
610610
}
611611

612612
if (_cid != f->cid) {
613-
u2f_send_err_hid(f->cid, U2FHID_ERR_CHANNEL_BUSY);
613+
u2f_queue_error_hid(f->cid, U2FHID_ERR_CHANNEL_BUSY);
614614
goto exit;
615615
}
616616

617617
if (_reader.seq != f->cont.seq) {
618618
usb_reply_queue_clear();
619619
_reset_state();
620-
u2f_send_err_hid(f->cid, U2FHID_ERR_INVALID_SEQ);
620+
u2f_queue_error_hid(f->cid, U2FHID_ERR_INVALID_SEQ);
621621
goto exit;
622622
}
623623

@@ -649,7 +649,7 @@ void u2f_device_timeout(void)
649649

650650
if (_current_time_ms > U2F_TIMEOUT) {
651651
_reset_state();
652-
u2f_send_err_hid(_cid, U2FHID_ERR_MSG_TIMEOUT);
652+
u2f_queue_error_hid(_cid, U2FHID_ERR_MSG_TIMEOUT);
653653
usb_reply_queue_send();
654654
}
655655
}

src/u2f_device.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
extern const uint8_t U2F_HIJACK_CODE[U2F_HIJACK_ORIGIN_TOTAL][U2F_APPID_SIZE];
4242

4343

44-
void u2f_send_message(const uint8_t *data, const uint32_t len);
45-
void u2f_send_err_hid(uint32_t fcid, uint8_t err);
44+
void u2f_queue_message(const uint8_t *data, const uint32_t len);
45+
void u2f_queue_error_hid(uint32_t fcid, uint8_t err);
4646
void u2f_device_run(const USB_FRAME *f);
4747
void u2f_device_timeout(void);
4848

src/usb.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,18 @@ void usb_u2f_report(const unsigned char *command)
7171
}
7272
if (c->type >= U2FHID_VENDOR_FIRST) {
7373
// Disable vendor defined commands in u2f interface
74-
u2f_send_err_hid(c->cid, U2FHID_ERR_INVALID_CMD);
74+
u2f_queue_error_hid(c->cid, U2FHID_ERR_INVALID_CMD);
7575
usb_reply_queue_send();
7676
return;
7777
}
7878
u2f_device_run(c);
7979
}
8080

8181

82+
/*
83+
* Callback passed to the low level driver.
84+
* Called after a report is sent to the host computer.
85+
*/
8286
void usb_report_sent(void)
8387
{
8488
usb_reply_queue_send();

0 commit comments

Comments
 (0)