Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/release-candidate' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
skotopes committed Jun 2, 2023
2 parents 16b9764 + 2d8f262 commit e4830a6
Show file tree
Hide file tree
Showing 192 changed files with 3,749 additions and 1,076 deletions.
17 changes: 5 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,11 @@ jobs:
- name: 'Upload artifacts to update server'
if: ${{ !github.event.pull_request.head.repo.fork }}
run: |
mkdir -p ~/.ssh
ssh-keyscan -p ${{ secrets.RSYNC_DEPLOY_PORT }} -H ${{ secrets.RSYNC_DEPLOY_HOST }} > ~/.ssh/known_hosts
echo "${{ secrets.RSYNC_DEPLOY_KEY }}" > deploy_key;
chmod 600 ./deploy_key;
rsync -avzP --delete --mkpath \
-e 'ssh -p ${{ secrets.RSYNC_DEPLOY_PORT }} -i ./deploy_key' \
artifacts/ ${{ secrets.RSYNC_DEPLOY_USER }}@${{ secrets.RSYNC_DEPLOY_HOST }}:"${{ secrets.RSYNC_DEPLOY_BASE_PATH }}${BRANCH_NAME}/";
rm ./deploy_key;
- name: 'Trigger update server reindex'
if: ${{ !github.event.pull_request.head.repo.fork }}
run: curl -X POST -F 'key=${{ secrets.REINDEX_KEY }}' ${{ secrets.REINDEX_URL }}
FILES=$(for CUR in $(ls artifacts/); do echo "-F files=@artifacts/$CUR"; done)
curl --fail -L -H "Token: ${{ secrets.INDEXER_TOKEN }}" \
-F "branch=${BRANCH_NAME}" \
${FILES[@]} \
"${{ secrets.INDEXER_URL }}"/firmware/uploadfiles
- name: 'Find Previous Comment'
if: ${{ !github.event.pull_request.head.repo.fork && github.event.pull_request }}
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/reindex.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ jobs:
steps:
- name: Trigger reindex
run: |
curl -X POST -F 'key=${{ secrets.REINDEX_KEY }}' ${{ secrets.REINDEX_URL }}
curl --fail -L -H "Token: ${{ secrets.INDEXER_TOKEN }}" \
"${{ secrets.INDEXER_URL }}"/firmware/reindex
22 changes: 11 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,25 @@ bindings/
.mxproject
Brewfile.lock.json

# Visual Studio Code
/.vscode/

# Kate
.kateproject
.kateconfig

# legendary cmake's
build
CMakeLists.txt

# bundle output
dist

# kde
.directory

# SCons
.sconsign.dblite


# Visual Studio Code
/.vscode

# bundle output
/dist

# SCons build dir
build/
/build

# Toolchain
/toolchain
Expand All @@ -64,3 +62,5 @@ PVS-Studio.log
*.PVS-Studio.*

.gdbinit

/fbt_options_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ void lfrfid_debug_scene_tune_on_enter(void* context) {
furi_hal_rfid_comp_set_callback(comparator_trigger_callback, app);
furi_hal_rfid_comp_start();

furi_hal_rfid_pins_read();
furi_hal_rfid_tim_read(125000, 0.5);
furi_hal_rfid_tim_read_start();
furi_hal_rfid_tim_read_start(125000, 0.5);

view_dispatcher_switch_to_view(app->view_dispatcher, LfRfidDebugViewTune);
}
Expand All @@ -43,6 +41,5 @@ void lfrfid_debug_scene_tune_on_exit(void* context) {

furi_hal_gpio_init_simple(&gpio_ext_pa7, GpioModeAnalog);
furi_hal_rfid_tim_read_stop();
furi_hal_rfid_tim_reset();
furi_hal_rfid_pins_reset();
}
61 changes: 52 additions & 9 deletions applications/debug/unit_tests/nfc/nfc_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ static const uint32_t nfc_test_file_version = 1;
#define NFC_TEST_DATA_MAX_LEN 18
#define NFC_TETS_TIMINGS_MAX_LEN 1350

// Maximum allowed time for buffer preparation to fit 500us nt message timeout
#define NFC_TEST_4_BYTE_BUILD_BUFFER_TIM_MAX (150)
#define NFC_TEST_16_BYTE_BUILD_BUFFER_TIM_MAX (640)
#define NFC_TEST_4_BYTE_BUILD_SIGNAL_TIM_MAX (110)
#define NFC_TEST_16_BYTE_BUILD_SIGNAL_TIM_MAX (440)

