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;
35 ServerChannel::~ServerChannel()
37 if (isClosed() == false)
43 void ServerChannel::closeSync()
45 ByteArray command, result;
49 if (isBasicChannel() == false)
52 command = apdu.generateAPDU(APDUHelper::COMMAND_CLOSE_LOGICAL_CHANNEL, channelNum, ByteArray::EMPTY);
53 rv = terminal->transmitSync(command, result);
55 if (rv == 0 && result.getLength() >= 2)
57 ResponseHelper resp(result);
59 if (resp.getStatus() == 0)
61 SCARD_DEBUG("close success");
65 SCARD_DEBUG_ERR("status word [%d][ 0x%02X 0x%02X ]", resp.getStatus(), result[result.getLength() - 2], result[result.getLength() - 1]);
70 SCARD_DEBUG_ERR("select apdu is failed, rv [%d], length [%d]", rv, result.getLength());
77 int ServerChannel::getChannelNumber()
82 int ServerChannel::transmitSync(ByteArray command, ByteArray &result)
86 if (session != NULL) /* admin channel */
88 helper.setCommand(command);
91 if ((helper.getINS() == APDUCommand::INS_SELECT_FILE && helper.getP1() == APDUCommand::P1_SELECT_BY_DF_NAME) ||
92 (helper.getINS() == APDUCommand::INS_MANAGE_CHANNEL))
94 return -4; /* security reason */
97 /* insert channel ID */
98 helper.setChannel(0, channelNum);
100 helper.getBuffer(command);
103 SCARD_DEBUG("command [%d] : %s", command.getLength(), command.toString());
105 return terminal->transmitSync(command, result);
108 } /* namespace smartcard_service_api */