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