Skip to content

Commit 28aad59

Browse files
author
Sergey Matsievskiy
committed
Apply review edits
1 parent 457bffe commit 28aad59

File tree

3 files changed

+85
-88
lines changed

3 files changed

+85
-88
lines changed

fru.c

Lines changed: 64 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@
4040
static bool autodetect = true;
4141

4242
const char* enc_names[TOTAL_FIELD_TYPES] = {
43-
[FIELD_TYPE_AUTO] = "auto",
44-
[FIELD_TYPE_BINARY] = "binary",
45-
[FIELD_TYPE_BCDPLUS] = "bcdplus",
46-
[FIELD_TYPE_SIXBITASCII] = "6bitascii",
47-
[FIELD_TYPE_TEXT] = "text"
43+
[FIELD_TYPE_AUTO] = "auto",
44+
[FIELD_TYPE_BINARY] = "binary",
45+
[FIELD_TYPE_BCDPLUS] = "bcdplus",
46+
[FIELD_TYPE_SIXBITASCII] = "6bitascii",
47+
[FIELD_TYPE_TEXT] = "text"
4848
};
4949

5050
void fru_set_autodetect(bool enable)
@@ -100,7 +100,7 @@ static
100100
uint8_t fru_get_typelen(int len, /**< [in] Length of the data,
101101
LEN_AUTO for pure text zero-terminated data or
102102
one of LEN_BCDPLUS, LEN_6BITASCII, LEN_TEXT for explicit text type */
103-
const uint8_t *data) /**< [in] The input data */
103+
const uint8_t *data) /**< [in] The input data */
104104
{
105105
uint8_t typelen = len;
106106
int i;
@@ -111,16 +111,16 @@ uint8_t fru_get_typelen(int len, /**< [in] Length of the data,
111111
if (len < 0) {
112112
DEBUG("Forcing string '%s' to ...\n", (char *)data);
113113
// Explicit text type
114-
if (len == LEN_BCDPLUS) {
114+
if (len == LEN_BCDPLUS) {
115115
DEBUG("BCDPLUS type\n");
116116
return FRU_TYPELEN(BCDPLUS, (strlen(data) + 1) / 2);
117-
} else if (len == LEN_6BITASCII) {
117+
} else if (len == LEN_6BITASCII) {
118118
DEBUG("6BIT ASCII type\n");
119119
return FRU_TYPELEN(ASCII_6BIT, FRU_6BIT_LENGTH(strlen(data)));
120-
} else if (len == LEN_TEXT) {
120+
} else if (len == LEN_TEXT) {
121121
DEBUG("ASCII type\n");
122122
return FRU_TYPELEN(TEXT, strlen(data));
123-
} else {
123+
} else {
124124
DEBUG("Nothing... Unknown text type\n");
125125
return FRU_FIELD_TERMINATOR;
126126
}
@@ -211,8 +211,7 @@ static fru_field_t *fru_encode_6bit(const unsigned char *s /**< [in] Input strin
211211
fru_field_t *out = NULL;
212212
size_t outlen = sizeof(fru_field_t) + len6bit + 1; // 1 extra for null-byte
213213

214-
if (len6bit > FRU_FIELDDATALEN(len6bit) ||
215-
!(out = calloc(1, outlen)))
214+
if (len6bit > FRU_FIELDDATALEN(len6bit) || !(out = calloc(1, outlen)))
216215
{
217216
return out;
218217
}
@@ -257,8 +256,8 @@ static fru_field_t *fru_encode_6bit(const unsigned char *s /**< [in] Input strin
257256
*/
258257
static
259258
bool fru_decode_6bit(const fru_field_t *field,
260-
uint8_t *out,
261-
size_t out_len)
259+
uint8_t *out,
260+
size_t out_len)
262261
{
263262
const unsigned char *s6;
264263
int len, len6bit;
@@ -321,8 +320,8 @@ bool fru_decode_6bit(const fru_field_t *field,
321320
*/
322321
static
323322
bool fru_decode_bcdplus(const fru_field_t *field,
324-
uint8_t *out,
325-
size_t out_len)
323+
uint8_t *out,
324+
size_t out_len)
326325
{
327326
int i;
328327
uint8_t c;
@@ -333,25 +332,21 @@ bool fru_decode_bcdplus(const fru_field_t *field,
333332
c = (field->data[i / 2] >> ((i % 2) ? 0 : 4)) & 0x0F;
334333
switch (c) {
335334
case 0xA:
336-
out[i] = ' ';
337-
break;
335+
out[i] = ' ';
336+
break;
338337
case 0xB:
339-
out[i] = '-';
340-
break;
338+
out[i] = '-';
339+
break;
341340
case 0xC:
342-
out[i] = '.';
343-
break;
341+
out[i] = '.';
342+
break;
344343
case 0xD:
345-
out[i] = '?';
346-
break;
347344
case 0xE:
348-
out[i] = '?';
349-
break;
350345
case 0xF:
351-
out[i] = '?';
352-
break;
346+
out[i] = '?';
347+
break;
353348
default: // Digits
354-
out[i] = c + '0';
349+
out[i] = c + '0';
355350
}
356351
}
357352
out[2 * FRU_FIELDDATALEN(field->typelen)] = 0; // Terminate the string
@@ -373,8 +368,8 @@ bool fru_decode_bcdplus(const fru_field_t *field,
373368
*/
374369
static
375370
bool fru_decode_binary(const fru_field_t *field,
376-
uint8_t *out,
377-
size_t out_len)
371+
uint8_t *out,
372+
size_t out_len)
378373
{
379374
int i;
380375
uint8_t c;
@@ -452,8 +447,8 @@ fru_field_t * fru_encode_data(int len, const uint8_t *data)
452447
}
453448

454449
bool fru_decode_data(fru_field_t *field,
455-
typed_field_t *out,
456-
size_t out_len)
450+
typed_field_t *out,
451+
size_t out_len)
457452
{
458453
if (!field) return false;
459454

@@ -464,16 +459,16 @@ bool fru_decode_data(fru_field_t *field,
464459
if (out_len < (FRU_FIELDDATALEN(field->typelen) + 1))
465460
return false;
466461

467-
if (FRU_ISTYPE(field->typelen, BCDPLUS)) {
462+
if (FRU_ISTYPE(field->typelen, BCDPLUS)) {
468463
out->type = FIELD_TYPE_BCDPLUS;
469464
return fru_decode_bcdplus(field, out->val, out_len);
470-
} else {
465+
} else {
471466
out->type = FIELD_TYPE_TEXT;
472467
memcpy(out->val, field->data, FRU_FIELDDATALEN(field->typelen));
473468
out->val[FRU_FIELDDATALEN(field->typelen)] = 0; // Terminate the string
474469
return true;
475-
}
476-
}
470+
}
471+
}
477472
}
478473

479474
#if 0
@@ -545,11 +540,11 @@ uint8_t fru_area_checksum(fru_info_area_t *area)
545540
*/
546541
static
547542
fru_info_area_t *fru_create_info_area(fru_area_type_t atype, ///< [in] Area type (FRU_[CHASSIS|BOARD|PRODUCT]_INFO)
548-
uint8_t langtype, ///< [in] Language code for areas that use it (board, product) or Chassis Type for chassis info area
549-
const struct timeval *tv, ///< [in] Manufacturing time since the Epoch (1970/01/01 00:00:00 +0000 UTC) for areas that use it (board)
550-
fru_reclist_t *fields, ///< [in] Single-linked list of data fields
551-
size_t nstrings, ///< [in] Number of strings for mandatory fields
552-
const typed_field_t strings[]) ///<[in] Array of typed strings for mandatory fields
543+
uint8_t langtype, ///< [in] Language code for areas that use it (board, product) or Chassis Type for chassis info area
544+
const struct timeval *tv, ///< [in] Manufacturing time since the Epoch (1970/01/01 00:00:00 +0000 UTC) for areas that use it (board)
545+
fru_reclist_t *fields, ///< [in] Single-linked list of data fields
546+
size_t nstrings, ///< [in] Number of strings for mandatory fields
547+
const typed_field_t strings[]) ///<[in] Array of typed strings for mandatory fields
553548
{
554549
int i = 0;
555550
int field_count;
@@ -684,7 +679,7 @@ static bool fru_decode_custom_fields(const uint8_t *data, fru_reclist_t **reclis
684679
field = (fru_field_t*)data;
685680

686681
// end of fields
687-
if (field->typelen == 0xc1)
682+
if (field->typelen == FRU_TYPE_EOF)
688683
break;
689684

690685
fru_reclist_t *custom_field = add_reclist(reclist);
@@ -695,18 +690,15 @@ static bool fru_decode_custom_fields(const uint8_t *data, fru_reclist_t **reclis
695690
custom_field->rec = calloc(1, FRU_FIELDMAXARRAY);
696691
custom_field->rec->typelen = field->typelen;
697692
switch (FRU_TYPE(field->typelen)) {
698-
case __TYPE_BINARY: {
693+
case __TYPE_BINARY:
699694
fru_decode_binary(field, custom_field->rec->data, FRU_FIELDMAXLEN);
700695
break;
701-
}
702-
case __TYPE_ASCII_6BIT: {
696+
case __TYPE_ASCII_6BIT:
703697
fru_decode_6bit(field, custom_field->rec->data, FRU_FIELDMAXLEN);
704698
break;
705-
}
706-
case __TYPE_BCDPLUS: {
699+
case __TYPE_BCDPLUS:
707700
fru_decode_bcdplus(field, custom_field->rec->data, FRU_FIELDMAXLEN);
708701
break;
709-
}
710702
default:
711703
memcpy(custom_field->rec->data, field->data, length);
712704
custom_field->rec->data[length] = 0; // Terminate the string
@@ -759,8 +751,8 @@ fru_chassis_area_t * fru_encode_chassis_info(const fru_exploded_chassis_t *chass
759751
}
760752

761753
out = fru_create_info_area(FRU_CHASSIS_INFO,
762-
chassis->type, NULL, fields,
763-
ARRAY_SZ(strings), strings);
754+
chassis->type, NULL, fields,
755+
ARRAY_SZ(strings), strings);
764756

765757
return out;
766758
}
@@ -829,16 +821,14 @@ fru_board_area_t * fru_encode_board_info(const fru_exploded_board_t *board) ///<
829821
fru_board_area_t *out = NULL;
830822

831823
out = (fru_board_area_t *)fru_create_info_area(FRU_BOARD_INFO,
832-
board->lang, &board->tv, fields,
833-
ARRAY_SZ(strings), strings);
824+
board->lang, &board->tv, fields,
825+
ARRAY_SZ(strings), strings);
834826

835827
return out;
836828
}
837829

