fix little endian vs big endian in the macros... again... but this time correct
[RRG-proxmark3.git] / client / src / iso7816 / apduinfo.h
bloba1528801ac716c3bdaf02b8362f34059fc986041
1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2017 Merlok
3 //
4 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
5 // at your option, any later version. See the LICENSE.txt file for the text of
6 // the license.
7 //-----------------------------------------------------------------------------
8 // APDU status bytes information
9 //-----------------------------------------------------------------------------
11 #ifndef APDUINFO_H__
12 #define APDUINFO_H__
14 #include "common.h"
16 #define APDUCODE_TYPE_NONE 0
17 #define APDUCODE_TYPE_INFO 1
18 #define APDUCODE_TYPE_WARNING 2
19 #define APDUCODE_TYPE_ERROR 3
20 #define APDUCODE_TYPE_SECURITY 4
22 typedef struct {
23 const char *ID;
24 const uint8_t Type;
25 const char *Description;
26 } APDUCode;
28 const APDUCode *GetAPDUCode(uint8_t sw1, uint8_t sw2);
29 const char *GetAPDUCodeDescription(uint8_t sw1, uint8_t sw2);
31 typedef struct {
32 uint8_t CLA;
33 uint8_t INS;
34 uint8_t P1;
35 uint8_t P2;
36 uint8_t Lc;
37 uint8_t *data;
38 } PACKED sAPDU;
40 typedef struct {
41 uint8_t cla;
42 uint8_t ins;
43 uint8_t p1;
44 uint8_t p2;
45 uint8_t lc[3];
46 } PACKED ExtAPDUHeader;
48 typedef struct {
49 uint8_t cla;
50 uint8_t ins;
51 uint8_t p1;
52 uint8_t p2;
53 uint16_t lc;
54 uint8_t *data;
55 uint32_t le;
56 bool extended_apdu;
57 uint8_t case_type;
58 } PACKED APDUStruct;
60 extern int APDUDecode(uint8_t *data, int len, APDUStruct *apdu);
61 extern int APDUEncode(APDUStruct *apdu, uint8_t *data, int *len);
62 extern int APDUEncodeS(sAPDU *sapdu, bool extended, uint16_t le, uint8_t *data, int *len);
63 extern void APDUPrint(APDUStruct apdu);
64 extern void APDUPrintEx(APDUStruct apdu, size_t maxdatalen);
66 void SAPDUPrint(sAPDU apdu, size_t maxdatalen);
67 #endif