1
mirror of https://github.com/DarkFlippers/unleashed-firmware.git synced 2025-12-12 04:34:43 +04:00

add findmy to system apps [ci skip]

autoload by Willy-JL
This commit is contained in:
MX
2025-02-13 20:12:18 +03:00
parent 85cba9fd8d
commit 95483fb56f
33 changed files with 1725 additions and 1 deletions

View File

@@ -5,6 +5,7 @@ App(
provides=[ provides=[
"updater_app", "updater_app",
"js_app", "js_app",
"findmy_startup",
# "archive", # "archive",
], ],
) )

View File

@@ -0,0 +1,113 @@
# FindMy Flipper - FindMy SmartTag Emulator
This app extends the functionality of the FlipperZero's bluetooth capabilities, enabling it to act as an Apple AirTag or Samsung SmartTag, or even both simultaneously. It utilizes the FlipperZero's BLE beacon to broadcast a SmartTag signal to be picked up by the FindMy Network. I made this to serve as a versatile tool for tracking purposes, offering the ability to clone existing tags, generate OpenHaystack key pairs for integration with Apple's FindMy network, and tune the device's beacon broadcast settings.
## Features
1. Tag Emulation: Clone your existing Apple AirTag or Samsung SmartTag to the FlipperZero, or generate a key pair for use with the FindMy network without owning an actual AirTag.
2. Customization: Users can adjust the interval between beacon broadcasts and modify the transmit power to suit their needs, optimizing for both visibility and battery life.
3. Efficient Background Operation: The app is optimized to run in the background, ensuring that your FlipperZero can still be tracked with minimal battery usage and without stopping normal use.
## Usage Guide
### Step 1: Installation
- **Option A:** Use the released/precompiled firmware appropriate (FAP) for your device.
- **Option B:** Build the firmware yourself using `fbt/ufbt`.
- Both Installation options require you to be running a dev build of firmware. When release gets access to the extra BLE beacon this will change, thank you!
- All firmware should now work with main branch, including icons
### Step 2: Obtaining SmartTag Data
#### Option A: Cloning Existing Tag (Preferred and allows you to track without additional setup)
1. **Pair a Tag:** First, pair an AirTag or Samsung SmartTag with your device.
2. **Enter 'Lost' Mode:** Keep the tag away from the device it's registered to for approximately 15 minutes.
3. **Download nrfConnect:** Install nrfConnect from the Google Play Store. (Apple version doesn't reveal the needed Raw data, looking for a workaround)
4. **Filter and Scan:**
- Open the app, click on filters, and exclude all except for the brand of your tag (Apple/Samsung).
- Adjust the RSSI to the lowest setting (-40 dBm).
- Initiate a scan. Wait for your SmartTag to appear as a "FindMy" device.
5. **Capture Data:** Click **Raw** or **View Raw** to capture your **payload** and note your tag's **MAC Address**. Immediately remove the tag's battery to prevent key/MAC rotation.
6. **Enter Data in FlipperZero App:** Input the captured **payload** and **MAC Address** into the FlipperZero app.
#### Option B: Open Haystack Method
1. **Generate a Tag:** Download the `generate_keys.py` file and execute it in your terminal. (You will need cryptography ```python3 -m pip install cryptography```)
2. **Follow Prompts:** During execution, you'll be prompted for inputs. By the end, you'll obtain a **Private Key**, **Public Key**, **Payload**, and **MAC Address**.
- **Private Key** is necessary to receive location reports from Apple.
- **MAC Address** should be registered in the FlipperZero app:
1. Open the app and navigate to the config menu.
2. Choose "register tag" and enter the MAC Address when prompted.
3. A payload dialog will appear next. Enter your **Payload** here.
4. Click save.
3. **Configuration Completion:** With this setup, your device is ready for Open Haystack. Proceed with the specific steps for Open Haystack or MaclessHaystack based on your setup.
- Don't Own a Mac: https://github.com/dchristl/macless-haystack or https://github.com/Chapoly1305/FindMy
- Own a Mac: https://github.com/seemoo-lab/openhaystack
To use OpenHayStack for tracking, you must use MacOS lower than version 14 (Mail Plug-in Incompetiablity of MacOS 14+ seemoo-lab/openhaystack#224). If you do own a device, I believe a convertor script can be provided without much of effort. If you do not own a Mac device or the system has been upgraded to 14 and beyond. The alternative solution includes,
https://github.com/dchristl/macless-haystack (recommended in README)
https://github.com/Chapoly1305/FindMy (a project uses python and docker to provide location lookup as a backend service)
## Setting Up on Mac with OpenHayStack (OHS) App -- If you own a Mac instructions
Follow these steps to get everything working on a Mac using the latest version of the OpenHayStack app.
Thanks to Wr3nch for the help
### Step 1: Create a New Device
- Start by creating a new device in the OpenHayStack app, but **do not deploy** it immediately after creation.
### Step 2: Export Configuration
- Choose to **EXPORT** the configuration by selecting "all accessories as file." To simplify, ensure you only have one entry in the list before exporting.
- It is crucial that the export format is in JSON.
### Step 3: Modify the JSON File
Open the exported JSON file in a text editor and make the following changes:
- **Left OHS, Right keys from my ```generate_keys.py``` script:**
- `symmetricKey` should be set to the `Hashed adv key`.
- `privateKey` should be replaced with your `Private Key`.
- `oldestRelevantSymmetricKey` should also use the `Hashed adv key`.
- Additionally, update the following attributes to `true`:
- `"isDeployed": true`
- `"isActive": true`
### Step 4: Re-import the Configuration
- After saving your changes to the JSON file, re-import it back into OpenHayStack.
### Step 5: Adjust Settings in OHS App
- In the OpenHayStack Mac App, navigate to the top bar and change the time setting from `1 Day` to `30min`.
- Give it some time to process and apply the new settings.
By following these steps, you should have your device set up and ready to go with OpenHayStack on a Mac.
****
### Step 3: Configuration on the FlipperZero
- Upon launching the app, open the config menu and either click ```Import Tag From File``` or ```Register Tag Manually```. Put your generated .keys file onto the FlipperZero SD card inside the AppsData/FindMyFlipper folder to import from file. Or you can manually enter the tag information. When using the cloning method, you can export a .txt file from nrfConnect (click save button) amd place that in the same folder in order to import.
### Step 4: Tracking
- Once the app is configured, your FlipperZero can be tracked using the relevant platform's tracking service (FindMy app for Apple devices, SmartThings for Samsung devices, and respective web browsers). If using generated keys and OpenHaystack then you can track on the OHS app or via the Macless Haystack setup. Links to both are above
Customization
- Beacon Interval: Adjust how frequently your FlipperZero broadcasts its presence.
- Transmit Power: Increase or decrease the signal strength to balance between tracking range and battery life.
Background Use
The app is designed to have a negligible impact on battery life, even when running in the background. This allows for continuous tracking without the need for frequent recharging.
Compatibility
- Apple devices for AirTag tracking via the FindMy network.
- Any device that supports Samsung SmartTag tracking, including web browsers (previously FindMyMobile).
Thanks
- Huge thanks to all the people that contributed to the OpenHaystack project, supporting projects, and guides on the subject. This wouldn't be a thing without any of you! Special thanks to WillyJL for helping get the app input working and overall overhaul of the apps functions!
Legal and Privacy
This app is intended for personal and educational use. Users are responsible for complying with local privacy laws and regulations regarding tracking devices. The cloning and emulation of tracking tags should be done responsibly and with respect to the ownership of the original devices.
Disclaimer
This project is not affiliated with Apple Inc. or Samsung. All product names, logos, and brands are property of their respective owners. Use this app responsibly and ethically.

View File

@@ -0,0 +1,24 @@
App(
appid="findmy",
name="FindMy Flipper",
apptype=FlipperAppType.EXTERNAL,
entry_point="findmy_main",
requires=["gui"],
stack_size=2 * 1024,
fap_icon="location_icon.png",
fap_icon_assets="icons",
fap_category="Bluetooth",
fap_author="@MatthewKuKanich",
fap_weburl="https://github.com/MatthewKuKanich/FindMyFlipper",
fap_version="3.5",
fap_description="BLE FindMy Location Beacon",
)
App(
appid="findmy_startup",
targets=["f7"],
apptype=FlipperAppType.STARTUP,
entry_point="findmy_startup",
sources=["findmy_startup.c", "findmy_state.c"],
order=1000,
)

View File

@@ -0,0 +1,141 @@
#include "findmy_i.h"
static bool findmy_custom_event_callback(void* context, uint32_t event) {
furi_assert(context);
FindMy* app = context;
return scene_manager_handle_custom_event(app->scene_manager, event);
}
static bool findmy_back_event_callback(void* context) {
furi_assert(context);
FindMy* app = context;
return scene_manager_handle_back_event(app->scene_manager);
}
static FindMy* findmy_app_alloc() {
FindMy* app = malloc(sizeof(FindMy));
app->gui = furi_record_open(RECORD_GUI);
app->storage = furi_record_open(RECORD_STORAGE);
app->dialogs = furi_record_open(RECORD_DIALOGS);
app->view_dispatcher = view_dispatcher_alloc();
app->scene_manager = scene_manager_alloc(&findmy_scene_handlers, app);
view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
view_dispatcher_set_custom_event_callback(app->view_dispatcher, findmy_custom_event_callback);
view_dispatcher_set_navigation_event_callback(
app->view_dispatcher, findmy_back_event_callback);
app->findmy_main = findmy_main_alloc(app);
view_dispatcher_add_view(
app->view_dispatcher, FindMyViewMain, findmy_main_get_view(app->findmy_main));
app->byte_input = byte_input_alloc();
view_dispatcher_add_view(
app->view_dispatcher, FindMyViewByteInput, byte_input_get_view(app->byte_input));
app->var_item_list = variable_item_list_alloc();
view_dispatcher_add_view(
app->view_dispatcher,
FindMyViewVarItemList,
variable_item_list_get_view(app->var_item_list));
app->popup = popup_alloc();
view_dispatcher_add_view(app->view_dispatcher, FindMyViewPopup, popup_get_view(app->popup));
view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
findmy_state_load(&app->state);
findmy_state_apply(&app->state);
findmy_main_update_active(app->findmy_main, app->state.beacon_active);
findmy_main_update_interval(app->findmy_main, app->state.broadcast_interval);
findmy_main_toggle_mac(app->findmy_main, app->state.show_mac);
findmy_main_update_mac(app->findmy_main, app->state.mac);
findmy_main_update_type(app->findmy_main, app->state.tag_type);
return app;
}
static void findmy_app_free(FindMy* app) {
furi_assert(app);
view_dispatcher_remove_view(app->view_dispatcher, FindMyViewPopup);
popup_free(app->popup);
view_dispatcher_remove_view(app->view_dispatcher, FindMyViewVarItemList);
variable_item_list_free(app->var_item_list);
view_dispatcher_remove_view(app->view_dispatcher, FindMyViewByteInput);
byte_input_free(app->byte_input);
view_dispatcher_remove_view(app->view_dispatcher, FindMyViewMain);
findmy_main_free(app->findmy_main);
view_dispatcher_free(app->view_dispatcher);
scene_manager_free(app->scene_manager);
furi_record_close(RECORD_DIALOGS);
furi_record_close(RECORD_STORAGE);
furi_record_close(RECORD_GUI);
free(app);
}
int32_t findmy_main(void* p) {
UNUSED(p);
FindMy* app = findmy_app_alloc();
scene_manager_next_scene(app->scene_manager, FindMySceneMain);
view_dispatcher_run(app->view_dispatcher);
findmy_app_free(app);
return 0;
}
void findmy_change_broadcast_interval(FindMy* app, uint8_t value) {
if(value > 10 || value < 1) {
return;
}
app->state.broadcast_interval = value;
findmy_main_update_interval(app->findmy_main, app->state.broadcast_interval);
findmy_state_save_and_apply(&app->state);
}
void findmy_change_transmit_power(FindMy* app, uint8_t value) {
if(value > 6) {
return;
}
app->state.transmit_power = value;
findmy_state_save_and_apply(&app->state);
}
void findmy_toggle_show_mac(FindMy* app, bool show_mac) {
app->state.show_mac = show_mac;
findmy_main_toggle_mac(app->findmy_main, app->state.show_mac);
findmy_state_save_and_apply(&app->state);
}
void findmy_toggle_beacon(FindMy* app) {
app->state.beacon_active = !app->state.beacon_active;
findmy_state_save_and_apply(&app->state);
findmy_main_update_active(app->findmy_main, app->state.beacon_active);
}
void findmy_set_tag_type(FindMy* app, FindMyType type) {
app->state.tag_type = type;
findmy_state_save_and_apply(&app->state);
findmy_main_update_type(app->findmy_main, type);
}
void findmy_reverse_mac_addr(uint8_t mac_addr[GAP_MAC_ADDR_SIZE]) {
uint8_t tmp;
for(size_t i = 0; i < GAP_MAC_ADDR_SIZE / 2; i++) {
tmp = mac_addr[i];
mac_addr[i] = mac_addr[GAP_MAC_ADDR_SIZE - 1 - i];
mac_addr[GAP_MAC_ADDR_SIZE - 1 - i] = tmp;
}
}

View File

@@ -0,0 +1,3 @@
#pragma once
typedef struct FindMy FindMy;

View File

@@ -0,0 +1,54 @@
#pragma once
#include "findmy.h"
#include "findmy_state.h"
#include <furi_hal_bt.h>
#include <extra_beacon.h>
#include "findmy_icons.h"
#include <toolbox/stream/file_stream.h>
#include <toolbox/hex.h>
#include <toolbox/path.h>
#include <gui/gui.h>
#include <storage/storage.h>
#include <dialogs/dialogs.h>
#include <gui/scene_manager.h>
#include <gui/view_dispatcher.h>
#include "views/findmy_main.h"
#include <gui/modules/byte_input.h>
#include <gui/modules/variable_item_list.h>
#include <gui/modules/popup.h>
#include "scenes/findmy_scene.h"
#include "helpers/base64.h"
void findmy_reverse_mac_addr(uint8_t mac_addr[GAP_MAC_ADDR_SIZE]);
struct FindMy {
Gui* gui;
Storage* storage;
DialogsApp* dialogs;
SceneManager* scene_manager;
ViewDispatcher* view_dispatcher;
FindMyMain* findmy_main;
ByteInput* byte_input;
VariableItemList* var_item_list;
Popup* popup;
uint8_t mac_buf[EXTRA_BEACON_MAC_ADDR_SIZE];
uint8_t packet_buf[EXTRA_BEACON_MAX_DATA_SIZE];
FindMyState state;
};
typedef enum {
FindMyViewMain,
FindMyViewByteInput,
FindMyViewVarItemList,
FindMyViewPopup,
} FindMyView;
void findmy_change_broadcast_interval(FindMy* app, uint8_t value);
void findmy_change_transmit_power(FindMy* app, uint8_t value);
void findmy_toggle_show_mac(FindMy* app, bool show_mac);
void findmy_set_tag_type(FindMy* app, FindMyType type);
void findmy_toggle_beacon(FindMy* app);

View File

@@ -0,0 +1,51 @@
#include "findmy_state.h"
#include <furi_hal.h>
#include <bt/bt_service/bt.h>
#include <storage/storage.h>
#include <toolbox/run_parallel.h>
#define TAG "FindMyStartup"
static int32_t findmy_startup_apply(void* context) {
UNUSED(context);
FURI_LOG_D(TAG, "Loading state");
// Wait for BT init and check core2
furi_record_open(RECORD_BT);
furi_record_close(RECORD_BT);
if(!furi_hal_bt_is_gatt_gap_supported()) return 0;
FindMyState state;
if(findmy_state_load(&state)) {
FURI_LOG_D(TAG, "Activating beacon");
findmy_state_apply(&state);
} else {
FURI_LOG_D(TAG, "Beacon not active, bailing");
}
return 0;
}
static void findmy_startup_mount_callback(const void* message, void* context) {
UNUSED(context);
const StorageEvent* event = message;
if(event->type == StorageEventTypeCardMount) {
run_parallel(findmy_startup_apply, NULL, 2048);
}
}
void findmy_startup() {
if(furi_hal_rtc_get_boot_mode() != FuriHalRtcBootModeNormal) return;
Storage* storage = furi_record_open(RECORD_STORAGE);
furi_pubsub_subscribe(storage_get_pubsub(storage), findmy_startup_mount_callback, NULL);
if(storage_sd_status(storage) != FSE_OK) {
FURI_LOG_D(TAG, "SD Card not ready, skipping startup hook");
} else {
findmy_startup_apply(NULL);
}
furi_record_close(RECORD_STORAGE);
}

View File

@@ -0,0 +1,192 @@
#include "findmy_state.h"
#include <string.h>
#include <stddef.h>
#include <furi_hal_bt.h>
#include <furi_hal_power.h>
#include <flipper_format/flipper_format.h>
bool findmy_state_load(FindMyState* out_state) {
FindMyState state;
// Try to load from file
bool loaded_from_file = false;
Storage* storage = furi_record_open(RECORD_STORAGE);
if(storage_file_exists(storage, FINDMY_STATE_PATH)) {
FlipperFormat* file = flipper_format_file_alloc(storage);
FuriString* str = furi_string_alloc();
uint32_t tmp;
do {
if(!flipper_format_file_open_existing(file, FINDMY_STATE_PATH)) break;
if(!flipper_format_read_header(file, str, &tmp)) break;
if(furi_string_cmp_str(str, FINDMY_STATE_HEADER)) break;
if(tmp != FINDMY_STATE_VER) break;
if(!flipper_format_read_bool(file, "beacon_active", &state.beacon_active, 1)) break;
if(!flipper_format_read_uint32(file, "broadcast_interval", &tmp, 1)) break;
state.broadcast_interval = tmp;
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)) {
tmp = FindMyTypeApple;
flipper_format_rewind(file);
}
state.tag_type = tmp;
if(!flipper_format_read_bool(file, "show_mac", &state.show_mac, 1)) {
// Support migrating from old config
state.show_mac = false;
flipper_format_rewind(file);
}
if(!flipper_format_read_hex(file, "mac", state.mac, sizeof(state.mac))) break;
if(!flipper_format_read_hex(
file, "data", state.data, findmy_state_data_size(state.tag_type)))
break;
loaded_from_file = true;
} while(0);
furi_string_free(str);
flipper_format_free(file);
}
furi_record_close(RECORD_STORAGE);
// Otherwise set default values
if(!loaded_from_file) {
state.beacon_active = false;
state.broadcast_interval = 5;
state.transmit_power = 6;
state.show_mac = false;
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));
// Set default empty AirTag data
uint8_t* data = state.data;
*data++ = 0x1E; // Length
*data++ = 0xFF; // Manufacturer Specific Data
*data++ = 0x4C; // Company ID (Apple, Inc.)
*data++ = 0x00; // ...
*data++ = 0x12; // Type (FindMy)
*data++ = 0x19; // Length
*data++ = 0x00; // Battery Status set to Full
// Placeholder Empty Public Key without the MAC address
for(size_t i = 0; i < 22; ++i) {
*data++ = 0x00;
}
*data++ = 0x00; // First 2 bits are the version
*data++ = 0x00; // Hint (0x00)
}
// Copy to caller state before popping stack
memcpy(out_state, &state, sizeof(state));
// Return if active, can be used to start after loading in an if statement
return state.beacon_active;
}
static void findmy_state_update_payload_battery(FindMyState* state) {
// Update the battery level in the payload
if(state->tag_type == FindMyTypeApple) {
uint32_t battery_capacity = furi_hal_power_get_battery_full_capacity();
uint32_t battery_remaining = furi_hal_power_get_battery_remaining_capacity();
uint8_t battery_percent = (battery_remaining * 100) / battery_capacity;
uint8_t battery_level;
if(battery_percent > 80) {
battery_level = BATTERY_FULL;
} else if(battery_percent > 50) {
battery_level = BATTERY_MEDIUM;
} else if(battery_percent > 20) {
battery_level = BATTERY_LOW;
} else {
battery_level = BATTERY_CRITICAL;
}
state->data[6] = battery_level;
}
}
void findmy_state_apply(FindMyState* state) {
// This function applies configured state to the beacon (loaded values)
// Stop beacon before configuring
if(furi_hal_bt_extra_beacon_is_active()) {
furi_check(furi_hal_bt_extra_beacon_stop());
}
// Make config struct from configured parameters and set it
GapExtraBeaconConfig config = {
.min_adv_interval_ms = state->broadcast_interval * 1000, // Converting s to ms
.max_adv_interval_ms = (state->broadcast_interval * 1000) + 150,
.adv_channel_map = GapAdvChannelMapAll,
.adv_power_level = GapAdvPowerLevel_0dBm + state->transmit_power,
.address_type = GapAddressTypePublic,
};
memcpy(config.address, state->mac, sizeof(config.address));
furi_check(furi_hal_bt_extra_beacon_set_config(&config));
// Update data payload with battery level and set it
findmy_state_update_payload_battery(state);
furi_check(
furi_hal_bt_extra_beacon_set_data(state->data, findmy_state_data_size(state->tag_type)));
// Start beacon if configured
if(state->beacon_active) {
furi_check(furi_hal_bt_extra_beacon_start());
}
}
static void findmy_state_save(FindMyState* state) {
Storage* storage = furi_record_open(RECORD_STORAGE);
storage_simply_mkdir(storage, FINDMY_STATE_DIR);
FlipperFormat* file = flipper_format_file_alloc(storage);
do {
uint32_t tmp;
if(!flipper_format_file_open_always(file, FINDMY_STATE_PATH)) break;
if(!flipper_format_write_header_cstr(file, FINDMY_STATE_HEADER, FINDMY_STATE_VER)) break;
if(!flipper_format_write_bool(file, "beacon_active", &state->beacon_active, 1)) break;
tmp = state->broadcast_interval;
if(!flipper_format_write_uint32(file, "broadcast_interval", &tmp, 1)) break;
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_bool(file, "show_mac", &state->show_mac, 1)) break;
if(!flipper_format_write_hex(file, "mac", state->mac, sizeof(state->mac))) 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);
}
void findmy_state_save_and_apply(FindMyState* state) {
findmy_state_apply(state);
findmy_state_save(state);
}
uint8_t findmy_state_data_size(FindMyType type) {
switch(type) {
case FindMyTypeApple:
case FindMyTypeSamsung:
return 31;
case FindMyTypeTile:
return 21;
default:
return 0;
}
}

