Skip to content

Commit

Permalink
add uhf rfid app WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
xMasterX committed Aug 13, 2023
1 parent 8dda636 commit 718aaa3
Show file tree
Hide file tree
Showing 37 changed files with 2,414 additions and 0 deletions.
1 change: 1 addition & 0 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ Games:
## RFID
- [RFID Beacon (by nmrr)](https://github.com/nmrr/flipperzero-rfidbeacon) - `A letter/number Morse beacon on 125 kHz`
- [EM4100 universal keys generator (for RFID Fuzzer) (by Milk-Cool)](https://github.com/Milk-Cool/fz-em4100-generator)
- [YRM100 UHF RFID (by frux-c)](https://github.com/frux-c/uhf_rfid) -> WIP -> (+Added icon by @xMasterX)

## Sub-GHz
- [Enhanced Sub-GHz Chat (by twisted-pear)](https://github.com/twisted-pear/esubghz_chat)
Expand Down
144 changes: 144 additions & 0 deletions non_catalog_apps/uhf_rfid/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# [UHF]RFID App for FlipperZero

![FlipperZero](assets/img/uhf_demo_app.jpg)

## Overview

This repository contains a UHF RFID application developed for FlipperZero, a versatile multi-tool device. The app leverages the YRM100 module to enable UHF RFID functionality.

## Features

- [x] Read Single UHF RFID tag.
- [x] View saved UHF RFID tag.
- [ ] Write Single UHF RFID tag. __(in progress)__
- [ ] Change Module setting parameters.
- [ ] Easy-to-use interface on FlipperZero's display.
- Extras
- [ ] Read multiple tags at once
- [ ] View multiple on a list view

## Requirements

To run this application on FlipperZero, you will need:

- FlipperZero device (purchase from [Flipper Devices](https://www.flipperdevices.com))
- YRM100 UHF RFID module (purchase from [Ali-Express](https://www.aliexpress.com/item/1005005296512846.html))

## Setup and Installation

1. Ensure you have set up your FlipperZero device with the YRM100 module properly. You can also read more about how to setup the module from the [Md5Stack Docs page](http://docs.m5stack.com/en/unit/uhf_rfid).
![wiring diagram](https://static-cdn.m5stack.com/resource/docs/products/unit/uhf_rfid/uhf_rfid_sch_01.webp)
2. Clone this repository to the `applications_user` folder of your flipper firmware of your choice
3. If you have VSCode setup with your flipper firmware.
- ### Windows
1. Press `Ctrl+Shift+B` on vscode while in the uhf_app folder
2. Select the `Launch App on Flipper` option. And watch as the app launches on your flipper
- If you don't have vscode setup you can use the cli command `./fbt COMPACT=1 DEBUG=0 launch APPSRC=applications_user\uhf_rfid`
- ### MacOS
... tbd

## Usage

1. Power on your FlipperZero device.
2. Connect the uhf module to the flipper via gpio.
3. Navigate to the UHF RFID app on FlipperZero's menu.
4. Currently Reading the EPC tag is the only usable option
... will further update this page as it development goes

## Contributions

As this app is still in the development stage, I welcome contributions to this project. If you find any issues or want to enhance the application, feel free to create a pull request.

<!-- ## License
This project is licensed under the [MIT License](link_to_license_file). -->

## Future Plans
- Code cleanup
- Build a framework around the chip communication commands
- Build a proper tag class
```c
// Ideal concept
#include <stdint.h>
#include <stdio.h>
#include <string.h>

typedef struct {
int uart_fd; // UART file descriptor or other identifier
} YRM100_RFID;

void sendCommand(YRM100_RFID *rfid, const uint8_t *command, size_t length) {
// Implementation to send the command through UART
// Write the command to the UART interface using rfid->uart_fd
}

// Configuration functions:

void setCommunicationBaudRate(YRM100_RFID *rfid) {
uint8_t command[] = {0xBB, 0x00, 0x11, 0x00, 0x02, 0x00, 0xC0, 0xD3, 0x7E};
sendCommand(rfid, command, sizeof(command));
}

void setWorkingArea(YRM100_RFID *rfid, uint8_t area) {
uint8_t command[] = {0xBB, 0x00, 0x07, 0x00, 0x01, area, 0x09, 0x7E};
sendCommand(rfid, command, sizeof(command));
}

// other method etc ...
```
```c
// Ideal concept
#include <stdint.h>
#include <stdlib.h>
typedef struct {
uint8_t *killPassword;
uint8_t *accessPassword;
size_t size;
} ReservedMemory;
typedef struct {
uint8_t *header;
uint8_t *filter;
uint8_t *partition;
uint8_t *companyPrefix;
uint8_t *itemReference;
size_t size;
} EPCMemory;
typedef struct {
uint8_t *tid;
size_t size;
} TIDMemory;
typedef struct {
uint8_t *userMemory;
size_t size;
} UserMemory;
typedef struct {
ReservedMemory reserved;
EPCMemory epc;
TIDMemory tid;
UserMemory user;
} ISO18000_6C_Tag;
```

## Disclaimer

- This application is provided as-is and may contain bugs or issues.
- Use it at your own risk.
- I am not responsible for any damage or loss caused by the usage of this app.

## Extra Resources

- [MagicRF M100&QM100_Firmware_manual_en.pdf](assets/res/MagicRF_M100&QM100_Firmware_manual_en.pdf)

## Contact

For any inquiries or support, you can reach out to us at :

- Personal Email : [[email protected]](mailto:[email protected])
- Discord Server: [Flipper Zero Tutorial-Unoffical by @jamisonderek](https://discord.gg/REunuAnTX9)
- Discord User: [frux.c]()
17 changes: 17 additions & 0 deletions non_catalog_apps/uhf_rfid/application.fam
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
App(
appid="uhf_rfid",
name="[YRM100] UHF RFID",
apptype=FlipperAppType.EXTERNAL,
targets=["f7"],
entry_point="uhf_app_main",
requires=[
"storage",
"gui",
],
stack_size=4 * 1024,
order=30,
fap_icon="uhf_10px.png",
fap_category="RFID",
fap_icon_assets="icons",
fap_icon_assets_symbol="uhf_rfid",
)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added non_catalog_apps/uhf_rfid/icons/Nfc_10px.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions non_catalog_apps/uhf_rfid/scenes/uhf_scene.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "uhf_scene.h"

// Generate scene on_enter handlers array
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
void (*const uhf_on_enter_handlers[])(void*) = {
#include "uhf_scene_config.h"
};
#undef ADD_SCENE

// Generate scene on_event handlers array
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event,
bool (*const uhf_on_event_handlers[])(void* context, SceneManagerEvent event) = {
#include "uhf_scene_config.h"
};
#undef ADD_SCENE

// Generate scene on_exit handlers array
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_exit,
void (*const uhf_on_exit_handlers[])(void* context) = {
#include "uhf_scene_config.h"
};
#undef ADD_SCENE

// Initialize scene handlers configuration structure
const SceneManagerHandlers uhf_scene_handlers = {
.on_enter_handlers = uhf_on_enter_handlers,
.on_event_handlers = uhf_on_event_handlers,
.on_exit_handlers = uhf_on_exit_handlers,
.scene_num = UHFSceneNum,
};
29 changes: 29 additions & 0 deletions non_catalog_apps/uhf_rfid/scenes/uhf_scene.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

#include <gui/scene_manager.h>

// Generate scene id and total number
#define ADD_SCENE(prefix, name, id) UHFScene##id,
typedef enum {
#include "uhf_scene_config.h"
UHFSceneNum,
} UHFScene;
#undef ADD_SCENE

extern const SceneManagerHandlers uhf_scene_handlers;

// Generate scene on_enter handlers declaration
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*);
#include "uhf_scene_config.h"
#undef ADD_SCENE

// Generate scene on_event handlers declaration
#define ADD_SCENE(prefix, name, id) \
bool prefix##_scene_##name##_on_event(void* context, SceneManagerEvent event);
#include "uhf_scene_config.h"
#undef ADD_SCENE

// Generate scene on_exit handlers declaration
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_exit(void* context);
#include "uhf_scene_config.h"
#undef ADD_SCENE
62 changes: 62 additions & 0 deletions non_catalog_apps/uhf_rfid/scenes/uhf_scene_card_menu.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include "../uhf_app_i.h"

enum SubmenuIndex {
SubmenuIndexSave,
SubmenuIndexChangeKey,
};

void uhf_scene_card_menu_submenu_callback(void* ctx, uint32_t index) {
UHFApp* uhf_app = ctx;
view_dispatcher_send_custom_event(uhf_app->view_dispatcher, index);
}

void uhf_scene_card_menu_on_enter(void* ctx) {
UHFApp* uhf_app = ctx;

Submenu* submenu = uhf_app->submenu;

submenu_add_item(
submenu, "Save", SubmenuIndexSave, uhf_scene_card_menu_submenu_callback, uhf_app);
submenu_add_item(
submenu,
"Change Key",
SubmenuIndexChangeKey,
uhf_scene_card_menu_submenu_callback,
uhf_app);

submenu_set_selected_item(
submenu, scene_manager_get_scene_state(uhf_app->scene_manager, UHFSceneCardMenu));

view_dispatcher_switch_to_view(uhf_app->view_dispatcher, UHFViewMenu);
}

bool uhf_scene_card_menu_on_event(void* ctx, SceneManagerEvent event) {
UHFApp* uhf_app = ctx;
bool consumed = false;

if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubmenuIndexSave) {
scene_manager_set_scene_state(
uhf_app->scene_manager, UHFSceneCardMenu, SubmenuIndexSave);
scene_manager_next_scene(uhf_app->scene_manager, UHFSceneSaveName);
consumed = true;
}
// else if(event.event == SubmenuIndexChangeKey) {
// scene_manager_set_scene_state(
// picopass->scene_manager, UHFSceneCardMenu, SubmenuIndexChangeKey);
// scene_manager_next_scene(picopass->scene_manager, PicopassSceneKeyMenu);
// consumed = true;
// }
} else if(event.type == SceneManagerEventTypeBack) {
consumed = scene_manager_search_and_switch_to_previous_scene(
uhf_app->scene_manager, UHFSceneStart);
}

return consumed;
}

void uhf_scene_card_menu_on_exit(void* ctx) {
UHFApp* uhf_app = ctx;

submenu_reset(uhf_app->submenu);
}
17 changes: 17 additions & 0 deletions non_catalog_apps/uhf_rfid/scenes/uhf_scene_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ADD_SCENE(uhf, verify, Verify)
ADD_SCENE(uhf, start, Start)
ADD_SCENE(uhf, read_tag, ReadTag)
ADD_SCENE(uhf, read_tag_success, ReadTagSuccess)
ADD_SCENE(uhf, card_menu, CardMenu)
ADD_SCENE(uhf, save_name, SaveName)
ADD_SCENE(uhf, save_success, SaveSuccess)
ADD_SCENE(uhf, saved_menu, SavedMenu)
ADD_SCENE(uhf, file_select, FileSelect)
ADD_SCENE(uhf, device_info, DeviceInfo)
ADD_SCENE(uhf, delete, Delete)
ADD_SCENE(uhf, delete_success, DeleteSuccess)
// ADD_SCENE(uhf, write_card, WriteCard)
// ADD_SCENE(uhf, write_card_success, WriteCardSuccess)
// ADD_SCENE(uhf, read_factory_success, ReadFactorySuccess)
// ADD_SCENE(uhf, write_key, WriteKey)
// ADD_SCENE(uhf, key_menu, KeyMenu)
50 changes: 50 additions & 0 deletions non_catalog_apps/uhf_rfid/scenes/uhf_scene_delete.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include "../uhf_app_i.h"

void uhf_scene_delete_widget_callback(GuiButtonType result, InputType type, void* context) {
UHFApp* uhf_app = context;
if(type == InputTypeShort) {
view_dispatcher_send_custom_event(uhf_app->view_dispatcher, result);
}
}

void uhf_scene_delete_on_enter(void* context) {
UHFApp* uhf_app = context;

// Setup Custom Widget view
char temp_str[64];
snprintf(temp_str, sizeof(temp_str), "\e#Delete %s?\e#", uhf_app->uhf_device->dev_name);
widget_add_text_box_element(
uhf_app->widget, 0, 0, 128, 23, AlignCenter, AlignCenter, temp_str, false);
widget_add_button_element(
uhf_app->widget, GuiButtonTypeLeft, "Back", uhf_scene_delete_widget_callback, uhf_app);
widget_add_button_element(
uhf_app->widget, GuiButtonTypeRight, "Delete", uhf_scene_delete_widget_callback, uhf_app);

view_dispatcher_switch_to_view(uhf_app->view_dispatcher, UHFViewWidget);
}

bool uhf_scene_delete_on_event(void* context, SceneManagerEvent event) {
UHFApp* uhf_app = context;
bool consumed = false;

if(event.type == SceneManagerEventTypeCustom) {
if(event.event == GuiButtonTypeLeft) {
return scene_manager_previous_scene(uhf_app->scene_manager);
} else if(event.event == GuiButtonTypeRight) {
if(uhf_device_delete(uhf_app->uhf_device, true)) {
scene_manager_next_scene(uhf_app->scene_manager, UHFSceneDeleteSuccess);
} else {
scene_manager_search_and_switch_to_previous_scene(
uhf_app->scene_manager, UHFSceneStart);
}
consumed = true;
}
}
return consumed;
}

void uhf_scene_delete_on_exit(void* context) {
UHFApp* uhf_app = context;

widget_reset(uhf_app->widget);
}
Loading

0 comments on commit 718aaa3

Please sign in to comment.