From 7b6e94cbdd3e375089539be68747b6db667c915d Mon Sep 17 00:00:00 2001 From: Wonkyu Kwon Date: Wed, 22 May 2013 14:35:25 +0900 Subject: [PATCH] Return status word instead of negative error value Change-Id: Iad873372927da497c910b0c1e5ceff9371529671 --- common/APDUHelper.cpp | 1 - common/FileObject.cpp | 36 +++++++++++++----------------------- server/ServerChannel.cpp | 4 ++-- server/ServerResource.cpp | 20 +++++++------------- 4 files changed, 22 insertions(+), 39 deletions(-) diff --git a/common/APDUHelper.cpp b/common/APDUHelper.cpp index 757c1a8..f37af2c 100644 --- a/common/APDUHelper.cpp +++ b/common/APDUHelper.cpp @@ -78,7 +78,6 @@ namespace smartcard_service_api case (unsigned char)0x90 : /* SW2:00, No further qualification */ case (unsigned char)0x91 : /* extra information */ case (unsigned char)0x92 : /* extra information */ - result = 0; break; default : diff --git a/common/FileObject.cpp b/common/FileObject.cpp index 65c18d3..e1d71f3 100644 --- a/common/FileObject.cpp +++ b/common/FileObject.cpp @@ -59,7 +59,7 @@ namespace smartcard_service_api ResponseHelper resp(response); selectResponse = response; - if (resp.getStatus() == 0) + if (resp.getStatus() >= 0) { fcp.releaseFCP(); @@ -72,8 +72,8 @@ namespace smartcard_service_api } else { - _ERR("status word [%d][ %02X %02X ]", - resp.getStatus(), resp.getSW1(), resp.getSW2()); + _ERR("status word [ %02X %02X ]", + resp.getSW1(), resp.getSW2()); } } else @@ -103,21 +103,11 @@ namespace smartcard_service_api { ResponseHelper resp(result); - if (resp.getStatus() == 0) - { - if (setSelectResponse(result) == true) - { - opened = true; - ret = SUCCESS; - } - else - { - ret = ERROR_ILLEGAL_STATE; - } - } - else if (resp.getStatus() == ResponseHelper::ERROR_FILE_NOT_FOUND) + ret = resp.getStatus(); + + if (setSelectResponse(result) == true) { - ret = ResponseHelper::ERROR_FILE_NOT_FOUND; + opened = true; } } else @@ -223,7 +213,7 @@ namespace smartcard_service_api ResponseHelper resp(response); ret = resp.getStatus(); - if (ret == 0) + if (ret >= 0) { _DBG("response [%d] : %s", response.getLength(), response.toString()); @@ -231,7 +221,7 @@ namespace smartcard_service_api } else { - _ERR("status word [%d][ %02X %02X ]", resp.getStatus(), resp.getSW1(), resp.getSW2()); + _ERR("status word [ %02X %02X ]", resp.getSW1(), resp.getSW2()); } } else @@ -266,7 +256,7 @@ namespace smartcard_service_api { ResponseHelper resp(response); - if (resp.getStatus() == 0) + if (resp.getStatus() >= 0) { _DBG("response [%d] : %s", response.getLength(), response.toString()); @@ -276,7 +266,7 @@ namespace smartcard_service_api } else { - _ERR("status word [%d][ %02X %02X ]", resp.getStatus(), resp.getSW1(), resp.getSW2()); + _ERR("status word [ %02X %02X ]", resp.getSW1(), resp.getSW2()); } } else @@ -301,7 +291,7 @@ namespace smartcard_service_api { ResponseHelper resp(response); - if (resp.getStatus() == 0) + if (resp.getStatus() >= 0) { _DBG("response [%d] : %s", response.getLength(), response.toString()); @@ -309,7 +299,7 @@ namespace smartcard_service_api } else { - _ERR("status word [%d][ %02X %02X ]", resp.getStatus(), resp.getSW1(), resp.getSW2()); + _ERR("status word [ %02X %02X ]", resp.getSW1(), resp.getSW2()); } } else diff --git a/server/ServerChannel.cpp b/server/ServerChannel.cpp index 1d896d1..8d13597 100644 --- a/server/ServerChannel.cpp +++ b/server/ServerChannel.cpp @@ -60,13 +60,13 @@ namespace smartcard_service_api { ResponseHelper resp(result); - if (resp.getStatus() == 0) + if (resp.getStatus() >= 0) { _DBG("close success"); } else { - _ERR("status word [%d][ %02X %02X ]", resp.getStatus(), resp.getSW1(), resp.getSW2()); + _ERR("status word [ %02X %02X ]", resp.getSW1(), resp.getSW2()); } } else diff --git a/server/ServerResource.cpp b/server/ServerResource.cpp index 70b802b..232fcdf 100644 --- a/server/ServerResource.cpp +++ b/server/ServerResource.cpp @@ -426,19 +426,13 @@ namespace smartcard_service_api { ResponseHelper resp(response); - if (resp.getStatus() == 0) + if (resp.getStatus() >= 0) { result = resp.getDataField()[0]; } else { - _ERR("status word [%d][ %02X %02X ]", resp.getStatus(), resp.getSW1(), resp.getSW2()); - if (0) - { - /* TODO : if there is no more channel, return error code */ - _ERR("no more logical channel"); - result = -2; - } + result = resp.getStatus(); } } else @@ -451,7 +445,7 @@ namespace smartcard_service_api int ServerResource::_closeLogicalChannel(Terminal *terminal, int channelNum) { - int result = -1; + int result = SCARD_ERROR_UNKNOWN; int rv = 0; ByteArray command; ByteArray response; @@ -463,14 +457,14 @@ namespace smartcard_service_api { ResponseHelper resp(response); - if (resp.getStatus() == 0) + if (resp.getStatus() >= 0) { _DBG("channel closed [%d]", channelNum); - result = 0; + result = SCARD_ERROR_OK; } else { - _ERR("status word [%d][ %02X %02X ]", resp.getStatus(), resp.getSW1(), resp.getSW2()); + _ERR("status word [ %02X %02X ]", resp.getSW1(), resp.getSW2()); } } else @@ -548,7 +542,7 @@ namespace smartcard_service_api FileObject file(channel); rv = file.select(aid); - if (rv == FileObject::SUCCESS) + if (rv >= 0) { /* remove privilege mode */ channel->unsetPrivilegeMode(); -- 2.7.4