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 #ifndef SPILAYERINTERFACE_H_ 20 #define SPILAYERINTERFACE_H_ 21 22 #include "utils-lib/Tpdu.h" 23 24 typedef struct SpiDriver_config { 25 char* pDevName; 26 /*!< Port name connected to ESE 27 * 28 * Platform specific canonical device name to which ESE is connected. 29 * 30 * e.g. On Linux based systems this would be /dev/p73 31 */ 32 33 uint32_t devMaxFreq; 34 /*!< Communication speed between DH and ESE 35 * 36 * This is the baudrate of the bus for communication between DH and ESE 37 */ 38 39 void* pDevHandle; 40 /*!< Device handle output */ 41 } SpiDriver_config_t, *pSpiDriver_config_t; /* pointer to SpiDriver_config_t */ 42 43 /** 44 * Initializes the connection to the SE: 45 * 1- Initial configuration of the SPI bus (if needed) 46 * 2- Start the polling mechanism to read the ATP from the eSE and set-up the 47 * atp struct. 48 * 3- Reconfigure SPI bus after the atp (if needed) 49 * 50 * @return 0 if connection could be initialized, -1 otherwise. 51 */ 52 int SpiLayerInterface_init(SpiDriver_config_t* tSpiDriver); 53 54 /** 55 * Sends a TPDU to the SE, waits for the response and returns it. 56 * 57 * @param cmdTpdu The TPDU to be sent. 58 * @param respTpdu The memory position where to store the response. 59 * @param numberOfBwt The maximum number of BWT to wait. 60 * 61 * @return 0 if everything went ok, -1 otherwise. If timeout expired with no 62 * response, 0 will be returned and respTpdu will be NULL. 63 */ 64 int SpiLayerInterface_transcieveTpdu(Tpdu* cmdTpdu, Tpdu* respTpdu, 65 int numberOfBwt); 66 67 void SpiLayerInterface_close(void* pDevHandle); 68 69 /** 70 * Setup communication to the SE: 71 * 1- Perform a SE reset pulse 72 * 2- Start the polling mechanism to read the ATP from the eSE and set-up the 73 * atp struct. 74 * 3- Configure the IFSD length with the SE. 75 * 76 * @return 0 if connection could be initialized, -1 otherwise. 77 */ 78 int SpiLayerInterface_setup(); 79 80 #endif /* SPILAYERINTERFACE_H_ */ 81