1 /* 2 * Copyright (C) 2011 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 package com.android.nfc; 18 19 import android.nfc.NdefMessage; 20 import android.os.Bundle; 21 22 import java.io.IOException; 23 24 public interface DeviceHost { 25 public interface DeviceHostListener { 26 public void onRemoteEndpointDiscovered(TagEndpoint tag); 27 28 /** 29 * Notifies transaction 30 */ 31 public void onCardEmulationDeselected(); 32 33 /** 34 * Notifies transaction 35 */ 36 public void onCardEmulationAidSelected(byte[] aid); 37 38 /** 39 */ 40 public void onHostCardEmulationActivated(); 41 public void onHostCardEmulationData(byte[] data); 42 public void onHostCardEmulationDeactivated(); 43 44 /** 45 * Notifies P2P Device detected, to activate LLCP link 46 */ 47 public void onLlcpLinkActivated(NfcDepEndpoint device); 48 49 /** 50 * Notifies P2P Device detected, to activate LLCP link 51 */ 52 public void onLlcpLinkDeactivated(NfcDepEndpoint device); 53 54 public void onLlcpFirstPacketReceived(NfcDepEndpoint device); 55 56 public void onRemoteFieldActivated(); 57 58 public void onRemoteFieldDeactivated(); 59 60 /** 61 * Notifies that the SE has been activated in listen mode 62 */ 63 public void onSeListenActivated(); 64 65 /** 66 * Notifies that the SE has been deactivated 67 */ 68 public void onSeListenDeactivated(); 69 70 public void onSeApduReceived(byte[] apdu); 71 72 public void onSeEmvCardRemoval(); 73 74 public void onSeMifareAccess(byte[] block); 75 } 76 77 public interface TagEndpoint { 78 boolean connect(int technology); 79 boolean reconnect(); 80 boolean disconnect(); 81 82 boolean presenceCheck(); 83 boolean isPresent(); 84 void startPresenceChecking(int presenceCheckDelay); 85 86 int[] getTechList(); 87 void removeTechnology(int tech); // TODO remove this one 88 Bundle[] getTechExtras(); 89 byte[] getUid(); 90 int getHandle(); 91 92 byte[] transceive(byte[] data, boolean raw, int[] returnCode); 93 94 boolean checkNdef(int[] out); 95 byte[] readNdef(); 96 boolean writeNdef(byte[] data); 97 NdefMessage findAndReadNdef(); 98 boolean formatNdef(byte[] key); 99 boolean isNdefFormatable(); 100 boolean makeReadOnly(); 101 102 int getConnectedTechnology(); 103 } 104 105 public interface NfceeEndpoint { 106 // TODO flesh out multi-EE and use this 107 } 108 109 public interface NfcDepEndpoint { 110 111 /** 112 * Peer-to-Peer Target 113 */ 114 public static final short MODE_P2P_TARGET = 0x00; 115 /** 116 * Peer-to-Peer Initiator 117 */ 118 public static final short MODE_P2P_INITIATOR = 0x01; 119 /** 120 * Invalid target mode 121 */ 122 public static final short MODE_INVALID = 0xff; 123 124 public byte[] receive(); 125 126 public boolean send(byte[] data); 127 128 public boolean connect(); 129 130 public boolean disconnect(); 131 132 public byte[] transceive(byte[] data); 133 134 public int getHandle(); 135 136 public int getMode(); 137 138 public byte[] getGeneralBytes(); 139 } 140 141 public interface LlcpSocket { 142 public void connectToSap(int sap) throws IOException; 143 144 public void connectToService(String serviceName) throws IOException; 145 146 public void close() throws IOException; 147 148 public void send(byte[] data) throws IOException; 149 150 public int receive(byte[] recvBuff) throws IOException; 151 152 public int getRemoteMiu(); 153 154 public int getRemoteRw(); 155 156 public int getLocalSap(); 157 158 public int getLocalMiu(); 159 160 public int getLocalRw(); 161 } 162 163 public interface LlcpServerSocket { 164 public LlcpSocket accept() throws IOException, LlcpException; 165 166 public void close() throws IOException; 167 } 168 169 public interface LlcpConnectionlessSocket { 170 public int getLinkMiu(); 171 172 public int getSap(); 173 174 public void send(int sap, byte[] data) throws IOException; 175 176 public LlcpPacket receive() throws IOException; 177 178 public void close() throws IOException; 179 } 180 181 /** 182 * Called at boot if NFC is disabled to give the device host an opportunity 183 * to check the firmware version to see if it needs updating. Normally the firmware version 184 * is checked during {@link #initialize()}, but the firmware may need to be updated after 185 * an OTA update. 186 * 187 * <p>This is called from a thread 188 * that may block for long periods of time during the update process. 189 */ 190 public void checkFirmware(); 191 192 public boolean initialize(); 193 194 public boolean deinitialize(); 195 196 public String getName(); 197 198 public void enableDiscovery(); 199 200 public void disableDiscovery(); 201 202 public void enableRoutingToHost(); 203 204 public void disableRoutingToHost(); 205 206 public int[] doGetSecureElementList(); 207 208 public void doSelectSecureElement(); 209 210 public void doDeselectSecureElement(); 211 212 public boolean sendRawFrame(byte[] data); 213 214 public boolean routeAid(byte[] aid, int route); 215 216 public boolean unrouteAid(byte[] aid); 217 218 public LlcpConnectionlessSocket createLlcpConnectionlessSocket(int nSap, String sn) 219 throws LlcpException; 220 221 public LlcpServerSocket createLlcpServerSocket(int nSap, String sn, int miu, 222 int rw, int linearBufferLength) throws LlcpException; 223 224 public LlcpSocket createLlcpSocket(int sap, int miu, int rw, 225 int linearBufferLength) throws LlcpException; 226 227 public boolean doCheckLlcp(); 228 229 public boolean doActivateLlcp(); 230 231 public void resetTimeouts(); 232 233 public boolean setTimeout(int technology, int timeout); 234 235 public int getTimeout(int technology); 236 237 public void doAbort(); 238 239 boolean canMakeReadOnly(int technology); 240 241 int getMaxTransceiveLength(int technology); 242 243 void setP2pInitiatorModes(int modes); 244 245 void setP2pTargetModes(int modes); 246 247 boolean getExtendedLengthApdusSupported(); 248 249 boolean enablePN544Quirks(); 250 251 byte[][] getWipeApdus(); 252 253 int getDefaultLlcpMiu(); 254 255 int getDefaultLlcpRwSize(); 256 257 String dump(); 258 259 boolean enableReaderMode(int technologies); 260 261 boolean disableReaderMode(); 262 } 263