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 _STESEAPI_H_ 21 #define _STESEAPI_H_ 22 23 #include <stdint.h> 24 25 typedef struct StEse_data { 26 uint16_t len; /*!< length of the buffer */ 27 uint8_t* p_data; /*!< pointer to a buffer */ 28 } StEse_data; 29 30 typedef enum { 31 ESESTATUS_SUCCESS, 32 ESESTATUS_FAILED, 33 ESESTATUS_INVALID_PARAMETER, 34 ESESTATUS_NOT_INITIALISED, 35 ESESTATUS_ALREADY_INITIALISED, 36 ESESTATUS_FEATURE_NOT_SUPPORTED, 37 ESESTATUS_CONNECTION_SUCCESS, 38 ESESTATUS_CONNECTION_FAILED, 39 ESESTATUS_BUSY, 40 ESESTATUS_UNKNOWN_ERROR, 41 } ESESTATUS; 42 43 typedef enum { 44 ESE_STATUS_CLOSE = 0x00, 45 ESE_STATUS_OPEN, 46 } SpiEse_status; 47 48 /* SPI Control structure */ 49 typedef struct ese_Context { 50 SpiEse_status EseLibStatus; /* Indicate if Ese Lib is open or closed */ 51 void* pDevHandle; 52 } ese_Context_t; 53 54 /** 55 * StEse_init 56 * 57 * This function initializes protocol stack instance variables 58 * 59 * @param void 60 * 61 * @return This function return ESESTATUS_SUCCES (0) in case of success 62 * In case of failure returns other failure value. 63 * 64 */ 65 ESESTATUS StEse_init(); 66 67 /** 68 * StEse_Transceive 69 * 70 * This function prepares the C-APDU, send to ESE and then receives the 71 * response from ESE, decode it and returns data. 72 * 73 * @param pCmd: Command to eSE 74 * @param pRsp: Response from eSE (Returned data to be freed 75 * after copying) 76 * 77 * @return ESESTATUS_SUCCESS On Success ESESTATUS_SUCCESS else proper error code 78 * 79 */ 80 ESESTATUS StEse_Transceive(StEse_data* pCmd, StEse_data* pRsp); 81 82 /** 83 * StEse_close 84 * 85 * This function close the ESE interface and free all resources. 86 * 87 * @param void 88 * 89 * @return ESESTATUS_SUCCESS Always return ESESTATUS_SUCCESS (0). 90 * 91 */ 92 93 ESESTATUS StEse_close(void); 94 95 /** 96 * StEseApi_isOpen 97 * 98 * This function checks if the hal is opened. 99 * 100 * @param void 101 * 102 * @return false if it is close, otherwise true 103 * 104 */ 105 bool StEseApi_isOpen(); 106 107 /** 108 * StEse_getAtr 109 * 110 * This function get the last ATR received. 111 * 112 * @param void 113 * 114 * @return pointer to the ATR array. 115 * 116 */ 117 uint8_t* StEse_getAtr(void); 118 119 /** 120 * StEse_Reset 121 * 122 * This function get the last ATR received. 123 * 124 * @param void 125 * 126 * @return ESESTATUS_SUCCESS is successful, ESESTATUS_SUCCESS otherwise 127 * 128 */ 129 ESESTATUS StEse_Reset(void); 130 131 #endif /* _STESEAPI_H_ */ 132