2022-07-05 15:28:27 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <storage/storage.h>
|
|
|
|
#include <dialogs/dialogs.h>
|
2022-08-23 13:19:17 +00:00
|
|
|
#include <mbedtls/des.h>
|
2022-09-14 16:11:38 +00:00
|
|
|
|
|
|
|
#include "rfal_picopass.h"
|
2022-10-06 13:55:57 +00:00
|
|
|
#include <optimized_ikeys.h>
|
|
|
|
#include <optimized_cipher.h>
|
2022-10-18 14:58:26 +00:00
|
|
|
#include "helpers/iclass_elite_dict.h"
|
2022-08-23 13:19:17 +00:00
|
|
|
|
2022-07-10 12:46:46 +00:00
|
|
|
#define PICOPASS_DEV_NAME_MAX_LEN 22
|
|
|
|
#define PICOPASS_READER_DATA_MAX_SIZE 64
|
|
|
|
#define PICOPASS_BLOCK_LEN 8
|
2022-07-25 15:36:38 +00:00
|
|
|
#define PICOPASS_MAX_APP_LIMIT 32
|
|
|
|
|
|
|
|
#define PICOPASS_CSN_BLOCK_INDEX 0
|
|
|
|
#define PICOPASS_CONFIG_BLOCK_INDEX 1
|
2022-12-28 13:04:58 +00:00
|
|
|
#define PICOPASS_EPURSE_BLOCK_INDEX 2
|
|
|
|
#define PICOPASS_KD_BLOCK_INDEX 3
|
|
|
|
#define PICOPASS_KC_BLOCK_INDEX 4
|
2022-07-25 15:36:38 +00:00
|
|
|
#define PICOPASS_AIA_BLOCK_INDEX 5
|
2023-02-26 07:59:50 +00:00
|
|
|
#define PICOPASS_PACS_CFG_BLOCK_INDEX 6
|
2022-07-10 12:46:46 +00:00
|
|
|
|
|
|
|
#define PICOPASS_APP_EXTENSION ".picopass"
|
|
|
|
#define PICOPASS_APP_SHADOW_EXTENSION ".pas"
|
|
|
|
|
2022-08-23 13:19:17 +00:00
|
|
|
typedef void (*PicopassLoadingCallback)(void* context, bool state);
|
|
|
|
|
2022-07-10 12:46:46 +00:00
|
|
|
typedef enum {
|
|
|
|
PicopassDeviceEncryptionUnknown = 0,
|
|
|
|
PicopassDeviceEncryptionNone = 0x14,
|
|
|
|
PicopassDeviceEncryptionDES = 0x15,
|
|
|
|
PicopassDeviceEncryption3DES = 0x17,
|
|
|
|
} PicopassEncryption;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
PicopassDeviceSaveFormatHF,
|
|
|
|
PicopassDeviceSaveFormatLF,
|
|
|
|
} PicopassDeviceSaveFormat;
|
|
|
|
|
2022-07-05 15:28:27 +00:00
|
|
|
typedef struct {
|
|
|
|
bool valid;
|
|
|
|
uint8_t bitLength;
|
|
|
|
uint8_t FacilityCode;
|
|
|
|
uint16_t CardNumber;
|
|
|
|
} PicopassWiegandRecord;
|
|
|
|
|
|
|
|
typedef struct {
|
2022-07-25 15:36:38 +00:00
|
|
|
bool legacy;
|
|
|
|
bool se_enabled;
|
2022-09-19 13:37:12 +00:00
|
|
|
bool sio;
|
2022-07-05 15:28:27 +00:00
|
|
|
bool biometrics;
|
2022-10-18 14:58:26 +00:00
|
|
|
uint8_t key[8];
|
2022-07-25 15:36:38 +00:00
|
|
|
uint8_t pin_length;
|
2022-07-10 12:46:46 +00:00
|
|
|
PicopassEncryption encryption;
|
2022-07-05 15:28:27 +00:00
|
|
|
uint8_t credential[8];
|
|
|
|
uint8_t pin0[8];
|
|
|
|
uint8_t pin1[8];
|
|
|
|
PicopassWiegandRecord record;
|
|
|
|
} PicopassPacs;
|
|
|
|
|
|
|
|
typedef struct {
|
2022-07-25 15:36:38 +00:00
|
|
|
uint8_t data[PICOPASS_BLOCK_LEN];
|
|
|
|
} PicopassBlock;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
PicopassBlock AA1[PICOPASS_MAX_APP_LIMIT];
|
2022-07-05 15:28:27 +00:00
|
|
|
PicopassPacs pacs;
|
|
|
|
} PicopassDeviceData;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
Storage* storage;
|
|
|
|
DialogsApp* dialogs;
|
|
|
|
PicopassDeviceData dev_data;
|
2022-07-10 12:46:46 +00:00
|
|
|
char dev_name[PICOPASS_DEV_NAME_MAX_LEN + 1];
|
2022-10-05 15:15:23 +00:00
|
|
|
FuriString* load_path;
|
2022-07-10 12:46:46 +00:00
|
|
|
PicopassDeviceSaveFormat format;
|
2022-08-23 13:19:17 +00:00
|
|
|
PicopassLoadingCallback loading_cb;
|
|
|
|
void* loading_cb_ctx;
|
2022-07-05 15:28:27 +00:00
|
|
|
} PicopassDevice;
|
|
|
|
|
|
|
|
PicopassDevice* picopass_device_alloc();
|
|
|
|
|
|
|
|
void picopass_device_free(PicopassDevice* picopass_dev);
|
|
|
|
|
2022-07-10 12:46:46 +00:00
|
|
|
void picopass_device_set_name(PicopassDevice* dev, const char* name);
|
|
|
|
|
|
|
|
bool picopass_device_save(PicopassDevice* dev, const char* dev_name);
|
|
|
|
|
2022-08-23 13:19:17 +00:00
|
|
|
bool picopass_file_select(PicopassDevice* dev);
|
|
|
|
|
2022-07-05 15:28:27 +00:00
|
|
|
void picopass_device_data_clear(PicopassDeviceData* dev_data);
|
|
|
|
|
|
|
|
void picopass_device_clear(PicopassDevice* dev);
|
2022-08-23 13:19:17 +00:00
|
|
|
|
|
|
|
bool picopass_device_delete(PicopassDevice* dev, bool use_load_path);
|
|
|
|
|
|
|
|
void picopass_device_set_loading_callback(
|
|
|
|
PicopassDevice* dev,
|
|
|
|
PicopassLoadingCallback callback,
|
|
|
|
void* context);
|
|
|
|
|
|
|
|
ReturnCode picopass_device_parse_credential(PicopassBlock* AA1, PicopassPacs* pacs);
|
|
|
|
ReturnCode picopass_device_parse_wiegand(uint8_t* data, PicopassWiegandRecord* record);
|