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)
32 this->terminal = terminal;
33 this->caller = caller;
34 this->channelNum = channelNum;
35 this->privilege = true;
38 ServerChannel::~ServerChannel()
40 if (isClosed() == false)
46 void ServerChannel::closeSync()
47 throw(ErrorIO &, ErrorIllegalState &)
49 ByteArray command, result;
53 if (isBasicChannel() == false)
56 command = apdu.generateAPDU(APDUHelper::COMMAND_CLOSE_LOGICAL_CHANNEL, channelNum, ByteArray::EMPTY);
57 rv = terminal->transmitSync(command, result);
59 if (rv == 0 && result.getLength() >= 2)
61 ResponseHelper resp(result);
63 if (resp.getStatus() == 0)
65 _DBG("close success");
69 _ERR("status word [%d][ %02X %02X ]", resp.getStatus(), resp.getSW1(), resp.getSW2());
74 _ERR("select apdu is failed, rv [%d], length [%d]", rv, result.getLength());
81 int ServerChannel::transmitSync(ByteArray command, ByteArray &result)
82 throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
87 if (isClosed() == true)
92 helper.setCommand(command);
95 if (privilege == false)
97 if ((helper.getINS() == APDUCommand::INS_SELECT_FILE &&
98 helper.getP1() == APDUCommand::P1_SELECT_BY_DF_NAME) ||
99 (helper.getINS() == APDUCommand::INS_MANAGE_CHANNEL))
101 return -4; /* security reason */
105 /* TODO : insert channel ID using atr information */
106 helper.setChannel(APDUCommand::CLA_CHANNEL_STANDARD, channelNum);
107 helper.getBuffer(command);
109 _DBG("command [%d] : %s", command.getLength(), command.toString());
111 ret = terminal->transmitSync(command, result);
116 } /* namespace smartcard_service_api */