Store select response in channel instance
authorWonkyu Kwon <wonkyu.kwon@samsung.com>
Fri, 15 Feb 2013 04:14:47 +0000 (13:14 +0900)
committerWonkyu Kwon <wonkyu.kwon@samsung.com>
Mon, 18 Feb 2013 02:02:00 +0000 (11:02 +0900)
Change-Id: I625a09a0f69d52dff37f5dc9c7dff2729b6f12f6

client/ClientChannel.cpp
common/include/Channel.h
server/ServerChannel.cpp
server/ServerResource.cpp

index b5b69a0..b74ba0f 100644 (file)
@@ -27,6 +27,7 @@
 #include "ClientIPC.h"
 #include "ClientChannel.h"
 #include "ReaderHelper.h"
+#include "APDUHelper.h"
 
 #ifndef EXTERN_API
 #define EXTERN_API __attribute__((visibility("default")))
@@ -36,7 +37,7 @@ namespace smartcard_service_api
 {
        ClientChannel::ClientChannel(void *context, Session *session,
                int channelNum, ByteArray selectResponse, void *handle)
-               :Channel(session)
+               : Channel(session)
        {
                this->channelNum = -1;
                this->handle = NULL;
@@ -259,6 +260,14 @@ namespace smartcard_service_api
                                /* transmit result */
                                SCARD_DEBUG("MSG_REQUEST_TRANSMIT");
 
+                               if (msg->error == 0 &&
+                                       ResponseHelper::getStatus(msg->data) == 0)
+                               {
+                                       /* store select response */
+                                       if (msg->data.getAt(1) == APDUCommand::INS_SELECT_FILE)
+                                               channel->setSelectResponse(msg->data);
+                               }
+
                                if (msg->isSynchronousCall() == true) /* synchronized call */
                                {
                                        /* sync call */
index 3df4ad2..a6a5dc9 100644 (file)
@@ -30,7 +30,8 @@ namespace smartcard_service_api
 {
        class SessionHelper;    /* explicit declaration */
 
-       typedef void (*transmitCallback)(unsigned char *buffer, unsigned int length, int error, void *userParam);
+       typedef void (*transmitCallback)(unsigned char *buffer, unsigned int length,
+               int error, void *userParam);
        typedef void (*closeCallback)(int error, void *userParam);
 
        class Channel : public Synchronous
@@ -43,6 +44,8 @@ namespace smartcard_service_api
                Channel() : Synchronous() { channelNum = -1; }
                Channel(SessionHelper *session) : Synchronous() { this->session = session; }
 
+               inline void setSelectResponse(ByteArray &response) { selectResponse = response; }
+
        public :
                virtual ~Channel() {};
 
index f4dab33..d0f880a 100644 (file)
@@ -25,7 +25,9 @@
 
 namespace smartcard_service_api
 {
-       ServerChannel::ServerChannel(ServerSession *session, void *caller, int channelNum, Terminal *terminal):Channel(session)
+       ServerChannel::ServerChannel(ServerSession *session, void *caller,
+               int channelNum, Terminal *terminal)
+               : Channel(session)
        {
                this->terminal = terminal;
                this->caller = caller;
@@ -41,7 +43,8 @@ namespace smartcard_service_api
                }
        }
 
-       void ServerChannel::closeSync() throw(ErrorIO &, ErrorIllegalState &)
+       void ServerChannel::closeSync()
+               throw(ErrorIO &, ErrorIllegalState &)
        {
                ByteArray command, result;
                APDUHelper apdu;
@@ -75,13 +78,15 @@ namespace smartcard_service_api
                channelNum = -1;
        }
 
-       int ServerChannel::transmitSync(ByteArray command, ByteArray &result) throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
+       int ServerChannel::transmitSync(ByteArray command, ByteArray &result)
+               throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
        {
+               int ret = -1;
                APDUCommand helper;
 
                if (isClosed() == true)
                {
-                       return -1;
+                       return ret;
                }
 
                helper.setCommand(command);
@@ -89,7 +94,8 @@ namespace smartcard_service_api
                /* filter command */
                if (privilege == false)
                {
-                       if ((helper.getINS() == APDUCommand::INS_SELECT_FILE && helper.getP1() == APDUCommand::P1_SELECT_BY_DF_NAME) ||
+                       if ((helper.getINS() == APDUCommand::INS_SELECT_FILE &&
+                               helper.getP1() == APDUCommand::P1_SELECT_BY_DF_NAME) ||
                                (helper.getINS() == APDUCommand::INS_MANAGE_CHANNEL))
                        {
                                return -4; /* security reason */
@@ -103,7 +109,15 @@ namespace smartcard_service_api
 
                SCARD_DEBUG("command [%d] : %s", command.getLength(), command.toString());
 
-               return terminal->transmitSync(command, result);
+               ret = terminal->transmitSync(command, result);
+               if (ret == 0 && ResponseHelper::getStatus(result) == 0)
+               {
+                       /* store select response */
+                       if (helper.getINS() == APDUCommand::INS_SELECT_FILE)
+                               setSelectResponse(result);
+               }
+
+               return ret;
        }
 
 } /* namespace smartcard_service_api */
index 7cc61dc..adae5c5 100644 (file)
@@ -577,7 +577,7 @@ namespace smartcard_service_api
                        channelNum = _openLogicalChannel(terminal);
                        if (channelNum > 0)
                        {
-                               SCARD_DEBUG("channelNum [%d]", result);
+                               SCARD_DEBUG("channelNum [%d]", channelNum);
                        }
                        else
                        {
@@ -619,7 +619,6 @@ namespace smartcard_service_api
 
                                if (resp.getStatus() == 0)
                                {
-                                       channel->selectResponse = response;
                                        /* remove privilege mode */
                                        channel->unsetPrivilegeMode();
                                }
@@ -641,7 +640,6 @@ namespace smartcard_service_api
                        result = IntegerHandle::INVALID_HANDLE;
                }
 
-
                return result;
        }
 #endif