#ifndef SSP_APDU_H
#define SSP_APDU_H

#include "ssp.h"

#define INVALID_CHANNEL                 0xFF

#define MAX_SSP_CAPDU_DATA_SIZE         255
#define MAX_SSP_RAPDU_DATA_SIZE         256

typedef struct apdu_header {
    uint8_t cla; /* Class of instruction */
    uint8_t ins; /* Instruction code */
    uint8_t p1; /* Instruction parameter 1 */
    uint8_t p2; /* Instruction parameter 2 */
#ifndef EXTENDED_APDU
    uint8_t lc; /* Size of command data. Ommited when zero */
#else
    uint32_t lc; /* Size of command data. Ommited when zero */
#endif
} apdu_header_t;

SSPSTATUS ssp_open_service_connection( uint8_t *channel, uint8_t ats[3] );
SSPSTATUS ssp_open_service_connection_with_appletID( const uint8_t *applet_id, uint8_t applet_id_size, uint8_t *channel);

SSPSTATUS ssp_close_service_connection( uint8_t channel );

/* rsp_data_size must contain size of buffer at rsp_data before call */
SSPSTATUS ssp_send_service_command( uint8_t channel, apdu_header_t hcmd,
                                    const uint8_t *cmd_data, uint8_t *rsp_data, uint32_t *rsp_data_size );

SSPSTATUS ese_status_2_ssp_status( ESESTATUS code );

#endif /* SSP_APDU_H */
