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