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.
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,
29 int channelNum, Terminal *terminal) :
30 Channel(session), terminal(terminal), caller(caller),
33 this->channelNum = channelNum;
36 ServerChannel::~ServerChannel()
38 if (isClosed() == false)
44 void ServerChannel::closeSync()
45 throw(ErrorIO &, ErrorIllegalState &)
47 ByteArray command, result;
51 if (isClosed() == false && isBasicChannel() == false)
54 command = apdu.generateAPDU(APDUHelper::COMMAND_CLOSE_LOGICAL_CHANNEL, channelNum, ByteArray::EMPTY);
55 rv = terminal->transmitSync(command, result);
57 if (rv == 0 && result.size() >= 2)
59 ResponseHelper resp(result);
61 if (resp.getStatus() >= 0)
63 _DBG("close success");
67 _ERR("status word [ %02X %02X ]", resp.getSW1(), resp.getSW2());
72 _ERR("select apdu is failed, rv [%d], length [%d]", rv, result.size());
79 int ServerChannel::transmitSync(const ByteArray &command, ByteArray &result)
80 throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
86 if (isClosed() == true)
91 helper.setCommand(command);
94 if (privilege == false)
96 if ((helper.getINS() == APDUCommand::INS_SELECT_FILE &&
97 helper.getP1() == APDUCommand::P1_SELECT_BY_DF_NAME) ||
98 (helper.getINS() == APDUCommand::INS_MANAGE_CHANNEL))
100 return SCARD_ERROR_SECURITY_NOT_ALLOWED;
104 /* TODO : insert channel ID using atr information */
105 helper.setChannel(APDUCommand::CLA_CHANNEL_STANDARD, channelNum);
106 helper.getBuffer(cmd);
108 _DBG("command [%d] : %s", cmd.size(), cmd.toString().c_str());
110 ret = terminal->transmitSync(cmd, result);
115 } /* namespace smartcard_service_api */