1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#![crate_name = "nfc"]
#![crate_type = "dylib"]

extern crate libc;

pub mod ffi;

pub mod initiator;
pub mod target;
pub mod device;
pub mod context;
pub mod error;
pub mod misc;
pub mod to_str;

use libc::size_t;

// Library initialization/deinitialization
// See http://www.libnfc.org/api/group__lib.html

/// Registers an NFC device driver with libnfc
pub fn register_driver(ndr: *const ffi::nfc_driver) -> i32 {
    unsafe { ffi::nfc_register_driver(ndr) }
}

/// Initializes libnfc. This function must be called before calling any other libnfc function
pub fn init(context: *mut *mut ffi::nfc_context) {
    unsafe { ffi::nfc_init(context); }
}

/// Deinitializes libnfc. Should be called after closing all open devices and before your application terminates
pub fn exit(context: *mut ffi::nfc_context) {
    unsafe { ffi::nfc_exit(context); }
}

// NFC Device/Hardware manipulation
// http://www.libnfc.org/api/group__dev.html

/// Open an NFC device
pub fn open(context: *mut ffi::nfc_context, connstring: *const ffi::nfc_connstring) -> *mut ffi::nfc_device {
    unsafe { ffi::nfc_open(context, connstring) }
}

/// Close from a NFC device
pub fn close(pnd: *mut ffi::nfc_device) {
    unsafe { ffi::nfc_close(pnd); }
}

/// Scan for discoverable supported devices
pub fn list_devices(context: *mut ffi::nfc_context, connstrings: *mut ffi::nfc_connstring, constrings_len: size_t) -> size_t {
    unsafe { ffi::nfc_list_devices(context, connstrings, constrings_len) }
}

/// Switches the NFC device to idle mode
pub fn idle(pnd: *mut ffi::nfc_device) -> i32 {
    unsafe { ffi::nfc_idle(pnd) }
}

/// Aborts current running command
pub fn abort_command(pnd: *mut ffi::nfc_device) -> i32 {
    unsafe { ffi::nfc_abort_command(pnd) }
}