Skip to content

Commit 9461329

Browse files
committed
upd uhf rfid
1 parent f242900 commit 9461329

File tree

13 files changed

+341
-245
lines changed

13 files changed

+341
-245
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
App(
22
appid="uhf_rfid",
3-
name="[(Q)M100] UHF RFID",
3+
name="[YRM100] UHF RFID",
44
apptype=FlipperAppType.EXTERNAL,
55
targets=["f7"],
66
entry_point="uhf_app_main",
77
requires=[
88
"storage",
99
"gui",
1010
],
11-
stack_size=8 * 1024,
11+
stack_size=10 * 1024,
1212
order=30,
1313
fap_icon="icons/uhf_10px.png",
14-
fap_category="RFID",
14+
fap_category="GPIO",
1515
fap_icon_assets="icons",
1616
fap_icon_assets_symbol="uhf_rfid",
1717
)

non_catalog_apps/uhf_rfid/scenes/uhf_scene_settings.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
#include "../uhf_module.h"
33

44
void uhf_settings_set_module_baudrate(VariableItem* item) {
5-
M100Module* uhf_module = variable_item_get_context(item);
5+
M100Module* module = variable_item_get_context(item);
66
uint8_t index = variable_item_get_current_value_index(item);
77
if(index >= BAUD_RATES_COUNT) {
88
return;
99
}
1010
uint32_t baudrate = BAUD_RATES[index];
11-
m100_set_baudrate(uhf_module, baudrate);
11+
m100_set_baudrate(module, baudrate);
1212
char text_buf[10];
13-
snprintf(text_buf, sizeof(text_buf), "%lu", uhf_module->baudrate);
13+
snprintf(text_buf, sizeof(text_buf), "%lu", module->uart->baudrate);
1414
variable_item_set_current_value_text(item, text_buf);
1515
}
1616

