Skip to main content

Crate nfc_sys

Crate nfc_sys 

Source
Expand description

Raw Rust FFI bindings for libnfc.

This crate follows the usual *-sys crate pattern: it exposes libnfc’s C API with minimal translation and does not manage ownership, lifetimes, or error handling for you. Most useful calls are unsafe because callers must satisfy the same requirements as the corresponding native libnfc functions.

The nfc_context, nfc_device, and nfc_driver types are opaque because libnfc treats them as incomplete public types. Use the accessor and lifecycle functions exported by libnfc instead of relying on their internal layout.

§Linking

The build script links against a system-provided libnfc. On macOS it checks common Homebrew locations. For custom installations, set LIBNFC_LIB_DIR to the directory containing the native library.

§Example

use std::ffi::CStr;
use std::ptr;

use nfc_sys::{nfc_exit, nfc_init, nfc_version};

unsafe {
    let mut context = ptr::null_mut();
    nfc_init(&mut context);

    if !context.is_null() {
        let version = CStr::from_ptr(nfc_version()).to_string_lossy();
        println!("libnfc version: {}", version);

        nfc_exit(context);
    }
}

Structs§

nfc_barcode_info
nfc_context
Opaque libnfc context handle.
nfc_dep_info
nfc_device
Opaque libnfc device handle.
nfc_driver
Opaque libnfc driver handle.
nfc_emulation_state_machine
nfc_emulator
nfc_felica_info
nfc_iso14443a_info
nfc_iso14443b2ct_info
nfc_iso14443b2sr_info
nfc_iso14443b_info
nfc_iso14443bi_info
nfc_iso14443biclass_info
nfc_jewel_info
nfc_modulation
nfc_target

Enums§

nfc_baud_rate
nfc_dep_mode
nfc_mode
nfc_modulation_type
nfc_property

Constants§

NFC_BUFSIZE_CONNSTRING
NFC_ECHIP
NFC_EDEVNOTSUPP
NFC_EINVARG
NFC_EIO
NFC_EMFCAUTHFAIL
NFC_ENOTIMPL
NFC_ENOTSUCHDEV
NFC_EOPABORTED
NFC_EOVFLOW
NFC_ERFTRANS
NFC_ESOFT
NFC_ETGRELEASED
NFC_ETIMEOUT
NFC_SUCCESS
NMT_END_ENUM

Functions§

iso14443a_crc
iso14443a_crc_append
iso14443a_locate_historical_bytes
iso14443b_crc
iso14443b_crc_append
nfc_abort_command
nfc_close
nfc_device_get_connstring
nfc_device_get_information_about
nfc_device_get_last_error
nfc_device_get_name
nfc_device_get_supported_baud_rate
nfc_device_get_supported_baud_rate_target_mode
nfc_device_get_supported_modulation
nfc_device_set_property_bool
nfc_device_set_property_int
nfc_emulate_target
nfc_exit
nfc_free
nfc_idle
nfc_init
nfc_initiator_deselect_target
nfc_initiator_init
nfc_initiator_init_secure_element
nfc_initiator_list_passive_targets
nfc_initiator_poll_dep_target
nfc_initiator_poll_target
nfc_initiator_select_dep_target
nfc_initiator_select_passive_target
nfc_initiator_target_is_present
nfc_initiator_transceive_bits
nfc_initiator_transceive_bits_timed
nfc_initiator_transceive_bytes
nfc_initiator_transceive_bytes_timed
nfc_list_devices
nfc_open
nfc_perror
nfc_register_driver
nfc_strerror
nfc_strerror_r
nfc_target_init
nfc_target_receive_bits
nfc_target_receive_bytes
nfc_target_send_bits
nfc_target_send_bytes
nfc_version
str_nfc_baud_rate
str_nfc_modulation_type
str_nfc_target

Type Aliases§

nfc_connstring

Unions§

nfc_target_info