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