-
Notifications
You must be signed in to change notification settings - Fork 1
/
error_handling.h
54 lines (35 loc) · 996 Bytes
/
error_handling.h
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// ERROR HANDLING
void respondErrorPDU(byte *buffer, int err) {
SET_MSG_LEN(buffer, 2); //len("") + 2 byte SW
byte *datapart = buffer + 7;
(*datapart++) = (err >> 8) & 0xff;
(*datapart++) = err & 0xff;
RawHID.send(buffer, 100);
}
void send_u2f_error(byte *buffer, int code) {
memcpy(response, buffer, 4);
response[4] = U2FHID_ERROR;
SET_MSG_LEN(response, 1);
response[7] = code & 0xff;
DISPLAY_IF_DEBUG("u2f error:");
DISPLAY_IF_DEBUG(code);
RawHID.send(response, 100);
}
void error_invalid_channel_id() {
return send_u2f_error(recieved, ERR_SYNC_FAIL);
}
void error_timeout() {
return send_u2f_error(recieved, ERR_MSG_TIMEOUT);
}
void error_invalid_length() {
return send_u2f_error(recieved, ERR_INVALID_LEN);
}
void error_invalid_seq() {
return send_u2f_error(recieved, ERR_INVALID_SEQ);
}
void error_channel_busy() {
return send_u2f_error(recieved, ERR_CHANNEL_BUSY);
}
void error_invalid_cmd() {
return send_u2f_error(recieved, ERR_INVALID_CMD);
}