838-
bool fru_decode_board_info(
839-
const fru_board_area_t *area,
840-
fru_exploded_board_t *board_out
841-
)
830+
bool fru_decode_board_info(const fru_board_area_t *area,
831+
fru_exploded_board_t *board_out)
842832
{
843833
fru_field_t *field;
844834
const uint8_t *data = area->data;
@@ -849,8 +839,7 @@ bool fru_decode_board_info(
849839
union {
850840
uint32_t val;
851841
uint8_t arr[4];
852-
} min_since_1996_big_endian = {0};
853-
min_since_1996_big_endian.val = 0;
842+
} min_since_1996_big_endian = { 0 };
854843
min_since_1996_big_endian.arr[1] = area->mfgdate[2];
855844
min_since_1996_big_endian.arr[2] = area->mfgdate[1];
856845
min_since_1996_big_endian.arr[3] = area->mfgdate[0];
@@ -930,15 +919,16 @@ fru_product_area_t * fru_encode_product_info(const fru_exploded_product_t *produ
930919
[FRU_PROD_FILE] = { NULL, product->cust },
931920
};
932921

933-
const typed_field_t strings[] = { product->mfg, product->pname,
934-
product->pn, product->ver,
935-
product->serial, product->atag,
936-
product->file };
922+
const typed_field_t strings[] = {
923+
product->mfg, product->pname,
924+
product->pn, product->ver,
925+
product->serial, product->atag,
926+
product->file };
937927
fru_product_area_t *out = NULL;
938928

939929
out = fru_create_info_area(FRU_PRODUCT_INFO,
940-
product->lang, NULL, fields,
941-
ARRAY_SZ(strings), strings);
930+
product->lang, NULL, fields,
931+
ARRAY_SZ(strings), strings);
942932

