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   int bgt;
34 
35   int polling_interval;
36 
37   uint32_t devMaxFreq;
38   /*!< Communication speed between DH and ESE
39    *
40    * This is the baudrate of the bus for communication between DH and ESE
41    */
42 
43   void* pDevHandle;
44   /*!< Device handle output */
45 } SpiDriver_config_t, *pSpiDriver_config_t; /* pointer to SpiDriver_config_t */
46 
47 /**
48  * Initializes the connection to the SE:
49  *  1- Initial configuration of the SPI bus (if needed)
50  *  2- Start the polling mechanism to read the ATP from the eSE and set-up the
51  *     atp struct.
52  *  3- Reconfigure SPI bus after the atp (if needed)
53  *
54  * @return 0 if connection could be initialized, -1 otherwise.
55  */
56 int SpiLayerInterface_init(SpiDriver_config_t* tSpiDriver);
57 
58 /**
59  * Sends a TPDU to the SE, waits for the response and returns it.
60  *
61  * @param cmdTpdu The TPDU to be sent.
62  * @param respTpdu The memory position where to store the response.
63  * @param numberOfBwt The maximum number of BWT to wait.
64  *
65  * @return 0 if everything went ok, -1 otherwise. If timeout expired with no
66  * response, 0 will be returned and respTpdu will be NULL.
67  */
68 int SpiLayerInterface_transcieveTpdu(Tpdu* cmdTpdu, Tpdu* respTpdu,
69                                      int numberOfBwt);
70 
71 void SpiLayerInterface_close(void* pDevHandle);
72 
73 /**
74  * Setup communication to the SE:
75  *  1- Perform a SE reset pulse
76  *  2- Start the polling mechanism to read the ATP from the eSE and set-up the
77  *     atp struct.
78  *  3- Configure the IFSD length with the SE.
79  *
80  * @return 0 if connection could be initialized, -1 otherwise.
81  */
82 int SpiLayerInterface_setup();
83 
84 #endif /* SPILAYERINTERFACE_H_ */
85