Keyple Card Calypso C++ Library 2.2.5.6
Reference Terminal Reader API for C++
CmdCardReadBinary.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 "CmdCardReadBinary.h"
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 CmdCardReadBinary::STATUS_TABLE = initStatusTable();
39
40CmdCardReadBinary::CmdCardReadBinary(const std::shared_ptr<CalypsoCardAdapter> calypsoCard,
41 const uint8_t sfi,
42 const int offset,
43 const int length)
44: AbstractCardCommand(CalypsoCardCommand::READ_BINARY, length, calypsoCard),
45 mSfi(sfi),
46 mOffset(offset)
47{
48 const uint8_t msb = ((offset & 0xFF00) >> 8);
49 const uint8_t lsb = (offset & 0xFF);
50
51 /*
52 * 100xxxxx : 'xxxxx' = SFI of the EF to select.
53 * 0xxxxxxx : 'xxxxxxx' = MSB of the offset of the first byte.
54 */
55 const uint8_t p1 = msb > 0 ? msb : 0x80 + mSfi;
56
57 // APDU Case 2
59 std::make_shared<ApduRequestAdapter>(
60 ApduUtil::build(
61 calypsoCard->getCardClass().getValue(),
62 getCommandRef().getInstructionByte(),
63 p1,
64 lsb,
65 static_cast<uint8_t>(length))));
66
67 std::stringstream extraInfo;
68 extraInfo << "SFI:" << sfi << "h, "
69 << "OFFSET:" << offset << ", "
70 << "LENGTH:" << length;
71
72 addSubName(extraInfo.str());
73}
74
75void CmdCardReadBinary::parseApduResponse(const std::shared_ptr<ApduResponseApi> apduResponse)
76{
78
79 getCalypsoCard()->setContent(mSfi, 1, apduResponse->getDataOut(), mOffset);
80}
81
83{
84 return false;
85}
86
88{
89 return mOffset;
90}
91
92const std::map<const int, const std::shared_ptr<StatusProperties>>
93 CmdCardReadBinary::initStatusTable()
94{
95 std::map<const int, const std::shared_ptr<StatusProperties>> m =
97
98 m.insert({0x6981,
99 std::make_shared<StatusProperties>("Incorrect EF type: not a Binary EF.",
100 typeid(CardDataAccessException))});
101 m.insert({0x6982,
102 std::make_shared<StatusProperties>("Security conditions not fulfilled (PIN code " \
103 "not presented, encryption required).",
104 typeid(CardSecurityContextException))});
105 m.insert({0x6985,
106 std::make_shared<StatusProperties>("Access forbidden (Never access mode).",
107 typeid(CardAccessForbiddenException))});
108 m.insert({0x6986,
109 std::make_shared<StatusProperties>("Incorrect file type: the Current File is not " \
110 "an EF. Supersedes 6981h.",
111 typeid(CardDataAccessException))});
112 m.insert({0x6A82,
113 std::make_shared<StatusProperties>("File not found",
114 typeid(CardDataAccessException))});
115 m.insert({0x6A83,
116 std::make_shared<StatusProperties>("Offset not in the file (offset overflow).",
117 typeid(CardDataAccessException))});
118 m.insert({0x6B00,
119 std::make_shared<StatusProperties>("P1 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
void parseApduResponse(const std::shared_ptr< ApduResponseApi > apduResponse) override
const CalypsoCardCommand & getCommandRef() const override
std::shared_ptr< CalypsoCardAdapter > getCalypsoCard() const
void parseApduResponse(const std::shared_ptr< ApduResponseApi > apduResponse) override
const std::map< const int, const std::shared_ptr< StatusProperties > > & getStatusTable() const override
CmdCardReadBinary(const std::shared_ptr< CalypsoCardAdapter > calypsoCard, const uint8_t sfi, const int offset, const int length)