1 /*
2  * Copyright (C) 2017-2018, 2020 NXP
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 #include "NCILxDebugDecoder.h"
18 #include "phOsal_Posix.h"
19 
20 #include <netinet/in.h>
21 #include <cstdint>
22 #include <cstring>
23 
24 using namespace std;
25 
26 /*
27 #define LOG_FUNCTION_ENTRY \
28             phOsal_LogFunctionEntry((const uint8_t*) \
29                  "LxDecoder",(const uint8_t*)__FUNCTION__)
30 #define LOG_FUNCTION_EXIT \
31             phOsal_LogFunctionExit((const uint8_t*) \
32                   "LxDecoder",(const uint8_t*)__FUNCTION__)
33 */
34 
35 #define LOG_FUNCTION_ENTRY
36 #define LOG_FUNCTION_EXIT
37 
38 NCI_LxDebug_Decoder* NCI_LxDebug_Decoder::mLxDbgDecoder = nullptr;
39 
40 /*******************************************************************************
41  **
42  ** Function:        NCI_LxDebug_Decoder()
43  **
44  ** Description:
45  **
46  ** Returns:         nothing
47  **
48  ******************************************************************************/
NCI_LxDebug_Decoder()49 NCI_LxDebug_Decoder::NCI_LxDebug_Decoder()
50     : mL2DebugMode(false),        // bit:0 Byte0
51       mFelicaRFDebugMode(false),  // bit:1 Byte0
52       mFelicaSCDebugMode(false),  // bit:2 Byte0
53       mL1DebugMode(false),        // bit:4 Byte0
54       m7816DebugMode(false),      // bit:6 Byte0
55       mRssiDebugMode(false) {     // bit:0 Byte1
56 }
57 
58 /*******************************************************************************
59  **
60  ** Function:        ~NCI_LxDebug_Decoder()
61  **
62  ** Description:
63  **
64  ** Returns:         nothing
65  **
66  ******************************************************************************/
~NCI_LxDebug_Decoder()67 NCI_LxDebug_Decoder::~NCI_LxDebug_Decoder() { mLxDbgDecoder = nullptr; }
68 
69 /*******************************************************************************
70  **
71  ** Function:        getInstance()
72  **
73  ** Description:     This function return the singleton of LxDebug Decoder
74  **
75  ** Returns:         return singleton object
76  **
77  ******************************************************************************/
getInstance()78 NCI_LxDebug_Decoder& NCI_LxDebug_Decoder::getInstance() {
79   if (mLxDbgDecoder == nullptr) {
80     mLxDbgDecoder = new NCI_LxDebug_Decoder;
81     return (*mLxDbgDecoder);
82   } else
83     return (*mLxDbgDecoder);
84 }
85 
86 /*******************************************************************************
87  **
88  ** Function:        setLxDebugModes(uint8_t *, uint16_t)
89  **
90  ** Description:     This function sets the proper Lx Debug level decoding
91  **
92  ** Returns:         void
93  **
94  ******************************************************************************/
setLxDebugModes(uint8_t * pNciPkt,uint16_t pktLen)95 void NCI_LxDebug_Decoder::setLxDebugModes(uint8_t* pNciPkt,
96                                           __attribute__((unused))
97                                           uint16_t pktLen) {
98   mL2DebugMode = (pNciPkt[7] & 0x01) ? true : false;        // bit:0 Byte0
99   mFelicaRFDebugMode = (pNciPkt[7] & 0x02) ? true : false;  // bit:1 Byte0
100   mFelicaSCDebugMode = (pNciPkt[7] & 0x04) ? true : false;  // bit:2 Byte0
101   mL1DebugMode = (pNciPkt[7] & 0x10) ? true : false;        // bit:4 Byte0
102   m7816DebugMode = (pNciPkt[7] & 0x40) ? true : false;      // bit:6 Byte0
103   mRssiDebugMode = (pNciPkt[8] & 0x01) ? true : false;      // bit:0 Byte1
104 
105   phOsal_LogInfoU32d((const uint8_t*)"LxDecoder> L1 Debug Enable",
106                      mL1DebugMode);
107   phOsal_LogInfoU32d((const uint8_t*)"LxDecoder> L2 Debug Enable",
108                      mL2DebugMode);
109   phOsal_LogInfoU32d((const uint8_t*)"LxDecoder> FelicaRF Enable",
110                      mFelicaRFDebugMode);
111   phOsal_LogInfoU32d((const uint8_t*)"LxDecoder> FelicaSC Enable",
112                      mFelicaSCDebugMode);
113   phOsal_LogInfoU32d((const uint8_t*)"LxDecoder> 7816-4RC Enable",
114                      m7816DebugMode);
115   phOsal_LogInfoU32d((const uint8_t*)"LxDecoder> RSSI Dbg Enable",
116                      mRssiDebugMode);
117 }
118 
119 /*******************************************************************************
120  **
121  ** Function:        processLxDbgNciPkt(uint8_t *,uint16_t)
122  **
123  ** Description:     This function process Lx NTF, finds the type of it whether
124  *L1
125  **                  or L2 and then calls the appropriate decoding function
126  **
127  ** Returns:         void
128  **
129  ******************************************************************************/
processLxDbgNciPkt(uint8_t * pNciPkt,uint16_t pktLen)130 void NCI_LxDebug_Decoder::processLxDbgNciPkt(uint8_t* pNciPkt,
131                                              uint16_t pktLen) {
132   LOG_FUNCTION_ENTRY;
133 
134   sLxNtfCoded_t sLxNtfCoded = {.pLxNtf = nullptr, .LxNtfLen = 0};
135   psLxNtfCoded_t psLxNtfCoded = &sLxNtfCoded;
136 
137   sLxNtfDecoded_t sLxNtfDecoded;
138   sL1NtfDecoded_t sL1NtfDecoded;
139   sL2NtfDecoded_t sL2NtfDecoded;
140 
141   memset((uint8_t*)&sLxNtfDecoded, 0, sizeof(sLxNtfDecoded_t));
142   memset((uint8_t*)&sL1NtfDecoded, 0, sizeof(sL1NtfDecoded_t));
143   memset((uint8_t*)&sL2NtfDecoded, 0, sizeof(sL2NtfDecoded_t));
144 
145   psLxNtfDecoded_t psLxNtfDecoded = &sLxNtfDecoded;
146   psLxNtfDecoded->psL1NtfDecoded = &sL1NtfDecoded;
147   psLxNtfDecoded->psL2NtfDecoded = &sL2NtfDecoded;
148 
149   if ((pNciPkt != nullptr) && (pktLen != 0)) {
150     if (pNciPkt[0] == 0x6F && (pNciPkt[1] == 0x35 || pNciPkt[1] == 0x36)) {
151       psLxNtfCoded->pLxNtf = pNciPkt;
152       psLxNtfCoded->LxNtfLen = pktLen;
153     } else if ((pNciPkt[0] == 0x20) && (pNciPkt[1] == 0x02)) {
154       if ((pNciPkt[4] == 0xA0) && (pNciPkt[5] == 0x1D)) {
155         setLxDebugModes(pNciPkt, pktLen);
156       }
157     } else
158       return;
159   } else
160     return;
161 
162   if ((psLxNtfCoded->pLxNtf != nullptr) && (psLxNtfCoded->LxNtfLen != 0)) {
163     if (psLxNtfCoded->pLxNtf[1] == SYSTEM_DEBUG_STATE_L1_MESSAGE) {
164       psLxNtfDecoded->level = SYSTEM_DEBUG_STATE_L1_MESSAGE;
165       parseL1DbgNtf(psLxNtfCoded, psLxNtfDecoded);
166     } else if (psLxNtfCoded->pLxNtf[1] == SYSTEM_DEBUG_STATE_L2_MESSAGE) {
167       psLxNtfDecoded->level = SYSTEM_DEBUG_STATE_L2_MESSAGE;
168       parseL2DbgNtf(psLxNtfCoded, psLxNtfDecoded);
169     }
170 
171     printLxDebugInfo(psLxNtfDecoded);
172   } else
173     return;
174 
175   LOG_FUNCTION_EXIT;
176 }
177 
178 /*******************************************************************************
179  **
180  ** Function:        parseL1DebugNtf(psLxNtfCoded_t, psLxNtfDecoded_t)
181  **
182  ** Description:     This function parse L1 NTF and decodes the values.
183  **
184  ** Returns:         void
185  **
186  ******************************************************************************/
parseL1DbgNtf(psLxNtfCoded_t psLxNtfCoded,psLxNtfDecoded_t psLxNtfDecoded)187 void NCI_LxDebug_Decoder::parseL1DbgNtf(psLxNtfCoded_t psLxNtfCoded,
188                                         psLxNtfDecoded_t psLxNtfDecoded) {
189   LOG_FUNCTION_ENTRY;
190 
191   sLxNtfDecodingInfo_t sLxNtfDecodingInfo;
192   memset((uint8_t*)&sLxNtfDecodingInfo, 0, sizeof(sLxNtfDecodingInfo_t));
193   psLxNtfDecodingInfo_t psLxNtfDecodingInfo = &sLxNtfDecodingInfo;
194 
195   psLxNtfDecodingInfo->baseIndex = 3;  // Entry Start Index
196 
197   psLxNtfDecodingInfo->milliSecOffset = 0;  // 3rd byte 4th byte
198   psLxNtfDecodingInfo->microSecOffset = 2;  // 5th byte 6th byte
199   psLxNtfDecodingInfo->rawRSSIOffset = 0;   // RSSI dbg enable
200   psLxNtfDecodingInfo->intrpltdRSSIOffset = 4;
201   psLxNtfDecodingInfo->apcOffset = 4;
202   psLxNtfDecodingInfo->cliffStateTriggerTypeOffset = 6;
203   psLxNtfDecodingInfo->cliffStateRFTechModeOffset = 6;
204   psLxNtfDecodingInfo->eddOffset = 7;
205   psLxNtfDecodingInfo->retCode78164Offset = 8;
206 
207   if (psLxNtfCoded->pLxNtf[2] == L1_EVT_LEN)  // 0x07 == Normal L1 Event Entry
208   {
209     // TODO: Remove common code
210     if (mRssiDebugMode) {
211       decodeCLIFFState(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
212       decodeRSSIValues(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
213     } else {
214       decodeTimeStamp(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
215       decodeCLIFFState(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
216       if ((psLxNtfDecoded->psL1NtfDecoded->sInfo
217                .pCliffStateTriggerTypeDirection) &&
218           (!strcmp((const char*)psLxNtfDecoded->psL1NtfDecoded->sInfo
219                        .pCliffStateTriggerTypeDirection,
220                    (const char*)"CLF_EVT_RX")))
221         decodeRSSIValues(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
222       else {
223         decodeAPCTable(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
224         calculateTxVpp(psLxNtfDecoded);
225       }
226     }
227   } else if (psLxNtfCoded->pLxNtf[2] ==
228              L1_EVT_EXTRA_DBG_LEN)  // 0x08 == L1 Event Entry + EDD
229   {
230     if (mRssiDebugMode) {
231       decodeCLIFFState(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
232       decodeRSSIValues(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
233     } else {
234       decodeTimeStamp(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
235       decodeCLIFFState(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
236       if ((psLxNtfDecoded->psL1NtfDecoded->sInfo
237                .pCliffStateTriggerTypeDirection) &&
238           (!strcmp((const char*)psLxNtfDecoded->psL1NtfDecoded->sInfo
239                        .pCliffStateTriggerTypeDirection,
240                    (const char*)"CLF_EVT_RX")))
241         decodeRSSIValues(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
242       else {
243         decodeAPCTable(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
244         calculateTxVpp(psLxNtfDecoded);
245       }
246     }
247     decodeExtraDbgData(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
248   } else if (psLxNtfCoded->pLxNtf[2] ==
249              L1_EVT_7816_RET_CODE_LEN)  // 0xA0 == L1 Event Entry + EDD + 7816-4
250                                         // SW1SW2
251   {
252     if (mRssiDebugMode) {
253       decodeCLIFFState(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
254       decodeRSSIValues(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
255     } else {
256       decodeTimeStamp(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
257       decodeCLIFFState(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
258       if ((psLxNtfDecoded->psL1NtfDecoded->sInfo
259                .pCliffStateTriggerTypeDirection) &&
260           (!strcmp((const char*)psLxNtfDecoded->psL1NtfDecoded->sInfo
261                        .pCliffStateTriggerTypeDirection,
262                    (const char*)"CLF_EVT_RX")))
263         decodeRSSIValues(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
264       else {
265         decodeAPCTable(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
266         calculateTxVpp(psLxNtfDecoded);
267       }
268     }
269     decodeExtraDbgData(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
270     decode78164RetCode(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
271   } else {
272     phOsal_LogDebug((const uint8_t*)"LxDecoder> Invalid Length !");
273   }
274 
275   LOG_FUNCTION_EXIT;
276 }
277 
278 /*******************************************************************************
279  **
280  ** Function:        parseL2DbgNtf(psLxNtfCoded_t, psLxNtfDecoded_t)
281  **
282  ** Description:     This functions parses L2 NTF, finds event TAG and decodes
283  **                  them one by one.
284  **
285  ** Returns:         void
286  **
287  ******************************************************************************/
parseL2DbgNtf(psLxNtfCoded_t psLxNtfCoded,psLxNtfDecoded_t psLxNtfDecoded)288 void NCI_LxDebug_Decoder::parseL2DbgNtf(psLxNtfCoded_t psLxNtfCoded,
289                                         psLxNtfDecoded_t psLxNtfDecoded) {
290   LOG_FUNCTION_ENTRY;
291 
292   uint8_t tlvCount = 0;
293   int32_t totalTLVlength = 0;
294   uint8_t tlvIndex = 3;
295   sLxNtfDecodingInfo_t sLxNtfDecodingInfo;
296   psLxNtfDecodingInfo_t psLxNtfDecodingInfo = &sLxNtfDecodingInfo;
297 
298   memset((uint8_t*)&sLxNtfDecodingInfo, 0, sizeof(sLxNtfDecodingInfo_t));
299   // Set the Decoding Mapping
300   psLxNtfDecodingInfo->milliSecOffset = 1;
301   psLxNtfDecodingInfo->microSecOffset = 3;
302   psLxNtfDecodingInfo->rawRSSIOffset = 1;
303   psLxNtfDecodingInfo->intrpltdRSSIOffset = 5;
304   psLxNtfDecodingInfo->apcOffset = 5;
305   psLxNtfDecodingInfo->felicaCmdOffset = 5;
306   psLxNtfDecodingInfo->felicaRspCodeOffset = 7;
307   psLxNtfDecodingInfo->cliffStateTriggerTypeOffset = 7;
308   psLxNtfDecodingInfo->cliffStateRFTechModeOffset = 7;
309   psLxNtfDecodingInfo->felicaCmdOffset = 7;
310   psLxNtfDecodingInfo->felicaRspStatusFlagsOffset = 8;
311   psLxNtfDecodingInfo->eddOffset = 8;
312   psLxNtfDecodingInfo->eddFelicaOffset = 9;
313 
314   totalTLVlength = psLxNtfCoded->pLxNtf[2];
315   phOsal_LogDebugU32d((const uint8_t*)"LxDecoder> Total TLV length",
316                       totalTLVlength);
317 
318   do {
319     psLxNtfDecoded->psL2NtfDecoded->tlvCount = tlvCount;
320     psLxNtfDecodingInfo->baseIndex = tlvIndex;
321 
322     if (psLxNtfCoded->pLxNtf[tlvIndex] == (L2_EVT_TAG_ID | L2_EVT_TAG_ID_LEN)) {
323       totalTLVlength = totalTLVlength - (L2_EVT_TAG_ID_LEN + 1);
324       tlvIndex = tlvIndex + (L2_EVT_TAG_ID_LEN + 1);
325       if (mRssiDebugMode) {
326         decodeRSSIValues(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
327         decodeCLIFFState(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
328       } else {
329         decodeTimeStamp(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
330         decodeCLIFFState(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
331         if ((psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
332                  .pCliffStateTriggerTypeDirection) &&
333             (!strcmp(
334                 (const char*)psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
335                     .pCliffStateTriggerTypeDirection,
336                 (const char*)"CLF_EVT_RX")))
337           decodeRSSIValues(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
338         else {
339           decodeAPCTable(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
340           calculateTxVpp(psLxNtfDecoded);
341         }
342       }
343     } else if (psLxNtfCoded->pLxNtf[tlvIndex] ==
344                (L2_EVT_TAG_ID | L2_EVT_TAG_ID_EXTRA_DBG_LEN))  // EDD
345     {
346       totalTLVlength = totalTLVlength - (L2_EVT_TAG_ID_EXTRA_DBG_LEN + 1);
347       tlvIndex = tlvIndex + L2_EVT_TAG_ID_EXTRA_DBG_LEN + 1;
348       if (mRssiDebugMode) {
349         decodeCLIFFState(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
350         decodeRSSIValues(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
351       } else {
352         decodeTimeStamp(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
353         decodeCLIFFState(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
354         if ((psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
355                  .pCliffStateTriggerTypeDirection) &&
356             (!strcmp(
357                 (const char*)psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
358                     .pCliffStateTriggerTypeDirection,
359                 (const char*)"CLF_EVT_RX")))
360           decodeRSSIValues(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
361         else {
362           decodeAPCTable(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
363           calculateTxVpp(psLxNtfDecoded);
364         }
365       }
366       decodeExtraDbgData(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
367     } else if (psLxNtfCoded->pLxNtf[tlvIndex] ==
368                (L2_EVT_FELICA_CMD_TAG_ID | L2_EVT_FELICA_CMD_TAG_ID_LEN)) {
369       totalTLVlength = totalTLVlength - (L2_EVT_FELICA_CMD_TAG_ID_LEN + 1);
370       tlvIndex = tlvIndex + L2_EVT_FELICA_CMD_TAG_ID_LEN + 1;
371       decodeTimeStamp(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
372       decodeRSSIValues(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
373       decodeFelicaCmdCode(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
374     } else if (psLxNtfCoded->pLxNtf[tlvIndex] ==
375                (L2_EVT_FELICA_CMD_TAG_ID |
376                 L2_EVT_FELICA_CMD_TAG_ID_EXTRA_DBG_LEN))  // EDD
377     {
378       totalTLVlength =
379           totalTLVlength - (L2_EVT_FELICA_CMD_TAG_ID_EXTRA_DBG_LEN + 1);
380       tlvIndex = tlvIndex + L2_EVT_FELICA_CMD_TAG_ID_EXTRA_DBG_LEN + 1;
381       decodeTimeStamp(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
382       decodeRSSIValues(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
383       decodeFelicaCmdCode(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
384       decodeExtraDbgData(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
385     } else if (psLxNtfCoded->pLxNtf[tlvIndex] ==
386                (L2_EVT_FELICA_SYS_CODE_TAG_ID |
387                 L2_EVT_FELICA_SYS_CODE_TAG_ID_LEN)) {
388       totalTLVlength = totalTLVlength - (L2_EVT_FELICA_SYS_CODE_TAG_ID_LEN + 1);
389       tlvIndex = tlvIndex + L2_EVT_FELICA_SYS_CODE_TAG_ID_LEN + 1;
390       decodeTimeStamp(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
391       decodeFelicaSystemCode(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
392     } else if (psLxNtfCoded->pLxNtf[tlvIndex] ==
393                (L2_EVT_FELICA_RSP_CODE_TAG_ID |
394                 L2_EVT_FELICA_RSP_CODE_TAG_ID_LEN)) {
395       totalTLVlength = totalTLVlength - (L2_EVT_FELICA_RSP_CODE_TAG_ID_LEN + 1);
396       tlvIndex = tlvIndex + L2_EVT_FELICA_RSP_CODE_TAG_ID_LEN + 1;
397       decodeTimeStamp(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
398       decodeAPCTable(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
399       calculateTxVpp(psLxNtfDecoded);
400       decodeFelicaRspCode(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
401     } else if (psLxNtfCoded->pLxNtf[tlvIndex] ==
402                (L2_EVT_FELICA_RSP_CODE_TAG_ID |
403                 L2_EVT_FELICA_RSP_CODE_TAG_ID_EXTRA_DBG_LEN)) {
404       totalTLVlength =
405           totalTLVlength - (L2_EVT_FELICA_RSP_CODE_TAG_ID_EXTRA_DBG_LEN + 1);
406       tlvIndex = tlvIndex + L2_EVT_FELICA_RSP_CODE_TAG_ID_EXTRA_DBG_LEN + 1;
407       decodeTimeStamp(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
408       decodeAPCTable(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
409       calculateTxVpp(psLxNtfDecoded);
410       decodeFelicaRspCode(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
411       decodeExtraDbgData(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
412     } else if (psLxNtfCoded->pLxNtf[tlvIndex] ==
413                (L2_EVT_FELICA_MISC_TAG_ID | L2_EVT_FELICA_MISC_TAG_ID_LEN)) {
414       totalTLVlength = totalTLVlength - (L2_EVT_FELICA_MISC_TAG_ID_LEN + 1);
415       tlvIndex = tlvIndex + L2_EVT_FELICA_MISC_TAG_ID_LEN + 1;
416       decodeTimeStamp(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
417       decodeFelicaMiscCode(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
418     } else if (psLxNtfCoded->pLxNtf[tlvIndex] ==
419                (L2_EVT_FELICA_MISC_TAG_ID |
420                 L2_EVT_FELICA_MISC_TAG_ID_EXTRA_DBG_LEN)) {
421       totalTLVlength =
422           totalTLVlength - (L2_EVT_FELICA_MISC_TAG_ID_EXTRA_DBG_LEN + 1);
423       tlvIndex = tlvIndex + L2_EVT_FELICA_MISC_TAG_ID_EXTRA_DBG_LEN + 1;
424       decodeTimeStamp(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
425       decodeFelicaMiscCode(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
426       decodeExtraDbgData(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
427     } else {
428       phOsal_LogDebug((const uint8_t*)"LxDecoder> Invalid Length !");
429     }
430   } while ((totalTLVlength > 0) && (++tlvCount < MAX_TLV));
431 
432   LOG_FUNCTION_EXIT;
433 }
434 
435 /*******************************************************************************
436  **
437  ** Function:        printLxDebugInfo(psLxNtfDecoded)
438  **
439  ** Description:     This function prints the decoded information
440  **
441  ** Returns:         void
442  **
443  ******************************************************************************/
printLxDebugInfo(psLxNtfDecoded_t psLxNtfDecoded)444 void NCI_LxDebug_Decoder::printLxDebugInfo(psLxNtfDecoded_t psLxNtfDecoded) {
445   if (psLxNtfDecoded != nullptr) {
446     if (psLxNtfDecoded->level == SYSTEM_DEBUG_STATE_L1_MESSAGE) {
447       phOsal_LogInfo((
448           const uint8_t*)"---------------------L1 Debug "
449                          "Information--------------------");
450       phOsal_LogInfoU32dd((const uint8_t*)"Time Stamp",
451                           psLxNtfDecoded->psL1NtfDecoded->sInfo.timeStampMs,
452                           psLxNtfDecoded->psL1NtfDecoded->sInfo.timeStampUs);
453       phOsal_LogInfoString(
454           (const uint8_t*)"Trigger Type",
455           psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateTriggerType);
456       phOsal_LogInfoString(
457           (const uint8_t*)"RF Tech and Mode",
458           psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateRFTechNMode);
459       phOsal_LogInfoString((const uint8_t*)"Event Type",
460                            psLxNtfDecoded->psL1NtfDecoded->sInfo
461                                .pCliffStateTriggerTypeDirection);
462       if (mRssiDebugMode) {
463         phOsal_LogInfoU32h((const uint8_t*)"Raw RSSI ADC",
464                            psLxNtfDecoded->psL1NtfDecoded->sInfo.rawRSSIADC);
465         phOsal_LogInfoU32h((const uint8_t*)"Raw RSSI AGC",
466                            psLxNtfDecoded->psL1NtfDecoded->sInfo.rawRSSIAGC);
467       } else
468         phOsal_LogInfoU32hh(
469             (const uint8_t*)"Interpolated RSSI",
470             psLxNtfDecoded->psL1NtfDecoded->sInfo.intrpltdRSSI[0],
471             psLxNtfDecoded->psL1NtfDecoded->sInfo.intrpltdRSSI[1]);
472       phOsal_LogInfoU32hh((const uint8_t*)"Auto Power Control",
473                           psLxNtfDecoded->psL1NtfDecoded->sInfo.APC[0],
474                           psLxNtfDecoded->psL1NtfDecoded->sInfo.APC[1]);
475       phOsal_LogInfoString((const uint8_t*)"L1 Error EDD",
476                            psLxNtfDecoded->psL1NtfDecoded->sInfo.pEddL1Error);
477       phOsal_LogInfoString((const uint8_t*)"L1 RxNak EDD",
478                            psLxNtfDecoded->psL1NtfDecoded->sInfo.pEddL1RxNak);
479       phOsal_LogInfoString((const uint8_t*)"L1 TxErr EDD",
480                            psLxNtfDecoded->psL1NtfDecoded->sInfo.pEddL1TxErr);
481       phOsal_LogInfoU32hh(
482           (const uint8_t*)"L1 7816-4 Ret Code",
483           psLxNtfDecoded->psL1NtfDecoded->sInfo.eddL178164RetCode[0],
484           psLxNtfDecoded->psL1NtfDecoded->sInfo.eddL178164RetCode[1]);
485       if ((psLxNtfDecoded->psL1NtfDecoded->sInfo
486                .pCliffStateTriggerTypeDirection) &&
487           (!strcmp((const char*)psLxNtfDecoded->psL1NtfDecoded->sInfo
488                        .pCliffStateTriggerTypeDirection,
489                    (const char*)"CLF_EVT_TX"))) {
490         phOsal_LogInfoU32d(
491             (const uint8_t*)"Residual Carrier",
492             psLxNtfDecoded->psL1NtfDecoded->sInfo.residualCarrier);
493         phOsal_LogInfoU32d((const uint8_t*)"Number Driver",
494                            psLxNtfDecoded->psL1NtfDecoded->sInfo.numDriver);
495         phOsal_LogInfo32f((const uint8_t*)"Vtx AMP",
496                           psLxNtfDecoded->psL1NtfDecoded->sInfo.vtxAmp);
497         phOsal_LogInfo32f((const uint8_t*)"Vtx LDO",
498                           psLxNtfDecoded->psL1NtfDecoded->sInfo.vtxLDO);
499         phOsal_LogInfoU32d((const uint8_t*)"Tx Vpp",
500                            psLxNtfDecoded->psL1NtfDecoded->sInfo.txVpp);
501       }
502       phOsal_LogInfo((
503           const uint8_t*)"----------------------------------------"
504                          "---------------------");
505     } else if (psLxNtfDecoded->level == SYSTEM_DEBUG_STATE_L2_MESSAGE) {
506       uint8_t tlvCount = psLxNtfDecoded->psL2NtfDecoded->tlvCount;
507 
508       for (int tlv = 0; tlv < tlvCount; tlv++) {
509         phOsal_LogInfo((
510             const uint8_t*)"---------------------L2 Debug "
511                            "Information--------------------");
512         phOsal_LogInfoU32d((const uint8_t*)"TLV Number", tlv);
513         phOsal_LogInfoU32dd(
514             (const uint8_t*)"Time Stamp",
515             psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlv].timeStampMs,
516             psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlv].timeStampUs);
517         phOsal_LogInfoString((const uint8_t*)"Trigger Type",
518                              psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlv]
519                                  .pCliffStateTriggerType);
520         phOsal_LogInfoString((const uint8_t*)"RF Tech and Mode",
521                              psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlv]
522                                  .pCliffStateRFTechNMode);
523         phOsal_LogInfoString((const uint8_t*)"Event Type",
524                              psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlv]
525                                  .pCliffStateTriggerTypeDirection);
526         if (mRssiDebugMode) {
527           phOsal_LogInfoU32h(
528               (const uint8_t*)"Raw RSSI ADC",
529               psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlv].rawRSSIADC);
530           phOsal_LogInfoU32h(
531               (const uint8_t*)"Raw RSSI AGC",
532               psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlv].rawRSSIAGC);
533         } else
534           phOsal_LogInfoU32hh(
535               (const uint8_t*)"Interpolated RSSI",
536               psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlv].intrpltdRSSI[0],
537               psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlv].intrpltdRSSI[1]);
538         phOsal_LogInfoU32hh(
539             (const uint8_t*)"Auto Power Control",
540             psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlv].APC[0],
541             psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlv].APC[1]);
542         phOsal_LogInfoString(
543             (const uint8_t*)"L2 WUP IOT EDD",
544             psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlv].pEddL2WUP);
545         if (mFelicaRFDebugMode || mFelicaSCDebugMode) {
546           phOsal_LogInfoU32h(
547               (const uint8_t*)"Felica Command Code",
548               psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlv].felicaCmdCode);
549           phOsal_LogInfoU32hh(
550               (const uint8_t*)"Felica System Code",
551               psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlv].felicaSysCode[0],
552               psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlv].felicaSysCode[1]);
553           phOsal_LogInfoU32h(
554               (const uint8_t*)"Felica Response Code",
555               psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlv].felicaRspCode);
556           phOsal_LogInfoU32hh((const uint8_t*)"Felica Rsp Code Status Flags",
557                               psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlv]
558                                   .felicaRspCodeStatusFlags[0],
559                               psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlv]
560                                   .felicaRspCodeStatusFlags[1]);
561           phOsal_LogInfoString(
562               (const uint8_t*)"Felica Misc Entry",
563               psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlv].pFelicaMisc);
564           phOsal_LogInfoU32h(
565               (const uint8_t*)"Felica EDD",
566               psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlv].eddFelica);
567         }
568         if ((psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
569                  .pCliffStateTriggerTypeDirection) &&
570             (!strcmp(
571                 (const char*)psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
572                     .pCliffStateTriggerTypeDirection,
573                 (const char*)"CLF_EVT_TX"))) {
574           phOsal_LogInfoU32d(
575               (const uint8_t*)"Residual Carrier",
576               psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlv].residualCarrier);
577           phOsal_LogInfoU32d(
578               (const uint8_t*)"Number Driver",
579               psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlv].numDriver);
580           phOsal_LogInfo32f(
581               (const uint8_t*)"Vtx AMP",
582               psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlv].vtxAmp);
583           phOsal_LogInfo32f(
584               (const uint8_t*)"Vtx LDO",
585               psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlv].vtxLDO);
586           phOsal_LogInfoU32d(
587               (const uint8_t*)"Tx Vpp",
588               psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlv].txVpp);
589         }
590       }
591     }
592   }
593 }
594 
595 /*******************************************************************************
596  **
597  ** Function:        decodeTimeStamp(psLxNtfCoded_t, psLxNtfDecodingInfo_t,
598  *psLxNtfDecoded_t)
599  **
600  ** Description:     This function decodes the time stamp.
601  **
602  ** Returns:         void
603  **
604  ******************************************************************************/
decodeTimeStamp(psLxNtfCoded_t psLxNtfCoded,psLxNtfDecodingInfo_t psLxNtfDecodingInfo,psLxNtfDecoded_t psLxNtfDecoded)605 void NCI_LxDebug_Decoder::decodeTimeStamp(
606     psLxNtfCoded_t psLxNtfCoded, psLxNtfDecodingInfo_t psLxNtfDecodingInfo,
607     psLxNtfDecoded_t psLxNtfDecoded) {
608   uint8_t base = 0;
609   uint8_t offsetMilliSec = 0;
610   uint8_t offsetMicroSec = 0;
611   uint8_t milliSec[2] = {0};
612   uint8_t microSec[2] = {0};
613 
614   if (psLxNtfDecodingInfo != nullptr) {
615     base = psLxNtfDecodingInfo->baseIndex;
616     offsetMilliSec = psLxNtfDecodingInfo->milliSecOffset;
617     offsetMicroSec = psLxNtfDecodingInfo->microSecOffset;
618   } else
619     return;
620 
621   /*Converting Little Endian to Big Endian*/
622   milliSec[1] = psLxNtfCoded->pLxNtf[base + offsetMilliSec];
623   offsetMilliSec++;
624   milliSec[0] = psLxNtfCoded->pLxNtf[base + offsetMilliSec];
625 
626   /*Converting Little Endian to Big Endian*/
627   microSec[1] = psLxNtfCoded->pLxNtf[base + offsetMicroSec];
628   offsetMicroSec++;
629   microSec[0] = psLxNtfCoded->pLxNtf[base + offsetMicroSec];
630 
631   if (psLxNtfCoded->pLxNtf[1] == SYSTEM_DEBUG_STATE_L1_MESSAGE) {
632     psLxNtfDecoded->psL1NtfDecoded->sInfo.timeStampMs =
633         ntohs(*((uint16_t*)milliSec));
634     psLxNtfDecoded->psL1NtfDecoded->sInfo.timeStampUs =
635         ntohs(*((uint16_t*)microSec));
636   } else if (psLxNtfCoded->pLxNtf[1] == SYSTEM_DEBUG_STATE_L2_MESSAGE) {
637     uint8_t tlvCount = psLxNtfDecoded->psL2NtfDecoded->tlvCount;
638     phOsal_LogInfoU32d((const uint8_t*)"tlvCount", tlvCount);
639     psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount].timeStampMs =
640         ntohs(*((uint16_t*)milliSec));
641     psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount].timeStampUs =
642         ntohs(*((uint16_t*)microSec));
643   }
644 }
645 
646 /*******************************************************************************
647  **
648  ** Function:        decodeRSSIandAPC(psLxNtfCoded_t, psLxNtfDecodingInfo_t,
649  *psLxNtfDecoded_t)
650  **
651  ** Description:     This function decodes RSSI values in case RSSI mode enabled
652  **
653  ** Returns:         void
654  **
655  ******************************************************************************/
decodeRSSIValues(psLxNtfCoded_t psLxNtfCoded,psLxNtfDecodingInfo_t psLxNtfDecodingInfo,psLxNtfDecoded_t psLxNtfDecoded)656 void NCI_LxDebug_Decoder::decodeRSSIValues(
657     psLxNtfCoded_t psLxNtfCoded, psLxNtfDecodingInfo_t psLxNtfDecodingInfo,
658     psLxNtfDecoded_t psLxNtfDecoded) {
659   uint8_t base = 0;
660   uint8_t offsetRawRSSI = 0;
661   uint8_t offsetIntrpltdRSSI = 0;
662   uint8_t rawRSSIAGC = 0;
663   uint8_t rawRSSIADC = 0;
664   uint8_t intrpltdRSSI[2] = {0};
665 
666   if (psLxNtfDecodingInfo != nullptr) {
667     base = psLxNtfDecodingInfo->baseIndex;
668     offsetRawRSSI = psLxNtfDecodingInfo->rawRSSIOffset;
669     offsetIntrpltdRSSI = psLxNtfDecodingInfo->intrpltdRSSIOffset;
670   } else
671     return;
672 
673   rawRSSIAGC = psLxNtfCoded->pLxNtf[base + offsetRawRSSI];
674   offsetRawRSSI++;
675   rawRSSIADC = psLxNtfCoded->pLxNtf[base + offsetRawRSSI];
676 
677   /*Converting Little Endian to Big Endian*/
678   intrpltdRSSI[0] = psLxNtfCoded->pLxNtf[base + offsetIntrpltdRSSI];
679   offsetIntrpltdRSSI++;
680   intrpltdRSSI[1] = psLxNtfCoded->pLxNtf[base + offsetIntrpltdRSSI];
681 
682   if (psLxNtfCoded->pLxNtf[1] == SYSTEM_DEBUG_STATE_L1_MESSAGE) {
683     if (mRssiDebugMode) {
684       psLxNtfDecoded->psL1NtfDecoded->sInfo.rawRSSIADC = rawRSSIADC;
685       psLxNtfDecoded->psL1NtfDecoded->sInfo.rawRSSIAGC = rawRSSIAGC;
686     }
687     psLxNtfDecoded->psL1NtfDecoded->sInfo.intrpltdRSSI[0] = intrpltdRSSI[0];
688     psLxNtfDecoded->psL1NtfDecoded->sInfo.intrpltdRSSI[1] = intrpltdRSSI[1];
689   } else if (psLxNtfCoded->pLxNtf[1] == SYSTEM_DEBUG_STATE_L2_MESSAGE) {
690     uint8_t tlvCount = psLxNtfDecoded->psL2NtfDecoded->tlvCount;
691 
692     if (mRssiDebugMode) {
693       psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount].rawRSSIADC =
694           rawRSSIADC;
695       psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount].rawRSSIAGC =
696           rawRSSIAGC;
697     }
698     psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount].intrpltdRSSI[0] =
699         intrpltdRSSI[0];
700     psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount].intrpltdRSSI[1] =
701         intrpltdRSSI[1];
702   }
703 }
704 
705 /*******************************************************************************
706  **
707  ** Function:       decodeRSSIandAPC(psLxNtfCoded_t, psLxNtfDecodingInfo_t,
708  *psLxNtfDecoded_t)
709  **
710  ** Description:    X X X X X X |  X X X  |  X X   |  X  | X X X X X
711  **                     RFU     |  VtxLDO | VtxAmp | NuD | ResCarrier
712  **
713  ** Returns:        void
714  **
715  ******************************************************************************/
decodeAPCTable(psLxNtfCoded_t psLxNtfCoded,psLxNtfDecodingInfo_t psLxNtfDecodingInfo,psLxNtfDecoded_t psLxNtfDecoded)716 void NCI_LxDebug_Decoder::decodeAPCTable(
717     psLxNtfCoded_t psLxNtfCoded, psLxNtfDecodingInfo_t psLxNtfDecodingInfo,
718     psLxNtfDecoded_t psLxNtfDecoded) {
719   uint8_t base = 0;
720   uint8_t offsetAPC = 0;
721   uint8_t APC[2] = {0};
722 
723   if (psLxNtfDecodingInfo != nullptr) {
724     base = psLxNtfDecodingInfo->baseIndex;
725     offsetAPC = psLxNtfDecodingInfo->apcOffset;
726   } else
727     return;
728 
729   /*Converting Little Endian to Big Endian*/
730   APC[1] = psLxNtfCoded->pLxNtf[base + offsetAPC];
731   offsetAPC++;
732   APC[0] = psLxNtfCoded->pLxNtf[base + offsetAPC];
733 
734   if (psLxNtfCoded->pLxNtf[1] == SYSTEM_DEBUG_STATE_L1_MESSAGE) {
735     psLxNtfDecoded->psL1NtfDecoded->sInfo.APC[0] = APC[0];
736     psLxNtfDecoded->psL1NtfDecoded->sInfo.APC[1] = APC[1];
737     psLxNtfDecoded->psL1NtfDecoded->sInfo.residualCarrier =
738         mLOOKUP_RESCARRIER[(APC[1] & mLOOKUP_RESCARRIER_BITMASK)];
739     psLxNtfDecoded->psL1NtfDecoded->sInfo.numDriver =
740         mLOOKUP_NUMDRIVER[(APC[1] & mLOOKUP_NUMDRIVER_BITMASK)];
741     psLxNtfDecoded->psL1NtfDecoded->sInfo.vtxAmp =
742         mLOOKUP_VTXAMP[(APC[1] & mLOOKUP_VTXAMP_BITMASK)];
743     psLxNtfDecoded->psL1NtfDecoded->sInfo.vtxLDO =
744         mLOOKUP_VTXLDO[(APC[0] & mLOOKUP_VTXLDO_BITMASK)];
745   } else if (psLxNtfCoded->pLxNtf[1] == SYSTEM_DEBUG_STATE_L2_MESSAGE) {
746     uint8_t tlvCount = psLxNtfDecoded->psL2NtfDecoded->tlvCount;
747 
748     psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount].APC[0] = APC[0];
749     psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount].APC[1] = APC[1];
750     psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount].residualCarrier =
751         mLOOKUP_RESCARRIER[(APC[1] & mLOOKUP_RESCARRIER_BITMASK)];
752     psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount].numDriver =
753         mLOOKUP_NUMDRIVER[(APC[1] & mLOOKUP_NUMDRIVER_BITMASK)];
754     psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount].vtxAmp =
755         mLOOKUP_VTXAMP[(APC[0] & mLOOKUP_VTXAMP_BITMASK)];
756     psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount].vtxLDO =
757         mLOOKUP_VTXLDO[(APC[0] & mLOOKUP_VTXLDO_BITMASK)];
758   }
759 }
760 
761 /*******************************************************************************
762  **
763  ** Function:        calculateTxVpp(psLxNtfDecoded_t)
764  **
765  ** Description:     This function calculates TxVpp based on formula
766  **                  ( (VtxLDO + VtxAmp) * (1 - ((ResCarrier*1.61)/2)/100) ) *
767  *(2 - NumDriver + 1);
768  **
769  ** Returns:         void
770  **
771  ******************************************************************************/
calculateTxVpp(psLxNtfDecoded_t psLxNtfDecoded)772 void NCI_LxDebug_Decoder::calculateTxVpp(psLxNtfDecoded_t psLxNtfDecoded) {
773   uint8_t residualCarrier = 0;
774   uint8_t numDriver = 0;
775   float vtxAmp = 0;
776   float vtxLDO = 0;
777   uint16_t txVpp = 0;
778   uint8_t tlvNumber = 0;
779 
780   // Vpp = ( (VtxLDO + VtxAmp) * (1 - (ResCarrier*0.00805)) ) * (2 - NumDriver +
781   // 1);
782 
783   if (psLxNtfDecoded->level == SYSTEM_DEBUG_STATE_L1_MESSAGE) {
784     residualCarrier = psLxNtfDecoded->psL1NtfDecoded->sInfo.residualCarrier;
785     numDriver = psLxNtfDecoded->psL1NtfDecoded->sInfo.numDriver;
786     vtxAmp = psLxNtfDecoded->psL1NtfDecoded->sInfo.vtxAmp;
787     vtxLDO = psLxNtfDecoded->psL1NtfDecoded->sInfo.vtxLDO;
788     txVpp = ((vtxLDO + vtxAmp) * (1 - (residualCarrier * 0.00805))) *
789             (2 - numDriver + 1);
790     psLxNtfDecoded->psL1NtfDecoded->sInfo.txVpp = txVpp;
791   } else if (psLxNtfDecoded->level == SYSTEM_DEBUG_STATE_L1_MESSAGE) {
792     tlvNumber = psLxNtfDecoded->psL2NtfDecoded->tlvCount;
793     residualCarrier =
794         psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvNumber].residualCarrier;
795     numDriver = psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvNumber].numDriver;
796     vtxAmp = psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvNumber].vtxAmp;
797     vtxLDO = psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvNumber].vtxLDO;
798     txVpp = ((vtxLDO + vtxAmp) * (1 - (residualCarrier * 0.00805))) *
799             (2 - numDriver + 1);
800     psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvNumber].txVpp = txVpp;
801   }
802 }
803 
804 /*******************************************************************************
805  **
806  ** Function:        decodeCLIFFState(psLxNtfCoded_t, psLxNtfDecodingInfo_t,
807  *psLxNtfDecoded_t)
808  **
809  ** Description:     This functions decodes the current CLIFF state.
810  **
811  ** Returns:         void
812  **
813  ******************************************************************************/
decodeCLIFFState(psLxNtfCoded_t psLxNtfCoded,psLxNtfDecodingInfo_t psLxNtfDecodingInfo,psLxNtfDecoded_t psLxNtfDecoded)814 void NCI_LxDebug_Decoder::decodeCLIFFState(
815     psLxNtfCoded_t psLxNtfCoded, psLxNtfDecodingInfo_t psLxNtfDecodingInfo,
816     psLxNtfDecoded_t psLxNtfDecoded) {
817   if (psLxNtfDecodingInfo != nullptr) {
818     decodeTriggerType(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
819     decodeRFTechMode(psLxNtfCoded, psLxNtfDecodingInfo, psLxNtfDecoded);
820   } else
821     return;
822 }
823 
824 /*******************************************************************************
825  **
826  ** Function:        decodeTriggerType(psLxNtfCoded_t, psLxNtfDecodingInfo_t,
827  *psLxNtfDecoded_t)
828  **
829  ** Description:     This function decodes the CLIFF trigger type.
830  **
831  ** Returns:         void
832  **
833  ******************************************************************************/
decodeTriggerType(psLxNtfCoded_t psLxNtfCoded,psLxNtfDecodingInfo_t psLxNtfDecodingInfo,psLxNtfDecoded_t psLxNtfDecoded)834 void NCI_LxDebug_Decoder::decodeTriggerType(
835     psLxNtfCoded_t psLxNtfCoded, psLxNtfDecodingInfo_t psLxNtfDecodingInfo,
836     psLxNtfDecoded_t psLxNtfDecoded) {
837   uint8_t base = psLxNtfDecodingInfo->baseIndex;
838   uint8_t offsetTriggerType = psLxNtfDecodingInfo->cliffStateTriggerTypeOffset;
839 
840   if (psLxNtfCoded->pLxNtf[1] == SYSTEM_DEBUG_STATE_L1_MESSAGE) {
841     switch ((psLxNtfCoded->pLxNtf[base + offsetTriggerType] & 0x0F)) {
842       case CLF_L1_EVT_ACTIVATED:  // APC
843         psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateTriggerType =
844             mCLF_STAT_L1_TRIG_TYPE[1];
845         psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateTriggerTypeDirection =
846             mCLF_EVT_DIRECTION[0];
847         break;
848       case CLF_L1_EVT_DATA_RX:  // RSSI
849         psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateTriggerType =
850             mCLF_STAT_L1_TRIG_TYPE[2];
851         psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateTriggerTypeDirection =
852             mCLF_EVT_DIRECTION[0];
853         break;
854       case CLF_L1_EVT_RX_DESLECT:  // RSSI
855         psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateTriggerType =
856             mCLF_STAT_L1_TRIG_TYPE[3];
857         psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateTriggerTypeDirection =
858             mCLF_EVT_DIRECTION[0];
859         break;
860       case CLF_L1_EVT_RX_WTX:  // RSSI
861         psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateTriggerType =
862             mCLF_STAT_L1_TRIG_TYPE[4];
863         psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateTriggerTypeDirection =
864             mCLF_EVT_DIRECTION[0];
865         break;
866       case CLF_L1_EVT_ERROR:  // RSSI, EDD Error Types
867         psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateTriggerType =
868             mCLF_STAT_L1_TRIG_TYPE[5];
869         psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateTriggerTypeDirection =
870             mCLF_EVT_DIRECTION[0];
871         break;
872       case CLF_L1_EVT_RX_ACK:  // RSSI
873         psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateTriggerType =
874             mCLF_STAT_L1_TRIG_TYPE[6];
875         psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateTriggerTypeDirection =
876             mCLF_EVT_DIRECTION[0];
877         break;
878       case CLF_L1_EVT_RX_NACK:  // RSSI, IOT1, IOT2, IOT3, IOT4, IOT5
879         psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateTriggerType =
880             mCLF_STAT_L1_TRIG_TYPE[7];
881         psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateTriggerTypeDirection =
882             mCLF_EVT_DIRECTION[0];
883         break;
884       case CLF_L1_EVT_DATA_TX:  // APC , DPLL
885         psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateTriggerType =
886             mCLF_STAT_L1_TRIG_TYPE[8];
887         psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateTriggerTypeDirection =
888             mCLF_EVT_DIRECTION[1];
889         break;
890       case CLF_L1_EVT_WTX_AND_DATA_TX:  // APC, DPLL
891         psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateTriggerType =
892             mCLF_STAT_L1_TRIG_TYPE[9];
893         psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateTriggerTypeDirection =
894             mCLF_EVT_DIRECTION[1];
895         break;
896       case CLF_L1_EVT_TX_DESELECT:  // APC, DPLL
897         psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateTriggerType =
898             mCLF_STAT_L1_TRIG_TYPE[10];
899         psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateTriggerTypeDirection =
900             mCLF_EVT_DIRECTION[1];
901         break;
902       case CLF_L1_EVT_TX_WTX:  // APC, DPLL
903         psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateTriggerType =
904             mCLF_STAT_L1_TRIG_TYPE[11];
905         psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateTriggerTypeDirection =
906             mCLF_EVT_DIRECTION[1];
907         break;
908       case CLF_L1_EVT_TX_ACK:  // APC, DPLL
909         psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateTriggerType =
910             mCLF_STAT_L1_TRIG_TYPE[12];
911         psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateTriggerTypeDirection =
912             mCLF_EVT_DIRECTION[1];
913         break;
914       case CLF_L1_EVT_TX_NAK:  // APC, DPLL
915         psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateTriggerType =
916             mCLF_STAT_L1_TRIG_TYPE[13];
917         psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateTriggerTypeDirection =
918             mCLF_EVT_DIRECTION[1];
919         break;
920       case CLF_L1_EVT_EXTENDED:  // APC, 7816-4 Return Code
921         psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateTriggerType =
922             mCLF_STAT_L1_TRIG_TYPE[14];
923         psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateTriggerTypeDirection =
924             mCLF_EVT_DIRECTION[1];
925         break;
926       default:
927         break;
928     }
929   } else if (psLxNtfCoded->pLxNtf[1] == SYSTEM_DEBUG_STATE_L2_MESSAGE) {
930     uint8_t tlvCount = psLxNtfDecoded->psL2NtfDecoded->tlvCount;
931 
932     switch ((psLxNtfCoded->pLxNtf[base + offsetTriggerType] & 0x0F)) {
933       case CLF_L2_EVT_MODULATION_DETECTED:
934         psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
935             .pCliffStateTriggerType = mCLF_STAT_L2_TRIG_TYPE[1];
936         psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
937             .pCliffStateTriggerTypeDirection = mCLF_EVT_DIRECTION[0];
938         break;
939       case CLF_L2_EVT_DATA_RX:
940         psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
941             .pCliffStateTriggerType = mCLF_STAT_L2_TRIG_TYPE[2];
942         psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
943             .pCliffStateTriggerTypeDirection = mCLF_EVT_DIRECTION[0];
944         break;
945       case CLF_L2_EVT_TIMEOUT:
946         psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
947             .pCliffStateTriggerType = mCLF_STAT_L2_TRIG_TYPE[3];
948         psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
949             .pCliffStateTriggerTypeDirection = mCLF_EVT_DIRECTION[0];
950         break;
951       case CLF_L2_EVT_ACTIVE_ISO14443_3:
952         psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
953             .pCliffStateTriggerType = mCLF_STAT_L2_TRIG_TYPE[4];
954         psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
955             .pCliffStateTriggerTypeDirection = mCLF_EVT_DIRECTION[0];
956         break;
957       case CLF_L2_EVT_ERROR:
958         psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
959             .pCliffStateTriggerType = mCLF_STAT_L2_TRIG_TYPE[5];
960         psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
961             .pCliffStateTriggerTypeDirection = mCLF_EVT_DIRECTION[0];
962         break;
963       case CLF_L2_EVT_SENSING:
964         psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
965             .pCliffStateTriggerType = mCLF_STAT_L2_TRIG_TYPE[6];
966         psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
967             .pCliffStateTriggerTypeDirection = mCLF_EVT_DIRECTION[0];
968         break;
969       case CLF_L2_EVT_ACTIVE_ISO14443_4:  // APC
970         psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
971             .pCliffStateTriggerType = mCLF_STAT_L2_TRIG_TYPE[7];
972         psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
973             .pCliffStateTriggerTypeDirection = mCLF_EVT_DIRECTION[1];
974         break;
975       case CLF_L2_EVT_RFON:
976         psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
977             .pCliffStateTriggerType = mCLF_STAT_L2_TRIG_TYPE[8];
978         psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
979             .pCliffStateTriggerTypeDirection = mCLF_EVT_DIRECTION[0];
980         break;
981       case CLF_L2_EVT_RFOFF:
982         psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
983             .pCliffStateTriggerType = mCLF_STAT_L2_TRIG_TYPE[9];
984         psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
985             .pCliffStateTriggerTypeDirection = mCLF_EVT_DIRECTION[0];
986         break;
987       case CLF_L2_EVT_DATA_TX:  // APC
988         psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
989             .pCliffStateTriggerType = mCLF_STAT_L2_TRIG_TYPE[10];
990         psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
991             .pCliffStateTriggerTypeDirection = mCLF_EVT_DIRECTION[1];
992         break;
993       case CLF_L2_EVT_WUP_IOT_RECONFIG:
994         psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
995             .pCliffStateTriggerType = mCLF_STAT_L2_TRIG_TYPE[11];
996         psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
997             .pCliffStateTriggerTypeDirection = mCLF_EVT_DIRECTION[0];
998         break;
999       default:
1000         break;
1001     }
1002   }
1003 }
1004 
1005 /*******************************************************************************
1006  **
1007  ** Function:        decodeRFTechMode(psLxNtfCoded_t, psLxNtfDecodingInfo_t,
1008  *psLxNtfDecoded_t)
1009  **
1010  ** Description:     This function decodes CLIFF RF Tech & Mode
1011  **
1012  ** Returns:         void
1013  **
1014  ******************************************************************************/
decodeRFTechMode(psLxNtfCoded_t psLxNtfCoded,psLxNtfDecodingInfo_t psLxNtfDecodingInfo,psLxNtfDecoded_t psLxNtfDecoded)1015 void NCI_LxDebug_Decoder::decodeRFTechMode(
1016     psLxNtfCoded_t psLxNtfCoded, psLxNtfDecodingInfo_t psLxNtfDecodingInfo,
1017     psLxNtfDecoded_t psLxNtfDecoded) {
1018   uint8_t base = psLxNtfDecodingInfo->baseIndex;
1019   uint8_t offsetRFTechMode = psLxNtfDecodingInfo->cliffStateRFTechModeOffset;
1020 
1021   if (psLxNtfCoded->pLxNtf[1] == SYSTEM_DEBUG_STATE_L1_MESSAGE) {
1022     switch ((psLxNtfCoded->pLxNtf[base + offsetRFTechMode] & 0xF0)) {
1023       case CLF_STATE_TECH_CE_A:  // APC for Tx Events
1024         psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateRFTechNMode =
1025             mCLF_STAT_RF_TECH_MODE[1];
1026         break;
1027       case CLF_STATE_TECH_CE_B:  // APC for Tx Events
1028         psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateRFTechNMode =
1029             mCLF_STAT_RF_TECH_MODE[2];
1030         break;
1031       case CLF_STATE_TECH_CE_F:  // APC for Tx Events
1032         psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateRFTechNMode =
1033             mCLF_STAT_RF_TECH_MODE[3];
1034         break;
1035       case CLF_STATE_TECH_NFCIP1_TARGET_PASSIVE_A:
1036         psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateRFTechNMode =
1037             mCLF_STAT_RF_TECH_MODE[4];
1038         break;
1039       case CLF_STATE_TECH_NFCIP1_TARGET_PASSIVE_F:
1040         psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateRFTechNMode =
1041             mCLF_STAT_RF_TECH_MODE[5];
1042         break;
1043       case CLF_STATE_TECH_NFCIP1_TARGET_ACTIVE_A:
1044         psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateRFTechNMode =
1045             mCLF_STAT_RF_TECH_MODE[6];
1046         break;
1047       case CLF_STATE_TECH_NFCIP1_TARGET_ACTIVE_F:
1048         psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateRFTechNMode =
1049             mCLF_STAT_RF_TECH_MODE[7];
1050         break;
1051       case CLF_STATE_TECH_RM_A:
1052         psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateRFTechNMode =
1053             mCLF_STAT_RF_TECH_MODE[8];
1054         break;
1055       case CLF_STATE_TECH_RM_B:
1056         psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateRFTechNMode =
1057             mCLF_STAT_RF_TECH_MODE[9];
1058         break;
1059       case CLF_STATE_TECH_RM_F:
1060         psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateRFTechNMode =
1061             mCLF_STAT_RF_TECH_MODE[10];
1062         break;
1063       case CLF_STATE_TECH_NFCIP1_INITIATOR_PASSIVE_A:
1064         psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateRFTechNMode =
1065             mCLF_STAT_RF_TECH_MODE[11];
1066         break;
1067       case CLF_STATE_TECH_NFCIP1_INITIATOR_PASSIVE_B:
1068         psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateRFTechNMode =
1069             mCLF_STAT_RF_TECH_MODE[12];
1070         break;
1071       case CLF_STATE_TECH_NFCIP1_INITIATOR_PASSIVE_F:
1072         psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateRFTechNMode =
1073             mCLF_STAT_RF_TECH_MODE[13];
1074         break;
1075       default:
1076         psLxNtfDecoded->psL1NtfDecoded->sInfo.pCliffStateRFTechNMode =
1077             mCLF_STAT_RF_TECH_MODE[0];
1078         break;
1079     }
1080   } else if (psLxNtfCoded->pLxNtf[1] == SYSTEM_DEBUG_STATE_L2_MESSAGE) {
1081     uint8_t tlvCount = psLxNtfDecoded->psL2NtfDecoded->tlvCount;
1082 
1083     switch ((psLxNtfCoded->pLxNtf[base + offsetRFTechMode] & 0xF0)) {
1084       case CLF_STATE_TECH_CE_A:  // APC for Tx Events
1085         psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
1086             .pCliffStateRFTechNMode = mCLF_STAT_RF_TECH_MODE[1];
1087         break;
1088       case CLF_STATE_TECH_CE_B:  // APC for Tx Events
1089         psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
1090             .pCliffStateRFTechNMode = mCLF_STAT_RF_TECH_MODE[2];
1091         break;
1092       case CLF_STATE_TECH_CE_F:  // APC for Tx Events
1093         psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
1094             .pCliffStateRFTechNMode = mCLF_STAT_RF_TECH_MODE[3];
1095         break;
1096       case CLF_STATE_TECH_NFCIP1_TARGET_PASSIVE_A:
1097         psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
1098             .pCliffStateRFTechNMode = mCLF_STAT_RF_TECH_MODE[4];
1099         break;
1100       case CLF_STATE_TECH_NFCIP1_TARGET_PASSIVE_F:
1101         psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
1102             .pCliffStateRFTechNMode = mCLF_STAT_RF_TECH_MODE[5];
1103         break;
1104       case CLF_STATE_TECH_NFCIP1_TARGET_ACTIVE_A:
1105         psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
1106             .pCliffStateRFTechNMode = mCLF_STAT_RF_TECH_MODE[6];
1107         break;
1108       case CLF_STATE_TECH_NFCIP1_TARGET_ACTIVE_F:
1109         psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
1110             .pCliffStateRFTechNMode = mCLF_STAT_RF_TECH_MODE[7];
1111         break;
1112       case CLF_STATE_TECH_RM_A:
1113         psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
1114             .pCliffStateRFTechNMode = mCLF_STAT_RF_TECH_MODE[8];
1115         break;
1116       case CLF_STATE_TECH_RM_B:
1117         psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
1118             .pCliffStateRFTechNMode = mCLF_STAT_RF_TECH_MODE[9];
1119         break;
1120       case CLF_STATE_TECH_RM_F:
1121         psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
1122             .pCliffStateRFTechNMode = mCLF_STAT_RF_TECH_MODE[10];
1123         break;
1124       case CLF_STATE_TECH_NFCIP1_INITIATOR_PASSIVE_A:
1125         psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
1126             .pCliffStateRFTechNMode = mCLF_STAT_RF_TECH_MODE[11];
1127         break;
1128       case CLF_STATE_TECH_NFCIP1_INITIATOR_PASSIVE_B:
1129         psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
1130             .pCliffStateRFTechNMode = mCLF_STAT_RF_TECH_MODE[12];
1131         break;
1132       case CLF_STATE_TECH_NFCIP1_INITIATOR_PASSIVE_F:
1133         psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
1134             .pCliffStateRFTechNMode = mCLF_STAT_RF_TECH_MODE[13];
1135         break;
1136       default:
1137         psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
1138             .pCliffStateRFTechNMode = mCLF_STAT_RF_TECH_MODE[0];
1139         break;
1140     }
1141   }
1142 }
1143 
1144 /*******************************************************************************
1145  **
1146  ** Function:        decodeExtraDbgData(psLxNtfCoded_t, psLxNtfDecodingInfo_t,
1147  *psLxNtfDecoded_t)
1148  **
1149  ** Description:     This function decodes Extra Debug Data in case of Errors
1150  **
1151  ** Returns:         void
1152  **
1153  ******************************************************************************/
decodeExtraDbgData(psLxNtfCoded_t psLxNtfCoded,psLxNtfDecodingInfo_t psLxNtfDecodingInfo,psLxNtfDecoded_t psLxNtfDecoded)1154 void NCI_LxDebug_Decoder::decodeExtraDbgData(
1155     psLxNtfCoded_t psLxNtfCoded, psLxNtfDecodingInfo_t psLxNtfDecodingInfo,
1156     psLxNtfDecoded_t psLxNtfDecoded) {
1157   uint8_t base = 0;
1158   uint8_t offsetEDD = 0;
1159   uint8_t offsetEDDFelica = 0;
1160 
1161   if (psLxNtfDecodingInfo != nullptr) {
1162     base = psLxNtfDecodingInfo->baseIndex;
1163   } else
1164     return;
1165 
1166   if (psLxNtfCoded->pLxNtf[1] == SYSTEM_DEBUG_STATE_L1_MESSAGE) {
1167     offsetEDD = psLxNtfDecodingInfo->eddOffset;
1168 
1169     switch (psLxNtfCoded->pLxNtf[base + offsetEDD]) {
1170       case L1_ERROR_EDD_RF_TIMEOUT:
1171         psLxNtfDecoded->psL1NtfDecoded->sInfo.pEddL1Error = mEDD_L1_ERROR[0];
1172         break;
1173       case L1_ERROR_EDD_RF_CRC_ERROR:
1174         psLxNtfDecoded->psL1NtfDecoded->sInfo.pEddL1Error = mEDD_L1_ERROR[1];
1175         break;
1176       case L1_ERROR_EDD_RF_COLLISION:
1177         psLxNtfDecoded->psL1NtfDecoded->sInfo.pEddL1Error = mEDD_L1_ERROR[2];
1178         break;
1179       case L1_ERROR_EDD_RX_DATA_OVERFLOW:
1180         psLxNtfDecoded->psL1NtfDecoded->sInfo.pEddL1Error = mEDD_L1_ERROR[3];
1181         break;
1182       case L1_ERROR_EDD_RX_PROTOCOL_ERROR:
1183         psLxNtfDecoded->psL1NtfDecoded->sInfo.pEddL1Error = mEDD_L1_ERROR[4];
1184         break;
1185       case L1_ERROR_EDD_TX_NO_DATA_ERROR:
1186         psLxNtfDecoded->psL1NtfDecoded->sInfo.pEddL1Error = mEDD_L1_ERROR[5];
1187         break;
1188       case L1_ERROR_EDD_EXTERNAL_FIELD_ERROR:
1189         psLxNtfDecoded->psL1NtfDecoded->sInfo.pEddL1Error = mEDD_L1_ERROR[6];
1190         break;
1191       case L1_ERROR_EDD_RXDATA_LENGTH_ERROR:
1192         psLxNtfDecoded->psL1NtfDecoded->sInfo.pEddL1Error = mEDD_L1_ERROR[7];
1193         break;
1194       case L1_TX_EVT_EDD_DPLL_UNLOCKED:
1195         psLxNtfDecoded->psL1NtfDecoded->sInfo.pEddL1TxErr = mEDD_L1_TX_ERROR;
1196         break;
1197       case L1_RX_NACK_EDD_IOT_STAGE1:
1198         psLxNtfDecoded->psL1NtfDecoded->sInfo.pEddL1RxNak = mEDD_L1_RX_NAK[0];
1199         break;
1200       case L1_RX_NACK_EDD_IOT_STAGE2:
1201         psLxNtfDecoded->psL1NtfDecoded->sInfo.pEddL1RxNak = mEDD_L1_RX_NAK[1];
1202         break;
1203       case L1_RX_NACK_EDD_IOT_STAGE3:
1204         psLxNtfDecoded->psL1NtfDecoded->sInfo.pEddL1RxNak = mEDD_L1_RX_NAK[2];
1205         break;
1206       case L1_RX_NACK_EDD_IOT_STAGE4:
1207         psLxNtfDecoded->psL1NtfDecoded->sInfo.pEddL1RxNak = mEDD_L1_RX_NAK[3];
1208         break;
1209       case L1_RX_NACK_EDD_IOT_STAGE5:
1210         psLxNtfDecoded->psL1NtfDecoded->sInfo.pEddL1RxNak = mEDD_L1_RX_NAK[4];
1211         break;
1212       default:
1213         break;
1214     }
1215   } else if (psLxNtfCoded->pLxNtf[1] == SYSTEM_DEBUG_STATE_L2_MESSAGE) {
1216     uint8_t tlvCount = psLxNtfDecoded->psL2NtfDecoded->tlvCount;
1217     offsetEDD = psLxNtfDecodingInfo->eddOffset;
1218 
1219     switch (psLxNtfCoded->pLxNtf[base + offsetEDD]) {
1220       case L2_EDD_WUP_IOT_STAGE1:
1221         psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount].pEddL2WUP =
1222             mEDD_L2_WUP[0];
1223         break;
1224       case L2_EDD_WUP_IOT_STAGE2:
1225         psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount].pEddL2WUP =
1226             mEDD_L2_WUP[1];
1227         break;
1228       case L2_EDD_WUP_IOT_STAGE3:
1229         psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount].pEddL2WUP =
1230             mEDD_L2_WUP[2];
1231         break;
1232       case L2_EDD_WUP_IOT_STAGE4:
1233         psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount].pEddL2WUP =
1234             mEDD_L2_WUP[3];
1235         break;
1236       case L2_EDD_WUP_IOT_STAGE5:
1237         psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount].pEddL2WUP =
1238             mEDD_L2_WUP[4];
1239         break;
1240     }
1241 
1242     offsetEDDFelica = psLxNtfDecodingInfo->eddFelicaOffset;
1243 
1244     psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount].eddFelica =
1245         psLxNtfCoded->pLxNtf[base + offsetEDDFelica];
1246   }
1247 }
1248 
1249 /*******************************************************************************
1250  **
1251  ** Function:        decode78164RetCode(psLxNtfCoded_t, psLxNtfDecodingInfo_t,
1252  *psLxNtfDecoded_t)
1253  **
1254  ** Description:     This function decodes the ISO-7816-4 Return Code.
1255  **
1256  ** Returns:         void
1257  **
1258  ******************************************************************************/
decode78164RetCode(psLxNtfCoded_t psLxNtfCoded,psLxNtfDecodingInfo_t psLxNtfDecodingInfo,psLxNtfDecoded_t psLxNtfDecoded)1259 void NCI_LxDebug_Decoder::decode78164RetCode(
1260     psLxNtfCoded_t psLxNtfCoded, psLxNtfDecodingInfo_t psLxNtfDecodingInfo,
1261     psLxNtfDecoded_t psLxNtfDecoded) {
1262   uint8_t base = 0;
1263   uint8_t offsetRetCode78164 = 0;
1264   uint8_t retCode78164[2] = {0};
1265 
1266   if (psLxNtfDecodingInfo != nullptr) {
1267     base = psLxNtfDecodingInfo->baseIndex;
1268     offsetRetCode78164 = psLxNtfDecodingInfo->retCode78164Offset;
1269   } else
1270     return;
1271 
1272   retCode78164[1] = psLxNtfCoded->pLxNtf[base + offsetRetCode78164];
1273   offsetRetCode78164++;
1274   retCode78164[0] = psLxNtfCoded->pLxNtf[base + offsetRetCode78164];
1275 
1276   psLxNtfDecoded->psL1NtfDecoded->sInfo.eddL178164RetCode[0] = retCode78164[0];
1277   psLxNtfDecoded->psL1NtfDecoded->sInfo.eddL178164RetCode[1] = retCode78164[1];
1278 }
1279 
1280 /*******************************************************************************
1281  **
1282  ** Function:        decodeFelicaCmdCode(psLxNtfCoded_t, psLxNtfDecodingInfo_t,
1283  *psLxNtfDecoded_t)
1284  **
1285  ** Description:     This function decodes the Felica Command
1286  **
1287  ** Returns:         status
1288  **
1289  ******************************************************************************/
decodeFelicaCmdCode(psLxNtfCoded_t psLxNtfCoded,psLxNtfDecodingInfo_t psLxNtfDecodingInfo,psLxNtfDecoded_t psLxNtfDecoded)1290 void NCI_LxDebug_Decoder::decodeFelicaCmdCode(
1291     psLxNtfCoded_t psLxNtfCoded, psLxNtfDecodingInfo_t psLxNtfDecodingInfo,
1292     psLxNtfDecoded_t psLxNtfDecoded) {
1293   uint8_t base = 0;
1294   uint8_t offsetCmdCode = 0;
1295 
1296   if (psLxNtfDecodingInfo != nullptr) {
1297     base = psLxNtfDecodingInfo->baseIndex;
1298     offsetCmdCode = psLxNtfDecodingInfo->felicaCmdOffset;
1299   } else
1300     return;
1301 
1302   uint8_t tlvCount = psLxNtfDecoded->psL2NtfDecoded->tlvCount;
1303   psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount].felicaCmdCode =
1304       psLxNtfCoded->pLxNtf[base + offsetCmdCode];
1305 }
1306 
1307 /*******************************************************************************
1308  **
1309  ** Function:        decodeFelicaSystemCode(psLxNtfCoded_t,
1310  *psLxNtfDecodingInfo_t, psLxNtfDecoded_t)
1311  **
1312  ** Description:     This function decodes the Felica System Code
1313  **
1314  ** Returns:         status
1315  **
1316  ******************************************************************************/
decodeFelicaSystemCode(psLxNtfCoded_t psLxNtfCoded,psLxNtfDecodingInfo_t psLxNtfDecodingInfo,psLxNtfDecoded_t psLxNtfDecoded)1317 void NCI_LxDebug_Decoder::decodeFelicaSystemCode(
1318     psLxNtfCoded_t psLxNtfCoded, psLxNtfDecodingInfo_t psLxNtfDecodingInfo,
1319     psLxNtfDecoded_t psLxNtfDecoded) {
1320   uint8_t base = 0;
1321   uint8_t offsetSystemCode = 0;
1322   uint8_t systemCode[2] = {0};
1323 
1324   if (psLxNtfDecodingInfo != nullptr) {
1325     base = psLxNtfDecodingInfo->baseIndex;
1326     offsetSystemCode = psLxNtfDecodingInfo->felicaSysCodeOffset;
1327   } else
1328     return;
1329 
1330   uint8_t tlvCount = psLxNtfDecoded->psL2NtfDecoded->tlvCount;
1331 
1332   systemCode[1] = psLxNtfCoded->pLxNtf[base + offsetSystemCode];
1333   offsetSystemCode++;
1334   systemCode[0] = psLxNtfCoded->pLxNtf[base + offsetSystemCode];
1335 
1336   psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount].felicaSysCode[0] =
1337       systemCode[0];
1338   psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount].felicaSysCode[1] =
1339       systemCode[1];
1340 }
1341 
1342 /*******************************************************************************
1343  **
1344  ** Function:        phNxpNciHal_ext_parseLxdebugNtf(psLxNtfCoded_t,
1345  *psLxNtfDecodingInfo_t, psLxNtfDecoded_t)
1346  **
1347  ** Description:     This function decodes the Felica Response Code
1348  **
1349  ** Returns:         status
1350  **
1351  ******************************************************************************/
decodeFelicaRspCode(psLxNtfCoded_t psLxNtfCoded,psLxNtfDecodingInfo_t psLxNtfDecodingInfo,psLxNtfDecoded_t psLxNtfDecoded)1352 void NCI_LxDebug_Decoder::decodeFelicaRspCode(
1353     psLxNtfCoded_t psLxNtfCoded, psLxNtfDecodingInfo_t psLxNtfDecodingInfo,
1354     psLxNtfDecoded_t psLxNtfDecoded) {
1355   uint8_t base = 0;
1356   uint8_t offsetFelicaRspCode = 0;
1357   uint8_t offsetFelicaRspCodeStatusFlags = 0;
1358   uint8_t felicaRspCodeStatusFlags[2] = {0};
1359 
1360   if (psLxNtfDecodingInfo != nullptr) {
1361     base = psLxNtfDecodingInfo->baseIndex;
1362     offsetFelicaRspCode = psLxNtfDecodingInfo->felicaRspCodeOffset;
1363     offsetFelicaRspCodeStatusFlags =
1364         psLxNtfDecodingInfo->felicaRspStatusFlagsOffset;
1365   } else
1366     return;
1367 
1368   uint8_t tlvCount = psLxNtfDecoded->psL2NtfDecoded->tlvCount;
1369   psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount].felicaRspCode =
1370       psLxNtfCoded->pLxNtf[base + offsetFelicaRspCode];
1371 
1372   felicaRspCodeStatusFlags[1] =
1373       psLxNtfCoded->pLxNtf[base + offsetFelicaRspCodeStatusFlags];
1374   offsetFelicaRspCodeStatusFlags++;
1375   felicaRspCodeStatusFlags[0] =
1376       psLxNtfCoded->pLxNtf[base + offsetFelicaRspCodeStatusFlags];
1377 
1378   psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
1379       .felicaRspCodeStatusFlags[0] = felicaRspCodeStatusFlags[0];
1380   psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount]
1381       .felicaRspCodeStatusFlags[1] = felicaRspCodeStatusFlags[1];
1382 }
1383 
1384 /*******************************************************************************
1385  **
1386  ** Function:        decodeFelicaMiscCode(psLxNtfCoded_t, psLxNtfDecodingInfo_t,
1387  *psLxNtfDecoded_t)
1388  **
1389  ** Description:     This function decodes the Felica Misc Code.
1390  **
1391  ** Returns:         status
1392  **
1393  ******************************************************************************/
decodeFelicaMiscCode(psLxNtfCoded_t psLxNtfCoded,psLxNtfDecodingInfo_t psLxNtfDecodingInfo,psLxNtfDecoded_t psLxNtfDecoded)1394 void NCI_LxDebug_Decoder::decodeFelicaMiscCode(
1395     psLxNtfCoded_t psLxNtfCoded, psLxNtfDecodingInfo_t psLxNtfDecodingInfo,
1396     psLxNtfDecoded_t psLxNtfDecoded) {
1397   uint8_t base = 0;
1398   uint8_t offsetfelicaMisc = 0;
1399 
1400   if (psLxNtfDecodingInfo != nullptr) {
1401     base = psLxNtfDecodingInfo->baseIndex;
1402     offsetfelicaMisc = psLxNtfDecodingInfo->felicaMiscOffset;
1403   } else
1404     return;
1405 
1406   uint8_t tlvCount = psLxNtfDecoded->psL2NtfDecoded->tlvCount;
1407 
1408   switch (psLxNtfCoded->pLxNtf[base + offsetfelicaMisc]) {
1409     case FLC_MISC_EVT_GENERIC_ERROR:
1410       psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount].pFelicaMisc =
1411           mFELICA_MISC_EVT[1];
1412       break;
1413     case FLC_MISC_EVT_EMPTY_FRAME_FROM_ESE:
1414       psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount].pFelicaMisc =
1415           mFELICA_MISC_EVT[2];
1416       break;
1417     case FLC_MISC_EVT_BUFFER_OVERFLOW:
1418       psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount].pFelicaMisc =
1419           mFELICA_MISC_EVT[3];
1420       break;
1421     case FLC_MISC_EVT_RF_ERROR:
1422       psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount].pFelicaMisc =
1423           mFELICA_MISC_EVT[4];
1424       break;
1425     default:
1426       psLxNtfDecoded->psL2NtfDecoded->sTlvInfo[tlvCount].pFelicaMisc =
1427           mFELICA_MISC_EVT[0];
1428       break;
1429   }
1430 }
1431