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     /**
    152      * Called at boot if NFC is disabled to give the device host an opportunity
    153      * to check the firmware version to see if it needs updating. Normally the firmware version
    154      * is checked during {@link #initialize()}, but the firmware may need to be updated after
    155      * an OTA update.
    156      *
    157      * <p>This is called from a thread
    158      * that may block for long periods of time during the update process.
    159      */
    160     public void checkFirmware();
    161 
    162     public boolean initialize();
    163 
    164     public boolean deinitialize();
    165 
    166     public void enableDiscovery();
    167 
    168     public void disableDiscovery();
    169 
    170     public int[] doGetSecureElementList();
    171 
    172     public void doSelectSecureElement();
    173 
    174     public void doDeselectSecureElement();
    175 
    176     public int doGetLastError();
    177 
    178     public LlcpServerSocket createLlcpServerSocket(int nSap, String sn, int miu,
    179             int rw, int linearBufferLength) throws LlcpException;
    180 
    181     public LlcpSocket createLlcpSocket(int sap, int miu, int rw,
    182             int linearBufferLength) throws LlcpException;
    183 
    184     public boolean doCheckLlcp();
    185 
    186     public boolean doActivateLlcp();
    187 
    188     public void resetTimeouts();
    189 
    190     public boolean setTimeout(int technology, int timeout);
    191 
    192     public int getTimeout(int technology);
    193 
    194     public void doAbort();
    195 
    196     boolean canMakeReadOnly(int technology);
    197 
    198     int getMaxTransceiveLength(int technology);
    199 
    200     String dump();
    201 }
    202