Example usage for javax.smartcardio ResponseAPDU getSW2

List of usage examples for javax.smartcardio ResponseAPDU getSW2

Introduction

In this page you can find the example usage for javax.smartcardio ResponseAPDU getSW2.

Prototype

public int getSW2() 

Source Link

Document

Returns the value of the status byte SW2 as a value between 0 and 255.

Usage

From source file:eu.abc4trust.smartcard.HardwareSmartcard.java

private SmartcardStatusCode evaluateStatus(ResponseAPDU response) {
    switch (response.getSW1()) {
    case STATUS_OK:
        return SmartcardStatusCode.OK;
    case STATUS_FORBIDDEN:
        return SmartcardStatusCode.FORBIDDEN;
    case STATUS_TOO_LITTLE_DATA:
    case STATUS_NOT_EXACT_DATA_SIZE:
    case STATUS_TOO_SMALL_CHALLENGE:
    case STATUS_RFU:
        return SmartcardStatusCode.BAD_REQUEST;
    case STATUS_ERROR:
        switch (response.getSW2()) {
        case STATUS_BAD_PIN:
        case STATUS_BAD_PUK:
            return SmartcardStatusCode.UNAUTHORIZED;
        case STATUS_CARD_LOCKED:
        case STATUS_CARD_DEAD:
            return SmartcardStatusCode.FORBIDDEN;

        }//from  w w w. j  a v  a  2s. c  o  m
        return SmartcardStatusCode.BAD_REQUEST;
    default:
        return SmartcardStatusCode.BAD_REQUEST;
    }
}

From source file:NFC.IsmbSnepConnectionTarget.java

/**
 * Sends and receives APDUs to and from the controller
 *
 * @param instr//from ww w. j  a v a  2 s  .  c  o  m
 *            Instruction
 * @param param
 *            Payload to send
 *
 * @return The response payload 
 */
private byte[] transceive(byte instr, byte[] payload) throws IsmbSnepException {

    if (ch == null) {
        throw new IsmbSnepException("channel not open");
    }
    int payloadLength = (payload != null) ? payload.length : 0;
    byte[] instruction = { (byte) 0xd4, instr };

    //ACR122 header
    byte[] header = { (byte) 0xff, (byte) 0x00, (byte) 0x00, (byte) 0x00,
            (byte) (instruction.length + payloadLength) };

    /* construct the command */
    byte[] cmd = Util.appendToByteArray(header, instruction, 0, instruction.length);
    cmd = Util.appendToByteArray(cmd, payload);

    if (debugMode)
        Util.debugAPDUs(cmd, null);

    try {
        CommandAPDU c = new CommandAPDU(cmd);
        ResponseAPDU r = ch.transmit(c);

        byte[] ra = r.getBytes();

        if (debugMode)
            Util.debugAPDUs(null, ra);

        /* check whether APDU command was accepted by the Controller */
        if (r.getSW1() == 0x63 && r.getSW2() == 0x27) {
            throw new CardException("wrong checksum from contactless response");
        } else if (r.getSW1() == 0x63 && r.getSW2() == 0x7f) {
            throw new CardException("wrong PN53x command");
        } else if (r.getSW1() != 0x90 && r.getSW2() != 0x00) {
            throw new CardException("unknown error");
        }
        return Util.subByteArray(ra, 2, ra.length - 4);
    } catch (CardException e) {

        throw new IsmbSnepException("problem with transmitting data");
    }
}