1 /****************************************************************************** 2 * 3 * Copyright (C) 2018 ST Microelectronics S.A. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at: 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 * 18 ******************************************************************************/ 19 20 #ifndef COMMANDAPDU_H_ 21 #define COMMANDAPDU_H_ 22 23 #define MAX_CMD_APDU_DATA_LENGTH 255 24 25 typedef struct CommandApdu { 26 char cla; 27 char ins; 28 char p1; 29 char p2; 30 char lc; 31 char data[MAX_CMD_APDU_DATA_LENGTH]; 32 char le; 33 } CommandApdu; 34 35 /** 36 * Transforms a CommandApdu into a byte array. 37 * 38 * @param cmdApdu:Apdu Structure (input) 39 * @param CommandApduArray: Array of bytes (output) 40 * 41 * @return size of CommandApduArray 42 */ 43 int CommandApdu_toByteArray(CommandApdu cmdApdu, char* CommandApduArray); 44 45 /** 46 * Get the size of a CommandApdu structure 47 * @param comdApdu: Apdu Structure to get the size 48 * @return Size of the CommandApdu 49 */ 50 int CommandApdu_getSize(CommandApdu cmdApdu); 51 52 /** 53 * Forms an APDU 54 * @param cla 55 * @param ins 56 * @param p1 57 * @param p2 58 * @param cmdDataSize 59 * @param cmdData 60 * @param le 61 * @param cmdApdu 62 * @return -1 if error 0 if ok 63 */ 64 int CommandApdu_formApduType4(char cla, char ins, char p1, char p2, char lc, 65 char* cmdData, char le, CommandApdu* cmdApdu); 66 67 /** 68 * Forms an APDU 69 * @param cla 70 * @param ins 71 * @param p1 72 * @param p2 73 * @param le 74 * @param cmdApdu 75 * @return -1 if error 0 if ok 76 */ 77 int CommandApdu_formApduType2(char cla, char ins, char p1, char p2, char le, 78 CommandApdu* cmdApdu); 79 80 #endif /* COMMANDAPDU_H_ */ 81