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 
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     }
51 
52     public interface TagEndpoint {
connect(int technology)53         boolean connect(int technology);
reconnect()54         boolean reconnect();
disconnect()55         boolean disconnect();
56 
presenceCheck()57         boolean presenceCheck();
isPresent()58         boolean isPresent();
startPresenceChecking(int presenceCheckDelay, @Nullable TagDisconnectedCallback callback)59         void startPresenceChecking(int presenceCheckDelay,
60                                    @Nullable TagDisconnectedCallback callback);
61 
getTechList()62         int[] getTechList();
removeTechnology(int tech)63         void removeTechnology(int tech); // TODO remove this one
getTechExtras()64         Bundle[] getTechExtras();
getUid()65         byte[] getUid();
getHandle()66         int getHandle();
67 
transceive(byte[] data, boolean raw, int[] returnCode)68         byte[] transceive(byte[] data, boolean raw, int[] returnCode);
69 
checkNdef(int[] out)70         boolean checkNdef(int[] out);
readNdef()71         byte[] readNdef();
writeNdef(byte[] data)72         boolean writeNdef(byte[] data);
findAndReadNdef()73         NdefMessage findAndReadNdef();
formatNdef(byte[] key)74         boolean formatNdef(byte[] key);
isNdefFormatable()75         boolean isNdefFormatable();
makeReadOnly()76         boolean makeReadOnly();
77 
getConnectedTechnology()78         int getConnectedTechnology();
79     }
80 
81     public interface TagDisconnectedCallback {
onTagDisconnected(long handle)82         void onTagDisconnected(long handle);
83     }
84 
85     public interface NfceeEndpoint {
86         // TODO flesh out multi-EE and use this
87     }
88 
89     public interface NfcDepEndpoint {
90 
91         /**
92          * Peer-to-Peer Target
93          */
94         public static final short MODE_P2P_TARGET = 0x00;
95         /**
96          * Peer-to-Peer Initiator
97          */
98         public static final short MODE_P2P_INITIATOR = 0x01;
99         /**
100          * Invalid target mode
101          */
102         public static final short MODE_INVALID = 0xff;
103 
receive()104         public byte[] receive();
105 
send(byte[] data)106         public boolean send(byte[] data);
107 
connect()108         public boolean connect();
109 
disconnect()110         public boolean disconnect();
111 
transceive(byte[] data)112         public byte[] transceive(byte[] data);
113 
getHandle()114         public int getHandle();
115 
getMode()116         public int getMode();
117 
getGeneralBytes()118         public byte[] getGeneralBytes();
119 
getLlcpVersion()120         public byte getLlcpVersion();
121     }
122 
123     public interface LlcpSocket {
connectToSap(int sap)124         public void connectToSap(int sap) throws IOException;
125 
connectToService(String serviceName)126         public void connectToService(String serviceName) throws IOException;
127 
close()128         public void close() throws IOException;
129 
send(byte[] data)130         public void send(byte[] data) throws IOException;
131 
receive(byte[] recvBuff)132         public int receive(byte[] recvBuff) throws IOException;
133 
getRemoteMiu()134         public int getRemoteMiu();
135 
getRemoteRw()136         public int getRemoteRw();
137 
getLocalSap()138         public int getLocalSap();
139 
getLocalMiu()140         public int getLocalMiu();
141 
getLocalRw()142         public int getLocalRw();
143     }
144 
145     public interface LlcpServerSocket {
accept()146         public LlcpSocket accept() throws IOException, LlcpException;
147 
close()148         public void close() throws IOException;
149     }
150 
151     public interface LlcpConnectionlessSocket {
getLinkMiu()152         public int getLinkMiu();
153 
getSap()154         public int getSap();
155 
send(int sap, byte[] data)156         public void send(int sap, byte[] data) throws IOException;
157 
receive()158         public LlcpPacket receive() throws IOException;
159 
close()160         public void close() throws IOException;
161     }
162 
163     /**
164      * Called at boot if NFC is disabled to give the device host an opportunity
165      * to check the firmware version to see if it needs updating. Normally the firmware version
166      * is checked during {@link #initialize(boolean enableScreenOffSuspend)},
167      * but the firmware may need to be updated after an OTA update.
168      *
169      * <p>This is called from a thread
170      * that may block for long periods of time during the update process.
171      */
checkFirmware()172     public void checkFirmware();
173 
initialize()174     public boolean initialize();
175 
deinitialize()176     public boolean deinitialize();
177 
getName()178     public String getName();
179 
enableDiscovery(NfcDiscoveryParameters params, boolean restart)180     public void enableDiscovery(NfcDiscoveryParameters params, boolean restart);
181 
disableDiscovery()182     public void disableDiscovery();
183 
sendRawFrame(byte[] data)184     public boolean sendRawFrame(byte[] data);
185 
routeAid(byte[] aid, int route)186     public boolean routeAid(byte[] aid, int route);
187 
unrouteAid(byte[] aid)188     public boolean unrouteAid(byte[] aid);
189 
commitRouting()190     public boolean commitRouting();
191 
registerT3tIdentifier(byte[] t3tIdentifier)192     public void registerT3tIdentifier(byte[] t3tIdentifier);
193 
deregisterT3tIdentifier(byte[] t3tIdentifier)194     public void deregisterT3tIdentifier(byte[] t3tIdentifier);
195 
clearT3tIdentifiersCache()196     public void clearT3tIdentifiersCache();
197 
getLfT3tMax()198     public int getLfT3tMax();
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(String msg)219     public void doAbort(String msg);
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 
getDefaultLlcpMiu()231     int getDefaultLlcpMiu();
232 
getDefaultLlcpRwSize()233     int getDefaultLlcpRwSize();
234 
dump()235     String dump();
236 
enableScreenOffSuspend()237     boolean enableScreenOffSuspend();
238 
disableScreenOffSuspend()239     boolean disableScreenOffSuspend();
240 }
241