#ifndef __APDU_H__
#define __APDU_H__

#include "types.h"

typedef struct{
    union{
        struct{
            uint8_t sw1;
            uint8_t sw2;
        };
    };
   uint32_t size;
   uint8_t data[1];
}response_apdu_t;

// reference to ts_102221 Table 10.5
#define MK_CLA_INS(cla, ins)  (cla<<8 | ins)
#define SELECT_FILE_CLA_INS MK_CLA_INS(0x0, 0xA4)
#define STATUS_CLA_INS  MK_CLA_INS(0x80, 0xF2) 

typedef struct{
    uint8_t size_of_apdu;
    struct{
        uint8_t CLA; 
        uint8_t INS; 
        uint8_t P1; 
        uint8_t P2; 
    } header;
    struct{
        union{
        uint8_t P3;
        uint8_t lc; //Number of bytes in the command data field
        };
        uint8_t le; // Maximum number of data bytes expected in response of the command
        uint8_t data[1]; //Command data string
    }body;
}__attribute__((packed)) command_apdu_t, *command_apdu_ptr;

#endif /*__APDU_H__*/
