revise exported headers and cleanup headers
[platform/core/connectivity/smartcard-service.git] / server / ServerChannel.cpp
index 1d896d1..daedefc 100644 (file)
  * limitations under the License.
  */
 
-/* standard library header */
-
-/* SLP library header */
-
-/* local header */
 #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)
+               int channelNum, Terminal *terminal) :
+               Channel(session), terminal(terminal), caller(caller),
+               privilege(true)
        {
-               this->terminal = terminal;
-               this->caller = caller;
                this->channelNum = channelNum;
-               this->privilege = true;
        }
 
        ServerChannel::~ServerChannel()
@@ -50,39 +43,40 @@ namespace smartcard_service_api
                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)
                                {
                                        _DBG("close success");
                                }
                                else
                                {
-                                       _ERR("status word [%d][ %02X %02X ]", resp.getStatus(), resp.getSW1(), resp.getSW2());
+                                       _ERR("status word [ %02X %02X ]", resp.getSW1(), resp.getSW2());
                                }
                        }
                        else
                        {
-                               _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;
+                       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 (isClosed() == true)
                {
@@ -98,17 +92,17 @@ namespace smartcard_service_api
                                helper.getP1() == APDUCommand::P1_SELECT_BY_DF_NAME) ||
                                (helper.getINS() == APDUCommand::INS_MANAGE_CHANNEL))
                        {
-                               return -4; /* security reason */
+                               return SCARD_ERROR_SECURITY_NOT_ALLOWED;
                        }
                }
 
                /* TODO : insert channel ID using atr information */
                helper.setChannel(APDUCommand::CLA_CHANNEL_STANDARD, channelNum);
-               helper.getBuffer(command);
+               helper.getBuffer(cmd);
 
-               _DBG("command [%d] : %s", command.getLength(), command.toString());
+               _DBG("command [%d] : %s", cmd.size(), cmd.toString().c_str());
 
-               ret = terminal->transmitSync(command, result);
+               ret = terminal->transmitSync(cmd, result);
 
                return ret;
        }