mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2025-12-12 04:34:43 +04:00
hal: additional fixes for constness in USB subsystem
This commit is contained in:
@@ -44,7 +44,7 @@ struct BadUsbApp {
|
||||
BadUsbScript* bad_usb_script;
|
||||
|
||||
BadUsbHidInterface interface;
|
||||
FuriHalUsbInterface* usb_if_prev;
|
||||
const FuriHalUsbInterface* usb_if_prev;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
|
||||
@@ -189,7 +189,7 @@ static int32_t u2f_hid_worker(void* context) {
|
||||
|
||||
FURI_LOG_D(WORKER_TAG, "Init");
|
||||
|
||||
FuriHalUsbInterface* usb_mode_prev = furi_hal_usb_get_config();
|
||||
const FuriHalUsbInterface* usb_mode_prev = furi_hal_usb_get_config();
|
||||
furi_check(furi_hal_usb_set_config(&usb_hid_u2f, NULL) == true);
|
||||
|
||||
u2f_hid->lock_timer =
|
||||
|
||||
@@ -40,7 +40,7 @@ typedef struct {
|
||||
volatile bool connected;
|
||||
volatile bool running;
|
||||
|
||||
FuriHalUsbInterface* usb_if_prev;
|
||||
const FuriHalUsbInterface* usb_if_prev;
|
||||
|
||||
uint8_t data_buffer[USB_CDC_PKT_LEN];
|
||||
} CliVcp;
|
||||
|
||||
@@ -174,7 +174,7 @@ int32_t hid_usb_app(void* p) {
|
||||
|
||||
FURI_LOG_D("HID", "Starting as USB app");
|
||||
|
||||
FuriHalUsbInterface* usb_mode_prev = furi_hal_usb_get_config();
|
||||
const FuriHalUsbInterface* usb_mode_prev = furi_hal_usb_get_config();
|
||||
furi_hal_usb_unlock();
|
||||
furi_check(furi_hal_usb_set_config(&usb_hid, NULL) == true);
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
typedef struct {
|
||||
FuriHalUsbHidConfig* hid_cfg;
|
||||
uint16_t layout[128];
|
||||
FuriHalUsbInterface* usb_if_prev;
|
||||
const FuriHalUsbInterface* usb_if_prev;
|
||||
uint8_t key_hold_cnt;
|
||||
} JsBadusbInst;
|
||||
|
||||
|
||||
@@ -1489,12 +1489,12 @@ Function,+,furi_hal_usb_ccid_remove_smartcard,void,
|
||||
Function,+,furi_hal_usb_ccid_set_callbacks,void,"CcidCallbacks*, void*"
|
||||
Function,+,furi_hal_usb_disable,void,
|
||||
Function,+,furi_hal_usb_enable,void,
|
||||
Function,+,furi_hal_usb_get_config,FuriHalUsbInterface*,
|
||||
Function,+,furi_hal_usb_get_config,const FuriHalUsbInterface*,
|
||||
Function,-,furi_hal_usb_init,void,
|
||||
Function,+,furi_hal_usb_is_locked,_Bool,
|
||||
Function,+,furi_hal_usb_lock,void,
|
||||
Function,+,furi_hal_usb_reinit,void,
|
||||
Function,+,furi_hal_usb_set_config,_Bool,"FuriHalUsbInterface*, void*"
|
||||
Function,+,furi_hal_usb_set_config,_Bool,"const FuriHalUsbInterface*, void*"
|
||||
Function,-,furi_hal_usb_set_state_callback,void,"FuriHalUsbStateCallback, void*"
|
||||
Function,+,furi_hal_usb_unlock,void,
|
||||
Function,+,furi_hal_version_do_i_belong_here,_Bool,
|
||||
|
||||
|
@@ -1709,12 +1709,12 @@ Function,+,furi_hal_usb_ccid_remove_smartcard,void,
|
||||
Function,+,furi_hal_usb_ccid_set_callbacks,void,"CcidCallbacks*, void*"
|
||||
Function,+,furi_hal_usb_disable,void,
|
||||
Function,+,furi_hal_usb_enable,void,
|
||||
Function,+,furi_hal_usb_get_config,FuriHalUsbInterface*,
|
||||
Function,+,furi_hal_usb_get_config,const FuriHalUsbInterface*,
|
||||
Function,-,furi_hal_usb_init,void,
|
||||
Function,+,furi_hal_usb_is_locked,_Bool,
|
||||
Function,+,furi_hal_usb_lock,void,
|
||||
Function,+,furi_hal_usb_reinit,void,
|
||||
Function,+,furi_hal_usb_set_config,_Bool,"FuriHalUsbInterface*, void*"
|
||||
Function,+,furi_hal_usb_set_config,_Bool,"const FuriHalUsbInterface*, void*"
|
||||
Function,-,furi_hal_usb_set_state_callback,void,"FuriHalUsbStateCallback, void*"
|
||||
Function,+,furi_hal_usb_unlock,void,
|
||||
Function,+,furi_hal_version_do_i_belong_here,_Bool,
|
||||
|
||||
|
@@ -32,7 +32,7 @@ typedef struct {
|
||||
} UsbApiEventDataStateCallback;
|
||||
|
||||
typedef struct {
|
||||
FuriHalUsbInterface* interface;
|
||||
const FuriHalUsbInterface* interface;
|
||||
void* context;
|
||||
} UsbApiEventDataInterface;
|
||||
|
||||
@@ -43,7 +43,7 @@ typedef union {
|
||||
|
||||
typedef union {
|
||||
bool bool_value;
|
||||
void* void_value;
|
||||
const void* void_value;
|
||||
} UsbApiEventReturnData;
|
||||
|
||||
typedef struct {
|
||||
@@ -60,7 +60,7 @@ typedef struct {
|
||||
bool connected;
|
||||
bool mode_lock;
|
||||
bool request_pending;
|
||||
FuriHalUsbInterface* interface;
|
||||
const FuriHalUsbInterface* interface;
|
||||
void* interface_context;
|
||||
FuriHalUsbStateCallback callback;
|
||||
void* callback_context;
|
||||
@@ -132,7 +132,7 @@ static void furi_hal_usb_send_message(UsbApiEventMessage* message) {
|
||||
api_lock_wait_unlock_and_free(message->lock);
|
||||
}
|
||||
|
||||
bool furi_hal_usb_set_config(FuriHalUsbInterface* new_if, void* ctx) {
|
||||
bool furi_hal_usb_set_config(const FuriHalUsbInterface* new_if, void* ctx) {
|
||||
UsbApiEventReturnData return_data = {
|
||||
.bool_value = false,
|
||||
};
|
||||
@@ -152,7 +152,7 @@ bool furi_hal_usb_set_config(FuriHalUsbInterface* new_if, void* ctx) {
|
||||
return return_data.bool_value;
|
||||
}
|
||||
|
||||
FuriHalUsbInterface* furi_hal_usb_get_config(void) {
|
||||
const FuriHalUsbInterface* furi_hal_usb_get_config(void) {
|
||||
UsbApiEventReturnData return_data = {
|
||||
.void_value = NULL,
|
||||
};
|
||||
@@ -326,7 +326,7 @@ static void wkup_evt(usbd_device* dev, uint8_t event, uint8_t ep) {
|
||||
}
|
||||
}
|
||||
|
||||
static void usb_process_mode_start(FuriHalUsbInterface* interface, void* context) {
|
||||
static void usb_process_mode_start(const FuriHalUsbInterface* interface, void* context) {
|
||||
if(usb.interface != NULL) {
|
||||
usb.interface->deinit(&udev);
|
||||
}
|
||||
@@ -344,7 +344,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(const FuriHalUsbInterface* interface, void* context) {
|
||||
if((interface != usb.interface) || (context != usb.interface_context)) {
|
||||
if(usb.enabled) {
|
||||
// Disable current interface
|
||||
@@ -374,7 +374,7 @@ static void usb_process_mode_reinit(void) {
|
||||
usb_process_mode_start(usb.interface, usb.interface_context);
|
||||
}
|
||||
|
||||
static bool usb_process_set_config(FuriHalUsbInterface* interface, void* context) {
|
||||
static bool usb_process_set_config(const FuriHalUsbInterface* interface, void* context) {
|
||||
if(usb.mode_lock) {
|
||||
return false;
|
||||
} else {
|
||||
|
||||
@@ -170,7 +170,7 @@ static const struct CcidConfigDescriptor ccid_cfg_desc = {
|
||||
},
|
||||
};
|
||||
|
||||
static void ccid_init(usbd_device* dev, FuriHalUsbInterface* intf, void* ctx);
|
||||
static void ccid_init(usbd_device* dev, const FuriHalUsbInterface* intf, void* ctx);
|
||||
static void ccid_deinit(usbd_device* dev);
|
||||
static void ccid_on_wakeup(usbd_device* dev);
|
||||
static void ccid_on_suspend(usbd_device* dev);
|
||||
@@ -223,7 +223,7 @@ static void* ccid_set_string_descr(char* str) {
|
||||
return dev_str_desc;
|
||||
}
|
||||
|
||||
static void ccid_init(usbd_device* dev, FuriHalUsbInterface* intf, void* ctx) {
|
||||
static void ccid_init(usbd_device* dev, const FuriHalUsbInterface* intf, void* ctx) {
|
||||
UNUSED(intf);
|
||||
|
||||
FuriHalUsbCcidConfig* cfg = (FuriHalUsbCcidConfig*)ctx;
|
||||
|
||||
@@ -385,7 +385,7 @@ static const struct CdcConfigDescriptorDual
|
||||
static struct usb_cdc_line_coding cdc_config[IF_NUM_MAX] = {};
|
||||
static uint8_t cdc_ctrl_line_state[IF_NUM_MAX];
|
||||
|
||||
static void cdc_init(usbd_device* dev, FuriHalUsbInterface* intf, void* ctx);
|
||||
static void cdc_init(usbd_device* dev, const FuriHalUsbInterface* intf, void* ctx);
|
||||
static void cdc_deinit(usbd_device* dev);
|
||||
static void cdc_on_wakeup(usbd_device* dev);
|
||||
static void cdc_on_suspend(usbd_device* dev);
|
||||
@@ -429,10 +429,11 @@ FuriHalUsbInterface usb_cdc_dual = {
|
||||
.cfg_descr = (void*)&cdc_cfg_desc_dual,
|
||||
};
|
||||
|
||||
static void cdc_init(usbd_device* dev, FuriHalUsbInterface* intf, void* ctx) {
|
||||
static void cdc_init(usbd_device* dev, const FuriHalUsbInterface* intf, void* ctx) {
|
||||
UNUSED(ctx);
|
||||
usb_dev = dev;
|
||||
cdc_if_cur = intf;
|
||||
cdc_if_cur = malloc(sizeof(FuriHalUsbInterface));
|
||||
memcpy((void*)cdc_if_cur, intf, sizeof(FuriHalUsbInterface));
|
||||
|
||||
char* name = (char*)furi_hal_version_get_device_name_ptr();
|
||||
uint8_t len = (name == NULL) ? (0) : (strlen(name));
|
||||
@@ -469,6 +470,7 @@ static void cdc_deinit(usbd_device* dev) {
|
||||
free(cdc_if_cur->str_prod_descr);
|
||||
free(cdc_if_cur->str_serial_descr);
|
||||
|
||||
free((void*)cdc_if_cur);
|
||||
cdc_if_cur = NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -226,7 +226,7 @@ static struct HidReport {
|
||||
struct HidReportConsumer consumer;
|
||||
} FURI_PACKED hid_report;
|
||||
|
||||
static void hid_init(usbd_device* dev, FuriHalUsbInterface* intf, void* ctx);
|
||||
static void hid_init(usbd_device* dev, const FuriHalUsbInterface* intf, void* ctx);
|
||||
static void hid_deinit(usbd_device* dev);
|
||||
static void hid_on_wakeup(usbd_device* dev);
|
||||
static void hid_on_suspend(usbd_device* dev);
|
||||
@@ -374,7 +374,7 @@ static void* hid_set_string_descr(char* str) {
|
||||
return dev_str_desc;
|
||||
}
|
||||
|
||||
static void hid_init(usbd_device* dev, FuriHalUsbInterface* intf, void* ctx) {
|
||||
static void hid_init(usbd_device* dev, const FuriHalUsbInterface* intf, void* ctx) {
|
||||
UNUSED(intf);
|
||||
FuriHalUsbHidConfig* cfg = (FuriHalUsbHidConfig*)ctx;
|
||||
if(hid_semaphore == NULL) hid_semaphore = furi_semaphore_alloc(1, 1);
|
||||
|
||||
@@ -137,7 +137,7 @@ static const struct HidConfigDescriptor hid_u2f_cfg_desc = {
|
||||
},
|
||||
};
|
||||
|
||||
static void hid_u2f_init(usbd_device* dev, FuriHalUsbInterface* intf, void* ctx);
|
||||
static void hid_u2f_init(usbd_device* dev, const FuriHalUsbInterface* intf, void* ctx);
|
||||
static void hid_u2f_deinit(usbd_device* dev);
|
||||
static void hid_u2f_on_wakeup(usbd_device* dev);
|
||||
static void hid_u2f_on_suspend(usbd_device* dev);
|
||||
@@ -189,7 +189,7 @@ const FuriHalUsbInterface usb_hid_u2f = {
|
||||
.cfg_descr = (void*)&hid_u2f_cfg_desc,
|
||||
};
|
||||
|
||||
static void hid_u2f_init(usbd_device* dev, FuriHalUsbInterface* intf, void* ctx) {
|
||||
static void hid_u2f_init(usbd_device* dev, const FuriHalUsbInterface* intf, void* ctx) {
|
||||
UNUSED(intf);
|
||||
UNUSED(ctx);
|
||||
if(hid_u2f_semaphore == NULL) {
|
||||
|
||||
@@ -9,7 +9,7 @@ extern "C" {
|
||||
typedef struct FuriHalUsbInterface FuriHalUsbInterface;
|
||||
|
||||
struct FuriHalUsbInterface {
|
||||
void (*init)(usbd_device* dev, FuriHalUsbInterface* intf, void* ctx);
|
||||
void (*init)(usbd_device* dev, const FuriHalUsbInterface* intf, void* ctx);
|
||||
void (*deinit)(usbd_device* dev);
|
||||
void (*wakeup)(usbd_device* dev);
|
||||
void (*suspend)(usbd_device* dev);
|
||||
@@ -49,13 +49,13 @@ void furi_hal_usb_init(void);
|
||||
* @param ctx context passed to device mode init function
|
||||
* @return true - mode switch started, false - mode switch is locked
|
||||
*/
|
||||
bool furi_hal_usb_set_config(FuriHalUsbInterface* new_if, void* ctx);
|
||||
bool furi_hal_usb_set_config(const FuriHalUsbInterface* new_if, void* ctx);
|
||||
|
||||
/** Get USB device configuration
|
||||
*
|
||||
* @return current USB device mode
|
||||
*/
|
||||
FuriHalUsbInterface* furi_hal_usb_get_config(void);
|
||||
const FuriHalUsbInterface* furi_hal_usb_get_config(void);
|
||||
|
||||
/** Lock USB device mode switch
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user