1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 #include <ese/ese.h>
19 
20 #include "ese_operations_interface.h"
21 #include "ese_operations_wrapper.h"
22 
InitializeEse(struct EseInterface * ese,EseOperationsInterface * ops_interface)23 void EseOperationsWrapper::InitializeEse(
24     struct EseInterface *ese, EseOperationsInterface *ops_interface) {
25   EseOperationsWrapperData data;
26   data.ops_interface = ops_interface;
27   ese_init(ese, data.wrapper);
28 }
29 
EseOpen(struct EseInterface * ese,void * data)30 static int EseOpen(struct EseInterface *ese, void *data) {
31   return EseOperationsWrapperData::ops_interface->EseOpen(ese, data);
32 }
33 
EseHwReceive(struct EseInterface * ese,uint8_t * data,uint32_t len,int complete)34 static uint32_t EseHwReceive(struct EseInterface *ese, uint8_t *data, uint32_t len, int complete) {
35   return EseOperationsWrapperData::ops_interface->EseHwReceive(ese, data, len, complete);
36 }
37 
EseHwTransmit(struct EseInterface * ese,const uint8_t * data,uint32_t len,int complete)38 static uint32_t EseHwTransmit(struct EseInterface *ese, const uint8_t *data, uint32_t len, int complete) {
39   return EseOperationsWrapperData::ops_interface->EseHwTransmit(ese, data, len, complete);
40 }
41 
EseReset(struct EseInterface * ese)42 static int EseReset(struct EseInterface *ese) {
43   return EseOperationsWrapperData::ops_interface->EseReset(ese);
44 }
45 
EseTransceive(struct EseInterface * ese,const struct EseSgBuffer * tx_sg,uint32_t tx_nsg,struct EseSgBuffer * rx_sg,uint32_t rx_nsg)46 static uint32_t EseTransceive(struct EseInterface *ese, const struct EseSgBuffer *tx_sg, uint32_t tx_nsg,
47                                struct EseSgBuffer *rx_sg, uint32_t rx_nsg) {
48   return EseOperationsWrapperData::ops_interface->EseTransceive(ese, tx_sg, tx_nsg, rx_sg, rx_nsg);
49 }
50 
EsePoll(struct EseInterface * ese,uint8_t poll_for,float timeout,int complete)51 static int EsePoll(struct EseInterface *ese, uint8_t poll_for, float timeout, int complete) {
52   return EseOperationsWrapperData::ops_interface->EsePoll(ese, poll_for, timeout, complete);
53 }
54 
EseClose(struct EseInterface * ese)55 static void EseClose(struct EseInterface *ese) {
56   return EseOperationsWrapperData::ops_interface->EseClose(ese);
57 }
58 
59 EseOperationsInterface *EseOperationsWrapperData::ops_interface =
60   reinterpret_cast<EseOperationsInterface *>(NULL);
61 
62 static const char *kErrors[] = {};
63 const struct EseOperations EseOperationsWrapperData::ops = {
64   .name = "EseOperationsWrapper HW",
65   .open = &EseOpen,
66   .hw_receive = &EseHwReceive,
67   .hw_transmit = &EseHwTransmit,
68   .hw_reset = &EseReset,
69   .poll = &EsePoll,
70   .transceive = &EseTransceive,
71   .close = &EseClose,
72   .opts = NULL,
73   .errors = kErrors,
74   .errors_count = 0,
75 };
76 const struct EseOperations *EseOperationsWrapperData::wrapper_ops =
77   &EseOperationsWrapperData::ops;
78