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 onRemoteFieldActivated();
     49 
     50         public void onRemoteFieldDeactivated();
     51 
     52         public void onSeApduReceived(byte[] apdu);
     53 
     54         public void onSeEmvCardRemoval();
     55 
     56         public void onSeMifareAccess(byte[] block);
     57     }
     58 
     59     public interface TagEndpoint {
     60         boolean connect(int technology);
     61         boolean reconnect();
     62         boolean disconnect();
     63 
     64         boolean presenceCheck();
     65         boolean isPresent();
     66         void startPresenceChecking();
     67 
     68         int[] getTechList();
     69         void removeTechnology(int tech); // TODO remove this one
     70         Bundle[] getTechExtras();
     71         byte[] getUid();
     72         int getHandle();
     73 
     74         byte[] transceive(byte[] data, boolean raw, int[] returnCode);
     75 
     76         boolean checkNdef(int[] out);
     77         byte[] readNdef();
     78         boolean writeNdef(byte[] data);
     79         NdefMessage findAndReadNdef();
     80         boolean formatNdef(byte[] key);
     81         boolean isNdefFormatable();
     82         boolean makeReadOnly();
     83 
     84         int getConnectedTechnology();
     85     }
     86 
     87     public interface NfceeEndpoint {
     88         // TODO flesh out multi-EE and use this
     89     }
     90 
     91     public interface NfcDepEndpoint {
     92 
     93         /**
     94          * Peer-to-Peer Target
     95          */
     96         public static final short MODE_P2P_TARGET = 0x00;
     97         /**
     98          * Peer-to-Peer Initiator
     99          */
    100         public static final short MODE_P2P_INITIATOR = 0x01;
    101         /**
    102          * Invalid target mode
    103          */
    104         public static final short MODE_INVALID = 0xff;
    105 
    106         public byte[] receive();
    107 
    108         public boolean send(byte[] data);
    109 
    110         public boolean connect();
    111 
    112         public boolean disconnect();
    113 
    114         public byte[] transceive(byte[] data);
    115 
    116         public int getHandle();
    117 
    118         public int getMode();
    119 
    120         public byte[] getGeneralBytes();
    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()}, but the firmware may need to be updated after
    167      * 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 void enableDiscovery();
    179 
    180     public void disableDiscovery();
    181 
    182     public int[] doGetSecureElementList();
    183 
    184     public void doSelectSecureElement();
    185 
    186     public void doDeselectSecureElement();
    187 
    188     public LlcpConnectionlessSocket createLlcpConnectionlessSocket(int nSap, String sn)
    189             throws LlcpException;
    190 
    191     public LlcpServerSocket createLlcpServerSocket(int nSap, String sn, int miu,
    192             int rw, int linearBufferLength) throws LlcpException;
    193 
    194     public LlcpSocket createLlcpSocket(int sap, int miu, int rw,
    195             int linearBufferLength) throws LlcpException;
    196 
    197     public boolean doCheckLlcp();
    198 
    199     public boolean doActivateLlcp();
    200 
    201     public void resetTimeouts();
    202 
    203     public boolean setTimeout(int technology, int timeout);
    204 
    205     public int getTimeout(int technology);
    206 
    207     public void doAbort();
    208 
    209     boolean canMakeReadOnly(int technology);
    210 
    211     int getMaxTransceiveLength(int technology);
    212 
    213     void setP2pInitiatorModes(int modes);
    214 
    215     void setP2pTargetModes(int modes);
    216 
    217     boolean getExtendedLengthApdusSupported();
    218 
    219     String dump();
    220 }
    221