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 */
22 /* SLP library header */
27 #include "SimpleTLV.h"
28 //#include "ISO7816BERTLV.h"
29 #include "NumberStream.h"
31 namespace smartcard_service_api
33 /* FCP class method */
40 FCP::FCP(const ByteArray &array)
51 void FCP::resetMemberVar()
53 fileSize = FCI::INFO_NOT_AVAILABLE;
54 totalFileSize = FCI::INFO_NOT_AVAILABLE;
55 fid = FCI::INFO_NOT_AVAILABLE;
56 sfi = FCI::INFO_NOT_AVAILABLE;
57 maxRecordSize = FCI::INFO_NOT_AVAILABLE;
58 numberOfRecord = FCI::INFO_NOT_AVAILABLE;
59 fileType = FCI::INFO_NOT_AVAILABLE;
60 fileStructure = FCI::INFO_NOT_AVAILABLE;
61 lcs = FCI::INFO_NOT_AVAILABLE;
64 bool FCP::setFCP(const ByteArray &array)
73 if (array.size() == 0)
78 if (fcpBuffer[0] != 0x62)
80 _ERR("it is not FCP response [%02X]", fcpBuffer[0]);
85 tlv.setTLVBuffer(fcpBuffer);
87 if (tlv.decodeTLV()) {
88 tlv.enterToValueTLV();
90 while (tlv.decodeTLV())
94 case 0x80 : /* file length without structural information */
96 _DBG("0x%02X : file length without structural information : %s", tlv.getTag(), tlv.getValue().toString().c_str());
99 fileSize = NumberStream::getBigEndianNumber(tlv.getValue());
104 case 0x81 : /* file length with structural information */
106 _DBG("0x%02X : file length with structural information : %s", tlv.getTag(), tlv.getValue().toString().c_str());
109 maxRecordSize = NumberStream::getBigEndianNumber(tlv.getValue());
114 case 0x82 : /* file descriptor bytes */
116 _DBG("0x%02X : file descriptor bytes : %s", tlv.getTag(), tlv.getValue().toString().c_str());
117 // ByteArray value = tlv.getValue();
121 case 0x83 : /* file identifier */
123 _DBG("0x%02X : file identifier : %s", tlv.getTag(), tlv.getValue().toString().c_str());
126 ByteArray value = tlv.getValue();
130 memcpy(&fid, value.getBuffer(), value.size());
135 case 0x84 : /* DF name */
137 SECURE_LOGD("0x%02X : DF name : %s", tlv.getTag(), tlv.getValue().toString().c_str()); //LCOV_EXCL_LINE
138 // ByteArray value = tlv.getValue();
142 case 0x85 : /* proprietary information not encoded in BER-TLV */
144 _DBG("0x%02X : proprietary information not encoded in BER-TLV : %s", tlv.getTag(), tlv.getValue().toString().c_str());
145 // ByteArray value = tlv.getValue();
149 case 0x86 : /* Security attribute in proprietary format */
151 SECURE_LOGD("0x%02X : Security attribute in proprietary format : %s", tlv.getTag(), tlv.getValue().toString().c_str()); //LCOV_EXCL_LINE
152 // ByteArray value = tlv.getValue();
156 case 0x87 : /* Identifier of an EF containing an extension of the file control information */
158 _DBG("0x%02X : Identifier of an EF containing an extension of the file control information : %s", tlv.getTag(), tlv.getValue().toString().c_str());
159 // ByteArray value = tlv.getValue();
163 case 0x88 : /* Short EF identifier */
165 _DBG("0x%02X : Short EF identifier : %s", tlv.getTag(), tlv.getValue().toString().c_str());
169 ByteArray value = tlv.getValue();
173 memcpy(&sfi, value.getBuffer(), value.size());
178 case 0x8A : /* life cycle status byte */
180 _DBG("0x%02X : life cycle status byte : %s", tlv.getTag(), tlv.getValue().toString().c_str());
183 ByteArray value = tlv.getValue();
187 memcpy(&lcs, value.getBuffer(), value.size());
192 case 0x8B : /* Security attribute referencing the expanded format */
194 SECURE_LOGD("0x%02X : Security attribute referencing the expanded format : %s", tlv.getTag(), tlv.getValue().toString().c_str()); //LCOV_EXCL_LINE
195 // ByteArray value = tlv.getValue();
199 case 0x8C : /* Security attribute in compact format */
201 SECURE_LOGD("0x%02X : Security attribute in compact format : %s", tlv.getTag(), tlv.getValue().toString().c_str()); //LCOV_EXCL_LINE
202 // ByteArray value = tlv.getValue();
206 case 0x8D : /* Identifier of an EF containing security environment templates */
208 SECURE_LOGD("0x%02X : Identifier of an EF containing security environment templates : %s", tlv.getTag(), tlv.getValue().toString().c_str()); //LCOV_EXCL_LINE
209 // ByteArray value = tlv.getValue();
213 case 0x8E : /* Channel security attribute */
215 SECURE_LOGD("0x%02X : Channel security attribute : %s", tlv.getTag(), tlv.getValue().toString().c_str()); //LCOV_EXCL_LINE
216 // ByteArray value = tlv.getValue();
220 case 0xA0 : /* Security attribute template for data objects */
222 SECURE_LOGD("0x%02X : Security attribute template for data objects : %s", tlv.getTag(), tlv.getValue().toString().c_str()); //LCOV_EXCL_LINE
223 // ByteArray value = tlv.getValue();
227 case 0xA1 : /* Security attribute template in proprietary format */
229 SECURE_LOGD("0x%02X : Security attribute template in proprietary format : %s", tlv.getTag(), tlv.getValue().toString().c_str()); //LCOV_EXCL_LINE
230 // ByteArray value = tlv.getValue();
234 case 0xA2 : /* Template consisting of one or more pairs of data objects */
236 _DBG("0x%02X : Template consisting of one or more pairs of data objects : %s", tlv.getTag(), tlv.getValue().toString().c_str());
237 // ByteArray value = tlv.getValue();
241 case 0xA5 : /* proprietary information encoded in BER-TLV */
243 _DBG("0x%02X : proprietary information encoded in BER-TLV : %s", tlv.getTag(), tlv.getValue().toString().c_str());
244 // ByteArray value = tlv.getValue();
248 case 0xAB : /* Security attribute template in expanded format */
250 SECURE_LOGD("0x%02X : Security attribute template in expanded format : %s", tlv.getTag(), tlv.getValue().toString().c_str()); //LCOV_EXCL_LINE
251 // ByteArray value = tlv.getValue();
255 case 0xAC : /* Cryptographic mechanism identifier template */
257 _DBG("0x%02X : Cryptographic mechanism identifier template : %s", tlv.getTag(), tlv.getValue().toString().c_str());
258 // ByteArray value = tlv.getValue();
262 case 0xC6 : /* PIN status template DO */
264 SECURE_LOGD("0x%02X : PIN status template DO : %s", tlv.getTag(), tlv.getValue().toString().c_str()); //LCOV_EXCL_LINE
265 // ByteArray value = tlv.getValue();
271 _DBG("0x%02X : unknown : %s", tlv.getTag(), tlv.getValue().toString().c_str());
276 tlv.returnToParentTLV();
278 _ERR("tlv.decodeTLV failed");
286 const ByteArray FCP::getFCP() const
291 void FCP::releaseFCP()
298 int FCP::getFileSize() const
303 int FCP::getTotalFileSize() const
305 return totalFileSize;
308 int FCP::getFID() const
313 int FCP::getSFI() const
318 int FCP::getMaxRecordSize() const
320 return maxRecordSize;
323 int FCP::getNumberOfRecord() const
325 return numberOfRecord;
328 int FCP::getFileType() const
333 int FCP::getFileStructure() const
335 return fileStructure;
338 int FCP::getLCS() const
343 const string FCP::toString() const
347 if (fileSize != FCI::INFO_NOT_AVAILABLE)
348 ss << "size [" << fileSize << "], ";
350 if (totalFileSize != FCI::INFO_NOT_AVAILABLE)
351 ss << "total size [" << totalFileSize << "], ";
353 if (fid != FCI::INFO_NOT_AVAILABLE)
354 ss << "fid [" << fid << "], ";
356 if (sfi != FCI::INFO_NOT_AVAILABLE)
357 ss << "sfi [" << sfi << "], ";
359 if (maxRecordSize != FCI::INFO_NOT_AVAILABLE)
360 ss << "max rec. [" << maxRecordSize << "], ";
362 if (numberOfRecord != FCI::INFO_NOT_AVAILABLE)
363 ss << "n of rec [" << numberOfRecord << "], ";
365 if (fileType != FCI::INFO_NOT_AVAILABLE)
366 ss << "type [" << fileType << "], ";
368 if (fileStructure != FCI::INFO_NOT_AVAILABLE)
369 ss << "struct [" << fileStructure << "], ";
371 if (lcs != FCI::INFO_NOT_AVAILABLE)
372 ss << "lcs [" << lcs << "], ";
378 /* FCM class method */
388 /* FCI class method */
397 bool FCI::setFCIBuffer(const ByteArray &array)
405 } /* namespace smartcard_service_api */