Keyple Card Calypso C++ Library 2.2.2
Reference Terminal Reader API for C++
CmdCardUpdateOrWriteBinary.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#include "System.h"
21
22/* Keyple Card Calypso */
29
30namespace keyple {
31namespace card {
32namespace calypso {
33
34using namespace keyple::core::util;
35using namespace keyple::core::util::cpp;
36
37const std::map<const int, const std::shared_ptr<StatusProperties>>
38 CmdCardUpdateOrWriteBinary::STATUS_TABLE = initStatusTable();
39
41 const bool isUpdateCommand,
42 const CalypsoCardClass calypsoCardClass,
43 const uint8_t sfi,
44 const uint8_t offset,
45 const std::vector<uint8_t>& data)
46: AbstractCardCommand(isUpdateCommand ? CalypsoCardCommand::UPDATE_BINARY :
47 CalypsoCardCommand::WRITE_BINARY,
48 0),
49 mSfi(sfi),
50 mOffset(offset),
51 mData(data)
52{
53 const uint8_t msb = (offset & 0xFF00) >> 8;
54 const uint8_t lsb = (offset & 0xFF);
55
56 /*
57 * 100xxxxx : 'xxxxx' = SFI of the EF to select.
58 * 0xxxxxxx : 'xxxxxxx' = MSB of the offset of the first byte.
59 */
60 const uint8_t p1 = msb > 0 ? msb : 0x80 + sfi;
61
63 std::make_shared<ApduRequestAdapter>(
64 ApduUtil::build(calypsoCardClass.getValue(),
65 getCommandRef().getInstructionByte(),
66 p1,
67 lsb,
68 data)));
69
70
71
72 std::stringstream extraInfo;
73 extraInfo << "SFI:" << sfi << "h, "
74 << "OFFSET:" << offset;
75
76 addSubName(extraInfo.str());
77}
78
80{
81 return true;
82}
83
85{
86 return mSfi;
87}
88
90{
91 return mOffset;
92}
93
94const std::vector<uint8_t>& CmdCardUpdateOrWriteBinary::getData() const
95{
96 return mData;
97}
98
99const std::map<const int, const std::shared_ptr<StatusProperties>>
100 CmdCardUpdateOrWriteBinary::initStatusTable()
101{
102 std::map<const int, const std::shared_ptr<StatusProperties>> m =
104
105 m.insert({0x6400,
106 std::make_shared<StatusProperties>("Too many modifications in session",
108 m.insert({0x6700,
109 std::make_shared<StatusProperties>("Lc value not supported, or Offset+Lc > file size",
110 typeid(CardDataAccessException))});
111 m.insert({0x6981,
112 std::make_shared<StatusProperties>("Incorrect EF type: not a Binary EF",
113 typeid(CardDataAccessException))});
114 m.insert({0x6982,
115 std::make_shared<StatusProperties>("Security conditions not fulfilled (no secure " \
116 "session, incorrect key, encryption required, " \
117 "PKI mode and not Always access mode)",
118 typeid(CardSecurityContextException))});
119 m.insert({0x6985,
120 std::make_shared<StatusProperties>("Access forbidden (Never access mode, DF is " \
121 "invalidated, etc..)",
122 typeid(CardAccessForbiddenException))});
123 m.insert({0x6986,
124 std::make_shared<StatusProperties>("Incorrect file type: the Current File is not " \
125 "an EF. Supersedes 6981h",
126 typeid(CardDataAccessException))});
127 m.insert({0x6A82,
128 std::make_shared<StatusProperties>("File not found",
129 typeid(CardDataAccessException))});
130 m.insert({0x6A83,
131 std::make_shared<StatusProperties>("Offset not in the file (offset overflow)",
132 typeid(CardDataAccessException))});
133 m.insert({0x6B00,
134 std::make_shared<StatusProperties>("P1 value not supported",
135 typeid(CardIllegalParameterException))});
136
137 return m;
138}
139
140const std::map<const int, const std::shared_ptr<StatusProperties>>&
142{
143 return STATUS_TABLE;
144}
145
146}
147}
148}
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
const CalypsoCardCommand & getCommandRef() const override
CmdCardUpdateOrWriteBinary(const bool isUpdateCommand, const CalypsoCardClass calypsoCardClass, const uint8_t sfi, const uint8_t offset, const std::vector< uint8_t > &data)
const std::map< const int, const std::shared_ptr< StatusProperties > > & getStatusTable() const override