Update NFC Maker

by Willy-JL
This commit is contained in:
MX
2023-07-14 01:18:35 +03:00
parent af23870d3b
commit 0a45cba2bf
20 changed files with 548 additions and 233 deletions

View File

@@ -76,7 +76,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

@@ -18,8 +18,12 @@
#include <furi_hal_bt.h>
#include "strnlen.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,
@@ -46,10 +50,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,5 +1,10 @@
ADD_SCENE(nfc_maker, menu, Menu)
ADD_SCENE(nfc_maker, start, Start)
ADD_SCENE(nfc_maker, bluetooth, Bluetooth)
ADD_SCENE(nfc_maker, contact, Contact)
ADD_SCENE(nfc_maker, contact_last, ContactLast)
ADD_SCENE(nfc_maker, contact_mail, ContactMail)
ADD_SCENE(nfc_maker, contact_phone, ContactPhone)
ADD_SCENE(nfc_maker, contact_url, ContactUrl)
ADD_SCENE(nfc_maker, https, Https)
ADD_SCENE(nfc_maker, mail, Mail)
ADD_SCENE(nfc_maker, phone, Phone)
@@ -9,5 +14,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

@@ -0,0 +1,53 @@
#include "../nfc_maker.h"
enum TextInputResult {
TextInputResultOk,
};
static void nfc_maker_scene_contact_text_input_callback(void* context) {
NfcMaker* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, TextInputResultOk);
}
void nfc_maker_scene_contact_on_enter(void* context) {
NfcMaker* app = context;
NFCMaker_TextInput* text_input = app->text_input;
nfc_maker_text_input_set_header_text(text_input, "Enter First Name:");
strlcpy(app->small_buf1, "Ben", SMALL_INPUT_LEN);
nfc_maker_text_input_set_result_callback(
text_input,
nfc_maker_scene_contact_text_input_callback,
app,
app->small_buf1,
SMALL_INPUT_LEN,
true);
view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewTextInput);
}
bool nfc_maker_scene_contact_on_event(void* context, SceneManagerEvent event) {
NfcMaker* app = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
consumed = true;
switch(event.event) {
case TextInputResultOk:
scene_manager_next_scene(app->scene_manager, NfcMakerSceneContactLast);
break;
default:
break;
}
}
return consumed;
}
void nfc_maker_scene_contact_on_exit(void* context) {
NfcMaker* app = context;
nfc_maker_text_input_reset(app->text_input);
}

View File

@@ -0,0 +1,55 @@
#include "../nfc_maker.h"
enum TextInputResult {
TextInputResultOk,
};
static void nfc_maker_scene_contact_last_text_input_callback(void* context) {
NfcMaker* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, TextInputResultOk);
}
void nfc_maker_scene_contact_last_on_enter(void* context) {
NfcMaker* app = context;
NFCMaker_TextInput* text_input = app->text_input;
nfc_maker_text_input_set_header_text(text_input, "Enter Last Name:");
strlcpy(app->small_buf2, "Dover", SMALL_INPUT_LEN);
nfc_maker_text_input_set_result_callback(
text_input,
nfc_maker_scene_contact_last_text_input_callback,
app,
app->small_buf2,
SMALL_INPUT_LEN,
true);
nfc_maker_text_input_set_minimum_length(text_input, 0);
view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewTextInput);
}
bool nfc_maker_scene_contact_last_on_event(void* context, SceneManagerEvent event) {
NfcMaker* app = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
consumed = true;
switch(event.event) {
case TextInputResultOk:
scene_manager_next_scene(app->scene_manager, NfcMakerSceneContactMail);
break;
default:
break;
}
}
return consumed;
}
void nfc_maker_scene_contact_last_on_exit(void* context) {
NfcMaker* app = context;
nfc_maker_text_input_reset(app->text_input);
}

View File

