/****************************************************************************
 * Copyright (C) 2012 HS Coburg.
 * All rights reserved.
 * Contact: ecsec GmbH (info@ecsec.de)
 *
 * This file is part of the Open eCard App.
 *
 * GNU General Public License Usage
 * This file may be used under the terms of the GNU General Public
 * License version 3.0 as published by the Free Software Foundation
 * and appearing in the file LICENSE.GPL included in the packaging of
 * this file. Please review the following information to ensure the
 * GNU General Public License version 3.0 requirements will be met:
 * http://www.gnu.org/copyleft/gpl.html.
 *
 * Other Usage
 * Alternatively, this file may be used in accordance with the terms
 * and conditions contained in a signed written agreement between
 * you and ecsec GmbH.
 *
 ***************************************************************************/

package org.openecard.scio;

import android.nfc.tech.IsoDep;
import java.io.IOException;
import org.openecard.common.ifd.scio.SCIOATR;
import org.openecard.common.ifd.scio.SCIOCard;
import org.openecard.common.ifd.scio.SCIOChannel;
import org.openecard.common.ifd.scio.SCIOErrorCode;
import org.openecard.common.ifd.scio.SCIOException;
import org.openecard.common.ifd.scio.SCIOProtocol;
import org.openecard.common.ifd.scio.SCIOTerminal;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * NFC implementation of SCIO API card interface.
 *
 * @author Dirk Petrautzki
 */
public class NFCCard implements SCIOCard {

    private static final Logger logger = LoggerFactory.getLogger(NFCCard.class);
    private final NFCCardChannel nfcCardChannel = new NFCCardChannel(this);
    protected IsoDep isodep;
    
    NFCCard(IsoDep tag) {
	isodep = tag;
    }

    @Override
    public void beginExclusive() throws SCIOException {
	logger.warn("beginExclusive not supported");
    }

    @Override
    public void endExclusive() throws SCIOException {
	logger.warn("endExclusive not supported");
    }

    @Override
    public void disconnect(boolean arg0) throws SCIOException {
	try {
	    isodep.close();
	} catch (IOException e) {
	    // TODO: check if the error code can be chosen more specifically
	    throw new SCIOException("Disconnect failed", SCIOErrorCode.SCARD_F_UNKNOWN_ERROR, e);
	}
    }

    @Override
    public SCIOATR getATR() {
	logger.warn("getATR not supported");
	// for now there is no way to get the ATR in android nfc api
	return new SCIOATR(new byte[0]);
    }

    @Override
    public SCIOChannel getBasicChannel() {
	return this.nfcCardChannel;
    }

    @Override
    public SCIOProtocol getProtocol() {
	logger.warn("getProtocol not supported");
	// for now theres no way to get the used protocol in android nfc api
        return null;
    }

    @Override
    public SCIOChannel openLogicalChannel() throws SCIOException {
	return nfcCardChannel;
    }

    @Override
    public byte[] transmitControlCommand(int arg0, byte[] arg1) throws SCIOException {
	logger.warn("transmitControlCommand not supported");
	return new byte[0];
    }

    @Override
    public SCIOTerminal getTerminal() {
        return null;
    }
}

@@ -92,16 +92,21 @@
 (C) 2012
+-2017
  HS Cobu
@@ -109,16 +109,16 @@
 Coburg.%0A
-
  * All r
@@ -1559,22 +1559,19 @@
  Logger 
-logger
+LOG
  = Logge
@@ -1830,30 +1830,27 @@
 xception %7B%0A%09
-logger
+LOG
 .warn(%22begin
@@ -1948,30 +1948,27 @@
 xception %7B%0A%09
-logger
+LOG
 .warn(%22endEx
@@ -2344,30 +2344,27 @@
 getATR() %7B%0A%09
-logger
+LOG
 .warn(%22getAT
@@ -2637,139 +2637,61 @@
  %7B%0A%09
-logger.warn(%22getProtocol not supported%22);%0A%09// for now theres no way to get the used protocol in android nfc api%0A        return null
+// NFC is contactless%0A        return SCIOProtocol.TCL
 ;%0A  
@@ -2913,14 +2913,11 @@
  %7B%0A%09
-logger
+LOG
 .war
@@ -3062,16 +3062,17 @@
 n null;%0A
-
     %7D%0A
+%0A
 %7D%0A

Return TCL protocol in case of NFC