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