make style

This commit is contained in:
merlokk 2019-07-12 13:58:38 +03:00
commit d94c74b24b
4 changed files with 66 additions and 52 deletions

View file

@ -418,6 +418,12 @@ int APDUDecode(uint8_t *data, size_t len, APDUStruct *apdu) {
}
int APDUEncode(APDUStruct *apdu, uint8_t *data, size_t *len) {
if (len)
*len = 0;
if (apdu->le > 0x10000 || apdu->lc != 0xffff)
return 1;
size_t dptr = 0;
data[dptr++] = apdu->cla;
data[dptr++] = apdu->ins;
@ -425,7 +431,7 @@ int APDUEncode(APDUStruct *apdu, uint8_t *data, size_t *len) {
data[dptr++] = apdu->p2;
if (apdu->lc) {
if (apdu->extended_apdu || apdu->lc > 0xff || apdu->le > 0xff) {
if (apdu->extended_apdu || apdu->lc > 0xff || apdu->le > 0x100) {
data[dptr++] = 0x00;
data[dptr++] = (apdu->lc >> 8) & 0xff;
data[dptr++] = (apdu->lc) & 0xff;
@ -441,19 +447,29 @@ int APDUEncode(APDUStruct *apdu, uint8_t *data, size_t *len) {
if (apdu->le) {
if (apdu->extended_apdu) {
if (apdu->le != 0x10000) {
data[dptr++] = 0x00;
data[dptr++] = (apdu->le >> 8) & 0xff;
data[dptr++] = (apdu->le) & 0xff;
} else {
data[dptr++] = 0x00;
data[dptr++] = 0x00;
data[dptr++] = 0x00;
}
} else {
if (apdu->le != 0x100)
data[dptr++] = apdu->le;
else
data[dptr++] = 0x00;
}
}
if (len)
*len = dptr;
return 0;
}
void APDUPrint(APDUStruct apdu) {
PrintAndLogEx(INFO, "apdu: %scase=%02x cla=%02x ins=%02x p1=%02x p2=%02x lc=%d le=%d\n",
PrintAndLogEx(INFO, "apdu: %scase=%02x cla=%02x ins=%02x p1=%02x p2=%02x Lc=%d Le=%d\n",
apdu.extended_apdu ? "[e]" : "", apdu.case_type, apdu.cla, apdu.ins, apdu.p1, apdu.p2, apdu.lc, apdu.le);
}

View file

@ -32,8 +32,7 @@ typedef struct {
const APDUCode *GetAPDUCode(uint8_t sw1, uint8_t sw2);
const char *GetAPDUCodeDescription(uint8_t sw1, uint8_t sw2);
typedef struct
{
typedef struct {
uint8_t cla;
uint8_t ins;
uint8_t p1;
@ -41,8 +40,7 @@ typedef struct
uint8_t lc[3];
} __attribute__((packed)) ExtAPDUHeader;
typedef struct
{
typedef struct {
uint8_t cla;
uint8_t ins;
uint8_t p1;