1 /******************************************************************************
2 *
3 * Copyright (C) 2024 The Android Open Source Project.
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 #include <android-base/logging.h>
19 #include <android-base/stringprintf.h>
20 #include <string.h>
21
22 #include "nfa_nfcee_int.h"
23
24 using android::base::StringPrintf;
25
26 /*******************************************************************************
27 **
28 ** Function NFA_T4tNfcEeOpenConnection
29 **
30 ** Description Creates logical connection with T4T Nfcee
31 ** Returns:
32 ** NFA_STATUS_OK if successfully initiated
33 ** NFA_STATUS_FAILED otherwise
34 **
35 *******************************************************************************/
NFA_T4tNfcEeOpenConnection()36 tNFA_STATUS NFA_T4tNfcEeOpenConnection() {
37 tNFA_T4TNFCEE_OPERATION* p_msg;
38
39 LOG(DEBUG) << StringPrintf("%s : Enter", __func__);
40
41 if ((p_msg = (tNFA_T4TNFCEE_OPERATION*)GKI_getbuf(
42 (uint16_t)(sizeof(tNFA_T4TNFCEE_OPERATION)))) != NULL) {
43 p_msg->hdr.event = NFA_T4TNFCEE_OP_REQUEST_EVT;
44 p_msg->op = NFA_T4TNFCEE_OP_OPEN_CONNECTION;
45 nfa_sys_sendmsg(p_msg);
46
47 return (NFA_STATUS_OK);
48 }
49
50 return (NFA_STATUS_FAILED);
51 }
52 /*******************************************************************************
53 **
54 ** Function NFA_T4tNfcEeClear
55 **
56 ** Description Clear Ndef data to T4T NFC EE.
57 ** For file ID NDEF, perform the NDEF detection procedure
58 ** and set the NDEF tag data to zero.
59 ** Returns:
60 ** NFA_STATUS_OK if successfully initiated
61 ** NFA_STATUS_FAILED otherwise
62 **
63 *******************************************************************************/
NFA_T4tNfcEeClear(uint8_t * p_fileId)64 tNFA_STATUS NFA_T4tNfcEeClear(uint8_t* p_fileId) {
65 tNFA_T4TNFCEE_OPERATION* p_msg;
66 LOG(DEBUG) << StringPrintf("%s : Enter ", __func__);
67
68 if ((p_msg = (tNFA_T4TNFCEE_OPERATION*)GKI_getbuf(
69 (uint16_t)(sizeof(tNFA_T4TNFCEE_OPERATION)))) != NULL) {
70 p_msg->hdr.event = NFA_T4TNFCEE_OP_REQUEST_EVT;
71 p_msg->op = NFA_T4TNFCEE_OP_CLEAR;
72 p_msg->p_fileId = p_fileId;
73 nfa_sys_sendmsg(p_msg);
74
75 return (NFA_STATUS_OK);
76 }
77 return (NFA_STATUS_FAILED);
78 }
79 /*******************************************************************************
80 **
81 ** Function NFA_T4tNfcEeWrite
82 **
83 ** Description Write data to the T4T NFC EE of given file id.
84 ** If file ID is of NDEF, perform the NDEF detection procedure
85 ** and write the NDEF tag data using the appropriate method for
86 ** NDEF EE.
87 ** If File ID is Not NDEF then reads proprietary way
88 ** Returns:
89 ** NFA_STATUS_OK if successfully initiated
90 ** NFA_STATUS_FAILED otherwise
91 **
92 *******************************************************************************/
NFA_T4tNfcEeWrite(uint8_t * p_fileId,uint8_t * p_data,uint32_t len)93 tNFA_STATUS NFA_T4tNfcEeWrite(uint8_t* p_fileId, uint8_t* p_data,
94 uint32_t len) {
95 tNFA_T4TNFCEE_OPERATION* p_msg;
96
97 LOG(DEBUG) << StringPrintf("%s : Enter p_data=%s, len: %i", __func__, p_data,
98 len);
99
100 if ((p_msg = (tNFA_T4TNFCEE_OPERATION*)GKI_getbuf(
101 (uint16_t)(sizeof(tNFA_T4TNFCEE_OPERATION)))) != NULL) {
102 p_msg->hdr.event = NFA_T4TNFCEE_OP_REQUEST_EVT;
103 p_msg->op = NFA_T4TNFCEE_OP_WRITE;
104 p_msg->p_fileId = p_fileId;
105 p_msg->write.len = len;
106 p_msg->write.p_data = p_data;
107 nfa_sys_sendmsg(p_msg);
108
109 return (NFA_STATUS_OK);
110 }
111
112 return (NFA_STATUS_FAILED);
113 }
114
115 /*******************************************************************************
116 **
117 ** Function NFA_T4tNfcEeRead
118 **
119 ** Description Read T4T message from NFCC area.of given file id
120 ** If file ID is of NDEF, perform the NDEF detection procedure
121 ** and read the NDEF tag data using the appropriate method for
122 ** NDEF EE.
123 ** If File ID is Not NDEF then reads proprietary way
124 **
125 ** Returns:
126 ** NFA_STATUS_OK if successfully initiated
127 ** NFA_STATUS_FAILED otherwise
128 **
129 *******************************************************************************/
NFA_T4tNfcEeRead(uint8_t * p_fileId)130 tNFA_STATUS NFA_T4tNfcEeRead(uint8_t* p_fileId) {
131 tNFA_T4TNFCEE_OPERATION* p_msg;
132 uint16_t m_fileId = (uint16_t)(((uint16_t)(*(p_fileId)) << 8) +
133 (uint16_t)(*((p_fileId) + 1)));
134
135 if ((p_msg = (tNFA_T4TNFCEE_OPERATION*)GKI_getbuf(
136 (uint16_t)(sizeof(tNFA_T4TNFCEE_OPERATION)))) != NULL) {
137 p_msg->hdr.event = NFA_T4TNFCEE_OP_REQUEST_EVT;
138 if (m_fileId == T4T_CC_FILE_ID) {
139 p_msg->op = NFA_T4TNFCEE_OP_READ_CC_FILE;
140 } else {
141 p_msg->op = NFA_T4TNFCEE_OP_READ;
142 }
143 p_msg->p_fileId = p_fileId;
144 nfa_sys_sendmsg(p_msg);
145
146 return (NFA_STATUS_OK);
147 }
148
149 return (NFA_STATUS_FAILED);
150 }
151
152 /*******************************************************************************
153 **
154 ** Function NFA_T4tNfcEeCloseConnection
155 **
156 ** Description Closes logical connection with T4T Nfcee
157 ** Returns:
158 ** NFA_STATUS_OK if successfully initiated
159 ** NFA_STATUS_FAILED otherwise
160 **
161 *******************************************************************************/
NFA_T4tNfcEeCloseConnection()162 tNFA_STATUS NFA_T4tNfcEeCloseConnection() {
163 tNFA_T4TNFCEE_OPERATION* p_msg;
164
165 LOG(DEBUG) << StringPrintf("%s : Enter", __func__);
166
167 if ((p_msg = (tNFA_T4TNFCEE_OPERATION*)GKI_getbuf(
168 (uint16_t)(sizeof(tNFA_T4TNFCEE_OPERATION)))) != NULL) {
169 p_msg->hdr.event = NFA_T4TNFCEE_OP_REQUEST_EVT;
170 p_msg->op = NFA_T4TNFCEE_OP_CLOSE_CONNECTION;
171 nfa_sys_sendmsg(p_msg);
172
173 return (NFA_STATUS_OK);
174 }
175
176 return (NFA_STATUS_FAILED);
177 }
178