1 /****************************************************************************** 2 * 3 * Copyright 2018-2019,2021 NXP 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 * \addtogroup ISO7816-4_application_protocol_implementation 21 * 22 * @{ */ 23 24 #ifndef _PHNXPESE_APDU_H 25 #define _PHNXPESE_APDU_H 26 #include <phEseStatus.h> 27 28 /** 29 * \brief 7816-4 APDU command Header Size 30 * 31 */ 32 33 #define MIN_HEADER_LEN 4 34 35 /** 36 * \ingroup ISO7816-4_application_protocol_implementation 37 * \brief Command data unit structure params 38 * 39 */ 40 typedef struct phNxpEse_7816_cpdu { 41 uint8_t cla; /*!< Class of instruction */ 42 uint8_t ins; /*!< Instruction code */ 43 uint8_t p1; /*!< Instruction parameter 1 */ 44 uint8_t p2; /*!< Instruction parameter 2 */ 45 uint16_t lc; /*!< No of data present in the data field of the command */ 46 uint8_t cpdu_type; /*!< 0 - short len, 1 = extended len, this field is valid 47 only if le > 0*/ 48 uint8_t* pdata; /*!< application data*/ 49 uint8_t le_type; /*!< 0 - Le absent ,1 - one byte le,2 - two byte le or 3 - 3 50 byte le*/ 51 uint32_t le; /*!< le value field */ 52 } phNxpEse_7816_cpdu_t; 53 54 /** 55 * \ingroup ISO7816-4_application_protocol_implementation 56 * \brief Command data unit structure params 57 * 58 */ 59 typedef phNxpEse_7816_cpdu_t* pphNxpEse_7816_cpdu_t; 60 61 /** 62 * \ingroup ISO7816-4_application_protocol_implementation 63 * \brief Response data unit structure params 64 * 65 */ 66 typedef struct phNxpEse_7816_rpdu { 67 uint8_t sw1; /*!< Status byte most significant byte */ 68 uint8_t sw2; /*!< Status byte least significant byte */ 69 uint8_t* pdata; /*!< Buffer allocated by caller*/ 70 uint16_t len; /*!< Length of the buffer, updated by calling api */ 71 } phNxpEse_7816_rpdu_t; 72 73 /** 74 * \ingroup ISO7816-4_application_protocol_implementation 75 * \brief Response data unit structure params 76 * 77 */ 78 typedef phNxpEse_7816_rpdu_t* pphNxpEse_7816_rpdu_t; 79 80 /** 81 * \ingroup ISO7816-4_application_protocol_implementation 82 * \brief This function prepares C-APDU and sends to p61 and receives response 83 *from the p61. 84 * also it parses all required fields of the response PDU. 85 * 86 * \param[in] pCmd - CMD to p61 87 * \param[out] pRsp - RSP from p61(all required memory 88 *allocated by caller) 89 * 90 * \retval ESESTATUS_SUCCESS - On Success #pphNxpEse_7816_rpdu_t all fields are 91 *filled correctly. 92 * else proper error code. 93 * \retval ESESTATUS_INVALID_PARAMETER - If any invalid buffer passed from 94 *application \n 95 * \retval ESESTATUS_INSUFFICIENT_RESOURCES - Any problem occurred during 96 *allocating the memory \n 97 * \retval ESESTATUS_INVALID_BUFFER - If any invalid buffer received \n 98 * \retval ESESTATUS_FAILED - Any other error occurred. \n 99 */ 100 101 ESESTATUS phNxpEse_7816_Transceive(pphNxpEse_7816_cpdu_t pCmd, 102 pphNxpEse_7816_rpdu_t pRsp); 103 104 #endif /* _PHNXPESE_APDU_H */ 105 /** @} */ 106