Skip to content

Commit 0b42e28

Browse files
committed
explore: test rfid read/write secured
1 parent fae4d67 commit 0b42e28

File tree

3 files changed

+56
-19
lines changed

3 files changed

+56
-19
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ embedded-hal-bus = { version = "0.3.0", features = ["async"] }
4444
embedded-tls = { version = "0.17.0", default-features = false, features = ["alloc", "embedded-io-adapters", "log"] }
4545
rand_core = { version = "0.6.4", features = ["getrandom"] }
4646
ag-lcd-async = { git = "https://github.com/filipton/ag-lcd-async", features = [] }
47-
esp-hal-mfrc522 = { version = "0.3.0", features = ["embassy-time"] }
47+
esp-hal-mfrc522 = { version = "0.3.2", features = ["embassy-time"] }
4848
esp-bootloader-esp-idf = { version = "0.2.0", features = ["log-04", "esp32c3"] }
4949

5050
[features]

src/rfid.rs

Lines changed: 53 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -104,22 +104,6 @@ pub async fn rfid_task(
104104
let card_uid = card.get_number();
105105
log::info!("Card UID: {card_uid}");
106106

107-
// TODO: check read
108-
let status = mfrc522
109-
.pcd_authenticate(
110-
esp_hal_mfrc522::consts::PICCCommand::PICC_CMD_MF_AUTH_KEY_A,
111-
1,
112-
&[0x42, 0x0, 0x69, 0x12, 0x15, 0x9A], // test read key
113-
&card,
114-
)
115-
.await;
116-
if status.is_ok() {
117-
let mut buff = [0; 18];
118-
let mut byte_count = 18;
119-
let res = mfrc522.mifare_read(1, &mut buff, &mut byte_count).await;
120-
log::info!("read: {res:?}, data: {buff:#?}");
121-
}
122-
123107
let last_scan_time = (Instant::now().saturating_duration_since(last_card.1)).as_millis();
124108
if last_card.0 == card_uid && last_scan_time < 500 {
125109
log::warn!(
@@ -140,9 +124,60 @@ pub async fn rfid_task(
140124

141125
if unsafe { !crate::state::TRUST_SERVER } {
142126
log::error!("Skipping card scan. Server not trusted!");
127+
_ = mfrc522.picc_halta().await;
143128
continue;
144129
}
145130

131+
// TODO: WRITE SECURED
132+
/*
133+
let status = mfrc522
134+
.pcd_authenticate(
135+
esp_hal_mfrc522::consts::PICCCommand::PICC_CMD_MF_AUTH_KEY_A,
136+
63,
137+
&[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF],
138+
&card,
139+
)
140+
.await;
141+
log::info!("auth status: {status:?}");
142+
if status.is_ok() {
143+
let mut buff = [0; 18];
144+
let mut byte_count = 18;
145+
let res = mfrc522.mifare_read(63, &mut buff, &mut byte_count).await;
146+
log::info!("read: {res:?}, data: {buff:#?}");
147+
148+
let mut custom_key = [0x69, 0x42, 0x00, 0x13, 0x56, 0xAE];
149+
150+
buff[..6].copy_from_slice(&custom_key);
151+
buff[6] = 0xFF;
152+
buff[7] = 0x07;
153+
buff[8] = 0x80;
154+
buff[9] = 0x69;
155+
buff[10..16].copy_from_slice(&custom_key);
156+
157+
let res = mfrc522.mifare_write(63, &buff, 16).await;
158+
log::info!("write res: {res:?}");
159+
}
160+
*/
161+
162+
// TODO: READ SECURED
163+
/*
164+
let status = mfrc522
165+
.pcd_authenticate(
166+
esp_hal_mfrc522::consts::PICCCommand::PICC_CMD_MF_AUTH_KEY_A,
167+
63,
168+
&[0x69, 0x42, 0x00, 0x13, 0x56, 0xAE],
169+
&card,
170+
)
171+
.await;
172+
log::info!("auth status2: {status:?}");
173+
if status.is_ok() {
174+
let mut buff = [0; 18];
175+
let mut byte_count = 18;
176+
let res = mfrc522.mifare_read(62, &mut buff, &mut byte_count).await;
177+
log::info!("read: {res:?}, data: {buff:#?}");
178+
}
179+
*/
180+
146181
let resp = crate::ws::send_request::<CardInfoResponsePacket>(
147182
crate::structs::TimerPacketInner::CardInfoRequest {
148183
card_id: card_uid as u64,
@@ -180,7 +215,9 @@ pub async fn rfid_task(
180215
#[cfg(not(feature = "e2e"))]
181216
{
182217
_ = mfrc522.picc_halta().await;
218+
_ = mfrc522.pcd_stop_crypto1().await;
183219
}
220+
embassy_time::Timer::after_secs(1).await;
184221
}
185222
}
186223

0 commit comments

Comments
 (0)