1*2d40c451Schristos.\" Copyright (c) 2018-2021 Yubico AB. All rights reserved. 2*2d40c451Schristos.\" 3*2d40c451Schristos.\" Redistribution and use in source and binary forms, with or without 4*2d40c451Schristos.\" modification, are permitted provided that the following conditions are 5*2d40c451Schristos.\" met: 6*2d40c451Schristos.\" 7*2d40c451Schristos.\" 1. Redistributions of source code must retain the above copyright 8*2d40c451Schristos.\" notice, this list of conditions and the following disclaimer. 9*2d40c451Schristos.\" 2. Redistributions in binary form must reproduce the above copyright 10*2d40c451Schristos.\" notice, this list of conditions and the following disclaimer in 11*2d40c451Schristos.\" the documentation and/or other materials provided with the 12*2d40c451Schristos.\" distribution. 13*2d40c451Schristos.\" 14*2d40c451Schristos.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 15*2d40c451Schristos.\" "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16*2d40c451Schristos.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 17*2d40c451Schristos.\" A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 18*2d40c451Schristos.\" HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 19*2d40c451Schristos.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 20*2d40c451Schristos.\" LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21*2d40c451Schristos.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22*2d40c451Schristos.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23*2d40c451Schristos.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24*2d40c451Schristos.\" OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25*2d40c451Schristos.\" 26*2d40c451Schristos.\" SPDX-License-Identifier: BSD-2-Clause 27ba9bdd8bSchristos.\" 28ba9bdd8bSchristos.Dd $Mdocdate: May 25 2018 $ 29ba9bdd8bSchristos.Dt FIDO_DEV_SET_IO_FUNCTIONS 3 30ba9bdd8bSchristos.Os 31ba9bdd8bSchristos.Sh NAME 3295dbdf32Schristos.Nm fido_dev_set_io_functions , 33*2d40c451Schristos.Nm fido_dev_set_sigmask , 34*2d40c451Schristos.Nm fido_dev_set_timeout , 35*2d40c451Schristos.Nm fido_dev_set_transport_functions , 36*2d40c451Schristos.Nm fido_dev_io_handle 37ba9bdd8bSchristos.Nd FIDO2 device I/O interface 38ba9bdd8bSchristos.Sh SYNOPSIS 39ba9bdd8bSchristos.In fido.h 40ba9bdd8bSchristos.Bd -literal 41ba9bdd8bSchristostypedef void *fido_dev_io_open_t(const char *); 42ba9bdd8bSchristostypedef void fido_dev_io_close_t(void *); 43ba9bdd8bSchristostypedef int fido_dev_io_read_t(void *, unsigned char *, size_t, int); 44ba9bdd8bSchristostypedef int fido_dev_io_write_t(void *, const unsigned char *, size_t); 45ba9bdd8bSchristos 46ba9bdd8bSchristostypedef struct fido_dev_io { 47ba9bdd8bSchristos fido_dev_io_open_t *open; 48ba9bdd8bSchristos fido_dev_io_close_t *close; 49ba9bdd8bSchristos fido_dev_io_read_t *read; 50ba9bdd8bSchristos fido_dev_io_write_t *write; 51ba9bdd8bSchristos} fido_dev_io_t; 5295dbdf32Schristos 5395dbdf32Schristos#ifdef _WIN32 5495dbdf32Schristostypedef int fido_sigset_t; 5595dbdf32Schristos#else 5695dbdf32Schristostypedef sigset_t fido_sigset_t; 5795dbdf32Schristos#endif 58*2d40c451Schristos 59*2d40c451Schristostypedef int fido_dev_rx_t(struct fido_dev *, 60*2d40c451Schristos uint8_t, unsigned char *, size_t, int); 61*2d40c451Schristostypedef int fido_dev_tx_t(struct fido_dev *, 62*2d40c451Schristos uint8_t, const unsigned char *, size_t); 63*2d40c451Schristos 64*2d40c451Schristostypedef struct fido_dev_transport { 65*2d40c451Schristos fido_dev_rx_t *rx; 66*2d40c451Schristos fido_dev_tx_t *tx; 67*2d40c451Schristos} fido_dev_transport_t; 68ba9bdd8bSchristos.Ed 69*2d40c451Schristos.Pp 70ba9bdd8bSchristos.Ft int 71ba9bdd8bSchristos.Fn fido_dev_set_io_functions "fido_dev_t *dev" "const fido_dev_io_t *io" 7295dbdf32Schristos.Ft int 7395dbdf32Schristos.Fn fido_dev_set_sigmask "fido_dev_t *dev" "const fido_sigset_t *sigmask" 74*2d40c451Schristos.Ft int 75*2d40c451Schristos.Fn fido_dev_set_timeout "fido_dev_t *dev" "int ms" 76*2d40c451Schristos.Ft int 77*2d40c451Schristos.Fn fido_dev_set_transport_functions "fido_dev_t *dev" "const fido_dev_transport_t *t" 78*2d40c451Schristos.Ft void * 79*2d40c451Schristos.Fn fido_dev_io_handle "const fido_dev_t *dev" 80ba9bdd8bSchristos.Sh DESCRIPTION 81ba9bdd8bSchristosThe 8295dbdf32Schristos.Fn fido_dev_set_io_functions 8395dbdf32Schristosfunction sets the I/O handlers used by 84ba9bdd8bSchristos.Em libfido2 8595dbdf32Schristosto talk to 86ba9bdd8bSchristos.Fa dev . 8795dbdf32SchristosBy default, these handlers are set to the operating system's native HID or NFC 8895dbdf32Schristosinterfaces. 8995dbdf32SchristosThey are defined as follows: 9095dbdf32Schristos.Bl -tag -width Ds 9195dbdf32Schristos.It Vt fido_dev_open_t 9295dbdf32SchristosReceives a 9395dbdf32Schristos.Vt const char * 9495dbdf32Schristosholding a path and opens the corresponding device, returning a 9595dbdf32Schristosnon-NULL opaque pointer on success and NULL on error. 9695dbdf32Schristos.It Vt fido_dev_close_t 9795dbdf32SchristosReceives the opaque pointer returned by 9895dbdf32Schristos.Vt fido_dev_open_t 9995dbdf32Schristosand closes the device. 10095dbdf32Schristos.It Vt fido_dev_read_t 10195dbdf32SchristosReads a single transmission unit (HID report, APDU) from a device. 10295dbdf32SchristosThe first parameter is the opaque pointer returned by 10395dbdf32Schristos.Vt fido_dev_open_t . 10495dbdf32SchristosThe second parameter is the read buffer, and the third parameter 10595dbdf32Schristosis the read buffer size. 10695dbdf32SchristosThe fourth parameter is the number of milliseconds the caller is 10795dbdf32Schristoswilling to sleep, should the call need to block. 108ba9bdd8bSchristosIf this value holds -1, 10995dbdf32Schristos.Vt fido_dev_read_t 110ba9bdd8bSchristosmay block indefinitely. 11195dbdf32SchristosOn success, the number of bytes read is returned. 112ba9bdd8bSchristosOn error, -1 is returned. 11395dbdf32Schristos.It Vt fido_dev_write_t 11495dbdf32SchristosWrites a single transmission unit (HID report, APDU) to 115ba9bdd8bSchristos.Fa dev . 11695dbdf32SchristosThe first parameter is the opaque pointer returned by 11795dbdf32Schristos.Vt fido_dev_open_t . 11895dbdf32SchristosThe second parameter is the write buffer, and the third parameter 11995dbdf32Schristosis the number of bytes to be written. 120ba9bdd8bSchristosA 12195dbdf32Schristos.Vt fido_dev_write_t 12295dbdf32Schristosmay block. 12395dbdf32SchristosOn success, the number of bytes written is returned. 124ba9bdd8bSchristosOn error, -1 is returned. 12595dbdf32Schristos.El 126ba9bdd8bSchristos.Pp 127ba9bdd8bSchristosWhen calling 128ba9bdd8bSchristos.Fn fido_dev_set_io_functions , 129ba9bdd8bSchristosthe 130ba9bdd8bSchristos.Fa open , 131ba9bdd8bSchristos.Fa close , 13295dbdf32Schristos.Fa read , 133ba9bdd8bSchristosand 134ba9bdd8bSchristos.Fa write 135ba9bdd8bSchristosfields of 136ba9bdd8bSchristos.Fa io 137ba9bdd8bSchristosmay not be NULL. 138ba9bdd8bSchristos.Pp 139ba9bdd8bSchristosNo references to 140ba9bdd8bSchristos.Fa io 141ba9bdd8bSchristosare held by 142ba9bdd8bSchristos.Fn fido_dev_set_io_functions . 14395dbdf32Schristos.Pp 14495dbdf32SchristosThe 14595dbdf32Schristos.Fn fido_dev_set_sigmask 14695dbdf32Schristosfunction may be used to specify a non-NULL signal mask 14795dbdf32Schristos.Fa sigmask 14895dbdf32Schristosto be used while 14995dbdf32Schristos.Em libfido2's 15095dbdf32Schristosdefault I/O handlers wait on 15195dbdf32Schristos.Fa dev . 15295dbdf32SchristosOn UNIX-like operating systems, 15395dbdf32Schristos.Vt fido_sigset_t 15495dbdf32Schristosis defined as 15595dbdf32Schristos.Vt sigset_t . 15695dbdf32SchristosOn Windows, 15795dbdf32Schristos.Vt fido_sigset_t 15895dbdf32Schristosis defined as 15995dbdf32Schristos.Vt int 16095dbdf32Schristosand 16195dbdf32Schristos.Fn fido_dev_set_sigmask 16295dbdf32Schristosis a no-op. 16395dbdf32Schristos.Pp 16495dbdf32SchristosNo references to 16595dbdf32Schristos.Fa sigmask 16695dbdf32Schristosare held by 16795dbdf32Schristos.Fn fido_dev_set_sigmask . 168*2d40c451Schristos.Pp 169*2d40c451SchristosThe 170*2d40c451Schristos.Fn fido_dev_set_timeout 171*2d40c451Schristosfunction informs 172*2d40c451Schristos.Em libfido2 173*2d40c451Schristosnot to block for more than 174*2d40c451Schristos.Fa ms 175*2d40c451Schristosmilliseconds while communicating with 176*2d40c451Schristos.Fa dev . 177*2d40c451SchristosIf a timeout occurs, the corresponding 178*2d40c451Schristos.Em fido_dev_* 179*2d40c451Schristosfunction will fail with 180*2d40c451Schristos.Dv FIDO_ERR_RX . 181*2d40c451SchristosIf 182*2d40c451Schristos.Fa ms 183*2d40c451Schristosis -1, 184*2d40c451Schristosthen 185*2d40c451Schristos.Em libfido2 186*2d40c451Schristosmay block indefinitely. 187*2d40c451SchristosThis is the default behaviour. 188*2d40c451SchristosWhen using the Windows Hello backend, 189*2d40c451Schristos.Fa ms 190*2d40c451Schristosis used as a guidance and may be overwritten by the platform. 191*2d40c451Schristos.Pp 192*2d40c451SchristosThe 193*2d40c451Schristos.Fn fido_dev_set_transport_functions 194*2d40c451Schristosfunction sets the transport functions used by 195*2d40c451Schristos.Em libfido2 196*2d40c451Schristosto talk to 197*2d40c451Schristos.Fa dev . 198*2d40c451SchristosWhile the I/O handlers are responsible for sending and receiving 199*2d40c451Schristostransmission units of initialization and continuation packets already 200*2d40c451Schristosformatted by 201*2d40c451Schristos.Em libfido2 , 202*2d40c451Schristosthe transport handlers are responsible for sending and receiving 203*2d40c451Schristosthe CTAPHID commands and data directly, as defined in the FIDO Client 204*2d40c451Schristosto Authenticator Protocol (CTAP) standard. 205*2d40c451SchristosThey are defined as follows: 206*2d40c451Schristos.Bl -tag -width Ds 207*2d40c451Schristos.It Vt fido_dev_tx_t 208*2d40c451SchristosReceives a device, a CTAPHID command to transmit, a data buffer to 209*2d40c451Schristostransmit, and the length of the data buffer. 210*2d40c451SchristosOn success, 0 is returned. 211*2d40c451SchristosOn error, -1 is returned. 212*2d40c451Schristos.It Vt fido_dev_rx_t 213*2d40c451SchristosReceives a device, a CTAPHID command whose response the caller expects 214*2d40c451Schristosto receive, a data buffer to receive into, the size of the data buffer 215*2d40c451Schristosdetermining the maximum length of a response, and the maximum number of 216*2d40c451Schristosmilliseconds to wait for a response. 217*2d40c451SchristosOn success, the number of bytes read into the data buffer is returned. 218*2d40c451SchristosOn error, -1 is returned. 219*2d40c451Schristos.El 220*2d40c451Schristos.Pp 221*2d40c451SchristosWhen transport functions are specified, 222*2d40c451Schristos.Em libfido2 223*2d40c451Schristoswill use them instead of the 224*2d40c451Schristos.Dv read 225*2d40c451Schristosand 226*2d40c451Schristos.Dv write 227*2d40c451Schristosfunctions of the I/O handlers. 228*2d40c451SchristosHowever, the I/O handlers must still be specified to open and close the 229*2d40c451Schristosdevice. 230*2d40c451Schristos.Pp 231*2d40c451SchristosThe 232*2d40c451Schristos.Fn fido_dev_io_handle 233*2d40c451Schristosfunction returns the opaque pointer returned by the 234*2d40c451Schristos.Dv open 235*2d40c451Schristosfunction of the I/O handlers. 236*2d40c451SchristosThis is useful mainly for the transport functions, which unlike the I/O 237*2d40c451Schristoshandlers are passed the 238*2d40c451Schristos.Vt fido_dev_t 239*2d40c451Schristospointer instead of the opaque I/O handle. 240ba9bdd8bSchristos.Sh RETURN VALUES 241ba9bdd8bSchristosOn success, 242*2d40c451Schristos.Fn fido_dev_set_io_functions , 243*2d40c451Schristos.Fn fido_dev_set_transport_functions , 244*2d40c451Schristos.Fn fido_dev_set_sigmask , 24595dbdf32Schristosand 246*2d40c451Schristos.Fn fido_dev_set_timeout 24795dbdf32Schristosreturn 248ba9bdd8bSchristos.Dv FIDO_OK . 249ba9bdd8bSchristosOn error, a different error code defined in 250ba9bdd8bSchristos.In fido/err.h 251ba9bdd8bSchristosis returned. 252*2d40c451Schristos.Sh SEE ALSO 253*2d40c451Schristos.Xr fido_dev_info_manifest 3 , 254*2d40c451Schristos.Xr fido_dev_open 3 255*2d40c451Schristos.Rs 256*2d40c451Schristos.%D 2021-06-15 257*2d40c451Schristos.%O Proposed Standard, Version 2.1 258*2d40c451Schristos.%Q FIDO Alliance 259*2d40c451Schristos.%R Client to Authenticator Protocol (CTAP) 260*2d40c451Schristos.%U https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-20210615.html 261*2d40c451Schristos.Re 262