revise exported headers and cleanup headers
[platform/core/connectivity/smartcard-service.git] / server / ServerChannel.cpp
index 81d0017..daedefc 100644 (file)
@@ -1,34 +1,30 @@
 /*
-* Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-/* standard library header */
-
-/* SLP library header */
-
-/* local header */
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 #include "Debug.h"
 #include "ServerChannel.h"
 #include "APDUHelper.h"
 
 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), terminal(terminal), caller(caller),
+               privilege(true)
        {
-               this->terminal = terminal;
-               this->caller = caller;
                this->channelNum = channelNum;
        }
 
@@ -41,68 +37,74 @@ namespace smartcard_service_api
        }
 
        void ServerChannel::closeSync()
+               throw(ErrorIO &, ErrorIllegalState &)
        {
                ByteArray command, result;
                APDUHelper apdu;
                int rv;
 
-               if (isBasicChannel() == false)
+               if (isClosed() == false && isBasicChannel() == false)
                {
                        /* close channel */
                        command = apdu.generateAPDU(APDUHelper::COMMAND_CLOSE_LOGICAL_CHANNEL, channelNum, ByteArray::EMPTY);
                        rv = terminal->transmitSync(command, result);
 
-                       if (rv == 0 && result.getLength() >= 2)
+                       if (rv == 0 && result.size() >= 2)
                        {
                                ResponseHelper resp(result);
 
-                               if (resp.getStatus() == 0)
+                               if (resp.getStatus() >= 0)
                                {
-                                       SCARD_DEBUG("close success");
+                                       _DBG("close success");
                                }
                                else
                                {
-                                       SCARD_DEBUG_ERR("status word [%d][ %02X %02X ]", resp.getStatus(), resp.getSW1(), resp.getSW2());
+                                       _ERR("status word [ %02X %02X ]", resp.getSW1(), resp.getSW2());
                                }
                        }
                        else
                        {
-                               SCARD_DEBUG_ERR("select apdu is failed, rv [%d], length [%d]", rv, result.getLength());
+                               _ERR("select apdu is failed, rv [%d], length [%d]", rv, result.size());
                        }
-               }
-
-               channelNum = -1;
-       }
 
-       int ServerChannel::getChannelNumber()
-       {
-               return channelNum;
+                       channelNum = -1;
+               }
        }
 
-       int ServerChannel::transmitSync(ByteArray command, ByteArray &result)
+       int ServerChannel::transmitSync(const ByteArray &command, ByteArray &result)
+               throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
        {
+               int ret = -1;
                APDUCommand helper;
+               ByteArray cmd;
 
-               if (session != NULL) /* admin channel */
+               if (isClosed() == true)
                {
-                       helper.setCommand(command);
+                       return ret;
+               }
+
+               helper.setCommand(command);
 
-                       /* filter command */
-                       if ((helper.getINS() == APDUCommand::INS_SELECT_FILE && helper.getP1() == APDUCommand::P1_SELECT_BY_DF_NAME) ||
+               /* filter command */
+               if (privilege == false)
+               {
+                       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 */
+                               return SCARD_ERROR_SECURITY_NOT_ALLOWED;
                        }
+               }
 
-                       /* insert channel ID */
-                       helper.setChannel(0, channelNum);
+               /* TODO : insert channel ID using atr information */
+               helper.setChannel(APDUCommand::CLA_CHANNEL_STANDARD, channelNum);
+               helper.getBuffer(cmd);
 
-                       helper.getBuffer(command);
-               }
+               _DBG("command [%d] : %s", cmd.size(), cmd.toString().c_str());
 
-               SCARD_DEBUG("command [%d] : %s", command.getLength(), command.toString());
+               ret = terminal->transmitSync(cmd, result);
 
-               return terminal->transmitSync(command, result);
+               return ret;
        }
 
 } /* namespace smartcard_service_api */