{
/* ResponseHelper class */
ResponseHelper::ResponseHelper()
+ : status(0)
{
}
if (response.getLength() > 2)
{
- dataField.setBuffer(response.getBuffer(), response.getLength() - 2);
+ dataField.setBuffer(response.getBuffer(),
+ response.getLength() - 2);
}
result = true;
int ResponseHelper::parseStatusWord(unsigned char *sw)
{
- int result = 0;
+ int result = sw[0] << 8 | sw[1];
switch (sw[0])
{
/* Normal processing */
case (unsigned char)0x90 : /* SW2:00, No further qualification */
- break;
-
case (unsigned char)0x91 : /* extra information */
+ case (unsigned char)0x92 : /* extra information */
+ result = 0;
break;
+#if 0
case (unsigned char)0x61 : /* SW2 encodes the number of data bytes still available */
break;
case (unsigned char)0x6F : /* SW2:00, No precise diagnosis */
result = -1;
break;
-
+#endif
default :
- result = -1;
+ result *= -1;
break;
}
{
}
- bool APDUCommand::setCommand(unsigned char cla, unsigned char ins, unsigned char p1, unsigned char p2, ByteArray commandData, unsigned int maxResponseSize)
+ bool APDUCommand::setCommand(unsigned char cla, unsigned char ins, unsigned char p1,
+ unsigned char p2, ByteArray commandData, unsigned int maxResponseSize)
{
setCLA(cla);
setINS(ins);
{
if (isExtendedLength)
{
- /* TODO */
+ unsigned int temp;
+
+ temp = command.getAt(offset) << 8;
+ temp |= command.getAt(offset + 1);
+
+ if (temp == 0)
+ setMaxResponseSize(APDUCommand::LE_MAX);
+ else
+ setMaxResponseSize(temp);
+
offset += 2;
}
else
{
- setMaxResponseSize(command.getAt(offset));
+ if (command.getAt(offset) == 0)
+ setMaxResponseSize(APDUCommand::LE_MAX);
+ else
+ setMaxResponseSize(command.getAt(offset));
+
offset += 1;
}
}
this->maxResponseSize = maxResponseSize;
}
- unsigned int APDUCommand::setMaxResponseSize()
+ unsigned int APDUCommand::getMaxResponseSize()
{
return maxResponseSize;
}
}
else
{
- if (maxResponseSize != 256)
+ if (maxResponseSize < 256)
le[0] = maxResponseSize & 0x000000FF;
le_len = 1;
switch (command)
{
case COMMAND_OPEN_LOGICAL_CHANNEL :
- apdu.setCommand(0, APDUCommand::INS_MANAGE_CHANNEL, 0, 0, ByteArray::EMPTY, 1);
+ apdu.setCommand(0, APDUCommand::INS_MANAGE_CHANNEL, 0, 0, ByteArray::EMPTY, APDUCommand::LE_MAX);
apdu.getBuffer(result);
break;
ByteArray dataField;
static int parseStatusWord(unsigned char *sw);
+
public:
+ static const int SUCCESS = 0;
+
+ static const int ERROR_UNKNOWN = -1;
+
+ static const int ERROR_NO_INFORMATION = -(0x6900);
+ static const int ERROR_COMMAND_INCOMPATIBLE = -(0x6981);
+ static const int ERROR_SECURITY_NOT_SATISFIED = -(0x6982);
+ static const int ERROR_AUTH_PIN_BLOCKED = -(0x6983);
+ static const int ERROR_REF_DATA_INVALID = -(0x6984);
+ static const int ERROR_CONDITION_NOT_SATIFIED = -(0x6985);
+ static const int ERROR_COMMAND_NOT_ALLOW = -(0x6986);
+
+ static const int ERROR_INCORRECT_PARAMETER = -(0x6a80);
+ static const int ERROR_FUNCTION_NOT_SUPPORT = -(0x6a81);
+ static const int ERROR_FILE_NOT_FOUND = -(0x6a82);
+ static const int ERROR_RECORD_NOT_FOUND = -(0x6a83);
+ static const int ERROR_NOT_ENOUGH_MEMORY = -(0x6a84);
+ static const int ERROR_INCORRECT_P1_P2 = -(0x6a86);
+ static const int ERROR_LC_INCONSISTENT = -(0x6a87);
+ static const int ERROR_REF_DATA_NOT_FOUND = -(0x6a88);
+
ResponseHelper();
ResponseHelper(const ByteArray &response);
~ResponseHelper();
static const unsigned char CLA_CHANNEL_STANDARD = (unsigned char)0x00;
static const unsigned char CLA_CHANNEL_EXTENDED = (unsigned char)0x01;
+ static const unsigned int LE_MAX = -1;
+
APDUCommand();
~APDUCommand();
- bool setCommand(unsigned char cla, unsigned char ins, unsigned char p1, unsigned char p2, ByteArray commandData, unsigned int maxResponseSize);
+ bool setCommand(unsigned char cla, unsigned char ins, unsigned char p1,
+ unsigned char p2, ByteArray commandData, unsigned int maxResponseSize);
bool setCommand(const ByteArray &command);
bool setChannel(int type, int channelNum);
ByteArray getCommandData();
void setMaxResponseSize(unsigned int maxResponseSize);
- unsigned int setMaxResponseSize();
+ unsigned int getMaxResponseSize();
bool getBuffer(ByteArray &array);
};