Skip to main content

Context

Struct Context 

Source
pub struct Context { /* private fields */ }

Implementations§

Source§

impl Context

Source

pub fn new() -> Result<Self>

Examples found in repository?
examples/list_readers.rs (line 5)
4fn main() -> BoxResult<()> {
5	let mut context = nfc1::Context::new()?;
6	let devices = context.list_devices(10)?;
7	for device in &devices {
8		println!("{}", device)
9	}
10	Ok(())
11}
More examples
Hide additional examples
examples/get_reader_info.rs (line 6)
4fn main() -> BoxResult<()> {
5	let connstring = std::env::args().nth(1).ok_or("no connection string provided")?;
6	let mut context = nfc1::Context::new()?;
7	let mut device = context.open_with_connstring(&connstring)?;
8	println!("name: {}", device.name());
9	println!("connstring: {}", device.connstring());
10	println!("{}", device.get_information_about()?);
11	Ok(())
12}
examples/detect_magic_target.rs (line 9)
8fn main() -> nfc1::Result<()> {
9	let mut context = nfc1::Context::new()?;
10	let mut device = context.open()?;
11	print!("NFC reader: {} opened\n\n", device.name());
12	device.initiator_init()?;
13
14	// Configure the CRC
15	device.set_property_bool(nfc1::Property::HandleCrc, false)?;
16	// Use raw send/receive methods
17	device.set_property_bool(nfc1::Property::EasyFraming, false)?;
18	// Disable 14443-4 autoswitching
19	device.set_property_bool(nfc1::Property::AutoIso144434, false)?;
20
21	loop {
22		println!("Looking for targets...\n");
23		match device.initiator_select_passive_target(&nfc1::Modulation{
24			modulation_type: nfc1::ModulationType::Iso14443a,
25			baud_rate: nfc1::BaudRate::Baud106,
26		}) {
27			Ok(target) => {
28				print!("Target found: {}", target.to_string(false)?);
29				match device.initiator_transceive_bits(&UNLOCK_1, 7, MAX_FRAME_LEN) {
30					Ok(rx) => print!("Received bits: {:02X?}\n", rx),
31					Err(err) => {
32						print!("This is NOT a backdoored rewritable UID chinese card ({:?})\n", err);
33						sleep(Duration::from_secs(5));
34						print!("Looking for targets...\n");
35						continue;
36					},
37				};
38
39				match device.initiator_transceive_bytes(&UNLOCK_2, MAX_FRAME_LEN, nfc1::Timeout::Default){
40					Ok(rx) => {
41						print!("Received bytes: {:02X?}\n", rx);
42						print!("This is a backdoored rewritable UID chinese card\n")
43					},
44					Err(err) => print!("This is NOT a backdoored rewritable UID chinese card ({:?})\n", err),
45				};
46			},
47			Err(_) => { continue; }
48		}
49		sleep(Duration::from_secs(5));
50	}
51}
Source

pub fn open(&mut self) -> Result<Device>

Examples found in repository?
examples/detect_magic_target.rs (line 10)
8fn main() -> nfc1::Result<()> {
9	let mut context = nfc1::Context::new()?;
10	let mut device = context.open()?;
11	print!("NFC reader: {} opened\n\n", device.name());
12	device.initiator_init()?;
13
14	// Configure the CRC
15	device.set_property_bool(nfc1::Property::HandleCrc, false)?;
16	// Use raw send/receive methods
17	device.set_property_bool(nfc1::Property::EasyFraming, false)?;
18	// Disable 14443-4 autoswitching
19	device.set_property_bool(nfc1::Property::AutoIso144434, false)?;
20
21	loop {
22		println!("Looking for targets...\n");
23		match device.initiator_select_passive_target(&nfc1::Modulation{
24			modulation_type: nfc1::ModulationType::Iso14443a,
25			baud_rate: nfc1::BaudRate::Baud106,
26		}) {
27			Ok(target) => {
28				print!("Target found: {}", target.to_string(false)?);
29				match device.initiator_transceive_bits(&UNLOCK_1, 7, MAX_FRAME_LEN) {
30					Ok(rx) => print!("Received bits: {:02X?}\n", rx),
31					Err(err) => {
32						print!("This is NOT a backdoored rewritable UID chinese card ({:?})\n", err);
33						sleep(Duration::from_secs(5));
34						print!("Looking for targets...\n");
35						continue;
36					},
37				};
38
39				match device.initiator_transceive_bytes(&UNLOCK_2, MAX_FRAME_LEN, nfc1::Timeout::Default){
40					Ok(rx) => {
41						print!("Received bytes: {:02X?}\n", rx);
42						print!("This is a backdoored rewritable UID chinese card\n")
43					},
44					Err(err) => print!("This is NOT a backdoored rewritable UID chinese card ({:?})\n", err),
45				};
46			},
47			Err(_) => { continue; }
48		}
49		sleep(Duration::from_secs(5));
50	}
51}
Source

pub fn open_with_connstring(&mut self, connstring: &str) -> Result<Device>

Examples found in repository?
examples/get_reader_info.rs (line 7)
4fn main() -> BoxResult<()> {
5	let connstring = std::env::args().nth(1).ok_or("no connection string provided")?;
6	let mut context = nfc1::Context::new()?;
7	let mut device = context.open_with_connstring(&connstring)?;
8	println!("name: {}", device.name());
9	println!("connstring: {}", device.connstring());
10	println!("{}", device.get_information_about()?);
11	Ok(())
12}
Source

pub fn list_devices(&mut self, max: usize) -> Result<Vec<String>>

Examples found in repository?
examples/list_readers.rs (line 6)
4fn main() -> BoxResult<()> {
5	let mut context = nfc1::Context::new()?;
6	let devices = context.list_devices(10)?;
7	for device in &devices {
8		println!("{}", device)
9	}
10	Ok(())
11}

Trait Implementations§

Source§

impl Drop for Context

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for Context

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.