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.nfc.cardemulation.PollingFrame;
22 import android.os.Bundle;
23 
24 import java.io.FileDescriptor;
25 import java.io.IOException;
26 import java.util.List;
27 
28 public interface DeviceHost {
29     public interface DeviceHostListener {
onRemoteEndpointDiscovered(TagEndpoint tag)30         public void onRemoteEndpointDiscovered(TagEndpoint tag);
31 
32         /**
33          */
onHostCardEmulationActivated(int technology)34         public void onHostCardEmulationActivated(int technology);
onHostCardEmulationData(int technology, byte[] data)35         public void onHostCardEmulationData(int technology, byte[] data);
onHostCardEmulationDeactivated(int technology)36         public void onHostCardEmulationDeactivated(int technology);
37 
onRemoteFieldActivated()38         public void onRemoteFieldActivated();
39 
onRemoteFieldDeactivated()40         public void onRemoteFieldDeactivated();
41 
onNfcTransactionEvent(byte[] aid, byte[] data, String seName)42         public void onNfcTransactionEvent(byte[] aid, byte[] data, String seName);
43 
onEeUpdated()44         public void onEeUpdated();
45 
onHwErrorReported()46         public void onHwErrorReported();
47 
onPollingLoopDetected(List<PollingFrame> pollingFrames)48         public void onPollingLoopDetected(List<PollingFrame> pollingFrames);
49 
onWlcStopped(int wpt_end_condition)50         public void onWlcStopped(int wpt_end_condition);
51 
onVendorSpecificEvent(int gid, int oid, byte[] payload)52         public void onVendorSpecificEvent(int gid, int oid, byte[] payload);
53     }
54 
55     public interface TagEndpoint {
connect(int technology)56         boolean connect(int technology);
reconnect()57         boolean reconnect();
disconnect()58         boolean disconnect();
59 
presenceCheck()60         boolean presenceCheck();
isPresent()61         boolean isPresent();
startPresenceChecking(int presenceCheckDelay, @Nullable TagDisconnectedCallback callback)62         void startPresenceChecking(int presenceCheckDelay,
63                                    @Nullable TagDisconnectedCallback callback);
stopPresenceChecking()64         void stopPresenceChecking();
65 
getTechList()66         int[] getTechList();
removeTechnology(int tech)67         void removeTechnology(int tech); // TODO remove this one
getTechExtras()68         Bundle[] getTechExtras();
getUid()69         byte[] getUid();
getHandle()70         int getHandle();
71 
transceive(byte[] data, boolean raw, int[] returnCode)72         byte[] transceive(byte[] data, boolean raw, int[] returnCode);
73 
checkNdef(int[] out)74         boolean checkNdef(int[] out);
readNdef()75         byte[] readNdef();
writeNdef(byte[] data)76         boolean writeNdef(byte[] data);
findAndReadNdef()77         NdefMessage findAndReadNdef();
getNdef()78         NdefMessage getNdef();
formatNdef(byte[] key)79         boolean formatNdef(byte[] key);
isNdefFormatable()80         boolean isNdefFormatable();
makeReadOnly()81         boolean makeReadOnly();
82 
getConnectedTechnology()83         int getConnectedTechnology();
84 
85         /**
86          * Find Ndef only
87          * As per NFC forum test specification ndef write test expects only
88          * ndef detection followed by ndef write. System property
89          * nfc.dta.skipNdefRead added to skip default ndef read before tag
90          * dispatch. This system property is valid only in reader mode.
91          */
findNdef()92         void findNdef();
93     }
94 
95     public interface TagDisconnectedCallback {
onTagDisconnected()96         void onTagDisconnected();
97     }
98 
99     public interface NfceeEndpoint {
100         // TODO flesh out multi-EE and use this
101     }
102 
103     public interface NfcDepEndpoint {
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     }
125 
126     /**
127      * Called at boot if NFC is disabled to give the device host an opportunity
128      * to check the firmware version to see if it needs updating. Normally the firmware version
129      * is checked during {@link #initialize(boolean enableScreenOffSuspend)},
130      * but the firmware may need to be updated after an OTA update.
131      *
132      * <p>This is called from a thread
133      * that may block for long periods of time during the update process.
134      */
checkFirmware()135     public boolean checkFirmware();
136 
initialize()137     public boolean initialize();
138 
deinitialize()139     public boolean deinitialize();
140 
getName()141     public String getName();
142 
enableDiscovery(NfcDiscoveryParameters params, boolean restart)143     public void enableDiscovery(NfcDiscoveryParameters params, boolean restart);
144 
disableDiscovery()145     public void disableDiscovery();
146 
sendRawFrame(byte[] data)147     public boolean sendRawFrame(byte[] data);
148 
routeAid(byte[] aid, int route, int aidInfo, int power)149     public boolean routeAid(byte[] aid, int route, int aidInfo, int power);
150 
unrouteAid(byte[] aid)151     public boolean unrouteAid(byte[] aid);
152 
commitRouting()153     public boolean commitRouting();
154 
registerT3tIdentifier(byte[] t3tIdentifier)155     public void registerT3tIdentifier(byte[] t3tIdentifier);
156 
deregisterT3tIdentifier(byte[] t3tIdentifier)157     public void deregisterT3tIdentifier(byte[] t3tIdentifier);
158 
clearT3tIdentifiersCache()159     public void clearT3tIdentifiersCache();
160 
getLfT3tMax()161     public int getLfT3tMax();
162 
resetTimeouts()163     public void resetTimeouts();
164 
setTimeout(int technology, int timeout)165     public boolean setTimeout(int technology, int timeout);
166 
getTimeout(int technology)167     public int getTimeout(int technology);
168 
doAbort(String msg)169     public void doAbort(String msg);
170 
canMakeReadOnly(int technology)171     boolean canMakeReadOnly(int technology);
172 
getMaxTransceiveLength(int technology)173     int getMaxTransceiveLength(int technology);
174 
getAidTableSize()175     public int getAidTableSize();
176 
getExtendedLengthApdusSupported()177     boolean getExtendedLengthApdusSupported();
178 
dump(FileDescriptor fd)179     void dump(FileDescriptor fd);
180 
doSetScreenState(int screen_state_mask, boolean alwaysPoll)181     public void doSetScreenState(int screen_state_mask, boolean alwaysPoll);
182 
getNciVersion()183     public int getNciVersion();
184 
enableDtaMode()185     public void enableDtaMode();
186 
disableDtaMode()187     public void disableDtaMode();
188 
factoryReset()189     public void factoryReset();
190 
shutdown()191     public void shutdown();
192 
setNfcSecure(boolean enable)193     public boolean setNfcSecure(boolean enable);
194 
isObserveModeSupported()195     public boolean isObserveModeSupported();
196 
setObserveMode(boolean enable)197     public boolean setObserveMode(boolean enable);
198 
isObserveModeEnabled()199     public boolean isObserveModeEnabled();
200 
201     /**
202     * Get the committed listen mode routing configuration
203     */
getRoutingTable()204     byte[] getRoutingTable();
205 
206     /**
207     * Get the Max Routing Table size from cache
208     */
getMaxRoutingTableSize()209     int getMaxRoutingTableSize();
210 
211     /**
212     * Start or stop RF polling
213     */
startStopPolling(boolean enable)214     void startStopPolling(boolean enable);
215 
216     /**
217     * Set NFCC power state by sending NFCEE_POWER_AND_LINK_CNTRL_CMD
218     */
setNfceePowerAndLinkCtrl(boolean enable)219     void setNfceePowerAndLinkCtrl(boolean enable);
220 
221     /**
222      * Enable or Disable the Power Saving Mode based on flag
223      */
setPowerSavingMode(boolean flag)224     boolean setPowerSavingMode(boolean flag);
225 
isMultiTag()226     boolean isMultiTag();
227 
setIsoDepProtocolRoute(int route)228     void setIsoDepProtocolRoute(int route);
setTechnologyABRoute(int route)229     void setTechnologyABRoute(int route);
clearRoutingEntry(int clearFlags)230     void clearRoutingEntry(int clearFlags);
231 
232     /**
233     * Set NFCC discovery technology for polling and listening
234     */
setDiscoveryTech(int pollTech, int listenTech)235     void setDiscoveryTech(int pollTech, int listenTech);
resetDiscoveryTech()236     void resetDiscoveryTech();
237     /**
238      * Sends Vendor NCI command
239      */
sendRawVendorCmd(int mt, int gid, int oid, byte[] payload)240     NfcVendorNciResponse sendRawVendorCmd(int mt, int gid, int oid, byte[] payload);
241 
enableVendorNciNotifications(boolean enabled)242     void enableVendorNciNotifications(boolean enabled);
243 }
244