• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright 2015-2018,2020-2022 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 #define LOG_TAG "NxpHal"
19 #include "NxpNfcCapability.h"
20 #include <phNxpLog.h>
21 
22 capability* capability::instance = NULL;
23 tNFC_chipType capability::chipType = pn81T;
24 tNfc_featureList nfcFL;
25 
capability()26 capability::capability() {}
27 
getInstance()28 capability* capability::getInstance() {
29   if (NULL == instance) {
30     instance = new capability();
31   }
32   return instance;
33 }
34 
processChipType(uint8_t * msg,uint16_t msg_len)35 tNFC_chipType capability::processChipType(uint8_t* msg, uint16_t msg_len) {
36   if ((msg != NULL) && (msg_len != 0)) {
37     if (msg[0] == 0x60 && msg[1] == 0x00) {
38       if (msg[msg_len - 3] == 0x12 &&
39           (msg[msg_len - 2] == 0x01 || msg[msg_len - 2] == 0x21))
40         chipType = pn557;
41       else if (msg[msg_len - 3] == 0x11 && msg[msg_len - 2] == 0x02)
42         chipType = pn553;
43       else if (msg[msg_len - 3] == 0x01 && msg[msg_len - 2] == 0x10)
44         chipType = sn100u;
45       else if (msg[msg_len - 3] == 0x01 && msg[msg_len - 2] == 0x01) {
46         if (msg[msg_len - 4] == 0xCA) {
47           chipType = pn560;
48         } else {
49           chipType = sn220u;
50         }
51       }
52     } else if (msg[0] == 0x00) {
53       if (msg[offsetFwRomCodeVersion] == 0x01 &&
54           msg[offsetFwMajorVersion] == 0x01) {
55         if (msg[offsetDlRspChipType] == 0xCA) {
56           chipType = pn560;
57         } else {
58           chipType = sn220u;
59         }
60       } else if (msg[offsetFwRomCodeVersion] == 0x01 &&
61                  msg[offsetFwMajorVersion] == 0x10)
62         chipType = sn100u;
63       else if (msg[offsetFwRomCodeVersion] == 0x12 &&
64                (msg[offsetFwMajorVersion_pn557] == 0x21 ||
65                 msg[offsetFwMajorVersion_pn557] == 0x01))
66         chipType = pn557;
67     } else if (offsetHwVersion < msg_len) {
68       ALOGD("%s HwVersion : 0x%02x", __func__, msg[msg_len - 4]);
69       switch (msg[msg_len - 4]) {
70         case 0x40:  // PN553 A0
71         case 0x41:  // PN553 B0
72           chipType = pn553;
73           break;
74 
75         case 0x50:  // PN553 A0 + P73
76         case 0x51:  // PN553 B0 + P73
77           chipType = pn80T;
78           break;
79 
80         case 0x98:
81           chipType = pn551;
82           break;
83 
84         case 0xA8:
85         case 0x08:
86           chipType = pn67T;
87           break;
88 
89         case 0x28:
90         case 0x48:  // NQ210
91           chipType = pn548C2;
92           break;
93 
94         case 0x18:
95         case 0x58:  // NQ220
96           chipType = pn66T;
97           break;
98         case 0xA0:
99         case 0xA2:
100           chipType = sn100u;
101           break;
102         default:
103           chipType = pn80T;
104       }
105     } else {
106       ALOGD("%s Wrong msg_len. Setting Default ChipType pn80T", __func__);
107       chipType = pn81T;
108     }
109   }
110   ALOGD("%s Product : %s", __func__, product[chipType]);
111   return chipType;
112 }
113 
getFWVersionInfo(uint8_t * msg,uint16_t msg_len)114 uint32_t capability::getFWVersionInfo(uint8_t* msg, uint16_t msg_len) {
115   uint32_t versionInfo = 0;
116   if ((msg != NULL) && (msg_len != 0)) {
117     if (msg[0] == 0x00) {
118       versionInfo = msg[offsetFwRomCodeVersion] << 16;
119       versionInfo |= msg[offsetFwMajorVersion] << 8;
120       versionInfo |= msg[offsetFwMinorVersion];
121     }
122   }
123   return versionInfo;
124 }
125