Modify APDU classes
authorWonkyu Kwon <wonkyu.kwon@samsung.com>
Fri, 15 Feb 2013 04:25:06 +0000 (13:25 +0900)
committerWonkyu Kwon <wonkyu.kwon@samsung.com>
Mon, 18 Feb 2013 02:02:27 +0000 (11:02 +0900)
 - define status clauses and values
 - fix calculating max. response length
 - return status word when is called 'getStatus'
   function.

Change-Id: Id814af2b1e12266a2dfc8fd855e1cb41ed300d80

common/APDUHelper.cpp
common/include/APDUHelper.h

index 9fe5686..f94bfdd 100644 (file)
@@ -28,6 +28,7 @@ namespace smartcard_service_api
 {
        /* ResponseHelper class */
        ResponseHelper::ResponseHelper()
+               : status(0)
        {
        }
 
@@ -57,7 +58,8 @@ namespace smartcard_service_api
 
                        if (response.getLength() > 2)
                        {
-                               dataField.setBuffer(response.getBuffer(), response.getLength() - 2);
+                               dataField.setBuffer(response.getBuffer(),
+                                       response.getLength() - 2);
                        }
 
                        result = true;
@@ -68,17 +70,18 @@ namespace smartcard_service_api
 
        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;
 
@@ -138,9 +141,9 @@ namespace smartcard_service_api
                case (unsigned char)0x6F : /* SW2:00, No precise diagnosis */
                        result = -1;
                        break;
-
+#endif
                default :
-                       result = -1;
+                       result *= -1;
                        break;
                }
 
@@ -203,7 +206,8 @@ namespace smartcard_service_api
        {
        }
 
-       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);
@@ -258,12 +262,25 @@ namespace smartcard_service_api
                {
                        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;
                        }
                }
@@ -403,7 +420,7 @@ namespace smartcard_service_api
                this->maxResponseSize = maxResponseSize;
        }
 
-       unsigned int APDUCommand::setMaxResponseSize()
+       unsigned int APDUCommand::getMaxResponseSize()
        {
                return maxResponseSize;
        }
@@ -463,7 +480,7 @@ namespace smartcard_service_api
                        }
                        else
                        {
-                               if (maxResponseSize != 256)
+                               if (maxResponseSize < 256)
                                        le[0] = maxResponseSize & 0x000000FF;
 
                                le_len = 1;
@@ -512,7 +529,7 @@ namespace smartcard_service_api
                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;
 
index 6a591d3..0f24ac8 100644 (file)
@@ -35,7 +35,29 @@ namespace smartcard_service_api
                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();
@@ -117,10 +139,13 @@ namespace smartcard_service_api
                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);
@@ -141,7 +166,7 @@ namespace smartcard_service_api
                ByteArray getCommandData();
 
                void setMaxResponseSize(unsigned int maxResponseSize);
-               unsigned int setMaxResponseSize();
+               unsigned int getMaxResponseSize();
 
                bool getBuffer(ByteArray &array);
        };