View File

@@ -0,0 +1,37 @@
#pragma once
#include <extra_beacon.h>
#define FINDMY_STATE_HEADER "FindMy Flipper State"
#define FINDMY_STATE_VER 1
#define FINDMY_STATE_DIR EXT_PATH("apps_data/findmy")
#define FINDMY_STATE_PATH FINDMY_STATE_DIR "/findmy_state.txt"
#define BATTERY_FULL 0x00
#define BATTERY_MEDIUM 0x50
#define BATTERY_LOW 0xA0
#define BATTERY_CRITICAL 0xF0
typedef enum {
FindMyTypeApple,
FindMyTypeSamsung,
FindMyTypeTile,
} FindMyType;
typedef struct {
bool beacon_active;
uint8_t broadcast_interval;
uint8_t transmit_power;
bool show_mac;
uint8_t mac[EXTRA_BEACON_MAC_ADDR_SIZE];
uint8_t data[EXTRA_BEACON_MAX_DATA_SIZE];
FindMyType tag_type;
} FindMyState;
bool findmy_state_load(FindMyState* out_state);
void findmy_state_apply(FindMyState* state);
void findmy_state_save_and_apply(FindMyState* state);
uint8_t findmy_state_data_size(FindMyType type);

View File

@@ -0,0 +1,142 @@
/*
* Base64 encoding/decoding (RFC1341)
* Copyright (c) 2005-2011, Jouni Malinen <j@w1.fi>
*
* This software may be distributed under the terms of the BSD license.
* See README for more details.
*/
// https://web.mit.edu/freebsd/head/contrib/wpa/src/utils/base64.c
#include "base64.h"
#define os_malloc malloc
#define os_free free
#define os_memset memset
static const unsigned char base64_table[65] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
/**
* base64_encode - Base64 encode
* @src: Data to be encoded
* @len: Length of the data to be encoded
* @out_len: Pointer to output length variable, or %NULL if not used
* Returns: Allocated buffer of out_len bytes of encoded data,
* or %NULL on failure
*
* Caller is responsible for freeing the returned buffer. Returned buffer is
* nul terminated to make it easier to use as a C string. The nul terminator is
* not included in out_len.
*/
unsigned char* base64_encode(const unsigned char* src, size_t len, size_t* out_len) {
unsigned char *out, *pos;
const unsigned char *end, *in;
size_t olen;
int line_len;
olen = len * 4 / 3 + 4; /* 3-byte blocks to 4-byte */
olen += olen / 72; /* line feeds */
olen++; /* nul termination */
if(olen < len) return NULL; /* integer overflow */
out = os_malloc(olen);
if(out == NULL) return NULL;
end = src + len;
in = src;
pos = out;
line_len = 0;
while(end - in >= 3) {
*pos++ = base64_table[in[0] >> 2];
*pos++ = base64_table[((in[0] & 0x03) << 4) | (in[1] >> 4)];
*pos++ = base64_table[((in[1] & 0x0f) << 2) | (in[2] >> 6)];
*pos++ = base64_table[in[2] & 0x3f];
in += 3;
line_len += 4;
if(line_len >= 72) {
*pos++ = '\n';
line_len = 0;
}
}
if(end - in) {
*pos++ = base64_table[in[0] >> 2];
if(end - in == 1) {
*pos++ = base64_table[(in[0] & 0x03) << 4];
*pos++ = '=';
} else {
*pos++ = base64_table[((in[0] & 0x03) << 4) | (in[1] >> 4)];
*pos++ = base64_table[(in[1] & 0x0f) << 2];
}
*pos++ = '=';
line_len += 4;
}
if(line_len) *pos++ = '\n';
*pos = '\0';
if(out_len) *out_len = pos - out;
return out;
}
/**
* base64_decode - Base64 decode
* @src: Data to be decoded
* @len: Length of the data to be decoded
* @out_len: Pointer to output length variable
* Returns: Allocated buffer of out_len bytes of decoded data,
* or %NULL on failure
*
* Caller is responsible for freeing the returned buffer.
*/
unsigned char* base64_decode(const unsigned char* src, size_t len, size_t* out_len) {
unsigned char dtable[256], *out, *pos, block[4], tmp;
size_t i, count, olen;
int pad = 0;
os_memset(dtable, 0x80, 256);
for(i = 0; i < sizeof(base64_table) - 1; i++)
dtable[base64_table[i]] = (unsigned char)i;
dtable['='] = 0;
count = 0;
for(i = 0; i < len; i++) {
if(dtable[src[i]] != 0x80) count++;
}
if(count == 0 || count % 4) return NULL;
olen = count / 4 * 3;
pos = out = os_malloc(olen);
if(out == NULL) return NULL;
count = 0;
for(i = 0; i < len; i++) {
tmp = dtable[src[i]];
if(tmp == 0x80) continue;
if(src[i] == '=') pad++;
block[count] = tmp;
count++;
if(count == 4) {
*pos++ = (block[0] << 2) | (block[1] >> 4);
*pos++ = (block[1] << 4) | (block[2] >> 2);
*pos++ = (block[2] << 6) | block[3];
count = 0;
if(pad) {
if(pad == 1)
pos--;
else if(pad == 2)
pos -= 2;
else {
/* Invalid padding */
os_free(out);
return NULL;
}
break;
}
}
}
*out_len = pos - out;
return out;
}

