[FL-3113] BadUSB: disable CDC mode, USB mode switch fix (#2394)
This commit is contained in:
		
							parent
							
								
									d0c6c3402c
								
							
						
					
					
						commit
						bc06d407f3
					
				| @ -115,8 +115,12 @@ BadUsbApp* bad_usb_app_alloc(char* arg) { | |||||||
| 
 | 
 | ||||||
|     if(furi_hal_usb_is_locked()) { |     if(furi_hal_usb_is_locked()) { | ||||||
|         app->error = BadUsbAppErrorCloseRpc; |         app->error = BadUsbAppErrorCloseRpc; | ||||||
|  |         app->usb_if_prev = NULL; | ||||||
|         scene_manager_next_scene(app->scene_manager, BadUsbSceneError); |         scene_manager_next_scene(app->scene_manager, BadUsbSceneError); | ||||||
|     } else { |     } else { | ||||||
|  |         app->usb_if_prev = furi_hal_usb_get_config(); | ||||||
|  |         furi_check(furi_hal_usb_set_config(NULL, NULL)); | ||||||
|  | 
 | ||||||
|         if(!furi_string_empty(app->file_path)) { |         if(!furi_string_empty(app->file_path)) { | ||||||
|             app->bad_usb_script = bad_usb_script_open(app->file_path); |             app->bad_usb_script = bad_usb_script_open(app->file_path); | ||||||
|             bad_usb_script_set_keyboard_layout(app->bad_usb_script, app->keyboard_layout); |             bad_usb_script_set_keyboard_layout(app->bad_usb_script, app->keyboard_layout); | ||||||
| @ -138,6 +142,10 @@ void bad_usb_app_free(BadUsbApp* app) { | |||||||
|         app->bad_usb_script = NULL; |         app->bad_usb_script = NULL; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     if(app->usb_if_prev) { | ||||||
|  |         furi_check(furi_hal_usb_set_config(app->usb_if_prev, NULL)); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     // Views
 |     // Views
 | ||||||
|     view_dispatcher_remove_view(app->view_dispatcher, BadUsbAppViewWork); |     view_dispatcher_remove_view(app->view_dispatcher, BadUsbAppViewWork); | ||||||
|     bad_usb_free(app->bad_usb_view); |     bad_usb_free(app->bad_usb_view); | ||||||
|  | |||||||
| @ -14,6 +14,7 @@ | |||||||
| #include <gui/modules/variable_item_list.h> | #include <gui/modules/variable_item_list.h> | ||||||
| #include <gui/modules/widget.h> | #include <gui/modules/widget.h> | ||||||
| #include "views/bad_usb_view.h" | #include "views/bad_usb_view.h" | ||||||
|  | #include <furi_hal_usb.h> | ||||||
| 
 | 
 | ||||||
| #define BAD_USB_APP_BASE_FOLDER ANY_PATH("badusb") | #define BAD_USB_APP_BASE_FOLDER ANY_PATH("badusb") | ||||||
| #define BAD_USB_APP_PATH_LAYOUT_FOLDER BAD_USB_APP_BASE_FOLDER "/assets/layouts" | #define BAD_USB_APP_PATH_LAYOUT_FOLDER BAD_USB_APP_BASE_FOLDER "/assets/layouts" | ||||||
| @ -39,6 +40,8 @@ struct BadUsbApp { | |||||||
|     FuriString* keyboard_layout; |     FuriString* keyboard_layout; | ||||||
|     BadUsb* bad_usb_view; |     BadUsb* bad_usb_view; | ||||||
|     BadUsbScript* bad_usb_script; |     BadUsbScript* bad_usb_script; | ||||||
|  | 
 | ||||||
|  |     FuriHalUsbInterface* usb_if_prev; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| typedef enum { | typedef enum { | ||||||
|  | |||||||
| @ -490,8 +490,6 @@ static int32_t bad_usb_worker(void* context) { | |||||||
|     BadUsbWorkerState worker_state = BadUsbStateInit; |     BadUsbWorkerState worker_state = BadUsbStateInit; | ||||||
|     int32_t delay_val = 0; |     int32_t delay_val = 0; | ||||||
| 
 | 
 | ||||||
|     FuriHalUsbInterface* usb_mode_prev = furi_hal_usb_get_config(); |  | ||||||
| 
 |  | ||||||
|     FURI_LOG_I(WORKER_TAG, "Init"); |     FURI_LOG_I(WORKER_TAG, "Init"); | ||||||
|     File* script_file = storage_file_alloc(furi_record_open(RECORD_STORAGE)); |     File* script_file = storage_file_alloc(furi_record_open(RECORD_STORAGE)); | ||||||
|     bad_usb->line = furi_string_alloc(); |     bad_usb->line = furi_string_alloc(); | ||||||
| @ -642,8 +640,6 @@ static int32_t bad_usb_worker(void* context) { | |||||||
| 
 | 
 | ||||||
|     furi_hal_hid_set_state_callback(NULL, NULL); |     furi_hal_hid_set_state_callback(NULL, NULL); | ||||||
| 
 | 
 | ||||||
|     furi_hal_usb_set_config(usb_mode_prev, NULL); |  | ||||||
| 
 |  | ||||||
|     storage_file_close(script_file); |     storage_file_close(script_file); | ||||||
|     storage_file_free(script_file); |     storage_file_free(script_file); | ||||||
|     furi_string_free(bad_usb->line); |     furi_string_free(bad_usb->line); | ||||||
|  | |||||||
| @ -340,7 +340,7 @@ static void usb_process_mode_start(FuriHalUsbInterface* interface, void* context | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static void usb_process_mode_change(FuriHalUsbInterface* interface, void* context) { | static void usb_process_mode_change(FuriHalUsbInterface* interface, void* context) { | ||||||
|     if(interface != usb.interface) { |     if((interface != usb.interface) || (context != usb.interface_context)) { | ||||||
|         if(usb.enabled) { |         if(usb.enabled) { | ||||||
|             // Disable current interface
 |             // Disable current interface
 | ||||||
|             susp_evt(&udev, 0, 0); |             susp_evt(&udev, 0, 0); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Nikolay Minaylov
						Nikolay Minaylov