2 * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
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.
18 #include "ServerChannel.h"
19 #include "APDUHelper.h"
21 namespace smartcard_service_api
23 ServerChannel::ServerChannel(ServerSession *session, void *caller,
24 int channelNum, Terminal *terminal) :
25 Channel(session), terminal(terminal), caller(caller),
28 this->channelNum = channelNum;
31 ServerChannel::~ServerChannel()
33 if (isClosed() == false)
39 void ServerChannel::closeSync()
40 throw(ErrorIO &, ErrorIllegalState &)
42 ByteArray command, result;
46 if (isClosed() == false && isBasicChannel() == false)
49 command = apdu.generateAPDU(APDUHelper::COMMAND_CLOSE_LOGICAL_CHANNEL, channelNum, ByteArray::EMPTY);
50 rv = terminal->transmitSync(command, result);
52 if (rv == 0 && result.size() >= 2)
54 ResponseHelper resp(result);
56 if (resp.getStatus() >= 0)
58 _DBG("close success");
62 _ERR("status word [ %02X %02X ]", resp.getSW1(), resp.getSW2());
67 _ERR("select apdu is failed, rv [%d], length [%d]", rv, result.size());
74 int ServerChannel::transmitSync(const ByteArray &command, ByteArray &result)
75 throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
81 if (isClosed() == true)
86 helper.setCommand(command);
89 if (privilege == false)
91 if ((helper.getINS() == APDUCommand::INS_SELECT_FILE &&
92 helper.getP1() == APDUCommand::P1_SELECT_BY_DF_NAME) ||
93 (helper.getINS() == APDUCommand::INS_MANAGE_CHANNEL))
95 return SCARD_ERROR_SECURITY_NOT_ALLOWED;
99 /* TODO : insert channel ID using atr information */
100 helper.setChannel(APDUCommand::CLA_CHANNEL_STANDARD, channelNum);
101 helper.getBuffer(cmd);
103 _DBG("command [%d] : %s", cmd.size(), cmd.toString().c_str());
105 ret = terminal->transmitSync(cmd, result);
110 } /* namespace smartcard_service_api */