mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-24 03:29:57 -07:00
BadKB shorter mac and name length constants
This commit is contained in:
@@ -34,7 +34,7 @@ static void bad_kb_load_settings(BadKbApp* app) {
|
||||
memcpy(
|
||||
app->config.bt_mac,
|
||||
furi_hal_bt_get_profile_mac_addr(FuriHalBtProfileHidKeyboard),
|
||||
BAD_KB_MAC_ADDRESS_LEN);
|
||||
BAD_KB_MAC_LEN);
|
||||
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
FlipperFormat* file = flipper_format_file_alloc(storage);
|
||||
@@ -49,11 +49,11 @@ static void bad_kb_load_settings(BadKbApp* app) {
|
||||
strcpy(app->config.bt_name, "");
|
||||
}
|
||||
if(!flipper_format_read_hex(
|
||||
file, "Bt_Mac", (uint8_t*)&app->config.bt_mac, BAD_KB_MAC_ADDRESS_LEN)) {
|
||||
file, "Bt_Mac", (uint8_t*)&app->config.bt_mac, BAD_KB_MAC_LEN)) {
|
||||
memcpy(
|
||||
app->config.bt_mac,
|
||||
furi_hal_bt_get_profile_mac_addr(FuriHalBtProfileHidKeyboard),
|
||||
BAD_KB_MAC_ADDRESS_LEN);
|
||||
BAD_KB_MAC_LEN);
|
||||
}
|
||||
furi_string_free(tmp_str);
|
||||
flipper_format_file_close(file);
|
||||
@@ -82,8 +82,7 @@ static void bad_kb_save_settings(BadKbApp* app) {
|
||||
if(flipper_format_file_open_always(file, BAD_KB_SETTINGS_PATH)) {
|
||||
flipper_format_write_string(file, "Keyboard_Layout", app->keyboard_layout);
|
||||
flipper_format_write_string_cstr(file, "Bt_Name", app->config.bt_name);
|
||||
flipper_format_write_hex(
|
||||
file, "Bt_Mac", (uint8_t*)&app->config.bt_mac, BAD_KB_MAC_ADDRESS_LEN);
|
||||
flipper_format_write_hex(file, "Bt_Mac", (uint8_t*)&app->config.bt_mac, BAD_KB_MAC_LEN);
|
||||
flipper_format_file_close(file);
|
||||
}
|
||||
flipper_format_free(file);
|
||||
|
||||
@@ -12,10 +12,8 @@
|
||||
#include <dolphin/dolphin.h>
|
||||
#include <toolbox/hex.h>
|
||||
|
||||
const uint8_t BAD_KB_BOUND_MAC_ADDRESS[BAD_KB_MAC_ADDRESS_LEN] =
|
||||
{0x41, 0x4a, 0xef, 0xb6, 0xa9, 0xd4};
|
||||
const uint8_t BAD_KB_EMPTY_MAC_ADDRESS[BAD_KB_MAC_ADDRESS_LEN] =
|
||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||
const uint8_t BAD_KB_BOUND_MAC_ADDRESS[BAD_KB_MAC_LEN] = {0x41, 0x4a, 0xef, 0xb6, 0xa9, 0xd4};
|
||||
const uint8_t BAD_KB_EMPTY_MAC_ADDRESS[BAD_KB_MAC_LEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||
|
||||
#define TAG "BadKB"
|
||||
#define WORKER_TAG TAG "Worker"
|
||||
@@ -333,11 +331,11 @@ static bool ducky_set_usb_id(BadKbScript* bad_kb, const char* line) {
|
||||
|
||||
static bool ducky_set_bt_id(BadKbScript* bad_kb, const char* line) {
|
||||
size_t line_len = strlen(line);
|
||||
size_t mac_len = BAD_KB_MAC_ADDRESS_LEN * 3;
|
||||
size_t mac_len = BAD_KB_MAC_LEN * 3;
|
||||
if(line_len < mac_len + 1) return false; // MAC + at least 1 char for name
|
||||
|
||||
uint8_t mac[BAD_KB_MAC_ADDRESS_LEN];
|
||||
for(size_t i = 0; i < BAD_KB_MAC_ADDRESS_LEN; i++) {
|
||||
uint8_t mac[BAD_KB_MAC_LEN];
|
||||
for(size_t i = 0; i < BAD_KB_MAC_LEN; i++) {
|
||||
char a = line[i * 3];
|
||||
char b = line[i * 3 + 1];
|
||||
if((a < 'A' && a > 'F') || (a < '0' && a > '9') || (b < 'A' && b > 'F') ||
|
||||
@@ -427,11 +425,11 @@ static bool ducky_script_preload(BadKbScript* bad_kb, File* script_file) {
|
||||
bool reset_name = strncmp(
|
||||
bt_name,
|
||||
furi_hal_bt_get_profile_adv_name(FuriHalBtProfileHidKeyboard),
|
||||
BAD_KB_ADV_NAME_MAX_LEN);
|
||||
BAD_KB_NAME_LEN);
|
||||
bool reset_mac = memcmp(
|
||||
bt_mac,
|
||||
furi_hal_bt_get_profile_mac_addr(FuriHalBtProfileHidKeyboard),
|
||||
BAD_KB_MAC_ADDRESS_LEN);
|
||||
BAD_KB_MAC_LEN);
|
||||
if(reset_name && reset_mac) {
|
||||
furi_hal_bt_set_profile_adv_name(FuriHalBtProfileHidKeyboard, bt_name);
|
||||
} else if(reset_name) {
|
||||
@@ -576,7 +574,7 @@ int32_t bad_kb_conn_refresh(BadKbApp* app) {
|
||||
memcpy(
|
||||
app->prev_config.bt_mac,
|
||||
furi_hal_bt_get_profile_mac_addr(FuriHalBtProfileHidKeyboard),
|
||||
BAD_KB_MAC_ADDRESS_LEN);
|
||||
BAD_KB_MAC_LEN);
|
||||
app->prev_config.bt_mode =
|
||||
furi_hal_bt_get_profile_pairing_method(FuriHalBtProfileHidKeyboard);
|
||||
bt_timeout = bt_hid_delays[LevelRssi39_0];
|
||||
@@ -591,10 +589,8 @@ int32_t bad_kb_conn_refresh(BadKbApp* app) {
|
||||
furi_hal_bt_set_profile_pairing_method(
|
||||
FuriHalBtProfileHidKeyboard, GapPairingPinCodeVerifyYesNo);
|
||||
} else {
|
||||
if(memcmp(
|
||||
app->config.bt_mac,
|
||||
(uint8_t*)&BAD_KB_EMPTY_MAC_ADDRESS,
|
||||
BAD_KB_MAC_ADDRESS_LEN) != 0) {
|
||||
if(memcmp(app->config.bt_mac, (uint8_t*)&BAD_KB_EMPTY_MAC_ADDRESS, BAD_KB_MAC_LEN) !=
|
||||
0) {
|
||||
furi_hal_bt_set_profile_mac_addr(FuriHalBtProfileHidKeyboard, app->config.bt_mac);
|
||||
}
|
||||
furi_hal_bt_set_profile_pairing_method(FuriHalBtProfileHidKeyboard, GapPairingNone);
|
||||
@@ -605,13 +601,11 @@ int32_t bad_kb_conn_refresh(BadKbApp* app) {
|
||||
app->config.bt_name,
|
||||
furi_hal_bt_get_profile_adv_name(FuriHalBtProfileHidKeyboard));
|
||||
}
|
||||
if(memcmp(
|
||||
app->config.bt_mac, (uint8_t*)&BAD_KB_EMPTY_MAC_ADDRESS, BAD_KB_MAC_ADDRESS_LEN) ==
|
||||
0) {
|
||||
if(memcmp(app->config.bt_mac, (uint8_t*)&BAD_KB_EMPTY_MAC_ADDRESS, BAD_KB_MAC_LEN) == 0) {
|
||||
memcpy(
|
||||
app->config.bt_mac,
|
||||
furi_hal_bt_get_profile_mac_addr(FuriHalBtProfileHidKeyboard),
|
||||
BAD_KB_MAC_ADDRESS_LEN);
|
||||
BAD_KB_MAC_LEN);
|
||||
}
|
||||
if(app->bt_remember) {
|
||||
bt_enable_peer_key_update(app->bt);
|
||||
|
||||
@@ -109,20 +109,20 @@ void bad_kb_script_pause_resume(BadKbScript* bad_kb);
|
||||
|
||||
BadKbState* bad_kb_script_get_state(BadKbScript* bad_kb);
|
||||
|
||||
#define BAD_KB_ADV_NAME_MAX_LEN FURI_HAL_BT_ADV_NAME_LENGTH
|
||||
#define BAD_KB_MAC_ADDRESS_LEN GAP_MAC_ADDR_SIZE
|
||||
#define BAD_KB_NAME_LEN FURI_HAL_BT_ADV_NAME_LENGTH
|
||||
#define BAD_KB_MAC_LEN GAP_MAC_ADDR_SIZE
|
||||
|
||||
// this is the MAC address used when we do not forget paired device (BOUND STATE)
|
||||
extern const uint8_t BAD_KB_BOUND_MAC_ADDRESS[BAD_KB_MAC_ADDRESS_LEN];
|
||||
extern const uint8_t BAD_KB_EMPTY_MAC_ADDRESS[BAD_KB_MAC_ADDRESS_LEN];
|
||||
extern const uint8_t BAD_KB_BOUND_MAC_ADDRESS[BAD_KB_MAC_LEN];
|
||||
extern const uint8_t BAD_KB_EMPTY_MAC_ADDRESS[BAD_KB_MAC_LEN];
|
||||
|
||||
typedef enum {
|
||||
BadKbAppErrorNoFiles,
|
||||
} BadKbAppError;
|
||||
|
||||
typedef struct {
|
||||
char bt_name[BAD_KB_ADV_NAME_MAX_LEN];
|
||||
uint8_t bt_mac[BAD_KB_MAC_ADDRESS_LEN];
|
||||
char bt_name[BAD_KB_NAME_LEN];
|
||||
uint8_t bt_mac[BAD_KB_MAC_LEN];
|
||||
FuriHalUsbInterface* usb_mode;
|
||||
GapPairing bt_mode;
|
||||
} BadKbConfig;
|
||||
|
||||
@@ -112,7 +112,7 @@ bool bad_kb_scene_config_on_event(void* context, SceneManagerEvent event) {
|
||||
scene_manager_next_scene(bad_kb->scene_manager, BadKbSceneConfigMac);
|
||||
break;
|
||||
case VarItemListIndexRandomizeBtMac:
|
||||
furi_hal_random_fill_buf(bad_kb->config.bt_mac, BAD_KB_MAC_ADDRESS_LEN);
|
||||
furi_hal_random_fill_buf(bad_kb->config.bt_mac, BAD_KB_MAC_LEN);
|
||||
bt_set_profile_mac_address(bad_kb->bt, bad_kb->config.bt_mac);
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -12,7 +12,7 @@ void bad_kb_scene_config_mac_on_enter(void* context) {
|
||||
BadKbApp* bad_kb = context;
|
||||
ByteInput* byte_input = bad_kb->byte_input;
|
||||
|
||||
memmove(bad_kb->bt_mac_buf, bad_kb->config.bt_mac, GAP_MAC_ADDR_SIZE);
|
||||
memmove(bad_kb->bt_mac_buf, bad_kb->config.bt_mac, BAD_KB_MAC_LEN);
|
||||
|
||||
byte_input_set_header_text(byte_input, "Set BT MAC address");
|
||||
|
||||
@@ -22,7 +22,7 @@ void bad_kb_scene_config_mac_on_enter(void* context) {
|
||||
NULL,
|
||||
bad_kb,
|
||||
bad_kb->bt_mac_buf,
|
||||
GAP_MAC_ADDR_SIZE);
|
||||
BAD_KB_MAC_LEN);
|
||||
|
||||
view_dispatcher_switch_to_view(bad_kb->view_dispatcher, BadKbAppViewByteInput);
|
||||
}
|
||||
@@ -34,7 +34,7 @@ bool bad_kb_scene_config_mac_on_event(void* context, SceneManagerEvent event) {
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
consumed = true;
|
||||
if(event.event == BadKbAppCustomEventByteInputDone) {
|
||||
memmove(bad_kb->config.bt_mac, bad_kb->bt_mac_buf, GAP_MAC_ADDR_SIZE);
|
||||
memmove(bad_kb->config.bt_mac, bad_kb->bt_mac_buf, BAD_KB_MAC_LEN);
|
||||
bt_set_profile_mac_address(bad_kb->bt, bad_kb->config.bt_mac);
|
||||
}
|
||||
scene_manager_previous_scene(bad_kb->scene_manager);
|
||||
|
||||
@@ -10,7 +10,7 @@ void bad_kb_scene_config_name_on_enter(void* context) {
|
||||
BadKbApp* bad_kb = context;
|
||||
TextInput* text_input = bad_kb->text_input;
|
||||
|
||||
strlcpy(bad_kb->bt_name_buf, bad_kb->config.bt_name, BAD_KB_ADV_NAME_MAX_LEN);
|
||||
strlcpy(bad_kb->bt_name_buf, bad_kb->config.bt_name, BAD_KB_NAME_LEN);
|
||||
|
||||
text_input_set_header_text(text_input, "Set BT device name");
|
||||
|
||||
@@ -19,7 +19,7 @@ void bad_kb_scene_config_name_on_enter(void* context) {
|
||||
bad_kb_scene_config_name_text_input_callback,
|
||||
bad_kb,
|
||||
bad_kb->bt_name_buf,
|
||||
BAD_KB_ADV_NAME_MAX_LEN,
|
||||
BAD_KB_NAME_LEN,
|
||||
true);
|
||||
|
||||
view_dispatcher_switch_to_view(bad_kb->view_dispatcher, BadKbAppViewTextInput);
|
||||
@@ -32,7 +32,7 @@ bool bad_kb_scene_config_name_on_event(void* context, SceneManagerEvent event) {
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
consumed = true;
|
||||
if(event.event == BadKbAppCustomEventTextInputDone) {
|
||||
strlcpy(bad_kb->config.bt_name, bad_kb->bt_name_buf, BAD_KB_ADV_NAME_MAX_LEN);
|
||||
strlcpy(bad_kb->config.bt_name, bad_kb->bt_name_buf, BAD_KB_NAME_LEN);
|
||||
bt_set_profile_adv_name(bad_kb->bt, bad_kb->config.bt_name);
|
||||
}
|
||||
scene_manager_previous_scene(bad_kb->scene_manager);
|
||||
|
||||
Reference in New Issue
Block a user