DeviceHost.java revision 4a61d3b45e81c0070538f94747a70a49c78f12fa
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
17package com.android.nfc;
18
19import com.android.nfc.nxp.NativeLlcpConnectionlessSocket;
20import com.android.nfc.nxp.NativeLlcpServiceSocket;
21import com.android.nfc.nxp.NativeLlcpSocket;
22
23import android.nfc.NdefMessage;
24import android.os.Bundle;
25
26import java.io.IOException;
27
28public interface DeviceHost {
29    public interface DeviceHostListener {
30        public void onRemoteEndpointDiscovered(TagEndpoint tag);
31
32        /**
33         * Notifies transaction
34         */
35        public void onCardEmulationDeselected();
36
37        /**
38         * Notifies transaction
39         */
40        public void onCardEmulationAidSelected(byte[] aid);
41
42        /**
43         * Notifies P2P Device detected, to activate LLCP link
44         */
45        public void onLlcpLinkActivated(NfcDepEndpoint device);
46
47        /**
48         * Notifies P2P Device detected, to activate LLCP link
49         */
50        public void onLlcpLinkDeactivated(NfcDepEndpoint device);
51
52        public void onRemoteFieldActivated();
53
54        public void onRemoteFieldDeactivated();
55
56        public void onSeApduReceived(byte[] apdu);
57
58        public void onSeEmvCardRemoval();
59
60        public void onSeMifareAccess(byte[] block);
61    }
62
63    public interface TagEndpoint {
64        boolean connect(int technology);
65        boolean reconnect();
66        boolean disconnect();
67
68        boolean presenceCheck();
69        boolean isPresent();
70        void startPresenceChecking();
71
72        int[] getTechList();
73        void removeTechnology(int tech); // TODO remove this one
74        Bundle[] getTechExtras();
75        byte[] getUid();
76        int getHandle();
77
78        byte[] transceive(byte[] data, boolean raw, int[] returnCode);
79
80        boolean checkNdef(int[] out);
81        byte[] readNdef();
82        boolean writeNdef(byte[] data);
83        NdefMessage[] findAndReadNdef();
84        boolean formatNdef(byte[] key);
85        boolean isNdefFormatable();
86        boolean makeReadOnly();
87    }
88
89    public interface NfceeEndpoint {
90        // TODO flesh out multi-EE and use this
91    }
92
93    public interface NfcDepEndpoint {
94
95        /**
96         * Peer-to-Peer Target
97         */
98        public static final short MODE_P2P_TARGET = 0x00;
99        /**
100         * Peer-to-Peer Initiator
101         */
102        public static final short MODE_P2P_INITIATOR = 0x01;
103        /**
104         * Invalid target mode
105         */
106        public static final short MODE_INVALID = 0xff;
107
108        public byte[] receive();
109
110        public boolean send(byte[] data);
111
112        public boolean connect();
113
114        public boolean disconnect();
115
116        public byte[] transceive(byte[] data);
117
118        public int getHandle();
119
120        public int getMode();
121
122        public byte[] getGeneralBytes();
123    }
124
125    public interface LlcpSocket {
126        public void connectToSap(int sap) throws IOException;
127
128        public void connectToService(String serviceName) throws IOException;
129
130        public void close() throws IOException;
131
132        public void send(byte[] data) throws IOException;
133
134        public int receive(byte[] recvBuff) throws IOException;
135
136        public int getRemoteMiu();
137
138        public int getRemoteRw();
139
140        public int getLocalSap();
141
142        public int getLocalMiu();
143
144        public int getLocalRw();
145    }
146
147    public interface LlcpServerSocket {
148        public LlcpSocket accept() throws IOException, LlcpException;
149
150        public void close() throws IOException;
151    }
152
153    public boolean initialize();
154
155    public boolean deinitialize();
156
157    public void enableDiscovery();
158
159    public void disableDiscovery();
160
161    public int[] doGetSecureElementList();
162
163    public void doSelectSecureElement();
164
165    public void doDeselectSecureElement();
166
167    public int doGetLastError();
168
169    public LlcpServerSocket createLlcpServerSocket(int nSap, String sn, int miu,
170            int rw, int linearBufferLength) throws LlcpException;
171
172    public LlcpSocket createLlcpSocket(int sap, int miu, int rw,
173            int linearBufferLength) throws LlcpException;
174
175    public boolean doCheckLlcp();
176
177    public boolean doActivateLlcp();
178
179    public void resetTimeouts();
180
181    public boolean setTimeout(int technology, int timeout);
182
183    public int getTimeout(int technology);
184
185    public void doAbort();
186}
187