@@ -0,0 +1,55 @@
#include "../nfc_maker.h"
enum TextInputResult {
TextInputResultOk,
};
static void nfc_maker_scene_contact_mail_text_input_callback(void* context) {
NfcMaker* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, TextInputResultOk);
}
void nfc_maker_scene_contact_mail_on_enter(void* context) {
NfcMaker* app = context;
NFCMaker_TextInput* text_input = app->text_input;
nfc_maker_text_input_set_header_text(text_input, "Enter Email Address:");
strlcpy(app->mail_buf, "ben.dover@example.com", MAIL_INPUT_LEN);
nfc_maker_text_input_set_result_callback(
text_input,
nfc_maker_scene_contact_mail_text_input_callback,
app,
app->mail_buf,
MAIL_INPUT_LEN,
true);
nfc_maker_text_input_set_minimum_length(text_input, 0);
view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewTextInput);
}
bool nfc_maker_scene_contact_mail_on_event(void* context, SceneManagerEvent event) {
NfcMaker* app = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
consumed = true;
switch(event.event) {
case TextInputResultOk:
scene_manager_next_scene(app->scene_manager, NfcMakerSceneContactPhone);
break;
default:
break;
}
}
return consumed;
}
void nfc_maker_scene_contact_mail_on_exit(void* context) {
NfcMaker* app = context;
nfc_maker_text_input_reset(app->text_input);
}

View File

@@ -0,0 +1,55 @@
#include "../nfc_maker.h"
enum TextInputResult {
TextInputResultOk,
};
static void nfc_maker_scene_contact_phone_text_input_callback(void* context) {
NfcMaker* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, TextInputResultOk);
}
void nfc_maker_scene_contact_phone_on_enter(void* context) {
NfcMaker* app = context;
NFCMaker_TextInput* text_input = app->text_input;
nfc_maker_text_input_set_header_text(text_input, "Enter Phone Number:");
strlcpy(app->phone_buf, "+", PHONE_INPUT_LEN);
nfc_maker_text_input_set_result_callback(
text_input,
nfc_maker_scene_contact_phone_text_input_callback,
app,
app->phone_buf,
PHONE_INPUT_LEN,
false);
nfc_maker_text_input_set_minimum_length(text_input, 0);
view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewTextInput);
}
bool nfc_maker_scene_contact_phone_on_event(void* context, SceneManagerEvent event) {
NfcMaker* app = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
consumed = true;
switch(event.event) {
case TextInputResultOk:
scene_manager_next_scene(app->scene_manager, NfcMakerSceneContactUrl);
break;
default:
break;
}
}
return consumed;
}
void nfc_maker_scene_contact_phone_on_exit(void* context) {
NfcMaker* app = context;
nfc_maker_text_input_reset(app->text_input);
}

View File

@@ -0,0 +1,55 @@
#include "../nfc_maker.h"
enum TextInputResult {
TextInputResultOk,
};
static void nfc_maker_scene_contact_url_text_input_callback(void* context) {
NfcMaker* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, TextInputResultOk);
}
void nfc_maker_scene_contact_url_on_enter(void* context) {
NfcMaker* app = context;
NFCMaker_TextInput* text_input = app->text_input;
nfc_maker_text_input_set_header_text(text_input, "Enter URL Link:");
strlcpy(app->big_buf, "google.com", BIG_INPUT_LEN);
nfc_maker_text_input_set_result_callback(
text_input,
nfc_maker_scene_contact_url_text_input_callback,
app,
app->big_buf,
BIG_INPUT_LEN,
true);
nfc_maker_text_input_set_minimum_length(text_input, 0);
view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewTextInput);
}
bool nfc_maker_scene_contact_url_on_event(void* context, SceneManagerEvent event) {
NfcMaker* app = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
consumed = true;
switch(event.event) {
case TextInputResultOk:
scene_manager_next_scene(app->scene_manager, NfcMakerSceneSave);
break;
default:
break;
}
}
return consumed;
}
void nfc_maker_scene_contact_url_on_exit(void* context) {
NfcMaker* app = context;
nfc_maker_text_input_reset(app->text_input);
}

View File

