Keyple Card Calypso C++ Library 2.2.5.6
Reference Terminal Reader API for C++
CmdCardUpdateRecord.cpp
Go to the documentation of this file.
1/**************************************************************************************************
2 * Copyright (c) 2023 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 "CmdCardUpdateRecord.h"
14
15#include <sstream>
16
17/* Keyple Core Util */
18#include "ApduUtil.h"
19
20/* Keyple Card Calypso */
26
27namespace keyple {
28namespace card {
29namespace calypso {
30
31using namespace keyple::core::util;
32
33const CalypsoCardCommand CmdCardUpdateRecord::mCommand = CalypsoCardCommand::UPDATE_RECORD;
34const std::map<const int, const std::shared_ptr<StatusProperties>>
35 CmdCardUpdateRecord::STATUS_TABLE = initStatusTable();
36
37CmdCardUpdateRecord::CmdCardUpdateRecord(const std::shared_ptr<CalypsoCardAdapter> calypsoCard,
38 const uint8_t sfi,
39 const uint8_t recordNumber,
40 const std::vector<uint8_t>& newRecordData)
41: AbstractCardCommand(mCommand, 0, calypsoCard),
42 mSfi(sfi),
43 mRecordNumber(recordNumber),
44 mData(newRecordData)
45{
46 const uint8_t cla = calypsoCard->getCardClass().getValue();
47 const uint8_t p2 = (sfi == 0) ? 0x04 : sfi * 8 + 4;
48
49 // APDU Case 3
51 std::make_shared<ApduRequestAdapter>(
52 ApduUtil::build(cla,
53 mCommand.getInstructionByte(),
54 recordNumber,
55 p2,
56 newRecordData)));
57
58
59 std::stringstream extraInfo;
60 extraInfo << "SFI:" << sfi << "h, "
61 << "REC:" << recordNumber;
62
63 addSubName(extraInfo.str());
64}
65
66void CmdCardUpdateRecord::parseApduResponse(const std::shared_ptr<ApduResponseApi> apduResponse)
67{
69
70 getCalypsoCard()->setContent(mSfi, mRecordNumber, mData);
71}
72
74{
75 return true;
76}
77
78const std::map<const int, const std::shared_ptr<StatusProperties>>
79 CmdCardUpdateRecord::initStatusTable()
80{
81 std::map<const int, const std::shared_ptr<StatusProperties>> m =
83
84 m.insert({0x6400,
85 std::make_shared<StatusProperties>("Too many modifications in session.",
87 m.insert({0x6700,
88 std::make_shared<StatusProperties>("Lc value not supported.",
89 typeid(CardDataAccessException))});
90 m.insert({0x6981,
91 std::make_shared<StatusProperties>("Command forbidden on cyclic files when the " \
92 "record exists and is not record 01h and on " \
93 "binary files.",
94 typeid(CardDataAccessException))});
95 m.insert({0x6982,
96 std::make_shared<StatusProperties>("Security conditions not fulfilled (no session, " \
97 "wrong key, encryption required).",
98 typeid(CardSecurityContextException))});
99 m.insert({0x6985,
100 std::make_shared<StatusProperties>("Access forbidden (Never access mode, DF is " \
101 "invalidated, etc..).",
102 typeid(CardAccessForbiddenException))});
103 m.insert({0x6986,
104 std::make_shared<StatusProperties>("Command not allowed (no current EF).",
105 typeid(CardDataAccessException))});
106 m.insert({0x6A83,
107 std::make_shared<StatusProperties>("Record is not found (record index is 0 or " \
108 "above NumRec).",
109 typeid(CardDataAccessException))});
110 m.insert({0x6B00,
111 std::make_shared<StatusProperties>("P2 value not supported.",
112 typeid(CardIllegalParameterException))});
113
114 return m;
115}
116
117const std::map<const int, const std::shared_ptr<StatusProperties>>&
119{
120 return STATUS_TABLE;
121}
122
123}
124}
125}
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
void parseApduResponse(const std::shared_ptr< ApduResponseApi > apduResponse) override
std::shared_ptr< CalypsoCardAdapter > getCalypsoCard() const
static const CalypsoCardCommand UPDATE_RECORD
void parseApduResponse(const std::shared_ptr< ApduResponseApi > apduResponse) override
CmdCardUpdateRecord(const std::shared_ptr< CalypsoCardAdapter > calypsoCard, const uint8_t sfi, const uint8_t recordNumber, const std::vector< uint8_t > &newRecordData)
const std::map< const int, const std::shared_ptr< StatusProperties > > & getStatusTable() const override