1f540a430SEd Maste.\" Copyright (c) 2018-2021 Yubico AB. All rights reserved. 2*2ccfa855SEd Maste.\" 3*2ccfa855SEd Maste.\" Redistribution and use in source and binary forms, with or without 4*2ccfa855SEd Maste.\" modification, are permitted provided that the following conditions are 5*2ccfa855SEd Maste.\" met: 6*2ccfa855SEd Maste.\" 7*2ccfa855SEd Maste.\" 1. Redistributions of source code must retain the above copyright 8*2ccfa855SEd Maste.\" notice, this list of conditions and the following disclaimer. 9*2ccfa855SEd Maste.\" 2. Redistributions in binary form must reproduce the above copyright 10*2ccfa855SEd Maste.\" notice, this list of conditions and the following disclaimer in 11*2ccfa855SEd Maste.\" the documentation and/or other materials provided with the 12*2ccfa855SEd Maste.\" distribution. 13*2ccfa855SEd Maste.\" 14*2ccfa855SEd Maste.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 15*2ccfa855SEd Maste.\" "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16*2ccfa855SEd Maste.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 17*2ccfa855SEd Maste.\" A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 18*2ccfa855SEd Maste.\" HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 19*2ccfa855SEd Maste.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 20*2ccfa855SEd Maste.\" LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21*2ccfa855SEd Maste.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22*2ccfa855SEd Maste.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23*2ccfa855SEd Maste.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24*2ccfa855SEd Maste.\" OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25*2ccfa855SEd Maste.\" 26*2ccfa855SEd Maste.\" SPDX-License-Identifier: BSD-2-Clause 270afa8e06SEd Maste.\" 280afa8e06SEd Maste.Dd $Mdocdate: May 25 2018 $ 290afa8e06SEd Maste.Dt FIDO_DEV_SET_IO_FUNCTIONS 3 300afa8e06SEd Maste.Os 310afa8e06SEd Maste.Sh NAME 320afa8e06SEd Maste.Nm fido_dev_set_io_functions , 33f540a430SEd Maste.Nm fido_dev_set_sigmask , 343e696dfbSEd Maste.Nm fido_dev_set_timeout , 353e696dfbSEd Maste.Nm fido_dev_set_transport_functions , 363e696dfbSEd Maste.Nm fido_dev_io_handle 370afa8e06SEd Maste.Nd FIDO2 device I/O interface 380afa8e06SEd Maste.Sh SYNOPSIS 390afa8e06SEd Maste.In fido.h 400afa8e06SEd Maste.Bd -literal 410afa8e06SEd Mastetypedef void *fido_dev_io_open_t(const char *); 420afa8e06SEd Mastetypedef void fido_dev_io_close_t(void *); 430afa8e06SEd Mastetypedef int fido_dev_io_read_t(void *, unsigned char *, size_t, int); 440afa8e06SEd Mastetypedef int fido_dev_io_write_t(void *, const unsigned char *, size_t); 450afa8e06SEd Maste 460afa8e06SEd Mastetypedef struct fido_dev_io { 470afa8e06SEd Maste fido_dev_io_open_t *open; 480afa8e06SEd Maste fido_dev_io_close_t *close; 490afa8e06SEd Maste fido_dev_io_read_t *read; 500afa8e06SEd Maste fido_dev_io_write_t *write; 510afa8e06SEd Maste} fido_dev_io_t; 520afa8e06SEd Maste 530afa8e06SEd Maste#ifdef _WIN32 540afa8e06SEd Mastetypedef int fido_sigset_t; 550afa8e06SEd Maste#else 560afa8e06SEd Mastetypedef sigset_t fido_sigset_t; 570afa8e06SEd Maste#endif 583e696dfbSEd Maste 593e696dfbSEd Mastetypedef int fido_dev_rx_t(struct fido_dev *, 603e696dfbSEd Maste uint8_t, unsigned char *, size_t, int); 613e696dfbSEd Mastetypedef int fido_dev_tx_t(struct fido_dev *, 623e696dfbSEd Maste uint8_t, const unsigned char *, size_t); 633e696dfbSEd Maste 643e696dfbSEd Mastetypedef struct fido_dev_transport { 653e696dfbSEd Maste fido_dev_rx_t *rx; 663e696dfbSEd Maste fido_dev_tx_t *tx; 673e696dfbSEd Maste} fido_dev_transport_t; 680afa8e06SEd Maste.Ed 693e696dfbSEd Maste.Pp 700afa8e06SEd Maste.Ft int 710afa8e06SEd Maste.Fn fido_dev_set_io_functions "fido_dev_t *dev" "const fido_dev_io_t *io" 720afa8e06SEd Maste.Ft int 730afa8e06SEd Maste.Fn fido_dev_set_sigmask "fido_dev_t *dev" "const fido_sigset_t *sigmask" 74f540a430SEd Maste.Ft int 75f540a430SEd Maste.Fn fido_dev_set_timeout "fido_dev_t *dev" "int ms" 763e696dfbSEd Maste.Ft int 773e696dfbSEd Maste.Fn fido_dev_set_transport_functions "fido_dev_t *dev" "const fido_dev_transport_t *t" 783e696dfbSEd Maste.Ft void * 793e696dfbSEd Maste.Fn fido_dev_io_handle "const fido_dev_t *dev" 800afa8e06SEd Maste.Sh DESCRIPTION 810afa8e06SEd MasteThe 820afa8e06SEd Maste.Fn fido_dev_set_io_functions 830afa8e06SEd Mastefunction sets the I/O handlers used by 840afa8e06SEd Maste.Em libfido2 850afa8e06SEd Masteto talk to 860afa8e06SEd Maste.Fa dev . 870afa8e06SEd MasteBy default, these handlers are set to the operating system's native HID or NFC 880afa8e06SEd Masteinterfaces. 890afa8e06SEd MasteThey are defined as follows: 900afa8e06SEd Maste.Bl -tag -width Ds 910afa8e06SEd Maste.It Vt fido_dev_open_t 920afa8e06SEd MasteReceives a 930afa8e06SEd Maste.Vt const char * 940afa8e06SEd Masteholding a path and opens the corresponding device, returning a 950afa8e06SEd Mastenon-NULL opaque pointer on success and NULL on error. 960afa8e06SEd Maste.It Vt fido_dev_close_t 970afa8e06SEd MasteReceives the opaque pointer returned by 980afa8e06SEd Maste.Vt fido_dev_open_t 990afa8e06SEd Masteand closes the device. 1000afa8e06SEd Maste.It Vt fido_dev_read_t 1010afa8e06SEd MasteReads a single transmission unit (HID report, APDU) from a device. 1020afa8e06SEd MasteThe first parameter is the opaque pointer returned by 1030afa8e06SEd Maste.Vt fido_dev_open_t . 1040afa8e06SEd MasteThe second parameter is the read buffer, and the third parameter 1050afa8e06SEd Masteis the read buffer size. 1060afa8e06SEd MasteThe fourth parameter is the number of milliseconds the caller is 1070afa8e06SEd Mastewilling to sleep, should the call need to block. 1080afa8e06SEd MasteIf this value holds -1, 1090afa8e06SEd Maste.Vt fido_dev_read_t 1100afa8e06SEd Mastemay block indefinitely. 1110afa8e06SEd MasteOn success, the number of bytes read is returned. 1120afa8e06SEd MasteOn error, -1 is returned. 1130afa8e06SEd Maste.It Vt fido_dev_write_t 1140afa8e06SEd MasteWrites a single transmission unit (HID report, APDU) to 1150afa8e06SEd Maste.Fa dev . 1160afa8e06SEd MasteThe first parameter is the opaque pointer returned by 1170afa8e06SEd Maste.Vt fido_dev_open_t . 1180afa8e06SEd MasteThe second parameter is the write buffer, and the third parameter 1190afa8e06SEd Masteis the number of bytes to be written. 1200afa8e06SEd MasteA 1210afa8e06SEd Maste.Vt fido_dev_write_t 1220afa8e06SEd Mastemay block. 1230afa8e06SEd MasteOn success, the number of bytes written is returned. 1240afa8e06SEd MasteOn error, -1 is returned. 1250afa8e06SEd Maste.El 1260afa8e06SEd Maste.Pp 1270afa8e06SEd MasteWhen calling 1280afa8e06SEd Maste.Fn fido_dev_set_io_functions , 1290afa8e06SEd Mastethe 1300afa8e06SEd Maste.Fa open , 1310afa8e06SEd Maste.Fa close , 1320afa8e06SEd Maste.Fa read , 1330afa8e06SEd Masteand 1340afa8e06SEd Maste.Fa write 1350afa8e06SEd Mastefields of 1360afa8e06SEd Maste.Fa io 1370afa8e06SEd Mastemay not be NULL. 1380afa8e06SEd Maste.Pp 1390afa8e06SEd MasteNo references to 1400afa8e06SEd Maste.Fa io 1410afa8e06SEd Masteare held by 1420afa8e06SEd Maste.Fn fido_dev_set_io_functions . 1430afa8e06SEd Maste.Pp 1440afa8e06SEd MasteThe 1450afa8e06SEd Maste.Fn fido_dev_set_sigmask 1460afa8e06SEd Mastefunction may be used to specify a non-NULL signal mask 1470afa8e06SEd Maste.Fa sigmask 1480afa8e06SEd Masteto be used while 1490afa8e06SEd Maste.Em libfido2's 1500afa8e06SEd Mastedefault I/O handlers wait on 1510afa8e06SEd Maste.Fa dev . 1520afa8e06SEd MasteOn UNIX-like operating systems, 1530afa8e06SEd Maste.Vt fido_sigset_t 1540afa8e06SEd Masteis defined as 1550afa8e06SEd Maste.Vt sigset_t . 1560afa8e06SEd MasteOn Windows, 1570afa8e06SEd Maste.Vt fido_sigset_t 1580afa8e06SEd Masteis defined as 1590afa8e06SEd Maste.Vt int 1600afa8e06SEd Masteand 1610afa8e06SEd Maste.Fn fido_dev_set_sigmask 1620afa8e06SEd Masteis a no-op. 1630afa8e06SEd Maste.Pp 1640afa8e06SEd MasteNo references to 1650afa8e06SEd Maste.Fa sigmask 1660afa8e06SEd Masteare held by 1670afa8e06SEd Maste.Fn fido_dev_set_sigmask . 168f540a430SEd Maste.Pp 169f540a430SEd MasteThe 170f540a430SEd Maste.Fn fido_dev_set_timeout 171f540a430SEd Mastefunction informs 172f540a430SEd Maste.Em libfido2 173f540a430SEd Mastenot to block for more than 174f540a430SEd Maste.Fa ms 175f540a430SEd Mastemilliseconds while communicating with 176f540a430SEd Maste.Fa dev . 177f540a430SEd MasteIf a timeout occurs, the corresponding 178f540a430SEd Maste.Em fido_dev_* 179f540a430SEd Mastefunction will fail with 180f540a430SEd Maste.Dv FIDO_ERR_RX . 181f540a430SEd MasteIf 182f540a430SEd Maste.Fa ms 183f540a430SEd Masteis -1, 184f540a430SEd Mastethen 185f540a430SEd Maste.Em libfido2 186f540a430SEd Mastemay block indefinitely. 187f540a430SEd MasteThis is the default behaviour. 188f540a430SEd MasteWhen using the Windows Hello backend, 189f540a430SEd Maste.Fa ms 190f540a430SEd Masteis used as a guidance and may be overwritten by the platform. 1913e696dfbSEd Maste.Pp 1923e696dfbSEd MasteThe 1933e696dfbSEd Maste.Fn fido_dev_set_transport_functions 1943e696dfbSEd Mastefunction sets the transport functions used by 1953e696dfbSEd Maste.Em libfido2 1963e696dfbSEd Masteto talk to 1973e696dfbSEd Maste.Fa dev . 1983e696dfbSEd MasteWhile the I/O handlers are responsible for sending and receiving 1993e696dfbSEd Mastetransmission units of initialization and continuation packets already 2003e696dfbSEd Masteformatted by 2013e696dfbSEd Maste.Em libfido2 , 2023e696dfbSEd Mastethe transport handlers are responsible for sending and receiving 2033e696dfbSEd Mastethe CTAPHID commands and data directly, as defined in the FIDO Client 2043e696dfbSEd Masteto Authenticator Protocol (CTAP) standard. 2053e696dfbSEd MasteThey are defined as follows: 2063e696dfbSEd Maste.Bl -tag -width Ds 2073e696dfbSEd Maste.It Vt fido_dev_tx_t 2083e696dfbSEd MasteReceives a device, a CTAPHID command to transmit, a data buffer to 2093e696dfbSEd Mastetransmit, and the length of the data buffer. 2103e696dfbSEd MasteOn success, 0 is returned. 2113e696dfbSEd MasteOn error, -1 is returned. 2123e696dfbSEd Maste.It Vt fido_dev_rx_t 2133e696dfbSEd MasteReceives a device, a CTAPHID command whose response the caller expects 2143e696dfbSEd Masteto receive, a data buffer to receive into, the size of the data buffer 2153e696dfbSEd Mastedetermining the maximum length of a response, and the maximum number of 2163e696dfbSEd Mastemilliseconds to wait for a response. 2173e696dfbSEd MasteOn success, the number of bytes read into the data buffer is returned. 2183e696dfbSEd MasteOn error, -1 is returned. 2193e696dfbSEd Maste.El 2203e696dfbSEd Maste.Pp 2213e696dfbSEd MasteWhen transport functions are specified, 2223e696dfbSEd Maste.Em libfido2 2233e696dfbSEd Mastewill use them instead of the 2243e696dfbSEd Maste.Dv read 2253e696dfbSEd Masteand 2263e696dfbSEd Maste.Dv write 2273e696dfbSEd Mastefunctions of the I/O handlers. 2283e696dfbSEd MasteHowever, the I/O handlers must still be specified to open and close the 2293e696dfbSEd Mastedevice. 2303e696dfbSEd Maste.Pp 2313e696dfbSEd MasteThe 2323e696dfbSEd Maste.Fn fido_dev_io_handle 2333e696dfbSEd Mastefunction returns the opaque pointer returned by the 2343e696dfbSEd Maste.Dv open 2353e696dfbSEd Mastefunction of the I/O handlers. 2363e696dfbSEd MasteThis is useful mainly for the transport functions, which unlike the I/O 2373e696dfbSEd Mastehandlers are passed the 2383e696dfbSEd Maste.Vt fido_dev_t 2393e696dfbSEd Mastepointer instead of the opaque I/O handle. 2400afa8e06SEd Maste.Sh RETURN VALUES 2410afa8e06SEd MasteOn success, 242f540a430SEd Maste.Fn fido_dev_set_io_functions , 2433e696dfbSEd Maste.Fn fido_dev_set_transport_functions , 244f540a430SEd Maste.Fn fido_dev_set_sigmask , 2450afa8e06SEd Masteand 246f540a430SEd Maste.Fn fido_dev_set_timeout 2470afa8e06SEd Mastereturn 2480afa8e06SEd Maste.Dv FIDO_OK . 2490afa8e06SEd MasteOn error, a different error code defined in 2500afa8e06SEd Maste.In fido/err.h 2510afa8e06SEd Masteis returned. 2523e696dfbSEd Maste.Sh SEE ALSO 2533e696dfbSEd Maste.Xr fido_dev_info_manifest 3 , 2543e696dfbSEd Maste.Xr fido_dev_open 3 2553e696dfbSEd Maste.Rs 2563e696dfbSEd Maste.%D 2021-06-15 2573e696dfbSEd Maste.%O Proposed Standard, Version 2.1 2583e696dfbSEd Maste.%Q FIDO Alliance 2593e696dfbSEd Maste.%R Client to Authenticator Protocol (CTAP) 2603e696dfbSEd Maste.%U https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-20210615.html 2613e696dfbSEd Maste.Re 262