View File

@@ -0,0 +1,21 @@
/*
* Base64 encoding/decoding (RFC1341)
* Copyright (c) 2005, Jouni Malinen <j@w1.fi>
*
* This software may be distributed under the terms of the BSD license.
* See README for more details.
*/
// https://web.mit.edu/freebsd/head/contrib/wpa/src/utils/base64.h
#ifndef BASE64_H
#define BASE64_H
#include <stdint.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
unsigned char* base64_encode(const unsigned char* src, size_t len, size_t* out_len);
unsigned char* base64_decode(const unsigned char* src, size_t len, size_t* out_len);
#endif /* BASE64_H */

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 B

View File

@@ -0,0 +1,31 @@
#include "findmy_scene.h"
#include "findmy.h"
// Generate scene on_enter handlers array
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
void (*const findmy_on_enter_handlers[])(void*) = {
#include "findmy_scenes.h"
};
#undef ADD_SCENE
// Generate scene on_event handlers array
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event,
bool (*const findmy_on_event_handlers[])(void* context, SceneManagerEvent event) = {
#include "findmy_scenes.h"
};
#undef ADD_SCENE
// Generate scene on_exit handlers array
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_exit,
void (*const findmy_on_exit_handlers[])(void* context) = {
#include "findmy_scenes.h"
};
#undef ADD_SCENE
// Initialize scene handlers configuration structure
const SceneManagerHandlers findmy_scene_handlers = {
.on_enter_handlers = findmy_on_enter_handlers,
.on_event_handlers = findmy_on_event_handlers,
.on_exit_handlers = findmy_on_exit_handlers,
.scene_num = FindMySceneNum,
};

