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 { onRemoteEndpointDiscovered(TagEndpoint tag)26 public void onRemoteEndpointDiscovered(TagEndpoint tag); 27 28 /** 29 * Notifies transaction 30 */ onCardEmulationDeselected()31 public void onCardEmulationDeselected(); 32 33 /** 34 * Notifies transaction 35 */ onCardEmulationAidSelected(byte[] aid)36 public void onCardEmulationAidSelected(byte[] aid); 37 38 /** 39 * Notifies P2P Device detected, to activate LLCP link 40 */ onLlcpLinkActivated(NfcDepEndpoint device)41 public void onLlcpLinkActivated(NfcDepEndpoint device); 42 43 /** 44 * Notifies P2P Device detected, to activate LLCP link 45 */ onLlcpLinkDeactivated(NfcDepEndpoint device)46 public void onLlcpLinkDeactivated(NfcDepEndpoint device); 47 onRemoteFieldActivated()48 public void onRemoteFieldActivated(); 49 onRemoteFieldDeactivated()50 public void onRemoteFieldDeactivated(); 51 52 /** 53 * Notifies that the SE has been activated in listen mode 54 */ onSeListenActivated()55 public void onSeListenActivated(); 56 57 /** 58 * Notifies that the SE has been deactivated 59 */ onSeListenDeactivated()60 public void onSeListenDeactivated(); 61 onSeApduReceived(byte[] apdu)62 public void onSeApduReceived(byte[] apdu); 63 onSeEmvCardRemoval()64 public void onSeEmvCardRemoval(); 65 onSeMifareAccess(byte[] block)66 public void onSeMifareAccess(byte[] block); 67 } 68 69 public interface TagEndpoint { connect(int technology)70 boolean connect(int technology); reconnect()71 boolean reconnect(); disconnect()72 boolean disconnect(); 73 presenceCheck()74 boolean presenceCheck(); isPresent()75 boolean isPresent(); startPresenceChecking()76 void startPresenceChecking(); 77 getTechList()78 int[] getTechList(); removeTechnology(int tech)79 void removeTechnology(int tech); // TODO remove this one getTechExtras()80 Bundle[] getTechExtras(); getUid()81 byte[] getUid(); getHandle()82 int getHandle(); 83 transceive(byte[] data, boolean raw, int[] returnCode)84 byte[] transceive(byte[] data, boolean raw, int[] returnCode); 85 checkNdef(int[] out)86 boolean checkNdef(int[] out); readNdef()87 byte[] readNdef(); writeNdef(byte[] data)88 boolean writeNdef(byte[] data); findAndReadNdef()89 NdefMessage findAndReadNdef(); formatNdef(byte[] key)90 boolean formatNdef(byte[] key); isNdefFormatable()91 boolean isNdefFormatable(); makeReadOnly()92 boolean makeReadOnly(); 93 getConnectedTechnology()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 receive()116 public byte[] receive(); 117 send(byte[] data)118 public boolean send(byte[] data); 119 connect()120 public boolean connect(); 121 disconnect()122 public boolean disconnect(); 123 transceive(byte[] data)124 public byte[] transceive(byte[] data); 125 getHandle()126 public int getHandle(); 127 getMode()128 public int getMode(); 129 getGeneralBytes()130 public byte[] getGeneralBytes(); 131 } 132 133 public interface LlcpSocket { connectToSap(int sap)134 public void connectToSap(int sap) throws IOException; 135 connectToService(String serviceName)136 public void connectToService(String serviceName) throws IOException; 137 close()138 public void close() throws IOException; 139 send(byte[] data)140 public void send(byte[] data) throws IOException; 141 receive(byte[] recvBuff)142 public int receive(byte[] recvBuff) throws IOException; 143 getRemoteMiu()144 public int getRemoteMiu(); 145 getRemoteRw()146 public int getRemoteRw(); 147 getLocalSap()148 public int getLocalSap(); 149 getLocalMiu()150 public int getLocalMiu(); 151 getLocalRw()152 public int getLocalRw(); 153 } 154 155 public interface LlcpServerSocket { accept()156 public LlcpSocket accept() throws IOException, LlcpException; 157 close()158 public void close() throws IOException; 159 } 160 161 public interface LlcpConnectionlessSocket { getLinkMiu()162 public int getLinkMiu(); 163 getSap()164 public int getSap(); 165 send(int sap, byte[] data)166 public void send(int sap, byte[] data) throws IOException; 167 receive()168 public LlcpPacket receive() throws IOException; 169 close()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 */ checkFirmware()182 public void checkFirmware(); 183 initialize()184 public boolean initialize(); 185 deinitialize()186 public boolean deinitialize(); 187 getName()188 public String getName(); 189 enableDiscovery()190 public void enableDiscovery(); 191 disableDiscovery()192 public void disableDiscovery(); 193 doGetSecureElementList()194 public int[] doGetSecureElementList(); 195 doSelectSecureElement()196 public void doSelectSecureElement(); 197 doDeselectSecureElement()198 public void doDeselectSecureElement(); 199 createLlcpConnectionlessSocket(int nSap, String sn)200 public LlcpConnectionlessSocket createLlcpConnectionlessSocket(int nSap, String sn) 201 throws LlcpException; 202 createLlcpServerSocket(int nSap, String sn, int miu, int rw, int linearBufferLength)203 public LlcpServerSocket createLlcpServerSocket(int nSap, String sn, int miu, 204 int rw, int linearBufferLength) throws LlcpException; 205 createLlcpSocket(int sap, int miu, int rw, int linearBufferLength)206 public LlcpSocket createLlcpSocket(int sap, int miu, int rw, 207 int linearBufferLength) throws LlcpException; 208 doCheckLlcp()209 public boolean doCheckLlcp(); 210 doActivateLlcp()211 public boolean doActivateLlcp(); 212 resetTimeouts()213 public void resetTimeouts(); 214 setTimeout(int technology, int timeout)215 public boolean setTimeout(int technology, int timeout); 216 getTimeout(int technology)217 public int getTimeout(int technology); 218 doAbort()219 public void doAbort(); 220 canMakeReadOnly(int technology)221 boolean canMakeReadOnly(int technology); 222 getMaxTransceiveLength(int technology)223 int getMaxTransceiveLength(int technology); 224 setP2pInitiatorModes(int modes)225 void setP2pInitiatorModes(int modes); 226 setP2pTargetModes(int modes)227 void setP2pTargetModes(int modes); 228 getExtendedLengthApdusSupported()229 boolean getExtendedLengthApdusSupported(); 230 enablePN544Quirks()231 boolean enablePN544Quirks(); 232 getWipeApdus()233 byte[][] getWipeApdus(); 234 getDefaultLlcpMiu()235 int getDefaultLlcpMiu(); 236 getDefaultLlcpRwSize()237 int getDefaultLlcpRwSize(); 238 dump()239 String dump(); 240 } 241