1 /* 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 #pragma once 18 #define LOG_TAG "BrcmNfcJni" 19 #include <JNIHelp.h> 20 #include <jni.h> 21 #include <pthread.h> 22 #include <sys/queue.h> 23 #include <semaphore.h> 24 25 26 /* Discovery modes -- keep in sync with NFCManager.DISCOVERY_MODE_* */ 27 #define DISCOVERY_MODE_TAG_READER 0 28 #define DISCOVERY_MODE_NFCIP1 1 29 #define DISCOVERY_MODE_CARD_EMULATION 2 30 #define DISCOVERY_MODE_TABLE_SIZE 3 31 32 #define DISCOVERY_MODE_DISABLED 0 33 #define DISCOVERY_MODE_ENABLED 1 34 35 #define MODE_P2P_TARGET 0 36 #define MODE_P2P_INITIATOR 1 37 38 39 /* Properties values */ 40 #define PROPERTY_LLCP_LTO 0 41 #define PROPERTY_LLCP_MIU 1 42 #define PROPERTY_LLCP_WKS 2 43 #define PROPERTY_LLCP_OPT 3 44 #define PROPERTY_NFC_DISCOVERY_A 4 45 #define PROPERTY_NFC_DISCOVERY_B 5 46 #define PROPERTY_NFC_DISCOVERY_F 6 47 #define PROPERTY_NFC_DISCOVERY_15693 7 48 #define PROPERTY_NFC_DISCOVERY_NCFIP 8 49 50 51 /* Error codes */ 52 #define ERROR_BUFFER_TOO_SMALL -12 53 #define ERROR_INSUFFICIENT_RESOURCES -9 54 55 56 /* Pre-defined tag type values. These must match the values in 57 * Ndef.java in the framework. 58 */ 59 #define NDEF_UNKNOWN_TYPE -1 60 #define NDEF_TYPE1_TAG 1 61 #define NDEF_TYPE2_TAG 2 62 #define NDEF_TYPE3_TAG 3 63 #define NDEF_TYPE4_TAG 4 64 #define NDEF_MIFARE_CLASSIC_TAG 101 65 66 67 /* Pre-defined card read/write state values. These must match the values in 68 * Ndef.java in the framework. 69 */ 70 #define NDEF_MODE_READ_ONLY 1 71 #define NDEF_MODE_READ_WRITE 2 72 #define NDEF_MODE_UNKNOWN 3 73 74 75 /* Name strings for target types. These *must* match the values in TagTechnology.java */ 76 #define TARGET_TYPE_UNKNOWN -1 77 #define TARGET_TYPE_ISO14443_3A 1 78 #define TARGET_TYPE_ISO14443_3B 2 79 #define TARGET_TYPE_ISO14443_4 3 80 #define TARGET_TYPE_FELICA 4 81 #define TARGET_TYPE_ISO15693 5 82 #define TARGET_TYPE_NDEF 6 83 #define TARGET_TYPE_NDEF_FORMATABLE 7 84 #define TARGET_TYPE_MIFARE_CLASSIC 8 85 #define TARGET_TYPE_MIFARE_UL 9 86 87 88 //define a few NXP error codes that NFC service expects; 89 //see external/libnfc-nxp/src/phLibNfcStatus.h; 90 //see external/libnfc-nxp/inc/phNfcStatus.h 91 #define NFCSTATUS_SUCCESS (0x0000) 92 #define NFCSTATUS_FAILED (0x00FF) 93 94 //default general trasceive timeout in millisecond 95 #define DEFAULT_GENERAL_TRANS_TIMEOUT 1000 96 97 struct nfc_jni_native_data 98 { 99 /* Thread handle */ 100 pthread_t thread; 101 int running; 102 103 /* Our VM */ 104 JavaVM *vm; 105 int env_version; 106 107 /* Reference to the NFCManager instance */ 108 jobject manager; 109 110 /* Cached objects */ 111 jobject cached_NfcTag; 112 jobject cached_P2pDevice; 113 114 /* Secure Element selected */ 115 int seId; 116 117 /* LLCP params */ 118 int lto; 119 int miu; 120 int wks; 121 int opt; 122 123 int tech_mask; 124 125 /* Tag detected */ 126 jobject tag; 127 128 int tHandle; 129 int tProtocols[16]; 130 int handles[16]; 131 }; 132 133 134 extern "C" 135 { 136 jint JNI_OnLoad(JavaVM *jvm, void *reserved); 137 } 138 139 140 namespace android 141 { 142 int nfc_jni_cache_object (JNIEnv *e, const char *clsname, jobject *cached_obj); 143 int nfc_jni_get_nfc_socket_handle (JNIEnv *e, jobject o); 144 struct nfc_jni_native_data* nfc_jni_get_nat (JNIEnv *e, jobject o); 145 int register_com_android_nfc_NativeNfcManager (JNIEnv *e); 146 int register_com_android_nfc_NativeNfcTag (JNIEnv *e); 147 int register_com_android_nfc_NativeP2pDevice (JNIEnv *e); 148 int register_com_android_nfc_NativeLlcpConnectionlessSocket (JNIEnv *e); 149 int register_com_android_nfc_NativeLlcpServiceSocket (JNIEnv *e); 150 int register_com_android_nfc_NativeLlcpSocket (JNIEnv *e); 151 int register_com_android_nfc_NativeNfcSecureElement (JNIEnv *e); 152 } // namespace android 153