pub struct Context { /* private fields */ }Implementations§
Source§impl Context
impl Context
Sourcepub fn new() -> Result<Self>
pub fn new() -> Result<Self>
Examples found in repository?
More examples
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}Sourcepub fn open(&mut self) -> Result<Device>
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}Sourcepub fn open_with_connstring(&mut self, connstring: &str) -> Result<Device>
pub fn open_with_connstring(&mut self, connstring: &str) -> Result<Device>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Context
impl RefUnwindSafe for Context
impl !Sync for Context
impl Unpin for Context
impl UnwindSafe for Context
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more