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 */
39 FCP::FCP(const ByteArray &array)
50 void FCP::resetMemberVar()
52 fileSize = FCI::INFO_NOT_AVAILABLE;
53 totalFileSize = FCI::INFO_NOT_AVAILABLE;
54 fid = FCI::INFO_NOT_AVAILABLE;
55 sfi = FCI::INFO_NOT_AVAILABLE;
56 maxRecordSize = FCI::INFO_NOT_AVAILABLE;
57 numberOfRecord = FCI::INFO_NOT_AVAILABLE;
58 fileType = FCI::INFO_NOT_AVAILABLE;
59 fileStructure = FCI::INFO_NOT_AVAILABLE;
60 lcs = FCI::INFO_NOT_AVAILABLE;
63 bool FCP::setFCP(const ByteArray &array)
72 if (array.size() == 0)
77 if (fcpBuffer[0] != 0x62)
79 _ERR("it is not FCP response [%02X]", fcpBuffer[0]);
84 tlv.setTLVBuffer(fcpBuffer.getBuffer(), fcpBuffer.size());
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 // ByteArray value = tlv.getValue();
141 case 0x85 : /* proprietary information not encoded in BER-TLV */
143 _DBG("0x%02X : proprietary information not encoded in BER-TLV : %s", tlv.getTag(), tlv.getValue().toString().c_str());
144 // ByteArray value = tlv.getValue();
148 case 0x86 : /* Security attribute in proprietary format */
150 // ByteArray value = tlv.getValue();
154 case 0x87 : /* Identifier of an EF containing an extension of the file control information */
156 _DBG("0x%02X : Identifier of an EF containing an extension of the file control information : %s", tlv.getTag(), tlv.getValue().toString().c_str());
157 // ByteArray value = tlv.getValue();
161 case 0x88 : /* Short EF identifier */
163 _DBG("0x%02X : Short EF identifier : %s", tlv.getTag(), tlv.getValue().toString().c_str());
167 ByteArray value = tlv.getValue();
171 memcpy(&sfi, value.getBuffer(), value.size());
176 case 0x8A : /* life cycle status byte */
178 _DBG("0x%02X : life cycle status byte : %s", tlv.getTag(), tlv.getValue().toString().c_str());
181 ByteArray value = tlv.getValue();
185 memcpy(&lcs, value.getBuffer(), value.size());
190 case 0x8B : /* Security attribute referencing the expanded format */
192 // ByteArray value = tlv.getValue();
196 case 0x8C : /* Security attribute in compact format */
198 // ByteArray value = tlv.getValue();
202 case 0x8D : /* Identifier of an EF containing security environment templates */
204 // ByteArray value = tlv.getValue();
208 case 0x8E : /* Channel security attribute */
210 // ByteArray value = tlv.getValue();
214 case 0xA0 : /* Security attribute template for data objects */
216 // ByteArray value = tlv.getValue();
220 case 0xA1 : /* Security attribute template in proprietary format */
222 // ByteArray value = tlv.getValue();
226 case 0xA2 : /* Template consisting of one or more pairs of data objects */
228 _DBG("0x%02X : Template consisting of one or more pairs of data objects : %s", tlv.getTag(), tlv.getValue().toString().c_str());
229 // ByteArray value = tlv.getValue();
233 case 0xA5 : /* proprietary information encoded in BER-TLV */
235 _DBG("0x%02X : proprietary information encoded in BER-TLV : %s", tlv.getTag(), tlv.getValue().toString().c_str());
236 // ByteArray value = tlv.getValue();
240 case 0xAB : /* Security attribute template in expanded format */
242 // ByteArray value = tlv.getValue();
246 case 0xAC : /* Cryptographic mechanism identifier template */
248 _DBG("0x%02X : Cryptographic mechanism identifier template : %s", tlv.getTag(), tlv.getValue().toString().c_str());
249 // ByteArray value = tlv.getValue();
253 case 0xC6 : /* PIN status template DO */
255 // ByteArray value = tlv.getValue();
261 _DBG("0x%02X : unknown : %s", tlv.getTag(), tlv.getValue().toString().c_str());
266 tlv.returnToParentTLV();
270 _ERR("tlv.decodeTLV failed");
278 const ByteArray FCP::getFCP() const
283 void FCP::releaseFCP()
290 int FCP::getFileSize() const
295 int FCP::getTotalFileSize() const
297 return totalFileSize;
300 int FCP::getFID() const
305 int FCP::getSFI() const
310 int FCP::getMaxRecordSize() const
312 return maxRecordSize;
315 int FCP::getNumberOfRecord() const
317 return numberOfRecord;
320 int FCP::getFileType() const
325 int FCP::getFileStructure() const
327 return fileStructure;
330 int FCP::getLCS() const
335 const string FCP::toString() const
339 if (fileSize != FCI::INFO_NOT_AVAILABLE)
340 ss << "size [" << fileSize << "], ";
342 if (totalFileSize != FCI::INFO_NOT_AVAILABLE)
343 ss << "total size [" << totalFileSize << "], ";
345 if (fid != FCI::INFO_NOT_AVAILABLE)
346 ss << "fid [" << fid << "], ";
348 if (sfi != FCI::INFO_NOT_AVAILABLE)
349 ss << "sfi [" << sfi << "], ";
351 if (maxRecordSize != FCI::INFO_NOT_AVAILABLE)
352 ss << "max rec. [" << maxRecordSize << "], ";
354 if (numberOfRecord != FCI::INFO_NOT_AVAILABLE)
355 ss << "n of rec [" << numberOfRecord << "], ";
357 if (fileType != FCI::INFO_NOT_AVAILABLE)
358 ss << "type [" << fileType << "], ";
360 if (fileStructure != FCI::INFO_NOT_AVAILABLE)
361 ss << "struct [" << fileStructure << "], ";
363 if (lcs != FCI::INFO_NOT_AVAILABLE)
364 ss << "lcs [" << lcs << "], ";
370 /* FCM class method */
380 /* FCI class method */
389 bool FCI::setFCIBuffer(const ByteArray &array)
396 } /* namespace smartcard_service_api */