blob: 0009e1cdcd73c5d9040a1a89551f6eac91478048 [file] [log] [blame]
Prithvi Pai5af42bb2025-02-11 17:59:07 +05301#include "tpm.hpp"
2
3#include "mdrv2.hpp"
4
5#include <fstream>
6#include <iomanip>
7#include <iostream>
8#include <sstream>
9
10namespace phosphor
11{
12namespace smbios
13{
14
15void Tpm::tpmInfoUpdate(uint8_t* smbiosTableStorage,
16 const std::string& motherboard)
17{
18 storage = smbiosTableStorage;
19 motherboardPath = motherboard;
20
21 uint8_t* dataIn = storage;
22 dataIn = getSMBIOSTypePtr(dataIn, tpmDeviceType);
23 if (dataIn == nullptr)
24 {
25 return;
26 }
27 for (uint8_t index = 0; index < tpmId; index++)
28 {
29 dataIn = smbiosNextPtr(dataIn);
30 if (dataIn == nullptr)
31 {
32 return;
33 }
34 dataIn = getSMBIOSTypePtr(dataIn, tpmDeviceType);
35 if (dataIn == nullptr)
36 {
37 return;
38 }
39 }
40 auto tpmInfo = reinterpret_cast<struct TPMInfo*>(dataIn);
41
42 present(true);
43 purpose(softwareversion::VersionPurpose::Other);
44 tpmVendor(tpmInfo);
45 tpmFirmwareVersion(tpmInfo);
46 tpmDescription(tpmInfo->description, tpmInfo->length, dataIn);
Prithvi Pai6a84b4c2025-05-02 12:41:21 +053047 trustedComponentType(trustedComponent::ComponentAttachType::Discrete);
Prithvi Pai5af42bb2025-02-11 17:59:07 +053048}
49
50void Tpm::tpmVendor(const struct TPMInfo* tpmInfo)
51{
52 constexpr int vendorIdLength = 4;
53 // Specified as four ASCII characters, as defined by TCG Vendor ID
54 char vendorId[vendorIdLength + 1];
55 int i;
56 for (i = 0; i < vendorIdLength && tpmInfo->vendor[i] != '\0'; i++)
57 {
58 if (std::isprint(tpmInfo->vendor[i]))
59 {
60 vendorId[i] = tpmInfo->vendor[i];
61 }
62 else
63 {
64 vendorId[i] = '.';
65 }
66 }
67 vendorId[i] = '\0';
68 manufacturer(vendorId);
69}
70
71void Tpm::tpmFirmwareVersion(const struct TPMInfo* tpmInfo)
72{
73 std::stringstream stream;
74
75 if (tpmInfo->specMajor == tpmMajorVerion1)
76 {
77 auto ver = reinterpret_cast<const struct TPMVersionSpec1*>(
78 &tpmInfo->firmwareVersion1);
79 stream << ver->revMajor << "." << ver->revMinor;
80 }
81 else if (tpmInfo->specMajor == tpmMajorVerion2)
82 {
83 auto ver = reinterpret_cast<const struct TPMVersionSpec2*>(
84 &tpmInfo->firmwareVersion1);
85 stream << ver->revMajor << "." << ver->revMinor;
86 }
87 version(stream.str());
88}
89
90void Tpm::tpmDescription(const uint8_t positionNum, const uint8_t structLen,
91 uint8_t* dataIn)
92{
93 std::string result = positionToString(positionNum, structLen, dataIn);
94 prettyName(result);
95}
96} // namespace smbios
97} // namespace phosphor