@@ -16,14 +16,14 @@ void nfc_maker_scene_https_on_enter(void* context) {
nfc_maker_text_input_set_header_text(text_input, "Enter HTTPS Link:");
strlcpy(app->text_buf, "google.com", TEXT_INPUT_LEN);
strlcpy(app->big_buf, "google.com", BIG_INPUT_LEN);
nfc_maker_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) {
nfc_maker_text_input_set_header_text(text_input, "Enter Email Address:");
strlcpy(app->text_buf, "ben.dover@example.com", TEXT_INPUT_LEN);
strlcpy(app->mail_buf, "ben.dover@example.com", MAIL_INPUT_LEN);
nfc_maker_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) {
nfc_maker_text_input_set_header_text(text_input, "Enter Phone Number:");
strlcpy(app->text_buf, "+", TEXT_INPUT_LEN);
strlcpy(app->phone_buf, "+", PHONE_INPUT_LEN);
nfc_maker_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;
@@ -61,221 +61,199 @@ void nfc_maker_scene_result_on_enter(void* context) {
buf[i++] = 0x48; // Internal
buf[i++] = 0x00; // Lock bytes
buf[i++] = 0x00; // ...
buf[i++] = 0xE1; // Capability container
buf[i++] = 0x10; // ...
buf[i++] = 0x3E; // ...
buf[i++] = 0x00; // ...
buf[i++] = 0x03; // Message flags
size_t start = i++;
switch(scene_manager_get_scene_state(app->scene_manager, NfcMakerSceneMenu)) {
buf[i++] = 0x03; // Container flags
// NDEF Docs: https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/protocols/nfc/index.html#nfc-data-exchange-format-ndef
uint8_t tnf = 0x00;
const char* type = "";
uint8_t* payload = NULL;
size_t payload_len = 0;
size_t data_len = 0;
size_t j = 0;
switch(scene_manager_get_scene_state(app->scene_manager, NfcMakerSceneStart)) {
case NfcMakerSceneBluetooth: {
buf[i++] = 0xD2;
buf[i++] = 0x20;
buf[i++] = 0x08;
buf[i++] = 0x61;
buf[i++] = 0x70;
tnf = 0x02; // Media-type [RFC 2046]
type = "application/vnd.bluetooth.ep.oob";
buf[i++] = 0x70;
buf[i++] = 0x6C;
buf[i++] = 0x69;
buf[i++] = 0x63;
data_len = MAC_INPUT_LEN;
payload_len = data_len + 2;
payload = malloc(payload_len);
buf[i++] = 0x61;
buf[i++] = 0x74;
buf[i++] = 0x69;
buf[i++] = 0x6F;
payload[j++] = 0x08;
payload[j++] = 0x00;
memcpy(&payload[j], app->mac_buf, data_len);
j += data_len;
break;
}
case NfcMakerSceneContact: {
tnf = 0x02; // Media-type [RFC 2046]
type = "text/vcard";
buf[i++] = 0x6E;
buf[i++] = 0x2F;
buf[i++] = 0x76;
buf[i++] = 0x6E;
FuriString* vcard = furi_string_alloc_set("BEGIN:VCARD\r\nVERSION:3.0\r\n");
furi_string_cat_printf(
vcard, "PRODID:-//Flipper Xtreme//%s//EN\r\n", version_get_version(NULL));
furi_string_cat_printf(vcard, "N:%s;%s;;;\r\n", app->small_buf2, app->small_buf1);
furi_string_cat_printf(
vcard,
"FN:%s%s%s\r\n",
app->small_buf1,
strnlen(app->small_buf2, SMALL_INPUT_LEN) ? " " : "",
app->small_buf2);
if(strnlen(app->mail_buf, MAIL_INPUT_LEN)) {
furi_string_cat_printf(vcard, "EMAIL:%s\r\n", app->mail_buf);
}
if(strnlen(app->phone_buf, PHONE_INPUT_LEN)) {
furi_string_cat_printf(vcard, "TEL:%s\r\n", app->phone_buf);
}
if(strnlen(app->big_buf, BIG_INPUT_LEN)) {
furi_string_cat_printf(vcard, "URL:%s\r\n", app->big_buf);
}
furi_string_cat_printf(vcard, "END:VCARD\r\n");
buf[i++] = 0x64;
buf[i++] = 0x2E;
buf[i++] = 0x62;
buf[i++] = 0x6C;
buf[i++] = 0x75;
buf[i++] = 0x65;
buf[i++] = 0x74;
buf[i++] = 0x6F;
buf[i++] = 0x6F;
buf[i++] = 0x74;
buf[i++] = 0x68;
buf[i++] = 0x2E;
buf[i++] = 0x65;
buf[i++] = 0x70;
buf[i++] = 0x2E;
buf[i++] = 0x6F;
buf[i++] = 0x6F;
buf[i++] = 0x62;
buf[i++] = 0x08;
buf[i++] = 0x00;
memcpy(&buf[i], app->mac_buf, GAP_MAC_ADDR_SIZE);
i += GAP_MAC_ADDR_SIZE;
payload_len = furi_string_size(vcard);
payload = malloc(payload_len);
memcpy(payload, furi_string_get_cstr(vcard), payload_len);
furi_string_free(vcard);
break;
}
case NfcMakerSceneHttps: {
uint8_t data_len = strnlen(app->text_buf, TEXT_INPUT_LEN);
tnf = 0x01; // NFC Forum well-known type [NFC RTD]
type = "\x55";
buf[i++] = 0xD1;
buf[i++] = 0x01;
buf[i++] = data_len + 1;
buf[i++] = 0x55;
data_len = strnlen(app->big_buf, BIG_INPUT_LEN);
payload_len = data_len + 1;
payload = malloc(payload_len);
buf[i++] = 0x04; // Prepend "https://"
memcpy(&buf[i], app->text_buf, data_len);
i += data_len;
payload[j++] = 0x04; // Prepend "https://"
memcpy(&payload[j], app->big_buf, data_len);
j += data_len;
break;
}
case NfcMakerSceneMail: {
uint8_t data_len = strnlen(app->text_buf, TEXT_INPUT_LEN);
tnf = 0x01; // NFC Forum well-known type [NFC RTD]
type = "\x55";
buf[i++] = 0xD1;
buf[i++] = 0x01;
buf[i++] = data_len + 1;
buf[i++] = 0x55;
data_len = strnlen(app->mail_buf, MAIL_INPUT_LEN);
payload_len = data_len + 1;
payload = malloc(payload_len);
buf[i++] = 0x06; // Prepend "mailto:"
memcpy(&buf[i], app->text_buf, data_len);
i += data_len;
payload[j++] = 0x06; // Prepend "mailto:"
memcpy(&payload[j], app->mail_buf, data_len);
j += data_len;
break;
}
case NfcMakerScenePhone: {
uint8_t data_len = strnlen(app->text_buf, TEXT_INPUT_LEN);
tnf = 0x01; // NFC Forum well-known type [NFC RTD]
type = "\x55";
buf[i++] = 0xD1;
buf[i++] = 0x01;
buf[i++] = data_len + 1;
buf[i++] = 0x55;
data_len = strnlen(app->phone_buf, PHONE_INPUT_LEN);
payload_len = data_len + 1;
payload = malloc(payload_len);
buf[i++] = 0x05; // Prepend "tel:"
memcpy(&buf[i], app->text_buf, data_len);
i += data_len;
payload[j++] = 0x05; // Prepend "tel:"
memcpy(&payload[j], app->phone_buf, data_len);
j += data_len;
break;
}
case NfcMakerSceneText: {
uint8_t data_len = strnlen(app->text_buf, TEXT_INPUT_LEN);
tnf = 0x01; // NFC Forum well-known type [NFC RTD]
type = "\x54";
buf[i++] = 0xD1;
buf[i++] = 0x01;
buf[i++] = data_len + 3;
buf[i++] = 0x54;
data_len = strnlen(app->big_buf, BIG_INPUT_LEN);
payload_len = data_len + 3;
payload = malloc(payload_len);
buf[i++] = 0x02;
buf[i++] = 0x65; // e
buf[i++] = 0x6E; // n
memcpy(&buf[i], app->text_buf, data_len);
i += data_len;
payload[j++] = 0x02;
payload[j++] = 0x65; // e
payload[j++] = 0x6E; // n
memcpy(&payload[j], app->big_buf, data_len);
j += data_len;
break;
}
case NfcMakerSceneUrl: {
uint8_t data_len = strnlen(app->text_buf, TEXT_INPUT_LEN);
tnf = 0x01; // NFC Forum well-known type [NFC RTD]
type = "\x55";
buf[i++] = 0xD1;
buf[i++] = 0x01;
buf[i++] = data_len + 1;
buf[i++] = 0x55;
data_len = strnlen(app->big_buf, BIG_INPUT_LEN);
payload_len = data_len + 1;
payload = malloc(payload_len);
buf[i++] = 0x00; // No prepend
memcpy(&buf[i], app->text_buf, data_len);
i += data_len;
payload[j++] = 0x00; // No prepend
memcpy(&payload[j], app->big_buf, data_len);
j += data_len;
break;
}
case NfcMakerSceneWifi: {
uint8_t ssid_len = strnlen(app->text_buf, WIFI_INPUT_LEN);
uint8_t pass_len = strnlen(app->pass_buf, WIFI_INPUT_LEN);
tnf = 0x02; // Media-type [RFC 2046]
type = "application/vnd.wfa.wsc";
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);
buf[i++] = 0xD2;
buf[i++] = 0x17;
buf[i++] = data_len + 47;
buf[i++] = 0x61;
buf[i++] = 0x70;
payload[j++] = 0x10;
payload[j++] = 0x0E;
payload[j++] = 0x00;
buf[i++] = 0x70;
buf[i++] = 0x6C;
buf[i++] = 0x69;
buf[i++] = 0x63;
payload[j++] = data_len + 43;
payload[j++] = 0x10;
payload[j++] = 0x26;
payload[j++] = 0x00;
buf[i++] = 0x61;
buf[i++] = 0x74;
buf[i++] = 0x69;
buf[i++] = 0x6F;
payload[j++] = 0x01;
payload[j++] = 0x01;
payload[j++] = 0x10;
payload[j++] = 0x45;
buf[i++] = 0x6E;
buf[i++] = 0x2F;
buf[i++] = 0x76;
buf[i++] = 0x6E;
payload[j++] = 0x00;
payload[j++] = ssid_len;
memcpy(&payload[j], app->small_buf1, ssid_len);
j += ssid_len;
payload[j++] = 0x10;
payload[j++] = 0x03;
buf[i++] = 0x64;
buf[i++] = 0x2E;
buf[i++] = 0x77;
buf[i++] = 0x66;
payload[j++] = 0x00;
payload[j++] = 0x02;
payload[j++] = 0x00;
payload[j++] =
scene_manager_get_scene_state(app->scene_manager, NfcMakerSceneWifiAuth);
buf[i++] = 0x61;
buf[i++] = 0x2E;
buf[i++] = 0x77;
buf[i++] = 0x73;
payload[j++] = 0x10;
payload[j++] = 0x0F;
payload[j++] = 0x00;
payload[j++] = 0x02;
buf[i++] = 0x63;
buf[i++] = 0x10;
buf[i++] = 0x0E;
buf[i++] = 0x00;
payload[j++] = 0x00;
payload[j++] =
scene_manager_get_scene_state(app->scene_manager, NfcMakerSceneWifiEncr);
payload[j++] = 0x10;
payload[j++] = 0x27;
buf[i++] = data_len + 43;
buf[i++] = 0x10;
buf[i++] = 0x26;
buf[i++] = 0x00;
payload[j++] = 0x00;
payload[j++] = pass_len;
memcpy(&payload[j], app->small_buf2, pass_len);
j += pass_len;
payload[j++] = 0x10;
payload[j++] = 0x20;
buf[i++] = 0x01;
buf[i++] = 0x01;
buf[i++] = 0x10;
buf[i++] = 0x45;
payload[j++] = 0x00;
payload[j++] = 0x06;
payload[j++] = 0xFF;
payload[j++] = 0xFF;
buf[i++] = 0x00;
buf[i++] = ssid_len;
memcpy(&buf[i], app->text_buf, ssid_len);
i += ssid_len;
buf[i++] = 0x10;
buf[i++] = 0x03;
buf[i++] = 0x00;
buf[i++] = 0x02;
buf[i++] = 0x00;
buf[i++] = scene_manager_get_scene_state(app->scene_manager, NfcMakerSceneWifiAuth);
buf[i++] = 0x10;
buf[i++] = 0x0F;
buf[i++] = 0x00;
buf[i++] = 0x02;
buf[i++] = 0x00;
buf[i++] = scene_manager_get_scene_state(app->scene_manager, NfcMakerSceneWifiEncr);
buf[i++] = 0x10;
buf[i++] = 0x27;
buf[i++] = 0x00;
buf[i++] = pass_len;
memcpy(&buf[i], app->pass_buf, pass_len);
i += pass_len;
buf[i++] = 0x10;
buf[i++] = 0x20;
buf[i++] = 0x00;
buf[i++] = 0x06;
buf[i++] = 0xFF;
buf[i++] = 0xFF;
buf[i++] = 0xFF;
buf[i++] = 0xFF;
buf[i++] = 0xFF;
buf[i++] = 0xFF;
payload[j++] = 0xFF;
payload[j++] = 0xFF;
payload[j++] = 0xFF;
payload[j++] = 0xFF;
break;
}
@@ -283,8 +261,51 @@ void nfc_maker_scene_result_on_enter(void* context) {
break;
}
// Message length and terminator
buf[start] = i - start - 1;
// Record header
uint8_t flags = 0;
flags |= 1 << 7; // MB (Message Begin)
flags |= 1 << 6; // ME (Message End)
flags |= tnf; // TNF (Type Name Format)
size_t type_len = strlen(type);
size_t header_len = 0;
header_len += 1; // Flags and TNF
header_len += 1; // Type length
if(payload_len < 0xFF) {
flags |= 1 << 4; // SR (Short Record)
header_len += 1; // Payload length
} else {
header_len += 4; // Payload length
}
header_len += type_len; // Payload type
size_t record_len = header_len + payload_len;
if(record_len < 0xFF) {
buf[i++] = record_len; // Record length
} else {
buf[i++] = 0xFF; // Record length
buf[i++] = record_len >> 8; // ...
buf[i++] = record_len & 0xFF; // ...
}
buf[i++] = flags; // Flags and TNF
buf[i++] = type_len; // Type length
if(flags & 1 << 4) { // SR (Short Record)
buf[i++] = payload_len; // Payload length
} else {
buf[i++] = 0x00; // Payload length
buf[i++] = 0x00; // ...
buf[i++] = payload_len >> 8; // ...
buf[i++] = payload_len & 0xFF; // ...
}
memcpy(&buf[i], type, type_len); // Payload type
i += type_len;
// Record payload
memcpy(&buf[i], payload, payload_len);
i += payload_len;
free(payload);
// Record terminator
buf[i++] = 0xFE;
// Padding until last 5 pages
@@ -363,7 +384,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;
NFCMaker_TextInput* text_input = app->text_input;
nfc_maker_text_input_set_header_text(text_input, "Name the NFC tag:");
nfc_maker_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);
nfc_maker_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;
nfc_maker_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,46 @@ 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,
"Contact Vcard",
NfcMakerSceneContact,
nfc_maker_scene_start_submenu_callback,
app);
submenu_add_item(
submenu, "Email Address", NfcMakerSceneMail, nfc_maker_scene_menu_submenu_callback, app);
submenu, "HTTPS Link", NfcMakerSceneHttps, nfc_maker_scene_start_submenu_callback, app);
submenu_add_item(
submenu, "Phone Number", NfcMakerScenePhone, nfc_maker_scene_menu_submenu_callback, app);
submenu, "Mail Address", NfcMakerSceneMail, nfc_maker_scene_start_submenu_callback, app);
submenu_add_item(
submenu, "Text Note", NfcMakerSceneText, nfc_maker_scene_menu_submenu_callback, app);
submenu, "Phone Number", NfcMakerScenePhone, nfc_maker_scene_start_submenu_callback, app);
submenu_add_item(
submenu, "Plain URL", NfcMakerSceneUrl, nfc_maker_scene_menu_submenu_callback, app);
submenu, "Text Note", NfcMakerSceneText, nfc_maker_scene_start_submenu_callback, app);
submenu_add_item(
submenu, "WiFi Login", NfcMakerSceneWifi, 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_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 +62,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) {
nfc_maker_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);
nfc_maker_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) {
nfc_maker_text_input_set_header_text(text_input, "Enter Plain URL:");
strlcpy(app->text_buf, "https://google.com", TEXT_INPUT_LEN);
strlcpy(app->big_buf, "https://google.com", BIG_INPUT_LEN);
nfc_maker_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) {
nfc_maker_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);
nfc_maker_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) {
nfc_maker_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);
nfc_maker_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;