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