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