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 */
21 /* SLP library header */
26 #include "SimpleTLV.h"
27 //#include "ISO7816BERTLV.h"
28 #include "NumberStream.h"
30 namespace smartcard_service_api
32 /* FCP class method */
38 FCP::FCP(ByteArray &array)
49 void FCP::resetMemberVar()
51 fileSize = FCI::INFO_NOT_AVAILABLE;
52 totalFileSize = FCI::INFO_NOT_AVAILABLE;
53 fid = FCI::INFO_NOT_AVAILABLE;
54 sfi = FCI::INFO_NOT_AVAILABLE;
55 maxRecordSize = FCI::INFO_NOT_AVAILABLE;
56 numberOfRecord = FCI::INFO_NOT_AVAILABLE;
57 fileType = FCI::INFO_NOT_AVAILABLE;
58 fileStructure = FCI::INFO_NOT_AVAILABLE;
59 lcs = FCI::INFO_NOT_AVAILABLE;
62 bool FCP::setFCP(ByteArray array)
71 if (array.getLength() == 0)
76 if (fcpBuffer[0] != 0x62)
78 _ERR("it is not FCP response [%02X]", fcpBuffer[0]);
83 tlv.setTLVBuffer(fcpBuffer.getBuffer(), fcpBuffer.getLength());
87 tlv.enterToValueTLV();
89 while (tlv.decodeTLV())
93 case 0x80 : /* file length without structural information */
95 _DBG("0x%02X : file length without structural information : %s", tlv.getTag(), tlv.getValue().toString());
96 if (tlv.getLength() > 0)
98 fileSize = NumberStream::getBigEndianNumber(tlv.getValue());
103 case 0x81 : /* file length with structural information */
105 _DBG("0x%02X : file length with structural information : %s", tlv.getTag(), tlv.getValue().toString());
106 if (tlv.getLength() > 0)
108 maxRecordSize = NumberStream::getBigEndianNumber(tlv.getValue());
113 case 0x82 : /* file descriptor bytes */
115 _DBG("0x%02X : file descriptor bytes : %s", tlv.getTag(), tlv.getValue().toString());
116 // ByteArray value = tlv.getValue();
120 case 0x83 : /* file identifier */
122 _DBG("0x%02X : file identifier : %s", tlv.getTag(), tlv.getValue().toString());
123 if (tlv.getLength() > 0)
125 ByteArray value = tlv.getValue();
129 memcpy(&fid, value.getBuffer(), value.getLength());
134 case 0x84 : /* DF name */
136 SCARD_DEBUG("0x%02X : DF name : %s", tlv.getTag(), tlv.getValue().toString());
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());
144 // ByteArray value = tlv.getValue();
148 case 0x86 : /* Security attribute in proprietary format */
150 SCARD_DEBUG("0x%02X : Security attribute in proprietary format : %s", tlv.getTag(), tlv.getValue().toString());
151 // ByteArray value = tlv.getValue();
155 case 0x87 : /* Identifier of an EF containing an extension of the file control information */
157 _DBG("0x%02X : Identifier of an EF containing an extension of the file control information : %s", tlv.getTag(), tlv.getValue().toString());
158 // ByteArray value = tlv.getValue();
162 case 0x88 : /* Short EF identifier */
164 _DBG("0x%02X : Short EF identifier : %s", tlv.getTag(), tlv.getValue().toString());
166 if (tlv.getLength() > 0)
168 ByteArray value = tlv.getValue();
172 memcpy(&sfi, value.getBuffer(), value.getLength());
177 case 0x8A : /* life cycle status byte */
179 _DBG("0x%02X : life cycle status byte : %s", tlv.getTag(), tlv.getValue().toString());
180 if (tlv.getLength() > 0)
182 ByteArray value = tlv.getValue();
186 memcpy(&lcs, value.getBuffer(), value.getLength());
191 case 0x8B : /* Security attribute referencing the expanded format */
193 SCARD_DEBUG("0x%02X : Security attribute referencing the expanded format : %s", tlv.getTag(), tlv.getValue().toString());
194 // ByteArray value = tlv.getValue();
198 case 0x8C : /* Security attribute in compact format */
200 SCARD_DEBUG("0x%02X : Security attribute in compact format : %s", tlv.getTag(), tlv.getValue().toString());
201 // ByteArray value = tlv.getValue();
205 case 0x8D : /* Identifier of an EF containing security environment templates */
207 SCARD_DEBUG("0x%02X : Identifier of an EF containing security environment templates : %s", tlv.getTag(), tlv.getValue().toString());
208 // ByteArray value = tlv.getValue();
212 case 0x8E : /* Channel security attribute */
214 SCARD_DEBUG("0x%02X : Channel security attribute : %s", tlv.getTag(), tlv.getValue().toString());
215 // ByteArray value = tlv.getValue();
219 case 0xA0 : /* Security attribute template for data objects */
221 SCARD_DEBUG("0x%02X : Security attribute template for data objects : %s", tlv.getTag(), tlv.getValue().toString());
222 // ByteArray value = tlv.getValue();
226 case 0xA1 : /* Security attribute template in proprietary format */
228 SCARD_DEBUG("0x%02X : Security attribute template in proprietary format : %s", tlv.getTag(), tlv.getValue().toString());
229 // ByteArray value = tlv.getValue();
233 case 0xA2 : /* Template consisting of one or more pairs of data objects */
235 _DBG("0x%02X : Template consisting of one or more pairs of data objects : %s", tlv.getTag(), tlv.getValue().toString());
236 // ByteArray value = tlv.getValue();
240 case 0xA5 : /* proprietary information encoded in BER-TLV */
242 _DBG("0x%02X : proprietary information encoded in BER-TLV : %s", tlv.getTag(), tlv.getValue().toString());
243 // ByteArray value = tlv.getValue();
247 case 0xAB : /* Security attribute template in expanded format */
249 SCARD_DEBUG("0x%02X : Security attribute template in expanded format : %s", tlv.getTag(), tlv.getValue().toString());
250 // ByteArray value = tlv.getValue();
254 case 0xAC : /* Cryptographic mechanism identifier template */
256 _DBG("0x%02X : Cryptographic mechanism identifier template : %s", tlv.getTag(), tlv.getValue().toString());
257 // ByteArray value = tlv.getValue();
261 case 0xC6 : /* PIN status template DO */
263 SCARD_DEBUG("0x%02X : PIN status template DO : %s", tlv.getTag(), tlv.getValue().toString());
264 // ByteArray value = tlv.getValue();
270 _DBG("0x%02X : unknown : %s", tlv.getTag(), tlv.getValue().toString());
275 tlv.returnToParentTLV();
279 _ERR("tlv.decodeTLV failed");
287 ByteArray FCP::getFCP()
292 void FCP::releaseFCP()
294 fcpBuffer.releaseBuffer();
299 unsigned int FCP::getFileSize()
304 unsigned int FCP::getTotalFileSize()
306 return totalFileSize;
309 unsigned int FCP::getFID()
314 unsigned int FCP::getSFI()
319 unsigned int FCP::getMaxRecordSize()
321 return maxRecordSize;
324 unsigned int FCP::getNumberOfRecord()
326 return numberOfRecord;
329 unsigned int FCP::getFileType()
334 unsigned int FCP::getFileStructure()
336 return fileStructure;
339 unsigned int FCP::getLCS()
344 const char *FCP::toString()
346 memset(strBuffer, 0, sizeof(strBuffer));
348 snprintf(strBuffer, sizeof(strBuffer), "size [%d], total size [%d], fid [%x], sfi [%x], max rec [%d], n of rec [%d], type [%d], struct [%d], lcs [%d]",
349 getFileSize(), getTotalFileSize(), getFID(), getSFI(), getMaxRecordSize(), getNumberOfRecord(), getFileType(), getFileStructure(), getLCS());
351 return (const char *)strBuffer;
355 /* FCM class method */
365 /* FCI class method */
374 bool FCI::setFCIBuffer(ByteArray array)
381 } /* namespace smartcard_service_api */