diff --git a/applications/main/bad_kb/bad_kb_app.c b/applications/main/bad_kb/bad_kb_app.c index f4c771691..987c35a93 100644 --- a/applications/main/bad_kb/bad_kb_app.c +++ b/applications/main/bad_kb/bad_kb_app.c @@ -130,6 +130,7 @@ BadKbApp* bad_kb_app_alloc(char* arg) { app->bt->suppress_pin_screen = true; app->is_bt = XTREME_SETTINGS()->bad_bt; app->bt_remember = XTREME_SETTINGS()->bad_bt_remember; + bad_kb_config_adjust(&app->config); // Save prev config BadKbConfig* prev = &app->prev_config; diff --git a/applications/main/bad_kb/helpers/ducky_script.c b/applications/main/bad_kb/helpers/ducky_script.c index 16e7d04fd..7881be52d 100644 --- a/applications/main/bad_kb/helpers/ducky_script.c +++ b/applications/main/bad_kb/helpers/ducky_script.c @@ -588,6 +588,23 @@ void bad_kb_conn_reset(BadKbApp* app) { app->conn_mode = BadKbConnModeNone; } +void bad_kb_config_adjust(BadKbConfig* cfg) { + // MAC is adjusted by furi_hal_bt, adjust here too so it matches after applying + const uint8_t* normal_mac = furi_hal_version_get_ble_mac(); + uint8_t empty_mac[BAD_KB_MAC_LEN] = FURI_HAL_BT_EMPTY_MAC_ADDR; + uint8_t default_mac[BAD_KB_MAC_LEN] = FURI_HAL_BT_DEFAULT_MAC_ADDR; + if(memcmp(cfg->bt_mac, empty_mac, BAD_KB_MAC_LEN) == 0 || + memcmp(cfg->bt_mac, normal_mac, BAD_KB_MAC_LEN) == 0 || + memcmp(cfg->bt_mac, default_mac, BAD_KB_MAC_LEN) == 0) { + memcpy(cfg->bt_mac, normal_mac, BAD_KB_MAC_LEN); + cfg->bt_mac[2]++; + } + + // Use defaults if vid or pid are unset + if(cfg->usb_cfg.vid == 0) cfg->usb_cfg.vid = HID_VID_DEFAULT; + if(cfg->usb_cfg.pid == 0) cfg->usb_cfg.pid = HID_PID_DEFAULT; +} + void bad_kb_config_refresh(BadKbApp* app) { bt_set_status_changed_callback(app->bt, NULL, NULL); furi_hal_hid_set_state_callback(NULL, NULL); @@ -601,17 +618,7 @@ void bad_kb_config_refresh(BadKbApp* app) { bool apply = false; if(app->is_bt) { BadKbConfig* cfg = app->set_bt_id ? &app->id_config : &app->config; - - // MAC is adjusted by furi_hal_bt, adjust here too so it matches after applying - const uint8_t* normal_mac = furi_hal_version_get_ble_mac(); - uint8_t empty_mac[BAD_KB_MAC_LEN] = FURI_HAL_BT_EMPTY_MAC_ADDR; - uint8_t default_mac[BAD_KB_MAC_LEN] = FURI_HAL_BT_DEFAULT_MAC_ADDR; - if(memcmp(cfg->bt_mac, empty_mac, BAD_KB_MAC_LEN) == 0 || - memcmp(cfg->bt_mac, normal_mac, BAD_KB_MAC_LEN) == 0 || - memcmp(cfg->bt_mac, default_mac, BAD_KB_MAC_LEN) == 0) { - memcpy(cfg->bt_mac, normal_mac, BAD_KB_MAC_LEN); - cfg->bt_mac[2]++; - } + bad_kb_config_adjust(cfg); if(app->conn_mode != BadKbConnModeBt) { apply = true; @@ -627,8 +634,8 @@ void bad_kb_config_refresh(BadKbApp* app) { BAD_KB_MAC_LEN); } } else { - FuriHalUsbHidConfig* cfg = app->set_usb_id ? &app->id_config.usb_cfg : - &app->config.usb_cfg; + BadKbConfig* cfg = app->set_usb_id ? &app->id_config : &app->config; + bad_kb_config_adjust(cfg); if(app->conn_mode != BadKbConnModeUsb) { apply = true; @@ -638,10 +645,10 @@ void bad_kb_config_refresh(BadKbApp* app) { if(furi_hal_usb_get_config() == &usb_hid && (ctx = furi_hal_usb_get_config_context()) != NULL) { FuriHalUsbHidConfig* cur = ctx; - apply = apply || cfg->vid != cur->vid; - apply = apply || cfg->pid != cur->pid; - apply = apply || strncmp(cfg->manuf, cur->manuf, sizeof(cur->manuf)); - apply = apply || strncmp(cfg->product, cur->product, sizeof(cur->product)); + apply = apply || cfg->usb_cfg.vid != cur->vid; + apply = apply || cfg->usb_cfg.pid != cur->pid; + apply = apply || strncmp(cfg->usb_cfg.manuf, cur->manuf, sizeof(cur->manuf)); + apply = apply || strncmp(cfg->usb_cfg.product, cur->product, sizeof(cur->product)); } else { apply = true; } diff --git a/applications/main/bad_kb/helpers/ducky_script.h b/applications/main/bad_kb/helpers/ducky_script.h index fa4f1df86..b027c3f56 100644 --- a/applications/main/bad_kb/helpers/ducky_script.h +++ b/applications/main/bad_kb/helpers/ducky_script.h @@ -169,6 +169,8 @@ void bad_kb_conn_reset(BadKbApp* app); void bad_kb_config_refresh(BadKbApp* app); +void bad_kb_config_adjust(BadKbConfig* cfg); + #ifdef __cplusplus } #endif diff --git a/firmware/targets/f7/furi_hal/furi_hal_usb_hid.c b/firmware/targets/f7/furi_hal/furi_hal_usb_hid.c index 334aa0102..a7a5742ef 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_usb_hid.c +++ b/firmware/targets/f7/furi_hal/furi_hal_usb_hid.c @@ -12,9 +12,6 @@ #define HID_INTERVAL 2 -#define HID_VID_DEFAULT 0x046D -#define HID_PID_DEFAULT 0xC529 - struct HidIntfDescriptor { struct usb_interface_descriptor hid; struct usb_hid_descriptor hid_desc; diff --git a/firmware/targets/furi_hal_include/furi_hal_usb_hid.h b/firmware/targets/furi_hal_include/furi_hal_usb_hid.h index 13e83ef67..b1e6da31b 100644 --- a/firmware/targets/furi_hal_include/furi_hal_usb_hid.h +++ b/firmware/targets/furi_hal_include/furi_hal_usb_hid.h @@ -9,6 +9,9 @@ extern "C" { #endif +#define HID_VID_DEFAULT 0x046D +#define HID_PID_DEFAULT 0xC529 + /** Max number of simultaneously pressed keys (keyboard) */ #define HID_KB_MAX_KEYS 6 /** Max number of simultaneously pressed keys (consumer control) */