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