|
|
@@ -1,24 +1,55 @@
|
|
|
#include "swiftpair.h"
|
|
|
#include "_protocols.h"
|
|
|
|
|
|
+#include <storage/storage.h>
|
|
|
+#include <toolbox/stream/file_stream.h>
|
|
|
+
|
|
|
// Hacked together by @Willy-JL and @Spooks4576
|
|
|
// Documentation at https://learn.microsoft.com/en-us/windows-hardware/design/component-guidelines/bluetooth-swift-pair
|
|
|
|
|
|
-static const char* names[] = {
|
|
|
- "Assquach💦",
|
|
|
- "Flipper 🐬",
|
|
|
- "iOS 17 🍎",
|
|
|
- "Kink💦",
|
|
|
- "👉👌",
|
|
|
- "🔵🦷",
|
|
|
-};
|
|
|
-static const uint8_t names_count = COUNT_OF(names);
|
|
|
+static char names[256][sizeof(((SwiftpairCfg*)0)->name)];
|
|
|
+static uint8_t names_count = 0;
|
|
|
|
|
|
static const char* get_name(const Payload* payload) {
|
|
|
UNUSED(payload);
|
|
|
return "SwiftPair";
|
|
|
}
|
|
|
|
|
|
+static const char* random_name() {
|
|
|
+ if(names_count == 0) {
|
|
|
+ // Fill random names
|
|
|
+ Storage* storage = furi_record_open(RECORD_STORAGE);
|
|
|
+ Stream* stream = file_stream_alloc(storage);
|
|
|
+ FuriString* line = furi_string_alloc();
|
|
|
+ if(!storage_file_exists(storage, APP_DATA_PATH("swiftpair.txt"))) {
|
|
|
+ // Copy default names
|
|
|
+ storage_common_copy(
|
|
|
+ storage, APP_ASSETS_PATH("swiftpair.txt"), APP_DATA_PATH("swiftpair.txt"));
|
|
|
+ }
|
|
|
+ if(file_stream_open(
|
|
|
+ stream, APP_DATA_PATH("swiftpair.txt"), FSAM_READ, FSOM_OPEN_EXISTING)) {
|
|
|
+ while(stream_read_line(stream, line)) {
|
|
|
+ furi_string_replace_all(line, "\r", "");
|
|
|
+ furi_string_replace_all(line, "\n", "");
|
|
|
+ if(furi_string_size(line)) {
|
|
|
+ strlcpy(names[names_count++], furi_string_get_cstr(line), sizeof(names[0]));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ furi_string_free(line);
|
|
|
+ file_stream_close(stream);
|
|
|
+ stream_free(stream);
|
|
|
+ furi_record_close(RECORD_STORAGE);
|
|
|
+
|
|
|
+ if(names_count == 0) {
|
|
|
+ // Add fallback if list is empty
|
|
|
+ strlcpy(names[names_count++], "SwiftPair", sizeof(names[0]));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return names[rand() % names_count];
|
|
|
+}
|
|
|
+
|
|
|
static void make_packet(uint8_t* _size, uint8_t** _packet, Payload* payload) {
|
|
|
SwiftpairCfg* cfg = payload ? &payload->cfg.swiftpair : NULL;
|
|
|
|
|
|
@@ -26,7 +57,7 @@ static void make_packet(uint8_t* _size, uint8_t** _packet, Payload* payload) {
|
|
|
switch(cfg ? payload->mode : PayloadModeRandom) {
|
|
|
case PayloadModeRandom:
|
|
|
default:
|
|
|
- name = names[rand() % names_count];
|
|
|
+ name = random_name();
|
|
|
break;
|
|
|
case PayloadModeValue:
|
|
|
name = cfg->name;
|