typedef struct {
Storage* storage;
NfcaSignal* signal;
Expand Down Expand Up @@ -89,13 +95,13 @@ static bool nfc_test_read_signal_from_file(const char* file_name) {

static bool nfc_test_digital_signal_test_encode(
const char* file_name,
uint32_t encode_max_time,
uint32_t build_signal_max_time_us,
uint32_t build_buffer_max_time_us,
uint32_t timing_tolerance,
uint32_t timings_sum_tolerance) {
furi_assert(nfc_test);

bool success = false;
uint32_t time = 0;
uint32_t dut_timings_sum = 0;
uint32_t ref_timings_sum = 0;
uint8_t parity[10] = {};
Expand All @@ -109,17 +115,37 @@ static bool nfc_test_digital_signal_test_encode(

// Encode signal
FURI_CRITICAL_ENTER();
time = DWT->CYCCNT;
uint32_t time_start = DWT->CYCCNT;

nfca_signal_encode(
nfc_test->signal, nfc_test->test_data, nfc_test->test_data_len * 8, parity);

uint32_t time_signal =
(DWT->CYCCNT - time_start) / furi_hal_cortex_instructions_per_microsecond();

time_start = DWT->CYCCNT;

digital_signal_prepare_arr(nfc_test->signal->tx_signal);
time = (DWT->CYCCNT - time) / furi_hal_cortex_instructions_per_microsecond();

uint32_t time_buffer =
(DWT->CYCCNT - time_start) / furi_hal_cortex_instructions_per_microsecond();
FURI_CRITICAL_EXIT();

// Check timings
if(time > encode_max_time) {
if(time_signal > build_signal_max_time_us) {
FURI_LOG_E(
TAG, "Encoding time: %ld us while accepted value: %ld us", time, encode_max_time);
TAG,
"Build signal time: %ld us while accepted value: %ld us",
time_signal,
build_signal_max_time_us);
break;
}
if(time_buffer > build_buffer_max_time_us) {
FURI_LOG_E(
TAG,
"Build buffer time: %ld us while accepted value: %ld us",
time_buffer,
build_buffer_max_time_us);
break;
}

Expand Down Expand Up @@ -156,7 +182,16 @@ static bool nfc_test_digital_signal_test_encode(
break;
}

FURI_LOG_I(TAG, "Encoding time: %ld us. Acceptable time: %ld us", time, encode_max_time);
FURI_LOG_I(
TAG,
"Build signal time: %ld us. Acceptable time: %ld us",
time_signal,
build_signal_max_time_us);
FURI_LOG_I(
TAG,
"Build buffer time: %ld us. Acceptable time: %ld us",
time_buffer,
build_buffer_max_time_us);
FURI_LOG_I(
TAG,
"Timings sum difference: %ld [1/64MHZ]. Acceptable difference: %ld [1/64MHz]",
Expand All @@ -171,11 +206,19 @@ static bool nfc_test_digital_signal_test_encode(
MU_TEST(nfc_digital_signal_test) {
mu_assert(
nfc_test_digital_signal_test_encode(
NFC_TEST_RESOURCES_DIR NFC_TEST_SIGNAL_SHORT_FILE, 500, 1, 37),
NFC_TEST_RESOURCES_DIR NFC_TEST_SIGNAL_SHORT_FILE,
NFC_TEST_4_BYTE_BUILD_SIGNAL_TIM_MAX,
NFC_TEST_4_BYTE_BUILD_BUFFER_TIM_MAX,
1,
37),
"NFC short digital signal test failed\r\n");
mu_assert(
nfc_test_digital_signal_test_encode(
NFC_TEST_RESOURCES_DIR NFC_TEST_SIGNAL_LONG_FILE, 2000, 1, 37),
NFC_TEST_RESOURCES_DIR NFC_TEST_SIGNAL_LONG_FILE,
NFC_TEST_16_BYTE_BUILD_SIGNAL_TIM_MAX,
NFC_TEST_16_BYTE_BUILD_BUFFER_TIM_MAX,
1,
37),
"NFC long digital signal test failed\r\n");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#include "magic.h"
#include "classic_gen1.h"

#include <furi_hal_nfc.h>

#define TAG "Magic"

#define MAGIC_CMD_WUPA (0x40)
#define MAGIC_CMD_WIPE (0x41)
#define MAGIC_CMD_ACCESS (0x43)

#define MAGIC_MIFARE_READ_CMD (0x30)
Expand All @@ -15,27 +14,14 @@

#define MAGIC_BUFFER_SIZE (32)

bool magic_wupa() {
bool magic_gen1_wupa() {
bool magic_activated = false;
uint8_t tx_data[MAGIC_BUFFER_SIZE] = {};
uint8_t rx_data[MAGIC_BUFFER_SIZE] = {};
uint16_t rx_len = 0;
FuriHalNfcReturn ret = 0;

do {
// Setup nfc poller
furi_hal_nfc_exit_sleep();
furi_hal_nfc_ll_txrx_on();
furi_hal_nfc_ll_poll();
ret = furi_hal_nfc_ll_set_mode(
FuriHalNfcModePollNfca, FuriHalNfcBitrate106, FuriHalNfcBitrate106);
if(ret != FuriHalNfcReturnOk) break;

furi_hal_nfc_ll_set_fdt_listen(FURI_HAL_NFC_LL_FDT_LISTEN_NFCA_POLLER);
furi_hal_nfc_ll_set_fdt_poll(FURI_HAL_NFC_LL_FDT_POLL_NFCA_POLLER);
furi_hal_nfc_ll_set_error_handling(FuriHalNfcErrorHandlingNfc);
furi_hal_nfc_ll_set_guard_time(FURI_HAL_NFC_LL_GT_NFCA);

// Start communication
tx_data[0] = MAGIC_CMD_WUPA;
ret = furi_hal_nfc_ll_txrx_bits(
Expand All @@ -53,15 +39,10 @@ bool magic_wupa() {
magic_activated = true;
} while(false);

if(!magic_activated) {
furi_hal_nfc_ll_txrx_off();
furi_hal_nfc_start_sleep();
}

return magic_activated;
}

bool magic_data_access_cmd() {
bool magic_gen1_data_access_cmd() {
bool write_cmd_success = false;
uint8_t tx_data[MAGIC_BUFFER_SIZE] = {};
uint8_t rx_data[MAGIC_BUFFER_SIZE] = {};
Expand All @@ -86,15 +67,10 @@ bool magic_data_access_cmd() {
write_cmd_success = true;
} while(false);

if(!write_cmd_success) {
furi_hal_nfc_ll_txrx_off();
furi_hal_nfc_start_sleep();
}

return write_cmd_success;
}

bool magic_read_block(uint8_t block_num, MfClassicBlock* data) {
bool magic_gen1_read_block(uint8_t block_num, MfClassicBlock* data) {
furi_assert(data);

bool read_success = false;
Expand Down Expand Up @@ -122,15 +98,10 @@ bool magic_read_block(uint8_t block_num, MfClassicBlock* data) {
read_success = true;
} while(false);

if(!read_success) {
furi_hal_nfc_ll_txrx_off();
furi_hal_nfc_start_sleep();
}

return read_success;
}

bool magic_write_blk(uint8_t block_num, MfClassicBlock* data) {
bool magic_gen1_write_blk(uint8_t block_num, MfClassicBlock* data) {
furi_assert(data);

bool write_success = false;
Expand Down Expand Up @@ -170,44 +141,5 @@ bool magic_write_blk(uint8_t block_num, MfClassicBlock* data) {
write_success = true;
} while(false);

if(!write_success) {
furi_hal_nfc_ll_txrx_off();
furi_hal_nfc_start_sleep();
}

return write_success;
}

bool magic_wipe() {
bool wipe_success = false;
uint8_t tx_data[MAGIC_BUFFER_SIZE] = {};
uint8_t rx_data[MAGIC_BUFFER_SIZE] = {};
uint16_t rx_len = 0;
FuriHalNfcReturn ret = 0;

do {
tx_data[0] = MAGIC_CMD_WIPE;
ret = furi_hal_nfc_ll_txrx_bits(
tx_data,
8,
rx_data,
sizeof(rx_data),
&rx_len,
FURI_HAL_NFC_LL_TXRX_FLAGS_CRC_TX_MANUAL | FURI_HAL_NFC_LL_TXRX_FLAGS_AGC_ON |
FURI_HAL_NFC_LL_TXRX_FLAGS_CRC_RX_KEEP,
furi_hal_nfc_ll_ms2fc(2000));

if(ret != FuriHalNfcReturnIncompleteByte) break;
if(rx_len != 4) break;
if(rx_data[0] != MAGIC_ACK) break;

wipe_success = true;
} while(false);

return wipe_success;
}

void magic_deactivate() {
furi_hal_nfc_ll_txrx_off();
furi_hal_nfc_sleep();
}
11 changes: 11 additions & 0 deletions applications/external/nfc_magic/lib/magic/classic_gen1.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include <lib/nfc/protocols/mifare_classic.h>

bool magic_gen1_wupa();

bool magic_gen1_read_block(uint8_t block_num, MfClassicBlock* data);

bool magic_gen1_data_access_cmd();

bool magic_gen1_write_blk(uint8_t block_num, MfClassicBlock* data);
33 changes: 33 additions & 0 deletions applications/external/nfc_magic/lib/magic/common.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "common.h"

#include <furi_hal_nfc.h>

#define REQA (0x26)
#define CL1_PREFIX (0x93)
#define SELECT (0x70)

#define MAGIC_BUFFER_SIZE (32)

bool magic_activate() {
FuriHalNfcReturn ret = 0;

// Setup nfc poller
furi_hal_nfc_exit_sleep();
furi_hal_nfc_ll_txrx_on();
furi_hal_nfc_ll_poll();
ret = furi_hal_nfc_ll_set_mode(
FuriHalNfcModePollNfca, FuriHalNfcBitrate106, FuriHalNfcBitrate106);
if(ret != FuriHalNfcReturnOk) return false;

furi_hal_nfc_ll_set_fdt_listen(FURI_HAL_NFC_LL_FDT_LISTEN_NFCA_POLLER);
furi_hal_nfc_ll_set_fdt_poll(FURI_HAL_NFC_LL_FDT_POLL_NFCA_POLLER);
furi_hal_nfc_ll_set_error_handling(FuriHalNfcErrorHandlingNfc);
furi_hal_nfc_ll_set_guard_time(FURI_HAL_NFC_LL_GT_NFCA);

return true;
}

void magic_deactivate() {
furi_hal_nfc_ll_txrx_off();
furi_hal_nfc_sleep();
}
Loading

0 comments on commit e4830a6

Please sign in to comment.