1FIDO_DEV_SET_IO_FUNCT... BSD Library Functions Manual FIDO_DEV_SET_IO_FUNCT...
2
4 fido_dev_set_io_functions, fido_dev_set_sigmask — FIDO 2 device I/O in‐
5 terface
6
8 #include <fido.h>
9
10 typedef void *fido_dev_io_open_t(const char *);
11 typedef void fido_dev_io_close_t(void *);
12 typedef int fido_dev_io_read_t(void *, unsigned char *, size_t, int);
13 typedef int fido_dev_io_write_t(void *, const unsigned char *, size_t);
14
15 typedef struct fido_dev_io {
16 fido_dev_io_open_t *open;
17 fido_dev_io_close_t *close;
18 fido_dev_io_read_t *read;
19 fido_dev_io_write_t *write;
20 } fido_dev_io_t;
21
22 #ifdef _WIN32
23 typedef int fido_sigset_t;
24 #else
25 typedef sigset_t fido_sigset_t;
26 #endif
27
28 int
29 fido_dev_set_io_functions(fido_dev_t *dev, const fido_dev_io_t *io);
30
31 int
32 fido_dev_set_sigmask(fido_dev_t *dev, const fido_sigset_t *sigmask);
33
35 The fido_dev_set_io_functions() function sets the I/O handlers used by
36 libfido2 to talk to dev. By default, these handlers are set to the oper‐
37 ating system's native HID or NFC interfaces. They are defined as fol‐
38 lows:
39
40 fido_dev_open_t
41 Receives a const char * holding a path and opens the correspond‐
42 ing device, returning a non-NULL opaque pointer on success and
43 NULL on error.
44
45 fido_dev_close_t
46 Receives the opaque pointer returned by fido_dev_open_t and
47 closes the device.
48
49 fido_dev_read_t
50 Reads a single transmission unit (HID report, APDU) from a de‐
51 vice. The first parameter is the opaque pointer returned by
52 fido_dev_open_t. The second parameter is the read buffer, and
53 the third parameter is the read buffer size. The fourth parame‐
54 ter is the number of milliseconds the caller is willing to sleep,
55 should the call need to block. If this value holds -1,
56 fido_dev_read_t may block indefinitely. On success, the number
57 of bytes read is returned. On error, -1 is returned.
58
59 fido_dev_write_t
60 Writes a single transmission unit (HID report, APDU) to dev. The
61 first parameter is the opaque pointer returned by
62 fido_dev_open_t. The second parameter is the write buffer, and
63 the third parameter is the number of bytes to be written. A
64 fido_dev_write_t may block. On success, the number of bytes
65 written is returned. On error, -1 is returned.
66
67 When calling fido_dev_set_io_functions(), the open, close, read, and
68 write fields of io may not be NULL.
69
70 No references to io are held by fido_dev_set_io_functions().
71
72 The fido_dev_set_sigmask() function may be used to specify a non-NULL
73 signal mask sigmask to be used while libfido2's default I/O handlers wait
74 on dev. On UNIX-like operating systems, fido_sigset_t is defined as
75 sigset_t. On Windows, fido_sigset_t is defined as int and
76 fido_dev_set_sigmask() is a no-op.
77
78 No references to sigmask are held by fido_dev_set_sigmask().
79
81 On success, fido_dev_set_io_functions() and fido_dev_set_sigmask() return
82 FIDO_OK. On error, a different error code defined in <fido/err.h> is re‐
83 turned.
84
85BSD May 25, 2018 BSD