---
name: "fido_dev_set_io_functions"
section: "3"
platform: "linux"
package: "libfido2"
version: "1.17.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/fido_dev_set_io_functions"
---

# fido\_dev\_set\_io\_functions(3)

FIDO2 device I/O interface

## NAME

**fido\_dev\_set\_io\_functions**, **fido\_dev\_set\_sigmask**, **fido\_dev\_set\_timeout**, **fido\_dev\_set\_transport\_functions**, **fido\_dev\_io\_handle** – FIDO2 device I/O interface

## SYNOPSIS

**#include \<fido.h\>**

```
typedef void *fido_dev_io_open_t(const char *);
typedef void  fido_dev_io_close_t(void *);
typedef int   fido_dev_io_read_t(void *, unsigned char *, size_t, int);
typedef int   fido_dev_io_write_t(void *, const unsigned char *, size_t);
typedef struct fido_dev_io {
	fido_dev_io_open_t  *open;
	fido_dev_io_close_t *close;
	fido_dev_io_read_t  *read;
	fido_dev_io_write_t *write;
} fido_dev_io_t;
#ifdef _WIN32
typedef int fido_sigset_t;
#else
typedef sigset_t fido_sigset_t;
#endif
typedef int   fido_dev_rx_t(struct fido_dev *,
                  uint8_t, unsigned char *, size_t, int);
typedef int   fido_dev_tx_t(struct fido_dev *,
                  uint8_t, const unsigned char *, size_t);
typedef struct fido_dev_transport {
	fido_dev_rx_t *rx;
	fido_dev_tx_t *tx;
} fido_dev_transport_t;
```

*int*\

**fido\_dev\_set\_io\_functions**(*fido\_dev\_t \*dev*, *const fido\_dev\_io\_t \*io*);

*int*\

**fido\_dev\_set\_sigmask**(*fido\_dev\_t \*dev*, *const fido\_sigset\_t \*sigmask*);

*int*\

**fido\_dev\_set\_timeout**(*fido\_dev\_t \*dev*, *int ms*);

*int*\

**fido\_dev\_set\_transport\_functions**(*fido\_dev\_t \*dev*, *const fido\_dev\_transport\_t \*t*);

*void* *\**\

**fido\_dev\_io\_handle**(*const fido\_dev\_t \*dev*);

## DESCRIPTION

The **fido\_dev\_set\_io\_functions**() function sets the I/O handlers used by *libfido2* to talk to *dev*. By default, these handlers are set to the operating system's native HID or NFC interfaces. They are defined as follows:

- *fido\_dev\_open\_t*

  Receives a *const* *char* *\** holding a path and opens the corresponding device, returning a non-NULL opaque pointer on success and NULL on error.

- *fido\_dev\_close\_t*

  Receives the opaque pointer returned by *fido\_dev\_open\_t* and closes the device.

- *fido\_dev\_read\_t*

  Reads a single transmission unit (HID report, APDU) from a device. The first parameter is the opaque pointer returned by *fido\_dev\_open\_t*. The second parameter is the read buffer, and the third parameter is the read buffer size. The fourth parameter is the number of milliseconds the caller is willing to sleep, should the call need to block. If this value holds -1, *fido\_dev\_read\_t* may block indefinitely. On success, the number of bytes read is returned. On error, -1 is returned.

- *fido\_dev\_write\_t*

  Writes a single transmission unit (HID report, APDU) to *dev*. The first parameter is the opaque pointer returned by *fido\_dev\_open\_t*. The second parameter is the write buffer, and the third parameter is the number of bytes to be written. A *fido\_dev\_write\_t* may block. On success, the number of bytes written is returned. On error, -1 is returned.

When calling **fido\_dev\_set\_io\_functions**(), the *open*, *close*, *read*, and *write* fields of *io* may not be NULL.

No references to *io* are held by **fido\_dev\_set\_io\_functions**().

The **fido\_dev\_set\_sigmask**() function may be used to specify a non-NULL signal mask *sigmask* to be used while *libfido2's* default I/O handlers wait on *dev*. On UNIX-like operating systems, *fido\_sigset\_t* is defined as *sigset\_t*. On Windows, *fido\_sigset\_t* is defined as *int* and **fido\_dev\_set\_sigmask**() is a no-op.

No references to *sigmask* are held by **fido\_dev\_set\_sigmask**().

The **fido\_dev\_set\_timeout**() function informs *libfido2* not to block for more than *ms* milliseconds while communicating with *dev*. If a timeout occurs, the corresponding *fido\_dev\_\** function will fail with FIDO\_ERR\_RX. If *ms* is -1, then *libfido2* may block indefinitely. This is the default behaviour. When using the Windows Hello backend, *ms* is used as a guidance and may be overwritten by the platform.

The **fido\_dev\_set\_transport\_functions**() function sets the transport functions used by *libfido2* to talk to *dev*. While the I/O handlers are responsible for sending and receiving transmission units of initialization and continuation packets already formatted by *libfido2*, the transport handlers are responsible for sending and receiving the CTAPHID commands and data directly, as defined in the FIDO Client to Authenticator Protocol (CTAP) standard. They are defined as follows:

- *fido\_dev\_tx\_t*

  Receives a device, a CTAPHID command to transmit, a data buffer to transmit, and the length of the data buffer. On success, 0 is returned. On error, -1 is returned.

- *fido\_dev\_rx\_t*

  Receives a device, a CTAPHID command whose response the caller expects to receive, a data buffer to receive into, the size of the data buffer determining the maximum length of a response, and the maximum number of milliseconds to wait for a response. On success, the number of bytes read into the data buffer is returned. On error, -1 is returned.

When transport functions are specified, *libfido2* will use them instead of the read and write functions of the I/O handlers. However, the I/O handlers must still be specified to open and close the device.

The **fido\_dev\_io\_handle**() function returns the opaque pointer returned by the open function of the I/O handlers. This is useful mainly for the transport functions, which unlike the I/O handlers are passed the *fido\_dev\_t* pointer instead of the opaque I/O handle.

## RETURN VALUES

On success, **fido\_dev\_set\_io\_functions**(), **fido\_dev\_set\_transport\_functions**(), **fido\_dev\_set\_sigmask**(), and **fido\_dev\_set\_timeout**() return FIDO\_OK. On error, a different error code defined in ⟨fido/err.h⟩ is returned.

## SEE ALSO

[fido\_dev\_info\_manifest(3)](/fido_dev_info_manifest/3.md), [fido\_dev\_open(3)](/fido_dev_open/3.md) Client to Authenticator Protocol (CTAP), FIDO Alliance, 2021-06-15, Proposed Standard, Version 2.1, https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-20210615.html.
