bios_table.cpp (29683b53872f96e68df2255be118c15997196b14) bios_table.cpp (d965934f04f9d9e0edd13f8bba1207fb2936712c)
1#include "bios_table.hpp"
2
3#include <fstream>
4
5#include "bios_table.h"
6
7namespace pldm
8{

--- 68 unchanged lines hidden (view full) ---

77 }
78
79 return table::string::decodeHandle(stringEntry);
80}
81
82namespace table
83{
84
1#include "bios_table.hpp"
2
3#include <fstream>
4
5#include "bios_table.h"
6
7namespace pldm
8{

--- 68 unchanged lines hidden (view full) ---

77 }
78
79 return table::string::decodeHandle(stringEntry);
80}
81
82namespace table
83{
84
85void appendPadAndChecksum(Table& table)
86{
87 auto sizeWithoutPad = table.size();
88 auto padAndChecksumSize = pldm_bios_table_pad_checksum_size(sizeWithoutPad);
89 table.resize(table.size() + padAndChecksumSize);
90
91 pldm_bios_table_append_pad_checksum(table.data(), table.size(),
92 sizeWithoutPad);
93}
94
85namespace string
86{
87
88uint16_t decodeHandle(const pldm_bios_string_table_entry* entry)
89{
90 return pldm_bios_table_string_entry_decode_handle(entry);
91}
92
93std::string decodeString(const pldm_bios_string_table_entry* entry)
94{
95 auto strLength = pldm_bios_table_string_entry_decode_string_length(entry);
96 std::vector<char> buffer(strLength + 1 /* sizeof '\0' */);
97 pldm_bios_table_string_entry_decode_string(entry, buffer.data(),
98 buffer.size());
99 return std::string(buffer.data(), buffer.data() + strLength);
100}
95namespace string
96{
97
98uint16_t decodeHandle(const pldm_bios_string_table_entry* entry)
99{
100 return pldm_bios_table_string_entry_decode_handle(entry);
101}
102
103std::string decodeString(const pldm_bios_string_table_entry* entry)
104{
105 auto strLength = pldm_bios_table_string_entry_decode_string_length(entry);
106 std::vector<char> buffer(strLength + 1 /* sizeof '\0' */);
107 pldm_bios_table_string_entry_decode_string(entry, buffer.data(),
108 buffer.size());
109 return std::string(buffer.data(), buffer.data() + strLength);
110}
111const pldm_bios_string_table_entry* constructEntry(Table& table,
112 const std::string& str)
113{
114 auto tableSize = table.size();
115 auto entryLength = pldm_bios_table_string_entry_encode_length(str.length());
116 table.resize(tableSize + entryLength);
117 pldm_bios_table_string_entry_encode(table.data() + tableSize, entryLength,
118 str.c_str(), str.length());
119 return reinterpret_cast<pldm_bios_string_table_entry*>(table.data() +
120 tableSize);
121}
101
102} // namespace string
103
104namespace attribute
105{
106
107TableHeader decodeHeader(const pldm_bios_attr_table_entry* entry)
108{
109 auto attrHandle = pldm_bios_table_attr_entry_decode_attribute_handle(entry);
110 auto attrType = pldm_bios_table_attr_entry_decode_attribute_type(entry);
111 auto stringHandle = pldm_bios_table_attr_entry_decode_string_handle(entry);
112 return {attrHandle, attrType, stringHandle};
113}
114
122
123} // namespace string
124
125namespace attribute
126{
127
128TableHeader decodeHeader(const pldm_bios_attr_table_entry* entry)
129{
130 auto attrHandle = pldm_bios_table_attr_entry_decode_attribute_handle(entry);
131 auto attrType = pldm_bios_table_attr_entry_decode_attribute_type(entry);
132 auto stringHandle = pldm_bios_table_attr_entry_decode_string_handle(entry);
133 return {attrHandle, attrType, stringHandle};
134}
135
136const pldm_bios_attr_table_entry* findByHandle(const Table& table,
137 uint16_t handle)
138{
139 return pldm_bios_table_attr_find_by_handle(table.data(), table.size(),
140 handle);
141}
142
115const pldm_bios_attr_table_entry*
116 constructStringEntry(Table& table,
117 pldm_bios_table_attr_entry_string_info* info)
118{
119 auto entryLength =
120 pldm_bios_table_attr_entry_string_encode_length(info->def_length);
121
122 auto tableSize = table.size();

--- 51 unchanged lines hidden (view full) ---

174 auto tableSize = table.size();
175 table.resize(tableSize + entryLength);
176 pldm_bios_table_attr_value_entry_encode_string(
177 table.data() + tableSize, entryLength, attrHandle, attrType, strLen,
178 str.c_str());
179 return reinterpret_cast<pldm_bios_attr_val_table_entry*>(table.data() +
180 tableSize);
181}
143const pldm_bios_attr_table_entry*
144 constructStringEntry(Table& table,
145 pldm_bios_table_attr_entry_string_info* info)
146{
147 auto entryLength =
148 pldm_bios_table_attr_entry_string_encode_length(info->def_length);
149
150 auto tableSize = table.size();

--- 51 unchanged lines hidden (view full) ---

202 auto tableSize = table.size();
203 table.resize(tableSize + entryLength);
204 pldm_bios_table_attr_value_entry_encode_string(
205 table.data() + tableSize, entryLength, attrHandle, attrType, strLen,
206 str.c_str());
207 return reinterpret_cast<pldm_bios_attr_val_table_entry*>(table.data() +
208 tableSize);
209}
210std::optional<Table> updateTable(const Table& table, const void* entry,
211 size_t size)
212{
213 // Replace the old attribute with the new attribute, the size of table will
214 // change:
215 // sizeof(newTableBuffer) = srcTableSize + sizeof(newAttribute) -
216 // sizeof(oldAttribute) + pad(4-byte alignment, max =
217 // 3)
218 // For simplicity, we use
219 // sizeof(newTableBuffer) = srcTableSize + sizeof(newAttribute) + 3
220 size_t destBufferLength = table.size() + size + 3;
221 Table destTable(destBufferLength);
182
222
223 auto rc = pldm_bios_table_attr_value_copy_and_update(
224 table.data(), table.size(), destTable.data(), &destBufferLength, entry,
225 size);
226 if (rc != PLDM_SUCCESS)
227 {
228 return std::nullopt;
229 }
230 destTable.resize(destBufferLength);
231
232 return destTable;
233}
234
183} // namespace attribute_value
184
185} // namespace table
186
187} // namespace bios
188} // namespace responder
189} // namespace pldm
235} // namespace attribute_value
236
237} // namespace table
238
239} // namespace bios
240} // namespace responder
241} // namespace pldm