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 */
21 /* SLP library header */
25 #include "ServerSession.h"
26 #include "ServerReader.h"
27 #include "ServerChannel.h"
28 #include "APDUHelper.h"
31 namespace smartcard_service_api
33 ServerSession::ServerSession(ServerReader *reader,
34 const vector<ByteArray> &certHashes,
35 void *caller, Terminal *terminal) : SessionHelper(reader)
37 this->terminal = NULL;
41 _ERR("invalid param");
46 this->terminal = terminal;
47 this->certHashes = certHashes;
50 ServerSession::~ServerSession()
52 if (isClosed() == false)
56 const ByteArray ServerSession::getATRSync()
57 throw(ErrorIO &, ErrorIllegalState &)
59 /* call get atr to terminal */
61 if (terminal != NULL) {
62 if (terminal->open() == true) {
63 int error = terminal->getATRSync(atr);
65 if (error < SCARD_ERROR_OK) {
66 _ERR("getATRSync failed, [%d]", error);
71 _ERR("terminal->open failed");
74 _ERR("terminal is null.");
81 void ServerSession::closeSync()
82 throw(ErrorIO &, ErrorIllegalState &)
84 if (isClosed() == false)
91 void ServerSession::closeChannels()
92 throw(ErrorIO &, ErrorIllegalState &)
96 for (i = 0; i < channels.size(); i++)
98 if (channels[i] != NULL)
99 channels[i]->closeSync();
105 Channel *ServerSession::openBasicChannelSync(const ByteArray &aid)
106 throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
108 return openBasicChannelSync(aid, NULL);
111 Channel *ServerSession::openBasicChannelSync(const ByteArray &aid, void *caller)
112 throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
114 ServerChannel *channel = NULL;
118 Channel *ServerSession::openBasicChannelSync(const unsigned char *aid, unsigned int length)
119 throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
121 ByteArray temp(aid, length);
123 return openBasicChannelSync(temp);
126 Channel *ServerSession::openBasicChannelSync(const unsigned char *aid, unsigned int length, void *caller)
127 throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
129 ByteArray temp(aid, length);
131 return openBasicChannelSync(temp, caller);
134 Channel *ServerSession::openLogicalChannelSync(const ByteArray &aid)
135 throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
137 return openLogicalChannelSync(aid, NULL);
140 Channel *ServerSession::openLogicalChannelSync(const ByteArray &aid, void *caller)
141 throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
143 ServerChannel *channel = NULL;
147 Channel *ServerSession::openLogicalChannelSync(const unsigned char *aid, unsigned int length)
148 throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
150 ByteArray temp(aid, length);
152 return openLogicalChannelSync(temp, NULL);
155 Channel *ServerSession::openLogicalChannelSync(const unsigned char *aid, unsigned int length, void *caller)
156 throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
158 ByteArray temp(aid, length);
160 return openLogicalChannelSync(temp, caller);
163 } /* namespace smartcard_service_api */