mirror of
https://github.com/flipperdevices/flipperzero-firmware.git
synced 2025-12-12 12:51:22 +04:00
Lock core2 when reinitialising bt
This commit is contained in:
@@ -87,10 +87,9 @@ static bool furi_hal_bt_radio_stack_is_supported(const BleGlueC2Info* info) {
|
||||
}
|
||||
|
||||
bool furi_hal_bt_start_radio_stack(void) {
|
||||
bool res = false;
|
||||
furi_check(furi_hal_bt.core2_mtx);
|
||||
furi_hal_bt_lock_core2();
|
||||
|
||||
furi_mutex_acquire(furi_hal_bt.core2_mtx, FuriWaitForever);
|
||||
bool res = false;
|
||||
|
||||
// Explicitly tell that we are in charge of CLK48 domain
|
||||
furi_check(LL_HSEM_1StepLock(HSEM, CFG_HW_CLK48_CONFIG_SEMID) == 0);
|
||||
@@ -123,7 +122,8 @@ bool furi_hal_bt_start_radio_stack(void) {
|
||||
}
|
||||
res = true;
|
||||
} while(false);
|
||||
furi_mutex_release(furi_hal_bt.core2_mtx);
|
||||
|
||||
furi_hal_bt_unlock_core2();
|
||||
|
||||
gap_extra_beacon_init();
|
||||
return res;
|
||||
@@ -198,6 +198,8 @@ FuriHalBleProfileBase* furi_hal_bt_start_app(
|
||||
}
|
||||
|
||||
void furi_hal_bt_reinit(void) {
|
||||
furi_hal_bt_lock_core2();
|
||||
|
||||
furi_hal_power_insomnia_enter();
|
||||
FURI_LOG_I(TAG, "Disconnect and stop advertising");
|
||||
furi_hal_bt_stop_advertising();
|
||||
@@ -229,6 +231,7 @@ void furi_hal_bt_reinit(void) {
|
||||
furi_hal_bus_disable(FuriHalBusCRC);
|
||||
|
||||
furi_hal_bt_init();
|
||||
furi_hal_bt_unlock_core2();
|
||||
furi_hal_bt_start_radio_stack();
|
||||
furi_hal_power_insomnia_exit();
|
||||
}
|
||||
|
||||
@@ -262,36 +262,54 @@ bool furi_hal_crypto_enclave_load_key(uint8_t slot, const uint8_t* iv) {
|
||||
|
||||
furi_hal_bus_enable(FuriHalBusAES1);
|
||||
|
||||
if(!furi_hal_bt_is_alive()) {
|
||||
return false;
|
||||
}
|
||||
bool success = false;
|
||||
|
||||
furi_hal_crypto_mode_init_done = false;
|
||||
crypto_key_init(NULL, (uint32_t*)iv);
|
||||
furi_hal_bt_lock_core2();
|
||||
|
||||
if(SHCI_C2_FUS_LoadUsrKey(slot) == SHCI_Success) {
|
||||
return true;
|
||||
} else {
|
||||
CLEAR_BIT(AES1->CR, AES_CR_EN);
|
||||
furi_check(furi_mutex_release(furi_hal_crypto_mutex) == FuriStatusOk);
|
||||
return false;
|
||||
}
|
||||
do {
|
||||
if(!furi_hal_bt_is_alive()) {
|
||||
break;
|
||||
}
|
||||
|
||||
furi_hal_crypto_mode_init_done = false;
|
||||
crypto_key_init(NULL, (uint32_t*)iv);
|
||||
|
||||
if(SHCI_C2_FUS_LoadUsrKey(slot) == SHCI_Success) {
|
||||
success = true;
|
||||
} else {
|
||||
CLEAR_BIT(AES1->CR, AES_CR_EN);
|
||||
furi_check(furi_mutex_release(furi_hal_crypto_mutex) == FuriStatusOk);
|
||||
}
|
||||
|
||||
} while(false);
|
||||
|
||||
furi_hal_bt_unlock_core2();
|
||||
return success;
|
||||
}
|
||||
|
||||
bool furi_hal_crypto_enclave_unload_key(uint8_t slot) {
|
||||
if(!furi_hal_bt_is_alive()) {
|
||||
return false;
|
||||
}
|
||||
furi_hal_bt_lock_core2();
|
||||
|
||||
CLEAR_BIT(AES1->CR, AES_CR_EN);
|
||||
bool success = false;
|
||||
|
||||
SHCI_CmdStatus_t shci_state = SHCI_C2_FUS_UnloadUsrKey(slot);
|
||||
do {
|
||||
if(!furi_hal_bt_is_alive()) {
|
||||
break;
|
||||
}
|
||||
|
||||
furi_hal_bus_disable(FuriHalBusAES1);
|
||||
CLEAR_BIT(AES1->CR, AES_CR_EN);
|
||||
|
||||
furi_check(furi_mutex_release(furi_hal_crypto_mutex) == FuriStatusOk);
|
||||
SHCI_CmdStatus_t shci_state = SHCI_C2_FUS_UnloadUsrKey(slot);
|
||||
|
||||
return (shci_state == SHCI_Success);
|
||||
furi_hal_bus_disable(FuriHalBusAES1);
|
||||
|
||||
furi_check(furi_mutex_release(furi_hal_crypto_mutex) == FuriStatusOk);
|
||||
|
||||
success = (shci_state == SHCI_Success);
|
||||
} while(false);
|
||||
|
||||
furi_hal_bt_unlock_core2();
|
||||
return success;
|
||||
}
|
||||
|
||||
bool furi_hal_crypto_load_key(const uint8_t* key, const uint8_t* iv) {
|
||||
|
||||
Reference in New Issue
Block a user