blob: 884898c67dabc3eade87e8b3ff117c1dd0a2cd26 [file] [log] [blame]
nxpandroid64fd68c2015-09-23 16:45:15 +05301/*
2 * Copyright (C) 2012 The Android Open Source Project
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 *
18 * The original Work has been changed by NXP Semiconductors.
19 *
20 * Copyright (C) 2015 NXP Semiconductors
21 *
22 * Licensed under the Apache License, Version 2.0 (the "License");
23 * you may not use this file except in compliance with the License.
24 * You may obtain a copy of the License at
25 *
26 * http://www.apache.org/licenses/LICENSE-2.0
27 *
28 * Unless required by applicable law or agreed to in writing, software
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
33 *
34 ******************************************************************************/
35#pragma once
36#undef LOG_TAG
37#define LOG_TAG "BrcmNfcJni"
38#include <JNIHelp.h>
39#include <jni.h>
40#include <pthread.h>
41#include <sys/queue.h>
42#include <semaphore.h>
43
44
45/* Discovery modes -- keep in sync with NFCManager.DISCOVERY_MODE_* */
46#define DISCOVERY_MODE_TAG_READER 0
47#define DISCOVERY_MODE_NFCIP1 1
48#define DISCOVERY_MODE_CARD_EMULATION 2
49#define DISCOVERY_MODE_TABLE_SIZE 3
50
51#define DISCOVERY_MODE_DISABLED 0
52#define DISCOVERY_MODE_ENABLED 1
53
54#define MODE_P2P_TARGET 0
55#define MODE_P2P_INITIATOR 1
56
57
58/* Properties values */
59#define PROPERTY_LLCP_LTO 0
60#define PROPERTY_LLCP_MIU 1
61#define PROPERTY_LLCP_WKS 2
62#define PROPERTY_LLCP_OPT 3
63#define PROPERTY_NFC_DISCOVERY_A 4
64#define PROPERTY_NFC_DISCOVERY_B 5
65#define PROPERTY_NFC_DISCOVERY_F 6
66#define PROPERTY_NFC_DISCOVERY_15693 7
67#define PROPERTY_NFC_DISCOVERY_NCFIP 8
68
69
70/* Error codes */
nxpandroid7d44e572016-08-01 19:11:04 +053071#define ERROR_BUFFER_TOO_SMALL (-12)
72#define ERROR_INSUFFICIENT_RESOURCES (-9)
nxpandroid64fd68c2015-09-23 16:45:15 +053073
74
75/* Pre-defined tag type values. These must match the values in
76 * Ndef.java in the framework.
77 */
nxpandroid7d44e572016-08-01 19:11:04 +053078#define NDEF_UNKNOWN_TYPE (-1)
nxpandroid64fd68c2015-09-23 16:45:15 +053079#define NDEF_TYPE1_TAG 1
80#define NDEF_TYPE2_TAG 2
81#define NDEF_TYPE3_TAG 3
82#define NDEF_TYPE4_TAG 4
83#define NDEF_MIFARE_CLASSIC_TAG 101
84
85
86/* Pre-defined card read/write state values. These must match the values in
87 * Ndef.java in the framework.
88 */
89#define NDEF_MODE_READ_ONLY 1
90#define NDEF_MODE_READ_WRITE 2
91#define NDEF_MODE_UNKNOWN 3
92
nxpandroid1153eb32015-11-06 18:46:58 +053093#if(NXP_EXTNS == TRUE)
nxpandroid64fd68c2015-09-23 16:45:15 +053094#define VEN_POWER_STATE_ON 6
95#define VEN_POWER_STATE_OFF 7
nxpandroida9a68ba2016-01-14 21:12:17 +053096// ESE Suppored Technologies
97#define TARGET_TYPE_ISO14443_3A_3B 11
nxpandroid64fd68c2015-09-23 16:45:15 +053098#endif
99/* Name strings for target types. These *must* match the values in TagTechnology.java */
nxpandroid7d44e572016-08-01 19:11:04 +0530100#define TARGET_TYPE_UNKNOWN (-1)
nxpandroid64fd68c2015-09-23 16:45:15 +0530101#define TARGET_TYPE_ISO14443_3A 1
102#define TARGET_TYPE_ISO14443_3B 2
103#define TARGET_TYPE_ISO14443_4 3
104#define TARGET_TYPE_FELICA 4
105#define TARGET_TYPE_ISO15693 5
106#define TARGET_TYPE_NDEF 6
107#define TARGET_TYPE_NDEF_FORMATABLE 7
108#define TARGET_TYPE_MIFARE_CLASSIC 8
109#define TARGET_TYPE_MIFARE_UL 9
110#define TARGET_TYPE_KOVIO_BARCODE 10
111#define TARGET_TYPE_ISO14443_4A 11
112#define TARGET_TYPE_ISO14443_4B 12
113
114/* Setting VEN_CFG */
nxpandroida9a68ba2016-01-14 21:12:17 +0530115#define NFC_MODE_ON 3
116#define NFC_MODE_OFF 2
nxpandroid64fd68c2015-09-23 16:45:15 +0530117
118//define a few NXP error codes that NFC service expects;
119//see external/libnfc-nxp/src/phLibNfcStatus.h;
120//see external/libnfc-nxp/inc/phNfcStatus.h
121#define NFCSTATUS_SUCCESS (0x0000)
122#define NFCSTATUS_FAILED (0x00FF)
123
124//default general trasceive timeout in millisecond
125#define DEFAULT_GENERAL_TRANS_TIMEOUT 2000
126
127struct nfc_jni_native_data
128{
129 /* Thread handle */
130 pthread_t thread;
131 int running;
132
133 /* Our VM */
134 JavaVM *vm;
135 int env_version;
136
137 /* Reference to the NFCManager instance */
138 jobject manager;
139
140 /* Cached objects */
141 jobject cached_NfcTag;
142 jobject cached_P2pDevice;
143
144 /* Secure Element selected */
145 int seId;
146
147 /* LLCP params */
148 int lto;
149 int miu;
150 int wks;
151 int opt;
152
153 int tech_mask;
154 int discovery_duration;
155
156 /* Tag detected */
157 jobject tag;
158
159 int tHandle;
160 int tProtocols[16];
161 int handles[16];
162};
163
164
165class ScopedAttach
166{
167public:
168 ScopedAttach(JavaVM* vm, JNIEnv** env) : vm_(vm)
169 {
170 vm_->AttachCurrentThread(env, NULL);
171 }
172
173 ~ScopedAttach()
174 {
175 vm_->DetachCurrentThread();
176 }
177
178private:
179 JavaVM* vm_;
180};
181
182
183extern "C"
184{
185 jint JNI_OnLoad(JavaVM *jvm, void *reserved);
186}
187
188
189namespace android
190{
191 int nfc_jni_cache_object (JNIEnv *e, const char *clsname, jobject *cached_obj);
192 int nfc_jni_cache_object_local (JNIEnv *e, const char *className, jobject *cachedObj);
193 int nfc_jni_get_nfc_socket_handle (JNIEnv *e, jobject o);
194 struct nfc_jni_native_data* nfc_jni_get_nat (JNIEnv *e, jobject o);
195 int register_com_android_nfc_NativeNfcManager (JNIEnv *e);
196 int register_com_android_nfc_NativeNfcTag (JNIEnv *e);
197 int register_com_android_nfc_NativeP2pDevice (JNIEnv *e);
198 int register_com_android_nfc_NativeLlcpConnectionlessSocket (JNIEnv *e);
199 int register_com_android_nfc_NativeLlcpServiceSocket (JNIEnv *e);
200 int register_com_android_nfc_NativeLlcpSocket (JNIEnv *e);
201 int register_com_android_nfc_NativeNfcSecureElement (JNIEnv *e);
202 int register_com_android_nfc_NativeNfcAla(JNIEnv *e);
203} // namespace android