Keyple Card Calypso C++ Library 2.1.0
Reference Terminal Reader API for C++
CmdCardWriteRecord.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 "CmdCardWriteRecord.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 CmdCardWriteRecord::mCommand = CalypsoCardCommand::WRITE_RECORD;
34const std::map<const int, const std::shared_ptr<StatusProperties>>
35 CmdCardWriteRecord::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 mRecordNumber,
54 p2,
55 newRecordData)));
56
57 std::stringstream extraInfo;
58 extraInfo << "SFI:" << sfi << "h, "
59 << "REC:" << recordNumber;
60
61 addSubName(extraInfo.str());
62}
63
65{
66 return true;
67}
68
70{
71 return mSfi;
72}
73
75{
76 return mRecordNumber;
77}
78
79const std::vector<uint8_t>& CmdCardWriteRecord::getData() const
80{
81 return mData;
82}
83
84const std::map<const int, const std::shared_ptr<StatusProperties>>
85 CmdCardWriteRecord::initStatusTable()
86{
87 std::map<const int, const std::shared_ptr<StatusProperties>> m =
89
90 m.insert({0x6400,
91 std::make_shared<StatusProperties>("Too many modifications in session.",
93 m.insert({0x6700,
94 std::make_shared<StatusProperties>("Lc value not supported.",
95 typeid(CardDataAccessException))});
96 m.insert({0x6981,
97 std::make_shared<StatusProperties>("Wrong EF type (not a Linear EF, or Cyclic EF " \
98 "with Record Number 01h).",
99 typeid(CardDataAccessException))});
100 m.insert({0x6982,
101 std::make_shared<StatusProperties>("Security conditions not fulfilled (no session, " \
102 "wrong key, encryption required).",
103 typeid(CardSecurityContextException))});
104 m.insert({0x6985,
105 std::make_shared<StatusProperties>("Access forbidden (Never access mode, DF is " \
106 "invalidated, etc..).",
107 typeid(CardAccessForbiddenException))});
108 m.insert({0x6986,
109 std::make_shared<StatusProperties>("Command not allowed (no current EF).",
110 typeid(CardDataAccessException))});
111 m.insert({0x6A82,
112 std::make_shared<StatusProperties>("File not found.",
113 typeid(CardDataAccessException))});
114 m.insert({0x6A83,
115 std::make_shared<StatusProperties>("Record is not found (record index is 0 or " \
116 "above NumRec).",
117 typeid(CardDataAccessException))});
118 m.insert({0x6B00,
119 std::make_shared<StatusProperties>("P2 value not supported.",
120 typeid(CardIllegalParameterException))});
121
122 return m;
123}
124
125const std::map<const int, const std::shared_ptr<StatusProperties>>&
127{
128 return STATUS_TABLE;
129}
130
131}
132}
133}
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 WRITE_RECORD
const std::map< const int, const std::shared_ptr< StatusProperties > > & getStatusTable() const override
const std::vector< uint8_t > & getData() const
CmdCardWriteRecord(const CalypsoCardClass calypsoCardClass, const uint8_t sfi, const uint8_t recordNumber, const std::vector< uint8_t > &newRecordData)