refactoring. add ability to produce command specific apdu codes

This commit is contained in:
merlokk 2022-01-28 20:16:48 +02:00
commit 43577b3db4
3 changed files with 15 additions and 13 deletions

View file

@ -56,11 +56,6 @@ static const PxSE_AID_t PxSE_AID_LIST[] = {
{{0xA0, 0x00, 0x00, 0x05, 0x07, 0x06, 0x00}, "Proximity Micro-Payment System Environment (PMSE)" }
};
typedef struct {
const uint16_t Code;
const char *Description;
} APDUSpcCodeDescription_t;
static const APDUSpcCodeDescription_t SelectAPDUCodeDescriptions[] = {
{0x6984, "Key is blocked for use as key encryption key" },
{0x6985, "Command not allowed on deactivated ADF or maximum files count already reached" },
@ -72,14 +67,6 @@ static const APDUSpcCodeDescription_t SelectAPDUCodeDescriptions[] = {
{0x6A89, "AID already exists" }
};
static const char *GetSpecificAPDUCodeDesc(const APDUSpcCodeDescription_t *desc, const size_t desclen, uint16_t code) {
for (int i = 0; i < desclen; i++) {
if (desc[i].Code == code)
return desc[i].Description;
}
return GetAPDUCodeDescription(code >> 8, code & 0xff);
}
static uint8_t defaultKeyId = 1;
static uint8_t defaultKey[CIPURSE_AES_KEY_LENGTH] = CIPURSE_DEFAULT_KEY;
#define CIPURSE_MAX_AID_LENGTH 16

View file

@ -329,6 +329,14 @@ const char *GetAPDUCodeDescription(uint8_t sw1, uint8_t sw2) {
return APDUCodeTable[0].Description; //empty string
}
const char *GetSpecificAPDUCodeDesc(const APDUSpcCodeDescription_t *desc, const size_t desclen, uint16_t code) {
for (int i = 0; i < desclen; i++) {
if (desc[i].Code == code)
return desc[i].Description;
}
return GetAPDUCodeDescription(code >> 8, code & 0xff);
}
int APDUDecode(uint8_t *data, int len, APDU_t *apdu) {
ExtAPDUHeader_t *hapdu = (ExtAPDUHeader_t *)data;

View file

@ -38,6 +38,13 @@ typedef struct {
const APDUCode_t *GetAPDUCode(uint8_t sw1, uint8_t sw2);
const char *GetAPDUCodeDescription(uint8_t sw1, uint8_t sw2);
typedef struct {
const uint16_t Code;
const char *Description;
} APDUSpcCodeDescription_t;
const char *GetSpecificAPDUCodeDesc(const APDUSpcCodeDescription_t *desc, const size_t desclen, uint16_t code);
typedef struct {
uint8_t CLA;
uint8_t INS;