Keyple Card Calypso C++ Library 2.2.2
Reference Terminal Reader API for C++
CmdCardIncreaseOrDecrease.cpp
Go to the documentation of this file.
1/**************************************************************************************************
2 * Copyright (c) 2021 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
14
15#include <sstream>
16
17/* Keyple Core Util */
18#include "ApduUtil.h"
19#include "Arrays.h"
20
21/* Keyple Card Calypso */
28
29namespace keyple {
30namespace card {
31namespace calypso {
32
33using namespace keyple::core::util;
34using namespace keyple::core::util::cpp;
35
36const std::map<const int, const std::shared_ptr<StatusProperties>>
37 CmdCardIncreaseOrDecrease::STATUS_TABLE = initStatusTable();
38
40 const bool isDecreaseCommand,
41 const CalypsoCardClass calypsoCardClass,
42 const uint8_t sfi,
43 const uint8_t counterNumber,
44 const int incDecValue)
45: AbstractCardCommand(isDecreaseCommand ? CalypsoCardCommand::DECREASE :
46 CalypsoCardCommand::INCREASE,
47 0),
48 mSfi(sfi),
49 mCounterNumber(counterNumber),
50 mIncDecValue(incDecValue)
51{
52 const uint8_t cla = calypsoCardClass.getValue();
53
54 /*
55 * Convert the integer value into a 3-byte buffer
56 * CL-COUN-DATAIN.1
57 */
58 std::vector<uint8_t> valueBuffer(3);
59 valueBuffer[0] = ((incDecValue >> 16) & 0xFF);
60 valueBuffer[1] = ((incDecValue >> 8) & 0xFF);
61 valueBuffer[2] = (incDecValue & 0xFF);
62
63 const uint8_t p2 = sfi * 8;
64
65 /* This is a case4 command, we set Le = 0 */
67 std::make_shared<ApduRequestAdapter>(
68 ApduUtil::build(cla,
69 getCommandRef().getInstructionByte(),
70 mCounterNumber,
71 p2,
72 valueBuffer,
73 0x00)));
74
75 std::stringstream extraInfo;
76 extraInfo << "SFI:" << sfi << "h, "
77 << "COUNTER:" << mCounterNumber << ", ";
78 if (isDecreaseCommand) {
79 extraInfo << "DECREMENT";
80 } else {
81 extraInfo << "INCREMENT";
82 }
83 extraInfo << ":" << incDecValue;
84
85 addSubName(extraInfo.str());
86}
87
89{
90 return true;
91}
92
94{
95 return mSfi;
96}
97
99{
100 return mCounterNumber;
101}
102
104{
105 return mIncDecValue;
106}
107
108const std::map<const int, const std::shared_ptr<StatusProperties>>
109 CmdCardIncreaseOrDecrease::initStatusTable()
110{
111 std::map<const int, const std::shared_ptr<StatusProperties>> m =
113
114 m.insert({0x6400,
115 std::make_shared<StatusProperties>("Too many modifications in session.",
117 m.insert({0x6700,
118 std::make_shared<StatusProperties>("Lc value not supported.",
119 typeid(CardIllegalParameterException))});
120 m.insert({0x6981,
121 std::make_shared<StatusProperties>("The current EF is not a Counters or Simulated " \
122 "Counter EF.",
123 typeid(CardDataAccessException))});
124 m.insert({0x6982,
125 std::make_shared<StatusProperties>("Security conditions not fulfilled (no session, " \
126 "wrong key, encryption required).",
127 typeid(CardSecurityContextException))});
128 m.insert({0x6985,
129 std::make_shared<StatusProperties>("Access forbidden (Never access mode, DF is " \
130 "invalidated, etc.)",
131 typeid(CardAccessForbiddenException))});
132 m.insert({0x6986,
133 std::make_shared<StatusProperties>("Command not allowed (no current EF).",
134 typeid(CardDataAccessException))});
135 m.insert({0x6A80,
136 std::make_shared<StatusProperties>("Overflow error.",
137 typeid(CardDataOutOfBoundsException))});
138 m.insert({0x6A82,
139 std::make_shared<StatusProperties>("File not found.",
140 typeid(CardDataAccessException))});
141 m.insert({0x6B00,
142 std::make_shared<StatusProperties>("P1 or P2 value not supported.",
143 typeid(CardDataAccessException))});
144 m.insert({0x6103,
145 std::make_shared<StatusProperties>("Successful execution (possible only in ISO7816 " \
146 "T=0).",
147 typeid(nullptr))});
148
149 return m;
150}
151
152const std::map<const int, const std::shared_ptr<StatusProperties>>&
154{
155 return STATUS_TABLE;
156}
157
158}
159}
160}
static const std::map< const int, const std::shared_ptr< StatusProperties > > STATUS_TABLE
virtual void addSubName(const std::string &subName) final
virtual void setApduRequest(const std::shared_ptr< ApduRequestAdapter > apduRequest) final
const CalypsoCardCommand & getCommandRef() const override
CmdCardIncreaseOrDecrease(const bool isDecreaseCommand, const CalypsoCardClass calypsoCardClass, const uint8_t sfi, const uint8_t counterValue, const int incDecValue)
const std::map< const int, const std::shared_ptr< StatusProperties > > & getStatusTable() const override