Keyple Card Calypso C++ Library 2.1.0
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 : CalypsoCardCommand::INCREASE),
46 mSfi(sfi),
47 mCounterNumber(counterNumber),
48 mIncDecValue(incDecValue)
49{
50 const uint8_t cla = calypsoCardClass.getValue();
51
52 /*
53 * Convert the integer value into a 3-byte buffer
54 * CL-COUN-DATAIN.1
55 */
56 std::vector<uint8_t> valueBuffer(3);
57 valueBuffer[0] = ((incDecValue >> 16) & 0xFF);
58 valueBuffer[1] = ((incDecValue >> 8) & 0xFF);
59 valueBuffer[2] = (incDecValue & 0xFF);
60
61 const uint8_t p2 = sfi * 8;
62
63 /* This is a case4 command, we set Le = 0 */
65 std::make_shared<ApduRequestAdapter>(
66 ApduUtil::build(cla,
67 getCommandRef().getInstructionByte(),
68 mCounterNumber,
69 p2,
70 valueBuffer,
71 0x00)));
72
73 std::stringstream extraInfo;
74 extraInfo << "SFI:" << sfi << "h, "
75 << "COUNTER:" << mCounterNumber << ", ";
76 if (isDecreaseCommand) {
77 extraInfo << "DECREMENT";
78 } else {
79 extraInfo << "INCREMENT";
80 }
81 extraInfo << ":" << incDecValue;
82
83 addSubName(extraInfo.str());
84}
85
87{
88 return true;
89}
90
92{
93 return mSfi;
94}
95
97{
98 return mCounterNumber;
99}
100
102{
103 return mIncDecValue;
104}
105
106const std::map<const int, const std::shared_ptr<StatusProperties>>
107 CmdCardIncreaseOrDecrease::initStatusTable()
108{
109 std::map<const int, const std::shared_ptr<StatusProperties>> m;
110
111 m.insert({0x6400,
112 std::make_shared<StatusProperties>("Too many modifications in session.",
114 m.insert({0x6700,
115 std::make_shared<StatusProperties>("Lc value not supported.",
116 typeid(CardIllegalParameterException))});
117 m.insert({0x6981,
118 std::make_shared<StatusProperties>("The current EF is not a Counters or Simulated " \
119 "Counter EF.",
120 typeid(CardDataAccessException))});
121 m.insert({0x6982,
122 std::make_shared<StatusProperties>("Security conditions not fulfilled (no session, " \
123 "wrong key, encryption required).",
124 typeid(CardSecurityContextException))});
125 m.insert({0x6985,
126 std::make_shared<StatusProperties>("Access forbidden (Never access mode, DF is " \
127 "invalidated, etc.)",
128 typeid(CardAccessForbiddenException))});
129 m.insert({0x6986,
130 std::make_shared<StatusProperties>("Command not allowed (no current EF).",
131 typeid(CardDataAccessException))});
132 m.insert({0x6A80,
133 std::make_shared<StatusProperties>("Overflow error.",
134 typeid(CardDataOutOfBoundsException))});
135 m.insert({0x6A82,
136 std::make_shared<StatusProperties>("File not found.",
137 typeid(CardDataAccessException))});
138 m.insert({0x6B00,
139 std::make_shared<StatusProperties>("P1 or P2 value not supported.",
140 typeid(CardDataAccessException))});
141 m.insert({0x6103,
142 std::make_shared<StatusProperties>("Successful execution (possible only in ISO7816 " \
143 "T=0).",
144 typeid(nullptr))});
145
146 return m;
147}
148
149const std::map<const int, const std::shared_ptr<StatusProperties>>&
151{
152 return STATUS_TABLE;
153}
154
155}
156}
157}
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