1FIDO_DEV_SET_IO_FUNCT... BSD Library Functions Manual FIDO_DEV_SET_IO_FUNCT...
2

NAME

4     fido_dev_set_io_functions — FIDO 2 device I/O interface
5

SYNOPSIS

7     #include <fido.h>
8
9     typedef void *fido_dev_io_open_t(const char *);
10     typedef void  fido_dev_io_close_t(void *);
11     typedef int   fido_dev_io_read_t(void *, unsigned char *, size_t, int);
12     typedef int   fido_dev_io_write_t(void *, const unsigned char *, size_t);
13     typedef int   fido_dev_io_rx_t(struct fido_dev *, uint8_t, unsigned char *, size_t, int);
14     typedef int   fido_dev_io_tx_t(struct fido_dev *, uint8_t, const unsigned char *, size_t);
15
16     typedef struct fido_dev_io {
17             fido_dev_io_open_t  *open;
18             fido_dev_io_close_t *close;
19             fido_dev_io_read_t  *read;
20             fido_dev_io_write_t *write;
21             fido_dev_io_rx_t    *rx;
22             fido_dev_io_tx_t    *tx;
23     } fido_dev_io_t;
24
25     int
26     fido_dev_set_io_functions(fido_dev_t *dev, const fido_dev_io_t *io);
27

DESCRIPTION

29     The fido_dev_set_io_functions interface defines the I/O and transmission
30     handlers used to talk to dev.  Its usage is optional.  By default,
31     libfido2 will use the operating system's native HID interface to talk
32     CTAP2 to a FIDO device.
33
34     A fido_dev_io_open_t function is expected to return a non-NULL opaque
35     pointer on success, and NULL on error.  The returned opaque pointer is
36     never dereferenced by libfido2.
37
38     A fido_dev_io_close_t function receives the opaque handle obtained from
39     fido_dev_io_open_t.  It is not expected to be idempotent.
40
41     A fido_dev_io_read_t function reads a single HID report from dev.  The
42     first parameter taken is the opaque handle obtained from
43     fido_dev_io_open_t.  The read buffer is pointed to by the second parame‐
44     ter, and the third parameter holds its size.  The last argument passed to
45     fido_dev_io_read_t is the number of milliseconds the caller is willing to
46     sleep, should the call need to block.  If this value holds -1,
47     fido_dev_io_read_t may block indefinitely.  The number of bytes read is
48     returned.  On error, -1 is returned.
49
50     A fido_dev_io_write_t function writes a single HID report to dev.  The
51     first parameter taken is the opaque handle returned by
52     fido_dev_io_open_t.  The write buffer is pointed to by the second parame‐
53     ter, and the third parameter holds its size.  A fido_dev_io_write_t func‐
54     tion may block.  The number of bytes written is returned.  On error, -1
55     is returned.
56
57     A fido_dev_io_rx_t function receives a complete CTAP2 message from dev.
58     The first parameter taken is a pointer to dev.  The second parameter
59     holds the expected CTAP2 command byte.  The read buffer is pointed to by
60     the third parameter, and the fourth parameter holds its size.  The last
61     argument passed to fido_dev_io_rx_t is the number of milliseconds the
62     caller is willing to sleep, should the call need to block.  If this value
63     holds -1, fido_dev_io_rx_t may block indefinitely.  The number of bytes
64     read is returned.  On error, -1 is returned.
65
66     A fido_dev_io_tx_t function transmits a complete CTAP2 message to dev.
67     The first parameter taken is a pointer to dev.  The second parameter
68     holds the CTAP2 command byte.  The write buffer is pointed to by the
69     third parameter, and the fourth parameter holds its size.  A
70     fido_dev_io_tx_t function may block.  On success, 0 is returned.  On
71     error, -1 is returned.
72
73     When calling fido_dev_set_io_functions(), the open, close, read and write
74     fields of io may not be NULL.  Either rx or tx may be NULL, in which case
75     libfido2 uses its corresponding CTAP2 HID transport method.
76
77     No references to io are held by fido_dev_set_io_functions().
78

RETURN VALUES

80     On success, fido_dev_set_io_functions() returns FIDO_OK.  On error, a
81     different error code defined in <fido/err.h> is returned.
82
83BSD                              May 25, 2018                              BSD
Impressum