@@ -40,7 +40,7 @@ void uhf_settings_set_module_working_region(VariableItem* item) {
4040

4141
uint8_t uhf_settings_get_module_baudrate_index(M100Module* module) {
4242
for(uint8_t i = 0; i < BAUD_RATES_COUNT; i++) {
43-
if(BAUD_RATES[i] == module->baudrate) {
43+
if(BAUD_RATES[i] == module->uart->baudrate) {
4444
return i;
4545
}
4646
}
@@ -73,7 +73,7 @@ void uhf_scene_settings_on_enter(void* ctx) {
7373

7474
uint8_t value_index = uhf_settings_get_module_baudrate_index(uhf_module);
7575
char text_buf[10];
76-
snprintf(text_buf, sizeof(text_buf), "%lu", uhf_module->baudrate);
76+
snprintf(text_buf, sizeof(text_buf), "%lu", uhf_module->uart->baudrate);
7777
item = variable_item_list_add(
7878
variable_item_list,
7979
"Baudrate:",

non_catalog_apps/uhf_rfid/uhf_app.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -201,25 +201,20 @@ int32_t uhf_app_main(void* ctx) {
201201
expansion_disable(expansion);
202202

203203
UHFApp* uhf_app = uhf_alloc();
204-
205204
// enable 5v pin
206-
uint8_t attempts = 0;
205+
uint8_t attempts = 0;
207206
bool otg_was_enabled = furi_hal_power_is_otg_enabled();
208207
while(!furi_hal_power_is_otg_enabled() && attempts++ < 5) {
209208
furi_hal_power_enable_otg();
210209
furi_delay_ms(10);
211210
}
212-
furi_delay_ms(200);
213-
// init pin a2
214-
// furi_hal_gpio_init_simple(&gpio_ext_pa7, GpioModeOutputPushPull);
211+
// enter app
215212
scene_manager_next_scene(uhf_app->scene_manager, UHFSceneModuleInfo);
216213
view_dispatcher_run(uhf_app->view_dispatcher);
217-
218214
// disable 5v pin
219-
if(furi_hal_power_is_otg_enabled() && !otg_was_enabled) {
215+
if(furi_hal_power_is_otg_enabled() && !otg_was_enabled) {
220216
furi_hal_power_disable_otg();
221217
}
222-
// furi_hal_gpio_disable_int_callback()
223218
// exit app
224219
uhf_free(uhf_app);
225220

non_catalog_apps/uhf_rfid/uhf_buffer.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <stdlib.h>
33
#include <string.h>
44

5-
Buffer* buffer_alloc(size_t initial_capacity) {
5+
Buffer* uhf_buffer_alloc(size_t initial_capacity) {
66
Buffer* buf = (Buffer*)malloc(sizeof(Buffer));
77
buf->data = (uint8_t*)malloc(sizeof(uint8_t) * initial_capacity);
88
if(!buf->data) {
@@ -14,7 +14,7 @@ Buffer* buffer_alloc(size_t initial_capacity) {
1414
return buf;
1515
}
1616

17-
bool buffer_append_single(Buffer* buf, uint8_t data) {
17+
bool uhf_buffer_append_single(Buffer* buf, uint8_t data) {
1818
if(buf->closed) return false;
1919
if(buf->size + 1 > buf->capacity) {
2020
size_t new_capacity = buf->capacity * 2;
@@ -27,7 +27,7 @@ bool buffer_append_single(Buffer* buf, uint8_t data) {
2727
return true;
2828
}
2929

30-
bool buffer_append(Buffer* buf, uint8_t* data, size_t data_size) {
30+
bool uhf_buffer_append(Buffer* buf, uint8_t* data, size_t data_size) {
3131
if(buf->closed) return false;
3232
if(buf->size + data_size > buf->capacity) {
3333
size_t new_capacity = buf->capacity * 2;
@@ -43,27 +43,31 @@ bool buffer_append(Buffer* buf, uint8_t* data, size_t data_size) {
4343
return true;
4444
}
4545

46-
uint8_t* buffer_get_data(Buffer* buf) {
46+
uint8_t* uhf_buffer_get_data(Buffer* buf) {
4747
return buf->data;
4848
}
4949

50-
size_t buffer_get_size(Buffer* buf) {
50+
size_t uhf_buffer_get_size(Buffer* buf) {
5151
return buf->size;
5252
}
5353

54-
void buffer_close(Buffer* buf) {
54+
bool uhf_is_buffer_closed(Buffer* buf) {
55+
return buf->closed;
56+
}
57+
58+
void uhf_buffer_close(Buffer* buf) {
5559
buf->closed = true;
5660
}
5761

58-
void buffer_reset(Buffer* buf) {
62+
void uhf_buffer_reset(Buffer* buf) {
5963
for(size_t i = 0; i < MAX_BUFFER_SIZE; i++) {
6064
buf->data[i] = 0;
6165
}
6266
buf->size = 0;
6367
buf->closed = false;
6468
}
6569

66-
void buffer_free(Buffer* buf) {
70+
void uhf_buffer_free(Buffer* buf) {
6771
free(buf->data);
6872
free(buf);
6973
}

non_catalog_apps/uhf_rfid/uhf_buffer.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ typedef struct Buffer {
1212
bool closed;
1313
} Buffer;
1414

15-
Buffer* buffer_alloc(size_t inital_capacity);
16-
bool buffer_append_single(Buffer* buf, uint8_t value);
17-
bool buffer_append(Buffer* buf, uint8_t* data, size_t size);
18-
uint8_t* buffer_get_data(Buffer* buf);
19-
size_t buffer_get_size(Buffer* buf);
20-
void buffer_close(Buffer* buf);
21-
void buffer_reset(Buffer* buf);
22-
void buffer_free(Buffer* buf);
15+
Buffer* uhf_buffer_alloc(size_t inital_capacity);
16+
bool uhf_buffer_append_single(Buffer* buf, uint8_t value);
17+
bool uhf_buffer_append(Buffer* buf, uint8_t* data, size_t size);
18+
19+
uint8_t* uhf_buffer_get_data(Buffer* buf);
20+
size_t uhf_buffer_get_size(Buffer* buf);
21+
bool uhf_is_buffer_closed(Buffer* buf);
22+
void uhf_buffer_close(Buffer* buf);
23+
void uhf_buffer_reset(Buffer* buf);
24+
void uhf_buffer_free(Buffer* buf);

non_catalog_apps/uhf_rfid/uhf_device.c

Lines changed: 1 addition & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
static const char* uhf_file_header = "Flipper UHF RFID device";
99
static const uint32_t uhf_file_version = 1;
10-
// static const uint8_t bank_data_start = 20;
11-
// static const uint8_t bank_data_length = 16;
1210

1311
UHFDevice* uhf_device_alloc() {
1412
UHFDevice* uhf_device = malloc(sizeof(UHFDevice));
@@ -178,15 +176,6 @@ static bool uhf_device_load_data(UHFDevice* dev, FuriString* path, bool show_dia
178176
return parsed;
179177
}
180178

181-
// void picopass_device_clear(UHFDevice* dev) {
182-
// furi_assert(dev);
183-
184-
// picopass_device_data_clear(&dev->dev_data);
185-
// memset(&dev->dev_data, 0, sizeof(dev->dev_data));
186-
// dev->format = PicopassDeviceSaveFormatHF;
187-
// furi_string_reset(dev->load_path);
188-
// }
189-
190179
void uhf_device_free(UHFDevice* uhf_dev) {
191180
furi_assert(uhf_dev);
192181
furi_record_close(RECORD_STORAGE);
@@ -224,16 +213,6 @@ bool uhf_file_select(UHFDevice* dev) {
224213
return res;
225214
}
226215

227-
// void uhf_device_data_clear(UHFDevice* dev_data) {
228-
// for(size_t i = 0; i < PICOPASS_MAX_APP_LIMIT; i++) {
229-
// memset(dev_data->AA1[i].data, 0, sizeof(dev_data->AA1[i].data));
230-
// }
231-
// dev_data->pacs.legacy = false;
232-
// dev_data->pacs.se_enabled = false;
233-
// dev_data->pacs.elite_kdf = false;
234-
// dev_data->pacs.pin_length = 0;
235-
// }
236-
237216
bool uhf_device_delete(UHFDevice* dev, bool use_load_path) {
238217
furi_assert(dev);
239218

@@ -265,84 +244,4 @@ void uhf_device_set_loading_callback(UHFDevice* dev, UHFLoadingCallback callback
265244

266245
dev->loading_cb = callback;
267246
dev->loading_cb_ctx = context;
268-
}
269-
270-
// ReturnCode picopass_device_decrypt(uint8_t* enc_data, uint8_t* dec_data) {
271-
// uint8_t key[32] = {0};
272-
// memcpy(key, picopass_iclass_decryptionkey, sizeof(picopass_iclass_decryptionkey));
273-
// mbedtls_des3_context ctx;
274-
// mbedtls_des3_init(&ctx);
275-
// mbedtls_des3_set2key_dec(&ctx, key);
276-
// mbedtls_des3_crypt_ecb(&ctx, enc_data, dec_data);
277-
// mbedtls_des3_free(&ctx);
278-
// return ERR_NONE;
279-
// }
280-
281-
// ReturnCode picopass_device_parse_credential(PicopassBlock* AA1, PicopassPacs* pacs) {
282-
// ReturnCode err;
283-
284-
// pacs->biometrics = AA1[6].data[4];
285-
// pacs->pin_length = AA1[6].data[6] & 0x0F;
286-
// pacs->encryption = AA1[6].data[7];
287-
288-
// if(pacs->encryption == PicopassDeviceEncryption3DES) {
289-
// FURI_LOG_D(TAG, "3DES Encrypted");
290-
// err = picopass_device_decrypt(AA1[7].data, pacs->credential);
291-
// if(err != ERR_NONE) {
292-
// FURI_LOG_E(TAG, "decrypt error %d", err);
293-
// return err;
294-
// }
295-
296-
// err = picopass_device_decrypt(AA1[8].data, pacs->pin0);
297-
// if(err != ERR_NONE) {
298-
// FURI_LOG_E(TAG, "decrypt error %d", err);
299-
// return err;
300-
// }
301-
302-
// err = picopass_device_decrypt(AA1[9].data, pacs->pin1);
303-
// if(err != ERR_NONE) {
304-
// FURI_LOG_E(TAG, "decrypt error %d", err);
305-
// return err;
306-
// }
307-
// } else if(pacs->encryption == PicopassDeviceEncryptionNone) {
308-
// FURI_LOG_D(TAG, "No Encryption");
309-
// memcpy(pacs->credential, AA1[7].data, PICOPASS_BLOCK_LEN);
310-
// memcpy(pacs->pin0, AA1[8].data, PICOPASS_BLOCK_LEN);
311-
// memcpy(pacs->pin1, AA1[9].data, PICOPASS_BLOCK_LEN);
312-
// } else if(pacs->encryption == PicopassDeviceEncryptionDES) {
313-
// FURI_LOG_D(TAG, "DES Encrypted");
314-
// } else {
315-
// FURI_LOG_D(TAG, "Unknown encryption");
316-
// }
317-
318-
// pacs->sio = (AA1[10].data[0] == 0x30); // rough check
319-
320-
// return ERR_NONE;
321-
// }
322-
323-
// ReturnCode picopass_device_parse_wiegand(uint8_t* data, PicopassWiegandRecord* record) {
324-
// uint32_t* halves = (uint32_t*)data;
325-
// if(halves[0] == 0) {
326-
// uint8_t leading0s = __builtin_clz(REVERSE_BYTES_U32(halves[1]));
327-
// record->bitLength = 31 - leading0s;
328-
// } else {
329-
// uint8_t leading0s = __builtin_clz(REVERSE_BYTES_U32(halves[0]));
330-
// record->bitLength = 63 - leading0s;
331-
// }
332-
// FURI_LOG_D(TAG, "bitLength: %d", record->bitLength);
333-
334-
// if(record->bitLength == 26) {
335-
// uint8_t* v4 = data + 4;
336-
// uint32_t bot = v4[3] | (v4[2] << 8) | (v4[1] << 16) | (v4[0] << 24);
337-
338-
// record->CardNumber = (bot >> 1) & 0xFFFF;
339-
// record->FacilityCode = (bot >> 17) & 0xFF;
340-
// FURI_LOG_D(TAG, "FC: %u CN: %u", record->FacilityCode, record->CardNumber);
341-
// record->valid = true;
342-
// } else {
343-
// record->CardNumber = 0;
344-
// record->FacilityCode = 0;
345-
// record->valid = false;
346-
// }
347-
// return ERR_NONE;
348-
// }
247+
}

0 commit comments

Comments
 (0)