Keyple Card Calypso C++ Library 2.1.0
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 mSfi(sfi),
49 mOffset(offset),
50 mData(data)
51{
52 const uint8_t msb = (offset & 0xFF00) >> 8;
53 const uint8_t lsb = (offset & 0xFF);
54
55 /*
56 * 100xxxxx : 'xxxxx' = SFI of the EF to select.
57 * 0xxxxxxx : 'xxxxxxx' = MSB of the offset of the first byte.
58 */
59 const uint8_t p1 = msb > 0 ? msb : 0x80 + sfi;
60
62 std::make_shared<ApduRequestAdapter>(
63 ApduUtil::build(calypsoCardClass.getValue(),
64 getCommandRef().getInstructionByte(),
65 p1,
66 lsb,
67 data)));
68
69
70
71 std::stringstream extraInfo;
72 extraInfo << "SFI:" << sfi << "h, "
73 << "OFFSET:" << offset;
74
75 addSubName(extraInfo.str());
76}
77
79{
80 return true;
81}
82
84{
85 return mSfi;
86}
87
89{
90 return mOffset;
91}
92
93const std::vector<uint8_t>& CmdCardUpdateOrWriteBinary::getData() const
94{
95 return mData;
96}
97
98const std::map<const int, const std::shared_ptr<StatusProperties>>
99 CmdCardUpdateOrWriteBinary::initStatusTable()
100{
101 std::map<const int, const std::shared_ptr<StatusProperties>> m =
103
104 m.insert({0x6400,
105 std::make_shared<StatusProperties>("Too many modifications in session",
107 m.insert({0x6700,
108 std::make_shared<StatusProperties>("Lc value not supported, or Offset+Lc > file size",
109 typeid(CardDataAccessException))});
110 m.insert({0x6981,
111 std::make_shared<StatusProperties>("Incorrect EF type: not a Binary EF",
112 typeid(CardDataAccessException))});
113 m.insert({0x6982,
114 std::make_shared<StatusProperties>("Security conditions not fulfilled (no secure " \
115 "session, incorrect key, encryption required, " \
116 "PKI mode and not Always access mode)",
117 typeid(CardSecurityContextException))});
118 m.insert({0x6985,
119 std::make_shared<StatusProperties>("Access forbidden (Never access mode, DF is " \
120 "invalidated, etc..)",
121 typeid(CardAccessForbiddenException))});
122 m.insert({0x6986,
123 std::make_shared<StatusProperties>("Incorrect file type: the Current File is not " \
124 "an EF. Supersedes 6981h",
125 typeid(CardDataAccessException))});
126 m.insert({0x6A82,
127 std::make_shared<StatusProperties>("File not found",
128 typeid(CardDataAccessException))});
129 m.insert({0x6A83,
130 std::make_shared<StatusProperties>("Offset not in the file (offset overflow)",
131 typeid(CardDataAccessException))});
132 m.insert({0x6B00,
133 std::make_shared<StatusProperties>("P1 value not supported",
134 typeid(CardIllegalParameterException))});
135
136 return m;
137}
138
139const std::map<const int, const std::shared_ptr<StatusProperties>>&
141{
142 return STATUS_TABLE;
143}
144
145}
146}
147}
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