Skip to content

Commit

Permalink
update nfc maker
Browse files Browse the repository at this point in the history
  • Loading branch information
xMasterX committed Feb 10, 2024
1 parent a937495 commit 9dc271e
Show file tree
Hide file tree
Showing 18 changed files with 1,147 additions and 429 deletions.
674 changes: 674 additions & 0 deletions base_pack/nfc_maker/LICENSE

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions base_pack/nfc_maker/application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ App(
name="NFC Maker",
apptype=FlipperAppType.EXTERNAL,
entry_point="nfc_maker",
cdefines=["APP_NFC_MAKER"],
requires=[
"storage",
"gui",
],
stack_size=1 * 1024,
fap_icon="nfc_maker_10px.png",
fap_category="NFC",
fap_icon_assets="assets",
fap_author="@Willy-JL",
fap_weburl="https://github.com/Flipper-XFW/Xtreme-Apps/tree/dev/nfc_maker",
fap_version="1.1",
fap_description="Create NFC files for BT MACs, Contacts, Links, Emails, Phones, Text and WiFis",
)
33 changes: 33 additions & 0 deletions base_pack/nfc_maker/nfc_maker.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
#include "nfc_maker.h"

const NfcDataGeneratorType ntag_generators[NtagMAX] = {
[Ntag203] = NfcDataGeneratorTypeNTAG203,
[Ntag213] = NfcDataGeneratorTypeNTAG213,
[Ntag215] = NfcDataGeneratorTypeNTAG215,
[Ntag216] = NfcDataGeneratorTypeNTAG216,
[NtagI2C1K] = NfcDataGeneratorTypeNTAGI2C1k,
[NtagI2C2K] = NfcDataGeneratorTypeNTAGI2C2k,
};
const char* ntag_names[NtagMAX] = {
[Ntag203] = "NTAG203",
[Ntag213] = "NTAG213",
[Ntag215] = "NTAG215",
[Ntag216] = "NTAG216",
[NtagI2C1K] = "NTAG I2C 1K",
[NtagI2C2K] = "NTAG I2C 2K",
};
const size_t ntag_sizes[NtagMAX] = {
[Ntag203] = 0x12 * NTAG_DATA_AREA_UNIT_SIZE,
[Ntag213] = 0x12 * NTAG_DATA_AREA_UNIT_SIZE,
[Ntag215] = 0x3E * NTAG_DATA_AREA_UNIT_SIZE,
[Ntag216] = 0x6D * NTAG_DATA_AREA_UNIT_SIZE,
[NtagI2C1K] = 0x6D * NTAG_DATA_AREA_UNIT_SIZE,
[NtagI2C2K] = 0xEA * NTAG_DATA_AREA_UNIT_SIZE,
};

