2 * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 /* standard library header */
19 /* SLP library header */
23 #include "ServerChannel.h"
24 #include "APDUHelper.h"
26 namespace smartcard_service_api
28 ServerChannel::ServerChannel(ServerSession *session, void *caller, int channelNum, Terminal *terminal):Channel(session)
30 this->terminal = terminal;
31 this->caller = caller;
32 this->channelNum = channelNum;
33 this->privilege = true;
36 ServerChannel::~ServerChannel()
38 if (isClosed() == false)
44 void ServerChannel::closeSync()
46 ByteArray command, result;
50 if (isBasicChannel() == false)
53 command = apdu.generateAPDU(APDUHelper::COMMAND_CLOSE_LOGICAL_CHANNEL, channelNum, ByteArray::EMPTY);
54 rv = terminal->transmitSync(command, result);
56 if (rv == 0 && result.getLength() >= 2)
58 ResponseHelper resp(result);
60 if (resp.getStatus() == 0)
62 SCARD_DEBUG("close success");
66 SCARD_DEBUG_ERR("status word [%d][ %02X %02X ]", resp.getStatus(), resp.getSW1(), resp.getSW2());
71 SCARD_DEBUG_ERR("select apdu is failed, rv [%d], length [%d]", rv, result.getLength());
78 int ServerChannel::transmitSync(ByteArray command, ByteArray &result)
82 if (isClosed() == true)
87 helper.setCommand(command);
90 if (privilege == false)
92 if ((helper.getINS() == APDUCommand::INS_SELECT_FILE && helper.getP1() == APDUCommand::P1_SELECT_BY_DF_NAME) ||
93 (helper.getINS() == APDUCommand::INS_MANAGE_CHANNEL))
95 return -4; /* security reason */
99 /* TODO : insert channel ID using atr information */
100 helper.setChannel(APDUCommand::CLA_CHANNEL_STANDARD, channelNum);
102 helper.getBuffer(command);
104 SCARD_DEBUG("command [%d] : %s", command.getLength(), command.toString());
106 return terminal->transmitSync(command, result);
109 } /* namespace smartcard_service_api */