NFC Maker tidy up buffers and rename scenes

This commit is contained in:
Willy-JL
2023-07-12 02:55:07 +02:00
parent 6e9e6262c6
commit 99b6a6af86
15 changed files with 90 additions and 81 deletions

View File

@@ -74,7 +74,8 @@ void nfc_maker_free(NfcMaker* app) {
extern int32_t nfc_maker(void* p) {
UNUSED(p);
NfcMaker* app = nfc_maker_alloc();
scene_manager_next_scene(app->scene_manager, NfcMakerSceneMenu);
scene_manager_set_scene_state(app->scene_manager, NfcMakerSceneStart, NfcMakerSceneHttps);
scene_manager_next_scene(app->scene_manager, NfcMakerSceneStart);
view_dispatcher_run(app->view_dispatcher);
nfc_maker_free(app);
return 0;

View File

@@ -17,8 +17,12 @@
#include <applications/main/nfc/nfc_i.h>
#include <furi_hal_bt.h>
#define TEXT_INPUT_LEN 248
#define WIFI_INPUT_LEN 90
#define MAC_INPUT_LEN GAP_MAC_ADDR_SIZE
#define MAIL_INPUT_LEN 128
#define PHONE_INPUT_LEN 17
#define BIG_INPUT_LEN 248
#define SMALL_INPUT_LEN 90
typedef enum {
WifiAuthenticationOpen = 0x01,
@@ -45,10 +49,14 @@ typedef struct {
ByteInput* byte_input;
Popup* popup;
uint8_t mac_buf[GAP_MAC_ADDR_SIZE];
char text_buf[TEXT_INPUT_LEN];
char pass_buf[WIFI_INPUT_LEN];
char name_buf[TEXT_INPUT_LEN];
uint8_t mac_buf[MAC_INPUT_LEN];
char mail_buf[MAIL_INPUT_LEN];
char phone_buf[PHONE_INPUT_LEN];
char big_buf[BIG_INPUT_LEN];
char small_buf1[SMALL_INPUT_LEN];
char small_buf2[SMALL_INPUT_LEN];
char save_buf[BIG_INPUT_LEN];
} NfcMaker;
typedef enum {

View File

@@ -16,7 +16,7 @@ void nfc_maker_scene_bluetooth_on_enter(void* context) {
byte_input_set_header_text(byte_input, "Enter Bluetooth MAC:");
for(size_t i = 0; i < GAP_MAC_ADDR_SIZE; i++) {
for(size_t i = 0; i < MAC_INPUT_LEN; i++) {
app->mac_buf[i] = 0x69;
}
@@ -26,7 +26,7 @@ void nfc_maker_scene_bluetooth_on_enter(void* context) {
NULL,
app,
app->mac_buf,
GAP_MAC_ADDR_SIZE);
MAC_INPUT_LEN);
view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewByteInput);
}
@@ -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, NfcMakerSceneName);
scene_manager_next_scene(app->scene_manager, NfcMakerSceneSave);
break;
default:
break;

View File

@@ -1,4 +1,4 @@
ADD_SCENE(nfc_maker, menu, Menu)
ADD_SCENE(nfc_maker, start, Start)
ADD_SCENE(nfc_maker, bluetooth, Bluetooth)
ADD_SCENE(nfc_maker, https, Https)
ADD_SCENE(nfc_maker, mail, Mail)
@@ -9,5 +9,5 @@ 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, name, Name)
ADD_SCENE(nfc_maker, save, Save)
ADD_SCENE(nfc_maker, result, Result)

View File

@@ -16,14 +16,14 @@ void nfc_maker_scene_https_on_enter(void* context) {
text_input_set_header_text(text_input, "Enter Https Link:");
strlcpy(app->text_buf, "flipper-xtre.me", TEXT_INPUT_LEN);
strlcpy(app->big_buf, "flipper-xtre.me", BIG_INPUT_LEN);
text_input_set_result_callback(
text_input,
nfc_maker_scene_https_text_input_callback,
app,
app->text_buf,
TEXT_INPUT_LEN,
app->big_buf,
BIG_INPUT_LEN,
true);
view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewTextInput);
@@ -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, NfcMakerSceneName);
scene_manager_next_scene(app->scene_manager, NfcMakerSceneSave);
break;
default:
break;

View File

