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