diff --git a/CHANGELOG.md b/CHANGELOG.md index 03497a26a..a77b868d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ - OFW: CCID: App changes and improvements (by @kidbomb) - OFW: API: Exposed `view_dispatcher_get_event_loop` (by @CookiePLMonster) - Furi: + - UL: Extra checks for OTG power enable/disable (by @xMasterX) - OFW: Replace all calls to strncpy with strlcpy, use strdup more, expose strlcat (by @CookiePLMonster) - OFW: Threading, Timers improvements (by @CookiePLMonster) - OFW: FuriTimer uses an event instead of a volatile bool to wait for deletion (by @CookiePLMonster) diff --git a/applications/main/gpio/scenes/gpio_scene_start.c b/applications/main/gpio/scenes/gpio_scene_start.c index f28b58b23..a3ec8559f 100644 --- a/applications/main/gpio/scenes/gpio_scene_start.c +++ b/applications/main/gpio/scenes/gpio_scene_start.c @@ -94,9 +94,9 @@ bool gpio_scene_start_on_event(void* context, SceneManagerEvent event) { if(event.type == SceneManagerEventTypeCustom) { if(event.event == GpioStartEventOtgOn) { - furi_hal_power_enable_otg(); + if(!furi_hal_power_is_otg_enabled()) furi_hal_power_enable_otg(); } else if(event.event == GpioStartEventOtgOff) { - furi_hal_power_disable_otg(); + if(furi_hal_power_is_otg_enabled()) furi_hal_power_disable_otg(); } else if(event.event == GpioStartEventManualControl) { scene_manager_set_scene_state(app->scene_manager, GpioSceneStart, GpioItemTest); scene_manager_next_scene(app->scene_manager, GpioSceneTest); diff --git a/applications/main/infrared/infrared_app.c b/applications/main/infrared/infrared_app.c index 75c969c26..674f0cc67 100644 --- a/applications/main/infrared/infrared_app.c +++ b/applications/main/infrared/infrared_app.c @@ -460,9 +460,9 @@ void infrared_set_tx_pin(InfraredApp* infrared, FuriHalInfraredTxPin tx_pin) { void infrared_enable_otg(InfraredApp* infrared, bool enable) { if(enable) { - furi_hal_power_enable_otg(); + if(!furi_hal_power_is_otg_enabled()) furi_hal_power_enable_otg(); } else { - furi_hal_power_disable_otg(); + if(furi_hal_power_is_otg_enabled()) furi_hal_power_disable_otg(); } infrared->app_state.is_otg_enabled = enable; } diff --git a/applications/main/onewire/onewire_cli.c b/applications/main/onewire/onewire_cli.c index 128b58743..4ee81a462 100644 --- a/applications/main/onewire/onewire_cli.c +++ b/applications/main/onewire/onewire_cli.c @@ -20,7 +20,7 @@ static void onewire_cli_search(Cli* cli) { printf("Search started\r\n"); onewire_host_start(onewire); - furi_hal_power_enable_otg(); + if(!furi_hal_power_is_otg_enabled()) furi_hal_power_enable_otg(); while(!done) { if(onewire_host_search(onewire, address, OneWireHostSearchModeNormal) != 1) { @@ -37,7 +37,7 @@ static void onewire_cli_search(Cli* cli) { furi_delay_ms(100); } - furi_hal_power_disable_otg(); + if(furi_hal_power_is_otg_enabled()) furi_hal_power_disable_otg(); onewire_host_free(onewire); } diff --git a/applications/main/subghz/helpers/subghz_txrx_create_protocol_key.c b/applications/main/subghz/helpers/subghz_txrx_create_protocol_key.c index 82990af02..68172612a 100644 --- a/applications/main/subghz/helpers/subghz_txrx_create_protocol_key.c +++ b/applications/main/subghz/helpers/subghz_txrx_create_protocol_key.c @@ -387,14 +387,23 @@ void subghz_txrx_gen_serial_gangqi(uint64_t* result_key) { uint64_t randkey; uint64_t only_required_bytes; uint16_t sum_of_3bytes; + uint8_t xorbytes; do { randkey = (uint64_t)rand(); - only_required_bytes = (randkey & 0xFFFFF0000); + only_required_bytes = (randkey & 0x0FFFF0000) | 0x200000000; sum_of_3bytes = ((only_required_bytes >> 32) & 0xFF) + ((only_required_bytes >> 24) & 0xFF) + ((only_required_bytes >> 16) & 0xFF); - } while(!((!(sum_of_3bytes & 0x3)) && ((0xb2 < sum_of_3bytes) && (sum_of_3bytes < 0x1ae)))); + xorbytes = ((only_required_bytes >> 32) & 0xFF) ^ ((only_required_bytes >> 24) & 0xFF) ^ + ((only_required_bytes >> 16) & 0xFF); + } while( + !((((!(sum_of_3bytes & 0x3)) && ((0xB < sum_of_3bytes) && (sum_of_3bytes < 0x141))) && + ((((only_required_bytes >> 32) & 0xFF) == 0x2) || + (((only_required_bytes >> 32) & 0xFF) == 0x3))) && + ((((xorbytes == 0xBA) || (xorbytes == 0xE2)) || + ((xorbytes == 0x3A) || (xorbytes == 0xF2))) || + (xorbytes == 0xB2)))); // Serial 01 button 01 uint64_t new_key = only_required_bytes | (0b01 << 14) | (0xD << 10) | (0b01 << 8); diff --git a/applications/services/expansion/expansion_worker.c b/applications/services/expansion/expansion_worker.c index 421cb194e..2a64c9f7b 100644 --- a/applications/services/expansion/expansion_worker.c +++ b/applications/services/expansion/expansion_worker.c @@ -251,9 +251,9 @@ static bool expansion_worker_handle_state_connected( if(!expansion_worker_rpc_session_open(instance)) break; instance->state = ExpansionWorkerStateRpcActive; } else if(command == ExpansionFrameControlCommandEnableOtg) { - furi_hal_power_enable_otg(); + if(!furi_hal_power_is_otg_enabled()) furi_hal_power_enable_otg(); } else if(command == ExpansionFrameControlCommandDisableOtg) { - furi_hal_power_disable_otg(); + if(furi_hal_power_is_otg_enabled()) furi_hal_power_disable_otg(); } else { break; } diff --git a/applications/services/rpc/rpc_gpio.c b/applications/services/rpc/rpc_gpio.c index 40fc898a0..9952bec38 100644 --- a/applications/services/rpc/rpc_gpio.c +++ b/applications/services/rpc/rpc_gpio.c @@ -219,9 +219,9 @@ void rpc_system_gpio_set_otg_mode(const PB_Main* request, void* context) { const PB_Gpio_GpioOtgMode mode = request->content.gpio_set_otg_mode.mode; if(mode == PB_Gpio_GpioOtgMode_OFF) { - furi_hal_power_disable_otg(); + if(furi_hal_power_is_otg_enabled()) furi_hal_power_disable_otg(); } else { - furi_hal_power_enable_otg(); + if(!furi_hal_power_is_otg_enabled()) furi_hal_power_enable_otg(); } rpc_send_and_release_empty(session, request->command_id, PB_CommandStatus_OK); diff --git a/lib/ibutton/ibutton_worker_modes.c b/lib/ibutton/ibutton_worker_modes.c index 5900b10a2..8efb78f03 100644 --- a/lib/ibutton/ibutton_worker_modes.c +++ b/lib/ibutton/ibutton_worker_modes.c @@ -75,7 +75,7 @@ void ibutton_worker_mode_idle_stop(iButtonWorker* worker) { void ibutton_worker_mode_read_start(iButtonWorker* worker) { UNUSED(worker); - furi_hal_power_enable_otg(); + if(!furi_hal_power_is_otg_enabled()) furi_hal_power_enable_otg(); } void ibutton_worker_mode_read_tick(iButtonWorker* worker) { @@ -90,7 +90,7 @@ void ibutton_worker_mode_read_tick(iButtonWorker* worker) { void ibutton_worker_mode_read_stop(iButtonWorker* worker) { UNUSED(worker); - furi_hal_power_disable_otg(); + if(furi_hal_power_is_otg_enabled()) furi_hal_power_disable_otg(); } /*********************** EMULATE ***********************/ @@ -120,7 +120,7 @@ void ibutton_worker_mode_emulate_stop(iButtonWorker* worker) { void ibutton_worker_mode_write_common_start(iButtonWorker* worker) { //-V524 UNUSED(worker); - furi_hal_power_enable_otg(); + if(!furi_hal_power_is_otg_enabled()) furi_hal_power_enable_otg(); } void ibutton_worker_mode_write_id_tick(iButtonWorker* worker) { @@ -149,5 +149,5 @@ void ibutton_worker_mode_write_copy_tick(iButtonWorker* worker) { void ibutton_worker_mode_write_common_stop(iButtonWorker* worker) { //-V524 UNUSED(worker); - furi_hal_power_disable_otg(); + if(furi_hal_power_is_otg_enabled()) furi_hal_power_disable_otg(); } diff --git a/lib/subghz/protocols/gangqi.c b/lib/subghz/protocols/gangqi.c index 928e6760b..a2195dd33 100644 --- a/lib/subghz/protocols/gangqi.c +++ b/lib/subghz/protocols/gangqi.c @@ -496,8 +496,10 @@ void subghz_protocol_decoder_gangqi_get_string(void* context, FuriString* output (instance->generic.serial & 0xFF); // Returns true if serial is valid bool serial_is_valid = - ((!(sum_3bytes_serial & 0x3)) && - ((0xb2 < sum_3bytes_serial) && (sum_3bytes_serial < 0x1ae))); + (((!(sum_3bytes_serial & 0x3)) && + ((0xB < sum_3bytes_serial) && (sum_3bytes_serial < 0x141))) && + ((((instance->generic.serial >> 16) & 0xFF) == 0x2) || + (((instance->generic.serial >> 16) & 0xFF) == 0x3))); furi_string_cat_printf( output,