943933
return out;
944934
}
@@ -1134,43 +1124,43 @@ bool fru_decode_product_info(
11341124

11351125
field = (fru_field_t*)data;
11361126
if (!fru_decode_data(field, &product_out->mfg,
1137-
sizeof(product_out->mfg.val)))
1127+
sizeof(product_out->mfg.val)))
11381128
return false;
11391129
data += FRU_FIELDSIZE(field->typelen);
11401130

11411131
field = (fru_field_t*)data;
11421132
if (!fru_decode_data(field, &product_out->pname,
1143-
sizeof(product_out->pname.val)))
1133+
sizeof(product_out->pname.val)))
11441134
return false;
11451135
data += FRU_FIELDSIZE(field->typelen);
11461136

11471137
field = (fru_field_t*)data;
11481138
if (!fru_decode_data(field, &product_out->pn,
1149-
sizeof(product_out->pn.val)))
1139+
sizeof(product_out->pn.val)))
11501140
return false;
11511141
data += FRU_FIELDSIZE(field->typelen);
11521142

11531143
field = (fru_field_t*)data;
11541144
if (!fru_decode_data(field, &product_out->ver,
1155-
sizeof(product_out->ver.val)))
1145+
sizeof(product_out->ver.val)))
11561146
return false;
11571147
data += FRU_FIELDSIZE(field->typelen);
11581148