View File

@@ -0,0 +1,30 @@
#pragma once
#include <gui/scene_manager.h>
#include "findmy.h"
// Generate scene id and total number
#define ADD_SCENE(prefix, name, id) FindMyScene##id,
typedef enum {
#include "findmy_scenes.h"
FindMySceneNum,
} FindMyScene;
#undef ADD_SCENE
extern const SceneManagerHandlers findmy_scene_handlers;
// Generate scene on_enter handlers declaration
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*);
#include "findmy_scenes.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 "findmy_scenes.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 "findmy_scenes.h"
#undef ADD_SCENE

View File

@@ -0,0 +1,117 @@
#include "../findmy_i.h"
enum VarItemListIndex {
VarItemListIndexBroadcastInterval,
VarItemListIndexTransmitPower,
VarItemListIndexRegisterTag,
VarItemListIndexShowMac,
VarItemListIndexAbout,
};
void findmy_scene_config_broadcast_interval_changed(VariableItem* item) {
FindMy* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
findmy_change_broadcast_interval(app, index + 1);
char str[5];
snprintf(str, sizeof(str), "%ds", app->state.broadcast_interval);
variable_item_set_current_value_text(item, str);
variable_item_set_current_value_index(item, app->state.broadcast_interval - 1);
}
void findmy_scene_config_transmit_power_changed(VariableItem* item) {
FindMy* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
findmy_change_transmit_power(app, index);
char str[7];
snprintf(str, sizeof(str), "%ddBm", app->state.transmit_power);
variable_item_set_current_value_text(item, str);
variable_item_set_current_value_index(item, app->state.transmit_power);
}
void findmy_scene_config_show_mac(VariableItem* item) {
FindMy* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
findmy_toggle_show_mac(app, index);
variable_item_set_current_value_text(item, app->state.show_mac ? "Yes" : "No");
variable_item_set_current_value_index(item, app->state.show_mac);
}
void findmy_scene_config_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_on_enter(void* context) {
FindMy* app = context;
VariableItemList* var_item_list = app->var_item_list;
VariableItem* item;
item = variable_item_list_add(
var_item_list,
"Broadcast Interval",
10,
findmy_scene_config_broadcast_interval_changed,
app);
// Broadcast Interval is 1-10, so use 0-9 and offset indexes by 1
variable_item_set_current_value_index(item, app->state.broadcast_interval - 1);
char interval_str[5];
snprintf(interval_str, sizeof(interval_str), "%ds", app->state.broadcast_interval);
variable_item_set_current_value_text(item, interval_str);
item = variable_item_list_add(
var_item_list, "Transmit Power", 7, findmy_scene_config_transmit_power_changed, app);
variable_item_set_current_value_index(item, app->state.transmit_power);
char power_str[7];
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, "Register Tag", 0, NULL, NULL);
item = variable_item_list_add(var_item_list, "Show MAC", 2, findmy_scene_config_show_mac, app);
variable_item_set_current_value_index(item, app->state.show_mac);
variable_item_set_current_value_text(item, app->state.show_mac ? "Yes" : "No");
item = variable_item_list_add(
var_item_list,
"Matthew KuKanich, Thanks to Chapoly1305, WillyJL, OpenHaystack, Testers",
1,
NULL,
NULL);
variable_item_set_current_value_text(item, "Credits");
variable_item_list_set_enter_callback(var_item_list, findmy_scene_config_callback, app);
variable_item_list_set_selected_item(
var_item_list, scene_manager_get_scene_state(app->scene_manager, FindMySceneConfig));
view_dispatcher_switch_to_view(app->view_dispatcher, FindMyViewVarItemList);
}
bool findmy_scene_config_on_event(void* context, SceneManagerEvent event) {
FindMy* app = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
scene_manager_set_scene_state(app->scene_manager, FindMySceneConfig, event.event);
consumed = true;
switch(event.event) {
case VarItemListIndexRegisterTag:
scene_manager_next_scene(app->scene_manager, FindMySceneConfigTagtype);
break;
case VarItemListIndexAbout:
break;
default:
break;
}
}
return consumed;
}
void findmy_scene_config_on_exit(void* context) {
FindMy* app = context;
VariableItemList* var_item_list = app->var_item_list;
variable_item_list_reset(var_item_list);
}

