mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-27 03:49:58 -07:00
BLE Spam refactor random/set/custom mode handling
This commit is contained in:
@@ -10,12 +10,12 @@
|
||||
#include <core/core_defines.h>
|
||||
#include "../ble_spam.h"
|
||||
|
||||
typedef union ProtocolCfg ProtocolCfg;
|
||||
typedef struct ProtocolCfg ProtocolCfg;
|
||||
|
||||
typedef struct {
|
||||
const Icon* icon;
|
||||
const char* (*get_name)(const ProtocolCfg* _cfg);
|
||||
void (*make_packet)(uint8_t* _size, uint8_t** _packet, const ProtocolCfg* _cfg);
|
||||
void (*make_packet)(uint8_t* _size, uint8_t** _packet, ProtocolCfg* _cfg);
|
||||
void (*extra_config)(Ctx* ctx);
|
||||
uint8_t (*config_count)(const ProtocolCfg* _cfg);
|
||||
} Protocol;
|
||||
|
||||
@@ -5,11 +5,19 @@
|
||||
#include "easysetup.h"
|
||||
#include "swiftpair.h"
|
||||
|
||||
union ProtocolCfg {
|
||||
ContinuityCfg continuity;
|
||||
FastpairCfg fastpair;
|
||||
EasysetupCfg easysetup;
|
||||
SwiftpairCfg swiftpair;
|
||||
typedef enum {
|
||||
ProtocolModeRandom,
|
||||
ProtocolModeValue,
|
||||
} ProtocolMode;
|
||||
|
||||
struct ProtocolCfg {
|
||||
ProtocolMode mode;
|
||||
union {
|
||||
ContinuityCfg continuity;
|
||||
FastpairCfg fastpair;
|
||||
EasysetupCfg easysetup;
|
||||
SwiftpairCfg swiftpair;
|
||||
} specific;
|
||||
};
|
||||
|
||||
extern const Protocol* protocols[];
|
||||
|
||||
@@ -72,7 +72,7 @@ static const char* type_names[ContinuityTypeCOUNT] = {
|
||||
[ContinuityTypeCustomCrash] = "Continuity Custom",
|
||||
};
|
||||
static const char* get_name(const ProtocolCfg* _cfg) {
|
||||
const ContinuityCfg* cfg = &_cfg->continuity;
|
||||
const ContinuityCfg* cfg = &_cfg->specific.continuity;
|
||||
return type_names[cfg->type];
|
||||
}
|
||||
|
||||
@@ -87,8 +87,8 @@ static uint8_t packet_sizes[ContinuityTypeCOUNT] = {
|
||||
[ContinuityTypeNearbyInfo] = HEADER_LEN + 5,
|
||||
[ContinuityTypeCustomCrash] = HEADER_LEN + 11,
|
||||
};
|
||||
static void make_packet(uint8_t* _size, uint8_t** _packet, const ProtocolCfg* _cfg) {
|
||||
const ContinuityCfg* cfg = _cfg ? &_cfg->continuity : NULL;
|
||||
static void make_packet(uint8_t* _size, uint8_t** _packet, ProtocolCfg* _cfg) {
|
||||
ContinuityCfg* cfg = _cfg ? &_cfg->specific.continuity : NULL;
|
||||
|
||||
ContinuityType type;
|
||||
if(cfg && cfg->type != 0x00) {
|
||||
@@ -139,14 +139,18 @@ static void make_packet(uint8_t* _size, uint8_t** _packet, const ProtocolCfg* _c
|
||||
|
||||
case ContinuityTypeProximityPair: {
|
||||
uint16_t model;
|
||||
if(cfg && cfg->data.proximity_pair.model != 0x0000) {
|
||||
model = cfg->data.proximity_pair.model;
|
||||
} else {
|
||||
switch(cfg ? _cfg->mode : ProtocolModeRandom) {
|
||||
case ProtocolModeRandom:
|
||||
default:
|
||||
model = pp_models[rand() % pp_models_count].value;
|
||||
break;
|
||||
case ProtocolModeValue:
|
||||
model = cfg->data.proximity_pair.model;
|
||||
break;
|
||||
}
|
||||
|
||||
uint8_t prefix;
|
||||
if(cfg && cfg->data.proximity_pair.prefix == 0x00) {
|
||||
if(cfg && cfg->data.proximity_pair.prefix != 0x00) {
|
||||
prefix = cfg->data.proximity_pair.prefix;
|
||||
} else {
|
||||
if(model == 0x0055 || model == 0x0030)
|
||||
@@ -209,10 +213,14 @@ static void make_packet(uint8_t* _size, uint8_t** _packet, const ProtocolCfg* _c
|
||||
|
||||
case ContinuityTypeNearbyAction: {
|
||||
uint8_t action;
|
||||
if(cfg && cfg->data.nearby_action.action != 0x00) {
|
||||
action = cfg->data.nearby_action.action;
|
||||
} else {
|
||||
switch(cfg ? _cfg->mode : ProtocolModeRandom) {
|
||||
case ProtocolModeRandom:
|
||||
default:
|
||||
action = na_actions[rand() % na_actions_count].value;
|
||||
break;
|
||||
case ProtocolModeValue:
|
||||
action = cfg->data.nearby_action.action;
|
||||
break;
|
||||
}
|
||||
|
||||
uint8_t flags;
|
||||
@@ -293,7 +301,8 @@ enum {
|
||||
};
|
||||
static void config_callback(void* _ctx, uint32_t index) {
|
||||
Ctx* ctx = _ctx;
|
||||
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
ContinuityCfg* cfg = &_cfg->specific.continuity;
|
||||
scene_manager_set_scene_state(ctx->scene_manager, SceneConfig, index);
|
||||
switch(cfg->type) {
|
||||
case ContinuityTypeProximityPair: {
|
||||
@@ -341,19 +350,22 @@ static void config_callback(void* _ctx, uint32_t index) {
|
||||
}
|
||||
}
|
||||
static void pp_model_changed(VariableItem* item) {
|
||||
ContinuityCfg* cfg = variable_item_get_context(item);
|
||||
ProtocolCfg* _cfg = variable_item_get_context(item);
|
||||
ContinuityCfg* cfg = &_cfg->specific.continuity;
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
if(index) {
|
||||
index--;
|
||||
_cfg->mode = ProtocolModeValue;
|
||||
cfg->data.proximity_pair.model = pp_models[index].value;
|
||||
variable_item_set_current_value_text(item, pp_models[index].name);
|
||||
} else {
|
||||
cfg->data.proximity_pair.model = 0x0000;
|
||||
_cfg->mode = ProtocolModeRandom;
|
||||
variable_item_set_current_value_text(item, "Random");
|
||||
}
|
||||
}
|
||||
static void pp_prefix_changed(VariableItem* item) {
|
||||
ContinuityCfg* cfg = variable_item_get_context(item);
|
||||
ProtocolCfg* _cfg = variable_item_get_context(item);
|
||||
ContinuityCfg* cfg = &_cfg->specific.continuity;
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
if(index) {
|
||||
index--;
|
||||
@@ -365,33 +377,39 @@ static void pp_prefix_changed(VariableItem* item) {
|
||||
}
|
||||
}
|
||||
static void na_action_changed(VariableItem* item) {
|
||||
ContinuityCfg* cfg = variable_item_get_context(item);
|
||||
ProtocolCfg* _cfg = variable_item_get_context(item);
|
||||
ContinuityCfg* cfg = &_cfg->specific.continuity;
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
if(index) {
|
||||
index--;
|
||||
_cfg->mode = ProtocolModeValue;
|
||||
cfg->data.nearby_action.action = na_actions[index].value;
|
||||
variable_item_set_current_value_text(item, na_actions[index].name);
|
||||
} else {
|
||||
cfg->data.nearby_action.action = 0x00;
|
||||
_cfg->mode = ProtocolModeRandom;
|
||||
variable_item_set_current_value_text(item, "Random");
|
||||
}
|
||||
}
|
||||
static void extra_config(Ctx* ctx) {
|
||||
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
ContinuityCfg* cfg = &_cfg->specific.continuity;
|
||||
VariableItemList* list = ctx->variable_item_list;
|
||||
VariableItem* item;
|
||||
size_t value_index;
|
||||
|
||||
switch(cfg->type) {
|
||||
case ContinuityTypeProximityPair: {
|
||||
item =
|
||||
variable_item_list_add(list, "Model Code", pp_models_count + 1, pp_model_changed, cfg);
|
||||
item = variable_item_list_add(
|
||||
list, "Model Code", pp_models_count + 1, pp_model_changed, _cfg);
|
||||
const char* model_name = NULL;
|
||||
char model_name_buf[5];
|
||||
if(cfg->data.proximity_pair.model == 0x0000) {
|
||||
switch(_cfg->mode) {
|
||||
case ProtocolModeRandom:
|
||||
default:
|
||||
model_name = "Random";
|
||||
value_index = 0;
|
||||
} else {
|
||||
break;
|
||||
case ProtocolModeValue:
|
||||
for(uint8_t i = 0; i < pp_models_count; i++) {
|
||||
if(cfg->data.proximity_pair.model == pp_models[i].value) {
|
||||
model_name = pp_models[i].name;
|
||||
@@ -405,12 +423,13 @@ static void extra_config(Ctx* ctx) {
|
||||
model_name = model_name_buf;
|
||||
value_index = pp_models_count + 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, model_name);
|
||||
|
||||
item =
|
||||
variable_item_list_add(list, "Prefix", pp_prefixes_count + 1, pp_prefix_changed, cfg);
|
||||
variable_item_list_add(list, "Prefix", pp_prefixes_count + 1, pp_prefix_changed, _cfg);
|
||||
const char* prefix_name = NULL;
|
||||
char prefix_name_buf[3];
|
||||
if(cfg->data.proximity_pair.prefix == 0x00) {
|
||||
@@ -440,13 +459,16 @@ static void extra_config(Ctx* ctx) {
|
||||
}
|
||||
case ContinuityTypeNearbyAction: {
|
||||
item = variable_item_list_add(
|
||||
list, "Action Type", na_actions_count + 1, na_action_changed, cfg);
|
||||
list, "Action Type", na_actions_count + 1, na_action_changed, _cfg);
|
||||
const char* action_name = NULL;
|
||||
char action_name_buf[3];
|
||||
if(cfg->data.nearby_action.action == 0x00) {
|
||||
switch(_cfg->mode) {
|
||||
case ProtocolModeRandom:
|
||||
default:
|
||||
action_name = "Random";
|
||||
value_index = 0;
|
||||
} else {
|
||||
break;
|
||||
case ProtocolModeValue:
|
||||
for(uint8_t i = 0; i < na_actions_count; i++) {
|
||||
if(cfg->data.nearby_action.action == na_actions[i].value) {
|
||||
action_name = na_actions[i].name;
|
||||
@@ -463,6 +485,7 @@ static void extra_config(Ctx* ctx) {
|
||||
action_name = action_name_buf;
|
||||
value_index = na_actions_count + 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, action_name);
|
||||
@@ -503,7 +526,7 @@ static uint8_t config_counts[ContinuityTypeCOUNT] = {
|
||||
[ContinuityTypeCustomCrash] = ConfigCcCOUNT - ConfigExtraStart - 1,
|
||||
};
|
||||
static uint8_t config_count(const ProtocolCfg* _cfg) {
|
||||
const ContinuityCfg* cfg = &_cfg->continuity;
|
||||
const ContinuityCfg* cfg = &_cfg->specific.continuity;
|
||||
return config_counts[cfg->type];
|
||||
}
|
||||
|
||||
@@ -517,16 +540,18 @@ const Protocol protocol_continuity = {
|
||||
|
||||
static void pp_model_callback(void* _ctx, uint32_t index) {
|
||||
Ctx* ctx = _ctx;
|
||||
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
ContinuityCfg* cfg = &_cfg->specific.continuity;
|
||||
switch(index) {
|
||||
case 0:
|
||||
cfg->data.proximity_pair.model = 0x0000;
|
||||
_cfg->mode = ProtocolModeRandom;
|
||||
scene_manager_previous_scene(ctx->scene_manager);
|
||||
break;
|
||||
case pp_models_count + 1:
|
||||
scene_manager_next_scene(ctx->scene_manager, SceneContinuityPpModelCustom);
|
||||
break;
|
||||
default:
|
||||
_cfg->mode = ProtocolModeValue;
|
||||
cfg->data.proximity_pair.model = pp_models[index - 1].value;
|
||||
scene_manager_previous_scene(ctx->scene_manager);
|
||||
break;
|
||||
@@ -534,27 +559,28 @@ static void pp_model_callback(void* _ctx, uint32_t index) {
|
||||
}
|
||||
void scene_continuity_pp_model_on_enter(void* _ctx) {
|
||||
Ctx* ctx = _ctx;
|
||||
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
ContinuityCfg* cfg = &_cfg->specific.continuity;
|
||||
Submenu* submenu = ctx->submenu;
|
||||
uint32_t selected = 0;
|
||||
bool found = false;
|
||||
submenu_reset(submenu);
|
||||
|
||||
submenu_add_item(submenu, "Random", 0, pp_model_callback, ctx);
|
||||
if(cfg->data.proximity_pair.model == 0x0000) {
|
||||
found = true;
|
||||
if(_cfg->mode == ProtocolModeRandom) {
|
||||
selected = 0;
|
||||
}
|
||||
|
||||
bool found = false;
|
||||
for(uint8_t i = 0; i < pp_models_count; i++) {
|
||||
submenu_add_item(submenu, pp_models[i].name, i + 1, pp_model_callback, ctx);
|
||||
if(!found && cfg->data.proximity_pair.model == pp_models[i].value) {
|
||||
if(!found && _cfg->mode == ProtocolModeValue &&
|
||||
cfg->data.proximity_pair.model == pp_models[i].value) {
|
||||
found = true;
|
||||
selected = i + 1;
|
||||
}
|
||||
}
|
||||
submenu_add_item(submenu, "Custom", pp_models_count + 1, pp_model_callback, ctx);
|
||||
if(!found) {
|
||||
found = true;
|
||||
if(!found && _cfg->mode == ProtocolModeValue) {
|
||||
selected = pp_models_count + 1;
|
||||
}
|
||||
|
||||
@@ -573,14 +599,17 @@ void scene_continuity_pp_model_on_exit(void* _ctx) {
|
||||
|
||||
static void pp_model_custom_callback(void* _ctx) {
|
||||
Ctx* ctx = _ctx;
|
||||
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
ContinuityCfg* cfg = &_cfg->specific.continuity;
|
||||
_cfg->mode = ProtocolModeValue;
|
||||
cfg->data.proximity_pair.model = (ctx->byte_store[0] << 0x08) + (ctx->byte_store[1] << 0x00);
|
||||
scene_manager_previous_scene(ctx->scene_manager);
|
||||
scene_manager_previous_scene(ctx->scene_manager);
|
||||
}
|
||||
void scene_continuity_pp_model_custom_on_enter(void* _ctx) {
|
||||
Ctx* ctx = _ctx;
|
||||
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
ContinuityCfg* cfg = &_cfg->specific.continuity;
|
||||
ByteInput* byte_input = ctx->byte_input;
|
||||
|
||||
byte_input_set_header_text(byte_input, "Enter custom Model Code");
|
||||
@@ -604,7 +633,8 @@ void scene_continuity_pp_model_custom_on_exit(void* _ctx) {
|
||||
|
||||
static void pp_prefix_callback(void* _ctx, uint32_t index) {
|
||||
Ctx* ctx = _ctx;
|
||||
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
ContinuityCfg* cfg = &_cfg->specific.continuity;
|
||||
switch(index) {
|
||||
case 0:
|
||||
cfg->data.proximity_pair.prefix = 0x00;
|
||||
@@ -621,7 +651,8 @@ static void pp_prefix_callback(void* _ctx, uint32_t index) {
|
||||
}
|
||||
void scene_continuity_pp_prefix_on_enter(void* _ctx) {
|
||||
Ctx* ctx = _ctx;
|
||||
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
ContinuityCfg* cfg = &_cfg->specific.continuity;
|
||||
Submenu* submenu = ctx->submenu;
|
||||
uint32_t selected = 0;
|
||||
bool found = false;
|
||||
@@ -632,6 +663,7 @@ void scene_continuity_pp_prefix_on_enter(void* _ctx) {
|
||||
found = true;
|
||||
selected = 0;
|
||||
}
|
||||
|
||||
for(uint8_t i = 0; i < pp_prefixes_count; i++) {
|
||||
submenu_add_item(submenu, pp_prefixes[i].name, i + 1, pp_prefix_callback, ctx);
|
||||
if(!found && cfg->data.proximity_pair.prefix == pp_prefixes[i].value) {
|
||||
@@ -641,7 +673,6 @@ void scene_continuity_pp_prefix_on_enter(void* _ctx) {
|
||||
}
|
||||
submenu_add_item(submenu, "Custom", pp_prefixes_count + 1, pp_prefix_callback, ctx);
|
||||
if(!found) {
|
||||
found = true;
|
||||
selected = pp_prefixes_count + 1;
|
||||
}
|
||||
|
||||
@@ -660,14 +691,16 @@ void scene_continuity_pp_prefix_on_exit(void* _ctx) {
|
||||
|
||||
static void pp_prefix_custom_callback(void* _ctx) {
|
||||
Ctx* ctx = _ctx;
|
||||
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
ContinuityCfg* cfg = &_cfg->specific.continuity;
|
||||
cfg->data.proximity_pair.prefix = (ctx->byte_store[0] << 0x00);
|
||||
scene_manager_previous_scene(ctx->scene_manager);
|
||||
scene_manager_previous_scene(ctx->scene_manager);
|
||||
}
|
||||
void scene_continuity_pp_prefix_custom_on_enter(void* _ctx) {
|
||||
Ctx* ctx = _ctx;
|
||||
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
ContinuityCfg* cfg = &_cfg->specific.continuity;
|
||||
ByteInput* byte_input = ctx->byte_input;
|
||||
|
||||
byte_input_set_header_text(byte_input, "Enter custom Prefix");
|
||||
@@ -690,16 +723,18 @@ void scene_continuity_pp_prefix_custom_on_exit(void* _ctx) {
|
||||
|
||||
static void na_action_callback(void* _ctx, uint32_t index) {
|
||||
Ctx* ctx = _ctx;
|
||||
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
ContinuityCfg* cfg = &_cfg->specific.continuity;
|
||||
switch(index) {
|
||||
case 0:
|
||||
cfg->data.nearby_action.action = 0x00;
|
||||
_cfg->mode = ProtocolModeRandom;
|
||||
scene_manager_previous_scene(ctx->scene_manager);
|
||||
break;
|
||||
case na_actions_count + 1:
|
||||
scene_manager_next_scene(ctx->scene_manager, SceneContinuityNaActionCustom);
|
||||
break;
|
||||
default:
|
||||
_cfg->mode = ProtocolModeValue;
|
||||
cfg->data.nearby_action.action = na_actions[index - 1].value;
|
||||
scene_manager_previous_scene(ctx->scene_manager);
|
||||
break;
|
||||
@@ -707,27 +742,28 @@ static void na_action_callback(void* _ctx, uint32_t index) {
|
||||
}
|
||||
void scene_continuity_na_action_on_enter(void* _ctx) {
|
||||
Ctx* ctx = _ctx;
|
||||
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
ContinuityCfg* cfg = &_cfg->specific.continuity;
|
||||
Submenu* submenu = ctx->submenu;
|
||||
uint32_t selected = 0;
|
||||
bool found = false;
|
||||
submenu_reset(submenu);
|
||||
|
||||
submenu_add_item(submenu, "Random", 0, na_action_callback, ctx);
|
||||
if(cfg->data.nearby_action.action == 0x00) {
|
||||
found = true;
|
||||
if(_cfg->mode == ProtocolModeRandom) {
|
||||
selected = 0;
|
||||
}
|
||||
|
||||
bool found = false;
|
||||
for(uint8_t i = 0; i < na_actions_count; i++) {
|
||||
submenu_add_item(submenu, na_actions[i].name, i + 1, na_action_callback, ctx);
|
||||
if(!found && cfg->data.nearby_action.action == na_actions[i].value) {
|
||||
if(!found && _cfg->mode == ProtocolModeValue &&
|
||||
cfg->data.nearby_action.action == na_actions[i].value) {
|
||||
found = true;
|
||||
selected = i + 1;
|
||||
}
|
||||
}
|
||||
submenu_add_item(submenu, "Custom", na_actions_count + 1, na_action_callback, ctx);
|
||||
if(!found) {
|
||||
found = true;
|
||||
if(!found && _cfg->mode == ProtocolModeValue) {
|
||||
selected = na_actions_count + 1;
|
||||
}
|
||||
|
||||
@@ -746,14 +782,17 @@ void scene_continuity_na_action_on_exit(void* _ctx) {
|
||||
|
||||
static void na_action_custom_callback(void* _ctx) {
|
||||
Ctx* ctx = _ctx;
|
||||
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
ContinuityCfg* cfg = &_cfg->specific.continuity;
|
||||
_cfg->mode = ProtocolModeValue;
|
||||
cfg->data.nearby_action.action = (ctx->byte_store[0] << 0x00);
|
||||
scene_manager_previous_scene(ctx->scene_manager);
|
||||
scene_manager_previous_scene(ctx->scene_manager);
|
||||
}
|
||||
void scene_continuity_na_action_custom_on_enter(void* _ctx) {
|
||||
Ctx* ctx = _ctx;
|
||||
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
ContinuityCfg* cfg = &_cfg->specific.continuity;
|
||||
ByteInput* byte_input = ctx->byte_input;
|
||||
|
||||
byte_input_set_header_text(byte_input, "Enter custom Action Type");
|
||||
@@ -780,7 +819,8 @@ static void na_flags_callback(void* _ctx) {
|
||||
}
|
||||
void scene_continuity_na_flags_on_enter(void* _ctx) {
|
||||
Ctx* ctx = _ctx;
|
||||
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
ContinuityCfg* cfg = &_cfg->specific.continuity;
|
||||
ByteInput* byte_input = ctx->byte_input;
|
||||
|
||||
byte_input_set_header_text(byte_input, "Press back for automatic");
|
||||
@@ -801,6 +841,7 @@ bool scene_continuity_na_flags_on_event(void* _ctx, SceneManagerEvent event) {
|
||||
}
|
||||
void scene_continuity_na_flags_on_exit(void* _ctx) {
|
||||
Ctx* ctx = _ctx;
|
||||
ContinuityCfg* cfg = &ctx->attack->payload.cfg.continuity;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
ContinuityCfg* cfg = &_cfg->specific.continuity;
|
||||
cfg->data.nearby_action.flags = (ctx->byte_store[0] << 0x00);
|
||||
}
|
||||
|
||||
122
applications/external/ble_spam/protocols/easysetup.c
vendored
122
applications/external/ble_spam/protocols/easysetup.c
vendored
@@ -69,7 +69,7 @@ static const char* type_names[EasysetupTypeCOUNT] = {
|
||||
[EasysetupTypeWatch] = "EasySetup Watch",
|
||||
};
|
||||
static const char* get_name(const ProtocolCfg* _cfg) {
|
||||
const EasysetupCfg* cfg = &_cfg->easysetup;
|
||||
const EasysetupCfg* cfg = &_cfg->specific.easysetup;
|
||||
return type_names[cfg->type];
|
||||
}
|
||||
|
||||
@@ -77,8 +77,8 @@ static uint8_t packet_sizes[EasysetupTypeCOUNT] = {
|
||||
[EasysetupTypeBuds] = 31,
|
||||
[EasysetupTypeWatch] = 15,
|
||||
};
|
||||
void make_packet(uint8_t* out_size, uint8_t** out_packet, const ProtocolCfg* _cfg) {
|
||||
const EasysetupCfg* cfg = _cfg ? &_cfg->easysetup : NULL;
|
||||
void make_packet(uint8_t* out_size, uint8_t** out_packet, ProtocolCfg* _cfg) {
|
||||
EasysetupCfg* cfg = _cfg ? &_cfg->specific.easysetup : NULL;
|
||||
|
||||
EasysetupType type;
|
||||
if(cfg && cfg->type != 0x00) {
|
||||
@@ -98,10 +98,14 @@ void make_packet(uint8_t* out_size, uint8_t** out_packet, const ProtocolCfg* _cf
|
||||
switch(type) {
|
||||
case EasysetupTypeBuds: {
|
||||
uint32_t model;
|
||||
if(cfg && cfg->data.buds.model != 0x000000) {
|
||||
model = cfg->data.buds.model;
|
||||
} else {
|
||||
switch(cfg ? _cfg->mode : ProtocolModeRandom) {
|
||||
case ProtocolModeRandom:
|
||||
default:
|
||||
model = buds_models[rand() % buds_models_count].value;
|
||||
break;
|
||||
case ProtocolModeValue:
|
||||
model = cfg->data.buds.model;
|
||||
break;
|
||||
}
|
||||
|
||||
packet[i++] = 27; // Size
|
||||
@@ -141,10 +145,14 @@ void make_packet(uint8_t* out_size, uint8_t** out_packet, const ProtocolCfg* _cf
|
||||
}
|
||||
case EasysetupTypeWatch: {
|
||||
uint8_t model;
|
||||
if(cfg && cfg->data.watch.model != 0x00) {
|
||||
model = cfg->data.watch.model;
|
||||
} else {
|
||||
switch(cfg ? _cfg->mode : ProtocolModeRandom) {
|
||||
case ProtocolModeRandom:
|
||||
default:
|
||||
model = watch_models[rand() % watch_models_count].value;
|
||||
break;
|
||||
case ProtocolModeValue:
|
||||
model = cfg->data.watch.model;
|
||||
break;
|
||||
}
|
||||
|
||||
packet[i++] = 14; // Size
|
||||
@@ -185,7 +193,8 @@ enum {
|
||||
};
|
||||
static void config_callback(void* _ctx, uint32_t index) {
|
||||
Ctx* ctx = _ctx;
|
||||
EasysetupCfg* cfg = &ctx->attack->payload.cfg.easysetup;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
EasysetupCfg* cfg = &_cfg->specific.easysetup;
|
||||
scene_manager_set_scene_state(ctx->scene_manager, SceneConfig, index);
|
||||
switch(cfg->type) {
|
||||
case EasysetupTypeBuds: {
|
||||
@@ -218,31 +227,36 @@ static void config_callback(void* _ctx, uint32_t index) {
|
||||
}
|
||||
}
|
||||
static void buds_model_changed(VariableItem* item) {
|
||||
EasysetupCfg* cfg = variable_item_get_context(item);
|
||||
ProtocolCfg* _cfg = variable_item_get_context(item);
|
||||
EasysetupCfg* cfg = &_cfg->specific.easysetup;
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
if(index) {
|
||||
index--;
|
||||
_cfg->mode = ProtocolModeValue;
|
||||
cfg->data.buds.model = buds_models[index].value;
|
||||
variable_item_set_current_value_text(item, buds_models[index].name);
|
||||
} else {
|
||||
cfg->data.buds.model = 0x000000;
|
||||
_cfg->mode = ProtocolModeRandom;
|
||||
variable_item_set_current_value_text(item, "Random");
|
||||
}
|
||||
}
|
||||
static void watch_model_changed(VariableItem* item) {
|
||||
EasysetupCfg* cfg = variable_item_get_context(item);
|
||||
ProtocolCfg* _cfg = variable_item_get_context(item);
|
||||
EasysetupCfg* cfg = &_cfg->specific.easysetup;
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
if(index) {
|
||||
index--;
|
||||
_cfg->mode = ProtocolModeValue;
|
||||
cfg->data.watch.model = watch_models[index].value;
|
||||
variable_item_set_current_value_text(item, watch_models[index].name);
|
||||
} else {
|
||||
cfg->data.watch.model = 0x00;
|
||||
_cfg->mode = ProtocolModeRandom;
|
||||
variable_item_set_current_value_text(item, "Random");
|
||||
}
|
||||
}
|
||||
static void extra_config(Ctx* ctx) {
|
||||
EasysetupCfg* cfg = &ctx->attack->payload.cfg.easysetup;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
EasysetupCfg* cfg = &_cfg->specific.easysetup;
|
||||
VariableItemList* list = ctx->variable_item_list;
|
||||
VariableItem* item;
|
||||
size_t value_index;
|
||||
@@ -250,13 +264,16 @@ static void extra_config(Ctx* ctx) {
|
||||
switch(cfg->type) {
|
||||
case EasysetupTypeBuds: {
|
||||
item = variable_item_list_add(
|
||||
list, "Model Code", buds_models_count + 1, buds_model_changed, cfg);
|
||||
list, "Model Code", buds_models_count + 1, buds_model_changed, _cfg);
|
||||
const char* model_name = NULL;
|
||||
char model_name_buf[9];
|
||||
if(cfg->data.buds.model == 0x000000) {
|
||||
switch(_cfg->mode) {
|
||||
case ProtocolModeRandom:
|
||||
default:
|
||||
model_name = "Random";
|
||||
value_index = 0;
|
||||
} else {
|
||||
break;
|
||||
case ProtocolModeValue:
|
||||
for(uint8_t i = 0; i < buds_models_count; i++) {
|
||||
if(cfg->data.buds.model == buds_models[i].value) {
|
||||
model_name = buds_models[i].name;
|
||||
@@ -269,6 +286,7 @@ static void extra_config(Ctx* ctx) {
|
||||
model_name = model_name_buf;
|
||||
value_index = buds_models_count + 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, model_name);
|
||||
@@ -278,13 +296,16 @@ static void extra_config(Ctx* ctx) {
|
||||
}
|
||||
case EasysetupTypeWatch: {
|
||||
item = variable_item_list_add(
|
||||
list, "Model Code", watch_models_count + 1, watch_model_changed, cfg);
|
||||
list, "Model Code", watch_models_count + 1, watch_model_changed, _cfg);
|
||||
const char* model_name = NULL;
|
||||
char model_name_buf[3];
|
||||
if(cfg->data.watch.model == 0x00) {
|
||||
switch(_cfg->mode) {
|
||||
case ProtocolModeRandom:
|
||||
default:
|
||||
model_name = "Random";
|
||||
value_index = 0;
|
||||
} else {
|
||||
break;
|
||||
case ProtocolModeValue:
|
||||
for(uint8_t i = 0; i < watch_models_count; i++) {
|
||||
if(cfg->data.watch.model == watch_models[i].value) {
|
||||
model_name = watch_models[i].name;
|
||||
@@ -297,6 +318,7 @@ static void extra_config(Ctx* ctx) {
|
||||
model_name = model_name_buf;
|
||||
value_index = watch_models_count + 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, model_name);
|
||||
@@ -314,7 +336,7 @@ static uint8_t config_counts[EasysetupTypeCOUNT] = {
|
||||
[EasysetupTypeWatch] = ConfigWatchCOUNT - ConfigExtraStart - 1,
|
||||
};
|
||||
static uint8_t config_count(const ProtocolCfg* _cfg) {
|
||||
const EasysetupCfg* cfg = &_cfg->easysetup;
|
||||
const EasysetupCfg* cfg = &_cfg->specific.easysetup;
|
||||
return config_counts[cfg->type];
|
||||
}
|
||||
|
||||
@@ -328,16 +350,18 @@ const Protocol protocol_easysetup = {
|
||||
|
||||
static void buds_model_callback(void* _ctx, uint32_t index) {
|
||||
Ctx* ctx = _ctx;
|
||||
EasysetupCfg* cfg = &ctx->attack->payload.cfg.easysetup;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
EasysetupCfg* cfg = &_cfg->specific.easysetup;
|
||||
switch(index) {
|
||||
case 0:
|
||||
cfg->data.buds.model = 0x000000;
|
||||
_cfg->mode = ProtocolModeRandom;
|
||||
scene_manager_previous_scene(ctx->scene_manager);
|
||||
break;
|
||||
case buds_models_count + 1:
|
||||
scene_manager_next_scene(ctx->scene_manager, SceneEasysetupBudsModelCustom);
|
||||
break;
|
||||
default:
|
||||
_cfg->mode = ProtocolModeValue;
|
||||
cfg->data.buds.model = buds_models[index - 1].value;
|
||||
scene_manager_previous_scene(ctx->scene_manager);
|
||||
break;
|
||||
@@ -345,27 +369,28 @@ static void buds_model_callback(void* _ctx, uint32_t index) {
|
||||
}
|
||||
void scene_easysetup_buds_model_on_enter(void* _ctx) {
|
||||
Ctx* ctx = _ctx;
|
||||
EasysetupCfg* cfg = &ctx->attack->payload.cfg.easysetup;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
EasysetupCfg* cfg = &_cfg->specific.easysetup;
|
||||
Submenu* submenu = ctx->submenu;
|
||||
uint32_t selected = 0;
|
||||
bool found = false;
|
||||
submenu_reset(submenu);
|
||||
|
||||
submenu_add_item(submenu, "Random", 0, buds_model_callback, ctx);
|
||||
if(cfg->data.buds.model == 0x000000) {
|
||||
found = true;
|
||||
if(_cfg->mode == ProtocolModeRandom) {
|
||||
selected = 0;
|
||||
}
|
||||
|
||||
bool found = false;
|
||||
for(uint8_t i = 0; i < buds_models_count; i++) {
|
||||
submenu_add_item(submenu, buds_models[i].name, i + 1, buds_model_callback, ctx);
|
||||
if(!found && cfg->data.buds.model == buds_models[i].value) {
|
||||
if(!found && _cfg->mode == ProtocolModeValue &&
|
||||
cfg->data.buds.model == buds_models[i].value) {
|
||||
found = true;
|
||||
selected = i + 1;
|
||||
}
|
||||
}
|
||||
submenu_add_item(submenu, "Custom", buds_models_count + 1, buds_model_callback, ctx);
|
||||
if(!found) {
|
||||
found = true;
|
||||
if(!found && _cfg->mode == ProtocolModeValue) {
|
||||
selected = buds_models_count + 1;
|
||||
}
|
||||
|
||||
@@ -384,7 +409,9 @@ void scene_easysetup_buds_model_on_exit(void* _ctx) {
|
||||
|
||||
static void buds_model_custom_callback(void* _ctx) {
|
||||
Ctx* ctx = _ctx;
|
||||
EasysetupCfg* cfg = &ctx->attack->payload.cfg.easysetup;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
EasysetupCfg* cfg = &_cfg->specific.easysetup;
|
||||
_cfg->mode = ProtocolModeValue;
|
||||
cfg->data.buds.model =
|
||||
(ctx->byte_store[0] << 0x10) + (ctx->byte_store[1] << 0x08) + (ctx->byte_store[2] << 0x00);
|
||||
scene_manager_previous_scene(ctx->scene_manager);
|
||||
@@ -392,7 +419,8 @@ static void buds_model_custom_callback(void* _ctx) {
|
||||
}
|
||||
void scene_easysetup_buds_model_custom_on_enter(void* _ctx) {
|
||||
Ctx* ctx = _ctx;
|
||||
EasysetupCfg* cfg = &ctx->attack->payload.cfg.easysetup;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
EasysetupCfg* cfg = &_cfg->specific.easysetup;
|
||||
ByteInput* byte_input = ctx->byte_input;
|
||||
|
||||
byte_input_set_header_text(byte_input, "Enter custom Model Code");
|
||||
@@ -417,16 +445,18 @@ void scene_easysetup_buds_model_custom_on_exit(void* _ctx) {
|
||||
|
||||
static void watch_model_callback(void* _ctx, uint32_t index) {
|
||||
Ctx* ctx = _ctx;
|
||||
EasysetupCfg* cfg = &ctx->attack->payload.cfg.easysetup;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
EasysetupCfg* cfg = &_cfg->specific.easysetup;
|
||||
switch(index) {
|
||||
case 0:
|
||||
cfg->data.watch.model = 0x00;
|
||||
_cfg->mode = ProtocolModeRandom;
|
||||
scene_manager_previous_scene(ctx->scene_manager);
|
||||
break;
|
||||
case watch_models_count + 1:
|
||||
scene_manager_next_scene(ctx->scene_manager, SceneEasysetupWatchModelCustom);
|
||||
break;
|
||||
default:
|
||||
_cfg->mode = ProtocolModeValue;
|
||||
cfg->data.watch.model = watch_models[index - 1].value;
|
||||
scene_manager_previous_scene(ctx->scene_manager);
|
||||
break;
|
||||
@@ -434,27 +464,28 @@ static void watch_model_callback(void* _ctx, uint32_t index) {
|
||||
}
|
||||
void scene_easysetup_watch_model_on_enter(void* _ctx) {
|
||||
Ctx* ctx = _ctx;
|
||||
EasysetupCfg* cfg = &ctx->attack->payload.cfg.easysetup;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
EasysetupCfg* cfg = &_cfg->specific.easysetup;
|
||||
Submenu* submenu = ctx->submenu;
|
||||
uint32_t selected = 0;
|
||||
bool found = false;
|
||||
submenu_reset(submenu);
|
||||
|
||||
submenu_add_item(submenu, "Random", 0, watch_model_callback, ctx);
|
||||
if(cfg->data.watch.model == 0x00) {
|
||||
found = true;
|
||||
if(_cfg->mode == ProtocolModeRandom) {
|
||||
selected = 0;
|
||||
}
|
||||
|
||||
bool found = false;
|
||||
for(uint8_t i = 0; i < watch_models_count; i++) {
|
||||
submenu_add_item(submenu, watch_models[i].name, i + 1, watch_model_callback, ctx);
|
||||
if(!found && cfg->data.watch.model == watch_models[i].value) {
|
||||
if(!found && _cfg->mode == ProtocolModeValue &&
|
||||
cfg->data.watch.model == watch_models[i].value) {
|
||||
found = true;
|
||||
selected = i + 1;
|
||||
}
|
||||
}
|
||||
submenu_add_item(submenu, "Custom", watch_models_count + 1, watch_model_callback, ctx);
|
||||
if(!found) {
|
||||
found = true;
|
||||
if(!found && _cfg->mode == ProtocolModeValue) {
|
||||
selected = watch_models_count + 1;
|
||||
}
|
||||
|
||||
@@ -473,14 +504,17 @@ void scene_easysetup_watch_model_on_exit(void* _ctx) {
|
||||
|
||||
static void watch_model_custom_callback(void* _ctx) {
|
||||
Ctx* ctx = _ctx;
|
||||
EasysetupCfg* cfg = &ctx->attack->payload.cfg.easysetup;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
EasysetupCfg* cfg = &_cfg->specific.easysetup;
|
||||
_cfg->mode = ProtocolModeValue;
|
||||
cfg->data.watch.model = (ctx->byte_store[0] << 0x00);
|
||||
scene_manager_previous_scene(ctx->scene_manager);
|
||||
scene_manager_previous_scene(ctx->scene_manager);
|
||||
}
|
||||
void scene_easysetup_watch_model_custom_on_enter(void* _ctx) {
|
||||
Ctx* ctx = _ctx;
|
||||
EasysetupCfg* cfg = &ctx->attack->payload.cfg.easysetup;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
EasysetupCfg* cfg = &_cfg->specific.easysetup;
|
||||
ByteInput* byte_input = ctx->byte_input;
|
||||
|
||||
byte_input_set_header_text(byte_input, "Enter custom Model Code");
|
||||
|
||||
@@ -51,14 +51,18 @@ static const char* get_name(const ProtocolCfg* _cfg) {
|
||||
return "FastPair";
|
||||
}
|
||||
|
||||
static void make_packet(uint8_t* _size, uint8_t** _packet, const ProtocolCfg* _cfg) {
|
||||
const FastpairCfg* cfg = _cfg ? &_cfg->fastpair : NULL;
|
||||
static void make_packet(uint8_t* _size, uint8_t** _packet, ProtocolCfg* _cfg) {
|
||||
FastpairCfg* cfg = _cfg ? &_cfg->specific.fastpair : NULL;
|
||||
|
||||
uint32_t model;
|
||||
if(cfg && cfg->model != 0x000000) {
|
||||
model = cfg->model;
|
||||
} else {
|
||||
switch(cfg ? _cfg->mode : ProtocolModeRandom) {
|
||||
case ProtocolModeRandom:
|
||||
default:
|
||||
model = models[rand() % models_count].value;
|
||||
break;
|
||||
case ProtocolModeValue:
|
||||
model = cfg->model;
|
||||
break;
|
||||
}
|
||||
|
||||
uint8_t size = 14;
|
||||
@@ -107,30 +111,36 @@ static void config_callback(void* _ctx, uint32_t index) {
|
||||
}
|
||||
}
|
||||
static void model_changed(VariableItem* item) {
|
||||
FastpairCfg* cfg = variable_item_get_context(item);
|
||||
ProtocolCfg* _cfg = variable_item_get_context(item);
|
||||
FastpairCfg* cfg = &_cfg->specific.fastpair;
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
if(index) {
|
||||
index--;
|
||||
_cfg->mode = ProtocolModeValue;
|
||||
cfg->model = models[index].value;
|
||||
variable_item_set_current_value_text(item, models[index].name);
|
||||
} else {
|
||||
cfg->model = 0x000000;
|
||||
_cfg->mode = ProtocolModeRandom;
|
||||
variable_item_set_current_value_text(item, "Random");
|
||||
}
|
||||
}
|
||||
static void extra_config(Ctx* ctx) {
|
||||
FastpairCfg* cfg = &ctx->attack->payload.cfg.fastpair;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
FastpairCfg* cfg = &_cfg->specific.fastpair;
|
||||
VariableItemList* list = ctx->variable_item_list;
|
||||
VariableItem* item;
|
||||
size_t value_index;
|
||||
|
||||
item = variable_item_list_add(list, "Model Code", models_count + 1, model_changed, cfg);
|
||||
item = variable_item_list_add(list, "Model Code", models_count + 1, model_changed, _cfg);
|
||||
const char* model_name = NULL;
|
||||
char model_name_buf[9];
|
||||
if(cfg->model == 0x000000) {
|
||||
switch(_cfg->mode) {
|
||||
case ProtocolModeRandom:
|
||||
default:
|
||||
model_name = "Random";
|
||||
value_index = 0;
|
||||
} else {
|
||||
break;
|
||||
case ProtocolModeValue:
|
||||
for(uint8_t i = 0; i < models_count; i++) {
|
||||
if(cfg->model == models[i].value) {
|
||||
model_name = models[i].name;
|
||||
@@ -143,6 +153,7 @@ static void extra_config(Ctx* ctx) {
|
||||
model_name = model_name_buf;
|
||||
value_index = models_count + 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, model_name);
|
||||
@@ -167,16 +178,18 @@ const Protocol protocol_fastpair = {
|
||||
|
||||
static void model_callback(void* _ctx, uint32_t index) {
|
||||
Ctx* ctx = _ctx;
|
||||
FastpairCfg* cfg = &ctx->attack->payload.cfg.fastpair;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
FastpairCfg* cfg = &_cfg->specific.fastpair;
|
||||
switch(index) {
|
||||
case 0:
|
||||
cfg->model = 0x000000;
|
||||
_cfg->mode = ProtocolModeRandom;
|
||||
scene_manager_previous_scene(ctx->scene_manager);
|
||||
break;
|
||||
case models_count + 1:
|
||||
scene_manager_next_scene(ctx->scene_manager, SceneFastpairModelCustom);
|
||||
break;
|
||||
default:
|
||||
_cfg->mode = ProtocolModeValue;
|
||||
cfg->model = models[index - 1].value;
|
||||
scene_manager_previous_scene(ctx->scene_manager);
|
||||
break;
|
||||
@@ -184,27 +197,27 @@ static void model_callback(void* _ctx, uint32_t index) {
|
||||
}
|
||||
void scene_fastpair_model_on_enter(void* _ctx) {
|
||||
Ctx* ctx = _ctx;
|
||||
FastpairCfg* cfg = &ctx->attack->payload.cfg.fastpair;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
FastpairCfg* cfg = &_cfg->specific.fastpair;
|
||||
Submenu* submenu = ctx->submenu;
|
||||
uint32_t selected = 0;
|
||||
bool found = false;
|
||||
submenu_reset(submenu);
|
||||
|
||||
submenu_add_item(submenu, "Random", 0, model_callback, ctx);
|
||||
if(cfg->model == 0x000000) {
|
||||
found = true;
|
||||
if(_cfg->mode == ProtocolModeRandom) {
|
||||
selected = 0;
|
||||
}
|
||||
|
||||
bool found = false;
|
||||
for(uint8_t i = 0; i < models_count; i++) {
|
||||
submenu_add_item(submenu, models[i].name, i + 1, model_callback, ctx);
|
||||
if(!found && cfg->model == models[i].value) {
|
||||
if(!found && _cfg->mode == ProtocolModeValue && cfg->model == models[i].value) {
|
||||
found = true;
|
||||
selected = i + 1;
|
||||
}
|
||||
}
|
||||
submenu_add_item(submenu, "Custom", models_count + 1, model_callback, ctx);
|
||||
if(!found) {
|
||||
found = true;
|
||||
if(!found && _cfg->mode == ProtocolModeValue) {
|
||||
selected = models_count + 1;
|
||||
}
|
||||
|
||||
@@ -223,7 +236,9 @@ void scene_fastpair_model_on_exit(void* _ctx) {
|
||||
|
||||
static void model_custom_callback(void* _ctx) {
|
||||
Ctx* ctx = _ctx;
|
||||
FastpairCfg* cfg = &ctx->attack->payload.cfg.fastpair;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
FastpairCfg* cfg = &_cfg->specific.fastpair;
|
||||
_cfg->mode = ProtocolModeValue;
|
||||
cfg->model =
|
||||
(ctx->byte_store[0] << 0x10) + (ctx->byte_store[1] << 0x08) + (ctx->byte_store[2] << 0x00);
|
||||
scene_manager_previous_scene(ctx->scene_manager);
|
||||
@@ -231,7 +246,8 @@ static void model_custom_callback(void* _ctx) {
|
||||
}
|
||||
void scene_fastpair_model_custom_on_enter(void* _ctx) {
|
||||
Ctx* ctx = _ctx;
|
||||
FastpairCfg* cfg = &ctx->attack->payload.cfg.fastpair;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
FastpairCfg* cfg = &_cfg->specific.fastpair;
|
||||
ByteInput* byte_input = ctx->byte_input;
|
||||
|
||||
byte_input_set_header_text(byte_input, "Enter custom Model Code");
|
||||
|
||||
@@ -4,27 +4,33 @@
|
||||
// Hacked together by @Willy-JL and @Spooks4576
|
||||
// Documentation at https://learn.microsoft.com/en-us/windows-hardware/design/component-guidelines/bluetooth-swift-pair
|
||||
|
||||
const char* names[] = {
|
||||
"Assquach💦",
|
||||
"Flipper 🐬",
|
||||
"iOS 17 🍎",
|
||||
"Kink💦",
|
||||
"👉👌",
|
||||
"🔵🦷",
|
||||
};
|
||||
const uint8_t names_count = COUNT_OF(names);
|
||||
|
||||
static const char* get_name(const ProtocolCfg* _cfg) {
|
||||
UNUSED(_cfg);
|
||||
return "SwiftPair";
|
||||
}
|
||||
|
||||
static void make_packet(uint8_t* _size, uint8_t** _packet, const ProtocolCfg* _cfg) {
|
||||
const SwiftpairCfg* cfg = _cfg ? &_cfg->swiftpair : NULL;
|
||||
static void make_packet(uint8_t* _size, uint8_t** _packet, ProtocolCfg* _cfg) {
|
||||
SwiftpairCfg* cfg = _cfg ? &_cfg->specific.swiftpair : NULL;
|
||||
|
||||
const char* name;
|
||||
if(cfg && cfg->name[0] != '\0') {
|
||||
switch(cfg ? _cfg->mode : ProtocolModeRandom) {
|
||||
case ProtocolModeRandom:
|
||||
default:
|
||||
name = names[rand() % names_count];
|
||||
break;
|
||||
case ProtocolModeValue:
|
||||
name = cfg->name;
|
||||
} else {
|
||||
const char* names[] = {
|
||||
"Assquach💦",
|
||||
"Flipper 🐬",
|
||||
"iOS 17 🍎",
|
||||
"Kink💦",
|
||||
"👉👌",
|
||||
"🔵🦷",
|
||||
};
|
||||
name = names[rand() % COUNT_OF(names)];
|
||||
break;
|
||||
}
|
||||
uint8_t name_len = strlen(name);
|
||||
|
||||
@@ -67,12 +73,14 @@ static void config_callback(void* _ctx, uint32_t index) {
|
||||
}
|
||||
}
|
||||
static void extra_config(Ctx* ctx) {
|
||||
SwiftpairCfg* cfg = &ctx->attack->payload.cfg.swiftpair;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
SwiftpairCfg* cfg = &_cfg->specific.swiftpair;
|
||||
VariableItemList* list = ctx->variable_item_list;
|
||||
VariableItem* item;
|
||||
|
||||
item = variable_item_list_add(list, "Display Name", 0, NULL, NULL);
|
||||
variable_item_set_current_value_text(item, cfg->name[0] != '\0' ? cfg->name : "Random");
|
||||
variable_item_set_current_value_text(
|
||||
item, _cfg->mode == ProtocolModeRandom ? "Random" : cfg->name);
|
||||
|
||||
variable_item_list_add(list, "Requires enabling SwiftPair", 0, NULL, NULL);
|
||||
|
||||
@@ -94,15 +102,18 @@ const Protocol protocol_swiftpair = {
|
||||
|
||||
static void name_callback(void* _ctx) {
|
||||
Ctx* ctx = _ctx;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
_cfg->mode = ProtocolModeValue;
|
||||
scene_manager_previous_scene(ctx->scene_manager);
|
||||
}
|
||||
void scene_swiftpair_name_on_enter(void* _ctx) {
|
||||
Ctx* ctx = _ctx;
|
||||
SwiftpairCfg* cfg = &ctx->attack->payload.cfg.swiftpair;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
SwiftpairCfg* cfg = &_cfg->specific.swiftpair;
|
||||
TextInput* text_input = ctx->text_input;
|
||||
text_input_reset(text_input);
|
||||
|
||||
text_input_set_header_text(text_input, "Leave empty for random");
|
||||
text_input_set_header_text(text_input, "Press back for random");
|
||||
|
||||
text_input_set_result_callback(
|
||||
text_input, name_callback, ctx, cfg->name, sizeof(cfg->name), true);
|
||||
@@ -112,8 +123,11 @@ void scene_swiftpair_name_on_enter(void* _ctx) {
|
||||
view_dispatcher_switch_to_view(ctx->view_dispatcher, ViewTextInput);
|
||||
}
|
||||
bool scene_swiftpair_name_on_event(void* _ctx, SceneManagerEvent event) {
|
||||
UNUSED(_ctx);
|
||||
UNUSED(event);
|
||||
Ctx* ctx = _ctx;
|
||||
ProtocolCfg* _cfg = &ctx->attack->payload.cfg;
|
||||
if(event.type == SceneManagerEventTypeBack) {
|
||||
_cfg->mode = ProtocolModeRandom;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
void scene_swiftpair_name_on_exit(void* _ctx) {
|
||||
|
||||
Reference in New Issue
Block a user