11591149
field = (fru_field_t*)data;
11601150
if (!fru_decode_data(field, &product_out->serial,
1161-
sizeof(product_out->serial.val)))
1151+
sizeof(product_out->serial.val)))
11621152
return false;
11631153
data += FRU_FIELDSIZE(field->typelen);
11641154

11651155
field = (fru_field_t*)data;
11661156
if (!fru_decode_data(field, &product_out->atag,
1167-
sizeof(product_out->atag.val)))
1157+
sizeof(product_out->atag.val)))
11681158
return false;
11691159
data += FRU_FIELDSIZE(field->typelen);
11701160

11711161
field = (fru_field_t*)data;
11721162
if (!fru_decode_data(field, &product_out->file,
1173-
sizeof(product_out->file.val)))
1163+
sizeof(product_out->file.val)))
11741164
return false;
11751165
data += FRU_FIELDSIZE(field->typelen);
11761166

@@ -1258,8 +1248,7 @@ fru_t * fru_create(fru_area_t area[FRU_MAX_AREAS], size_t *size)
12581248
if (!blocks) continue;
12591249

12601250
DEBUG("copying %d bytes of area of type %d to offset 0x%03X (0x%03lX)\n",
1261-
FRU_BYTES(blocks), atype, FRU_BYTES(*offset), dst - (uint8_t *)out
1262-
);
1251+
FRU_BYTES(blocks), atype, FRU_BYTES(*offset), dst - (uint8_t *)out);
12631252
memcpy(dst, data, FRU_BYTES(blocks));
12641253
}
12651254

@@ -1389,7 +1378,7 @@ void test_encodings(void)
13891378
printf("Decoding... ");
13901379

13911380
if (!fru_decode_data(field->&typelen, &field->data,,
1392-
FRU_FIELDMAXARRAY)) {
1381+
FRU_FIELDMAXARRAY)) {
13931382
printf("FAIL!");
13941383
goto next;
13951384
}

fru.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ static inline fru_reclist_t *add_reclist(fru_reclist_t **reclist)
182182

183183
#define LANG_DEFAULT 0
184184
#define LANG_ENGLISH 25
185+
#define FRU_TYPE_EOF 0xc1
185186

186187
typedef struct fru_info_area_s { // The generic info area structure
187188
FRU_INFO_AREA_HEADER;

0 commit comments

Comments
 (0)