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();
     32         public void onHostCardEmulationData(byte[] data);
     33         public void onHostCardEmulationDeactivated();
     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 
    121     public interface LlcpSocket {
    122         public void connectToSap(int sap) throws IOException;
    123 
    124         public void connectToService(String serviceName) throws IOException;
    125 
    126         public void close() throws IOException;
    127 
    128         public void send(byte[] data) throws IOException;
    129 
    130         public int receive(byte[] recvBuff) throws IOException;
    131 
    132         public int getRemoteMiu();
    133 
    134         public int getRemoteRw();
    135 
    136         public int getLocalSap();
    137 
    138         public int getLocalMiu();
    139 
    140         public int getLocalRw();
    141     }
    142 
    143     public interface LlcpServerSocket {
    144         public LlcpSocket accept() throws IOException, LlcpException;
    145 
    146         public void close() throws IOException;
    147     }
    148 
    149     public interface LlcpConnectionlessSocket {
    150         public int getLinkMiu();
    151 
    152         public int getSap();
    153 
    154         public void send(int sap, byte[] data) throws IOException;
    155 
    156         public LlcpPacket receive() throws IOException;
    157 
    158         public void close() throws IOException;
    159     }
    160 
    161     /**
    162      * Called at boot if NFC is disabled to give the device host an opportunity
    163      * to check the firmware version to see if it needs updating. Normally the firmware version
    164      * is checked during {@link #initialize(boolean enableScreenOffSuspend)},
    165      * but the firmware may need to be updated after an OTA update.
    166      *
    167      * <p>This is called from a thread
    168      * that may block for long periods of time during the update process.
    169      */
    170     public void checkFirmware();
    171 
    172     public boolean initialize();
    173 
    174     public boolean deinitialize();
    175 
    176     public String getName();
    177 
    178     public void enableDiscovery(NfcDiscoveryParameters params, boolean restart);
    179 
    180     public void disableDiscovery();
    181 
    182     public boolean sendRawFrame(byte[] data);
    183 
    184     public boolean routeAid(byte[] aid, int route);
    185 
    186     public boolean unrouteAid(byte[] aid);
    187 
    188     public boolean commitRouting();
    189 
    190     public LlcpConnectionlessSocket createLlcpConnectionlessSocket(int nSap, String sn)
    191             throws LlcpException;
    192 
    193     public LlcpServerSocket createLlcpServerSocket(int nSap, String sn, int miu,
    194             int rw, int linearBufferLength) throws LlcpException;
    195 
    196     public LlcpSocket createLlcpSocket(int sap, int miu, int rw,
    197             int linearBufferLength) throws LlcpException;
    198 
    199     public boolean doCheckLlcp();
    200 
    201     public boolean doActivateLlcp();
    202 
    203     public void resetTimeouts();
    204 
    205     public boolean setTimeout(int technology, int timeout);
    206 
    207     public int getTimeout(int technology);
    208 
    209     public void doAbort();
    210 
    211     boolean canMakeReadOnly(int technology);
    212 
    213     int getMaxTransceiveLength(int technology);
    214 
    215     void setP2pInitiatorModes(int modes);
    216 
    217     void setP2pTargetModes(int modes);
    218 
    219     boolean getExtendedLengthApdusSupported();
    220 
    221     int getDefaultLlcpMiu();
    222 
    223     int getDefaultLlcpRwSize();
    224 
    225     String dump();
    226 
    227     boolean enableScreenOffSuspend();
    228 
    229     boolean disableScreenOffSuspend();
    230 }
    231