@@ -16,14 +16,14 @@ void nfc_maker_scene_mail_on_enter(void* context) {
text_input_set_header_text(text_input, "Enter Mail Address:");
strlcpy(app->text_buf, "ben.dover@example.com", TEXT_INPUT_LEN);
strlcpy(app->mail_buf, "ben.dover@yourmom.zip", MAIL_INPUT_LEN);
text_input_set_result_callback(
text_input,
nfc_maker_scene_mail_text_input_callback,
app,
app->text_buf,
TEXT_INPUT_LEN,
app->mail_buf,
MAIL_INPUT_LEN,
true);
view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewTextInput);
@@ -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, NfcMakerSceneName);
scene_manager_next_scene(app->scene_manager, NfcMakerSceneSave);
break;
default:
break;

View File

@@ -16,14 +16,14 @@ void nfc_maker_scene_phone_on_enter(void* context) {
text_input_set_header_text(text_input, "Enter Phone Number:");
strlcpy(app->text_buf, "+", TEXT_INPUT_LEN);
strlcpy(app->phone_buf, "+", PHONE_INPUT_LEN);
text_input_set_result_callback(
text_input,
nfc_maker_scene_phone_text_input_callback,
app,
app->text_buf,
TEXT_INPUT_LEN,
app->phone_buf,
PHONE_INPUT_LEN,
false);
view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewTextInput);
@@ -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, NfcMakerSceneName);
scene_manager_next_scene(app->scene_manager, NfcMakerSceneSave);
break;
default:
break;

View File

