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.annotation.Nullable; 20 import android.nfc.NdefMessage; 21 import android.os.Bundle; 22 23 import java.io.FileDescriptor; 24 import java.io.IOException; 25 26 public interface DeviceHost { 27 public interface DeviceHostListener { onRemoteEndpointDiscovered(TagEndpoint tag)28 public void onRemoteEndpointDiscovered(TagEndpoint tag); 29 30 /** 31 */ onHostCardEmulationActivated(int technology)32 public void onHostCardEmulationActivated(int technology); onHostCardEmulationData(int technology, byte[] data)33 public void onHostCardEmulationData(int technology, byte[] data); onHostCardEmulationDeactivated(int technology)34 public void onHostCardEmulationDeactivated(int technology); 35 36 /** 37 * Notifies P2P Device detected, to activate LLCP link 38 */ onLlcpLinkActivated(NfcDepEndpoint device)39 public void onLlcpLinkActivated(NfcDepEndpoint device); 40 41 /** 42 * Notifies P2P Device detected, to activate LLCP link 43 */ onLlcpLinkDeactivated(NfcDepEndpoint device)44 public void onLlcpLinkDeactivated(NfcDepEndpoint device); 45 onLlcpFirstPacketReceived(NfcDepEndpoint device)46 public void onLlcpFirstPacketReceived(NfcDepEndpoint device); 47 onRemoteFieldActivated()48 public void onRemoteFieldActivated(); 49 onRemoteFieldDeactivated()50 public void onRemoteFieldDeactivated(); 51 onNfcTransactionEvent(byte[] aid, byte[] data, String seName)52 public void onNfcTransactionEvent(byte[] aid, byte[] data, String seName); 53 onEeUpdated()54 public void onEeUpdated(); 55 onHwErrorReported()56 public void onHwErrorReported(); 57 } 58 59 public interface TagEndpoint { connect(int technology)60 boolean connect(int technology); reconnect()61 boolean reconnect(); disconnect()62 boolean disconnect(); 63 presenceCheck()64 boolean presenceCheck(); isPresent()65 boolean isPresent(); startPresenceChecking(int presenceCheckDelay, @Nullable TagDisconnectedCallback callback)66 void startPresenceChecking(int presenceCheckDelay, 67 @Nullable TagDisconnectedCallback callback); stopPresenceChecking()68 void stopPresenceChecking(); 69 getTechList()70 int[] getTechList(); removeTechnology(int tech)71 void removeTechnology(int tech); // TODO remove this one getTechExtras()72 Bundle[] getTechExtras(); getUid()73 byte[] getUid(); getHandle()74 int getHandle(); 75 transceive(byte[] data, boolean raw, int[] returnCode)76 byte[] transceive(byte[] data, boolean raw, int[] returnCode); 77 checkNdef(int[] out)78 boolean checkNdef(int[] out); readNdef()79 byte[] readNdef(); writeNdef(byte[] data)80 boolean writeNdef(byte[] data); findAndReadNdef()81 NdefMessage findAndReadNdef(); formatNdef(byte[] key)82 boolean formatNdef(byte[] key); isNdefFormatable()83 boolean isNdefFormatable(); makeReadOnly()84 boolean makeReadOnly(); 85 getConnectedTechnology()86 int getConnectedTechnology(); 87 88 /** 89 * Find Ndef only 90 * As per NFC forum test specification ndef write test expects only 91 * ndef detection followed by ndef write. System property 92 * nfc.dta.skipNdefRead added to skip default ndef read before tag 93 * dispatch. This system property is valid only in reader mode. 94 */ findNdef()95 void findNdef(); 96 } 97 98 public interface TagDisconnectedCallback { onTagDisconnected(long handle)99 void onTagDisconnected(long handle); 100 } 101 102 public interface NfceeEndpoint { 103 // TODO flesh out multi-EE and use this 104 } 105 106 public interface NfcDepEndpoint { 107 108 /** 109 * Peer-to-Peer Target 110 */ 111 public static final short MODE_P2P_TARGET = 0x00; 112 /** 113 * Peer-to-Peer Initiator 114 */ 115 public static final short MODE_P2P_INITIATOR = 0x01; 116 /** 117 * Invalid target mode 118 */ 119 public static final short MODE_INVALID = 0xff; 120 receive()121 public byte[] receive(); 122 send(byte[] data)123 public boolean send(byte[] data); 124 connect()125 public boolean connect(); 126 disconnect()127 public boolean disconnect(); 128 transceive(byte[] data)129 public byte[] transceive(byte[] data); 130 getHandle()131 public int getHandle(); 132 getMode()133 public int getMode(); 134 getGeneralBytes()135 public byte[] getGeneralBytes(); 136 getLlcpVersion()137 public byte getLlcpVersion(); 138 } 139 140 public interface LlcpSocket { connectToSap(int sap)141 public void connectToSap(int sap) throws IOException; 142 connectToService(String serviceName)143 public void connectToService(String serviceName) throws IOException; 144 close()145 public void close() throws IOException; 146 send(byte[] data)147 public void send(byte[] data) throws IOException; 148 receive(byte[] recvBuff)149 public int receive(byte[] recvBuff) throws IOException; 150 getRemoteMiu()151 public int getRemoteMiu(); 152 getRemoteRw()153 public int getRemoteRw(); 154 getLocalSap()155 public int getLocalSap(); 156 getLocalMiu()157 public int getLocalMiu(); 158 getLocalRw()159 public int getLocalRw(); 160 } 161 162 public interface LlcpServerSocket { accept()163 public LlcpSocket accept() throws IOException, LlcpException; 164 close()165 public void close() throws IOException; 166 } 167 168 public interface LlcpConnectionlessSocket { getLinkMiu()169 public int getLinkMiu(); 170 getSap()171 public int getSap(); 172 send(int sap, byte[] data)173 public void send(int sap, byte[] data) throws IOException; 174 receive()175 public LlcpPacket receive() throws IOException; 176 close()177 public void close() throws IOException; 178 } 179 180 /** 181 * Called at boot if NFC is disabled to give the device host an opportunity 182 * to check the firmware version to see if it needs updating. Normally the firmware version 183 * is checked during {@link #initialize(boolean enableScreenOffSuspend)}, 184 * but the firmware may need to be updated after an OTA update. 185 * 186 * <p>This is called from a thread 187 * that may block for long periods of time during the update process. 188 */ checkFirmware()189 public boolean checkFirmware(); 190 initialize()191 public boolean initialize(); 192 deinitialize()193 public boolean deinitialize(); 194 getName()195 public String getName(); 196 enableDiscovery(NfcDiscoveryParameters params, boolean restart)197 public void enableDiscovery(NfcDiscoveryParameters params, boolean restart); 198 disableDiscovery()199 public void disableDiscovery(); 200 sendRawFrame(byte[] data)201 public boolean sendRawFrame(byte[] data); 202 routeAid(byte[] aid, int route, int aidInfo, int power)203 public boolean routeAid(byte[] aid, int route, int aidInfo, int power); 204 unrouteAid(byte[] aid)205 public boolean unrouteAid(byte[] aid); 206 commitRouting()207 public boolean commitRouting(); 208 registerT3tIdentifier(byte[] t3tIdentifier)209 public void registerT3tIdentifier(byte[] t3tIdentifier); 210 deregisterT3tIdentifier(byte[] t3tIdentifier)211 public void deregisterT3tIdentifier(byte[] t3tIdentifier); 212 clearT3tIdentifiersCache()213 public void clearT3tIdentifiersCache(); 214 getLfT3tMax()215 public int getLfT3tMax(); 216 createLlcpConnectionlessSocket(int nSap, String sn)217 public LlcpConnectionlessSocket createLlcpConnectionlessSocket(int nSap, String sn) 218 throws LlcpException; 219 createLlcpServerSocket(int nSap, String sn, int miu, int rw, int linearBufferLength)220 public LlcpServerSocket createLlcpServerSocket(int nSap, String sn, int miu, 221 int rw, int linearBufferLength) throws LlcpException; 222 createLlcpSocket(int sap, int miu, int rw, int linearBufferLength)223 public LlcpSocket createLlcpSocket(int sap, int miu, int rw, 224 int linearBufferLength) throws LlcpException; 225 doCheckLlcp()226 public boolean doCheckLlcp(); 227 doActivateLlcp()228 public boolean doActivateLlcp(); 229 resetTimeouts()230 public void resetTimeouts(); 231 setTimeout(int technology, int timeout)232 public boolean setTimeout(int technology, int timeout); 233 getTimeout(int technology)234 public int getTimeout(int technology); 235 doAbort(String msg)236 public void doAbort(String msg); 237 canMakeReadOnly(int technology)238 boolean canMakeReadOnly(int technology); 239 getMaxTransceiveLength(int technology)240 int getMaxTransceiveLength(int technology); 241 getAidTableSize()242 public int getAidTableSize(); 243 setP2pInitiatorModes(int modes)244 void setP2pInitiatorModes(int modes); 245 setP2pTargetModes(int modes)246 void setP2pTargetModes(int modes); 247 getExtendedLengthApdusSupported()248 boolean getExtendedLengthApdusSupported(); 249 getDefaultLlcpMiu()250 int getDefaultLlcpMiu(); 251 getDefaultLlcpRwSize()252 int getDefaultLlcpRwSize(); 253 dump(FileDescriptor fd)254 void dump(FileDescriptor fd); 255 enableScreenOffSuspend()256 boolean enableScreenOffSuspend(); 257 disableScreenOffSuspend()258 boolean disableScreenOffSuspend(); 259 doSetScreenState(int screen_state_mask)260 public void doSetScreenState(int screen_state_mask); 261 getNciVersion()262 public int getNciVersion(); 263 enableDtaMode()264 public void enableDtaMode(); 265 disableDtaMode()266 public void disableDtaMode(); 267 factoryReset()268 public void factoryReset(); 269 shutdown()270 public void shutdown(); 271 setNfcSecure(boolean enable)272 public boolean setNfcSecure(boolean enable); 273 getNfaStorageDir()274 public String getNfaStorageDir(); 275 276 /** 277 * Get the committed listen mode routing configuration 278 */ getRoutingTable()279 byte[] getRoutingTable(); 280 281 /** 282 * Get the Max Routing Table size from cache 283 */ getMaxRoutingTableSize()284 int getMaxRoutingTableSize(); 285 286 /** 287 * Start or stop RF polling 288 */ startStopPolling(boolean enable)289 void startStopPolling(boolean enable); 290 291 /** 292 * Set NFCC power state by sending NFCEE_POWER_AND_LINK_CNTRL_CMD 293 */ setNfceePowerAndLinkCtrl(boolean enable)294 void setNfceePowerAndLinkCtrl(boolean enable); 295 } 296