View File

@@ -0,0 +1,231 @@
#include "../findmy_i.h"
enum VarItemListIndex {
VarItemListIndexNrfConnect,
VarItemListIndexOpenHaystack,
VarItemListIndexRegisterTagManually,
};
static const char* parse_nrf_connect(FindMy* app, const char* path) {
const char* error = NULL;
Stream* stream = file_stream_alloc(app->storage);
FuriString* line = furi_string_alloc();
do {
// XX-XX-XX-XX-XX-XX_YYYY-MM-DD HH_MM_SS.txt
error = "Filename must\nhave MAC\naddress";
uint8_t mac[EXTRA_BEACON_MAC_ADDR_SIZE];
path_extract_filename_no_ext(path, line);
if(furi_string_size(line) < sizeof(mac) * 3 - 1) break;
error = NULL;
for(size_t i = 0; i < sizeof(mac); i++) {
char a = furi_string_get_char(line, i * 3);
char b = furi_string_get_char(line, i * 3 + 1);
if((a < 'A' && a > 'F') || (a < '0' && a > '9') || (b < 'A' && b > 'F') ||
(b < '0' && b > '9') || !hex_char_to_uint8(a, b, &mac[i])) {
error = "Filename must\nhave MAC\naddress";
break;
}
}
if(error) break;
findmy_reverse_mac_addr(mac);
error = "Can't open file";
if(!file_stream_open(stream, path, FSAM_READ, FSOM_OPEN_EXISTING)) break;
// YYYY-MM-DD HH:MM:SS.ms, XX dBm, 0xXXXXX
error = "Wrong file format";
if(!stream_read_line(stream, line)) break;
const char* marker = " dBm, 0x";
size_t pos = furi_string_search(line, marker);
if(pos == FURI_STRING_FAILURE) break;
furi_string_right(line, pos + strlen(marker));
furi_string_trim(line);
error = "Wrong payload size";
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 < 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') ||
(b < '0' && b > '9') || !hex_char_to_uint8(a, b, &data[i])) {
error = "Invalid payload";
break;
}
}
if(error) break;
memcpy(app->state.mac, mac, sizeof(app->state.mac));
memcpy(app->state.data, data, sizeof(app->state.data));
findmy_state_save_and_apply(&app->state);
error = NULL;
} while(false);
furi_string_free(line);
file_stream_close(stream);
stream_free(stream);
return error;
}
static const char* parse_open_haystack(FindMy* app, const char* path) {
const char* error = NULL;
Stream* stream = file_stream_alloc(app->storage);
FuriString* line = furi_string_alloc();
do {
error = "Can't open file";
if(!file_stream_open(stream, path, FSAM_READ, FSOM_OPEN_EXISTING)) break;
error = "Wrong file format";
while(stream_read_line(stream, line)) {
if(furi_string_start_with(line, "Public key: ") ||
furi_string_start_with(line, "Advertisement key: ")) {
error = NULL;
break;
}
}
if(error) break;
furi_string_right(line, furi_string_search_char(line, ':') + 2);
furi_string_trim(line);
error = "Base64 failed";
size_t decoded_len;
uint8_t* public_key = base64_decode(
(uint8_t*)furi_string_get_cstr(line), furi_string_size(line), &decoded_len);
if(decoded_len != 28) {
free(public_key);
break;
}
memcpy(app->state.mac, public_key, sizeof(app->state.mac));
app->state.mac[0] |= 0b11000000;
findmy_reverse_mac_addr(app->state.mac);
uint8_t advertisement_template[EXTRA_BEACON_MAX_DATA_SIZE] = {
0x1e, // length (30)
0xff, // manufacturer specific data
0x4c, 0x00, // company ID (Apple)
0x12, 0x19, // offline finding type and length
0x00, //state
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, // first two bits of key[0]
0x00, // hint
};
memcpy(app->state.data, advertisement_template, sizeof(app->state.data));
memcpy(&app->state.data[7], &public_key[6], decoded_len - 6);
app->state.data[29] = public_key[0] >> 6;
findmy_state_save_and_apply(&app->state);
free(public_key);
error = NULL;
} while(false);
furi_string_free(line);
file_stream_close(stream);
stream_free(stream);
return error;
}
void findmy_scene_config_import_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_import_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 file type");
item = variable_item_list_add(var_item_list, "nRF Connect (.txt)", 0, NULL, NULL);
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);
variable_item_list_set_enter_callback(var_item_list, findmy_scene_config_import_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_import_on_event(void* context, SceneManagerEvent event) {
FindMy* app = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
scene_manager_set_scene_state(app->scene_manager, FindMySceneConfigImport, event.event);
consumed = true;
const char* extension = NULL;
switch(event.event) {
case VarItemListIndexNrfConnect:
extension = ".txt";
break;
case VarItemListIndexOpenHaystack:
extension = ".keys";
break;
case VarItemListIndexRegisterTagManually:
scene_manager_next_scene(app->scene_manager, FindMySceneConfigMac);
break;
default:
break;
}
if(!extension) {
return consumed;
}
const DialogsFileBrowserOptions browser_options = {
.extension = extension,
.icon = &I_text_10px,
.base_path = FINDMY_STATE_DIR,
};
storage_simply_mkdir(app->storage, browser_options.base_path);
FuriString* path = furi_string_alloc_set_str(browser_options.base_path);
if(dialog_file_browser_show(app->dialogs, path, path, &browser_options)) {
// The parse functions return the error text, or NULL for success
// Used in result to show success or error message
const char* error = NULL;
switch(event.event) {
case VarItemListIndexNrfConnect:
error = parse_nrf_connect(app, furi_string_get_cstr(path));
break;
case VarItemListIndexOpenHaystack:
error = parse_open_haystack(app, furi_string_get_cstr(path));
break;
}
scene_manager_set_scene_state(
app->scene_manager, FindMySceneConfigImportResult, (uint32_t)error);
scene_manager_next_scene(app->scene_manager, FindMySceneConfigImportResult);
}
furi_string_free(path);
}
return consumed;
}
void findmy_scene_config_import_on_exit(void* context) {
FindMy* app = context;
VariableItemList* var_item_list = app->var_item_list;
variable_item_list_reset(var_item_list);
}