@@ -17,7 +17,7 @@ void nfc_maker_scene_result_on_enter(void* context) {
FlipperFormat* file = flipper_format_file_alloc(furi_record_open(RECORD_STORAGE));
FuriString* path = furi_string_alloc();
furi_string_printf(path, NFC_APP_FOLDER "/%s" NFC_APP_EXTENSION, app->name_buf);
furi_string_printf(path, NFC_APP_FOLDER "/%s" NFC_APP_EXTENSION, app->save_buf);
uint32_t pages = 135;
size_t size = pages * 4;
@@ -77,12 +77,12 @@ void nfc_maker_scene_result_on_enter(void* context) {
size_t data_len = 0;
size_t j = 0;
switch(scene_manager_get_scene_state(app->scene_manager, NfcMakerSceneMenu)) {
switch(scene_manager_get_scene_state(app->scene_manager, NfcMakerSceneStart)) {
case NfcMakerSceneBluetooth: {
tnf = 0x02; // Media-type [RFC 2046]
type = "application/vnd.bluetooth.ep.oob";
data_len = GAP_MAC_ADDR_SIZE;
data_len = MAC_INPUT_LEN;
payload_len = data_len + 2;
payload = malloc(payload_len);
@@ -96,12 +96,12 @@ void nfc_maker_scene_result_on_enter(void* context) {
tnf = 0x01; // NFC Forum well-known type [NFC RTD]
type = "\x55";
data_len = strnlen(app->text_buf, TEXT_INPUT_LEN);
data_len = strnlen(app->big_buf, BIG_INPUT_LEN);
payload_len = data_len + 1;
payload = malloc(payload_len);
payload[j++] = 0x04; // Prepend "https://"
memcpy(&payload[j], app->text_buf, data_len);
memcpy(&payload[j], app->big_buf, data_len);
j += data_len;
break;
}
@@ -109,12 +109,12 @@ void nfc_maker_scene_result_on_enter(void* context) {
tnf = 0x01; // NFC Forum well-known type [NFC RTD]
type = "\x55";
data_len = strnlen(app->text_buf, TEXT_INPUT_LEN);
data_len = strnlen(app->mail_buf, MAIL_INPUT_LEN);
payload_len = data_len + 1;
payload = malloc(payload_len);
payload[j++] = 0x06; // Prepend "mailto:"
memcpy(&payload[j], app->text_buf, data_len);
memcpy(&payload[j], app->mail_buf, data_len);
j += data_len;
break;
}
@@ -122,12 +122,12 @@ void nfc_maker_scene_result_on_enter(void* context) {
tnf = 0x01; // NFC Forum well-known type [NFC RTD]
type = "\x55";
data_len = strnlen(app->text_buf, TEXT_INPUT_LEN);
data_len = strnlen(app->phone_buf, PHONE_INPUT_LEN);
payload_len = data_len + 1;
payload = malloc(payload_len);
payload[j++] = 0x05; // Prepend "tel:"
memcpy(&payload[j], app->text_buf, data_len);
memcpy(&payload[j], app->phone_buf, data_len);
j += data_len;
break;
}
@@ -135,14 +135,14 @@ void nfc_maker_scene_result_on_enter(void* context) {
tnf = 0x01; // NFC Forum well-known type [NFC RTD]
type = "\x54";
data_len = strnlen(app->text_buf, TEXT_INPUT_LEN);
data_len = strnlen(app->big_buf, BIG_INPUT_LEN);
payload_len = data_len + 3;
payload = malloc(payload_len);
payload[j++] = 0x02;
payload[j++] = 0x65; // e
payload[j++] = 0x6E; // n
memcpy(&payload[j], app->text_buf, data_len);
memcpy(&payload[j], app->big_buf, data_len);
j += data_len;
break;
}
@@ -150,12 +150,12 @@ void nfc_maker_scene_result_on_enter(void* context) {
tnf = 0x01; // NFC Forum well-known type [NFC RTD]
type = "\x55";
data_len = strnlen(app->text_buf, TEXT_INPUT_LEN);
data_len = strnlen(app->big_buf, BIG_INPUT_LEN);
payload_len = data_len + 1;
payload = malloc(payload_len);
payload[j++] = 0x00; // No prepend
memcpy(&payload[j], app->text_buf, data_len);
memcpy(&payload[j], app->big_buf, data_len);
j += data_len;
break;
}
@@ -163,8 +163,8 @@ void nfc_maker_scene_result_on_enter(void* context) {
tnf = 0x02; // Media-type [RFC 2046]
type = "application/vnd.wfa.wsc";
uint8_t ssid_len = strnlen(app->text_buf, WIFI_INPUT_LEN);
uint8_t pass_len = strnlen(app->pass_buf, WIFI_INPUT_LEN);
uint8_t ssid_len = strnlen(app->small_buf1, SMALL_INPUT_LEN);
uint8_t pass_len = strnlen(app->small_buf2, SMALL_INPUT_LEN);
uint8_t data_len = ssid_len + pass_len;
payload_len = data_len + 39;
payload = malloc(payload_len);
@@ -185,7 +185,7 @@ void nfc_maker_scene_result_on_enter(void* context) {
payload[j++] = 0x00;
payload[j++] = ssid_len;
memcpy(&payload[j], app->text_buf, ssid_len);
memcpy(&payload[j], app->small_buf1, ssid_len);
j += ssid_len;
payload[j++] = 0x10;
payload[j++] = 0x03;
@@ -209,7 +209,7 @@ void nfc_maker_scene_result_on_enter(void* context) {
payload[j++] = 0x00;
payload[j++] = pass_len;
memcpy(&payload[j], app->pass_buf, pass_len);
memcpy(&payload[j], app->small_buf2, pass_len);
j += pass_len;
payload[j++] = 0x10;
payload[j++] = 0x20;
@@ -353,7 +353,7 @@ bool nfc_maker_scene_result_on_event(void* context, SceneManagerEvent event) {
switch(event.event) {
case PopupEventExit:
scene_manager_search_and_switch_to_previous_scene(
app->scene_manager, NfcMakerSceneMenu);
app->scene_manager, NfcMakerSceneStart);
break;
default:
break;

View File

@@ -4,26 +4,26 @@ enum TextInputResult {
TextInputResultOk,
};
static void nfc_maker_scene_name_text_input_callback(void* context) {
static void nfc_maker_scene_save_text_input_callback(void* context) {
NfcMaker* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, TextInputResultOk);
}
void nfc_maker_scene_name_on_enter(void* context) {
void nfc_maker_scene_save_on_enter(void* context) {
NfcMaker* app = context;
TextInput* text_input = app->text_input;
text_input_set_header_text(text_input, "Name the NFC tag:");
text_input_set_header_text(text_input, "Save the NFC tag:");
set_random_name(app->name_buf, TEXT_INPUT_LEN);
set_random_name(app->save_buf, BIG_INPUT_LEN);
text_input_set_result_callback(
text_input,
nfc_maker_scene_name_text_input_callback,
nfc_maker_scene_save_text_input_callback,
app,
app->name_buf,
TEXT_INPUT_LEN,
app->save_buf,
BIG_INPUT_LEN,
true);
ValidatorIsFile* validator_is_file =
@@ -33,7 +33,7 @@ void nfc_maker_scene_name_on_enter(void* context) {
view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewTextInput);
}
bool nfc_maker_scene_name_on_event(void* context, SceneManagerEvent event) {
bool nfc_maker_scene_save_on_event(void* context, SceneManagerEvent event) {
NfcMaker* app = context;
bool consumed = false;
@@ -51,7 +51,7 @@ bool nfc_maker_scene_name_on_event(void* context, SceneManagerEvent event) {
return consumed;
}
void nfc_maker_scene_name_on_exit(void* context) {
void nfc_maker_scene_save_on_exit(void* context) {
NfcMaker* app = context;
text_input_reset(app->text_input);
}

View File

@@ -1,11 +1,11 @@
#include "../nfc_maker.h"
void nfc_maker_scene_menu_submenu_callback(void* context, uint32_t index) {
void nfc_maker_scene_start_submenu_callback(void* context, uint32_t index) {
NfcMaker* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, index);
}
void nfc_maker_scene_menu_on_enter(void* context) {
void nfc_maker_scene_start_on_enter(void* context) {
NfcMaker* app = context;
Submenu* submenu = app->submenu;
@@ -15,39 +15,39 @@ void nfc_maker_scene_menu_on_enter(void* context) {
submenu,
"Bluetooth MAC",
NfcMakerSceneBluetooth,
nfc_maker_scene_menu_submenu_callback,
nfc_maker_scene_start_submenu_callback,
app);
submenu_add_item(
submenu, "HTTPS Link", NfcMakerSceneHttps, nfc_maker_scene_menu_submenu_callback, app);
submenu, "HTTPS Link", NfcMakerSceneHttps, nfc_maker_scene_start_submenu_callback, app);
submenu_add_item(
submenu, "Mail Address", NfcMakerSceneMail, nfc_maker_scene_menu_submenu_callback, app);
submenu, "Mail Address", NfcMakerSceneMail, nfc_maker_scene_start_submenu_callback, app);
submenu_add_item(
submenu, "Phone Number", NfcMakerScenePhone, nfc_maker_scene_menu_submenu_callback, app);
submenu, "Phone Number", NfcMakerScenePhone, nfc_maker_scene_start_submenu_callback, app);
submenu_add_item(
submenu, "Text Note", NfcMakerSceneText, nfc_maker_scene_menu_submenu_callback, app);
submenu, "Text Note", NfcMakerSceneText, nfc_maker_scene_start_submenu_callback, app);
submenu_add_item(
submenu, "Plain URL", NfcMakerSceneUrl, nfc_maker_scene_menu_submenu_callback, app);
submenu, "Plain URL", NfcMakerSceneUrl, nfc_maker_scene_start_submenu_callback, app);
submenu_add_item(
submenu, "WiFi Login", NfcMakerSceneWifi, nfc_maker_scene_menu_submenu_callback, app);
submenu, "WiFi Login", NfcMakerSceneWifi, nfc_maker_scene_start_submenu_callback, app);
submenu_set_selected_item(
submenu, scene_manager_get_scene_state(app->scene_manager, NfcMakerSceneMenu));
submenu, scene_manager_get_scene_state(app->scene_manager, NfcMakerSceneStart));
view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewSubmenu);
}
bool nfc_maker_scene_menu_on_event(void* context, SceneManagerEvent event) {
bool nfc_maker_scene_start_on_event(void* context, SceneManagerEvent event) {
NfcMaker* app = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
scene_manager_set_scene_state(app->scene_manager, NfcMakerSceneMenu, event.event);
scene_manager_set_scene_state(app->scene_manager, NfcMakerSceneStart, event.event);
consumed = true;
scene_manager_next_scene(app->scene_manager, event.event);
}
@@ -55,7 +55,7 @@ bool nfc_maker_scene_menu_on_event(void* context, SceneManagerEvent event) {
return consumed;
}
void nfc_maker_scene_menu_on_exit(void* context) {
void nfc_maker_scene_start_on_exit(void* context) {
NfcMaker* app = context;
submenu_reset(app->submenu);
}

View File

@@ -16,14 +16,14 @@ void nfc_maker_scene_text_on_enter(void* context) {
text_input_set_header_text(text_input, "Enter Text Note:");
strlcpy(app->text_buf, "Lorem ipsum", TEXT_INPUT_LEN);
strlcpy(app->big_buf, "Lorem ipsum", BIG_INPUT_LEN);
text_input_set_result_callback(
text_input,
nfc_maker_scene_text_text_input_callback,
app,
app->text_buf,
TEXT_INPUT_LEN,
app->big_buf,
BIG_INPUT_LEN,
true);
view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewTextInput);
@@ -37,7 +37,7 @@ bool nfc_maker_scene_text_on_event(void* context, SceneManagerEvent event) {
consumed = true;
switch(event.event) {
case TextInputResultOk:
scene_manager_next_scene(app->scene_manager, NfcMakerSceneName);
scene_manager_next_scene(app->scene_manager, NfcMakerSceneSave);
break;
default:
break;

View File

@@ -16,14 +16,14 @@ void nfc_maker_scene_url_on_enter(void* context) {
text_input_set_header_text(text_input, "Enter Plain URL:");
strlcpy(app->text_buf, "https://flipper-xtre.me", TEXT_INPUT_LEN);
strlcpy(app->big_buf, "https://flipper-xtre.me", BIG_INPUT_LEN);
text_input_set_result_callback(
text_input,
nfc_maker_scene_url_text_input_callback,
app,
app->text_buf,
TEXT_INPUT_LEN,
app->big_buf,
BIG_INPUT_LEN,
true);
view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewTextInput);
@@ -37,7 +37,7 @@ bool nfc_maker_scene_url_on_event(void* context, SceneManagerEvent event) {
consumed = true;
switch(event.event) {
case TextInputResultOk:
scene_manager_next_scene(app->scene_manager, NfcMakerSceneName);
scene_manager_next_scene(app->scene_manager, NfcMakerSceneSave);
break;
default:
break;

View File

@@ -16,14 +16,14 @@ void nfc_maker_scene_wifi_on_enter(void* context) {
text_input_set_header_text(text_input, "Enter WiFi SSID:");
strlcpy(app->text_buf, "Bill Wi the Science Fi", WIFI_INPUT_LEN);
strlcpy(app->small_buf1, "Bill Wi the Science Fi", SMALL_INPUT_LEN);
text_input_set_result_callback(
text_input,
nfc_maker_scene_wifi_text_input_callback,
app,
app->text_buf,
WIFI_INPUT_LEN,
app->small_buf1,
SMALL_INPUT_LEN,
true);
view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewTextInput);

View File

@@ -65,8 +65,8 @@ bool nfc_maker_scene_wifi_auth_on_event(void* context, SceneManagerEvent event)
if(event.event == WifiAuthenticationOpen) {
scene_manager_set_scene_state(
app->scene_manager, NfcMakerSceneWifiEncr, WifiEncryptionNone);
strcpy(app->pass_buf, "");
scene_manager_next_scene(app->scene_manager, NfcMakerSceneName);
strcpy(app->small_buf2, "");
scene_manager_next_scene(app->scene_manager, NfcMakerSceneSave);
} else {
scene_manager_set_scene_state(
app->scene_manager, NfcMakerSceneWifiEncr, WifiEncryptionAes);

View File

@@ -16,14 +16,14 @@ void nfc_maker_scene_wifi_pass_on_enter(void* context) {
text_input_set_header_text(text_input, "Enter WiFi Password:");
strlcpy(app->pass_buf, "244466666", WIFI_INPUT_LEN);
strlcpy(app->small_buf2, "244466666", SMALL_INPUT_LEN);
text_input_set_result_callback(
text_input,
nfc_maker_scene_wifi_pass_text_input_callback,
app,
app->pass_buf,
WIFI_INPUT_LEN,
app->small_buf2,
SMALL_INPUT_LEN,
true);
view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewTextInput);
@@ -37,7 +37,7 @@ bool nfc_maker_scene_wifi_pass_on_event(void* context, SceneManagerEvent event)
consumed = true;
switch(event.event) {
case TextInputResultOk:
scene_manager_next_scene(app->scene_manager, NfcMakerSceneName);
scene_manager_next_scene(app->scene_manager, NfcMakerSceneSave);
break;
default:
break;