mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-24 03:29:57 -07:00
Restores bt mac @ and adv name before quitting bad usb app
This commit is contained in:
@@ -99,9 +99,11 @@ BadUsbApp* bad_usb_app_alloc(char* arg) {
|
||||
app->bt = bt;
|
||||
const char* adv_name = bt_get_profile_adv_name(bt);
|
||||
memcpy(app->name, adv_name, BAD_USB_ADV_NAME_MAX_LEN);
|
||||
memcpy(app->bt_old_config.name, adv_name, BAD_USB_ADV_NAME_MAX_LEN);
|
||||
|
||||
const uint8_t* mac_addr = bt_get_profile_mac_address(bt);
|
||||
memcpy(app->mac, mac_addr, BAD_USB_MAC_ADDRESS_LEN);
|
||||
memcpy(app->bt_old_config.mac, mac_addr, BAD_USB_MAC_ADDRESS_LEN);
|
||||
|
||||
// Custom Widget
|
||||
app->widget = widget_alloc();
|
||||
@@ -180,6 +182,17 @@ void bad_usb_app_free(BadUsbApp* app) {
|
||||
view_dispatcher_free(app->view_dispatcher);
|
||||
scene_manager_free(app->scene_manager);
|
||||
|
||||
// restores bt config
|
||||
// BtProfile have already been switched to the previous one
|
||||
// so we directly modify the right profile
|
||||
if (strcmp(app->bt_old_config.name, app->name) != 0) {
|
||||
furi_hal_bt_set_profile_adv_name(FuriHalBtProfileHidKeyboard, app->bt_old_config.name);
|
||||
}
|
||||
if (memcmp(app->bt_old_config.mac, app->mac, BAD_USB_MAC_ADDRESS_LEN) != 0) {
|
||||
furi_hal_bt_set_profile_mac_addr(FuriHalBtProfileHidKeyboard, app->bt_old_config.mac);
|
||||
}
|
||||
|
||||
|
||||
// Close records
|
||||
furi_record_close(RECORD_GUI);
|
||||
furi_record_close(RECORD_NOTIFICATION);
|
||||
|
||||
@@ -35,6 +35,15 @@ typedef enum BadUsbCustomEvent {
|
||||
BadUsbCustomEventErrorBack
|
||||
} BadUsbCustomEvent;
|
||||
|
||||
typedef struct {
|
||||
uint8_t mac[BAD_USB_MAC_ADDRESS_LEN];
|
||||
char name[BAD_USB_ADV_NAME_MAX_LEN + 1];
|
||||
|
||||
// number of bt keys before starting the app (all keys added in
|
||||
// the bt keys file then will be removed)
|
||||
uint16_t n_keys;
|
||||
} BadUsbBtConfig;
|
||||
|
||||
struct BadUsbApp {
|
||||
Gui* gui;
|
||||
ViewDispatcher* view_dispatcher;
|
||||
@@ -50,6 +59,7 @@ struct BadUsbApp {
|
||||
ByteInput* byte_input;
|
||||
uint8_t mac[BAD_USB_MAC_ADDRESS_LEN];
|
||||
char name[BAD_USB_ADV_NAME_MAX_LEN + 1];
|
||||
BadUsbBtConfig bt_old_config;
|
||||
|
||||
BadUsbAppError error;
|
||||
FuriString* file_path;
|
||||
|
||||
@@ -648,8 +648,7 @@ static int32_t bad_usb_worker(void* context) {
|
||||
bt_disconnect(bad_usb->bt);
|
||||
furi_delay_ms(200);
|
||||
bt_keys_storage_set_storage_path(bad_usb->bt, HID_BT_KEYS_STORAGE_PATH);
|
||||
|
||||
if(!bt_set_profile(bad_usb->bt, BtProfileHidKeyboard)) {
|
||||
if (!bt_set_profile(bad_usb->bt, BtProfileHidKeyboard)) {
|
||||
FURI_LOG_E(TAG, "Failed to switch to HID profile");
|
||||
return -1;
|
||||
}
|
||||
@@ -849,10 +848,10 @@ static int32_t bad_usb_worker(void* context) {
|
||||
bt_keys_storage_set_default_path(bad_usb->bt);
|
||||
|
||||
bt_set_profile_pairing_method(bad_usb->bt, old_pairing_method);
|
||||
|
||||
if(!bt_set_profile(bad_usb->bt, BtProfileSerial)) {
|
||||
FURI_LOG_E(TAG, "Failed to switch to Serial profile");
|
||||
}
|
||||
|
||||
// fails if ble radio stack isn't ready when switching profile
|
||||
// if it happens, maybe we should increase the delay after bt_disconnect
|
||||
bt_set_profile(bad_usb->bt, BtProfileSerial);
|
||||
} else {
|
||||
furi_hal_hid_set_state_callback(NULL, NULL);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user