Keyple Card Calypso C++ Library - 3.2.2
Component of the Keyple C++ middleware
CommandGetDataFcp.cpp
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (c) 2025 Calypso Networks Association https://calypsonet.org/ *
3 * *
4 * See the NOTICE file(s) distributed with this work for additional *
5 * information regarding copyright ownership. *
6 * *
7 * This program and the accompanying materials are made available under the *
8 * terms of the Eclipse Public License 2.0 which is available at *
9 * http://www.eclipse.org/legal/epl-2.0 *
10 * *
11 * SPDX-License-Identifier: EPL-2.0 *
12 ******************************************************************************/
13
14#include "keyple/card/calypso/CommandGetDataFcp.hpp"
15
16#include <map>
17#include <memory>
18
19#include "keyple/card/calypso/CalypsoCardAdapter.hpp"
20#include "keyple/card/calypso/CalypsoCardClass.hpp"
21#include "keyple/card/calypso/CalypsoCardConstant.hpp"
22#include "keyple/card/calypso/CardCommandRef.hpp"
23#include "keyple/card/calypso/CardDataAccessException.hpp"
24#include "keyple/card/calypso/CommandSelectFile.hpp"
25#include "keyple/core/util/ApduUtil.hpp"
26#include "keyple/core/util/BerTlvUtil.hpp"
27#include "keyple/core/util/HexUtil.hpp"
28
29namespace keyple {
30namespace card {
31namespace calypso {
32
33using keyple::core::util::ApduUtil;
34using keyple::core::util::BerTlvUtil;
35using keyple::core::util::HexUtil;
36
37const std::map<int, const std::shared_ptr<Command::StatusProperties>>
38 CommandGetDataFcp::STATUS_TABLE = [] {
39 std::map<int, const std::shared_ptr<Command::StatusProperties>> m(
40 Command::STATUS_TABLE);
41
42 m.insert(
43 {{0x6A88,
44 std::make_shared<StatusProperties>(
45 "Data object not found (optional mode not "
46 "available)",
47 typeid(CardDataAccessException))},
48 {0x6A82,
49 std::make_shared<StatusProperties>(
50 "File not found", typeid(CardDataAccessException))},
51 {0x6B00,
52 std::make_shared<StatusProperties>(
53 "P1 or P2 value not supported",
54 typeid(CardDataAccessException))}});
55 return m;
56 }();
57
58CommandGetDataFcp::CommandGetDataFcp(
59 const std::shared_ptr<DtoAdapters::TransactionContextDto>&
60 transactionContext,
61 const std::shared_ptr<DtoAdapters::CommandContextDto>& commandContext)
62: Command(CardCommandRef::GET_DATA, nullptr, transactionContext, commandContext)
63{
64 const std::uint8_t cardClass
65 = transactionContext->getCard() != nullptr
66 ? transactionContext->getCard()->getCardClass().getValue()
67 : CalypsoCardClass::ISO.getValue();
68
69 /* APDU Case 2 - always outside secure session */
70 setApduRequest(
71 std::make_shared<DtoAdapters::ApduRequestAdapter>(ApduUtil::build(
72 cardClass,
73 getCommandRef().getInstructionByte(),
74 CalypsoCardConstant::TAG_FCP_FOR_CURRENT_FILE_MSB,
75 CalypsoCardConstant::TAG_FCP_FOR_CURRENT_FILE_LSB,
76 0x00)));
77
78 addSubName("FCP_FOR_CURRENT_FILE");
79}
80
81void
82CommandGetDataFcp::finalizeRequest()
83{
84 /* NOP */
85}
86
87bool
88CommandGetDataFcp::isCryptoServiceRequiredToFinalizeRequest() const
89{
90 return false;
91}
92
93bool
94CommandGetDataFcp::synchronizeCryptoServiceBeforeCardProcessing()
95{
96 return true;
97}
98
99void
100CommandGetDataFcp::parseResponse(std::shared_ptr<ApduResponseApi> apduResponse)
101{
102 Command::setApduResponseAndCheckStatus(apduResponse);
103
104 CommandSelectFile::parseProprietaryInformation(
105 apduResponse->getDataOut(), getTransactionContext()->getCard());
106}
107
108const std::map<int, const std::shared_ptr<Command::StatusProperties>>&
109CommandGetDataFcp::getStatusTable() const
110{
111 return STATUS_TABLE;
112}
113
114} /* namespace calypso */
115} /* namespace card */
116} /* namespace keyple */