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);
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());
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());
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());
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());
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());
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());
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());
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());
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());
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());
265 // ByteArray value = tlv.getValue();
271 _DBG("0x%02X : unknown : %s", tlv.getTag(), tlv.getValue().toString().c_str());
276 tlv.returnToParentTLV();
280 _ERR("tlv.decodeTLV failed");
288 const ByteArray FCP::getFCP() const
293 void FCP::releaseFCP()
300 int FCP::getFileSize() const
305 int FCP::getTotalFileSize() const
307 return totalFileSize;
310 int FCP::getFID() const
315 int FCP::getSFI() const
320 int FCP::getMaxRecordSize() const
322 return maxRecordSize;
325 int FCP::getNumberOfRecord() const
327 return numberOfRecord;
330 int FCP::getFileType() const
335 int FCP::getFileStructure() const
337 return fileStructure;
340 int FCP::getLCS() const
345 const string FCP::toString() const
349 if (fileSize != FCI::INFO_NOT_AVAILABLE)
350 ss << "size [" << fileSize << "], ";
352 if (totalFileSize != FCI::INFO_NOT_AVAILABLE)
353 ss << "total size [" << totalFileSize << "], ";
355 if (fid != FCI::INFO_NOT_AVAILABLE)
356 ss << "fid [" << fid << "], ";
358 if (sfi != FCI::INFO_NOT_AVAILABLE)
359 ss << "sfi [" << sfi << "], ";
361 if (maxRecordSize != FCI::INFO_NOT_AVAILABLE)
362 ss << "max rec. [" << maxRecordSize << "], ";
364 if (numberOfRecord != FCI::INFO_NOT_AVAILABLE)
365 ss << "n of rec [" << numberOfRecord << "], ";
367 if (fileType != FCI::INFO_NOT_AVAILABLE)
368 ss << "type [" << fileType << "], ";
370 if (fileStructure != FCI::INFO_NOT_AVAILABLE)
371 ss << "struct [" << fileStructure << "], ";
373 if (lcs != FCI::INFO_NOT_AVAILABLE)
374 ss << "lcs [" << lcs << "], ";
380 /* FCM class method */
390 /* FCI class method */
399 bool FCI::setFCIBuffer(const ByteArray &array)
406 } /* namespace smartcard_service_api */