| Crates.io | freefare |
| lib.rs | freefare |
| version | 0.3.0 |
| created_at | 2016-06-19 19:10:33.855927+00 |
| updated_at | 2024-12-21 16:04:46.540474+00 |
| description | Rust bindings for the libfreefare library |
| homepage | https://github.com/dsgriffin/freefare |
| repository | https://github.com/dsgriffin/freefare |
| max_upload_size | |
| id | 5426 |
| size | 113,849 |
Rust bindings for the libfreefare library.
For raw FFI bindings for libfreefare, see freefare-sys.
You need to install libfreefare and libnfc before using this crate.
sudo apt install libfreefare-dev libnfc-dev
brew install libfreefare libnfc
If the two libraries above are not installed in the standard APT or Homebrew locations, you can override the following environment variables:
See build.rs for more details on how it works if needed.
Add both libc and freefare as dependencies in your Cargo.toml.
[dependencies]
libc = "0.2.0"
freefare = "0.3.0"
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...
}
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!
MIT