View File

@@ -0,0 +1,60 @@
#include "../findmy_i.h"
enum PopupEvent {
PopupEventExit,
};
static void findmy_scene_config_import_result_callback(void* context) {
FindMy* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, PopupEventExit);
}
void findmy_scene_config_import_result_on_enter(void* context) {
FindMy* app = context;
Popup* popup = app->popup;
const char* error = (const char*)scene_manager_get_scene_state(
app->scene_manager, FindMySceneConfigImportResult);
if(error) {
popup_set_icon(popup, 83, 22, &I_WarningDolphinFlip_45x42);
popup_set_header(popup, "Error!", 13, 22, AlignLeft, AlignBottom);
popup_set_text(popup, error, 6, 26, AlignLeft, AlignTop);
popup_disable_timeout(popup);
} else {
popup_set_icon(popup, 36, 5, &I_DolphinDone_80x58);
popup_set_header(popup, "Imported!", 7, 14, AlignLeft, AlignBottom);
popup_enable_timeout(popup);
}
popup_set_timeout(popup, 1500);
popup_set_context(popup, app);
popup_set_callback(popup, findmy_scene_config_import_result_callback);
findmy_main_update_active(app->findmy_main, app->state.beacon_active);
findmy_main_update_mac(app->findmy_main, app->state.mac);
findmy_main_update_type(app->findmy_main, app->state.tag_type);
view_dispatcher_switch_to_view(app->view_dispatcher, FindMyViewPopup);
}
bool findmy_scene_config_import_result_on_event(void* context, SceneManagerEvent event) {
FindMy* 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, FindMySceneConfig);
break;
default:
break;
}
}
return consumed;
}
void findmy_scene_config_import_result_on_exit(void* context) {
FindMy* app = context;
popup_reset(app->popup);
}

