Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into release-candidate
Browse files Browse the repository at this point in the history
  • Loading branch information
skotopes committed Apr 12, 2023
2 parents b556776 + 33e8bae commit 728320b
Show file tree
Hide file tree
Showing 19 changed files with 106 additions and 164 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ bindings/
Brewfile.lock.json

# Visual Studio Code
.vscode/
/.vscode/

# Kate
.kateproject
Expand Down
7 changes: 6 additions & 1 deletion applications/external/avr_isp_programmer/helpers/avr_isp.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,12 @@ bool avr_isp_auto_set_spi_speed_start_pmode(AvrIsp* instance) {
}
}
}
if(instance->spi) avr_isp_spi_sw_free(instance->spi);

if(instance->spi) {
avr_isp_spi_sw_free(instance->spi);
instance->spi = NULL;
}

return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,12 @@ static bool avr_isp_prog_auto_set_spi_speed_start_pmode(AvrIspProg* instance) {
}
}
}
if(instance->spi) avr_isp_spi_sw_free(instance->spi);

if(instance->spi) {
avr_isp_spi_sw_free(instance->spi);
instance->spi = NULL;
}

return false;
}

Expand Down
5 changes: 0 additions & 5 deletions applications/main/nfc/scenes/nfc_scene_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,6 @@ bool nfc_scene_read_on_event(void* context, SceneManagerEvent event) {
scene_manager_next_scene(nfc->scene_manager, NfcSceneMfDesfireReadSuccess);
DOLPHIN_DEED(DolphinDeedNfcReadSuccess);
consumed = true;
} else if(event.event == NfcWorkerEventReadBankCard) {
notification_message(nfc->notifications, &sequence_success);
scene_manager_next_scene(nfc->scene_manager, NfcSceneEmvReadSuccess);
DOLPHIN_DEED(DolphinDeedNfcReadSuccess);
consumed = true;
} else if(event.event == NfcWorkerEventReadMfClassicDictAttackRequired) {
if(mf_classic_dict_check_presence(MfClassicDictTypeSystem)) {
scene_manager_next_scene(nfc->scene_manager, NfcSceneMfClassicDictAttack);
Expand Down
12 changes: 0 additions & 12 deletions applications/main/nfc/scenes/nfc_scene_read_card_type.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ enum SubmenuIndex {
SubmenuIndexReadMifareClassic,
SubmenuIndexReadMifareDesfire,
SubmenuIndexReadMfUltralight,
SubmenuIndexReadEMV,
SubmenuIndexReadNFCA,
};

Expand Down Expand Up @@ -37,12 +36,6 @@ void nfc_scene_read_card_type_on_enter(void* context) {
SubmenuIndexReadMfUltralight,
nfc_scene_read_card_type_submenu_callback,
nfc);
submenu_add_item(
submenu,
"Read EMV card",
SubmenuIndexReadEMV,
nfc_scene_read_card_type_submenu_callback,
nfc);
submenu_add_item(
submenu,
"Read NFC-A data",
Expand Down Expand Up @@ -75,11 +68,6 @@ bool nfc_scene_read_card_type_on_event(void* context, SceneManagerEvent event) {
scene_manager_next_scene(nfc->scene_manager, NfcSceneRead);
consumed = true;
}
if(event.event == SubmenuIndexReadEMV) {
nfc->dev->dev_data.read_mode = NfcReadModeEMV;
scene_manager_next_scene(nfc->scene_manager, NfcSceneRead);
consumed = true;
}
if(event.event == SubmenuIndexReadNFCA) {
nfc->dev->dev_data.read_mode = NfcReadModeNFCA;
scene_manager_next_scene(nfc->scene_manager, NfcSceneRead);
Expand Down
6 changes: 5 additions & 1 deletion applications/main/subghz/scenes/subghz_scene_read_raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,11 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) {
(subghz->txrx->txrx_state == SubGhzTxRxStateSleep)) {
if(!subghz_tx_start(subghz, subghz->txrx->fff_data)) {
subghz->txrx->rx_key_state = SubGhzRxKeyStateBack;
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowOnlyRx);
subghz_read_raw_set_status(
subghz->subghz_read_raw,
SubGhzReadRAWStatusIDLE,
"",
subghz->txrx->raw_threshold_rssi);
} else {
if(scene_manager_has_previous_scene(
subghz->scene_manager, SubGhzSceneSaved) ||
Expand Down
4 changes: 1 addition & 3 deletions applications/main/subghz/scenes/subghz_scene_transmitter.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent event) {
}
if((subghz->txrx->txrx_state == SubGhzTxRxStateIDLE) ||
(subghz->txrx->txrx_state == SubGhzTxRxStateSleep)) {
if(!subghz_tx_start(subghz, subghz->txrx->fff_data)) {
scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowOnlyRx);
} else {
if(subghz_tx_start(subghz, subghz->txrx->fff_data)) {
subghz->state_notifications = SubGhzNotificationStateTx;
subghz_scene_transmitter_update_data_show(subghz);
DOLPHIN_DEED(DolphinDeedSubGhzSend);
Expand Down
7 changes: 5 additions & 2 deletions applications/main/subghz/subghz_i.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,19 @@ static bool subghz_tx(SubGhz* subghz, uint32_t frequency) {
furi_hal_subghz_set_frequency_and_path(frequency);
furi_hal_gpio_write(&gpio_cc1101_g0, false);
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
subghz_speaker_on(subghz);
bool ret = furi_hal_subghz_tx();
subghz->txrx->txrx_state = SubGhzTxRxStateTx;
if(ret) {
subghz_speaker_on(subghz);
subghz->txrx->txrx_state = SubGhzTxRxStateTx;
}
return ret;
}

void subghz_idle(SubGhz* subghz) {
furi_assert(subghz);
furi_assert(subghz->txrx->txrx_state != SubGhzTxRxStateSleep);
furi_hal_subghz_idle();
subghz_speaker_off(subghz);
subghz->txrx->txrx_state = SubGhzTxRxStateIDLE;
}

Expand Down
1 change: 0 additions & 1 deletion lib/nfc/nfc_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ typedef enum {
NfcReadModeMfClassic,
NfcReadModeMfUltralight,
NfcReadModeMfDesfire,
NfcReadModeEMV,
NfcReadModeNFCA,
} NfcReadMode;

Expand Down
80 changes: 0 additions & 80 deletions lib/nfc/nfc_worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,69 +229,6 @@ static bool nfc_worker_read_mf_desfire(NfcWorker* nfc_worker, FuriHalNfcTxRxCont
return read_success;
}

static bool nfc_worker_read_bank_card(NfcWorker* nfc_worker, FuriHalNfcTxRxContext* tx_rx) {
bool read_success = false;
EmvApplication emv_app = {};
EmvData* result = &nfc_worker->dev_data->emv_data;

if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) {
reader_analyzer_prepare_tx_rx(nfc_worker->reader_analyzer, tx_rx, false);
reader_analyzer_start(nfc_worker->reader_analyzer, ReaderAnalyzerModeDebugLog);
}

// Bank cards require strong field to start application. If we find AID, try at least several
// times to start EMV application
uint8_t start_application_attempts = 0;
while(start_application_attempts < 3) {
if(nfc_worker->state != NfcWorkerStateRead) break;
start_application_attempts++;
if(!furi_hal_nfc_detect(&nfc_worker->dev_data->nfc_data, 300)) break;
if(emv_read_bank_card(tx_rx, &emv_app)) {
FURI_LOG_D(TAG, "Bank card number read from %d attempt", start_application_attempts);
break;
} else if(emv_app.aid_len && !emv_app.app_started) {
FURI_LOG_D(
TAG,
"AID found but failed to start EMV app from %d attempt",
start_application_attempts);
furi_hal_nfc_sleep();
continue;
} else {
FURI_LOG_D(TAG, "Failed to find AID");
break;
}
}
// Copy data
if(emv_app.aid_len) {
result->aid_len = emv_app.aid_len;
memcpy(result->aid, emv_app.aid, result->aid_len);
read_success = true;
}
if(emv_app.card_number_len) {
result->number_len = emv_app.card_number_len;
memcpy(result->number, emv_app.card_number, result->number_len);
}
if(emv_app.name_found) {
memcpy(result->name, emv_app.name, sizeof(emv_app.name));
}
if(emv_app.exp_month) {
result->exp_mon = emv_app.exp_month;
result->exp_year = emv_app.exp_year;
}
if(emv_app.country_code) {
result->country_code = emv_app.country_code;
}
if(emv_app.currency_code) {
result->currency_code = emv_app.currency_code;
}

if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) {
reader_analyzer_stop(nfc_worker->reader_analyzer);
}

return read_success;
}

static bool nfc_worker_read_nfca(NfcWorker* nfc_worker, FuriHalNfcTxRxContext* tx_rx) {
FuriHalNfcDevData* nfc_data = &nfc_worker->dev_data->nfc_data;

Expand All @@ -315,14 +252,6 @@ static bool nfc_worker_read_nfca(NfcWorker* nfc_worker, FuriHalNfcTxRxContext* t
nfc_worker->dev_data->protocol = NfcDeviceProtocolUnknown;
}
card_read = true;
} else if(nfc_data->interface == FuriHalNfcInterfaceIsoDep) {
FURI_LOG_I(TAG, "ISO14443-4 card detected");
nfc_worker->dev_data->protocol = NfcDeviceProtocolEMV;
if(!nfc_worker_read_bank_card(nfc_worker, tx_rx)) {
FURI_LOG_I(TAG, "Unknown card. Save UID");
nfc_worker->dev_data->protocol = NfcDeviceProtocolUnknown;
}
card_read = true;
} else {
nfc_worker->dev_data->protocol = NfcDeviceProtocolUnknown;
card_read = true;
Expand Down Expand Up @@ -358,9 +287,6 @@ void nfc_worker_read(NfcWorker* nfc_worker) {
} else if(dev_data->protocol == NfcDeviceProtocolMifareDesfire) {
event = NfcWorkerEventReadMfDesfire;
break;
} else if(dev_data->protocol == NfcDeviceProtocolEMV) {
event = NfcWorkerEventReadBankCard;
break;
} else if(dev_data->protocol == NfcDeviceProtocolUnknown) {
event = NfcWorkerEventReadUidNfcA;
break;
Expand Down Expand Up @@ -444,12 +370,6 @@ void nfc_worker_read_type(NfcWorker* nfc_worker) {
event = NfcWorkerEventReadMfDesfire;
break;
}
} else if(read_mode == NfcReadModeEMV) {
nfc_worker->dev_data->protocol = NfcDeviceProtocolEMV;
if(nfc_worker_read_bank_card(nfc_worker, &tx_rx)) {
event = NfcWorkerEventReadBankCard;
break;
}
} else if(read_mode == NfcReadModeNFCA) {
nfc_worker->dev_data->protocol = NfcDeviceProtocolUnknown;
event = NfcWorkerEventReadUidNfcA;
Expand Down
1 change: 0 additions & 1 deletion lib/nfc/nfc_worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ typedef enum {
NfcWorkerEventReadMfClassicDone,
NfcWorkerEventReadMfClassicLoadKeyCache,
NfcWorkerEventReadMfClassicDictAttackRequired,
NfcWorkerEventReadBankCard,

// Nfc worker common events
NfcWorkerEventSuccess,
Expand Down
1 change: 0 additions & 1 deletion lib/nfc/nfc_worker_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <lib/toolbox/stream/file_stream.h>

#include <lib/nfc/protocols/nfc_util.h>
#include <lib/nfc/protocols/emv.h>
#include <lib/nfc/protocols/mifare_common.h>
#include <lib/nfc/protocols/mifare_ultralight.h>
#include <lib/nfc/protocols/mifare_classic.h>
Expand Down
6 changes: 4 additions & 2 deletions scripts/sconsdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ def bundle_sdk(self):
) as zf:
for component_key in sdk_components_keys:
component_path = self._dist_components.get(component_key)
components_paths[component_key] = basename(component_path)

if component_key.endswith(".dir"):
components_paths[component_key] = basename(component_path)
for root, dirnames, files in walk(component_path):
if "__pycache__" in dirnames:
dirnames.remove("__pycache__")
Expand All @@ -199,7 +199,9 @@ def bundle_sdk(self):
),
)
else:
zf.write(component_path, basename(component_path))
# We use fixed names for files to avoid having to regenerate VSCode project
components_paths[component_key] = component_key
zf.write(component_path, component_key)

zf.writestr(
"components.json",
Expand Down
22 changes: 22 additions & 0 deletions scripts/ufbt/SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,18 @@ dist_env.Alias("flash", openocd_target)
if env["FORCE"]:
env.AlwaysBuild(openocd_target)


firmware_jflash = dist_env.JFlash(
dist_env["UFBT_STATE_DIR"].File("jflash"),
dist_env["FW_BIN"],
JFLASHADDR="0x20000000",
)
dist_env.Alias("firmware_jflash", firmware_jflash)
dist_env.Alias("jflash", firmware_jflash)
if env["FORCE"]:
env.AlwaysBuild(firmware_jflash)


firmware_debug = dist_env.PhonyTarget(
"debug",
"${GDBPYCOM}",
Expand Down Expand Up @@ -391,3 +403,13 @@ AddPostAction(
dist_env.Precious(app_template_dist)
dist_env.NoClean(app_template_dist)
dist_env.Alias("create", app_template_dist)

dist_env.PhonyTarget(
"get_blackmagic",
"@echo $( ${BLACKMAGIC_ADDR} $)",
)

dist_env.PhonyTarget(
"get_apiversion",
"@echo $( ${UFBT_API_VERSION} $)",
)
63 changes: 30 additions & 33 deletions scripts/ufbt/project_template/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"inputs": [
// {
// "id": "BLACKMAGIC",
// "type": "command",
// "command": "shellCommand.execute",
// "args": {
// "useSingleResult": true,
// "env": {
// "PATH": "${workspaceFolder};${env:PATH}"
// },
// "command": "./fbt get_blackmagic",
// "description": "Get Blackmagic device",
// }
// },
{
"id": "BLACKMAGIC",
"type": "command",
"command": "shellCommand.execute",
"args": {
"description": "Get Blackmagic device",
"useSingleResult": true,
"command": "ufbt -s get_blackmagic",
}
},
],
"configurations": [
{
Expand Down Expand Up @@ -57,26 +54,26 @@
],
// "showDevDebugOutput": "raw",
},
// {
// "name": "Attach FW (blackmagic)",
// "cwd": "${workspaceFolder}",
// "executable": "@UFBT_FIRMWARE_ELF@",
// "request": "attach",
// "type": "cortex-debug",
// "servertype": "external",
// "gdbTarget": "${input:BLACKMAGIC}",
// "svdFile": "@UFBT_DEBUG_DIR@/STM32WB55_CM4.svd",
// "rtos": "FreeRTOS",
// "postAttachCommands": [
// "monitor swdp_scan",
// "attach 1",
// "set confirm off",
// "set mem inaccessible-by-default off",
// "source @UFBT_DEBUG_DIR@/flipperapps.py",
// "fap-set-debug-elf-root @UFBT_DEBUG_ELF_DIR@"
// ]
// // "showDevDebugOutput": "raw",
// },
{
"name": "Attach FW (blackmagic)",
"cwd": "${workspaceFolder}",
"executable": "@UFBT_FIRMWARE_ELF@",
"request": "attach",
"type": "cortex-debug",
"servertype": "external",
"gdbTarget": "${input:BLACKMAGIC}",
"svdFile": "@UFBT_DEBUG_DIR@/STM32WB55_CM4.svd",
"rtos": "FreeRTOS",
"postAttachCommands": [
"monitor swdp_scan",
"attach 1",
"set confirm off",
"set mem inaccessible-by-default off",
"source @UFBT_DEBUG_DIR@/flipperapps.py",
"fap-set-debug-elf-root @UFBT_DEBUG_ELF_DIR@"
]
// "showDevDebugOutput": "raw",
},
{
"name": "Attach FW (JLink)",
"cwd": "${workspaceFolder}",
Expand Down
Loading

0 comments on commit 728320b

Please sign in to comment.