Keyple Card Calypso C++ Library 2.1.0
Reference Terminal Reader API for C++
CmdCardUpdateRecord.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
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
38 const uint8_t sfi,
39 const uint8_t recordNumber,
40 const std::vector<uint8_t>& newRecordData)
41: AbstractCardCommand(mCommand),
42 mSfi(sfi),
43 mRecordNumber(recordNumber),
44 mData(newRecordData)
45{
46 const uint8_t cla = calypsoCardClass.getValue();
47 const uint8_t p2 = (sfi == 0) ? 0x04 : sfi * 8 + 4;
48
50 std::make_shared<ApduRequestAdapter>(
51 ApduUtil::build(cla,
52 mCommand.getInstructionByte(),
53 recordNumber,
54 p2,
55 newRecordData)));
56
57
58 std::stringstream extraInfo;
59 extraInfo << "SFI:" << sfi << "h, "
60 << "REC:" << recordNumber;
61
62 addSubName(extraInfo.str());
63}
64
66{
67 return true;
68}
69
71{
72 return mSfi;
73}
74
76{
77 return mRecordNumber;
78}
79
80const std::vector<uint8_t>& CmdCardUpdateRecord::getData() const
81{
82 return mData;
83}
84
85const std::map<const int, const std::shared_ptr<StatusProperties>>
86 CmdCardUpdateRecord::initStatusTable()
87{
88 std::map<const int, const std::shared_ptr<StatusProperties>> m =
90
91 m.insert({0x6400,
92 std::make_shared<StatusProperties>("Too many modifications in session.",
94 m.insert({0x6700,
95 std::make_shared<StatusProperties>("Lc value not supported.",
96 typeid(CardDataAccessException))});
97 m.insert({0x6981,
98 std::make_shared<StatusProperties>("Command forbidden on cyclic files when the " \
99 "record exists and is not record 01h and on " \
100 "binary files.",
101 typeid(CardDataAccessException))});
102 m.insert({0x6982,
103 std::make_shared<StatusProperties>("Security conditions not fulfilled (no session, " \
104 "wrong key, encryption required).",
105 typeid(CardSecurityContextException))});
106 m.insert({0x6985,
107 std::make_shared<StatusProperties>("Access forbidden (Never access mode, DF is " \
108 "invalidated, etc..).",
109 typeid(CardAccessForbiddenException))});
110 m.insert({0x6986,
111 std::make_shared<StatusProperties>("Command not allowed (no current EF).",
112 typeid(CardDataAccessException))});
113 m.insert({0x6A83,
114 std::make_shared<StatusProperties>("Record is not found (record index is 0 or " \
115 "above NumRec).",
116 typeid(CardDataAccessException))});
117 m.insert({0x6B00,
118 std::make_shared<StatusProperties>("P2 value not supported.",
119 typeid(CardIllegalParameterException))});
120
121 return m;
122}
123
124const std::map<const int, const std::shared_ptr<StatusProperties>>&
126{
127 return STATUS_TABLE;
128}
129
130}
131}
132}
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
static const CalypsoCardCommand UPDATE_RECORD
CmdCardUpdateRecord(const CalypsoCardClass calypsoCardClass, const uint8_t sfi, const uint8_t recordNumber, const std::vector< uint8_t > &newRecordData)
const std::vector< uint8_t > & getData() const
const std::map< const int, const std::shared_ptr< StatusProperties > > & getStatusTable() const override