View File

@@ -0,0 +1,60 @@
#include "../findmy_i.h"
enum ByteInputResult {
ByteInputResultOk,
};
static void findmy_scene_config_mac_callback(void* context) {
FindMy* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, ByteInputResultOk);
}
void findmy_scene_config_mac_on_enter(void* context) {
FindMy* app = context;
ByteInput* byte_input = app->byte_input;
byte_input_set_header_text(byte_input, "Enter Bluetooth MAC:");
memcpy(app->mac_buf, app->state.mac, sizeof(app->mac_buf));
findmy_reverse_mac_addr(app->mac_buf);
byte_input_set_result_callback(
byte_input,
findmy_scene_config_mac_callback,
NULL,
app,
app->mac_buf,
sizeof(app->mac_buf));
view_dispatcher_switch_to_view(app->view_dispatcher, FindMyViewByteInput);
}
bool findmy_scene_config_mac_on_event(void* context, SceneManagerEvent event) {
FindMy* app = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
consumed = true;
switch(event.event) {
case ByteInputResultOk:
findmy_reverse_mac_addr(app->mac_buf);
memcpy(&app->state.mac, app->mac_buf, sizeof(app->state.mac));
findmy_state_save_and_apply(&app->state);
findmy_main_update_mac(app->findmy_main, app->state.mac);
scene_manager_next_scene(app->scene_manager, FindMySceneConfigPacket);
break;
default:
break;
}
}
return consumed;
}
void findmy_scene_config_mac_on_exit(void* context) {
FindMy* app = context;
byte_input_set_result_callback(app->byte_input, NULL, NULL, NULL, NULL, 0);
byte_input_set_header_text(app->byte_input, "");
}

View File

@@ -0,0 +1,58 @@
#include "../findmy_i.h"
enum ByteInputResult {
ByteInputResultOk,
};
static void findmy_scene_config_packet_callback(void* context) {
FindMy* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, ByteInputResultOk);
}
void findmy_scene_config_packet_on_enter(void* context) {
FindMy* app = context;
ByteInput* byte_input = app->byte_input;
byte_input_set_header_text(byte_input, "Enter Bluetooth Payload:");
memcpy(app->packet_buf, app->state.data, findmy_state_data_size(app->state.tag_type));
byte_input_set_result_callback(
byte_input,
findmy_scene_config_packet_callback,
NULL,
app,
app->packet_buf,
findmy_state_data_size(app->state.tag_type));
view_dispatcher_switch_to_view(app->view_dispatcher, FindMyViewByteInput);
}
bool findmy_scene_config_packet_on_event(void* context, SceneManagerEvent event) {
FindMy* app = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
consumed = true;
switch(event.event) {
case ByteInputResultOk:
scene_manager_search_and_switch_to_previous_scene(
app->scene_manager, FindMySceneConfig);
memcpy(app->state.data, app->packet_buf, findmy_state_data_size(app->state.tag_type));
findmy_state_save_and_apply(&app->state);
break;
default:
break;
}
}
return consumed;
}
void findmy_scene_config_packet_on_exit(void* context) {
FindMy* app = context;
byte_input_set_result_callback(app->byte_input, NULL, NULL, NULL, NULL, 0);
byte_input_set_header_text(app->byte_input, "");
}

View File

@@ -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);
}

View File

@@ -0,0 +1,56 @@
#include "../findmy_i.h"
void findmy_scene_main_callback(FindMyMainEvent event, void* context) {
furi_assert(context);
FindMy* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, event);
}
void findmy_scene_main_on_enter(void* context) {
FindMy* app = context;
findmy_main_set_callback(app->findmy_main, findmy_scene_main_callback, app);
view_dispatcher_switch_to_view(app->view_dispatcher, FindMyViewMain);
}
bool findmy_scene_main_on_event(void* context, SceneManagerEvent event) {
FindMy* app = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
consumed = true;
switch(event.event) {
case FindMyMainEventToggle:
findmy_toggle_beacon(app);
break;
case FindMyMainEventBackground:
app->state.beacon_active = true;
findmy_state_save_and_apply(&app->state);
view_dispatcher_stop(app->view_dispatcher);
break;
case FindMyMainEventConfig:
scene_manager_next_scene(app->scene_manager, FindMySceneConfig);
break;
case FindMyMainEventIntervalUp:
findmy_change_broadcast_interval(app, app->state.broadcast_interval + 1);
break;
case FindMyMainEventIntervalDown:
findmy_change_broadcast_interval(app, app->state.broadcast_interval - 1);
break;
case FindMyMainEventQuit:
app->state.beacon_active = false;
findmy_state_save_and_apply(&app->state);
break;
default:
consumed = false;
break;
}
}
return consumed;
}
void findmy_scene_main_on_exit(void* context) {
FindMy* app = context;
UNUSED(app);
}

View File

@@ -0,0 +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)

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

