diff --git a/applications/picopass/picopass.c b/applications/picopass/picopass.c index e758794e852..fb9e6b0de6c 100644 --- a/applications/picopass/picopass.c +++ b/applications/picopass/picopass.c @@ -103,24 +103,24 @@ void picopass_free(Picopass* picopass) { free(picopass); } -static const NotificationSequence sequence_blink_start_blue = { +static const NotificationSequence picopass_sequence_blink_start_blue = { &message_blink_start_10, &message_blink_set_color_blue, &message_do_not_reset, NULL, }; -static const NotificationSequence sequence_blink_stop = { +static const NotificationSequence picopass_sequence_blink_stop = { &message_blink_stop, NULL, }; void picopass_blink_start(Picopass* picopass) { - notification_message(picopass->notifications, &sequence_blink_start_blue); + notification_message(picopass->notifications, &picopass_sequence_blink_start_blue); } void picopass_blink_stop(Picopass* picopass) { - notification_message(picopass->notifications, &sequence_blink_stop); + notification_message(picopass->notifications, &picopass_sequence_blink_stop); } int32_t picopass_app(void* p) { diff --git a/applications/picopass/picopass_device.h b/applications/picopass/picopass_device.h index 78ba414d62f..af4c07b9df2 100644 --- a/applications/picopass/picopass_device.h +++ b/applications/picopass/picopass_device.h @@ -12,7 +12,7 @@ typedef struct { uint8_t bitLength; uint8_t FacilityCode; uint16_t CardNumber; -} WiegandRecord; +} PicopassWiegandRecord; typedef struct { bool biometrics; @@ -20,12 +20,12 @@ typedef struct { uint8_t credential[8]; uint8_t pin0[8]; uint8_t pin1[8]; - WiegandRecord record; -} PACS; + PicopassWiegandRecord record; +} PicopassPacs; typedef struct { ApplicationArea AA1; - PACS pacs; + PicopassPacs pacs; } PicopassDeviceData; typedef struct { diff --git a/applications/picopass/picopass_worker.c b/applications/picopass/picopass_worker.c index 6094376f598..abefcb71a1c 100644 --- a/applications/picopass/picopass_worker.c +++ b/applications/picopass/picopass_worker.c @@ -15,25 +15,25 @@ #define TAG "PicopassWorker" -uint8_t iclass_key[8] = {0xaf, 0xa7, 0x85, 0xa7, 0xda, 0xb3, 0x33, 0x78}; -uint8_t iclass_decryptionkey[16] = +const uint8_t picopass_iclass_key[] = {0xaf, 0xa7, 0x85, 0xa7, 0xda, 0xb3, 0x33, 0x78}; +const uint8_t picopass_iclass_decryptionkey[] = {0xb4, 0x21, 0x2c, 0xca, 0xb7, 0xed, 0x21, 0x0f, 0x7b, 0x93, 0xd4, 0x59, 0x39, 0xc7, 0xdd, 0x36}; -void enable_field() { +static void picopass_worker_enable_field() { st25r3916TxRxOn(); rfalLowPowerModeStop(); rfalWorker(); } -ReturnCode disable_field(ReturnCode rc) { +static ReturnCode picopass_worker_disable_field(ReturnCode rc) { st25r3916TxRxOff(); rfalLowPowerModeStart(); return rc; } -ReturnCode decrypt(uint8_t* enc_data, uint8_t* dec_data) { +static ReturnCode picopass_worker_decrypt(uint8_t* enc_data, uint8_t* dec_data) { uint8_t key[32] = {0}; - memcpy(key, iclass_decryptionkey, sizeof(iclass_decryptionkey)); + memcpy(key, picopass_iclass_decryptionkey, sizeof(picopass_iclass_decryptionkey)); mbedtls_des3_context ctx; mbedtls_des3_init(&ctx); mbedtls_des3_set2key_dec(&ctx, key); @@ -42,7 +42,7 @@ ReturnCode decrypt(uint8_t* enc_data, uint8_t* dec_data) { return ERR_NONE; } -ReturnCode parseWiegand(uint8_t* data, WiegandRecord* record) { +static ReturnCode picopass_worker_parse_wiegand(uint8_t* data, PicopassWiegandRecord* record) { uint32_t* halves = (uint32_t*)data; if(halves[0] == 0) { uint8_t leading0s = __builtin_clz(REVERSE_BYTES_U32(halves[1])); @@ -129,7 +129,7 @@ void picopass_worker_stop(PicopassWorker* picopass_worker) { picopass_worker->state == PicopassWorkerStateReady) { return; } - disable_field(ERR_NONE); + picopass_worker_disable_field(ERR_NONE); picopass_worker_change_state(picopass_worker, PicopassWorkerStateStop); furi_thread_join(picopass_worker->thread); @@ -148,19 +148,19 @@ ReturnCode picopass_detect_card(int timeout) { err = rfalPicoPassPollerInitialize(); if(err != ERR_NONE) { - FURI_LOG_E(TAG, "rfalPicoPassPollerInitialize error %d\n", err); + FURI_LOG_E(TAG, "rfalPicoPassPollerInitialize error %d", err); return err; } err = rfalFieldOnAndStartGT(); if(err != ERR_NONE) { - FURI_LOG_E(TAG, "rfalFieldOnAndStartGT error %d\n", err); + FURI_LOG_E(TAG, "rfalFieldOnAndStartGT error %d", err); return err; } err = rfalPicoPassPollerCheckPresence(); if(err != ERR_RF_COLLISION) { - FURI_LOG_E(TAG, "rfalPicoPassPollerCheckPresence error %d\n", err); + FURI_LOG_E(TAG, "rfalPicoPassPollerCheckPresence error %d", err); return err; } @@ -181,13 +181,13 @@ ReturnCode picopass_read_card(ApplicationArea* AA1) { err = rfalPicoPassPollerIdentify(&idRes); if(err != ERR_NONE) { - FURI_LOG_E(TAG, "rfalPicoPassPollerIdentify error %d\n", err); + FURI_LOG_E(TAG, "rfalPicoPassPollerIdentify error %d", err); return err; } err = rfalPicoPassPollerSelect(idRes.CSN, &selRes); if(err != ERR_NONE) { - FURI_LOG_E(TAG, "rfalPicoPassPollerSelect error %d\n", err); + FURI_LOG_E(TAG, "rfalPicoPassPollerSelect error %d", err); return err; } @@ -198,7 +198,7 @@ ReturnCode picopass_read_card(ApplicationArea* AA1) { } memcpy(ccnr, rcRes.CCNR, sizeof(rcRes.CCNR)); // last 4 bytes left 0 - diversifyKey(selRes.CSN, iclass_key, div_key); + diversifyKey(selRes.CSN, picopass_iclass_key, div_key); opt_doReaderMAC(ccnr, div_key, mac); err = rfalPicoPassPollerCheck(mac, &chkRes); @@ -238,11 +238,11 @@ ReturnCode picopass_read_card(ApplicationArea* AA1) { int32_t picopass_worker_task(void* context) { PicopassWorker* picopass_worker = context; - enable_field(); + picopass_worker_enable_field(); if(picopass_worker->state == PicopassWorkerStateDetect) { picopass_worker_detect(picopass_worker); } - disable_field(ERR_NONE); + picopass_worker_disable_field(ERR_NONE); picopass_worker_change_state(picopass_worker, PicopassWorkerStateReady); @@ -254,7 +254,7 @@ void picopass_worker_detect(PicopassWorker* picopass_worker) { PicopassDeviceData* dev_data = picopass_worker->dev_data; ApplicationArea* AA1 = &dev_data->AA1; - PACS* pacs = &dev_data->pacs; + PicopassPacs* pacs = &dev_data->pacs; ReturnCode err; while(picopass_worker->state == PicopassWorkerStateDetect) { @@ -272,21 +272,21 @@ void picopass_worker_detect(PicopassWorker* picopass_worker) { if(pacs->encryption == 0x17) { FURI_LOG_D(TAG, "3DES Encrypted"); - err = decrypt(AA1->block[1].data, pacs->credential); + err = picopass_worker_decrypt(AA1->block[1].data, pacs->credential); if(err != ERR_NONE) { FURI_LOG_E(TAG, "decrypt error %d", err); break; } FURI_LOG_D(TAG, "Decrypted 7"); - err = decrypt(AA1->block[2].data, pacs->pin0); + err = picopass_worker_decrypt(AA1->block[2].data, pacs->pin0); if(err != ERR_NONE) { FURI_LOG_E(TAG, "decrypt error %d", err); break; } FURI_LOG_D(TAG, "Decrypted 8"); - err = decrypt(AA1->block[3].data, pacs->pin1); + err = picopass_worker_decrypt(AA1->block[3].data, pacs->pin1); if(err != ERR_NONE) { FURI_LOG_E(TAG, "decrypt error %d", err); break; @@ -304,7 +304,7 @@ void picopass_worker_detect(PicopassWorker* picopass_worker) { break; } - parseWiegand(pacs->credential, &pacs->record); + picopass_worker_parse_wiegand(pacs->credential, &pacs->record); // Notify caller and exit if(picopass_worker->callback) { diff --git a/applications/picopass/scenes/picopass_scene_read_card_success.c b/applications/picopass/scenes/picopass_scene_read_card_success.c index 4f426c51df5..8e65ce0039b 100644 --- a/applications/picopass/scenes/picopass_scene_read_card_success.c +++ b/applications/picopass/scenes/picopass_scene_read_card_success.c @@ -26,7 +26,7 @@ void picopass_scene_read_card_success_on_enter(void* context) { notification_message(picopass->notifications, &sequence_success); // Setup view - PACS* pacs = &picopass->dev->dev_data.pacs; + PicopassPacs* pacs = &picopass->dev->dev_data.pacs; Widget* widget = picopass->widget; string_set_str(credential_str, ""); diff --git a/lib/loclass/optimized_ikeys.c b/lib/loclass/optimized_ikeys.c index ec414f1a2cd..8e093feb3c0 100644 --- a/lib/loclass/optimized_ikeys.c +++ b/lib/loclass/optimized_ikeys.c @@ -304,7 +304,7 @@ void hash0(uint64_t c, uint8_t k[8]) { * @param key * @param div_key */ -void diversifyKey(uint8_t *csn, uint8_t *key, uint8_t *div_key) { +void diversifyKey(uint8_t *csn, const uint8_t *key, uint8_t *div_key) { // Prepare the DES key mbedtls_des_setkey_enc(&ctx_enc, key); diff --git a/lib/loclass/optimized_ikeys.h b/lib/loclass/optimized_ikeys.h index fd990cac929..e366bb6eeea 100644 --- a/lib/loclass/optimized_ikeys.h +++ b/lib/loclass/optimized_ikeys.h @@ -56,7 +56,7 @@ void hash0(uint64_t c, uint8_t k[8]); * @param div_key */ -void diversifyKey(uint8_t *csn, uint8_t *key, uint8_t *div_key); +void diversifyKey(uint8_t *csn, const uint8_t *key, uint8_t *div_key); /** * @brief Permutes a key from standard NIST format to Iclass specific format * @param key