31 #include "os_io_seproxyhal.h"
33 #define U2F_MASK_COMMAND 0x80
34 #define U2F_COMMAND_HEADER_SIZE 3
36 static const uint8_t BROADCAST_CHANNEL[] = {0xff, 0xff, 0xff, 0xff};
37 static const uint8_t FORBIDDEN_CHANNEL[] = {0x00, 0x00, 0x00, 0x00};
71 u2f_transport_reset(service);
77 static void u2f_transport_error(
u2f_service_t *service,
char errorCode)
81 G_io_usb_ep_buffer[8] = errorCode;
128 uint16_t dataSize = blockSize + headerSize;
136 G_io_usb_ep_buffer[offset++] = service->
sendCmd;
144 memmove(G_io_usb_ep_buffer + headerSize,
154 u2f_transport_reset(service);
157 G_io_app.apdu_state = APDU_IDLE;
161 void u2f_transport_send_usb_user_presence_required(
u2f_service_t *service)
168 G_io_usb_ep_buffer[offset++] = 0;
169 G_io_usb_ep_buffer[offset++] = 2;
170 G_io_usb_ep_buffer[offset++] = 0x69;
171 G_io_usb_ep_buffer[offset++] = 0x85;
182 G_io_usb_ep_buffer[offset++] = 0;
183 G_io_usb_ep_buffer[offset++] = 0;
196 G_io_usb_ep_buffer[offset++] = 0;
197 G_io_usb_ep_buffer[offset++] = 1;
198 G_io_usb_ep_buffer[offset++] = reason;
213 uint16_t commandLength = U2BE(buffer, 4 + 1) + U2F_COMMAND_HEADER_SIZE;
216 u2f_transport_send_wink(service);
249 u2f_transport_send_usb_user_presence_required(service);
258 THROW(EXCEPTION_IO_RESET);
273 service->
media = media;
285 if (!u2f_transport_receive_fakeChannel(service, buffer, size)) {
294 u2f_transport_reset(service);
297 if (size < (1 + channelHeader)) {
321 uint16_t commandLength = U2BE(buffer, channelHeader + 1);
335 if (size < (channelHeader + 3)) {
341 if ((buffer[channelHeader + 0] & U2F_MASK_COMMAND) == 0) {
364 G_io_usb_ep_buffer[offset++] = 0;
365 G_io_usb_ep_buffer[offset++] = 1;
380 uint16_t commandLength = U2BE(buffer, channelHeader + 1);
387 switch (buffer[channelHeader]) {
425 xfer_len =
MIN(size - (channelHeader), U2F_COMMAND_HEADER_SIZE + commandLength);
440 if (size < (channelHeader + 2)) {
454 u2f_transport_reset(service);
478 buffer + channelHeader + 1,
511 return (memcmp(channel, BROADCAST_CHANNEL, 4) == 0);
516 return (memcmp(channel, FORBIDDEN_CHANNEL, 4) == 0);
530 u2f_transport_send_usb_user_presence_required(service);
565 while (G_io_app.apdu_state != APDU_IDLE) {
CRC (Cyclic Redundancy Check).
Random Number Generation.
uint8_t * transportReceiveBuffer
uint8_t waitAsynchronousResponse
uint8_t * transportBuffer
uint8_t fakeChannelTransportPacketIndex
uint16_t transportReceiveBufferLength
uint8_t channel[U2F_CHANNEL_ID_SIZE]
u2f_transport_state_t transportState
uint8_t transportPacketIndex
uint16_t fakeChannelTransportOffset
u2f_transport_media_t media
u2f_transport_media_t transportMedia
uint8_t transportChannel[4]
u2f_transport_state_t fakeChannelTransportState
void u2f_io_send(uint8_t *buffer, uint16_t length, u2f_transport_media_t media)
void u2f_message_set_autoreply_wait_user_presence(u2f_service_t *service, bool enabled)
void u2f_message_complete(u2f_service_t *service)
void u2f_message_reply(u2f_service_t *service, uint8_t cmd, uint8_t *buffer, uint16_t length)
bool u2f_message_repliable(u2f_service_t *service)
@ U2F_WAIT_ASYNCH_REPLY_READY
void ctap2_handle_cmd_cancel(u2f_service_t *service, uint8_t *buffer, uint16_t length)
#define U2F_CHANNEL_ID_SIZE
#define ERROR_PROP_MEDIA_MIXED
#define ERROR_INVALID_LEN
void u2f_transport_sent(u2f_service_t *service, u2f_transport_media_t media)
#define ERROR_INVALID_CID
bool u2f_is_channel_forbidden(uint8_t *channel)
void u2f_transport_init(u2f_service_t *service, uint8_t *message_buffer, uint16_t message_buffer_length)
#define ERROR_CHANNEL_BUSY
bool u2f_is_channel_broadcast(uint8_t *channel)
void u2f_transport_received(u2f_service_t *service, uint8_t *buffer, uint16_t size, u2f_transport_media_t media)
#define ERROR_PROP_MESSAGE_TOO_SHORT
#define CTAP2_STATUS_KEEPALIVE
void u2f_transport_ctap2_send_keepalive(u2f_service_t *service, uint8_t reason)
#define ERROR_INVALID_SEQ
#define ERROR_INVALID_CMD