BadKB fix VID/PID handling + adjust cfg at start

This commit is contained in:
Willy-JL
2023-06-11 23:48:14 +01:00
parent 576aecbb8a
commit 004ca02773
5 changed files with 30 additions and 20 deletions

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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;

View File

@@ -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) */