xref: /openbsd-src/lib/libfido2/man/fido_dev_set_io_functions.3 (revision 99fd087599a8791921855f21bd7e36130f39aadc)
1.\" Copyright (c) 2018 Yubico AB. All rights reserved.
2.\" Use of this source code is governed by a BSD-style
3.\" license that can be found in the LICENSE file.
4.\"
5.Dd $Mdocdate: February 7 2020 $
6.Dt FIDO_DEV_SET_IO_FUNCTIONS 3
7.Os
8.Sh NAME
9.Nm fido_dev_set_io_functions
10.Nd FIDO 2 device I/O interface
11.Sh SYNOPSIS
12.In fido.h
13.Bd -literal
14typedef void *fido_dev_io_open_t(const char *);
15typedef void  fido_dev_io_close_t(void *);
16typedef int   fido_dev_io_read_t(void *, unsigned char *, size_t, int);
17typedef int   fido_dev_io_write_t(void *, const unsigned char *, size_t);
18
19typedef struct fido_dev_io {
20	fido_dev_io_open_t  *open;
21	fido_dev_io_close_t *close;
22	fido_dev_io_read_t  *read;
23	fido_dev_io_write_t *write;
24} fido_dev_io_t;
25.Ed
26.Ft int
27.Fn fido_dev_set_io_functions "fido_dev_t *dev" "const fido_dev_io_t *io"
28.Sh DESCRIPTION
29The
30.Nm
31interface defines the I/O handlers used to talk to
32.Fa dev .
33Its usage is optional.
34By default,
35.Em libfido2
36will use the operating system's native HID interface to talk to
37a FIDO device.
38.Pp
39A
40.Vt fido_dev_io_open_t
41function is expected to return a non-NULL opaque pointer on success,
42and NULL on error.
43The returned opaque pointer is never dereferenced by
44.Em libfido2 .
45.Pp
46A
47.Vt fido_dev_io_close_t
48function receives the opaque handle obtained from
49.Vt fido_dev_io_open_t .
50It is not expected to be idempotent.
51.Pp
52A
53.Vt fido_dev_io_read_t
54function reads from
55.Fa dev .
56The first parameter taken is the opaque handle obtained from
57.Vt fido_dev_io_open_t .
58The read buffer is pointed to by the second parameter, and the
59third parameter holds its size.
60Finally, the last argument passed to
61.Vt fido_dev_io_read_t
62is the number of milliseconds the caller is willing to sleep,
63should the call need to block.
64If this value holds -1,
65.Vt fido_dev_io_read_t
66may block indefinitely.
67The number of bytes read is returned.
68On error, -1 is returned.
69.Pp
70Conversely, a
71.Vt fido_dev_io_write_t
72function writes to
73.Fa dev .
74The first parameter taken is the opaque handle returned by
75.Vt fido_dev_io_open_t .
76The write buffer is pointed to by the second parameter, and the
77third parameter holds its size.
78A
79.Vt fido_dev_io_write_t
80function may block.
81The number of bytes written is returned.
82On error, -1 is returned.
83.Pp
84No references to
85.Fa io
86are held by
87.Fn fido_dev_set_io_functions .
88.Sh RETURN VALUES
89On success,
90.Fn fido_dev_set_io_functions
91returns
92.Dv FIDO_OK .
93On error, a different error code defined in
94.In fido/err.h
95is returned.
96