Example #1
0
    def __init__(self, handle, protocol):
        self._handle = handle
        self._protocol = protocol

        command = [0x00, 0xA4, 0x04, 0x00]
        command.append(len(self.CARD_AID))
        command.extend(self.CARD_AID)
        command.append(0x00)
        scard.SCardTransmit(handle, protocol, command)
Example #2
0
    def select_path(self, path):
        """Select path on card"""
        request = CardCommand.SELECT_PATH[:]
        request.append(len(path))
        request.extend(path)
        request.append(0x01)

        # transmit command to card
        result, response = scard.SCardTransmit(self._handle, self._protocol,
                                               request)

        # raise error if needed
        if result != scard.SCARD_S_SUCCESS:
            # failed selecting path
            message = scard.SCardGetErrorMessage(result)
            raise SelectPathError('Error selecting path: {0}'.format(message))

        return response
Example #3
0
    def get_data(self, command):
        """Get data from card"""
        data = None

        # get data from card
        result, response = scard.SCardTransmit(self._handle, self._protocol,
                                               command)

        # raise error if needed
        if result != scard.SCARD_S_SUCCESS:
            # failed reading data from card
            message = scard.SCardGetErrorMessage(result)
            raise GetDataError('Error reading card: {0}'.format(message))

        else:
            data = response

        return data[:-2]
def transmit(hcard, proto_hdr, bytes_):
    rv, resp = sc.SCardTransmit(hcard, proto_hdr, bytes_)
    if rv != 0:
        raise NFCException(rv)
    return resp