@@ -0,0 +1,193 @@
#include "findmy_main.h"
#include "../findmy_i.h"
struct FindMyMain {
View* view;
FindMyMainCallback callback;
void* context;
};
typedef struct {
bool active;
bool show_mac;
uint8_t interval;
uint8_t mac[6];
FindMyType type;
} FindMyMainModel;
static void findmy_main_draw_callback(Canvas* canvas, void* _model) {
FindMyMainModel* model = _model;
canvas_clear(canvas);
canvas_set_bitmap_mode(canvas, true);
canvas_set_font(canvas, FontPrimary);
canvas_draw_str(canvas, 4, 11, "FindMy Flipper");
const char* network_text = "";
switch(model->type) {
case FindMyTypeApple:
network_text = "Apple Network";
break;
case FindMyTypeSamsung:
network_text = "Samsung Network";
break;
case FindMyTypeTile:
network_text = "Tile Network";
break;
default:
break;
}
if(model->show_mac == false) {
canvas_set_font(canvas, FontPrimary);
canvas_draw_str(canvas, 4, 31, network_text);
canvas_draw_icon(canvas, 6 + canvas_string_width(canvas, network_text), 24, &I_Lock_7x8);
} else if(model->show_mac == true) {
canvas_set_font(canvas, FontSecondary);
char mac_str[23];
snprintf(
mac_str,
sizeof(mac_str),
"MAC: %02X:%02X:%02X:%02X:%02X:%02X",
model->mac[0],
model->mac[1],
model->mac[2],
model->mac[3],
model->mac[4],
model->mac[5]);
canvas_draw_str(canvas, 4, 40, mac_str);
canvas_draw_str(canvas, 4, 30, network_text);
canvas_draw_icon(canvas, 6 + canvas_string_width(canvas, network_text), 23, &I_Lock_7x8);
}
canvas_set_font(canvas, FontSecondary);
if(model->active) {
canvas_draw_str(canvas, 4, 49, "Broadcast Active");
canvas_draw_icon(canvas, 78, 41, &I_Ok_btn_9x9);
} else {
canvas_draw_str(canvas, 4, 49, "Broadcast Inactive");
}
canvas_set_font(canvas, FontSecondary);
canvas_draw_str(canvas, 4, 21, "Press <- to run in background");
canvas_set_font(canvas, FontSecondary);
char interval_str[20];
snprintf(interval_str, sizeof(interval_str), "Ping Interval: %ds", model->interval);
canvas_draw_str(canvas, 4, 62, interval_str);
canvas_set_font(canvas, FontSecondary);
canvas_draw_str(canvas, 100, 61, "Config");
canvas_draw_line(canvas, 100, 51, 127, 51);
canvas_draw_line(canvas, 97, 53, 97, 63);
canvas_draw_line(canvas, 97, 53, 99, 51);
canvas_draw_line(canvas, 3, 52, 87, 52);
}
static bool findmy_main_input_callback(InputEvent* event, void* context) {
furi_assert(context);
FindMyMain* findmy_main = context;
bool consumed = false;
if(event->type == InputTypePress) {
consumed = true;
FindMyMainEvent cb_event;
switch(event->key) {
case InputKeyBack:
cb_event = FindMyMainEventQuit;
break;
case InputKeyOk:
cb_event = FindMyMainEventToggle;
break;
case InputKeyLeft:
cb_event = FindMyMainEventBackground;
break;
case InputKeyRight:
cb_event = FindMyMainEventConfig;
break;
case InputKeyUp:
cb_event = FindMyMainEventIntervalUp;
break;
case InputKeyDown:
cb_event = FindMyMainEventIntervalDown;
break;
default:
return consumed;
}
findmy_main->callback(cb_event, findmy_main->context);
}
return consumed;
}
FindMyMain* findmy_main_alloc(FindMy* app) {
FindMyMain* findmy_main = malloc(sizeof(FindMyMain));
findmy_main->view = view_alloc();
view_allocate_model(findmy_main->view, ViewModelTypeLocking, sizeof(FindMyMainModel));
with_view_model(
findmy_main->view,
FindMyMainModel * model,
{
model->active = app->state.beacon_active;
model->interval = app->state.broadcast_interval;
model->show_mac = app->state.show_mac;
memcpy(model->mac, app->state.mac, sizeof(model->mac));
model->type = app->state.tag_type;
},
false);
view_set_context(findmy_main->view, findmy_main);
view_set_draw_callback(findmy_main->view, findmy_main_draw_callback);
view_set_input_callback(findmy_main->view, findmy_main_input_callback);
return findmy_main;
}
void findmy_main_free(FindMyMain* findmy_main) {
furi_assert(findmy_main);
view_free(findmy_main->view);
free(findmy_main);
}
View* findmy_main_get_view(FindMyMain* findmy_main) {
furi_assert(findmy_main);
return findmy_main->view;
}
void findmy_main_set_callback(FindMyMain* findmy_main, FindMyMainCallback callback, void* context) {
furi_assert(findmy_main);
furi_assert(callback);
findmy_main->callback = callback;
findmy_main->context = context;
}
void findmy_main_update_active(FindMyMain* findmy_main, bool active) {
furi_assert(findmy_main);
with_view_model(findmy_main->view, FindMyMainModel * model, { model->active = active; }, true);
}
void findmy_main_toggle_mac(FindMyMain* findmy_main, bool show_mac) {
furi_assert(findmy_main);
with_view_model(
findmy_main->view, FindMyMainModel * model, { model->show_mac = show_mac; }, true);
}
void findmy_main_update_mac(FindMyMain* findmy_main, uint8_t* mac) {
with_view_model(
findmy_main->view,
FindMyMainModel * model,
{
memcpy(model->mac, mac, sizeof(model->mac));
findmy_reverse_mac_addr(model->mac);
},
true);
}
void findmy_main_update_interval(FindMyMain* findmy_main, uint8_t interval) {
furi_assert(findmy_main);
with_view_model(
findmy_main->view, FindMyMainModel * model, { model->interval = interval; }, true);
}
void findmy_main_update_type(FindMyMain* findmy_main, FindMyType type) {
furi_assert(findmy_main);
with_view_model(findmy_main->view, FindMyMainModel * model, { model->type = type; }, true);
}

View File

@@ -0,0 +1,32 @@
#pragma once
#include "../findmy.h"
#include "../findmy_state.h"
#include <gui/view.h>
typedef enum {
FindMyMainEventToggle,
FindMyMainEventBackground,
FindMyMainEventConfig,
FindMyMainEventIntervalUp,
FindMyMainEventIntervalDown,
FindMyMainEventQuit,
} FindMyMainEvent;
typedef struct FindMyMain FindMyMain;
typedef void (*FindMyMainCallback)(FindMyMainEvent event, void* context);
// Main functionality
FindMyMain* findmy_main_alloc(FindMy* app);
void findmy_main_free(FindMyMain* findmy_main);
View* findmy_main_get_view(FindMyMain* findmy_main);
// To communicate with scene
void findmy_main_set_callback(FindMyMain* findmy_main, FindMyMainCallback callback, void* context);
// To redraw when info changes
void findmy_main_update_active(FindMyMain* findmy_main, bool active);
void findmy_main_update_interval(FindMyMain* findmy_main, uint8_t interval);
void findmy_main_toggle_mac(FindMyMain* findmy_main, bool show_mac);
void findmy_main_update_mac(FindMyMain* findmy_main, uint8_t* mac);
void findmy_main_update_type(FindMyMain* findmy_main, FindMyType type);