From: Wonkyu Kwon Date: Fri, 15 Feb 2013 04:18:20 +0000 (+0900) Subject: Create EF DIR class X-Git-Tag: accepted/tizen/20130912.185847^2~48 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=58451260c802c6090b0a6ca1f08fc14682f48730;p=platform%2Fcore%2Fconnectivity%2Fsmartcard-service.git Create EF DIR class - support searching EF DIR (2F 00) record Change-Id: I83abfc59cf9f4c50702b4c982ec22b0cca8af0f7 --- diff --git a/common/EFDIR.cpp b/common/EFDIR.cpp new file mode 100644 index 0000000..16dfc54 --- /dev/null +++ b/common/EFDIR.cpp @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* standard library header */ +#include + +/* SLP library header */ + +/* local header */ +#include "Debug.h" +#include "EFDIR.h" +#include "APDUHelper.h" +#include "SimpleTLV.h" + +namespace smartcard_service_api +{ + EFDIR::EFDIR(Channel *channel) : FileObject(channel) + { + unsigned char path[] = { 0x2f, 0x00 }; + ByteArray dirPath(ARRAY_AND_SIZE(path)); + int ret; + + ret = select(dirPath, false); + if (ret == FileObject::SUCCESS) + { + SCARD_DEBUG("response : %s", selectResponse.toString()); + } + else + { + SCARD_DEBUG_ERR("EFDIR select failed, [%d]", ret); + } + } + + EFDIR::EFDIR(Channel *channel, ByteArray selectResponse) + : FileObject(channel, selectResponse) + { + } + + EFDIR::~EFDIR() + { + } + + ByteArray EFDIR::parseRecord(Record &record, ByteArray &aid) + { + bool matched = false; + ByteArray result; + SimpleTLV tlv(record.getData()); + + if (tlv.decodeTLV() == true && tlv.getTag() == 0x61) + { + tlv.enterToValueTLV(); + while (tlv.decodeTLV() == true) + { + switch (tlv.getTag()) + { + case 0x4F : /* aid */ + if (tlv.getValue() == aid) + matched = true; + break; + case 0x50 : /* label */ + break; + case 0x51 : /* path */ + result = tlv.getValue(); + break; + case 0x53 : /* ddo */ + break; + } + } + tlv.returnToParentTLV(); + + if (matched == true) + { + SCARD_DEBUG("Found!! : path %s", result.toString()); + } + else + { + result.setBuffer(NULL, 0); + } + } + + return result; + } + + ByteArray EFDIR::getPathByAID(ByteArray &aid) + { + ByteArray result; + Record record; + unsigned int id; + int status = 0; + + for (id = 1; status >= 0; id++) + { + status = readRecord(0, id, record); + if (status >= 0) + { + result = parseRecord(record, aid); + if (result.getLength() > 0) + break; + } + } + + return result; + } +} /* namespace smartcard_service_api */ diff --git a/common/include/EFDIR.h b/common/include/EFDIR.h new file mode 100644 index 0000000..c2fd9f1 --- /dev/null +++ b/common/include/EFDIR.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef EFDIR_H_ +#define EFDIR_H_ + +/* standard library header */ +#include + +/* SLP library header */ + +/* local header */ +#include "FileObject.h" + +using namespace std; + +namespace smartcard_service_api +{ + class EFDIR : public FileObject + { + private: + ByteArray parseRecord(Record &record, ByteArray &aid); + + public: + static const unsigned int EFDIR_FID = 0x002f; + + EFDIR(Channel *channel); + EFDIR(Channel *channel, ByteArray selectResponse); + ~EFDIR(); + + ByteArray getPathByAID(ByteArray &aid); + }; +} /* namespace smartcard_service_api */ +#endif /* EFDIR_H_ */