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 
     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 
     52     public interface TagEndpoint {
     53         boolean connect(int technology);
     54         boolean reconnect();
     55         boolean disconnect();
     56 
     57         boolean presenceCheck();
     58         boolean isPresent();
     59         void startPresenceChecking(int presenceCheckDelay,
     60                                    @Nullable TagDisconnectedCallback callback);
     61 
     62         int[] getTechList();
     63         void removeTechnology(int tech); // TODO remove this one
     64         Bundle[] getTechExtras();
     65         byte[] getUid();
     66         int getHandle();
     67 
     68         byte[] transceive(byte[] data, boolean raw, int[] returnCode);
     69 
     70         boolean checkNdef(int[] out);
     71         byte[] readNdef();
     72         boolean writeNdef(byte[] data);
     73         NdefMessage findAndReadNdef();
     74         boolean formatNdef(byte[] key);
     75         boolean isNdefFormatable();
     76         boolean makeReadOnly();
     77 
     78         int getConnectedTechnology();
     79     }
     80 
     81     public interface TagDisconnectedCallback {
     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 
    104         public byte[] receive();
    105 
    106         public boolean send(byte[] data);
    107 
    108         public boolean connect();
    109 
    110         public boolean disconnect();
    111 
    112         public byte[] transceive(byte[] data);
    113 
    114         public int getHandle();
    115 
    116         public int getMode();
    117 
    118         public byte[] getGeneralBytes();
    119 
    120         public byte getLlcpVersion();
    121     }
    122 
    123     public interface LlcpSocket {
    124         public void connectToSap(int sap) throws IOException;
    125 
    126         public void connectToService(String serviceName) throws IOException;
    127 
    128         public void close() throws IOException;
    129 
    130         public void send(byte[] data) throws IOException;
    131 
    132         public int receive(byte[] recvBuff) throws IOException;
    133 
    134         public int getRemoteMiu();
    135 
    136         public int getRemoteRw();
    137 
    138         public int getLocalSap();
    139 
    140         public int getLocalMiu();
    141 
    142         public int getLocalRw();
    143     }
    144 
    145     public interface LlcpServerSocket {
    146         public LlcpSocket accept() throws IOException, LlcpException;
    147 
    148         public void close() throws IOException;
    149     }
    150 
    151     public interface LlcpConnectionlessSocket {
    152         public int getLinkMiu();
    153 
    154         public int getSap();
    155 
    156         public void send(int sap, byte[] data) throws IOException;
    157 
    158         public LlcpPacket receive() throws IOException;
    159 
    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      */
    172     public void checkFirmware();
    173 
    174     public boolean initialize();
    175 
    176     public boolean deinitialize();
    177 
    178     public String getName();
    179 
    180     public void enableDiscovery(NfcDiscoveryParameters params, boolean restart);
    181 
    182     public void disableDiscovery();
    183 
    184     public boolean sendRawFrame(byte[] data);
    185 
    186     public boolean routeAid(byte[] aid, int route);
    187 
    188     public boolean unrouteAid(byte[] aid);
    189 
    190     public boolean commitRouting();
    191 
    192     public void registerT3tIdentifier(byte[] t3tIdentifier);
    193 
    194     public void deregisterT3tIdentifier(byte[] t3tIdentifier);
    195 
    196     public void clearT3tIdentifiersCache();
    197 
    198     public int getLfT3tMax();
    199 
    200     public LlcpConnectionlessSocket createLlcpConnectionlessSocket(int nSap, String sn)
    201             throws LlcpException;
    202 
    203     public LlcpServerSocket createLlcpServerSocket(int nSap, String sn, int miu,
    204             int rw, int linearBufferLength) throws LlcpException;
    205 
    206     public LlcpSocket createLlcpSocket(int sap, int miu, int rw,
    207             int linearBufferLength) throws LlcpException;
    208 
    209     public boolean doCheckLlcp();
    210 
    211     public boolean doActivateLlcp();
    212 
    213     public void resetTimeouts();
    214 
    215     public boolean setTimeout(int technology, int timeout);
    216 
    217     public int getTimeout(int technology);
    218 
    219     public void doAbort();
    220 
    221     boolean canMakeReadOnly(int technology);
    222 
    223     int getMaxTransceiveLength(int technology);
    224 
    225     void setP2pInitiatorModes(int modes);
    226 
    227     void setP2pTargetModes(int modes);
    228 
    229     boolean getExtendedLengthApdusSupported();
    230 
    231     int getDefaultLlcpMiu();
    232 
    233     int getDefaultLlcpRwSize();
    234 
    235     String dump();
    236 
    237     boolean enableScreenOffSuspend();
    238 
    239     boolean disableScreenOffSuspend();
    240 }
    241