static bool nfc_maker_custom_event_callback(void* context, uint32_t event) {
furi_assert(context);
NfcMaker* app = context;
Expand Down Expand Up @@ -48,12 +73,20 @@ NfcMaker* nfc_maker_alloc() {
app->popup = popup_alloc();
view_dispatcher_add_view(app->view_dispatcher, NfcMakerViewPopup, popup_get_view(app->popup));

// Nfc Device
app->nfc_device = nfc_device_alloc();
app->ndef_buffer = malloc(MAX_NDEF_LEN);

return app;
}

void nfc_maker_free(NfcMaker* app) {
furi_assert(app);

// Nfc Device
nfc_device_free(app->nfc_device);
free(app->ndef_buffer);

// Gui modules
view_dispatcher_remove_view(app->view_dispatcher, NfcMakerViewSubmenu);
submenu_free(app->submenu);
Expand Down
26 changes: 26 additions & 0 deletions base_pack/nfc_maker/nfc_maker.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#pragma once

#include <furi.h>
#include <gui/gui.h>
#include <gui/view.h>
#include <gui/modules/validators.h>
Expand All @@ -14,6 +17,11 @@
#include <furi_hal_bt.h>
#include "newstrnlen.h"

#include <nfc/nfc_device.h>
#include <nfc/helpers/nfc_data_generator.h>
#include <nfc/protocols/mf_ultralight/mf_ultralight.h>
#include <nfc/nfc.h>

#define NFC_MK_APP_FOLDER EXT_PATH("nfc")
#define NFC_MK_APP_EXTENSION ".nfc"

Expand All @@ -24,6 +32,21 @@
#define BIG_INPUT_LEN 248
#define SMALL_INPUT_LEN 90

#define NTAG_DATA_AREA_UNIT_SIZE 2 * MF_ULTRALIGHT_PAGE_SIZE
typedef enum {
Ntag203,
Ntag213,
Ntag215,
Ntag216,
NtagI2C1K,
NtagI2C2K,
NtagMAX,
} Ntag;
extern const NfcDataGeneratorType ntag_generators[NtagMAX];
extern const char* ntag_names[NtagMAX];
extern const size_t ntag_sizes[NtagMAX];
#define MAX_NDEF_LEN ntag_sizes[NtagI2C2K]

typedef enum {
WifiAuthenticationOpen = 0x01,
WifiAuthenticationWpa2Personal = 0x20,
Expand All @@ -49,6 +72,9 @@ typedef struct {
ByteInput* byte_input;
Popup* popup;

NfcDevice* nfc_device;
uint8_t* ndef_buffer;

uint8_t mac_buf[MAC_INPUT_LEN];
char mail_buf[MAIL_INPUT_LEN];
char phone_buf[PHONE_INPUT_LEN];
Expand Down
2 changes: 1 addition & 1 deletion base_pack/nfc_maker/scenes/nfc_maker_scene_bluetooth.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ bool nfc_maker_scene_bluetooth_on_event(void* context, SceneManagerEvent event)
switch(event.event) {
case ByteInputResultOk:
furi_hal_bt_reverse_mac_addr(app->mac_buf);
scene_manager_next_scene(app->scene_manager, NfcMakerSceneSave);
scene_manager_next_scene(app->scene_manager, NfcMakerSceneSaveGenerate);
break;
default:
break;
Expand Down
5 changes: 3 additions & 2 deletions base_pack/nfc_maker/scenes/nfc_maker_scene_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ ADD_SCENE(nfc_maker, wifi, Wifi)
ADD_SCENE(nfc_maker, wifi_auth, WifiAuth)
ADD_SCENE(nfc_maker, wifi_encr, WifiEncr)
ADD_SCENE(nfc_maker, wifi_pass, WifiPass)
ADD_SCENE(nfc_maker, save, Save)
ADD_SCENE(nfc_maker, result, Result)
ADD_SCENE(nfc_maker, save_generate, SaveGenerate)
ADD_SCENE(nfc_maker, save_name, SaveName)
ADD_SCENE(nfc_maker, save_result, SaveResult)
2 changes: 1 addition & 1 deletion base_pack/nfc_maker/scenes/nfc_maker_scene_contact_url.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ bool nfc_maker_scene_contact_url_on_event(void* context, SceneManagerEvent event
consumed = true;
switch(event.event) {
case TextInputResultOk:
scene_manager_next_scene(app->scene_manager, NfcMakerSceneSave);
scene_manager_next_scene(app->scene_manager, NfcMakerSceneSaveGenerate);
break;
default:
break;
Expand Down
2 changes: 1 addition & 1 deletion base_pack/nfc_maker/scenes/nfc_maker_scene_https.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ bool nfc_maker_scene_https_on_event(void* context, SceneManagerEvent event) {
consumed = true;
switch(event.event) {
case TextInputResultOk:
scene_manager_next_scene(app->scene_manager, NfcMakerSceneSave);
scene_manager_next_scene(app->scene_manager, NfcMakerSceneSaveGenerate);
break;
default:
break;
Expand Down
2 changes: 1 addition & 1 deletion base_pack/nfc_maker/scenes/nfc_maker_scene_mail.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ bool nfc_maker_scene_mail_on_event(void* context, SceneManagerEvent event) {
consumed = true;
switch(event.event) {
case TextInputResultOk:
scene_manager_next_scene(app->scene_manager, NfcMakerSceneSave);
scene_manager_next_scene(app->scene_manager, NfcMakerSceneSaveGenerate);
break;
default:
break;
Expand Down
2 changes: 1 addition & 1 deletion base_pack/nfc_maker/scenes/nfc_maker_scene_phone.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ bool nfc_maker_scene_phone_on_event(void* context, SceneManagerEvent event) {
consumed = true;
switch(event.event) {
case TextInputResultOk:
scene_manager_next_scene(app->scene_manager, NfcMakerSceneSave);
scene_manager_next_scene(app->scene_manager, NfcMakerSceneSaveGenerate);
break;
default:
break;
Expand Down
Loading

0 comments on commit 9dc271e

Please sign in to comment.