2024-07-06 14:08:44 +03:00
|
|
|
#pragma once
|
2023-09-21 12:09:00 +03:00
|
|
|
|
|
|
|
#include <stdint.h>
|
2024-06-01 19:45:27 +03:00
|
|
|
#include "iso7816_atr.h"
|
|
|
|
#include "core/common_defines.h"
|
2023-09-21 12:09:00 +03:00
|
|
|
|
2024-07-06 14:08:44 +03:00
|
|
|
#define ISO7816_READ_COMMAND_APDU_OK 0
|
|
|
|
#define ISO7816_READ_COMMAND_APDU_ERROR_WRONG_LE 1
|
|
|
|
#define ISO7816_READ_COMMAND_APDU_ERROR_WRONG_LENGTH 2
|
|
|
|
|
|
|
|
typedef struct {
|
2023-09-21 12:09:00 +03:00
|
|
|
//header
|
|
|
|
uint8_t CLA;
|
2023-10-09 21:48:37 +03:00
|
|
|
uint8_t INS;
|
2023-09-21 12:09:00 +03:00
|
|
|
uint8_t P1;
|
|
|
|
uint8_t P2;
|
|
|
|
|
|
|
|
//body
|
2024-07-06 14:08:44 +03:00
|
|
|
uint16_t Lc; //data length
|
|
|
|
uint16_t Le; //maximum response data length expected by client
|
|
|
|
|
|
|
|
//Le can have value of 0x00, which actually meand 0x100 = 256
|
|
|
|
bool LePresent;
|
|
|
|
uint8_t Data[0];
|
|
|
|
} FURI_PACKED ISO7816_Command_APDU;
|
2023-09-21 12:09:00 +03:00
|
|
|
|
2024-07-06 14:08:44 +03:00
|
|
|
typedef struct {
|
2023-09-21 12:09:00 +03:00
|
|
|
uint8_t SW1;
|
2023-10-09 21:48:37 +03:00
|
|
|
uint8_t SW2;
|
2024-07-06 14:08:44 +03:00
|
|
|
uint16_t DataLen;
|
|
|
|
uint8_t Data[0];
|
|
|
|
} FURI_PACKED ISO7816_Response_APDU;
|
2023-09-21 12:09:00 +03:00
|
|
|
|
2024-06-01 19:45:27 +03:00
|
|
|
void iso7816_answer_to_reset(Iso7816Atr* atr);
|
2024-07-06 14:08:44 +03:00
|
|
|
uint8_t iso7816_read_command_apdu(
|
|
|
|
ISO7816_Command_APDU* command,
|
|
|
|
const uint8_t* pcToReaderDataBlock,
|
|
|
|
uint32_t pcToReaderDataBlockLen);
|
2023-09-21 12:09:00 +03:00
|
|
|
void iso7816_write_response_apdu(
|
2024-07-06 14:08:44 +03:00
|
|
|
const ISO7816_Response_APDU* response,
|
2024-06-01 19:45:27 +03:00
|
|
|
uint8_t* readerToPcDataBlock,
|
2024-07-06 14:08:44 +03:00
|
|
|
uint32_t* readerToPcDataBlockLen);
|