Keyple Card Calypso C++ Library 2.1.0
Reference Terminal Reader API for C++
CmdCardGetDataEfList.cpp
Go to the documentation of this file.
1/**************************************************************************************************
2 * Copyright (c) 2022 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/* Keyple Card Calypso */
16#include "ApduRequestAdapter.h"
17#include "CalypsoCardConstant.h"
19#include "FileHeaderAdapter.h"
20
21/* Keyple Core Util */
22#include "ApduUtil.h"
23#include "Arrays.h"
24#include "IllegalStateException.h"
25
26namespace keyple {
27namespace card {
28namespace calypso {
29
30using namespace keyple::core::util;
31using namespace keyple::core::util::cpp;
32
33const int CmdCardGetDataEfList::DESCRIPTORS_OFFSET = 2;
34const int CmdCardGetDataEfList::DESCRIPTOR_DATA_OFFSET = 2;
35const int CmdCardGetDataEfList::DESCRIPTOR_DATA_SFI_OFFSET = 2;
36const int CmdCardGetDataEfList::DESCRIPTOR_TAG_LENGTH = 8;
37const int CmdCardGetDataEfList::DESCRIPTOR_DATA_LENGTH = 6;
38const CalypsoCardCommand CmdCardGetDataEfList::mCommand = CalypsoCardCommand::GET_DATA;
39const std::map<const int, const std::shared_ptr<StatusProperties>>
40 CmdCardGetDataEfList::STATUS_TABLE = initStatusTable();
41
43: AbstractCardCommand(mCommand)
44{
46 std::make_shared<ApduRequestAdapter>(
47 ApduUtil::build(calypsoCardClass.getValue(),
48 mCommand.getInstructionByte(),
49 0x00,
50 0xC0,
51 0x00)));
52}
53
55{
56 return false;
57}
58
59const std::map<const int, const std::shared_ptr<StatusProperties>>
60 CmdCardGetDataEfList::initStatusTable()
61{
62 std::map<const int, const std::shared_ptr<StatusProperties>> m =
64
65 m.insert({0x6A88,
66 std::make_shared<StatusProperties>("Data object not found (optional mode not " \
67 "available).",
68 typeid(CardDataAccessException))});
69 m.insert({0x6B00,
70 std::make_shared<StatusProperties>("P1 or P2 value not supported.",
71 typeid(CardDataAccessException))});
72
73 return m;
74}
75
76const std::map<const int, const std::shared_ptr<StatusProperties>>&
78{
79 return STATUS_TABLE;
80}
81
82const std::map<const std::shared_ptr<FileHeaderAdapter>, const uint8_t>
84{
85 const std::vector<uint8_t> rawList = getApduResponse()->getDataOut();
86 std::map<const std::shared_ptr<FileHeaderAdapter>, const uint8_t> fileHeaderToSfiMap;
87 const int nbFiles = rawList[1] / DESCRIPTOR_TAG_LENGTH;
88
89 for (int i = 0; i < nbFiles; i++) {
90 fileHeaderToSfiMap.insert({
91 createFileHeader(
92 Arrays::copyOfRange(
93 rawList,
94 DESCRIPTORS_OFFSET + (i * DESCRIPTOR_TAG_LENGTH) + DESCRIPTOR_DATA_OFFSET,
95 DESCRIPTORS_OFFSET
96 + (i * DESCRIPTOR_TAG_LENGTH)
97 + DESCRIPTOR_DATA_OFFSET
98 + DESCRIPTOR_DATA_LENGTH)),
99 rawList[
100 DESCRIPTORS_OFFSET
101 + (i * DESCRIPTOR_TAG_LENGTH)
102 + DESCRIPTOR_DATA_OFFSET
103 + DESCRIPTOR_DATA_SFI_OFFSET]});
104 }
105
106 return fileHeaderToSfiMap;
107}
108
109const std::shared_ptr<FileHeaderAdapter> CmdCardGetDataEfList::createFileHeader(
110 const std::vector<uint8_t>& efDescriptorByteArray) const
111{
112 ElementaryFile::Type efType;
113
114 if (efDescriptorByteArray[3] == CalypsoCardConstant::EF_TYPE_LINEAR) {
115 efType = ElementaryFile::Type::LINEAR;
116 } else if (efDescriptorByteArray[3] == CalypsoCardConstant::EF_TYPE_CYCLIC) {
117 efType = ElementaryFile::Type::CYCLIC;
118 } else if (efDescriptorByteArray[3] == CalypsoCardConstant::EF_TYPE_COUNTERS) {
119 efType = ElementaryFile::Type::COUNTERS;
120 } else if (efDescriptorByteArray[3] == CalypsoCardConstant::EF_TYPE_BINARY) {
121 efType = ElementaryFile::Type::BINARY;
122 } else if (efDescriptorByteArray[3] == CalypsoCardConstant::EF_TYPE_SIMULATED_COUNTERS) {
123 efType = ElementaryFile::Type::SIMULATED_COUNTERS;
124 } else {
125 throw IllegalStateException("Unexpected EF type");
126 }
127
129 ->lid(efDescriptorByteArray[0] << 8 | (efDescriptorByteArray[1] & 0xFF))
130 .type(efType)
131 .recordSize(efDescriptorByteArray[4])
132 .recordsNumber(efDescriptorByteArray[5])
133 .build();
134}
135
136}
137}
138}
static const std::map< const int, const std::shared_ptr< StatusProperties > > STATUS_TABLE
virtual const std::shared_ptr< ApduResponseApi > getApduResponse() const final
virtual void setApduRequest(const std::shared_ptr< ApduRequestAdapter > apduRequest) final
static const CalypsoCardCommand GET_DATA
CmdCardGetDataEfList(const CalypsoCardClass calypsoCardClass)
const std::map< const int, const std::shared_ptr< StatusProperties > > & getStatusTable() const override
const std::map< const std::shared_ptr< FileHeaderAdapter >, const uint8_t > getEfHeaders() const
static std::shared_ptr< FileHeaderBuilder > builder()