diff --git a/applications/system/findmy/findmy.c b/applications/system/findmy/findmy.c index 4a292f11a6..7bb10f6b73 100644 --- a/applications/system/findmy/findmy.c +++ b/applications/system/findmy/findmy.c @@ -53,7 +53,7 @@ static FindMy* findmy_app_alloc() { findmy_main_update_active(app->findmy_main, furi_hal_bt_extra_beacon_is_active()); findmy_main_update_interval(app->findmy_main, app->state.broadcast_interval); - findmy_main_update_type(app->findmy_main, findmy_data_get_type(app->state.data)); + findmy_main_update_type(app->findmy_main, app->state.tag_type); return app; } @@ -141,18 +141,12 @@ void findmy_toggle_beacon(FindMy* app) { findmy_main_update_active(app->findmy_main, furi_hal_bt_extra_beacon_is_active()); } -FindMyType findmy_data_get_type(uint8_t data[EXTRA_BEACON_MAX_DATA_SIZE]) { - if(data[0] == 0x1E && // Length - data[1] == 0xFF && // Manufacturer Specific Data - data[2] == 0x4C && // Company ID (Apple, Inc.) - data[3] == 0x00 && // ... - data[4] == 0x12 && // Type (FindMy) - data[5] == 0x19 // Length - ) { - return FindMyTypeApple; - } else { - return FindMyTypeSamsung; - } +void findmy_set_tag_type(FindMy* app, FindMyType type) { + app->state.tag_type = type; + findmy_state_sync_config(&app->state); + findmy_state_save(&app->state); + findmy_main_update_type(app->findmy_main, type); + FURI_LOG_I("TagType2", "Tag Type: %d", type); } void furi_hal_bt_reverse_mac_addr(uint8_t mac_addr[GAP_MAC_ADDR_SIZE]) { diff --git a/applications/system/findmy/findmy.h b/applications/system/findmy/findmy.h index a5135f2d70..344882ef10 100644 --- a/applications/system/findmy/findmy.h +++ b/applications/system/findmy/findmy.h @@ -1,5 +1,3 @@ #pragma once typedef struct FindMy FindMy; - -typedef enum FindMyType FindMyType; \ No newline at end of file diff --git a/applications/system/findmy/findmy_i.h b/applications/system/findmy/findmy_i.h index 51d687401a..8f0920157f 100644 --- a/applications/system/findmy/findmy_i.h +++ b/applications/system/findmy/findmy_i.h @@ -49,12 +49,7 @@ typedef enum { FindMyViewPopup, } FindMyView; -enum FindMyType { - FindMyTypeApple, - FindMyTypeSamsung, -}; - void findmy_change_broadcast_interval(FindMy* app, uint8_t value); void findmy_change_transmit_power(FindMy* app, uint8_t value); +void findmy_set_tag_type(FindMy* app, FindMyType type); void findmy_toggle_beacon(FindMy* app); -FindMyType findmy_data_get_type(uint8_t data[EXTRA_BEACON_MAX_DATA_SIZE]); diff --git a/applications/system/findmy/findmy_state.c b/applications/system/findmy/findmy_state.c index 12e8cbed21..5528080b00 100644 --- a/applications/system/findmy/findmy_state.c +++ b/applications/system/findmy/findmy_state.c @@ -29,9 +29,18 @@ bool findmy_state_load(FindMyState* out_state) { if(!flipper_format_read_uint32(file, "transmit_power", &tmp, 1)) break; state.transmit_power = tmp; + if(!flipper_format_read_uint32(file, "tag_type", &tmp, 1)) { + // Support migrating from old config + tmp = FindMyTypeApple; + flipper_format_rewind(file); + } + state.tag_type = tmp; + if(!flipper_format_read_hex(file, "mac", state.mac, sizeof(state.mac))) break; - if(!flipper_format_read_hex(file, "data", state.data, sizeof(state.data))) break; + if(!flipper_format_read_hex( + file, "data", state.data, findmy_state_data_size(state.tag_type))) + break; loaded_from_file = true; } while(0); @@ -45,6 +54,8 @@ bool findmy_state_load(FindMyState* out_state) { state.broadcast_interval = 5; state.transmit_power = 6; + state.tag_type = FindMyTypeApple; + // Set default mac uint8_t default_mac[EXTRA_BEACON_MAC_ADDR_SIZE] = {0x66, 0x55, 0x44, 0x33, 0x22, 0x11}; memcpy(state.mac, default_mac, sizeof(state.mac)); @@ -88,7 +99,8 @@ void findmy_state_apply(FindMyState* state) { furi_check(furi_hal_bt_extra_beacon_set_config(&state->config)); - furi_check(furi_hal_bt_extra_beacon_set_data(state->data, sizeof(state->data))); + furi_check( + furi_hal_bt_extra_beacon_set_data(state->data, findmy_state_data_size(state->tag_type))); if(state->beacon_active) { furi_check(furi_hal_bt_extra_beacon_start()); @@ -120,11 +132,28 @@ void findmy_state_save(FindMyState* state) { tmp = state->transmit_power; if(!flipper_format_write_uint32(file, "transmit_power", &tmp, 1)) break; + tmp = state->tag_type; + if(!flipper_format_write_uint32(file, "tag_type", &tmp, 1)) break; + if(!flipper_format_write_hex(file, "mac", state->mac, sizeof(state->mac))) break; - if(!flipper_format_write_hex(file, "data", state->data, sizeof(state->data))) break; + if(!flipper_format_write_hex( + file, "data", state->data, findmy_state_data_size(state->tag_type))) + break; } while(0); flipper_format_free(file); furi_record_close(RECORD_STORAGE); } + +uint8_t findmy_state_data_size(FindMyType type) { + switch(type) { + case FindMyTypeApple: + case FindMyTypeSamsung: + return 31; + case FindMyTypeTile: + return 21; + default: + return 0; + } +} diff --git a/applications/system/findmy/findmy_state.h b/applications/system/findmy/findmy_state.h index d11313e588..4b25ffabb8 100644 --- a/applications/system/findmy/findmy_state.h +++ b/applications/system/findmy/findmy_state.h @@ -7,6 +7,12 @@ #define FINDMY_STATE_DIR EXT_PATH("apps_data/findmy") #define FINDMY_STATE_PATH FINDMY_STATE_DIR "/findmy_state.txt" +typedef enum { + FindMyTypeApple, + FindMyTypeSamsung, + FindMyTypeTile, +} FindMyType; + typedef struct { bool beacon_active; uint8_t broadcast_interval; @@ -14,6 +20,7 @@ typedef struct { uint8_t mac[EXTRA_BEACON_MAC_ADDR_SIZE]; uint8_t data[EXTRA_BEACON_MAX_DATA_SIZE]; + FindMyType tag_type; // Generated from the other state values GapExtraBeaconConfig config; @@ -26,3 +33,5 @@ void findmy_state_apply(FindMyState* state); void findmy_state_sync_config(FindMyState* state); void findmy_state_save(FindMyState* state); + +uint8_t findmy_state_data_size(FindMyType type); diff --git a/applications/system/findmy/scenes/findmy_scene_config.c b/applications/system/findmy/scenes/findmy_scene_config.c index eba1a85a2b..13c671c8da 100644 --- a/applications/system/findmy/scenes/findmy_scene_config.c +++ b/applications/system/findmy/scenes/findmy_scene_config.c @@ -3,8 +3,7 @@ enum VarItemListIndex { VarItemListIndexBroadcastInterval, VarItemListIndexTransmitPower, - VarItemListIndexImportTagFromFile, - VarItemListIndexRegisterTagManually, + VarItemListIndexRegisterTag, VarItemListIndexAbout, }; @@ -58,9 +57,7 @@ void findmy_scene_config_on_enter(void* context) { snprintf(power_str, sizeof(power_str), "%ddBm", app->state.transmit_power); variable_item_set_current_value_text(item, power_str); - item = variable_item_list_add(var_item_list, "Import Tag From File", 0, NULL, NULL); - - item = variable_item_list_add(var_item_list, "Register Tag Manually", 0, NULL, NULL); + item = variable_item_list_add(var_item_list, "Register Tag", 0, NULL, NULL); item = variable_item_list_add( var_item_list, @@ -86,11 +83,8 @@ bool findmy_scene_config_on_event(void* context, SceneManagerEvent event) { scene_manager_set_scene_state(app->scene_manager, FindMySceneConfig, event.event); consumed = true; switch(event.event) { - case VarItemListIndexImportTagFromFile: - scene_manager_next_scene(app->scene_manager, FindMySceneConfigImport); - break; - case VarItemListIndexRegisterTagManually: - scene_manager_next_scene(app->scene_manager, FindMySceneConfigMac); + case VarItemListIndexRegisterTag: + scene_manager_next_scene(app->scene_manager, FindMySceneConfigTagtype); break; case VarItemListIndexAbout: break; diff --git a/applications/system/findmy/scenes/findmy_scene_config_import.c b/applications/system/findmy/scenes/findmy_scene_config_import.c index 798c1af44d..d7cc3d7e32 100644 --- a/applications/system/findmy/scenes/findmy_scene_config_import.c +++ b/applications/system/findmy/scenes/findmy_scene_config_import.c @@ -3,6 +3,7 @@ enum VarItemListIndex { VarItemListIndexNrfConnect, VarItemListIndexOpenHaystack, + VarItemListIndexRegisterTagManually, }; static const char* parse_nrf_connect(FindMy* app, const char* path) { @@ -42,10 +43,15 @@ static const char* parse_nrf_connect(FindMy* app, const char* path) { furi_string_trim(line); error = "Wrong payload size"; - uint8_t data[EXTRA_BEACON_MAX_DATA_SIZE]; - if(furi_string_size(line) != sizeof(data) * 2) break; + size_t line_size = furi_string_size(line); + uint8_t data_size = findmy_state_data_size(app->state.tag_type); + FURI_LOG_I("ImportPayload", "Line Size: %d", line_size); + FURI_LOG_I("ImportPayload", "Data Size: %d", data_size * 2); + if(line_size != data_size * 2) break; + // Initialize full data to 0's, then fill only first data_size bytes + uint8_t data[EXTRA_BEACON_MAX_DATA_SIZE] = {0}; error = NULL; - for(size_t i = 0; i < sizeof(data); i++) { + for(size_t i = 0; i < data_size; i++) { char a = furi_string_get_char(line, i * 2); char b = furi_string_get_char(line, i * 2 + 1); if((a < 'A' && a > 'F') || (a < '0' && a > '9') || (b < 'A' && b > 'F') || @@ -151,6 +157,8 @@ void findmy_scene_config_import_on_enter(void* context) { item = variable_item_list_add(var_item_list, "OpenHaystack (.keys)", 0, NULL, NULL); + item = variable_item_list_add(var_item_list, "Register Tag Manually", 0, NULL, NULL); + // This scene acts more like a submenu than a var item list tbh UNUSED(item); @@ -178,6 +186,9 @@ bool findmy_scene_config_import_on_event(void* context, SceneManagerEvent event) case VarItemListIndexOpenHaystack: extension = ".keys"; break; + case VarItemListIndexRegisterTagManually: + scene_manager_next_scene(app->scene_manager, FindMySceneConfigMac); + break; default: break; } diff --git a/applications/system/findmy/scenes/findmy_scene_config_packet.c b/applications/system/findmy/scenes/findmy_scene_config_packet.c index 9d77fb1d79..80f23af98a 100644 --- a/applications/system/findmy/scenes/findmy_scene_config_packet.c +++ b/applications/system/findmy/scenes/findmy_scene_config_packet.c @@ -16,7 +16,7 @@ void findmy_scene_config_packet_on_enter(void* context) { byte_input_set_header_text(byte_input, "Enter Bluetooth Payload:"); - memcpy(app->packet_buf, app->state.data, sizeof(app->packet_buf)); + memcpy(app->packet_buf, app->state.data, findmy_state_data_size(app->state.tag_type)); byte_input_set_result_callback( byte_input, @@ -24,7 +24,7 @@ void findmy_scene_config_packet_on_enter(void* context) { NULL, app, app->packet_buf, - sizeof(app->packet_buf)); + findmy_state_data_size(app->state.tag_type)); view_dispatcher_switch_to_view(app->view_dispatcher, FindMyViewByteInput); } @@ -39,11 +39,10 @@ bool findmy_scene_config_packet_on_event(void* context, SceneManagerEvent event) case ByteInputResultOk: scene_manager_search_and_switch_to_previous_scene( app->scene_manager, FindMySceneConfig); - memcpy(app->state.data, app->packet_buf, sizeof(app->state.data)); + memcpy(app->state.data, app->packet_buf, findmy_state_data_size(app->state.tag_type)); findmy_state_save(&app->state); - furi_check( - furi_hal_bt_extra_beacon_set_data(app->state.data, sizeof(app->state.data))); - findmy_main_update_type(app->findmy_main, findmy_data_get_type(app->state.data)); + furi_check(furi_hal_bt_extra_beacon_set_data( + app->state.data, findmy_state_data_size(app->state.tag_type))); break; default: break; diff --git a/applications/system/findmy/scenes/findmy_scene_config_tagtype.c b/applications/system/findmy/scenes/findmy_scene_config_tagtype.c new file mode 100644 index 0000000000..e43eea7f84 --- /dev/null +++ b/applications/system/findmy/scenes/findmy_scene_config_tagtype.c @@ -0,0 +1,70 @@ +#include "../findmy_i.h" + +enum VarItemListIndex { + VarItemListIndexApple, + VarItemListIndexSamsung, + VarItemListIndexTile, +}; + +void findmy_scene_config_tagtype_callback(void* context, uint32_t index) { + furi_assert(context); + FindMy* app = context; + view_dispatcher_send_custom_event(app->view_dispatcher, index); +} + +void findmy_scene_config_tagtype_on_enter(void* context) { + FindMy* app = context; + VariableItemList* var_item_list = app->var_item_list; + VariableItem* item; + + variable_item_list_set_header(var_item_list, "Choose tag type"); + + item = variable_item_list_add(var_item_list, "Apple AirTag", 0, NULL, NULL); + + item = variable_item_list_add(var_item_list, "Samsung SmartTag", 0, NULL, NULL); + + item = variable_item_list_add(var_item_list, "Tile SmartTag", 0, NULL, NULL); + + UNUSED(item); + + variable_item_list_set_enter_callback( + var_item_list, findmy_scene_config_tagtype_callback, app); + + variable_item_list_set_selected_item( + var_item_list, scene_manager_get_scene_state(app->scene_manager, FindMySceneConfigImport)); + view_dispatcher_switch_to_view(app->view_dispatcher, FindMyViewVarItemList); +} + +bool findmy_scene_config_tagtype_on_event(void* context, SceneManagerEvent event) { + FindMy* app = context; + bool consumed = false; + + if(event.type == SceneManagerEventTypeCustom) { + scene_manager_set_scene_state(app->scene_manager, FindMySceneConfigTagtype, event.event); + consumed = true; + + switch(event.event) { + case VarItemListIndexApple: + findmy_set_tag_type(app, FindMyTypeApple); + break; + case VarItemListIndexSamsung: + findmy_set_tag_type(app, FindMyTypeSamsung); + break; + case VarItemListIndexTile: + findmy_set_tag_type(app, FindMyTypeTile); + break; + default: + break; + } + scene_manager_next_scene(app->scene_manager, FindMySceneConfigImport); + } + + return consumed; +} + +void findmy_scene_config_tagtype_on_exit(void* context) { + FindMy* app = context; + VariableItemList* var_item_list = app->var_item_list; + + variable_item_list_reset(var_item_list); +} \ No newline at end of file diff --git a/applications/system/findmy/scenes/findmy_scenes.h b/applications/system/findmy/scenes/findmy_scenes.h index 9a35c519d9..0680e2c5f9 100644 --- a/applications/system/findmy/scenes/findmy_scenes.h +++ b/applications/system/findmy/scenes/findmy_scenes.h @@ -1,6 +1,7 @@ ADD_SCENE(findmy, main, Main) ADD_SCENE(findmy, config, Config) ADD_SCENE(findmy, config_import, ConfigImport) +ADD_SCENE(findmy, config_tagtype, ConfigTagtype) ADD_SCENE(findmy, config_import_result, ConfigImportResult) ADD_SCENE(findmy, config_mac, ConfigMac) ADD_SCENE(findmy, config_packet, ConfigPacket) diff --git a/applications/system/findmy/views/findmy_main.c b/applications/system/findmy/views/findmy_main.c index b39adc2bf8..829088be76 100644 --- a/applications/system/findmy/views/findmy_main.c +++ b/applications/system/findmy/views/findmy_main.c @@ -34,18 +34,22 @@ static void findmy_main_draw_callback(Canvas* canvas, void* _model) { snprintf(interval_str, sizeof(interval_str), "Ping Interval: %ds", model->interval); canvas_draw_str(canvas, 4, 62, interval_str); canvas_set_font(canvas, FontPrimary); + const char* network_text = ""; switch(model->type) { case FindMyTypeApple: - canvas_draw_str(canvas, 4, 32, "Apple Network"); - canvas_draw_icon(canvas, 80, 24, &I_Lock_7x8); + network_text = "Apple Network"; break; case FindMyTypeSamsung: - canvas_draw_str(canvas, 4, 32, "Samsung Network"); - canvas_draw_icon(canvas, 97, 24, &I_Lock_7x8); + network_text = "Samsung Network"; + break; + case FindMyTypeTile: + network_text = "Tile Network"; break; default: break; } + canvas_draw_str(canvas, 4, 32, network_text); + canvas_draw_icon(canvas, 6 + canvas_string_width(canvas, network_text), 24, &I_Lock_7x8); canvas_set_font(canvas, FontSecondary); canvas_draw_str(canvas, 100, 61, "Config"); canvas_draw_line(canvas, 100, 51, 127, 51); @@ -103,7 +107,7 @@ FindMyMain* findmy_main_alloc(FindMy* app) { { model->active = app->state.beacon_active; model->interval = app->state.broadcast_interval; - model->type = findmy_data_get_type(app->state.data); + model->type = app->state.tag_type; }, false); view_set_context(findmy_main->view, findmy_main); diff --git a/applications/system/findmy/views/findmy_main.h b/applications/system/findmy/views/findmy_main.h index 92a9170ec2..d73040ee24 100644 --- a/applications/system/findmy/views/findmy_main.h +++ b/applications/system/findmy/views/findmy_main.h @@ -1,6 +1,7 @@ #pragma once #include "../findmy.h" +#include "../findmy_state.h" #include typedef enum {