Embedded SDK
Embedded SDK
u2f_service.h
Go to the documentation of this file.
1 
2 /*******************************************************************************
3  * Ledger Nano S - Secure firmware
4  * (c) 2022 Ledger
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  ********************************************************************************/
18 
19 #include <stdint.h>
20 #include <string.h>
21 #include <stdbool.h>
22 
23 #ifndef __U2F_SERVICE_H__
24 
25 #define __U2F_SERVICE_H__
26 
27 #define U2F_CHANNEL_ID_SIZE 4
28 
29 struct u2f_service_t;
30 
31 typedef void (*u2fHandle_t)(struct u2f_service_t *service, uint8_t *inputBuffer, uint8_t *channel);
32 typedef void (*u2fPromptUserPresence_t)(struct u2f_service_t *service,
33  bool enroll,
34  uint8_t *applicationParameter);
35 typedef void (*u2fTimer_t)(struct u2f_service_t *service);
36 
37 typedef enum {
46 
47 typedef enum {
53 
54 typedef enum {
59 
60 typedef struct u2f_service_t {
61  // Internal
62  uint32_t next_channel;
63 
66 
67  // buffer reference used when transport layer is reset, to process and receive the next message
69  // length of the receive buffer to avoid overflows
71 
79 
80  // handle fake channel state to simulate a USB keepalive
86 
87  // mark that an asynchronous response is available
89 
90  // uint16_t responseLength;
91  bool sending;
92 
94  uint32_t timerInterval;
95  uint32_t seqTimeout;
97  uint32_t keepaliveTimeout;
98 
101 
103 
104 // FIDO 2 compatible applications have to provide those implementations
105 
106 void ctap2_handle_cmd_cbor(u2f_service_t *service, uint8_t *buffer, uint16_t length);
107 void ctap2_handle_cmd_cancel(u2f_service_t *service, uint8_t *buffer, uint16_t length);
108 
109 #endif
uint16_t commandCrc
Definition: u2f_service.h:84
uint32_t next_channel
Definition: u2f_service.h:62
uint8_t * transportReceiveBuffer
Definition: u2f_service.h:68
uint8_t waitAsynchronousResponse
Definition: u2f_service.h:88
uint8_t * transportBuffer
Definition: u2f_service.h:76
uint8_t fakeChannelTransportPacketIndex
Definition: u2f_service.h:82
uint32_t seqTimeout
Definition: u2f_service.h:95
uint16_t transportReceiveBufferLength
Definition: u2f_service.h:70
uint8_t sendCmd
Definition: u2f_service.h:99
uint32_t keepaliveTimeout
Definition: u2f_service.h:97
uint16_t fakeChannelCrc
Definition: u2f_service.h:85
uint32_t timerInterval
Definition: u2f_service.h:94
uint8_t channel[U2F_CHANNEL_ID_SIZE]
Definition: u2f_service.h:64
u2f_transport_state_t transportState
Definition: u2f_service.h:77
uint16_t transportLength
Definition: u2f_service.h:74
u2fTimer_t timeoutFunction
Definition: u2f_service.h:93
uint8_t transportPacketIndex
Definition: u2f_service.h:75
bool requireKeepalive
Definition: u2f_service.h:96
uint16_t fakeChannelTransportOffset
Definition: u2f_service.h:81
u2f_transport_media_t media
Definition: u2f_service.h:65
uint16_t transportOffset
Definition: u2f_service.h:73
u2f_transport_media_t transportMedia
Definition: u2f_service.h:78
uint8_t transportChannel[4]
Definition: u2f_service.h:72
u2f_transport_state_t fakeChannelTransportState
Definition: u2f_service.h:83
void u2f_message_complete(u2f_service_t *service)
u2f_transport_media_t
Definition: u2f_service.h:47
@ U2F_MEDIA_BLE
Definition: u2f_service.h:51
@ U2F_MEDIA_NFC
Definition: u2f_service.h:50
@ U2F_MEDIA_USB
Definition: u2f_service.h:49
@ U2F_MEDIA_NONE
Definition: u2f_service.h:48
u2f_wait_asynch_state_t
Definition: u2f_service.h:54
@ U2F_WAIT_ASYNCH_ON
Definition: u2f_service.h:56
@ U2F_WAIT_ASYNCH_REPLY_READY
Definition: u2f_service.h:57
@ U2F_WAIT_ASYNCH_IDLE
Definition: u2f_service.h:55
struct u2f_service_t u2f_service_t
void(* u2fPromptUserPresence_t)(struct u2f_service_t *service, bool enroll, uint8_t *applicationParameter)
Definition: u2f_service.h:32
void(* u2fHandle_t)(struct u2f_service_t *service, uint8_t *inputBuffer, uint8_t *channel)
Definition: u2f_service.h:31
void ctap2_handle_cmd_cancel(u2f_service_t *service, uint8_t *buffer, uint16_t length)
u2f_transport_state_t
Definition: u2f_service.h:37
@ U2F_HANDLE_SEGMENTED
Definition: u2f_service.h:39
@ U2F_FAKE_RECEIVED
Definition: u2f_service.h:44
@ U2F_IDLE
Definition: u2f_service.h:38
@ U2F_PROCESSING_COMMAND
Definition: u2f_service.h:40
@ U2F_SENDING_ERROR
Definition: u2f_service.h:42
@ U2F_INTERNAL_ERROR
Definition: u2f_service.h:43
@ U2F_SENDING_RESPONSE
Definition: u2f_service.h:41
void(* u2fTimer_t)(struct u2f_service_t *service)
Definition: u2f_service.h:35
void ctap2_handle_cmd_cbor(u2f_service_t *service, uint8_t *buffer, uint16_t length)
#define U2F_CHANNEL_ID_SIZE
Definition: u2f_service.h:27
unsigned short uint16_t
Definition: usbd_conf.h:54
unsigned char uint8_t
Definition: usbd_conf.h:53