• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright 2015-2018,2020-2021 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         chipType = sn220u;
47     } else if (msg[0] == 0x00) {
48       if (msg[offsetFwRomCodeVersion] == 0x01 &&
49           msg[offsetFwMajorVersion] == 0x01)
50         chipType = sn220u;
51       else if (msg[offsetFwRomCodeVersion] == 0x01 &&
52                msg[offsetFwMajorVersion] == 0x10)
53         chipType = sn100u;
54       else if (msg[offsetFwRomCodeVersion] == 0x12 &&
55                (msg[offsetFwMajorVersion_pn557] == 0x21 ||
56                 msg[offsetFwMajorVersion_pn557] == 0x01))
57         chipType = pn557;
58     } else if (offsetHwVersion < msg_len) {
59       ALOGD("%s HwVersion : 0x%02x", __func__, msg[msg_len - 4]);
60       switch (msg[msg_len - 4]) {
61         case 0x40:  // PN553 A0
62         case 0x41:  // PN553 B0
63           chipType = pn553;
64           break;
65 
66         case 0x50:  // PN553 A0 + P73
67         case 0x51:  // PN553 B0 + P73
68           chipType = pn80T;
69           break;
70 
71         case 0x98:
72           chipType = pn551;
73           break;
74 
75         case 0xA8:
76         case 0x08:
77           chipType = pn67T;
78           break;
79 
80         case 0x28:
81         case 0x48:  // NQ210
82           chipType = pn548C2;
83           break;
84 
85         case 0x18:
86         case 0x58:  // NQ220
87           chipType = pn66T;
88           break;
89         case 0xA0:
90         case 0xA2:
91           chipType = sn100u;
92           break;
93         default:
94           chipType = pn80T;
95       }
96     } else {
97       ALOGD("%s Wrong msg_len. Setting Default ChiptType pn80T", __func__);
98       chipType = pn81T;
99     }
100   }
101   ALOGD("%s Product : %s", __func__, product[chipType]);
102   return chipType;
103 }
104 
getFWVersionInfo(uint8_t * msg,uint16_t msg_len)105 uint32_t capability::getFWVersionInfo(uint8_t* msg, uint16_t msg_len) {
106   uint32_t versionInfo = 0;
107   if ((msg != NULL) && (msg_len != 0)) {
108     if (msg[0] == 0x00) {
109       versionInfo = msg[offsetFwRomCodeVersion] << 16;
110       versionInfo |= msg[offsetFwMajorVersion] << 8;
111       versionInfo |= msg[offsetFwMinorVersion];
112     }
113   }
114   return versionInfo;
115 }
116