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