#include "ClientIPC.h"
#include "ClientChannel.h"
#include "ReaderHelper.h"
+#include "APDUHelper.h"
#ifndef EXTERN_API
#define EXTERN_API __attribute__((visibility("default")))
{
ClientChannel::ClientChannel(void *context, Session *session,
int channelNum, ByteArray selectResponse, void *handle)
- :Channel(session)
+ : Channel(session)
{
this->channelNum = -1;
this->handle = NULL;
/* transmit result */
SCARD_DEBUG("MSG_REQUEST_TRANSMIT");
+ if (msg->error == 0 &&
+ ResponseHelper::getStatus(msg->data) == 0)
+ {
+ /* store select response */
+ if (msg->data.getAt(1) == APDUCommand::INS_SELECT_FILE)
+ channel->setSelectResponse(msg->data);
+ }
+
if (msg->isSynchronousCall() == true) /* synchronized call */
{
/* sync call */
{
class SessionHelper; /* explicit declaration */
- typedef void (*transmitCallback)(unsigned char *buffer, unsigned int length, int error, void *userParam);
+ typedef void (*transmitCallback)(unsigned char *buffer, unsigned int length,
+ int error, void *userParam);
typedef void (*closeCallback)(int error, void *userParam);
class Channel : public Synchronous
Channel() : Synchronous() { channelNum = -1; }
Channel(SessionHelper *session) : Synchronous() { this->session = session; }
+ inline void setSelectResponse(ByteArray &response) { selectResponse = response; }
+
public :
virtual ~Channel() {};
namespace smartcard_service_api
{
- ServerChannel::ServerChannel(ServerSession *session, void *caller, int channelNum, Terminal *terminal):Channel(session)
+ ServerChannel::ServerChannel(ServerSession *session, void *caller,
+ int channelNum, Terminal *terminal)
+ : Channel(session)
{
this->terminal = terminal;
this->caller = caller;
}
}
- void ServerChannel::closeSync() throw(ErrorIO &, ErrorIllegalState &)
+ void ServerChannel::closeSync()
+ throw(ErrorIO &, ErrorIllegalState &)
{
ByteArray command, result;
APDUHelper apdu;
channelNum = -1;
}
- int ServerChannel::transmitSync(ByteArray command, ByteArray &result) throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
+ int ServerChannel::transmitSync(ByteArray command, ByteArray &result)
+ throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
{
+ int ret = -1;
APDUCommand helper;
if (isClosed() == true)
{
- return -1;
+ return ret;
}
helper.setCommand(command);
/* filter command */
if (privilege == false)
{
- if ((helper.getINS() == APDUCommand::INS_SELECT_FILE && helper.getP1() == APDUCommand::P1_SELECT_BY_DF_NAME) ||
+ if ((helper.getINS() == APDUCommand::INS_SELECT_FILE &&
+ helper.getP1() == APDUCommand::P1_SELECT_BY_DF_NAME) ||
(helper.getINS() == APDUCommand::INS_MANAGE_CHANNEL))
{
return -4; /* security reason */
SCARD_DEBUG("command [%d] : %s", command.getLength(), command.toString());
- return terminal->transmitSync(command, result);
+ ret = terminal->transmitSync(command, result);
+ if (ret == 0 && ResponseHelper::getStatus(result) == 0)
+ {
+ /* store select response */
+ if (helper.getINS() == APDUCommand::INS_SELECT_FILE)
+ setSelectResponse(result);
+ }
+
+ return ret;
}
} /* namespace smartcard_service_api */
channelNum = _openLogicalChannel(terminal);
if (channelNum > 0)
{
- SCARD_DEBUG("channelNum [%d]", result);
+ SCARD_DEBUG("channelNum [%d]", channelNum);
}
else
{
if (resp.getStatus() == 0)
{
- channel->selectResponse = response;
/* remove privilege mode */
channel->unsetPrivilegeMode();
}
result = IntegerHandle::INVALID_HANDLE;
}
-
return result;
}
#endif