freefare

Crates.iofreefare
lib.rsfreefare
version
sourcesrc
created_at2016-06-19 19:10:33.855927
updated_at2024-12-21 16:04:46.540474
descriptionRust bindings for the libfreefare library
homepagehttps://github.com/dsgriffin/freefare
repositoryhttps://github.com/dsgriffin/freefare
max_upload_size
id5426
Cargo.toml error:TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Daniel Griffin (dsgriffin)

documentation

https://github.com/dsgriffin/freefare

README

freefare

Crates.io

Rust bindings for the libfreefare library.

For raw FFI bindings for libfreefare, see freefare-sys.

Requirements

You need to install libfreefare and libnfc before using this crate.

Ubuntu + APT

sudo apt install libfreefare-dev libnfc-dev

MacOS + Homebrew

brew install libfreefare libnfc

Custom Paths

If the two libraries above are not installed in the standard APT or Homebrew locations, you can override the following environment variables:

  • LIBFREEFARE_PATH: Path to libfreefare (e.g. /path/to/libfreefare/lib).
  • LIBNFC_PATH: Path to libnfc (e.g. /path/to/libnfc/lib).

See build.rs for more details on how it works if needed.

Usage

Add both libc and freefare as dependencies in your Cargo.toml.

[dependencies]
libc = "0.2.0"
freefare = "0.3.0"

Example

extern crate freefare;

use freefare::freefare::Freefare;
use freefare::mifare::Mifare;

fn main() {
    let tag = /* Assume a valid FreefareTag obtained elsewhere */

    // Get friendly name of a tag
    match Freefare::get_tag_friendly_name(tag) {
        Ok(name) => println!("Tag friendly name: {}", name),
        Err(e) => eprintln!("Failed to get tag friendly name: {}", e),
    };

    // Write data to a Mifare Classic block
    let block = 4; // Example block number
    let data: [u8; 16] = [0xDE, 0xAD, 0xBE, 0xEF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B];
    match Mifare::classic_write(tag, block, &data) {
        Ok(_) => println!("Data written to block {}.", block),
        Err(e) => eprintln!("Failed to write data: {}", e),
    }

    // Read data from a Mifare Classic block
    let mut read_buffer = [0u8; 16];
    match Mifare::classic_read(tag, block, &mut read_buffer) {
        Ok(_) => println!("Read data from block {}: {:?}", block, read_buffer),
        Err(e) => eprintln!("Failed to read data: {}", e),
    }

    // Disconnect the tag
    match Mifare::classic_disconnect(tag) {
        Ok(_) => println!("Tag disconnected."),
        Err(e) => eprintln!("Failed to disconnect tag: {}", e),
    }

    // Etc...
}

Contributing

If you've found a bug or have an idea, feel free to open an Issue. If you've got a fix or feature ready, open a PR. Thanks!

License

MIT

Commit count: 21

cargo fmt