1 /******************************************************************************
2  *
3  *  Copyright 2020, 2023 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 #ifndef _WEAVER_PARSER_H_
20 #define _WEAVER_PARSER_H_
21 
22 #include <weaver_common.h>
23 
24 class WeaverParser {
25 public:
26   /**
27    * \brief virtual Function to Frame weaver applet request command for getSlots
28    *
29    * \param[out]    request - framed getslots command as vector
30    *
31    * \retval This function return true in case of success
32    *         In case of failure returns false.
33    */
34   virtual bool FrameGetSlotCmd(std::vector<uint8_t> &request) = 0;
35 
36   /**
37    * \brief virtual Function to Frame weaver applet request command for open
38    *
39    * \param[out]    request - framed open command as vector
40    *
41    * \retval This function return true in case of success
42    *         In case of failure returns false.
43    */
44   virtual bool FrameOpenCmd(std::vector<uint8_t> &request) = 0;
45 
46   /**
47    * \brief virtual Function to Frame weaver applet request command for read
48    *
49    * \param[in]     slotId  - input slotId to be used in read request.
50    * \param[in]     key     - input key to be used in read request.
51    * \param[out]    request - framed read command as vector
52    *
53    * \retval This function return true in case of success
54    *         In case of failure returns false.
55    */
56   virtual bool FrameReadCmd(uint32_t slotId, const std::vector<uint8_t> &key,
57                             std::vector<uint8_t> &request) = 0;
58 
59   /**
60    * \brief virtual Function to Frame weaver applet request command for write
61    *
62    * \param[in]     slotId  - input slotId to be used in write request.
63    * \param[in]     key     - input key to be used in write request.
64    * \param[in]     value   - input value to be used in write request.
65    * \param[out]    request - framed write command as vector
66    *
67    * \retval This function return true in case of success
68    *         In case of failure returns false.
69    */
70   virtual bool FrameWriteCmd(uint32_t slotId, const std::vector<uint8_t> &key,
71                              const std::vector<uint8_t> &value,
72                              std::vector<uint8_t> &request) = 0;
73 
74   /**
75    * \brief virtual Function to Frame weaver applet request command for get data
76    *
77    * \param[in]     p1      - p1 value for get Data command.
78    * \param[in]     p2      - p2 value for get Data command.
79    * \param[out]    request - framed get data command as vector
80    *
81    * \retval This function return true in case of success
82    *         In case of failure returns false.
83    */
84   virtual bool FrameGetDataCmd(uint8_t p1, uint8_t p2,
85                             std::vector<uint8_t> &request) = 0;
86 
87   /**
88    * \brief virtual Function to Parse getSlots response
89    *
90    * \param[in]     response  - response from applet.
91    * \param[out]    slotInfo  - parsed slots Information read out from applet
92    * response.
93    *
94    * \retval This function return true in case of success
95    *         In case of failure returns false.
96    */
97   virtual Status_Weaver ParseSlotInfo(std::vector<uint8_t> response,
98                                       SlotInfo &slotInfo) = 0;
99 
100   /**
101    * \brief virtual Function to Parse read response
102    *
103    * \param[in]     response  - response from applet.
104    * \param[out]    readInfo  - parsed read Information read out from applet
105    * response.
106    *
107    * \retval This function return true in case of success
108    *         In case of failure returns false.
109    */
110   virtual Status_Weaver ParseReadInfo(std::vector<uint8_t> response,
111                                       ReadRespInfo &readInfo) = 0;
112 
113   /**
114    * \brief virtual Function to Parse get data response
115    *
116    * \param[in]     response  - response from applet.
117    * \param[out]    readInfo  - parsed Get data Information read out from applet
118    * response.
119    *
120    * \retval This function return true in case of success
121    *         In case of failure returns false.
122    */
123   virtual Status_Weaver ParseGetDataInfo(std::vector<uint8_t> response,
124                                       GetDataRespInfo &getDataInfo) = 0;
125 
126   /**
127    * \brief virtual Function to check if response from applet is Success or not
128    *
129    * \param[in]     response  - response from applet.
130    *
131    * \retval This function return true if response code from applet is success
132    *         and false in other cases.
133    */
134   virtual bool isSuccess(std::vector<uint8_t> response) = 0;
135 
136   /**
137    * \brief virtual Function to get Weaver Applet ID
138    *
139    * \param[out]    aid  - applet ids of the weaver applet.
140    *
141    * \retval This function return true in case of success
142    *         In case of failure returns false.
143    */
144   virtual bool getAppletId(std::vector<std::vector<uint8_t>> &aid) = 0;
145 
146   /**
147    * \brief virtual destructor for weaver parser
148    */
~WeaverParser()149   virtual ~WeaverParser(){};
150 };
151 #endif /* _WEAVER_PARSER_H_ */
152