Keyple Card Calypso C++ Library 2.1.0
Reference Terminal Reader API for C++
CmdCardSelectFile.cpp
Go to the documentation of this file.
1/**************************************************************************************************
2 * Copyright (c) 2022 Calypso Networks Association https://calypsonet.org/ *
3 * *
4 * See the NOTICE file(s) distributed with this work for additional information regarding *
5 * copyright ownership. *
6 * *
7 * This program and the accompanying materials are made available under the terms of the Eclipse *
8 * Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0 *
9 * *
10 * SPDX-License-Identifier: EPL-2.0 *
11 **************************************************************************************************/
12
13#include "CmdCardSelectFile.h"
14
15/* Keyple Card Calypso */
18
19/* Keyple Core Util */
20#include "ApduUtil.h"
21#include "BerTlvUtil.h"
22#include "ByteArrayUtil.h"
23#include "IllegalStateException.h"
24#include "KeypleAssert.h"
25
26namespace keyple {
27namespace card {
28namespace calypso {
29
30using namespace calypsonet::terminal::calypso;
31using namespace keyple::core::util;
32using namespace keyple::core::util::cpp::exception;
33
34const int CmdCardSelectFile::TAG_PROPRIETARY_INFORMATION = 0x85;
35const CalypsoCardCommand CmdCardSelectFile::mCommand = CalypsoCardCommand::SELECT_FILE;
36const std::map<const int, const std::shared_ptr<StatusProperties>>
37 CmdCardSelectFile::STATUS_TABLE = initStatusTable();
38
40 const SelectFileControl selectFileControl)
41: AbstractCardCommand(mCommand)
42{
43 const uint8_t cla = calypsoCardClass.getValue();
44 uint8_t p1;
45 uint8_t p2;
46 const std::vector<uint8_t> selectData = {0x00, 0x00};
47
48 switch (selectFileControl) {
49 case SelectFileControl::FIRST_EF:
50 p1 = 0x02;
51 p2 = 0x00;
52 break;
53 case SelectFileControl::NEXT_EF:
54 p1 = 0x02;
55 p2 = 0x02;
56 break;
57 case SelectFileControl::CURRENT_DF:
58 /* CL-KEY-KIFSF.1 */
59 p1 = 0x09;
60 p2 = 0x00;
61 break;
62 default:
63 throw IllegalStateException("Unsupported selectFileControl parameter " \
64 "FIXME: selectFileControl.name()");
65 }
66
68 std::make_shared<ApduRequestAdapter>(
69 ApduUtil::build(cla, mCommand.getInstructionByte(), p1, p2, selectData, 0x00)));
70
71
72 addSubName("SELECTIONCONTROL FIXME: selectFileControl");
73}
74
76 const CalypsoCard::ProductType productType,
77 const uint16_t lid)
78: AbstractCardCommand(mCommand)
79{
80 /*
81 * handle the REV1 case
82 * CL-KEY-KIFSF.1
83 * If legacy and rev2 then 02h else if legacy then 08h else 09h
84 */
85 uint8_t p1;
86
87 if (calypsoCardClass == CalypsoCardClass::LEGACY &&
88 productType == CalypsoCard::ProductType::PRIME_REVISION_2) {
89 p1 = 0x02;
90 } else if (calypsoCardClass == CalypsoCardClass::LEGACY) {
91 p1 = 0x08;
92 } else {
93 p1 = 0x09;
94 }
95
96 const std::vector<uint8_t> dataIn = {static_cast<uint8_t>((lid >> 8) & 0xFF),
97 static_cast<uint8_t>(lid & 0xFF)};
98
100 std::make_shared<ApduRequestAdapter>(
101 ApduUtil::build(calypsoCardClass.getValue(),
102 mCommand.getInstructionByte(),
103 p1,
104 0x00,
105 dataIn,
106 0x00)));
107
108 addSubName("LID=" + ByteArrayUtil::toHex(dataIn));
109}
110
112{
113 return false;
114}
115
117{
118 if (mProprietaryInformation.empty()) {
119 const std::map<const int, const std::vector<uint8_t>> tags =
120 BerTlvUtil::parseSimple(getApduResponse()->getDataOut(), true);
121
122 const auto it = tags.find(TAG_PROPRIETARY_INFORMATION);
123 if (it == tags.end()) {
124 throw new IllegalStateException("Proprietary information: tag not found.");
125 }
126
127 mProprietaryInformation = it->second;
128 Assert::getInstance().isEqual(mProprietaryInformation.size(), 23, "proprietaryInformation");
129 }
130
131 return mProprietaryInformation;
132}
133
134const std::map<const int, const std::shared_ptr<StatusProperties>>
135 CmdCardSelectFile::initStatusTable()
136{
137 std::map<const int, const std::shared_ptr<StatusProperties>> m =
139
140 m.insert({0x6700,
141 std::make_shared<StatusProperties>("Lc value not supported.",
143 m.insert({0x6A82,
144 std::make_shared<StatusProperties>("File not found.",
145 typeid(CardDataAccessException))});
146 m.insert({0x6119,
147 std::make_shared<StatusProperties>("Correct execution (ISO7816 T=0).",
148 typeid(nullptr))});
149
150 return m;
151}
152
153const std::map<const int, const std::shared_ptr<StatusProperties>>&
155{
156 return STATUS_TABLE;
157}
158
159}
160}
161}
static const std::map< const int, const std::shared_ptr< StatusProperties > > STATUS_TABLE
virtual void addSubName(const std::string &subName) final
virtual const std::shared_ptr< ApduResponseApi > getApduResponse() const final
virtual void setApduRequest(const std::shared_ptr< ApduRequestAdapter > apduRequest) final
static const CalypsoCardClass LEGACY
static const CalypsoCardCommand SELECT_FILE
const std::map< const int, const std::shared_ptr< StatusProperties > > & getStatusTable() const override
const std::vector< uint8_t > & getProprietaryInformation()
CmdCardSelectFile(const CalypsoCardClass calypsoCardClass, const SelectFileControl selectFileControl)
CalypsoSam::ProductType ProductType