1 /******************************************************************************
2  *
3  *  Copyright 2015-2018,2020 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 && msg[msg_len - 2] == 0x01)
39         chipType = pn81T;
40       else if (msg[msg_len - 3] == 0x11 && msg[msg_len - 2] == 0x02)
41         chipType = pn553;
42       else if (msg[msg_len - 3] == 0x01 && msg[msg_len - 2] == 0x10)
43         chipType = sn100u;
44       else if (msg[msg_len - 3] == 0x01 && msg[msg_len - 2] == 0x01)
45         chipType = sn220u;
46     } else if (msg[0] == 0x00) {
47       if (msg[offsetFwRomCodeVersion] == 0x01 &&
48           msg[offsetFwMajorVersion] == 0x01)
49         chipType = sn220u;
50       if (msg[offsetFwRomCodeVersion] == 0x01 &&
51           msg[offsetFwMajorVersion] == 0x10)
52         chipType = sn100u;
53     } else if (offsetHwVersion < msg_len) {
54       ALOGD("%s HwVersion : 0x%02x", __func__, msg[msg_len - 4]);
55       switch (msg[msg_len - 4]) {
56         case 0x40:  // PN553 A0
57         case 0x41:  // PN553 B0
58           chipType = pn553;
59           break;
60 
61         case 0x50:  // PN553 A0 + P73
62         case 0x51:  // PN553 B0 + P73
63           chipType = pn80T;
64           break;
65 
66         case 0x98:
67           chipType = pn551;
68           break;
69 
70         case 0xA8:
71         case 0x08:
72           chipType = pn67T;
73           break;
74 
75         case 0x28:
76         case 0x48:  // NQ210
77           chipType = pn548C2;
78           break;
79 
80         case 0x18:
81         case 0x58:  // NQ220
82           chipType = pn66T;
83           break;
84         case 0xA0:
85         case 0xA2:
86           chipType = sn100u;
87           break;
88         default:
89           chipType = pn80T;
90       }
91     } else {
92       ALOGD("%s Wrong msg_len. Setting Default ChiptType pn80T", __func__);
93       chipType = pn81T;
94     }
95   }
96   ALOGD("%s Product : %s", __func__, product[chipType]);
97   return chipType;
98 }
99