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.
23 #include "SimpleTLV.h"
24 //#include "ISO7816BERTLV.h"
25 #include "NumberStream.h"
27 namespace smartcard_service_api
29 /* FCP class method */
35 FCP::FCP(const ByteArray &array)
46 void FCP::resetMemberVar()
48 fileSize = FCI::INFO_NOT_AVAILABLE;
49 totalFileSize = FCI::INFO_NOT_AVAILABLE;
50 fid = FCI::INFO_NOT_AVAILABLE;
51 sfi = FCI::INFO_NOT_AVAILABLE;
52 maxRecordSize = FCI::INFO_NOT_AVAILABLE;
53 numberOfRecord = FCI::INFO_NOT_AVAILABLE;
54 fileType = FCI::INFO_NOT_AVAILABLE;
55 fileStructure = FCI::INFO_NOT_AVAILABLE;
56 lcs = FCI::INFO_NOT_AVAILABLE;
59 bool FCP::setFCP(const ByteArray &array)
68 if (array.size() == 0)
73 if (fcpBuffer[0] != 0x62)
75 _ERR("it is not FCP response [%02X]", fcpBuffer[0]);
80 tlv.setTLVBuffer(fcpBuffer.getBuffer(), fcpBuffer.size());
84 tlv.enterToValueTLV();
86 while (tlv.decodeTLV())
90 case 0x80 : /* file length without structural information */
92 _DBG("0x%02X : file length without structural information : %s", tlv.getTag(), tlv.getValue().toString().c_str());
95 fileSize = NumberStream::getBigEndianNumber(tlv.getValue());
100 case 0x81 : /* file length with structural information */
102 _DBG("0x%02X : file length with structural information : %s", tlv.getTag(), tlv.getValue().toString().c_str());
105 maxRecordSize = NumberStream::getBigEndianNumber(tlv.getValue());
110 case 0x82 : /* file descriptor bytes */
112 _DBG("0x%02X : file descriptor bytes : %s", tlv.getTag(), tlv.getValue().toString().c_str());
113 // ByteArray value = tlv.getValue();
117 case 0x83 : /* file identifier */
119 _DBG("0x%02X : file identifier : %s", tlv.getTag(), tlv.getValue().toString().c_str());
122 ByteArray value = tlv.getValue();
126 memcpy(&fid, value.getBuffer(), value.size());
131 case 0x84 : /* DF name */
133 // ByteArray value = tlv.getValue();
137 case 0x85 : /* proprietary information not encoded in BER-TLV */
139 _DBG("0x%02X : proprietary information not encoded in BER-TLV : %s", tlv.getTag(), tlv.getValue().toString().c_str());
140 // ByteArray value = tlv.getValue();
144 case 0x86 : /* Security attribute in proprietary format */
146 // ByteArray value = tlv.getValue();
150 case 0x87 : /* Identifier of an EF containing an extension of the file control information */
152 _DBG("0x%02X : Identifier of an EF containing an extension of the file control information : %s", tlv.getTag(), tlv.getValue().toString().c_str());
153 // ByteArray value = tlv.getValue();
157 case 0x88 : /* Short EF identifier */
159 _DBG("0x%02X : Short EF identifier : %s", tlv.getTag(), tlv.getValue().toString().c_str());
163 ByteArray value = tlv.getValue();
167 memcpy(&sfi, value.getBuffer(), value.size());
172 case 0x8A : /* life cycle status byte */
174 _DBG("0x%02X : life cycle status byte : %s", tlv.getTag(), tlv.getValue().toString().c_str());
177 ByteArray value = tlv.getValue();
181 memcpy(&lcs, value.getBuffer(), value.size());
186 case 0x8B : /* Security attribute referencing the expanded format */
188 // ByteArray value = tlv.getValue();
192 case 0x8C : /* Security attribute in compact format */
194 // ByteArray value = tlv.getValue();
198 case 0x8D : /* Identifier of an EF containing security environment templates */
200 // ByteArray value = tlv.getValue();
204 case 0x8E : /* Channel security attribute */
206 // ByteArray value = tlv.getValue();
210 case 0xA0 : /* Security attribute template for data objects */
212 // ByteArray value = tlv.getValue();
216 case 0xA1 : /* Security attribute template in proprietary format */
218 // ByteArray value = tlv.getValue();
222 case 0xA2 : /* Template consisting of one or more pairs of data objects */
224 _DBG("0x%02X : Template consisting of one or more pairs of data objects : %s", tlv.getTag(), tlv.getValue().toString().c_str());
225 // ByteArray value = tlv.getValue();
229 case 0xA5 : /* proprietary information encoded in BER-TLV */
231 _DBG("0x%02X : proprietary information encoded in BER-TLV : %s", tlv.getTag(), tlv.getValue().toString().c_str());
232 // ByteArray value = tlv.getValue();
236 case 0xAB : /* Security attribute template in expanded format */
238 // ByteArray value = tlv.getValue();
242 case 0xAC : /* Cryptographic mechanism identifier template */
244 _DBG("0x%02X : Cryptographic mechanism identifier template : %s", tlv.getTag(), tlv.getValue().toString().c_str());
245 // ByteArray value = tlv.getValue();
249 case 0xC6 : /* PIN status template DO */
251 // ByteArray value = tlv.getValue();
257 _DBG("0x%02X : unknown : %s", tlv.getTag(), tlv.getValue().toString().c_str());
262 tlv.returnToParentTLV();
266 _ERR("tlv.decodeTLV failed");
274 const ByteArray FCP::getFCP() const
279 void FCP::releaseFCP()
286 int FCP::getFileSize() const
291 int FCP::getTotalFileSize() const
293 return totalFileSize;
296 int FCP::getFID() const
301 int FCP::getSFI() const
306 int FCP::getMaxRecordSize() const
308 return maxRecordSize;
311 int FCP::getNumberOfRecord() const
313 return numberOfRecord;
316 int FCP::getFileType() const
321 int FCP::getFileStructure() const
323 return fileStructure;
326 int FCP::getLCS() const
331 const string FCP::toString() const
335 if (fileSize != FCI::INFO_NOT_AVAILABLE)
336 ss << "size [" << fileSize << "], ";
338 if (totalFileSize != FCI::INFO_NOT_AVAILABLE)
339 ss << "total size [" << totalFileSize << "], ";
341 if (fid != FCI::INFO_NOT_AVAILABLE)
342 ss << "fid [" << fid << "], ";
344 if (sfi != FCI::INFO_NOT_AVAILABLE)
345 ss << "sfi [" << sfi << "], ";
347 if (maxRecordSize != FCI::INFO_NOT_AVAILABLE)
348 ss << "max rec. [" << maxRecordSize << "], ";
350 if (numberOfRecord != FCI::INFO_NOT_AVAILABLE)
351 ss << "n of rec [" << numberOfRecord << "], ";
353 if (fileType != FCI::INFO_NOT_AVAILABLE)
354 ss << "type [" << fileType << "], ";
356 if (fileStructure != FCI::INFO_NOT_AVAILABLE)
357 ss << "struct [" << fileStructure << "], ";
359 if (lcs != FCI::INFO_NOT_AVAILABLE)
360 ss << "lcs [" << lcs << "], ";
366 /* FCM class method */
376 /* FCI class method */
385 bool FCI::setFCIBuffer(const ByteArray &array)
392 } /* namespace smartcard_service_api */