BadKB: Choose BT Pairing security mode (YesNo, PIN Type, Pin Y/N)

This commit is contained in:
Willy-JL
2024-04-17 02:47:23 +01:00
parent a19598c44d
commit 5798446a09
4 changed files with 45 additions and 4 deletions

View File

@@ -36,6 +36,7 @@ void bad_kb_load_settings(BadKbApp* app) {
FlipperFormat* file = flipper_format_file_alloc(storage);
if(flipper_format_file_open_existing(file, BAD_KB_SETTINGS_PATH)) {
FuriString* tmp_str = furi_string_alloc();
uint32_t tmp_uint = 0;
if(!flipper_format_read_string(file, "Keyboard_Layout", app->keyboard_layout)) {
furi_string_reset(app->keyboard_layout);
@@ -52,6 +53,12 @@ void bad_kb_load_settings(BadKbApp* app) {
flipper_format_rewind(file);
}
if(!flipper_format_read_uint32(file, "Bt_Pairing", &tmp_uint, 1)) {
tmp_uint = GapPairingNone;
flipper_format_rewind(file);
}
cfg->ble.pairing = tmp_uint;
if(flipper_format_read_string(file, "Bt_Name", tmp_str)) {
strlcpy(cfg->ble.name, furi_string_get_cstr(tmp_str), sizeof(cfg->ble.name));
} else {
@@ -115,9 +122,12 @@ static void bad_kb_save_settings(BadKbApp* app) {
Storage* storage = furi_record_open(RECORD_STORAGE);
FlipperFormat* file = flipper_format_file_alloc(storage);
if(flipper_format_file_open_always(file, BAD_KB_SETTINGS_PATH)) {
uint32_t tmp_uint = 0;
flipper_format_write_string(file, "Keyboard_Layout", app->keyboard_layout);
flipper_format_write_bool(file, "Is_Bt", &app->is_bt, 1);
flipper_format_write_bool(file, "Bt_Remember", &cfg->ble.bonding, 1);
tmp_uint = cfg->ble.pairing;
flipper_format_write_uint32(file, "Bt_Pairing", &tmp_uint, 1);
flipper_format_write_string_cstr(file, "Bt_Name", cfg->ble.name);
flipper_format_write_hex(file, "Bt_Mac", (uint8_t*)&cfg->ble.mac, sizeof(cfg->ble.mac));
flipper_format_write_string_cstr(file, "Usb_Manuf", cfg->usb.manuf);
@@ -147,12 +157,9 @@ int32_t bad_kb_conn_apply(BadKbApp* app) {
BadKbConfig* cfg = app->set_bt_id ? &app->id_config : &app->config;
memcpy(&app->cur_ble_cfg, &cfg->ble, sizeof(cfg->ble));
if(app->cur_ble_cfg.bonding) {
app->cur_ble_cfg.pairing = GapPairingPinCodeVerifyYesNo;
// Hardcode mac for remember mode
// Change in config copy to preserve user choice for non-remember mode
memcpy(app->cur_ble_cfg.mac, BAD_KB_BOUND_MAC, sizeof(BAD_KB_BOUND_MAC));
} else {
app->cur_ble_cfg.pairing = GapPairingNone;
}
// Prepare for new profile
@@ -249,6 +256,7 @@ void bad_kb_config_refresh(BadKbApp* app) {
} else {
BleProfileHidParams* cur = &app->cur_ble_cfg;
apply = apply || cfg->ble.bonding != cur->bonding;
apply = apply || cfg->ble.pairing != cur->pairing;
apply = apply || strncmp(cfg->ble.name, cur->name, sizeof(cfg->ble.name));
apply = apply || memcmp(cfg->ble.mac, cur->mac, sizeof(cfg->ble.mac));
}

View File

@@ -345,8 +345,9 @@ static bool ducky_set_bt_id(BadKbScript* bad_kb, const char* line) {
strlcpy(cfg->ble.name, line + mac_len, sizeof(cfg->ble.name));
FURI_LOG_D(WORKER_TAG, "set bt id: %s", line);
// Can't set bonding via BT_ID, sync with user choice instead
// Can't set bonding and pairing via BT_ID, sync with user choice instead
cfg->ble.bonding = bad_kb->app->config.ble.bonding;
cfg->ble.pairing = bad_kb->app->config.ble.pairing;
return true;
}

View File

@@ -8,6 +8,7 @@ enum VarItemListIndex {
enum VarItemListIndexBt {
VarItemListIndexBtRemember = VarItemListIndexConnection + 1,
VarItemListIndexBtPairing,
VarItemListIndexBtDeviceName,
VarItemListIndexBtMacAddress,
VarItemListIndexBtRandomizeMac,
@@ -40,6 +41,24 @@ void bad_kb_scene_config_bt_remember_callback(VariableItem* item) {
view_dispatcher_send_custom_event(bad_kb->view_dispatcher, VarItemListIndexBtRemember);
}
const char* const bt_pairing_names[GapPairingCount] = {
"YesNo",
"PIN Type",
"PIN Y/N",
};
void bad_kb_scene_config_bt_pairing_callback(VariableItem* item) {
BadKbApp* bad_kb = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item);
// Set user config and remember
bad_kb->config.ble.pairing = index;
// Apply to ID config so its temporarily overridden (currently can't set pairing with BT_ID anyway)
if(bad_kb->set_bt_id) {
bad_kb->id_config.ble.pairing = index;
}
variable_item_set_current_value_text(item, bt_pairing_names[index]);
view_dispatcher_send_custom_event(bad_kb->view_dispatcher, VarItemListIndexBtPairing);
}
void bad_kb_scene_config_var_item_list_callback(void* context, uint32_t index) {
BadKbApp* bad_kb = context;
view_dispatcher_send_custom_event(bad_kb->view_dispatcher, index);
@@ -65,6 +84,15 @@ void bad_kb_scene_config_on_enter(void* context) {
variable_item_set_current_value_index(item, cfg->ble.bonding);
variable_item_set_current_value_text(item, cfg->ble.bonding ? "ON" : "OFF");
item = variable_item_list_add(
var_item_list,
"BT Pairing",
GapPairingCount,
bad_kb_scene_config_bt_pairing_callback,
bad_kb);
variable_item_set_current_value_index(item, cfg->ble.pairing);
variable_item_set_current_value_text(item, bt_pairing_names[cfg->ble.pairing]);
item = variable_item_list_add(var_item_list, "BT Device Name", 0, NULL, bad_kb);
item = variable_item_list_add(var_item_list, "BT MAC Address", 0, NULL, bad_kb);
@@ -117,6 +145,9 @@ bool bad_kb_scene_config_on_event(void* context, SceneManagerEvent event) {
case VarItemListIndexBtRemember:
bad_kb_config_refresh(bad_kb);
break;
case VarItemListIndexBtPairing:
bad_kb_config_refresh(bad_kb);
break;
case VarItemListIndexBtDeviceName:
scene_manager_next_scene(bad_kb->scene_manager, BadKbSceneConfigBtName);
break;

View File

@@ -52,6 +52,7 @@ typedef enum {
GapPairingNone,
GapPairingPinCodeShow,
GapPairingPinCodeVerifyYesNo,
GapPairingCount,
} GapPairing;
typedef struct {