Refactor payload config, dont need 2 structs

This commit is contained in:
Willy-JL
2023-10-25 21:43:26 +01:00
parent e4309dcb8a
commit f474e8c7ca
8 changed files with 273 additions and 276 deletions

View File

@@ -30,7 +30,7 @@ static Attack attacks[] = {
.payload = .payload =
{ {
.random_mac = false, .random_mac = false,
.cfg.specific.continuity = .cfg.continuity =
{ {
.type = ContinuityTypeCustomCrash, .type = ContinuityTypeCustomCrash,
.data = {}, .data = {},
@@ -44,7 +44,7 @@ static Attack attacks[] = {
.payload = .payload =
{ {
.random_mac = false, .random_mac = false,
.cfg.specific.continuity = .cfg.continuity =
{ {
.type = ContinuityTypeNearbyAction, .type = ContinuityTypeNearbyAction,
.data = {}, .data = {},
@@ -58,7 +58,7 @@ static Attack attacks[] = {
.payload = .payload =
{ {
.random_mac = false, .random_mac = false,
.cfg.specific.continuity = .cfg.continuity =
{ {
.type = ContinuityTypeProximityPair, .type = ContinuityTypeProximityPair,
.data = {}, .data = {},
@@ -72,7 +72,7 @@ static Attack attacks[] = {
.payload = .payload =
{ {
.random_mac = true, .random_mac = true,
.cfg.specific.fastpair = {}, .cfg.fastpair = {},
}, },
}, },
{ {
@@ -82,7 +82,7 @@ static Attack attacks[] = {
.payload = .payload =
{ {
.random_mac = true, .random_mac = true,
.cfg.specific.easysetup = .cfg.easysetup =
{ {
.type = EasysetupTypeBuds, .type = EasysetupTypeBuds,
.data = {}, .data = {},
@@ -96,7 +96,7 @@ static Attack attacks[] = {
.payload = .payload =
{ {
.random_mac = true, .random_mac = true,
.cfg.specific.easysetup = .cfg.easysetup =
{ {
.type = EasysetupTypeWatch, .type = EasysetupTypeWatch,
.data = {}, .data = {},
@@ -110,7 +110,7 @@ static Attack attacks[] = {
.payload = .payload =
{ {
.random_mac = true, .random_mac = true,
.cfg.specific.swiftpair = {}, .cfg.swiftpair = {},
}, },
}, },
}; };
@@ -171,18 +171,17 @@ static int32_t adv_thread(void* _ctx) {
uint8_t mac[GAP_MAC_ADDR_SIZE]; uint8_t mac[GAP_MAC_ADDR_SIZE];
Payload* payload = &attacks[state->index].payload; Payload* payload = &attacks[state->index].payload;
const Protocol* protocol = attacks[state->index].protocol; const Protocol* protocol = attacks[state->index].protocol;
ProtocolCfg* _cfg = &payload->cfg;
if(!payload->random_mac) furi_hal_random_fill_buf(mac, sizeof(mac)); if(!payload->random_mac) furi_hal_random_fill_buf(mac, sizeof(mac));
if(state->ctx.led_indicator) start_blink(state); if(state->ctx.led_indicator) start_blink(state);
while(state->advertising) { while(state->advertising) {
if(protocol) { if(protocol) {
if(_cfg->mode == ProtocolModeBruteforce && _cfg->bruteforce.counter++ >= 10) { if(payload->mode == PayloadModeBruteforce && payload->bruteforce.counter++ >= 10) {
_cfg->bruteforce.counter = 0; payload->bruteforce.counter = 0;
_cfg->bruteforce.value = payload->bruteforce.value =
(_cfg->bruteforce.value + 1) % (1 << (_cfg->bruteforce.size * 8)); (payload->bruteforce.value + 1) % (1 << (payload->bruteforce.size * 8));
} }
protocol->make_packet(&size, &packet, &payload->cfg); protocol->make_packet(&size, &packet, payload);
} else { } else {
protocols[rand() % protocols_count]->make_packet(&size, &packet, NULL); protocols[rand() % protocols_count]->make_packet(&size, &packet, NULL);
} }
@@ -367,13 +366,13 @@ static void draw_callback(Canvas* canvas, void* _ctx) {
char str[32]; char str[32];
canvas_set_font(canvas, FontBatteryPercent); canvas_set_font(canvas, FontBatteryPercent);
if(payload->cfg.mode == ProtocolModeBruteforce) { if(payload->mode == PayloadModeBruteforce) {
snprintf( snprintf(
str, str,
sizeof(str), sizeof(str),
"0x%0*lX", "0x%0*lX",
payload->cfg.bruteforce.size * 2, payload->bruteforce.size * 2,
payload->cfg.bruteforce.value); payload->bruteforce.value);
} else { } else {
snprintf(str, sizeof(str), "%ims", delays[state->delay]); snprintf(str, sizeof(str), "%ims", delays[state->delay]);
} }
@@ -382,7 +381,7 @@ static void draw_callback(Canvas* canvas, void* _ctx) {
canvas_draw_icon(canvas, 119, 10, &I_SmallArrowDown_3x5); canvas_draw_icon(canvas, 119, 10, &I_SmallArrowDown_3x5);
canvas_set_font(canvas, FontBatteryPercent); canvas_set_font(canvas, FontBatteryPercent);
if(payload->cfg.mode == ProtocolModeBruteforce) { if(payload->mode == PayloadModeBruteforce) {
canvas_draw_str_aligned(canvas, 64, 22, AlignCenter, AlignBottom, "Bruteforce"); canvas_draw_str_aligned(canvas, 64, 22, AlignCenter, AlignBottom, "Bruteforce");
if(delays[state->delay] < 100) { if(delays[state->delay] < 100) {
snprintf(str, sizeof(str), "%ims>", delays[state->delay]); snprintf(str, sizeof(str), "%ims>", delays[state->delay]);
@@ -403,7 +402,7 @@ static void draw_callback(Canvas* canvas, void* _ctx) {
"%02i/%02i: %s", "%02i/%02i: %s",
state->index + 1, state->index + 1,
ATTACKS_COUNT, ATTACKS_COUNT,
protocol ? protocol->get_name(&payload->cfg) : "Everything AND"); protocol ? protocol->get_name(payload) : "Everything AND");
canvas_draw_str(canvas, 4 - (state->index < 19 ? 1 : 0), 22, str); canvas_draw_str(canvas, 4 - (state->index < 19 ? 1 : 0), 22, str);
} }
@@ -461,7 +460,7 @@ static bool input_callback(InputEvent* input, void* _ctx) {
consumed = true; consumed = true;
bool is_attack = state->index >= 0 && state->index <= ATTACKS_COUNT - 1; bool is_attack = state->index >= 0 && state->index <= ATTACKS_COUNT - 1;
ProtocolCfg* _cfg = is_attack ? &attacks[state->index].payload.cfg : NULL; Payload* payload = is_attack ? &attacks[state->index].payload : NULL;
bool advertising = state->advertising; bool advertising = state->advertising;
switch(input->key) { switch(input->key) {
@@ -479,10 +478,10 @@ static bool input_callback(InputEvent* input, void* _ctx) {
break; break;
case InputKeyUp: case InputKeyUp:
if(is_attack) { if(is_attack) {
if(_cfg->mode == ProtocolModeBruteforce) { if(payload->mode == PayloadModeBruteforce) {
_cfg->bruteforce.counter = 0; payload->bruteforce.counter = 0;
_cfg->bruteforce.value = payload->bruteforce.value =
(_cfg->bruteforce.value + 1) % (1 << (_cfg->bruteforce.size * 8)); (payload->bruteforce.value + 1) % (1 << (payload->bruteforce.size * 8));
} else if(state->delay < COUNT_OF(delays) - 1) { } else if(state->delay < COUNT_OF(delays) - 1) {
state->delay++; state->delay++;
if(advertising) start_blink(state); if(advertising) start_blink(state);
@@ -491,10 +490,10 @@ static bool input_callback(InputEvent* input, void* _ctx) {
break; break;
case InputKeyDown: case InputKeyDown:
if(is_attack) { if(is_attack) {
if(_cfg->mode == ProtocolModeBruteforce) { if(payload->mode == PayloadModeBruteforce) {
_cfg->bruteforce.counter = 0; payload->bruteforce.counter = 0;
_cfg->bruteforce.value = payload->bruteforce.value =
(_cfg->bruteforce.value - 1) % (1 << (_cfg->bruteforce.size * 8)); (payload->bruteforce.value - 1) % (1 << (payload->bruteforce.size * 8));
} else if(state->delay > 0) { } else if(state->delay > 0) {
state->delay--; state->delay--;
if(advertising) start_blink(state); if(advertising) start_blink(state);
@@ -503,10 +502,11 @@ static bool input_callback(InputEvent* input, void* _ctx) {
break; break;
case InputKeyLeft: case InputKeyLeft:
if(input->type == InputTypeLong) { if(input->type == InputTypeLong) {
state->ignore_bruteforce = _cfg ? (_cfg->mode != ProtocolModeBruteforce) : true; state->ignore_bruteforce = payload ? (payload->mode != PayloadModeBruteforce) :
true;
} }
if(input->type == InputTypeShort || !is_attack || state->ignore_bruteforce || if(input->type == InputTypeShort || !is_attack || state->ignore_bruteforce ||
_cfg->mode != ProtocolModeBruteforce) { payload->mode != PayloadModeBruteforce) {
if(state->index > PAGE_MIN) { if(state->index > PAGE_MIN) {
if(advertising) toggle_adv(state); if(advertising) toggle_adv(state);
state->index--; state->index--;
@@ -520,7 +520,7 @@ static bool input_callback(InputEvent* input, void* _ctx) {
uint8_t size; uint8_t size;
uint8_t* packet; uint8_t* packet;
protocol->make_packet(&size, &packet, &payload->cfg); protocol->make_packet(&size, &packet, payload);
furi_hal_bt_custom_adv_set(packet, size); furi_hal_bt_custom_adv_set(packet, size);
free(packet); free(packet);
@@ -541,10 +541,11 @@ static bool input_callback(InputEvent* input, void* _ctx) {
break; break;
case InputKeyRight: case InputKeyRight:
if(input->type == InputTypeLong) { if(input->type == InputTypeLong) {
state->ignore_bruteforce = _cfg ? (_cfg->mode != ProtocolModeBruteforce) : true; state->ignore_bruteforce = payload ? (payload->mode != PayloadModeBruteforce) :
true;
} }
if(input->type == InputTypeShort || !is_attack || state->ignore_bruteforce || if(input->type == InputTypeShort || !is_attack || state->ignore_bruteforce ||
_cfg->mode != ProtocolModeBruteforce) { payload->mode != PayloadModeBruteforce) {
if(state->index < PAGE_MAX) { if(state->index < PAGE_MAX) {
if(advertising) toggle_adv(state); if(advertising) toggle_adv(state);
state->index++; state->index++;

View File

@@ -10,12 +10,12 @@
#include <core/core_defines.h> #include <core/core_defines.h>
#include "../ble_spam.h" #include "../ble_spam.h"
typedef struct ProtocolCfg ProtocolCfg; typedef struct Payload Payload;
typedef struct { typedef struct {
const Icon* icon; const Icon* icon;
const char* (*get_name)(const ProtocolCfg* _cfg); const char* (*get_name)(const Payload* payload);
void (*make_packet)(uint8_t* _size, uint8_t** _packet, ProtocolCfg* _cfg); void (*make_packet)(uint8_t* _size, uint8_t** _packet, Payload* payload);
void (*extra_config)(Ctx* ctx); void (*extra_config)(Ctx* ctx);
uint8_t (*config_count)(const ProtocolCfg* _cfg); uint8_t (*config_count)(const Payload* payload);
} Protocol; } Protocol;

View File

@@ -6,13 +6,14 @@
#include "swiftpair.h" #include "swiftpair.h"
typedef enum { typedef enum {
ProtocolModeRandom, PayloadModeRandom,
ProtocolModeValue, PayloadModeValue,
ProtocolModeBruteforce, PayloadModeBruteforce,
} ProtocolMode; } PayloadMode;
struct ProtocolCfg { struct Payload {
ProtocolMode mode; bool random_mac;
PayloadMode mode;
struct { struct {
uint8_t counter; uint8_t counter;
uint32_t value; uint32_t value;
@@ -23,18 +24,13 @@ struct ProtocolCfg {
FastpairCfg fastpair; FastpairCfg fastpair;
EasysetupCfg easysetup; EasysetupCfg easysetup;
SwiftpairCfg swiftpair; SwiftpairCfg swiftpair;
} specific; } cfg;
}; };
extern const Protocol* protocols[]; extern const Protocol* protocols[];
extern const size_t protocols_count; extern const size_t protocols_count;
typedef struct {
bool random_mac;
ProtocolCfg cfg;
} Payload;
struct Attack { struct Attack {
const char* title; const char* title;
const char* text; const char* text;

View File

@@ -71,8 +71,8 @@ static const char* type_names[ContinuityTypeCOUNT] = {
[ContinuityTypeNearbyInfo] = "Nearby Info", [ContinuityTypeNearbyInfo] = "Nearby Info",
[ContinuityTypeCustomCrash] = "Continuity Custom", [ContinuityTypeCustomCrash] = "Continuity Custom",
}; };
static const char* get_name(const ProtocolCfg* _cfg) { static const char* get_name(const Payload* payload) {
const ContinuityCfg* cfg = &_cfg->specific.continuity; const ContinuityCfg* cfg = &payload->cfg.continuity;
return type_names[cfg->type]; return type_names[cfg->type];
} }
@@ -87,8 +87,8 @@ static uint8_t packet_sizes[ContinuityTypeCOUNT] = {
[ContinuityTypeNearbyInfo] = HEADER_LEN + 5, [ContinuityTypeNearbyInfo] = HEADER_LEN + 5,
[ContinuityTypeCustomCrash] = HEADER_LEN + 11, [ContinuityTypeCustomCrash] = HEADER_LEN + 11,
}; };
static void make_packet(uint8_t* _size, uint8_t** _packet, ProtocolCfg* _cfg) { static void make_packet(uint8_t* _size, uint8_t** _packet, Payload* payload) {
ContinuityCfg* cfg = _cfg ? &_cfg->specific.continuity : NULL; ContinuityCfg* cfg = payload ? &payload->cfg.continuity : NULL;
ContinuityType type; ContinuityType type;
if(cfg && cfg->type != 0x00) { if(cfg && cfg->type != 0x00) {
@@ -139,16 +139,16 @@ static void make_packet(uint8_t* _size, uint8_t** _packet, ProtocolCfg* _cfg) {
case ContinuityTypeProximityPair: { case ContinuityTypeProximityPair: {
uint16_t model; uint16_t model;
switch(cfg ? _cfg->mode : ProtocolModeRandom) { switch(payload ? payload->mode : PayloadModeRandom) {
case ProtocolModeRandom: case PayloadModeRandom:
default: default:
model = pp_models[rand() % pp_models_count].value; model = pp_models[rand() % pp_models_count].value;
break; break;
case ProtocolModeValue: case PayloadModeValue:
model = cfg->data.proximity_pair.model; model = cfg->data.proximity_pair.model;
break; break;
case ProtocolModeBruteforce: case PayloadModeBruteforce:
model = cfg->data.proximity_pair.model = _cfg->bruteforce.value; model = cfg->data.proximity_pair.model = payload->bruteforce.value;
break; break;
} }
@@ -216,16 +216,16 @@ static void make_packet(uint8_t* _size, uint8_t** _packet, ProtocolCfg* _cfg) {
case ContinuityTypeNearbyAction: { case ContinuityTypeNearbyAction: {
uint8_t action; uint8_t action;
switch(cfg ? _cfg->mode : ProtocolModeRandom) { switch(payload ? payload->mode : PayloadModeRandom) {
case ProtocolModeRandom: case PayloadModeRandom:
default: default:
action = na_actions[rand() % na_actions_count].value; action = na_actions[rand() % na_actions_count].value;
break; break;
case ProtocolModeValue: case PayloadModeValue:
action = cfg->data.nearby_action.action; action = cfg->data.nearby_action.action;
break; break;
case ProtocolModeBruteforce: case PayloadModeBruteforce:
action = cfg->data.nearby_action.action = _cfg->bruteforce.value; action = cfg->data.nearby_action.action = payload->bruteforce.value;
break; break;
} }
@@ -307,8 +307,8 @@ enum {
}; };
static void config_callback(void* _ctx, uint32_t index) { static void config_callback(void* _ctx, uint32_t index) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg; Payload* payload = &ctx->attack->payload;
ContinuityCfg* cfg = &_cfg->specific.continuity; ContinuityCfg* cfg = &payload->cfg.continuity;
scene_manager_set_scene_state(ctx->scene_manager, SceneConfig, index); scene_manager_set_scene_state(ctx->scene_manager, SceneConfig, index);
switch(cfg->type) { switch(cfg->type) {
case ContinuityTypeProximityPair: { case ContinuityTypeProximityPair: {
@@ -356,22 +356,22 @@ static void config_callback(void* _ctx, uint32_t index) {
} }
} }
static void pp_model_changed(VariableItem* item) { static void pp_model_changed(VariableItem* item) {
ProtocolCfg* _cfg = variable_item_get_context(item); Payload* payload = variable_item_get_context(item);
ContinuityCfg* cfg = &_cfg->specific.continuity; ContinuityCfg* cfg = &payload->cfg.continuity;
uint8_t index = variable_item_get_current_value_index(item); uint8_t index = variable_item_get_current_value_index(item);
if(index) { if(index) {
index--; index--;
_cfg->mode = ProtocolModeValue; payload->mode = PayloadModeValue;
cfg->data.proximity_pair.model = pp_models[index].value; cfg->data.proximity_pair.model = pp_models[index].value;
variable_item_set_current_value_text(item, pp_models[index].name); variable_item_set_current_value_text(item, pp_models[index].name);
} else { } else {
_cfg->mode = ProtocolModeRandom; payload->mode = PayloadModeRandom;
variable_item_set_current_value_text(item, "Random"); variable_item_set_current_value_text(item, "Random");
} }
} }
static void pp_prefix_changed(VariableItem* item) { static void pp_prefix_changed(VariableItem* item) {
ProtocolCfg* _cfg = variable_item_get_context(item); Payload* payload = variable_item_get_context(item);
ContinuityCfg* cfg = &_cfg->specific.continuity; ContinuityCfg* cfg = &payload->cfg.continuity;
uint8_t index = variable_item_get_current_value_index(item); uint8_t index = variable_item_get_current_value_index(item);
if(index) { if(index) {
index--; index--;
@@ -383,22 +383,22 @@ static void pp_prefix_changed(VariableItem* item) {
} }
} }
static void na_action_changed(VariableItem* item) { static void na_action_changed(VariableItem* item) {
ProtocolCfg* _cfg = variable_item_get_context(item); Payload* payload = variable_item_get_context(item);
ContinuityCfg* cfg = &_cfg->specific.continuity; ContinuityCfg* cfg = &payload->cfg.continuity;
uint8_t index = variable_item_get_current_value_index(item); uint8_t index = variable_item_get_current_value_index(item);
if(index) { if(index) {
index--; index--;
_cfg->mode = ProtocolModeValue; payload->mode = PayloadModeValue;
cfg->data.nearby_action.action = na_actions[index].value; cfg->data.nearby_action.action = na_actions[index].value;
variable_item_set_current_value_text(item, na_actions[index].name); variable_item_set_current_value_text(item, na_actions[index].name);
} else { } else {
_cfg->mode = ProtocolModeRandom; payload->mode = PayloadModeRandom;
variable_item_set_current_value_text(item, "Random"); variable_item_set_current_value_text(item, "Random");
} }
} }
static void extra_config(Ctx* ctx) { static void extra_config(Ctx* ctx) {
ProtocolCfg* _cfg = &ctx->attack->payload.cfg; Payload* payload = &ctx->attack->payload;
ContinuityCfg* cfg = &_cfg->specific.continuity; ContinuityCfg* cfg = &payload->cfg.continuity;
VariableItemList* list = ctx->variable_item_list; VariableItemList* list = ctx->variable_item_list;
VariableItem* item; VariableItem* item;
size_t value_index; size_t value_index;
@@ -406,16 +406,16 @@ static void extra_config(Ctx* ctx) {
switch(cfg->type) { switch(cfg->type) {
case ContinuityTypeProximityPair: { case ContinuityTypeProximityPair: {
item = variable_item_list_add( item = variable_item_list_add(
list, "Model Code", pp_models_count + 1, pp_model_changed, _cfg); list, "Model Code", pp_models_count + 1, pp_model_changed, payload);
const char* model_name = NULL; const char* model_name = NULL;
char model_name_buf[5]; char model_name_buf[5];
switch(_cfg->mode) { switch(payload->mode) {
case ProtocolModeRandom: case PayloadModeRandom:
default: default:
model_name = "Random"; model_name = "Random";
value_index = 0; value_index = 0;
break; break;
case ProtocolModeValue: case PayloadModeValue:
for(uint8_t i = 0; i < pp_models_count; i++) { for(uint8_t i = 0; i < pp_models_count; i++) {
if(cfg->data.proximity_pair.model == pp_models[i].value) { if(cfg->data.proximity_pair.model == pp_models[i].value) {
model_name = pp_models[i].name; model_name = pp_models[i].name;
@@ -430,7 +430,7 @@ static void extra_config(Ctx* ctx) {
value_index = pp_models_count + 1; value_index = pp_models_count + 1;
} }
break; break;
case ProtocolModeBruteforce: case PayloadModeBruteforce:
model_name = "Bruteforce"; model_name = "Bruteforce";
value_index = pp_models_count + 1; value_index = pp_models_count + 1;
break; break;
@@ -438,8 +438,8 @@ static void extra_config(Ctx* ctx) {
variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, model_name); variable_item_set_current_value_text(item, model_name);
item = item = variable_item_list_add(
variable_item_list_add(list, "Prefix", pp_prefixes_count + 1, pp_prefix_changed, _cfg); list, "Prefix", pp_prefixes_count + 1, pp_prefix_changed, payload);
const char* prefix_name = NULL; const char* prefix_name = NULL;
char prefix_name_buf[3]; char prefix_name_buf[3];
if(cfg->data.proximity_pair.prefix == 0x00) { if(cfg->data.proximity_pair.prefix == 0x00) {
@@ -469,16 +469,16 @@ static void extra_config(Ctx* ctx) {
} }
case ContinuityTypeNearbyAction: { case ContinuityTypeNearbyAction: {
item = variable_item_list_add( 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, payload);
const char* action_name = NULL; const char* action_name = NULL;
char action_name_buf[3]; char action_name_buf[3];
switch(_cfg->mode) { switch(payload->mode) {
case ProtocolModeRandom: case PayloadModeRandom:
default: default:
action_name = "Random"; action_name = "Random";
value_index = 0; value_index = 0;
break; break;
case ProtocolModeValue: case PayloadModeValue:
for(uint8_t i = 0; i < na_actions_count; i++) { for(uint8_t i = 0; i < na_actions_count; i++) {
if(cfg->data.nearby_action.action == na_actions[i].value) { if(cfg->data.nearby_action.action == na_actions[i].value) {
action_name = na_actions[i].name; action_name = na_actions[i].name;
@@ -496,7 +496,7 @@ static void extra_config(Ctx* ctx) {
value_index = na_actions_count + 1; value_index = na_actions_count + 1;
} }
break; break;
case ProtocolModeBruteforce: case PayloadModeBruteforce:
action_name = "Bruteforce"; action_name = "Bruteforce";
value_index = na_actions_count + 1; value_index = na_actions_count + 1;
break; break;
@@ -539,8 +539,8 @@ static uint8_t config_counts[ContinuityTypeCOUNT] = {
[ContinuityTypeNearbyInfo] = 0, [ContinuityTypeNearbyInfo] = 0,
[ContinuityTypeCustomCrash] = ConfigCcCOUNT - ConfigExtraStart - 1, [ContinuityTypeCustomCrash] = ConfigCcCOUNT - ConfigExtraStart - 1,
}; };
static uint8_t config_count(const ProtocolCfg* _cfg) { static uint8_t config_count(const Payload* payload) {
const ContinuityCfg* cfg = &_cfg->specific.continuity; const ContinuityCfg* cfg = &payload->cfg.continuity;
return config_counts[cfg->type]; return config_counts[cfg->type];
} }
@@ -554,25 +554,25 @@ const Protocol protocol_continuity = {
static void pp_model_callback(void* _ctx, uint32_t index) { static void pp_model_callback(void* _ctx, uint32_t index) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg; Payload* payload = &ctx->attack->payload;
ContinuityCfg* cfg = &_cfg->specific.continuity; ContinuityCfg* cfg = &payload->cfg.continuity;
switch(index) { switch(index) {
case 0: case 0:
_cfg->mode = ProtocolModeRandom; payload->mode = PayloadModeRandom;
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
break; break;
case pp_models_count + 1: case pp_models_count + 1:
scene_manager_next_scene(ctx->scene_manager, SceneContinuityPpModelCustom); scene_manager_next_scene(ctx->scene_manager, SceneContinuityPpModelCustom);
break; break;
case pp_models_count + 2: case pp_models_count + 2:
_cfg->mode = ProtocolModeBruteforce; payload->mode = PayloadModeBruteforce;
_cfg->bruteforce.counter = 0; payload->bruteforce.counter = 0;
_cfg->bruteforce.value = cfg->data.proximity_pair.model; payload->bruteforce.value = cfg->data.proximity_pair.model;
_cfg->bruteforce.size = 2; payload->bruteforce.size = 2;
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
break; break;
default: default:
_cfg->mode = ProtocolModeValue; payload->mode = PayloadModeValue;
cfg->data.proximity_pair.model = pp_models[index - 1].value; cfg->data.proximity_pair.model = pp_models[index - 1].value;
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
break; break;
@@ -580,33 +580,33 @@ static void pp_model_callback(void* _ctx, uint32_t index) {
} }
void scene_continuity_pp_model_on_enter(void* _ctx) { void scene_continuity_pp_model_on_enter(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg; Payload* payload = &ctx->attack->payload;
ContinuityCfg* cfg = &_cfg->specific.continuity; ContinuityCfg* cfg = &payload->cfg.continuity;
Submenu* submenu = ctx->submenu; Submenu* submenu = ctx->submenu;
uint32_t selected = 0; uint32_t selected = 0;
submenu_reset(submenu); submenu_reset(submenu);
submenu_add_item(submenu, "Random", 0, pp_model_callback, ctx); submenu_add_item(submenu, "Random", 0, pp_model_callback, ctx);
if(_cfg->mode == ProtocolModeRandom) { if(payload->mode == PayloadModeRandom) {
selected = 0; selected = 0;
} }
bool found = false; bool found = false;
for(uint8_t i = 0; i < pp_models_count; i++) { for(uint8_t i = 0; i < pp_models_count; i++) {
submenu_add_item(submenu, pp_models[i].name, i + 1, pp_model_callback, ctx); submenu_add_item(submenu, pp_models[i].name, i + 1, pp_model_callback, ctx);
if(!found && _cfg->mode == ProtocolModeValue && if(!found && payload->mode == PayloadModeValue &&
cfg->data.proximity_pair.model == pp_models[i].value) { cfg->data.proximity_pair.model == pp_models[i].value) {
found = true; found = true;
selected = i + 1; selected = i + 1;
} }
} }
submenu_add_item(submenu, "Custom", pp_models_count + 1, pp_model_callback, ctx); submenu_add_item(submenu, "Custom", pp_models_count + 1, pp_model_callback, ctx);
if(!found && _cfg->mode == ProtocolModeValue) { if(!found && payload->mode == PayloadModeValue) {
selected = pp_models_count + 1; selected = pp_models_count + 1;
} }
submenu_add_item(submenu, "Bruteforce", pp_models_count + 2, pp_model_callback, ctx); submenu_add_item(submenu, "Bruteforce", pp_models_count + 2, pp_model_callback, ctx);
if(_cfg->mode == ProtocolModeBruteforce) { if(payload->mode == PayloadModeBruteforce) {
selected = pp_models_count + 2; selected = pp_models_count + 2;
} }
@@ -625,17 +625,17 @@ void scene_continuity_pp_model_on_exit(void* _ctx) {
static void pp_model_custom_callback(void* _ctx) { static void pp_model_custom_callback(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg; Payload* payload = &ctx->attack->payload;
ContinuityCfg* cfg = &_cfg->specific.continuity; ContinuityCfg* cfg = &payload->cfg.continuity;
_cfg->mode = ProtocolModeValue; payload->mode = PayloadModeValue;
cfg->data.proximity_pair.model = (ctx->byte_store[0] << 0x08) + (ctx->byte_store[1] << 0x00); 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);
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
} }
void scene_continuity_pp_model_custom_on_enter(void* _ctx) { void scene_continuity_pp_model_custom_on_enter(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg; Payload* payload = &ctx->attack->payload;
ContinuityCfg* cfg = &_cfg->specific.continuity; ContinuityCfg* cfg = &payload->cfg.continuity;
ByteInput* byte_input = ctx->byte_input; ByteInput* byte_input = ctx->byte_input;
byte_input_set_header_text(byte_input, "Enter custom Model Code"); byte_input_set_header_text(byte_input, "Enter custom Model Code");
@@ -659,8 +659,8 @@ void scene_continuity_pp_model_custom_on_exit(void* _ctx) {
static void pp_prefix_callback(void* _ctx, uint32_t index) { static void pp_prefix_callback(void* _ctx, uint32_t index) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg; Payload* payload = &ctx->attack->payload;
ContinuityCfg* cfg = &_cfg->specific.continuity; ContinuityCfg* cfg = &payload->cfg.continuity;
switch(index) { switch(index) {
case 0: case 0:
cfg->data.proximity_pair.prefix = 0x00; cfg->data.proximity_pair.prefix = 0x00;
@@ -677,8 +677,8 @@ static void pp_prefix_callback(void* _ctx, uint32_t index) {
} }
void scene_continuity_pp_prefix_on_enter(void* _ctx) { void scene_continuity_pp_prefix_on_enter(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg; Payload* payload = &ctx->attack->payload;
ContinuityCfg* cfg = &_cfg->specific.continuity; ContinuityCfg* cfg = &payload->cfg.continuity;
Submenu* submenu = ctx->submenu; Submenu* submenu = ctx->submenu;
uint32_t selected = 0; uint32_t selected = 0;
bool found = false; bool found = false;
@@ -717,16 +717,16 @@ void scene_continuity_pp_prefix_on_exit(void* _ctx) {
static void pp_prefix_custom_callback(void* _ctx) { static void pp_prefix_custom_callback(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg; Payload* payload = &ctx->attack->payload;
ContinuityCfg* cfg = &_cfg->specific.continuity; ContinuityCfg* cfg = &payload->cfg.continuity;
cfg->data.proximity_pair.prefix = (ctx->byte_store[0] << 0x00); cfg->data.proximity_pair.prefix = (ctx->byte_store[0] << 0x00);
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
} }
void scene_continuity_pp_prefix_custom_on_enter(void* _ctx) { void scene_continuity_pp_prefix_custom_on_enter(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg; Payload* payload = &ctx->attack->payload;
ContinuityCfg* cfg = &_cfg->specific.continuity; ContinuityCfg* cfg = &payload->cfg.continuity;
ByteInput* byte_input = ctx->byte_input; ByteInput* byte_input = ctx->byte_input;
byte_input_set_header_text(byte_input, "Enter custom Prefix"); byte_input_set_header_text(byte_input, "Enter custom Prefix");
@@ -749,25 +749,25 @@ void scene_continuity_pp_prefix_custom_on_exit(void* _ctx) {
static void na_action_callback(void* _ctx, uint32_t index) { static void na_action_callback(void* _ctx, uint32_t index) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg; Payload* payload = &ctx->attack->payload;
ContinuityCfg* cfg = &_cfg->specific.continuity; ContinuityCfg* cfg = &payload->cfg.continuity;
switch(index) { switch(index) {
case 0: case 0:
_cfg->mode = ProtocolModeRandom; payload->mode = PayloadModeRandom;
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
break; break;
case na_actions_count + 1: case na_actions_count + 1:
scene_manager_next_scene(ctx->scene_manager, SceneContinuityNaActionCustom); scene_manager_next_scene(ctx->scene_manager, SceneContinuityNaActionCustom);
break; break;
case na_actions_count + 2: case na_actions_count + 2:
_cfg->mode = ProtocolModeBruteforce; payload->mode = PayloadModeBruteforce;
_cfg->bruteforce.counter = 0; payload->bruteforce.counter = 0;
_cfg->bruteforce.value = cfg->data.nearby_action.action; payload->bruteforce.value = cfg->data.nearby_action.action;
_cfg->bruteforce.size = 1; payload->bruteforce.size = 1;
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
break; break;
default: default:
_cfg->mode = ProtocolModeValue; payload->mode = PayloadModeValue;
cfg->data.nearby_action.action = na_actions[index - 1].value; cfg->data.nearby_action.action = na_actions[index - 1].value;
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
break; break;
@@ -775,33 +775,33 @@ static void na_action_callback(void* _ctx, uint32_t index) {
} }
void scene_continuity_na_action_on_enter(void* _ctx) { void scene_continuity_na_action_on_enter(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg; Payload* payload = &ctx->attack->payload;
ContinuityCfg* cfg = &_cfg->specific.continuity; ContinuityCfg* cfg = &payload->cfg.continuity;
Submenu* submenu = ctx->submenu; Submenu* submenu = ctx->submenu;
uint32_t selected = 0; uint32_t selected = 0;
submenu_reset(submenu); submenu_reset(submenu);
submenu_add_item(submenu, "Random", 0, na_action_callback, ctx); submenu_add_item(submenu, "Random", 0, na_action_callback, ctx);
if(_cfg->mode == ProtocolModeRandom) { if(payload->mode == PayloadModeRandom) {
selected = 0; selected = 0;
} }
bool found = false; bool found = false;
for(uint8_t i = 0; i < na_actions_count; i++) { for(uint8_t i = 0; i < na_actions_count; i++) {
submenu_add_item(submenu, na_actions[i].name, i + 1, na_action_callback, ctx); submenu_add_item(submenu, na_actions[i].name, i + 1, na_action_callback, ctx);
if(!found && _cfg->mode == ProtocolModeValue && if(!found && payload->mode == PayloadModeValue &&
cfg->data.nearby_action.action == na_actions[i].value) { cfg->data.nearby_action.action == na_actions[i].value) {
found = true; found = true;
selected = i + 1; selected = i + 1;
} }
} }
submenu_add_item(submenu, "Custom", na_actions_count + 1, na_action_callback, ctx); submenu_add_item(submenu, "Custom", na_actions_count + 1, na_action_callback, ctx);
if(!found && _cfg->mode == ProtocolModeValue) { if(!found && payload->mode == PayloadModeValue) {
selected = na_actions_count + 1; selected = na_actions_count + 1;
} }
submenu_add_item(submenu, "Bruteforce", na_actions_count + 2, na_action_callback, ctx); submenu_add_item(submenu, "Bruteforce", na_actions_count + 2, na_action_callback, ctx);
if(_cfg->mode == ProtocolModeBruteforce) { if(payload->mode == PayloadModeBruteforce) {
selected = na_actions_count + 2; selected = na_actions_count + 2;
} }
@@ -820,17 +820,17 @@ void scene_continuity_na_action_on_exit(void* _ctx) {
static void na_action_custom_callback(void* _ctx) { static void na_action_custom_callback(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg; Payload* payload = &ctx->attack->payload;
ContinuityCfg* cfg = &_cfg->specific.continuity; ContinuityCfg* cfg = &payload->cfg.continuity;
_cfg->mode = ProtocolModeValue; payload->mode = PayloadModeValue;
cfg->data.nearby_action.action = (ctx->byte_store[0] << 0x00); cfg->data.nearby_action.action = (ctx->byte_store[0] << 0x00);
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
} }
void scene_continuity_na_action_custom_on_enter(void* _ctx) { void scene_continuity_na_action_custom_on_enter(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg; Payload* payload = &ctx->attack->payload;
ContinuityCfg* cfg = &_cfg->specific.continuity; ContinuityCfg* cfg = &payload->cfg.continuity;
ByteInput* byte_input = ctx->byte_input; ByteInput* byte_input = ctx->byte_input;
byte_input_set_header_text(byte_input, "Enter custom Action Type"); byte_input_set_header_text(byte_input, "Enter custom Action Type");
@@ -857,8 +857,8 @@ static void na_flags_callback(void* _ctx) {
} }
void scene_continuity_na_flags_on_enter(void* _ctx) { void scene_continuity_na_flags_on_enter(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg; Payload* payload = &ctx->attack->payload;
ContinuityCfg* cfg = &_cfg->specific.continuity; ContinuityCfg* cfg = &payload->cfg.continuity;
ByteInput* byte_input = ctx->byte_input; ByteInput* byte_input = ctx->byte_input;
byte_input_set_header_text(byte_input, "Press back for automatic"); byte_input_set_header_text(byte_input, "Press back for automatic");
@@ -879,7 +879,7 @@ bool scene_continuity_na_flags_on_event(void* _ctx, SceneManagerEvent event) {
} }
void scene_continuity_na_flags_on_exit(void* _ctx) { void scene_continuity_na_flags_on_exit(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg; Payload* payload = &ctx->attack->payload;
ContinuityCfg* cfg = &_cfg->specific.continuity; ContinuityCfg* cfg = &payload->cfg.continuity;
cfg->data.nearby_action.flags = (ctx->byte_store[0] << 0x00); cfg->data.nearby_action.flags = (ctx->byte_store[0] << 0x00);
} }

View File

@@ -68,8 +68,8 @@ static const char* type_names[EasysetupTypeCOUNT] = {
[EasysetupTypeBuds] = "EasySetup Buds", [EasysetupTypeBuds] = "EasySetup Buds",
[EasysetupTypeWatch] = "EasySetup Watch", [EasysetupTypeWatch] = "EasySetup Watch",
}; };
static const char* get_name(const ProtocolCfg* _cfg) { static const char* get_name(const Payload* payload) {
const EasysetupCfg* cfg = &_cfg->specific.easysetup; const EasysetupCfg* cfg = &payload->cfg.easysetup;
return type_names[cfg->type]; return type_names[cfg->type];
} }
@@ -77,8 +77,8 @@ static uint8_t packet_sizes[EasysetupTypeCOUNT] = {
[EasysetupTypeBuds] = 31, [EasysetupTypeBuds] = 31,
[EasysetupTypeWatch] = 15, [EasysetupTypeWatch] = 15,
}; };
void make_packet(uint8_t* out_size, uint8_t** out_packet, ProtocolCfg* _cfg) { void make_packet(uint8_t* out_size, uint8_t** out_packet, Payload* payload) {
EasysetupCfg* cfg = _cfg ? &_cfg->specific.easysetup : NULL; EasysetupCfg* cfg = payload ? &payload->cfg.easysetup : NULL;
EasysetupType type; EasysetupType type;
if(cfg && cfg->type != 0x00) { if(cfg && cfg->type != 0x00) {
@@ -98,16 +98,16 @@ void make_packet(uint8_t* out_size, uint8_t** out_packet, ProtocolCfg* _cfg) {
switch(type) { switch(type) {
case EasysetupTypeBuds: { case EasysetupTypeBuds: {
uint32_t model; uint32_t model;
switch(cfg ? _cfg->mode : ProtocolModeRandom) { switch(cfg ? payload->mode : PayloadModeRandom) {
case ProtocolModeRandom: case PayloadModeRandom:
default: default:
model = buds_models[rand() % buds_models_count].value; model = buds_models[rand() % buds_models_count].value;
break; break;
case ProtocolModeValue: case PayloadModeValue:
model = cfg->data.buds.model; model = cfg->data.buds.model;
break; break;
case ProtocolModeBruteforce: case PayloadModeBruteforce:
model = cfg->data.buds.model = _cfg->bruteforce.value; model = cfg->data.buds.model = payload->bruteforce.value;
break; break;
} }
@@ -148,16 +148,16 @@ void make_packet(uint8_t* out_size, uint8_t** out_packet, ProtocolCfg* _cfg) {
} }
case EasysetupTypeWatch: { case EasysetupTypeWatch: {
uint8_t model; uint8_t model;
switch(cfg ? _cfg->mode : ProtocolModeRandom) { switch(cfg ? payload->mode : PayloadModeRandom) {
case ProtocolModeRandom: case PayloadModeRandom:
default: default:
model = watch_models[rand() % watch_models_count].value; model = watch_models[rand() % watch_models_count].value;
break; break;
case ProtocolModeValue: case PayloadModeValue:
model = cfg->data.watch.model; model = cfg->data.watch.model;
break; break;
case ProtocolModeBruteforce: case PayloadModeBruteforce:
model = cfg->data.watch.model = _cfg->bruteforce.value; model = cfg->data.watch.model = payload->bruteforce.value;
break; break;
} }
@@ -199,8 +199,8 @@ enum {
}; };
static void config_callback(void* _ctx, uint32_t index) { static void config_callback(void* _ctx, uint32_t index) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg; Payload* payload = &ctx->attack->payload;
EasysetupCfg* cfg = &_cfg->specific.easysetup; EasysetupCfg* cfg = &payload->cfg.easysetup;
scene_manager_set_scene_state(ctx->scene_manager, SceneConfig, index); scene_manager_set_scene_state(ctx->scene_manager, SceneConfig, index);
switch(cfg->type) { switch(cfg->type) {
case EasysetupTypeBuds: { case EasysetupTypeBuds: {
@@ -233,36 +233,36 @@ static void config_callback(void* _ctx, uint32_t index) {
} }
} }
static void buds_model_changed(VariableItem* item) { static void buds_model_changed(VariableItem* item) {
ProtocolCfg* _cfg = variable_item_get_context(item); Payload* payload = variable_item_get_context(item);
EasysetupCfg* cfg = &_cfg->specific.easysetup; EasysetupCfg* cfg = &payload->cfg.easysetup;
uint8_t index = variable_item_get_current_value_index(item); uint8_t index = variable_item_get_current_value_index(item);
if(index) { if(index) {
index--; index--;
_cfg->mode = ProtocolModeValue; payload->mode = PayloadModeValue;
cfg->data.buds.model = buds_models[index].value; cfg->data.buds.model = buds_models[index].value;
variable_item_set_current_value_text(item, buds_models[index].name); variable_item_set_current_value_text(item, buds_models[index].name);
} else { } else {
_cfg->mode = ProtocolModeRandom; payload->mode = PayloadModeRandom;
variable_item_set_current_value_text(item, "Random"); variable_item_set_current_value_text(item, "Random");
} }
} }
static void watch_model_changed(VariableItem* item) { static void watch_model_changed(VariableItem* item) {
ProtocolCfg* _cfg = variable_item_get_context(item); Payload* payload = variable_item_get_context(item);
EasysetupCfg* cfg = &_cfg->specific.easysetup; EasysetupCfg* cfg = &payload->cfg.easysetup;
uint8_t index = variable_item_get_current_value_index(item); uint8_t index = variable_item_get_current_value_index(item);
if(index) { if(index) {
index--; index--;
_cfg->mode = ProtocolModeValue; payload->mode = PayloadModeValue;
cfg->data.watch.model = watch_models[index].value; cfg->data.watch.model = watch_models[index].value;
variable_item_set_current_value_text(item, watch_models[index].name); variable_item_set_current_value_text(item, watch_models[index].name);
} else { } else {
_cfg->mode = ProtocolModeRandom; payload->mode = PayloadModeRandom;
variable_item_set_current_value_text(item, "Random"); variable_item_set_current_value_text(item, "Random");
} }
} }
static void extra_config(Ctx* ctx) { static void extra_config(Ctx* ctx) {
ProtocolCfg* _cfg = &ctx->attack->payload.cfg; Payload* payload = &ctx->attack->payload;
EasysetupCfg* cfg = &_cfg->specific.easysetup; EasysetupCfg* cfg = &payload->cfg.easysetup;
VariableItemList* list = ctx->variable_item_list; VariableItemList* list = ctx->variable_item_list;
VariableItem* item; VariableItem* item;
size_t value_index; size_t value_index;
@@ -270,16 +270,16 @@ static void extra_config(Ctx* ctx) {
switch(cfg->type) { switch(cfg->type) {
case EasysetupTypeBuds: { case EasysetupTypeBuds: {
item = variable_item_list_add( 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, payload);
const char* model_name = NULL; const char* model_name = NULL;
char model_name_buf[9]; char model_name_buf[9];
switch(_cfg->mode) { switch(payload->mode) {
case ProtocolModeRandom: case PayloadModeRandom:
default: default:
model_name = "Random"; model_name = "Random";
value_index = 0; value_index = 0;
break; break;
case ProtocolModeValue: case PayloadModeValue:
for(uint8_t i = 0; i < buds_models_count; i++) { for(uint8_t i = 0; i < buds_models_count; i++) {
if(cfg->data.buds.model == buds_models[i].value) { if(cfg->data.buds.model == buds_models[i].value) {
model_name = buds_models[i].name; model_name = buds_models[i].name;
@@ -293,7 +293,7 @@ static void extra_config(Ctx* ctx) {
value_index = buds_models_count + 1; value_index = buds_models_count + 1;
} }
break; break;
case ProtocolModeBruteforce: case PayloadModeBruteforce:
model_name = "Bruteforce"; model_name = "Bruteforce";
value_index = buds_models_count + 1; value_index = buds_models_count + 1;
break; break;
@@ -306,16 +306,16 @@ static void extra_config(Ctx* ctx) {
} }
case EasysetupTypeWatch: { case EasysetupTypeWatch: {
item = variable_item_list_add( 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, payload);
const char* model_name = NULL; const char* model_name = NULL;
char model_name_buf[3]; char model_name_buf[3];
switch(_cfg->mode) { switch(payload->mode) {
case ProtocolModeRandom: case PayloadModeRandom:
default: default:
model_name = "Random"; model_name = "Random";
value_index = 0; value_index = 0;
break; break;
case ProtocolModeValue: case PayloadModeValue:
for(uint8_t i = 0; i < watch_models_count; i++) { for(uint8_t i = 0; i < watch_models_count; i++) {
if(cfg->data.watch.model == watch_models[i].value) { if(cfg->data.watch.model == watch_models[i].value) {
model_name = watch_models[i].name; model_name = watch_models[i].name;
@@ -329,7 +329,7 @@ static void extra_config(Ctx* ctx) {
value_index = watch_models_count + 1; value_index = watch_models_count + 1;
} }
break; break;
case ProtocolModeBruteforce: case PayloadModeBruteforce:
model_name = "Bruteforce"; model_name = "Bruteforce";
value_index = watch_models_count + 1; value_index = watch_models_count + 1;
break; break;
@@ -349,8 +349,8 @@ static uint8_t config_counts[EasysetupTypeCOUNT] = {
[EasysetupTypeBuds] = ConfigBudsCOUNT - ConfigExtraStart - 1, [EasysetupTypeBuds] = ConfigBudsCOUNT - ConfigExtraStart - 1,
[EasysetupTypeWatch] = ConfigWatchCOUNT - ConfigExtraStart - 1, [EasysetupTypeWatch] = ConfigWatchCOUNT - ConfigExtraStart - 1,
}; };
static uint8_t config_count(const ProtocolCfg* _cfg) { static uint8_t config_count(const Payload* payload) {
const EasysetupCfg* cfg = &_cfg->specific.easysetup; const EasysetupCfg* cfg = &payload->cfg.easysetup;
return config_counts[cfg->type]; return config_counts[cfg->type];
} }
@@ -364,25 +364,25 @@ const Protocol protocol_easysetup = {
static void buds_model_callback(void* _ctx, uint32_t index) { static void buds_model_callback(void* _ctx, uint32_t index) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg; Payload* payload = &ctx->attack->payload;
EasysetupCfg* cfg = &_cfg->specific.easysetup; EasysetupCfg* cfg = &payload->cfg.easysetup;
switch(index) { switch(index) {
case 0: case 0:
_cfg->mode = ProtocolModeRandom; payload->mode = PayloadModeRandom;
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
break; break;
case buds_models_count + 1: case buds_models_count + 1:
scene_manager_next_scene(ctx->scene_manager, SceneEasysetupBudsModelCustom); scene_manager_next_scene(ctx->scene_manager, SceneEasysetupBudsModelCustom);
break; break;
case buds_models_count + 2: case buds_models_count + 2:
_cfg->mode = ProtocolModeBruteforce; payload->mode = PayloadModeBruteforce;
_cfg->bruteforce.counter = 0; payload->bruteforce.counter = 0;
_cfg->bruteforce.value = cfg->data.buds.model; payload->bruteforce.value = cfg->data.buds.model;
_cfg->bruteforce.size = 3; payload->bruteforce.size = 3;
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
break; break;
default: default:
_cfg->mode = ProtocolModeValue; payload->mode = PayloadModeValue;
cfg->data.buds.model = buds_models[index - 1].value; cfg->data.buds.model = buds_models[index - 1].value;
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
break; break;
@@ -390,33 +390,33 @@ static void buds_model_callback(void* _ctx, uint32_t index) {
} }
void scene_easysetup_buds_model_on_enter(void* _ctx) { void scene_easysetup_buds_model_on_enter(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg; Payload* payload = &ctx->attack->payload;
EasysetupCfg* cfg = &_cfg->specific.easysetup; EasysetupCfg* cfg = &payload->cfg.easysetup;
Submenu* submenu = ctx->submenu; Submenu* submenu = ctx->submenu;
uint32_t selected = 0; uint32_t selected = 0;
submenu_reset(submenu); submenu_reset(submenu);
submenu_add_item(submenu, "Random", 0, buds_model_callback, ctx); submenu_add_item(submenu, "Random", 0, buds_model_callback, ctx);
if(_cfg->mode == ProtocolModeRandom) { if(payload->mode == PayloadModeRandom) {
selected = 0; selected = 0;
} }
bool found = false; bool found = false;
for(uint8_t i = 0; i < buds_models_count; i++) { for(uint8_t i = 0; i < buds_models_count; i++) {
submenu_add_item(submenu, buds_models[i].name, i + 1, buds_model_callback, ctx); submenu_add_item(submenu, buds_models[i].name, i + 1, buds_model_callback, ctx);
if(!found && _cfg->mode == ProtocolModeValue && if(!found && payload->mode == PayloadModeValue &&
cfg->data.buds.model == buds_models[i].value) { cfg->data.buds.model == buds_models[i].value) {
found = true; found = true;
selected = i + 1; selected = i + 1;
} }
} }
submenu_add_item(submenu, "Custom", buds_models_count + 1, buds_model_callback, ctx); submenu_add_item(submenu, "Custom", buds_models_count + 1, buds_model_callback, ctx);
if(!found && _cfg->mode == ProtocolModeValue) { if(!found && payload->mode == PayloadModeValue) {
selected = buds_models_count + 1; selected = buds_models_count + 1;
} }
submenu_add_item(submenu, "Bruteforce", buds_models_count + 2, buds_model_callback, ctx); submenu_add_item(submenu, "Bruteforce", buds_models_count + 2, buds_model_callback, ctx);
if(_cfg->mode == ProtocolModeBruteforce) { if(payload->mode == PayloadModeBruteforce) {
selected = buds_models_count + 2; selected = buds_models_count + 2;
} }
@@ -435,9 +435,9 @@ void scene_easysetup_buds_model_on_exit(void* _ctx) {
static void buds_model_custom_callback(void* _ctx) { static void buds_model_custom_callback(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg; Payload* payload = &ctx->attack->payload;
EasysetupCfg* cfg = &_cfg->specific.easysetup; EasysetupCfg* cfg = &payload->cfg.easysetup;
_cfg->mode = ProtocolModeValue; payload->mode = PayloadModeValue;
cfg->data.buds.model = cfg->data.buds.model =
(ctx->byte_store[0] << 0x10) + (ctx->byte_store[1] << 0x08) + (ctx->byte_store[2] << 0x00); (ctx->byte_store[0] << 0x10) + (ctx->byte_store[1] << 0x08) + (ctx->byte_store[2] << 0x00);
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
@@ -445,8 +445,8 @@ static void buds_model_custom_callback(void* _ctx) {
} }
void scene_easysetup_buds_model_custom_on_enter(void* _ctx) { void scene_easysetup_buds_model_custom_on_enter(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg; Payload* payload = &ctx->attack->payload;
EasysetupCfg* cfg = &_cfg->specific.easysetup; EasysetupCfg* cfg = &payload->cfg.easysetup;
ByteInput* byte_input = ctx->byte_input; ByteInput* byte_input = ctx->byte_input;
byte_input_set_header_text(byte_input, "Enter custom Model Code"); byte_input_set_header_text(byte_input, "Enter custom Model Code");
@@ -471,25 +471,25 @@ void scene_easysetup_buds_model_custom_on_exit(void* _ctx) {
static void watch_model_callback(void* _ctx, uint32_t index) { static void watch_model_callback(void* _ctx, uint32_t index) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg; Payload* payload = &ctx->attack->payload;
EasysetupCfg* cfg = &_cfg->specific.easysetup; EasysetupCfg* cfg = &payload->cfg.easysetup;
switch(index) { switch(index) {
case 0: case 0:
_cfg->mode = ProtocolModeRandom; payload->mode = PayloadModeRandom;
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
break; break;
case watch_models_count + 1: case watch_models_count + 1:
scene_manager_next_scene(ctx->scene_manager, SceneEasysetupWatchModelCustom); scene_manager_next_scene(ctx->scene_manager, SceneEasysetupWatchModelCustom);
break; break;
case watch_models_count + 2: case watch_models_count + 2:
_cfg->mode = ProtocolModeBruteforce; payload->mode = PayloadModeBruteforce;
_cfg->bruteforce.counter = 0; payload->bruteforce.counter = 0;
_cfg->bruteforce.value = cfg->data.watch.model; payload->bruteforce.value = cfg->data.watch.model;
_cfg->bruteforce.size = 1; payload->bruteforce.size = 1;
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
break; break;
default: default:
_cfg->mode = ProtocolModeValue; payload->mode = PayloadModeValue;
cfg->data.watch.model = watch_models[index - 1].value; cfg->data.watch.model = watch_models[index - 1].value;
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
break; break;
@@ -497,33 +497,33 @@ static void watch_model_callback(void* _ctx, uint32_t index) {
} }
void scene_easysetup_watch_model_on_enter(void* _ctx) { void scene_easysetup_watch_model_on_enter(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg; Payload* payload = &ctx->attack->payload;
EasysetupCfg* cfg = &_cfg->specific.easysetup; EasysetupCfg* cfg = &payload->cfg.easysetup;
Submenu* submenu = ctx->submenu; Submenu* submenu = ctx->submenu;
uint32_t selected = 0; uint32_t selected = 0;
submenu_reset(submenu); submenu_reset(submenu);
submenu_add_item(submenu, "Random", 0, watch_model_callback, ctx); submenu_add_item(submenu, "Random", 0, watch_model_callback, ctx);
if(_cfg->mode == ProtocolModeRandom) { if(payload->mode == PayloadModeRandom) {
selected = 0; selected = 0;
} }
bool found = false; bool found = false;
for(uint8_t i = 0; i < watch_models_count; i++) { for(uint8_t i = 0; i < watch_models_count; i++) {
submenu_add_item(submenu, watch_models[i].name, i + 1, watch_model_callback, ctx); submenu_add_item(submenu, watch_models[i].name, i + 1, watch_model_callback, ctx);
if(!found && _cfg->mode == ProtocolModeValue && if(!found && payload->mode == PayloadModeValue &&
cfg->data.watch.model == watch_models[i].value) { cfg->data.watch.model == watch_models[i].value) {
found = true; found = true;
selected = i + 1; selected = i + 1;
} }
} }
submenu_add_item(submenu, "Custom", watch_models_count + 1, watch_model_callback, ctx); submenu_add_item(submenu, "Custom", watch_models_count + 1, watch_model_callback, ctx);
if(!found && _cfg->mode == ProtocolModeValue) { if(!found && payload->mode == PayloadModeValue) {
selected = watch_models_count + 1; selected = watch_models_count + 1;
} }
submenu_add_item(submenu, "Bruteforce", watch_models_count + 2, watch_model_callback, ctx); submenu_add_item(submenu, "Bruteforce", watch_models_count + 2, watch_model_callback, ctx);
if(_cfg->mode == ProtocolModeBruteforce) { if(payload->mode == PayloadModeBruteforce) {
selected = watch_models_count + 2; selected = watch_models_count + 2;
} }
@@ -542,17 +542,17 @@ void scene_easysetup_watch_model_on_exit(void* _ctx) {
static void watch_model_custom_callback(void* _ctx) { static void watch_model_custom_callback(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg; Payload* payload = &ctx->attack->payload;
EasysetupCfg* cfg = &_cfg->specific.easysetup; EasysetupCfg* cfg = &payload->cfg.easysetup;
_cfg->mode = ProtocolModeValue; payload->mode = PayloadModeValue;
cfg->data.watch.model = (ctx->byte_store[0] << 0x00); cfg->data.watch.model = (ctx->byte_store[0] << 0x00);
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
} }
void scene_easysetup_watch_model_custom_on_enter(void* _ctx) { void scene_easysetup_watch_model_custom_on_enter(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg; Payload* payload = &ctx->attack->payload;
EasysetupCfg* cfg = &_cfg->specific.easysetup; EasysetupCfg* cfg = &payload->cfg.easysetup;
ByteInput* byte_input = ctx->byte_input; ByteInput* byte_input = ctx->byte_input;
byte_input_set_header_text(byte_input, "Enter custom Model Code"); byte_input_set_header_text(byte_input, "Enter custom Model Code");

View File

@@ -65,25 +65,25 @@ const struct {
}; };
const uint8_t models_count = COUNT_OF(models); const uint8_t models_count = COUNT_OF(models);
static const char* get_name(const ProtocolCfg* _cfg) { static const char* get_name(const Payload* payload) {
UNUSED(_cfg); UNUSED(payload);
return "FastPair"; return "FastPair";
} }
static void make_packet(uint8_t* _size, uint8_t** _packet, ProtocolCfg* _cfg) { static void make_packet(uint8_t* _size, uint8_t** _packet, Payload* payload) {
FastpairCfg* cfg = _cfg ? &_cfg->specific.fastpair : NULL; FastpairCfg* cfg = payload ? &payload->cfg.fastpair : NULL;
uint32_t model; uint32_t model;
switch(cfg ? _cfg->mode : ProtocolModeRandom) { switch(cfg ? payload->mode : PayloadModeRandom) {
case ProtocolModeRandom: case PayloadModeRandom:
default: default:
model = models[rand() % models_count].value; model = models[rand() % models_count].value;
break; break;
case ProtocolModeValue: case PayloadModeValue:
model = cfg->model; model = cfg->model;
break; break;
case ProtocolModeBruteforce: case PayloadModeBruteforce:
model = cfg->model = _cfg->bruteforce.value; model = cfg->model = payload->bruteforce.value;
break; break;
} }
@@ -133,36 +133,36 @@ static void config_callback(void* _ctx, uint32_t index) {
} }
} }
static void model_changed(VariableItem* item) { static void model_changed(VariableItem* item) {
ProtocolCfg* _cfg = variable_item_get_context(item); Payload* payload = variable_item_get_context(item);
FastpairCfg* cfg = &_cfg->specific.fastpair; FastpairCfg* cfg = &payload->cfg.fastpair;
uint8_t index = variable_item_get_current_value_index(item); uint8_t index = variable_item_get_current_value_index(item);
if(index) { if(index) {
index--; index--;
_cfg->mode = ProtocolModeValue; payload->mode = PayloadModeValue;
cfg->model = models[index].value; cfg->model = models[index].value;
variable_item_set_current_value_text(item, models[index].name); variable_item_set_current_value_text(item, models[index].name);
} else { } else {
_cfg->mode = ProtocolModeRandom; payload->mode = PayloadModeRandom;
variable_item_set_current_value_text(item, "Random"); variable_item_set_current_value_text(item, "Random");
} }
} }
static void extra_config(Ctx* ctx) { static void extra_config(Ctx* ctx) {
ProtocolCfg* _cfg = &ctx->attack->payload.cfg; Payload* payload = &ctx->attack->payload;
FastpairCfg* cfg = &_cfg->specific.fastpair; FastpairCfg* cfg = &payload->cfg.fastpair;
VariableItemList* list = ctx->variable_item_list; VariableItemList* list = ctx->variable_item_list;
VariableItem* item; VariableItem* item;
size_t value_index; 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, payload);
const char* model_name = NULL; const char* model_name = NULL;
char model_name_buf[9]; char model_name_buf[9];
switch(_cfg->mode) { switch(payload->mode) {
case ProtocolModeRandom: case PayloadModeRandom:
default: default:
model_name = "Random"; model_name = "Random";
value_index = 0; value_index = 0;
break; break;
case ProtocolModeValue: case PayloadModeValue:
for(uint8_t i = 0; i < models_count; i++) { for(uint8_t i = 0; i < models_count; i++) {
if(cfg->model == models[i].value) { if(cfg->model == models[i].value) {
model_name = models[i].name; model_name = models[i].name;
@@ -176,7 +176,7 @@ static void extra_config(Ctx* ctx) {
value_index = models_count + 1; value_index = models_count + 1;
} }
break; break;
case ProtocolModeBruteforce: case PayloadModeBruteforce:
model_name = "Bruteforce"; model_name = "Bruteforce";
value_index = models_count + 1; value_index = models_count + 1;
break; break;
@@ -189,8 +189,8 @@ static void extra_config(Ctx* ctx) {
variable_item_list_set_enter_callback(list, config_callback, ctx); variable_item_list_set_enter_callback(list, config_callback, ctx);
} }
static uint8_t config_count(const ProtocolCfg* _cfg) { static uint8_t config_count(const Payload* payload) {
UNUSED(_cfg); UNUSED(payload);
return ConfigCOUNT - ConfigExtraStart - 1; return ConfigCOUNT - ConfigExtraStart - 1;
} }
@@ -204,25 +204,25 @@ const Protocol protocol_fastpair = {
static void model_callback(void* _ctx, uint32_t index) { static void model_callback(void* _ctx, uint32_t index) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg; Payload* payload = &ctx->attack->payload;
FastpairCfg* cfg = &_cfg->specific.fastpair; FastpairCfg* cfg = &payload->cfg.fastpair;
switch(index) { switch(index) {
case 0: case 0:
_cfg->mode = ProtocolModeRandom; payload->mode = PayloadModeRandom;
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
break; break;
case models_count + 1: case models_count + 1:
scene_manager_next_scene(ctx->scene_manager, SceneFastpairModelCustom); scene_manager_next_scene(ctx->scene_manager, SceneFastpairModelCustom);
break; break;
case models_count + 2: case models_count + 2:
_cfg->mode = ProtocolModeBruteforce; payload->mode = PayloadModeBruteforce;
_cfg->bruteforce.counter = 0; payload->bruteforce.counter = 0;
_cfg->bruteforce.value = cfg->model; payload->bruteforce.value = cfg->model;
_cfg->bruteforce.size = 3; payload->bruteforce.size = 3;
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
break; break;
default: default:
_cfg->mode = ProtocolModeValue; payload->mode = PayloadModeValue;
cfg->model = models[index - 1].value; cfg->model = models[index - 1].value;
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
break; break;
@@ -230,32 +230,32 @@ static void model_callback(void* _ctx, uint32_t index) {
} }
void scene_fastpair_model_on_enter(void* _ctx) { void scene_fastpair_model_on_enter(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg; Payload* payload = &ctx->attack->payload;
FastpairCfg* cfg = &_cfg->specific.fastpair; FastpairCfg* cfg = &payload->cfg.fastpair;
Submenu* submenu = ctx->submenu; Submenu* submenu = ctx->submenu;
uint32_t selected = 0; uint32_t selected = 0;
submenu_reset(submenu); submenu_reset(submenu);
submenu_add_item(submenu, "Random", 0, model_callback, ctx); submenu_add_item(submenu, "Random", 0, model_callback, ctx);
if(_cfg->mode == ProtocolModeRandom) { if(payload->mode == PayloadModeRandom) {
selected = 0; selected = 0;
} }
bool found = false; bool found = false;
for(uint8_t i = 0; i < models_count; i++) { for(uint8_t i = 0; i < models_count; i++) {
submenu_add_item(submenu, models[i].name, i + 1, model_callback, ctx); submenu_add_item(submenu, models[i].name, i + 1, model_callback, ctx);
if(!found && _cfg->mode == ProtocolModeValue && cfg->model == models[i].value) { if(!found && payload->mode == PayloadModeValue && cfg->model == models[i].value) {
found = true; found = true;
selected = i + 1; selected = i + 1;
} }
} }
submenu_add_item(submenu, "Custom", models_count + 1, model_callback, ctx); submenu_add_item(submenu, "Custom", models_count + 1, model_callback, ctx);
if(!found && _cfg->mode == ProtocolModeValue) { if(!found && payload->mode == PayloadModeValue) {
selected = models_count + 1; selected = models_count + 1;
} }
submenu_add_item(submenu, "Bruteforce", models_count + 2, model_callback, ctx); submenu_add_item(submenu, "Bruteforce", models_count + 2, model_callback, ctx);
if(_cfg->mode == ProtocolModeBruteforce) { if(payload->mode == PayloadModeBruteforce) {
selected = models_count + 2; selected = models_count + 2;
} }
@@ -274,9 +274,9 @@ void scene_fastpair_model_on_exit(void* _ctx) {
static void model_custom_callback(void* _ctx) { static void model_custom_callback(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg; Payload* payload = &ctx->attack->payload;
FastpairCfg* cfg = &_cfg->specific.fastpair; FastpairCfg* cfg = &payload->cfg.fastpair;
_cfg->mode = ProtocolModeValue; payload->mode = PayloadModeValue;
cfg->model = cfg->model =
(ctx->byte_store[0] << 0x10) + (ctx->byte_store[1] << 0x08) + (ctx->byte_store[2] << 0x00); (ctx->byte_store[0] << 0x10) + (ctx->byte_store[1] << 0x08) + (ctx->byte_store[2] << 0x00);
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
@@ -284,8 +284,8 @@ static void model_custom_callback(void* _ctx) {
} }
void scene_fastpair_model_custom_on_enter(void* _ctx) { void scene_fastpair_model_custom_on_enter(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg; Payload* payload = &ctx->attack->payload;
FastpairCfg* cfg = &_cfg->specific.fastpair; FastpairCfg* cfg = &payload->cfg.fastpair;
ByteInput* byte_input = ctx->byte_input; ByteInput* byte_input = ctx->byte_input;
byte_input_set_header_text(byte_input, "Enter custom Model Code"); byte_input_set_header_text(byte_input, "Enter custom Model Code");

View File

@@ -14,21 +14,21 @@ const char* names[] = {
}; };
const uint8_t names_count = COUNT_OF(names); const uint8_t names_count = COUNT_OF(names);
static const char* get_name(const ProtocolCfg* _cfg) { static const char* get_name(const Payload* payload) {
UNUSED(_cfg); UNUSED(payload);
return "SwiftPair"; return "SwiftPair";
} }
static void make_packet(uint8_t* _size, uint8_t** _packet, ProtocolCfg* _cfg) { static void make_packet(uint8_t* _size, uint8_t** _packet, Payload* payload) {
SwiftpairCfg* cfg = _cfg ? &_cfg->specific.swiftpair : NULL; SwiftpairCfg* cfg = payload ? &payload->cfg.swiftpair : NULL;
const char* name; const char* name;
switch(cfg ? _cfg->mode : ProtocolModeRandom) { switch(cfg ? payload->mode : PayloadModeRandom) {
case ProtocolModeRandom: case PayloadModeRandom:
default: default:
name = names[rand() % names_count]; name = names[rand() % names_count];
break; break;
case ProtocolModeValue: case PayloadModeValue:
name = cfg->name; name = cfg->name;
break; break;
} }
@@ -73,22 +73,22 @@ static void config_callback(void* _ctx, uint32_t index) {
} }
} }
static void extra_config(Ctx* ctx) { static void extra_config(Ctx* ctx) {
ProtocolCfg* _cfg = &ctx->attack->payload.cfg; Payload* payload = &ctx->attack->payload;
SwiftpairCfg* cfg = &_cfg->specific.swiftpair; SwiftpairCfg* cfg = &payload->cfg.swiftpair;
VariableItemList* list = ctx->variable_item_list; VariableItemList* list = ctx->variable_item_list;
VariableItem* item; VariableItem* item;
item = variable_item_list_add(list, "Display Name", 0, NULL, NULL); item = variable_item_list_add(list, "Display Name", 0, NULL, NULL);
variable_item_set_current_value_text( variable_item_set_current_value_text(
item, _cfg->mode == ProtocolModeRandom ? "Random" : cfg->name); item, payload->mode == PayloadModeRandom ? "Random" : cfg->name);
variable_item_list_add(list, "Requires enabling SwiftPair", 0, NULL, NULL); variable_item_list_add(list, "Requires enabling SwiftPair", 0, NULL, NULL);
variable_item_list_set_enter_callback(list, config_callback, ctx); variable_item_list_set_enter_callback(list, config_callback, ctx);
} }
static uint8_t config_count(const ProtocolCfg* _cfg) { static uint8_t config_count(const Payload* payload) {
UNUSED(_cfg); UNUSED(payload);
return ConfigCOUNT - ConfigExtraStart - 1; return ConfigCOUNT - ConfigExtraStart - 1;
} }
@@ -102,14 +102,14 @@ const Protocol protocol_swiftpair = {
static void name_callback(void* _ctx) { static void name_callback(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg; Payload* payload = &ctx->attack->payload;
_cfg->mode = ProtocolModeValue; payload->mode = PayloadModeValue;
scene_manager_previous_scene(ctx->scene_manager); scene_manager_previous_scene(ctx->scene_manager);
} }
void scene_swiftpair_name_on_enter(void* _ctx) { void scene_swiftpair_name_on_enter(void* _ctx) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg; Payload* payload = &ctx->attack->payload;
SwiftpairCfg* cfg = &_cfg->specific.swiftpair; SwiftpairCfg* cfg = &payload->cfg.swiftpair;
TextInput* text_input = ctx->text_input; TextInput* text_input = ctx->text_input;
text_input_reset(text_input); text_input_reset(text_input);
@@ -124,9 +124,9 @@ void scene_swiftpair_name_on_enter(void* _ctx) {
} }
bool scene_swiftpair_name_on_event(void* _ctx, SceneManagerEvent event) { bool scene_swiftpair_name_on_event(void* _ctx, SceneManagerEvent event) {
Ctx* ctx = _ctx; Ctx* ctx = _ctx;
ProtocolCfg* _cfg = &ctx->attack->payload.cfg; Payload* payload = &ctx->attack->payload;
if(event.type == SceneManagerEventTypeBack) { if(event.type == SceneManagerEventTypeBack) {
_cfg->mode = ProtocolModeRandom; payload->mode = PayloadModeRandom;
} }
return false; return false;
} }

View File

@@ -19,7 +19,7 @@ static void config_callback(void* _ctx, uint32_t index) {
if(!ctx->attack->protocol) { if(!ctx->attack->protocol) {
index--; index--;
} else if(ctx->attack->protocol->config_count) { } else if(ctx->attack->protocol->config_count) {
uint8_t extra = ctx->attack->protocol->config_count(&ctx->attack->payload.cfg); uint8_t extra = ctx->attack->protocol->config_count(&ctx->attack->payload);
if(index > extra) index -= extra; if(index > extra) index -= extra;
} }