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