Freefare
Safe Rust bindings to the libfreefare library :nut_and_bolt:
Install / Use
/learn @dsgriffin/FreefareREADME
freefare
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
Related Skills
himalaya
348.2kCLI to manage emails via IMAP/SMTP. Use `himalaya` to list, read, write, reply, forward, search, and organize emails from the terminal. Supports multiple accounts and message composition with MML (MIME Meta Language).
node-connect
348.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
taskflow
348.2kname: taskflow description: Use when work should span one or more detached tasks but still behave like one job with a single owner context. TaskFlow is the durable flow substrate under authoring layer
frontend-design
108.9kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
