diff --git a/applications/external/nfc_maker/scenes/nfc_maker_scene_result.c b/applications/external/nfc_maker/scenes/nfc_maker_scene_result.c deleted file mode 100644 index 67fdf056769..00000000000 --- a/applications/external/nfc_maker/scenes/nfc_maker_scene_result.c +++ /dev/null @@ -1,382 +0,0 @@ -#include "../nfc_maker.h" - -enum PopupEvent { - PopupEventExit, -}; - -static void nfc_maker_scene_result_popup_callback(void* context) { - NfcMaker* app = context; - - view_dispatcher_send_custom_event(app->view_dispatcher, PopupEventExit); -} - -void nfc_maker_scene_result_on_enter(void* context) { - NfcMaker* app = context; - Popup* popup = app->popup; - bool success = false; - - 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); - - // uint32_t pages = 42; - uint32_t pages = 135; - size_t size = pages * 4; - uint8_t* buf = malloc(size); - do { - if(!flipper_format_file_open_new(file, furi_string_get_cstr(path))) break; - - if(!flipper_format_write_header_cstr(file, "Flipper NFC device", 3)) break; - // if(!flipper_format_write_string_cstr(file, "Device type", "NTAG203")) break; - if(!flipper_format_write_string_cstr(file, "Device type", "NTAG215")) break; - - // Serial number - size_t i = 0; - buf[i++] = 0x04; - furi_hal_random_fill_buf(&buf[i], 8); - i += 8; - uint8_t uid[7]; - memcpy(&uid[0], &buf[0], 3); - memcpy(&uid[3], &buf[4], 4); - - if(!flipper_format_write_hex(file, "UID", uid, sizeof(uid))) break; - if(!flipper_format_write_string_cstr(file, "ATQA", "00 44")) break; - if(!flipper_format_write_string_cstr(file, "SAK", "00")) break; - // TODO: Maybe randomize? - if(!flipper_format_write_string_cstr( - file, - "Signature", - "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00")) - break; - // if(!flipper_format_write_string_cstr(file, "Mifare version", "00 00 00 00 00 00 00 00")) - if(!flipper_format_write_string_cstr(file, "Mifare version", "00 04 04 02 01 00 11 03")) - break; - - if(!flipper_format_write_string_cstr(file, "Counter 0", "0")) break; - if(!flipper_format_write_string_cstr(file, "Tearing 0", "00")) break; - if(!flipper_format_write_string_cstr(file, "Counter 1", "0")) break; - if(!flipper_format_write_string_cstr(file, "Tearing 1", "00")) break; - if(!flipper_format_write_string_cstr(file, "Counter 2", "0")) break; - if(!flipper_format_write_string_cstr(file, "Tearing 2", "00")) break; - if(!flipper_format_write_uint32(file, "Pages total", &pages, 1)) break; - - // Static data - 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)) { - case NfcMakerSceneBluetooth: { - buf[i++] = 0xD2; - buf[i++] = 0x20; - buf[i++] = 0x08; - buf[i++] = 0x61; - buf[i++] = 0x70; - - buf[i++] = 0x70; - buf[i++] = 0x6C; - buf[i++] = 0x69; - buf[i++] = 0x63; - - buf[i++] = 0x61; - buf[i++] = 0x74; - buf[i++] = 0x69; - buf[i++] = 0x6F; - - buf[i++] = 0x6E; - buf[i++] = 0x2F; - buf[i++] = 0x76; - buf[i++] = 0x6E; - - 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; - break; - } - case NfcMakerSceneHttps: { - uint8_t data_len = strnlen(app->text_buf, TEXT_INPUT_LEN); - - buf[i++] = 0xD1; - buf[i++] = 0x01; - buf[i++] = data_len + 1; - buf[i++] = 0x55; - - buf[i++] = 0x04; // Prepend "https://" - memcpy(&buf[i], app->text_buf, data_len); - i += data_len; - break; - } - case NfcMakerSceneMail: { - uint8_t data_len = strnlen(app->text_buf, TEXT_INPUT_LEN); - - buf[i++] = 0xD1; - buf[i++] = 0x01; - buf[i++] = data_len + 1; - buf[i++] = 0x55; - - buf[i++] = 0x06; // Prepend "mailto:" - memcpy(&buf[i], app->text_buf, data_len); - i += data_len; - break; - } - case NfcMakerScenePhone: { - uint8_t data_len = strnlen(app->text_buf, TEXT_INPUT_LEN); - - buf[i++] = 0xD1; - buf[i++] = 0x01; - buf[i++] = data_len + 1; - buf[i++] = 0x55; - - buf[i++] = 0x05; // Prepend "tel:" - memcpy(&buf[i], app->text_buf, data_len); - i += data_len; - break; - } - case NfcMakerSceneText: { - uint8_t data_len = strnlen(app->text_buf, TEXT_INPUT_LEN); - - buf[i++] = 0xD1; - buf[i++] = 0x01; - buf[i++] = data_len + 3; - buf[i++] = 0x54; - - buf[i++] = 0x02; - buf[i++] = 0x65; // e - buf[i++] = 0x6E; // n - memcpy(&buf[i], app->text_buf, data_len); - i += data_len; - break; - } - case NfcMakerSceneUrl: { - uint8_t data_len = strnlen(app->text_buf, TEXT_INPUT_LEN); - - buf[i++] = 0xD1; - buf[i++] = 0x01; - buf[i++] = data_len + 1; - buf[i++] = 0x55; - - buf[i++] = 0x00; // No prepend - memcpy(&buf[i], app->text_buf, data_len); - i += 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); - uint8_t data_len = ssid_len + pass_len; - - buf[i++] = 0xD2; - buf[i++] = 0x17; - buf[i++] = data_len + 47; - buf[i++] = 0x61; - buf[i++] = 0x70; - - buf[i++] = 0x70; - buf[i++] = 0x6C; - buf[i++] = 0x69; - buf[i++] = 0x63; - - buf[i++] = 0x61; - buf[i++] = 0x74; - buf[i++] = 0x69; - buf[i++] = 0x6F; - - buf[i++] = 0x6E; - buf[i++] = 0x2F; - buf[i++] = 0x76; - buf[i++] = 0x6E; - - buf[i++] = 0x64; - buf[i++] = 0x2E; - buf[i++] = 0x77; - buf[i++] = 0x66; - - buf[i++] = 0x61; - buf[i++] = 0x2E; - buf[i++] = 0x77; - buf[i++] = 0x73; - - buf[i++] = 0x63; - buf[i++] = 0x10; - buf[i++] = 0x0E; - buf[i++] = 0x00; - - buf[i++] = data_len + 43; - buf[i++] = 0x10; - buf[i++] = 0x26; - buf[i++] = 0x00; - - buf[i++] = 0x01; - buf[i++] = 0x01; - buf[i++] = 0x10; - buf[i++] = 0x45; - - 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; - - break; - } - default: - break; - } - - // Message length and terminator - buf[start] = i - start - 1; - buf[i++] = 0xFE; - - // Padding until last 5 pages - for(; i < size - 20; i++) { - buf[i] = 0x00; - } - - // Last 5 static pages - buf[i++] = 0x00; - buf[i++] = 0x00; - buf[i++] = 0x00; - buf[i++] = 0xBD; - - buf[i++] = 0x04; - buf[i++] = 0x00; - buf[i++] = 0x00; - buf[i++] = 0xFF; - - buf[i++] = 0x00; - buf[i++] = 0x05; - buf[i++] = 0x00; - buf[i++] = 0x00; - - buf[i++] = 0xFF; - buf[i++] = 0xFF; - buf[i++] = 0xFF; - buf[i++] = 0xFF; - - buf[i++] = 0x00; - buf[i++] = 0x00; - buf[i++] = 0x00; - buf[i++] = 0x00; - - // Write pages - char str[16]; - bool ok = true; - for(size_t page = 0; page < pages; page++) { - snprintf(str, sizeof(str), "Page %u", page); - if(!flipper_format_write_hex(file, str, &buf[page * 4], 4)) { - ok = false; - break; - } - } - if(!ok) break; - - success = true; - - } while(false); - free(buf); - - furi_string_free(path); - flipper_format_free(file); - furi_record_close(RECORD_STORAGE); - - if(success) { - popup_set_icon(popup, 32, 5, &I_DolphinNice_96x59); - popup_set_header(popup, "Saved!", 13, 22, AlignLeft, AlignBottom); - } else { - popup_set_icon(popup, 32, 5, &I_DolphinNice_96x59); - popup_set_header(popup, "Saved!", 13, 22, AlignLeft, AlignBottom); - } - popup_set_timeout(popup, 1500); - popup_set_context(popup, app); - popup_set_callback(popup, nfc_maker_scene_result_popup_callback); - popup_enable_timeout(popup); - - view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewPopup); -} - -bool nfc_maker_scene_result_on_event(void* context, SceneManagerEvent event) { - NfcMaker* app = context; - bool consumed = false; - - if(event.type == SceneManagerEventTypeCustom) { - consumed = true; - switch(event.event) { - case PopupEventExit: - scene_manager_search_and_switch_to_previous_scene( - app->scene_manager, NfcMakerSceneMenu); - break; - default: - break; - } - } - - return consumed; -} - -void nfc_maker_scene_result_on_exit(void* context) { - NfcMaker* app = context; - popup_reset(app->popup); -} diff --git a/applications/external/nfc_maker/application.fam b/applications/external/nfc_maker_203/application.fam similarity index 89% rename from applications/external/nfc_maker/application.fam rename to applications/external/nfc_maker_203/application.fam index 6fd1b06f4c0..3154e0caa39 100644 --- a/applications/external/nfc_maker/application.fam +++ b/applications/external/nfc_maker_203/application.fam @@ -1,6 +1,6 @@ App( - appid="NFC_Maker", - name="NFC Maker", + appid="NFC_Maker_NTAG203", + name="NFC Maker NTAG203", apptype=FlipperAppType.EXTERNAL, entry_point="nfc_maker", # cdefines=["APP_NFC_MAKER"], diff --git a/applications/external/nfc_maker/assets/DolphinNice_96x59.png b/applications/external/nfc_maker_203/assets/DolphinNice_96x59.png similarity index 100% rename from applications/external/nfc_maker/assets/DolphinNice_96x59.png rename to applications/external/nfc_maker_203/assets/DolphinNice_96x59.png diff --git a/applications/external/nfc_maker/assets/KeyBackspaceSelected_16x9.png b/applications/external/nfc_maker_203/assets/KeyBackspaceSelected_16x9.png similarity index 100% rename from applications/external/nfc_maker/assets/KeyBackspaceSelected_16x9.png rename to applications/external/nfc_maker_203/assets/KeyBackspaceSelected_16x9.png diff --git a/applications/external/nfc_maker/assets/KeyBackspace_16x9.png b/applications/external/nfc_maker_203/assets/KeyBackspace_16x9.png similarity index 100% rename from applications/external/nfc_maker/assets/KeyBackspace_16x9.png rename to applications/external/nfc_maker_203/assets/KeyBackspace_16x9.png diff --git a/applications/external/nfc_maker/assets/KeyKeyboardSelected_10x11.png b/applications/external/nfc_maker_203/assets/KeyKeyboardSelected_10x11.png similarity index 100% rename from applications/external/nfc_maker/assets/KeyKeyboardSelected_10x11.png rename to applications/external/nfc_maker_203/assets/KeyKeyboardSelected_10x11.png diff --git a/applications/external/nfc_maker/assets/KeyKeyboard_10x11.png b/applications/external/nfc_maker_203/assets/KeyKeyboard_10x11.png similarity index 100% rename from applications/external/nfc_maker/assets/KeyKeyboard_10x11.png rename to applications/external/nfc_maker_203/assets/KeyKeyboard_10x11.png diff --git a/applications/external/nfc_maker/assets/KeySaveSelected_24x11.png b/applications/external/nfc_maker_203/assets/KeySaveSelected_24x11.png similarity index 100% rename from applications/external/nfc_maker/assets/KeySaveSelected_24x11.png rename to applications/external/nfc_maker_203/assets/KeySaveSelected_24x11.png diff --git a/applications/external/nfc_maker/assets/KeySave_24x11.png b/applications/external/nfc_maker_203/assets/KeySave_24x11.png similarity index 100% rename from applications/external/nfc_maker/assets/KeySave_24x11.png rename to applications/external/nfc_maker_203/assets/KeySave_24x11.png diff --git a/applications/external/nfc_maker/assets/WarningDolphin_45x42.png b/applications/external/nfc_maker_203/assets/WarningDolphin_45x42.png similarity index 100% rename from applications/external/nfc_maker/assets/WarningDolphin_45x42.png rename to applications/external/nfc_maker_203/assets/WarningDolphin_45x42.png diff --git a/applications/external/nfc_maker/nfc_maker.c b/applications/external/nfc_maker_203/nfc_maker.c similarity index 100% rename from applications/external/nfc_maker/nfc_maker.c rename to applications/external/nfc_maker_203/nfc_maker.c diff --git a/applications/external/nfc_maker/nfc_maker.h b/applications/external/nfc_maker_203/nfc_maker.h similarity index 100% rename from applications/external/nfc_maker/nfc_maker.h rename to applications/external/nfc_maker_203/nfc_maker.h diff --git a/applications/external/nfc_maker/nfc_maker_10px.png b/applications/external/nfc_maker_203/nfc_maker_10px.png similarity index 100% rename from applications/external/nfc_maker/nfc_maker_10px.png rename to applications/external/nfc_maker_203/nfc_maker_10px.png diff --git a/applications/external/nfc_maker/nfc_maker_text_input.c b/applications/external/nfc_maker_203/nfc_maker_text_input.c similarity index 100% rename from applications/external/nfc_maker/nfc_maker_text_input.c rename to applications/external/nfc_maker_203/nfc_maker_text_input.c diff --git a/applications/external/nfc_maker/nfc_maker_text_input.h b/applications/external/nfc_maker_203/nfc_maker_text_input.h similarity index 100% rename from applications/external/nfc_maker/nfc_maker_text_input.h rename to applications/external/nfc_maker_203/nfc_maker_text_input.h diff --git a/applications/external/nfc_maker/nfc_maker_validators.c b/applications/external/nfc_maker_203/nfc_maker_validators.c similarity index 100% rename from applications/external/nfc_maker/nfc_maker_validators.c rename to applications/external/nfc_maker_203/nfc_maker_validators.c diff --git a/applications/external/nfc_maker/nfc_maker_validators.h b/applications/external/nfc_maker_203/nfc_maker_validators.h similarity index 100% rename from applications/external/nfc_maker/nfc_maker_validators.h rename to applications/external/nfc_maker_203/nfc_maker_validators.h diff --git a/applications/external/nfc_maker/scenes/nfc_maker_scene.c b/applications/external/nfc_maker_203/scenes/nfc_maker_scene.c similarity index 100% rename from applications/external/nfc_maker/scenes/nfc_maker_scene.c rename to applications/external/nfc_maker_203/scenes/nfc_maker_scene.c diff --git a/applications/external/nfc_maker/scenes/nfc_maker_scene.h b/applications/external/nfc_maker_203/scenes/nfc_maker_scene.h similarity index 100% rename from applications/external/nfc_maker/scenes/nfc_maker_scene.h rename to applications/external/nfc_maker_203/scenes/nfc_maker_scene.h diff --git a/applications/external/nfc_maker/scenes/nfc_maker_scene_bluetooth.c b/applications/external/nfc_maker_203/scenes/nfc_maker_scene_bluetooth.c similarity index 100% rename from applications/external/nfc_maker/scenes/nfc_maker_scene_bluetooth.c rename to applications/external/nfc_maker_203/scenes/nfc_maker_scene_bluetooth.c diff --git a/applications/external/nfc_maker/scenes/nfc_maker_scene_config.h b/applications/external/nfc_maker_203/scenes/nfc_maker_scene_config.h similarity index 100% rename from applications/external/nfc_maker/scenes/nfc_maker_scene_config.h rename to applications/external/nfc_maker_203/scenes/nfc_maker_scene_config.h diff --git a/applications/external/nfc_maker/scenes/nfc_maker_scene_https.c b/applications/external/nfc_maker_203/scenes/nfc_maker_scene_https.c similarity index 100% rename from applications/external/nfc_maker/scenes/nfc_maker_scene_https.c rename to applications/external/nfc_maker_203/scenes/nfc_maker_scene_https.c diff --git a/applications/external/nfc_maker/scenes/nfc_maker_scene_mail.c b/applications/external/nfc_maker_203/scenes/nfc_maker_scene_mail.c similarity index 100% rename from applications/external/nfc_maker/scenes/nfc_maker_scene_mail.c rename to applications/external/nfc_maker_203/scenes/nfc_maker_scene_mail.c diff --git a/applications/external/nfc_maker/scenes/nfc_maker_scene_menu.c b/applications/external/nfc_maker_203/scenes/nfc_maker_scene_menu.c similarity index 100% rename from applications/external/nfc_maker/scenes/nfc_maker_scene_menu.c rename to applications/external/nfc_maker_203/scenes/nfc_maker_scene_menu.c diff --git a/applications/external/nfc_maker/scenes/nfc_maker_scene_name.c b/applications/external/nfc_maker_203/scenes/nfc_maker_scene_name.c similarity index 100% rename from applications/external/nfc_maker/scenes/nfc_maker_scene_name.c rename to applications/external/nfc_maker_203/scenes/nfc_maker_scene_name.c diff --git a/applications/external/nfc_maker/scenes/nfc_maker_scene_phone.c b/applications/external/nfc_maker_203/scenes/nfc_maker_scene_phone.c similarity index 100% rename from applications/external/nfc_maker/scenes/nfc_maker_scene_phone.c rename to applications/external/nfc_maker_203/scenes/nfc_maker_scene_phone.c diff --git a/applications/external/nfc_maker_203/scenes/nfc_maker_scene_result.c b/applications/external/nfc_maker_203/scenes/nfc_maker_scene_result.c new file mode 100644 index 00000000000..912bf3c9fc3 --- /dev/null +++ b/applications/external/nfc_maker_203/scenes/nfc_maker_scene_result.c @@ -0,0 +1,359 @@ +#include "../nfc_maker.h" + +enum PopupEvent { + PopupEventExit, +}; + +static void nfc_maker_scene_result_popup_callback(void* context) { + NfcMaker* app = context; + + view_dispatcher_send_custom_event(app->view_dispatcher, PopupEventExit); +} + +void nfc_maker_scene_result_on_enter(void* context) { + NfcMaker* app = context; + Popup* popup = app->popup; + bool success = false; + + 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); + do { + if(!flipper_format_file_open_new(file, furi_string_get_cstr(path))) break; + + uint32_t pages = 42; + size_t size = pages * 4; + uint8_t* buf = malloc(size); + + if(!flipper_format_write_header_cstr(file, "Flipper NFC device", 3)) break; + if(!flipper_format_write_string_cstr(file, "Device type", "NTAG203")) break; + + // Serial number + buf[0] = 0x04; + furi_hal_random_fill_buf(&buf[1], 8); + uint8_t uid[7]; + memcpy(&uid[0], &buf[0], 3); + memcpy(&uid[3], &buf[4], 4); + + if(!flipper_format_write_hex(file, "UID", uid, sizeof(uid))) break; + if(!flipper_format_write_string_cstr(file, "ATQA", "00 44")) break; + if(!flipper_format_write_string_cstr(file, "SAK", "00")) break; + // TODO: Maybe randomize? + if(!flipper_format_write_string_cstr( + file, + "Signature", + "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00")) + break; + if(!flipper_format_write_string_cstr(file, "Mifare version", "00 00 00 00 00 00 00 00")) + break; + + if(!flipper_format_write_string_cstr(file, "Counter 0", "0")) break; + if(!flipper_format_write_string_cstr(file, "Tearing 0", "00")) break; + if(!flipper_format_write_string_cstr(file, "Counter 1", "0")) break; + if(!flipper_format_write_string_cstr(file, "Tearing 1", "00")) break; + if(!flipper_format_write_string_cstr(file, "Counter 2", "0")) break; + if(!flipper_format_write_string_cstr(file, "Tearing 2", "00")) break; + if(!flipper_format_write_uint32(file, "Pages total", &pages, 1)) break; + + // Static data + buf[9] = 0x48; // Internal + buf[10] = 0x00; // Lock bytes + buf[11] = 0x00; // ... + buf[12] = 0xE1; // Capability container + buf[13] = 0x10; // ... + buf[14] = 0x12; // ... + buf[15] = 0x00; // ... + buf[16] = 0x01; // ... + buf[17] = 0x03; // ... + buf[18] = 0xA0; // ... + buf[19] = 0x10; // ... + buf[20] = 0x44; // ... + buf[21] = 0x03; // Message flags + + size_t msg_len = 0; + switch(scene_manager_get_scene_state(app->scene_manager, NfcMakerSceneMenu)) { + case NfcMakerSceneBluetooth: { + msg_len = 0x2B; + + buf[23] = 0xD2; + buf[24] = 0x20; + buf[25] = 0x08; + buf[26] = 0x61; + buf[27] = 0x70; + + buf[28] = 0x70; + buf[29] = 0x6C; + buf[30] = 0x69; + buf[31] = 0x63; + + buf[32] = 0x61; + buf[33] = 0x74; + buf[34] = 0x69; + buf[35] = 0x6F; + + buf[36] = 0x6E; + buf[37] = 0x2F; + buf[38] = 0x76; + buf[39] = 0x6E; + + buf[40] = 0x64; + buf[41] = 0x2E; + buf[42] = 0x62; + buf[43] = 0x6C; + + buf[44] = 0x75; + buf[45] = 0x65; + buf[46] = 0x74; + buf[47] = 0x6F; + + buf[48] = 0x6F; + buf[49] = 0x74; + buf[50] = 0x68; + buf[51] = 0x2E; + + buf[52] = 0x65; + buf[53] = 0x70; + buf[54] = 0x2E; + buf[55] = 0x6F; + + buf[56] = 0x6F; + buf[57] = 0x62; + buf[58] = 0x08; + buf[59] = 0x00; + + memcpy(&buf[60], app->mac_buf, GAP_MAC_ADDR_SIZE); + break; + } + case NfcMakerSceneHttps: { + uint8_t data_len = strnlen(app->text_buf, TEXT_INPUT_LEN); + msg_len = data_len + 5; + + buf[23] = 0xD1; + buf[24] = 0x01; + buf[25] = data_len + 1; + buf[26] = 0x55; + + buf[27] = 0x04; // Prepend "https://" + memcpy(&buf[28], app->text_buf, data_len); + break; + } + case NfcMakerSceneMail: { + uint8_t data_len = strnlen(app->text_buf, TEXT_INPUT_LEN); + msg_len = data_len + 5; + + buf[23] = 0xD1; + buf[24] = 0x01; + buf[25] = data_len + 1; + buf[26] = 0x55; + + buf[27] = 0x06; // Prepend "mailto:" + memcpy(&buf[28], app->text_buf, data_len); + break; + } + case NfcMakerScenePhone: { + uint8_t data_len = strnlen(app->text_buf, TEXT_INPUT_LEN); + msg_len = data_len + 5; + + buf[23] = 0xD1; + buf[24] = 0x01; + buf[25] = data_len + 1; + buf[26] = 0x55; + + buf[27] = 0x05; // Prepend "tel:" + memcpy(&buf[28], app->text_buf, data_len); + break; + } + case NfcMakerSceneText: { + uint8_t data_len = strnlen(app->text_buf, TEXT_INPUT_LEN); + msg_len = data_len + 7; + + buf[23] = 0xD1; + buf[24] = 0x01; + buf[25] = data_len + 3; + buf[26] = 0x54; + + buf[27] = 0x02; + buf[28] = 0x65; // e + buf[29] = 0x6E; // n + memcpy(&buf[30], app->text_buf, data_len); + break; + } + case NfcMakerSceneUrl: { + uint8_t data_len = strnlen(app->text_buf, TEXT_INPUT_LEN); + msg_len = data_len + 5; + + buf[23] = 0xD1; + buf[24] = 0x01; + buf[25] = data_len + 1; + buf[26] = 0x55; + + buf[27] = 0x00; // No prepend + memcpy(&buf[28], app->text_buf, 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); + uint8_t data_len = ssid_len + pass_len; + msg_len = data_len + 73; + + buf[23] = 0xD2; + buf[24] = 0x17; + buf[25] = data_len + 47; + buf[26] = 0x61; + buf[27] = 0x70; + + buf[28] = 0x70; + buf[29] = 0x6C; + buf[30] = 0x69; + buf[31] = 0x63; + + buf[32] = 0x61; + buf[33] = 0x74; + buf[34] = 0x69; + buf[35] = 0x6F; + + buf[36] = 0x6E; + buf[37] = 0x2F; + buf[38] = 0x76; + buf[39] = 0x6E; + + buf[40] = 0x64; + buf[41] = 0x2E; + buf[42] = 0x77; + buf[43] = 0x66; + + buf[44] = 0x61; + buf[45] = 0x2E; + buf[46] = 0x77; + buf[47] = 0x73; + + buf[48] = 0x63; + buf[49] = 0x10; + buf[50] = 0x0E; + buf[51] = 0x00; + + buf[52] = data_len + 43; + buf[53] = 0x10; + buf[54] = 0x26; + buf[55] = 0x00; + + buf[56] = 0x01; + buf[57] = 0x01; + buf[58] = 0x10; + buf[59] = 0x45; + + buf[60] = 0x00; + buf[61] = ssid_len; + memcpy(&buf[62], app->text_buf, ssid_len); + size_t ssid = 62 + ssid_len; + buf[ssid + 0] = 0x10; + buf[ssid + 1] = 0x03; + + buf[ssid + 2] = 0x00; + buf[ssid + 3] = 0x02; + buf[ssid + 4] = 0x00; + buf[ssid + 5] = + scene_manager_get_scene_state(app->scene_manager, NfcMakerSceneWifiAuth); + + buf[ssid + 6] = 0x10; + buf[ssid + 7] = 0x0F; + buf[ssid + 8] = 0x00; + buf[ssid + 9] = 0x02; + + buf[ssid + 10] = 0x00; + buf[ssid + 11] = + scene_manager_get_scene_state(app->scene_manager, NfcMakerSceneWifiEncr); + buf[ssid + 12] = 0x10; + buf[ssid + 13] = 0x27; + + buf[ssid + 14] = 0x00; + buf[ssid + 15] = pass_len; + memcpy(&buf[ssid + 16], app->pass_buf, pass_len); + size_t pass = ssid + 16 + pass_len; + buf[pass + 0] = 0x10; + buf[pass + 1] = 0x20; + + buf[pass + 2] = 0x00; + buf[pass + 3] = 0x06; + buf[pass + 4] = 0xFF; + buf[pass + 5] = 0xFF; + + buf[pass + 6] = 0xFF; + buf[pass + 7] = 0xFF; + buf[pass + 8] = 0xFF; + buf[pass + 9] = 0xFF; + + break; + } + default: + break; + } + + // Message length and terminator + buf[22] = msg_len; + size_t msg_end = 23 + msg_len; + buf[msg_end] = 0xFE; + + // Padding + for(size_t i = msg_end + 1; i < size; i++) { + buf[i] = 0x00; + } + + char str[16]; + bool ok = true; + for(size_t page = 0; page < pages; page++) { + snprintf(str, sizeof(str), "Page %u", page); + if(!flipper_format_write_hex(file, str, &buf[page * 4], 4)) { + ok = false; + break; + } + } + if(!ok) break; + + free(buf); + success = true; + + } while(false); + furi_string_free(path); + flipper_format_free(file); + furi_record_close(RECORD_STORAGE); + + if(success) { + popup_set_icon(popup, 32, 5, &I_DolphinNice_96x59); + popup_set_header(popup, "Saved!", 13, 22, AlignLeft, AlignBottom); + } else { + popup_set_icon(popup, 32, 5, &I_DolphinNice_96x59); + popup_set_header(popup, "Saved!", 13, 22, AlignLeft, AlignBottom); + } + popup_set_timeout(popup, 1500); + popup_set_context(popup, app); + popup_set_callback(popup, nfc_maker_scene_result_popup_callback); + popup_enable_timeout(popup); + + view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewPopup); +} + +bool nfc_maker_scene_result_on_event(void* context, SceneManagerEvent event) { + NfcMaker* app = context; + bool consumed = false; + + if(event.type == SceneManagerEventTypeCustom) { + consumed = true; + switch(event.event) { + case PopupEventExit: + scene_manager_search_and_switch_to_previous_scene( + app->scene_manager, NfcMakerSceneMenu); + break; + default: + break; + } + } + + return consumed; +} + +void nfc_maker_scene_result_on_exit(void* context) { + NfcMaker* app = context; + popup_reset(app->popup); +} diff --git a/applications/external/nfc_maker/scenes/nfc_maker_scene_text.c b/applications/external/nfc_maker_203/scenes/nfc_maker_scene_text.c similarity index 100% rename from applications/external/nfc_maker/scenes/nfc_maker_scene_text.c rename to applications/external/nfc_maker_203/scenes/nfc_maker_scene_text.c diff --git a/applications/external/nfc_maker/scenes/nfc_maker_scene_url.c b/applications/external/nfc_maker_203/scenes/nfc_maker_scene_url.c similarity index 100% rename from applications/external/nfc_maker/scenes/nfc_maker_scene_url.c rename to applications/external/nfc_maker_203/scenes/nfc_maker_scene_url.c diff --git a/applications/external/nfc_maker/scenes/nfc_maker_scene_wifi.c b/applications/external/nfc_maker_203/scenes/nfc_maker_scene_wifi.c similarity index 100% rename from applications/external/nfc_maker/scenes/nfc_maker_scene_wifi.c rename to applications/external/nfc_maker_203/scenes/nfc_maker_scene_wifi.c diff --git a/applications/external/nfc_maker/scenes/nfc_maker_scene_wifi_auth.c b/applications/external/nfc_maker_203/scenes/nfc_maker_scene_wifi_auth.c similarity index 100% rename from applications/external/nfc_maker/scenes/nfc_maker_scene_wifi_auth.c rename to applications/external/nfc_maker_203/scenes/nfc_maker_scene_wifi_auth.c diff --git a/applications/external/nfc_maker/scenes/nfc_maker_scene_wifi_encr.c b/applications/external/nfc_maker_203/scenes/nfc_maker_scene_wifi_encr.c similarity index 100% rename from applications/external/nfc_maker/scenes/nfc_maker_scene_wifi_encr.c rename to applications/external/nfc_maker_203/scenes/nfc_maker_scene_wifi_encr.c diff --git a/applications/external/nfc_maker/scenes/nfc_maker_scene_wifi_pass.c b/applications/external/nfc_maker_203/scenes/nfc_maker_scene_wifi_pass.c similarity index 100% rename from applications/external/nfc_maker/scenes/nfc_maker_scene_wifi_pass.c rename to applications/external/nfc_maker_203/scenes/nfc_maker_scene_wifi_pass.c diff --git a/applications/external/nfc_maker/strnlen.c b/applications/external/nfc_maker_203/strnlen.c similarity index 100% rename from applications/external/nfc_maker/strnlen.c rename to applications/external/nfc_maker_203/strnlen.c diff --git a/applications/external/nfc_maker/strnlen.h b/applications/external/nfc_maker_203/strnlen.h similarity index 100% rename from applications/external/nfc_maker/strnlen.h rename to applications/external/nfc_maker_203/strnlen.h diff --git a/applications/external/nfc_maker_215/application.fam b/applications/external/nfc_maker_215/application.fam new file mode 100644 index 00000000000..b76b678f7d2 --- /dev/null +++ b/applications/external/nfc_maker_215/application.fam @@ -0,0 +1,20 @@ +App( + appid="NFC_Maker_NTAG215", + name="NFC Maker NTAG215", + 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_icon_assets_symbol="nfc_maker2", + fap_author="Willy-JL", + fap_weburl="https://github.com/DarkFlippers/unleashed-firmware/tree/dev/applications/external/nfc_maker", + # fap_version="1.0", + fap_description="make tags with URLs, Wifi and other things", +) \ No newline at end of file diff --git a/applications/external/nfc_maker_215/assets/DolphinNice_96x59.png b/applications/external/nfc_maker_215/assets/DolphinNice_96x59.png new file mode 100644 index 00000000000..a299d363023 Binary files /dev/null and b/applications/external/nfc_maker_215/assets/DolphinNice_96x59.png differ diff --git a/applications/external/nfc_maker_215/assets/KeyBackspaceSelected_16x9.png b/applications/external/nfc_maker_215/assets/KeyBackspaceSelected_16x9.png new file mode 100644 index 00000000000..7cc0759a8ca Binary files /dev/null and b/applications/external/nfc_maker_215/assets/KeyBackspaceSelected_16x9.png differ diff --git a/applications/external/nfc_maker_215/assets/KeyBackspace_16x9.png b/applications/external/nfc_maker_215/assets/KeyBackspace_16x9.png new file mode 100644 index 00000000000..9946232d953 Binary files /dev/null and b/applications/external/nfc_maker_215/assets/KeyBackspace_16x9.png differ diff --git a/applications/external/nfc_maker_215/assets/KeyKeyboardSelected_10x11.png b/applications/external/nfc_maker_215/assets/KeyKeyboardSelected_10x11.png new file mode 100644 index 00000000000..231880386a9 Binary files /dev/null and b/applications/external/nfc_maker_215/assets/KeyKeyboardSelected_10x11.png differ diff --git a/applications/external/nfc_maker_215/assets/KeyKeyboard_10x11.png b/applications/external/nfc_maker_215/assets/KeyKeyboard_10x11.png new file mode 100644 index 00000000000..1f4c03478f6 Binary files /dev/null and b/applications/external/nfc_maker_215/assets/KeyKeyboard_10x11.png differ diff --git a/applications/external/nfc_maker_215/assets/KeySaveSelected_24x11.png b/applications/external/nfc_maker_215/assets/KeySaveSelected_24x11.png new file mode 100644 index 00000000000..eeb3569d3ac Binary files /dev/null and b/applications/external/nfc_maker_215/assets/KeySaveSelected_24x11.png differ diff --git a/applications/external/nfc_maker_215/assets/KeySave_24x11.png b/applications/external/nfc_maker_215/assets/KeySave_24x11.png new file mode 100644 index 00000000000..e7dba987a04 Binary files /dev/null and b/applications/external/nfc_maker_215/assets/KeySave_24x11.png differ diff --git a/applications/external/nfc_maker_215/assets/WarningDolphin_45x42.png b/applications/external/nfc_maker_215/assets/WarningDolphin_45x42.png new file mode 100644 index 00000000000..d766ffbb444 Binary files /dev/null and b/applications/external/nfc_maker_215/assets/WarningDolphin_45x42.png differ diff --git a/applications/external/nfc_maker_215/nfc_maker.c b/applications/external/nfc_maker_215/nfc_maker.c new file mode 100644 index 00000000000..6e61f1a163e --- /dev/null +++ b/applications/external/nfc_maker_215/nfc_maker.c @@ -0,0 +1,82 @@ +#include "nfc_maker.h" + +static bool nfc_maker_custom_event_callback(void* context, uint32_t event) { + furi_assert(context); + NfcMaker* app = context; + return scene_manager_handle_custom_event(app->scene_manager, event); +} + +static bool nfc_maker_back_event_callback(void* context) { + furi_assert(context); + NfcMaker* app = context; + + return scene_manager_handle_back_event(app->scene_manager); +} + +NfcMaker* nfc_maker_alloc() { + NfcMaker* app = malloc(sizeof(NfcMaker)); + app->gui = furi_record_open(RECORD_GUI); + + // View Dispatcher and Scene Manager + app->view_dispatcher = view_dispatcher_alloc(); + app->scene_manager = scene_manager_alloc(&nfc_maker_scene_handlers, app); + view_dispatcher_enable_queue(app->view_dispatcher); + view_dispatcher_set_event_callback_context(app->view_dispatcher, app); + + view_dispatcher_set_custom_event_callback( + app->view_dispatcher, nfc_maker_custom_event_callback); + view_dispatcher_set_navigation_event_callback( + app->view_dispatcher, nfc_maker_back_event_callback); + + view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen); + + // Gui Modules + app->submenu = submenu_alloc(); + view_dispatcher_add_view( + app->view_dispatcher, NfcMakerViewSubmenu, submenu_get_view(app->submenu)); + + app->text_input = text_input_alloc(); + view_dispatcher_add_view( + app->view_dispatcher, NfcMakerViewTextInput, text_input_get_view(app->text_input)); + + app->byte_input = byte_input_alloc(); + view_dispatcher_add_view( + app->view_dispatcher, NfcMakerViewByteInput, byte_input_get_view(app->byte_input)); + + app->popup = popup_alloc(); + view_dispatcher_add_view(app->view_dispatcher, NfcMakerViewPopup, popup_get_view(app->popup)); + + return app; +} + +void nfc_maker_free(NfcMaker* app) { + furi_assert(app); + + // Gui modules + view_dispatcher_remove_view(app->view_dispatcher, NfcMakerViewSubmenu); + submenu_free(app->submenu); + view_dispatcher_remove_view(app->view_dispatcher, NfcMakerViewTextInput); + text_input_free(app->text_input); + view_dispatcher_remove_view(app->view_dispatcher, NfcMakerViewByteInput); + byte_input_free(app->byte_input); + view_dispatcher_remove_view(app->view_dispatcher, NfcMakerViewPopup); + popup_free(app->popup); + + // View Dispatcher and Scene Manager + view_dispatcher_free(app->view_dispatcher); + scene_manager_free(app->scene_manager); + + // Records + furi_record_close(RECORD_GUI); + free(app); +} + +extern int32_t nfc_maker(void* p) { + UNUSED(p); + NfcMaker* app = nfc_maker_alloc(); + 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; +} diff --git a/applications/external/nfc_maker_215/nfc_maker.h b/applications/external/nfc_maker_215/nfc_maker.h new file mode 100644 index 00000000000..b09b4bc8404 --- /dev/null +++ b/applications/external/nfc_maker_215/nfc_maker.h @@ -0,0 +1,67 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include "nfc_maker2_icons.h" +#include +#include +#include +#include +#include "scenes/nfc_maker_scene.h" +#include +#include +#include +#include + +#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, + WifiAuthenticationWpa2Personal = 0x20, + WifiAuthenticationWpa2Enterprise = 0x10, + WifiAuthenticationWpaPersonal = 0x02, + WifiAuthenticationWpaEnterprise = 0x08, + WifiAuthenticationShared = 0x04, +} WifiAuthentication; + +typedef enum { + WifiEncryptionAes = 0x08, + WifiEncryptionWep = 0x02, + WifiEncryptionTkip = 0x04, + WifiEncryptionNone = 0x01, +} WifiEncryption; + +typedef struct { + Gui* gui; + SceneManager* scene_manager; + ViewDispatcher* view_dispatcher; + Submenu* submenu; + TextInput* text_input; + ByteInput* byte_input; + Popup* popup; + + 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 { + NfcMakerViewSubmenu, + NfcMakerViewTextInput, + NfcMakerViewByteInput, + NfcMakerViewPopup, +} NfcMakerView; diff --git a/applications/external/nfc_maker_215/nfc_maker_10px.png b/applications/external/nfc_maker_215/nfc_maker_10px.png new file mode 100644 index 00000000000..a9e2443f179 Binary files /dev/null and b/applications/external/nfc_maker_215/nfc_maker_10px.png differ diff --git a/applications/external/nfc_maker_215/scenes/nfc_maker_scene.c b/applications/external/nfc_maker_215/scenes/nfc_maker_scene.c new file mode 100644 index 00000000000..3a8b7d5025a --- /dev/null +++ b/applications/external/nfc_maker_215/scenes/nfc_maker_scene.c @@ -0,0 +1,30 @@ +#include "nfc_maker_scene.h" + +// Generate scene on_enter handlers array +#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter, +void (*const nfc_maker_on_enter_handlers[])(void*) = { +#include "nfc_maker_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 nfc_maker_on_event_handlers[])(void* context, SceneManagerEvent event) = { +#include "nfc_maker_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 nfc_maker_on_exit_handlers[])(void* context) = { +#include "nfc_maker_scene_config.h" +}; +#undef ADD_SCENE + +// Initialize scene handlers configuration structure +const SceneManagerHandlers nfc_maker_scene_handlers = { + .on_enter_handlers = nfc_maker_on_enter_handlers, + .on_event_handlers = nfc_maker_on_event_handlers, + .on_exit_handlers = nfc_maker_on_exit_handlers, + .scene_num = NfcMakerSceneNum, +}; diff --git a/applications/external/nfc_maker_215/scenes/nfc_maker_scene.h b/applications/external/nfc_maker_215/scenes/nfc_maker_scene.h new file mode 100644 index 00000000000..5ad69f2330d --- /dev/null +++ b/applications/external/nfc_maker_215/scenes/nfc_maker_scene.h @@ -0,0 +1,29 @@ +#pragma once + +#include + +// Generate scene id and total number +#define ADD_SCENE(prefix, name, id) NfcMakerScene##id, +typedef enum { +#include "nfc_maker_scene_config.h" + NfcMakerSceneNum, +} NfcMakerScene; +#undef ADD_SCENE + +extern const SceneManagerHandlers nfc_maker_scene_handlers; + +// Generate scene on_enter handlers declaration +#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*); +#include "nfc_maker_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 "nfc_maker_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 "nfc_maker_scene_config.h" +#undef ADD_SCENE diff --git a/applications/external/nfc_maker_215/scenes/nfc_maker_scene_bluetooth.c b/applications/external/nfc_maker_215/scenes/nfc_maker_scene_bluetooth.c new file mode 100644 index 00000000000..e392ea096bb --- /dev/null +++ b/applications/external/nfc_maker_215/scenes/nfc_maker_scene_bluetooth.c @@ -0,0 +1,57 @@ +#include "../nfc_maker.h" + +enum ByteInputResult { + ByteInputResultOk, +}; + +static void nfc_maker_scene_bluetooth_byte_input_callback(void* context) { + NfcMaker* app = context; + + view_dispatcher_send_custom_event(app->view_dispatcher, ByteInputResultOk); +} + +void nfc_maker_scene_bluetooth_on_enter(void* context) { + NfcMaker* app = context; + ByteInput* byte_input = app->byte_input; + + byte_input_set_header_text(byte_input, "Enter Bluetooth MAC:"); + + for(size_t i = 0; i < MAC_INPUT_LEN; i++) { + app->mac_buf[i] = 0x69; + } + + byte_input_set_result_callback( + byte_input, + nfc_maker_scene_bluetooth_byte_input_callback, + NULL, + app, + app->mac_buf, + MAC_INPUT_LEN); + + view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewByteInput); +} + +bool nfc_maker_scene_bluetooth_on_event(void* context, SceneManagerEvent event) { + NfcMaker* app = context; + bool consumed = false; + + if(event.type == SceneManagerEventTypeCustom) { + consumed = true; + switch(event.event) { + case ByteInputResultOk: + furi_hal_bt_reverse_mac_addr(app->mac_buf); + scene_manager_next_scene(app->scene_manager, NfcMakerSceneSave); + break; + default: + break; + } + } + + return consumed; +} + +void nfc_maker_scene_bluetooth_on_exit(void* context) { + NfcMaker* app = context; + byte_input_set_result_callback(app->byte_input, NULL, NULL, NULL, NULL, 0); + byte_input_set_header_text(app->byte_input, ""); +} diff --git a/applications/external/nfc_maker_215/scenes/nfc_maker_scene_config.h b/applications/external/nfc_maker_215/scenes/nfc_maker_scene_config.h new file mode 100644 index 00000000000..0ef4f021f6a --- /dev/null +++ b/applications/external/nfc_maker_215/scenes/nfc_maker_scene_config.h @@ -0,0 +1,18 @@ +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) +ADD_SCENE(nfc_maker, text, Text) +ADD_SCENE(nfc_maker, url, Url) +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) diff --git a/applications/external/nfc_maker_215/scenes/nfc_maker_scene_contact.c b/applications/external/nfc_maker_215/scenes/nfc_maker_scene_contact.c new file mode 100644 index 00000000000..ecc0546171f --- /dev/null +++ b/applications/external/nfc_maker_215/scenes/nfc_maker_scene_contact.c @@ -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; + TextInput* text_input = app->text_input; + + text_input_set_header_text(text_input, "Enter First Name:"); + + strlcpy(app->small_buf1, "Ben", SMALL_INPUT_LEN); + + 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; + text_input_reset(app->text_input); +} diff --git a/applications/external/nfc_maker_215/scenes/nfc_maker_scene_contact_last.c b/applications/external/nfc_maker_215/scenes/nfc_maker_scene_contact_last.c new file mode 100644 index 00000000000..78f6ba7126b --- /dev/null +++ b/applications/external/nfc_maker_215/scenes/nfc_maker_scene_contact_last.c @@ -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; + TextInput* text_input = app->text_input; + + text_input_set_header_text(text_input, "Enter Last Name:"); + + strlcpy(app->small_buf2, "Dover", SMALL_INPUT_LEN); + + text_input_set_result_callback( + text_input, + nfc_maker_scene_contact_last_text_input_callback, + app, + app->small_buf2, + SMALL_INPUT_LEN, + true); + + 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; + text_input_reset(app->text_input); +} diff --git a/applications/external/nfc_maker_215/scenes/nfc_maker_scene_contact_mail.c b/applications/external/nfc_maker_215/scenes/nfc_maker_scene_contact_mail.c new file mode 100644 index 00000000000..07f9c3cb7c9 --- /dev/null +++ b/applications/external/nfc_maker_215/scenes/nfc_maker_scene_contact_mail.c @@ -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; + TextInput* text_input = app->text_input; + + text_input_set_header_text(text_input, "Enter Mail Address:"); + + strlcpy(app->mail_buf, "ben.dover@yourmom.zip", MAIL_INPUT_LEN); + + text_input_set_result_callback( + text_input, + nfc_maker_scene_contact_mail_text_input_callback, + app, + app->mail_buf, + MAIL_INPUT_LEN, + true); + + 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; + text_input_reset(app->text_input); +} diff --git a/applications/external/nfc_maker_215/scenes/nfc_maker_scene_contact_phone.c b/applications/external/nfc_maker_215/scenes/nfc_maker_scene_contact_phone.c new file mode 100644 index 00000000000..e9d16a21760 --- /dev/null +++ b/applications/external/nfc_maker_215/scenes/nfc_maker_scene_contact_phone.c @@ -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; + TextInput* text_input = app->text_input; + + text_input_set_header_text(text_input, "Enter Phone Number:"); + + strlcpy(app->phone_buf, "+", PHONE_INPUT_LEN); + + text_input_set_result_callback( + text_input, + nfc_maker_scene_contact_phone_text_input_callback, + app, + app->phone_buf, + PHONE_INPUT_LEN, + false); + + 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; + text_input_reset(app->text_input); +} diff --git a/applications/external/nfc_maker_215/scenes/nfc_maker_scene_contact_url.c b/applications/external/nfc_maker_215/scenes/nfc_maker_scene_contact_url.c new file mode 100644 index 00000000000..1d2f61d2862 --- /dev/null +++ b/applications/external/nfc_maker_215/scenes/nfc_maker_scene_contact_url.c @@ -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; + TextInput* text_input = app->text_input; + + text_input_set_header_text(text_input, "Enter URL Link:"); + + strlcpy(app->big_buf, "flipper-xtre.me", BIG_INPUT_LEN); + + text_input_set_result_callback( + text_input, + nfc_maker_scene_contact_url_text_input_callback, + app, + app->big_buf, + BIG_INPUT_LEN, + true); + + 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; + text_input_reset(app->text_input); +} diff --git a/applications/external/nfc_maker_215/scenes/nfc_maker_scene_https.c b/applications/external/nfc_maker_215/scenes/nfc_maker_scene_https.c new file mode 100644 index 00000000000..a814f8e222c --- /dev/null +++ b/applications/external/nfc_maker_215/scenes/nfc_maker_scene_https.c @@ -0,0 +1,53 @@ +#include "../nfc_maker.h" + +enum TextInputResult { + TextInputResultOk, +}; + +static void nfc_maker_scene_https_text_input_callback(void* context) { + NfcMaker* app = context; + + view_dispatcher_send_custom_event(app->view_dispatcher, TextInputResultOk); +} + +void nfc_maker_scene_https_on_enter(void* context) { + NfcMaker* app = context; + TextInput* text_input = app->text_input; + + text_input_set_header_text(text_input, "Enter Https Link:"); + + 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->big_buf, + BIG_INPUT_LEN, + true); + + view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewTextInput); +} + +bool nfc_maker_scene_https_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_https_on_exit(void* context) { + NfcMaker* app = context; + text_input_reset(app->text_input); +} diff --git a/applications/external/nfc_maker_215/scenes/nfc_maker_scene_mail.c b/applications/external/nfc_maker_215/scenes/nfc_maker_scene_mail.c new file mode 100644 index 00000000000..eba7319d482 --- /dev/null +++ b/applications/external/nfc_maker_215/scenes/nfc_maker_scene_mail.c @@ -0,0 +1,53 @@ +#include "../nfc_maker.h" + +enum TextInputResult { + TextInputResultOk, +}; + +static void nfc_maker_scene_mail_text_input_callback(void* context) { + NfcMaker* app = context; + + view_dispatcher_send_custom_event(app->view_dispatcher, TextInputResultOk); +} + +void nfc_maker_scene_mail_on_enter(void* context) { + NfcMaker* app = context; + TextInput* text_input = app->text_input; + + text_input_set_header_text(text_input, "Enter Mail Address:"); + + 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->mail_buf, + MAIL_INPUT_LEN, + true); + + view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewTextInput); +} + +bool nfc_maker_scene_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, NfcMakerSceneSave); + break; + default: + break; + } + } + + return consumed; +} + +void nfc_maker_scene_mail_on_exit(void* context) { + NfcMaker* app = context; + text_input_reset(app->text_input); +} diff --git a/applications/external/nfc_maker_215/scenes/nfc_maker_scene_phone.c b/applications/external/nfc_maker_215/scenes/nfc_maker_scene_phone.c new file mode 100644 index 00000000000..27ad9e67167 --- /dev/null +++ b/applications/external/nfc_maker_215/scenes/nfc_maker_scene_phone.c @@ -0,0 +1,53 @@ +#include "../nfc_maker.h" + +enum TextInputResult { + TextInputResultOk, +}; + +static void nfc_maker_scene_phone_text_input_callback(void* context) { + NfcMaker* app = context; + + view_dispatcher_send_custom_event(app->view_dispatcher, TextInputResultOk); +} + +void nfc_maker_scene_phone_on_enter(void* context) { + NfcMaker* app = context; + TextInput* text_input = app->text_input; + + text_input_set_header_text(text_input, "Enter Phone Number:"); + + strlcpy(app->phone_buf, "+", PHONE_INPUT_LEN); + + text_input_set_result_callback( + text_input, + nfc_maker_scene_phone_text_input_callback, + app, + app->phone_buf, + PHONE_INPUT_LEN, + false); + + view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewTextInput); +} + +bool nfc_maker_scene_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, NfcMakerSceneSave); + break; + default: + break; + } + } + + return consumed; +} + +void nfc_maker_scene_phone_on_exit(void* context) { + NfcMaker* app = context; + text_input_reset(app->text_input); +} diff --git a/applications/external/nfc_maker_215/scenes/nfc_maker_scene_result.c b/applications/external/nfc_maker_215/scenes/nfc_maker_scene_result.c new file mode 100644 index 00000000000..ad7371b5c65 --- /dev/null +++ b/applications/external/nfc_maker_215/scenes/nfc_maker_scene_result.c @@ -0,0 +1,400 @@ +#include "../nfc_maker.h" + +enum PopupEvent { + PopupEventExit, +}; + +static void nfc_maker_scene_result_popup_callback(void* context) { + NfcMaker* app = context; + + view_dispatcher_send_custom_event(app->view_dispatcher, PopupEventExit); +} + +void nfc_maker_scene_result_on_enter(void* context) { + NfcMaker* app = context; + Popup* popup = app->popup; + bool success = false; + + 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->save_buf); + + uint32_t pages = 135; + size_t size = pages * 4; + uint8_t* buf = malloc(size); + do { + if(!flipper_format_file_open_new(file, furi_string_get_cstr(path))) break; + + if(!flipper_format_write_header_cstr(file, "Flipper NFC device", 3)) break; + if(!flipper_format_write_string_cstr(file, "Device type", "NTAG215")) break; + + // Serial number + size_t i = 0; + buf[i++] = 0x04; + furi_hal_random_fill_buf(&buf[i], 8); + i += 8; + uint8_t uid[7]; + memcpy(&uid[0], &buf[0], 3); + memcpy(&uid[3], &buf[4], 4); + + if(!flipper_format_write_hex(file, "UID", uid, sizeof(uid))) break; + if(!flipper_format_write_string_cstr(file, "ATQA", "00 44")) break; + if(!flipper_format_write_string_cstr(file, "SAK", "00")) break; + // TODO: Maybe randomize? + if(!flipper_format_write_string_cstr( + file, + "Signature", + "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00")) + break; + if(!flipper_format_write_string_cstr(file, "Mifare version", "00 04 04 02 01 00 11 03")) + break; + + if(!flipper_format_write_string_cstr(file, "Counter 0", "0")) break; + if(!flipper_format_write_string_cstr(file, "Tearing 0", "00")) break; + if(!flipper_format_write_string_cstr(file, "Counter 1", "0")) break; + if(!flipper_format_write_string_cstr(file, "Tearing 1", "00")) break; + if(!flipper_format_write_string_cstr(file, "Counter 2", "0")) break; + if(!flipper_format_write_string_cstr(file, "Tearing 2", "00")) break; + if(!flipper_format_write_uint32(file, "Pages total", &pages, 1)) break; + + // Static data + 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; // 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: { + tnf = 0x02; // Media-type [RFC 2046] + type = "application/vnd.bluetooth.ep.oob"; + + data_len = MAC_INPUT_LEN; + payload_len = data_len + 2; + payload = malloc(payload_len); + + 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"; + + 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"); + + 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: { + tnf = 0x01; // NFC Forum well-known type [NFC RTD] + type = "\x55"; + + 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->big_buf, data_len); + j += data_len; + break; + } + case NfcMakerSceneMail: { + tnf = 0x01; // NFC Forum well-known type [NFC RTD] + type = "\x55"; + + 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->mail_buf, data_len); + j += data_len; + break; + } + case NfcMakerScenePhone: { + tnf = 0x01; // NFC Forum well-known type [NFC RTD] + type = "\x55"; + + 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->phone_buf, data_len); + j += data_len; + break; + } + case NfcMakerSceneText: { + tnf = 0x01; // NFC Forum well-known type [NFC RTD] + type = "\x54"; + + 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->big_buf, data_len); + j += data_len; + break; + } + case NfcMakerSceneUrl: { + tnf = 0x01; // NFC Forum well-known type [NFC RTD] + type = "\x55"; + + 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->big_buf, data_len); + j += data_len; + break; + } + case NfcMakerSceneWifi: { + 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); + + payload[j++] = 0x10; + payload[j++] = 0x0E; + payload[j++] = 0x00; + + payload[j++] = data_len + 43; + payload[j++] = 0x10; + payload[j++] = 0x26; + payload[j++] = 0x00; + + payload[j++] = 0x01; + payload[j++] = 0x01; + payload[j++] = 0x10; + payload[j++] = 0x45; + + payload[j++] = 0x00; + payload[j++] = ssid_len; + memcpy(&payload[j], app->small_buf1, ssid_len); + j += ssid_len; + payload[j++] = 0x10; + payload[j++] = 0x03; + + payload[j++] = 0x00; + payload[j++] = 0x02; + payload[j++] = 0x00; + payload[j++] = + scene_manager_get_scene_state(app->scene_manager, NfcMakerSceneWifiAuth); + + payload[j++] = 0x10; + payload[j++] = 0x0F; + payload[j++] = 0x00; + payload[j++] = 0x02; + + payload[j++] = 0x00; + payload[j++] = + scene_manager_get_scene_state(app->scene_manager, NfcMakerSceneWifiEncr); + payload[j++] = 0x10; + payload[j++] = 0x27; + + payload[j++] = 0x00; + payload[j++] = pass_len; + memcpy(&payload[j], app->small_buf2, pass_len); + j += pass_len; + payload[j++] = 0x10; + payload[j++] = 0x20; + + payload[j++] = 0x00; + payload[j++] = 0x06; + payload[j++] = 0xFF; + payload[j++] = 0xFF; + + payload[j++] = 0xFF; + payload[j++] = 0xFF; + payload[j++] = 0xFF; + payload[j++] = 0xFF; + + break; + } + default: + break; + } + + // 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 + for(; i < size - 20; i++) { + buf[i] = 0x00; + } + + // Last 5 static pages + buf[i++] = 0x00; + buf[i++] = 0x00; + buf[i++] = 0x00; + buf[i++] = 0xBD; + + buf[i++] = 0x04; + buf[i++] = 0x00; + buf[i++] = 0x00; + buf[i++] = 0xFF; + + buf[i++] = 0x00; + buf[i++] = 0x05; + buf[i++] = 0x00; + buf[i++] = 0x00; + + buf[i++] = 0xFF; + buf[i++] = 0xFF; + buf[i++] = 0xFF; + buf[i++] = 0xFF; + + buf[i++] = 0x00; + buf[i++] = 0x00; + buf[i++] = 0x00; + buf[i++] = 0x00; + + // Write pages + char str[16]; + bool ok = true; + for(size_t page = 0; page < pages; page++) { + snprintf(str, sizeof(str), "Page %u", page); + if(!flipper_format_write_hex(file, str, &buf[page * 4], 4)) { + ok = false; + break; + } + } + if(!ok) break; + + success = true; + + } while(false); + free(buf); + + furi_string_free(path); + flipper_format_free(file); + furi_record_close(RECORD_STORAGE); + + if(success) { + popup_set_icon(popup, 32, 5, &I_DolphinNice_96x59); + popup_set_header(popup, "Saved!", 13, 22, AlignLeft, AlignBottom); + } else { + popup_set_icon(popup, 32, 5, &I_DolphinNice_96x59); + popup_set_header(popup, "Saved!", 13, 22, AlignLeft, AlignBottom); + } + popup_set_timeout(popup, 1500); + popup_set_context(popup, app); + popup_set_callback(popup, nfc_maker_scene_result_popup_callback); + popup_enable_timeout(popup); + + view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewPopup); +} + +bool nfc_maker_scene_result_on_event(void* context, SceneManagerEvent event) { + NfcMaker* app = context; + bool consumed = false; + + if(event.type == SceneManagerEventTypeCustom) { + consumed = true; + switch(event.event) { + case PopupEventExit: + scene_manager_search_and_switch_to_previous_scene( + app->scene_manager, NfcMakerSceneStart); + break; + default: + break; + } + } + + return consumed; +} + +void nfc_maker_scene_result_on_exit(void* context) { + NfcMaker* app = context; + popup_reset(app->popup); +} diff --git a/applications/external/nfc_maker_215/scenes/nfc_maker_scene_save.c b/applications/external/nfc_maker_215/scenes/nfc_maker_scene_save.c new file mode 100644 index 00000000000..e307c92dcd6 --- /dev/null +++ b/applications/external/nfc_maker_215/scenes/nfc_maker_scene_save.c @@ -0,0 +1,57 @@ +#include "../nfc_maker.h" + +enum TextInputResult { + TextInputResultOk, +}; + +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_save_on_enter(void* context) { + NfcMaker* app = context; + TextInput* text_input = app->text_input; + + text_input_set_header_text(text_input, "Save the NFC tag:"); + + set_random_name(app->save_buf, BIG_INPUT_LEN); + + text_input_set_result_callback( + text_input, + nfc_maker_scene_save_text_input_callback, + app, + app->save_buf, + BIG_INPUT_LEN, + true); + + ValidatorIsFile* validator_is_file = + validator_is_file_alloc_init(NFC_APP_FOLDER, NFC_APP_EXTENSION, NULL); + text_input_set_validator(text_input, validator_is_file_callback, validator_is_file); + + view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewTextInput); +} + +bool nfc_maker_scene_save_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, NfcMakerSceneResult); + break; + default: + break; + } + } + + return consumed; +} + +void nfc_maker_scene_save_on_exit(void* context) { + NfcMaker* app = context; + text_input_reset(app->text_input); +} diff --git a/applications/external/nfc_maker_215/scenes/nfc_maker_scene_start.c b/applications/external/nfc_maker_215/scenes/nfc_maker_scene_start.c new file mode 100644 index 00000000000..e791b1284a1 --- /dev/null +++ b/applications/external/nfc_maker_215/scenes/nfc_maker_scene_start.c @@ -0,0 +1,68 @@ +#include "../nfc_maker.h" + +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_start_on_enter(void* context) { + NfcMaker* app = context; + Submenu* submenu = app->submenu; + + submenu_set_header(submenu, "NFC Tag Maker:"); + + submenu_add_item( + submenu, + "Bluetooth MAC", + NfcMakerSceneBluetooth, + nfc_maker_scene_start_submenu_callback, + app); + + submenu_add_item( + submenu, + "Contact Vcard", + NfcMakerSceneContact, + nfc_maker_scene_start_submenu_callback, + app); + + submenu_add_item( + submenu, "HTTPS Link", NfcMakerSceneHttps, nfc_maker_scene_start_submenu_callback, app); + + submenu_add_item( + submenu, "Mail Address", NfcMakerSceneMail, nfc_maker_scene_start_submenu_callback, app); + + submenu_add_item( + submenu, "Phone Number", NfcMakerScenePhone, nfc_maker_scene_start_submenu_callback, app); + + submenu_add_item( + submenu, "Text Note", NfcMakerSceneText, nfc_maker_scene_start_submenu_callback, app); + + submenu_add_item( + 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, NfcMakerSceneStart)); + + view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewSubmenu); +} + +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, NfcMakerSceneStart, event.event); + consumed = true; + scene_manager_next_scene(app->scene_manager, event.event); + } + + return consumed; +} + +void nfc_maker_scene_start_on_exit(void* context) { + NfcMaker* app = context; + submenu_reset(app->submenu); +} diff --git a/applications/external/nfc_maker_215/scenes/nfc_maker_scene_text.c b/applications/external/nfc_maker_215/scenes/nfc_maker_scene_text.c new file mode 100644 index 00000000000..4c86f3b52d8 --- /dev/null +++ b/applications/external/nfc_maker_215/scenes/nfc_maker_scene_text.c @@ -0,0 +1,53 @@ +#include "../nfc_maker.h" + +enum TextInputResult { + TextInputResultOk, +}; + +static void nfc_maker_scene_text_text_input_callback(void* context) { + NfcMaker* app = context; + + view_dispatcher_send_custom_event(app->view_dispatcher, TextInputResultOk); +} + +void nfc_maker_scene_text_on_enter(void* context) { + NfcMaker* app = context; + TextInput* text_input = app->text_input; + + text_input_set_header_text(text_input, "Enter Text Note:"); + + 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->big_buf, + BIG_INPUT_LEN, + true); + + view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewTextInput); +} + +bool nfc_maker_scene_text_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_text_on_exit(void* context) { + NfcMaker* app = context; + text_input_reset(app->text_input); +} diff --git a/applications/external/nfc_maker_215/scenes/nfc_maker_scene_url.c b/applications/external/nfc_maker_215/scenes/nfc_maker_scene_url.c new file mode 100644 index 00000000000..f5d2eddaaaa --- /dev/null +++ b/applications/external/nfc_maker_215/scenes/nfc_maker_scene_url.c @@ -0,0 +1,53 @@ +#include "../nfc_maker.h" + +enum TextInputResult { + TextInputResultOk, +}; + +static void nfc_maker_scene_url_text_input_callback(void* context) { + NfcMaker* app = context; + + view_dispatcher_send_custom_event(app->view_dispatcher, TextInputResultOk); +} + +void nfc_maker_scene_url_on_enter(void* context) { + NfcMaker* app = context; + TextInput* text_input = app->text_input; + + text_input_set_header_text(text_input, "Enter Plain URL:"); + + 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->big_buf, + BIG_INPUT_LEN, + true); + + view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewTextInput); +} + +bool nfc_maker_scene_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_url_on_exit(void* context) { + NfcMaker* app = context; + text_input_reset(app->text_input); +} diff --git a/applications/external/nfc_maker_215/scenes/nfc_maker_scene_wifi.c b/applications/external/nfc_maker_215/scenes/nfc_maker_scene_wifi.c new file mode 100644 index 00000000000..cfbc51ace35 --- /dev/null +++ b/applications/external/nfc_maker_215/scenes/nfc_maker_scene_wifi.c @@ -0,0 +1,55 @@ +#include "../nfc_maker.h" + +enum TextInputResult { + TextInputResultOk, +}; + +static void nfc_maker_scene_wifi_text_input_callback(void* context) { + NfcMaker* app = context; + + view_dispatcher_send_custom_event(app->view_dispatcher, TextInputResultOk); +} + +void nfc_maker_scene_wifi_on_enter(void* context) { + NfcMaker* app = context; + TextInput* text_input = app->text_input; + + text_input_set_header_text(text_input, "Enter WiFi SSID:"); + + 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->small_buf1, + SMALL_INPUT_LEN, + true); + + view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewTextInput); +} + +bool nfc_maker_scene_wifi_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_set_scene_state( + app->scene_manager, NfcMakerSceneWifiAuth, WifiAuthenticationWpa2Personal); + scene_manager_next_scene(app->scene_manager, NfcMakerSceneWifiAuth); + break; + default: + break; + } + } + + return consumed; +} + +void nfc_maker_scene_wifi_on_exit(void* context) { + NfcMaker* app = context; + text_input_reset(app->text_input); +} diff --git a/applications/external/nfc_maker_215/scenes/nfc_maker_scene_wifi_auth.c b/applications/external/nfc_maker_215/scenes/nfc_maker_scene_wifi_auth.c new file mode 100644 index 00000000000..6e14c4e97e5 --- /dev/null +++ b/applications/external/nfc_maker_215/scenes/nfc_maker_scene_wifi_auth.c @@ -0,0 +1,83 @@ +#include "../nfc_maker.h" + +void nfc_maker_scene_wifi_auth_submenu_callback(void* context, uint32_t index) { + NfcMaker* app = context; + view_dispatcher_send_custom_event(app->view_dispatcher, index); +} + +void nfc_maker_scene_wifi_auth_on_enter(void* context) { + NfcMaker* app = context; + Submenu* submenu = app->submenu; + + submenu_set_header(submenu, "Authentication Type:"); + + submenu_add_item( + submenu, "Open", WifiAuthenticationOpen, nfc_maker_scene_wifi_auth_submenu_callback, app); + + submenu_add_item( + submenu, + "WPA 2 Personal", + WifiAuthenticationWpa2Personal, + nfc_maker_scene_wifi_auth_submenu_callback, + app); + + submenu_add_item( + submenu, + "WPA 2 Enterprise", + WifiAuthenticationWpa2Enterprise, + nfc_maker_scene_wifi_auth_submenu_callback, + app); + + submenu_add_item( + submenu, + "WPA Personal", + WifiAuthenticationWpaPersonal, + nfc_maker_scene_wifi_auth_submenu_callback, + app); + + submenu_add_item( + submenu, + "WPA Enterprise", + WifiAuthenticationWpaEnterprise, + nfc_maker_scene_wifi_auth_submenu_callback, + app); + + submenu_add_item( + submenu, + "Shared", + WifiAuthenticationShared, + nfc_maker_scene_wifi_auth_submenu_callback, + app); + + submenu_set_selected_item( + submenu, scene_manager_get_scene_state(app->scene_manager, NfcMakerSceneWifiAuth)); + + view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewSubmenu); +} + +bool nfc_maker_scene_wifi_auth_on_event(void* context, SceneManagerEvent event) { + NfcMaker* app = context; + bool consumed = false; + + if(event.type == SceneManagerEventTypeCustom) { + scene_manager_set_scene_state(app->scene_manager, NfcMakerSceneWifiAuth, event.event); + consumed = true; + if(event.event == WifiAuthenticationOpen) { + scene_manager_set_scene_state( + app->scene_manager, NfcMakerSceneWifiEncr, WifiEncryptionNone); + strcpy(app->small_buf2, ""); + scene_manager_next_scene(app->scene_manager, NfcMakerSceneSave); + } else { + scene_manager_set_scene_state( + app->scene_manager, NfcMakerSceneWifiEncr, WifiEncryptionAes); + scene_manager_next_scene(app->scene_manager, NfcMakerSceneWifiEncr); + } + } + + return consumed; +} + +void nfc_maker_scene_wifi_auth_on_exit(void* context) { + NfcMaker* app = context; + submenu_reset(app->submenu); +} diff --git a/applications/external/nfc_maker_215/scenes/nfc_maker_scene_wifi_encr.c b/applications/external/nfc_maker_215/scenes/nfc_maker_scene_wifi_encr.c new file mode 100644 index 00000000000..d1a21f51a5a --- /dev/null +++ b/applications/external/nfc_maker_215/scenes/nfc_maker_scene_wifi_encr.c @@ -0,0 +1,48 @@ +#include "../nfc_maker.h" + +void nfc_maker_scene_wifi_encr_submenu_callback(void* context, uint32_t index) { + NfcMaker* app = context; + view_dispatcher_send_custom_event(app->view_dispatcher, index); +} + +void nfc_maker_scene_wifi_encr_on_enter(void* context) { + NfcMaker* app = context; + Submenu* submenu = app->submenu; + + submenu_set_header(submenu, "Encryption Type:"); + + submenu_add_item( + submenu, "AES", WifiEncryptionAes, nfc_maker_scene_wifi_encr_submenu_callback, app); + + submenu_add_item( + submenu, "WEP", WifiEncryptionWep, nfc_maker_scene_wifi_encr_submenu_callback, app); + + submenu_add_item( + submenu, "TKIP", WifiEncryptionTkip, nfc_maker_scene_wifi_encr_submenu_callback, app); + + submenu_add_item( + submenu, "None", WifiEncryptionNone, nfc_maker_scene_wifi_encr_submenu_callback, app); + + submenu_set_selected_item( + submenu, scene_manager_get_scene_state(app->scene_manager, NfcMakerSceneWifiEncr)); + + view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewSubmenu); +} + +bool nfc_maker_scene_wifi_encr_on_event(void* context, SceneManagerEvent event) { + NfcMaker* app = context; + bool consumed = false; + + if(event.type == SceneManagerEventTypeCustom) { + scene_manager_set_scene_state(app->scene_manager, NfcMakerSceneWifiEncr, event.event); + consumed = true; + scene_manager_next_scene(app->scene_manager, NfcMakerSceneWifiPass); + } + + return consumed; +} + +void nfc_maker_scene_wifi_encr_on_exit(void* context) { + NfcMaker* app = context; + submenu_reset(app->submenu); +} diff --git a/applications/external/nfc_maker_215/scenes/nfc_maker_scene_wifi_pass.c b/applications/external/nfc_maker_215/scenes/nfc_maker_scene_wifi_pass.c new file mode 100644 index 00000000000..acf1d7447b4 --- /dev/null +++ b/applications/external/nfc_maker_215/scenes/nfc_maker_scene_wifi_pass.c @@ -0,0 +1,53 @@ +#include "../nfc_maker.h" + +enum TextInputResult { + TextInputResultOk, +}; + +static void nfc_maker_scene_wifi_pass_text_input_callback(void* context) { + NfcMaker* app = context; + + view_dispatcher_send_custom_event(app->view_dispatcher, TextInputResultOk); +} + +void nfc_maker_scene_wifi_pass_on_enter(void* context) { + NfcMaker* app = context; + TextInput* text_input = app->text_input; + + text_input_set_header_text(text_input, "Enter WiFi Password:"); + + 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->small_buf2, + SMALL_INPUT_LEN, + true); + + view_dispatcher_switch_to_view(app->view_dispatcher, NfcMakerViewTextInput); +} + +bool nfc_maker_scene_wifi_pass_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_wifi_pass_on_exit(void* context) { + NfcMaker* app = context; + text_input_reset(app->text_input); +}