| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
#include <ctype.h> |
| 43 |
#include <stdio.h> |
| 44 |
#include <stdlib.h> |
| 45 |
#include <string.h> |
| 46 |
#include <time.h> |
| 47 |
#include <limits.h> |
| 48 |
|
| 49 |
#include "fru_tools.h" |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
#if CHAR_BIT != 8 |
| 70 |
#error "unsupported char size" |
| 71 |
#endif |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
unsigned char calc_zero_checksum (unsigned char *data, size_t len) |
| 80 |
{ |
| 81 |
size_t i; |
| 82 |
unsigned char tmp = 0; |
| 83 |
|
| 84 |
for (i = 0; i <= len; i++) |
| 85 |
tmp += data[i]; |
| 86 |
|
| 87 |
return tmp; |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
time_t min2date(unsigned int mins) |
| 103 |
{ |
| 104 |
struct tm tm; |
| 105 |
time_t tmp; |
| 106 |
|
| 107 |
|
| 108 |
memset(&tm, 0, sizeof(struct tm)); |
| 109 |
tm.tm_year = 96; |
| 110 |
tm.tm_mday = 1; |
| 111 |
tm.tm_min += mins; |
| 112 |
tmp = mktime(&tm); |
| 113 |
return tmp; |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
int ascii2six(unsigned char **dest, unsigned char *src, size_t size) |
| 121 |
{ |
| 122 |
size_t i = 0; |
| 123 |
ssize_t j; |
| 124 |
unsigned int k, m = 0; |
| 125 |
unsigned char *p, *d, *e; |
| 126 |
|
| 127 |
if (!src || !size) |
| 128 |
return 0; |
| 129 |
|
| 130 |
e = d = calloc(1, size); |
| 131 |
|
| 132 |
p = src; |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
while (*p != '\0' && i <= size) { |
| 137 |
j = toupper(*p) - 0x20; |
| 138 |
if (j < 0 || j >= 0x40) { |
| 139 |
printf_warn("%s : trying to convert a string '%s'\n" |
| 140 |
"\t\twhich includes char '%c (0x%x)', which can't be converted\n", |
| 141 |
__func__, src, *p, *p); |
| 142 |
free(e); |
| 143 |
return -1; |
| 144 |
} |
| 145 |
*d = j; |
| 146 |
++p, ++d, i++; |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
*dest = calloc(1, size + 1); |
| 151 |
p = *dest; |
| 152 |
|
| 153 |
for (i = 0; i <= size ; i+= 4) { |
| 154 |
k = e[i]; |
| 155 |
m++; |
| 156 |
if ((i + 1) < size) { |
| 157 |
k |= e[i + 1] << 6; |
| 158 |
m++; |
| 159 |
} |
| 160 |
if ((i + 2) < size) { |
| 161 |
k |= e[i + 2] << 12; |
| 162 |
m++; |
| 163 |
} |
| 164 |
if ((i + 3) < size) { |
| 165 |
k |= e[i + 3] << 18; |
| 166 |
} |
| 167 |
#if __BYTE_ORDER == __BIG_ENDIAN |
| 168 |
k = __builtin_bswap32(k); |
| 169 |
#endif |
| 170 |
memcpy(p, &k, 3); |
| 171 |
p += 3; |
| 172 |
} |
| 173 |
|
| 174 |
free (e); |
| 175 |
|
| 176 |
return m; |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
unsigned char * six2ascii(unsigned char *buf, size_t size) |
| 184 |
{ |
| 185 |
unsigned char *p, *dest; |
| 186 |
size_t i; |
| 187 |
|
| 188 |
if (!size) |
| 189 |
return NULL; |
| 190 |
|
| 191 |
|
| 192 |
dest = calloc(1, ((size * 4) / 3) + 2); |
| 193 |
p = dest; |
| 194 |
|
| 195 |
for (i = 0; i < size; i += 3) { |
| 196 |
*dest = (buf[i] & 0x3F) + 0x20; |
| 197 |
|
| 198 |
dest++; |
| 199 |
if ((i + 1) < size) { |
| 200 |
*dest = ((buf[i] & 0xC0) >> 6 | (buf[i+1] & 0x0F) << 2) + 0x20; |
| 201 |
|
| 202 |
dest++; |
| 203 |
} |
| 204 |
if ((i + 2) < size) { |
| 205 |
*dest = ((buf[i+1] & 0xF0) >> 4 | (buf[i+2] & 0x03) << 4) + 0x20; |
| 206 |
|
| 207 |
dest++; |
| 208 |
} |
| 209 |
if ((i + 3) < size) { |
| 210 |
*dest = ((buf[i+2] & 0xFC) >> 2) + 0x20; |
| 211 |
|
| 212 |
dest++; |
| 213 |
} |
| 214 |
} |
| 215 |
|
| 216 |
*dest = 0; |
| 217 |
|
| 218 |
|
| 219 |
dest--; |
| 220 |
while ((*dest == 0 || *dest == ' ') && size) { |
| 221 |
*dest = 0; |
| 222 |
dest--; |
| 223 |
size--; |
| 224 |
} |
| 225 |
|
| 226 |
return p; |
| 227 |
} |
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
unsigned int parse_string(unsigned char *p, unsigned char **str, const char * field) |
| 235 |
{ |
| 236 |
size_t len, i, j; |
| 237 |
|
| 238 |
len = p[0] & 0x3F; |
| 239 |
|
| 240 |
if (!len) { |
| 241 |
*str = calloc(1, 3); |
| 242 |
*str[0] = (FRU_STRING_ASCII << 6); |
| 243 |
return 1; |
| 244 |
} |
| 245 |
|
| 246 |
switch((p[0] >> 6) & 0x3 ) { |
| 247 |
case FRU_STRING_BINARY: |
| 248 |
|
| 249 |
*str = calloc(1, len + 2); |
| 250 |
memcpy(*str, p, len + 1); |
| 251 |
break; |
| 252 |
case FRU_STRING_BCD: |
| 253 |
|
| 254 |
printf_err("BCD - sorry\n"); |
| 255 |
break; |
| 256 |
case FRU_STRING_SIXBIT: |
| 257 |
|
| 258 |
{ |
| 259 |
unsigned char *tmp1, *tmp2; |
| 260 |
size_t tlen; |
| 261 |
|
| 262 |
tmp1 = six2ascii(&p[1], p[0]& 0x3F); |
| 263 |
tlen = strlen((char *)tmp1); |
| 264 |
*str = calloc(1, tlen + 2); |
| 265 |
|
| 266 |
tmp2 = *str; |
| 267 |
tmp2++; |
| 268 |
memcpy(tmp2, tmp1, tlen + 1); |
| 269 |
if (tlen > 0x3F) |
| 270 |
tlen = 0x3F; |
| 271 |
|
| 272 |
*str[0] = (FRU_STRING_ASCII << 6) | tlen; |
| 273 |
free(tmp1); |
| 274 |
} |
| 275 |
break; |
| 276 |
case FRU_STRING_ASCII: |
| 277 |
|
| 278 |
*str = calloc(1, len + 2); |
| 279 |
memcpy(*str, p, len + 1); |
| 280 |
for (i = 1; i < len; i++) { |
| 281 |
if (p[i] < 0x20 || p[i] == 0x7F) { |
| 282 |
printf_warn("Field '%s' marked as ASCII, but contains non-printable " |
| 283 |
"characters:\n", field); |
| 284 |
printf_warn(" Length/Type : 0x%x (length:%i; type:ASCII(%i)\n", |
| 285 |
p[0], p[0] & 0x3F, FRU_STRING_ASCII); |
| 286 |
printf_warn(" Contents : "); |
| 287 |
for (j = 1; j < len + 1; j++) |
| 288 |
printf_warn("0x%02x ", p[j]); |
| 289 |
printf_warn(" |"); |
| 290 |
for (j = 0; j < len + 1; j++) |
| 291 |
printf_warn("%c", ((p[j] < 32) || (p[j] >= 127)) ? '.': p[j]); |
| 292 |
printf_warn("|\n"); |
| 293 |
} |
| 294 |
} |
| 295 |
break; |
| 296 |
} |
| 297 |
return len + 1; |
| 298 |
} |
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
struct BOARD_INFO * parse_board_area(unsigned char *data) |
| 305 |
{ |
| 306 |
|
| 307 |
struct BOARD_INFO *fru; |
| 308 |
unsigned char *p; |
| 309 |
unsigned int len, i, j; |
| 310 |
|
| 311 |
fru = calloc(1, sizeof(struct BOARD_INFO)); |
| 312 |
|
| 313 |
if (data[0] != 0x01) { |
| 314 |
printf_err("Board Area Format Version mismatch: 0x%02x should be 0x01\n", data [0]); |
| 315 |
goto err; |
| 316 |
} |
| 317 |
|
| 318 |
len = (data[1] * 8) - 1; |
| 319 |
if (calc_zero_checksum(data, len)) { |
| 320 |
printf_err("Board Area Checksum failed"); |
| 321 |
goto err; |
| 322 |
} |
| 323 |
|
| 324 |
if (data[2] != 0 && data[2] != 25) { |
| 325 |
printf_err("Board Area is non-English - sorry: Lang code = %i\n", data[2]); |
| 326 |
goto err; |
| 327 |
} |
| 328 |
|
| 329 |
len--; |
| 330 |
while ((data[len] == 0x00) && (len != 0)) |
| 331 |
len--; |
| 332 |
if (len == 0 || data[len] != 0xC1) { |
| 333 |
printf_err("BOARD INFO not terminated properly, walking backwards len: " |
| 334 |
"%i:0x%02x should be 0xC1\n", len, data[len]); |
| 335 |
goto err; |
| 336 |
} |
| 337 |
|
| 338 |
fru->mfg_date = data[3] | (data[4] << 8) | (data[5] << 16); |
| 339 |
|
| 340 |
p = &data[6]; |
| 341 |
len -= 6; |
| 342 |
|
| 343 |
i = parse_string(p, &fru->manufacturer, "Manufacture"); |
| 344 |
p += i, len -= i; |
| 345 |
|
| 346 |
i = parse_string(p, &fru->product_name, "Product Name"); |
| 347 |
p += i, len -= i; |
| 348 |
|
| 349 |
i = parse_string(p, &fru->serial_number, "Serial Number"); |
| 350 |
p += i, len -= i; |
| 351 |
|
| 352 |
i = parse_string(p, &fru->part_number, "Part Number"); |
| 353 |
p += i, len -= i; |
| 354 |
|
| 355 |
i = parse_string(p, &fru->FRU_file_ID, "FRU File ID"); |
| 356 |
p += i, len -= i; |
| 357 |
|
| 358 |
j = 0; |
| 359 |
while (len != 0 && j < CUSTOM_FIELDS) { |
| 360 |
i = parse_string(p, &fru->custom[j], "Custom Field"); |
| 361 |
p += i, len -= i, j++; |
| 362 |
} |
| 363 |
|
| 364 |
if (*p != 0xC1) { |
| 365 |
printf_err("BOARD INFO not terminated properly, " |
| 366 |
"offset %02i(0x%02x) : %02i(0x%02x) should be 0xC1\n", |
| 367 |
p - data, p - data, *p, *p); |
| 368 |
goto err; |
| 369 |
} |
| 370 |
|
| 371 |
return fru; |
| 372 |
|
| 373 |
err: |
| 374 |
free(fru->manufacturer); |
| 375 |
free(fru->product_name); |
| 376 |
free(fru->serial_number); |
| 377 |
free(fru->part_number); |
| 378 |
free(fru->FRU_file_ID); |
| 379 |
for( j = 0; j < CUSTOM_FIELDS; j++) |
| 380 |
free(fru->custom[j]); |
| 381 |
free(fru); |
| 382 |
return NULL; |
| 383 |
} |
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
n is |
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
struct MULTIRECORD_INFO * parse_multiboard_area(unsigned char *data) |
| 394 |
{ |
| 395 |
int i = 0, tmp, type; |
| 396 |
unsigned char *p; |
| 397 |
struct MULTIRECORD_INFO *multi; |
| 398 |
|
| 399 |
multi = calloc(1, sizeof(struct MULTIRECORD_INFO)); |
| 400 |
|
| 401 |
p = data; |
| 402 |
|
| 403 |
do { |
| 404 |
if (i != 0) |
| 405 |
p += 5 + p[2]; |
| 406 |
if (p[0] >= 0x06 && p[0] <= 0xBF) { |
| 407 |
printf_err("MultiRecord Area %i: Invalid Record Header\n", i); |
| 408 |
return NULL; |
| 409 |
} |
| 410 |
if (calc_zero_checksum(p, 4)) { |
| 411 |
printf_err("MultiRecord Area %i (Record Type 0x%x): " |
| 412 |
"Header Checksum failed\n", i, p[0]); |
| 413 |
return NULL; |
| 414 |
} |
| 415 |
|
| 416 |
if (!p[2] || ((calc_zero_checksum(p+5, p[2] - 1) + p[3]) & 0xFF)) { |
| 417 |
printf_err("MultiRecord Area %i (Record Type 0x%x): " |
| 418 |
"Record Checksum failed\n", i, p[0]); |
| 419 |
return NULL; |
| 420 |
} |
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
switch(p[0]) { |
| 426 |
case MULTIRECORD_DC_OUTPUT: |
| 427 |
case MULTIRECORD_DC_INPUT: |
| 428 |
tmp = p[5] & 0xF; |
| 429 |
if ((tmp) >= NUM_SUPPLIES) |
| 430 |
printf_err("Too many Supplies defined in Multirecords\n"); |
| 431 |
|
| 432 |
multi->supplies[tmp] = calloc(1, p[2] + 6); |
| 433 |
memcpy (multi->supplies[tmp], p, p[2] + 6); |
| 434 |
multi->supplies[tmp][1] = multi->supplies[tmp][1] & 0x7F; |
| 435 |
break; |
| 436 |
case MULTIRECORD_FMC: |
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
if ((p[5] | p[6] << 8 | p[7] << 16) != VITA_OUI) { |
| 441 |
printf_err("OUI Doesn't match : is 0x%06X, " |
| 442 |
"should be 0x%06x\n", p[5] | p[6] << 8 | p[7] << 16, VITA_OUI); |
| 443 |
} |
| 444 |
|
| 445 |
type = p[8] >> 4; |
| 446 |
|
| 447 |
switch (type) { |
| 448 |
case MULTIRECORD_CONNECTOR: |
| 449 |
|
| 450 |
multi->connector = calloc(1, p[2] + 6); |
| 451 |
memcpy (multi->connector, p, p[2] + 6); |
| 452 |
|
| 453 |
multi->connector[1] = multi->connector[1] & 0x7F; |
| 454 |
break; |
| 455 |
case MULTIRECORD_I2C: |
| 456 |
if (p[2] <= 5) { |
| 457 |
printf_warn("I2C MultiRecord is too short (len:%i)\n" |
| 458 |
" (at least 4 is needed for OUI and subtype)\n", |
| 459 |
p[2]); |
| 460 |
} else { |
| 461 |
|
| 462 |
unsigned char *foo2; |
| 463 |
foo2 = six2ascii(&p[9], p[2] - 4); |
| 464 |
|
| 465 |
multi->i2c_devices = calloc(1, strlen((char *)foo2) + 1); |
| 466 |
strcpy ((char *)multi->i2c_devices, (char *)foo2); |
| 467 |
free(foo2); |
| 468 |
|
| 469 |
multi->i2c_devices[1] = multi->i2c_devices[1] & 0x7F; |
| 470 |
} |
| 471 |
break; |
| 472 |
default: |
| 473 |
printf_err("Unknown multirecord type : %i\n", type); |
| 474 |
break; |
| 475 |
} |
| 476 |
|
| 477 |
if (type == 1) { |
| 478 |
|
| 479 |
} |
| 480 |
break; |
| 481 |
default: |
| 482 |
printf_err("Unknown MultiRecord Area\n"); |
| 483 |
} |
| 484 |
|
| 485 |
i++; |
| 486 |
} while (!(p[1] & 0x80)); |
| 487 |
|
| 488 |
return multi; |
| 489 |
} |
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
struct FRU_DATA * parse_FRU (unsigned char *data) |
| 496 |
{ |
| 497 |
struct FRU_DATA *fru; |
| 498 |
|
| 499 |
fru = calloc (1, sizeof(struct FRU_DATA)); |
| 500 |
|
| 501 |
|
| 502 |
if (data[0] != 0x01) { |
| 503 |
printf_err("FRU Version number mismatch 0x%02x should be 0x01\n", data[0]); |
| 504 |
goto err; |
| 505 |
} |
| 506 |
|
| 507 |
|
| 508 |
if (data[6] != 0x00) { |
| 509 |
printf_err("FRU byte 6 should be PAD, and be zero -- but it's not\n"); |
| 510 |
goto err; |
| 511 |
} |
| 512 |
|
| 513 |
|
| 514 |
if (calc_zero_checksum(data, 7)) { |
| 515 |
printf_err("Common Header Checksum failed\n"); |
| 516 |
goto err; |
| 517 |
} |
| 518 |
|
| 519 |
|
| 520 |
if (data[1]) { |
| 521 |
printf_err("Internal Use Area not yet implemented - sorry\n"); |
| 522 |
goto err; |
| 523 |
} |
| 524 |
|
| 525 |
|
| 526 |
if (data[2]) { |
| 527 |
printf_err("Chassis Info Area not yet implmented - sorry\n"); |
| 528 |
goto err; |
| 529 |
} |
| 530 |
|
| 531 |
|
| 532 |
if (data[3]) { |
| 533 |
fru->Board_Area = parse_board_area(&data[data[3] * 8]); |
| 534 |
if (!fru->Board_Area) |
| 535 |
goto err; |
| 536 |
} |
| 537 |
|
| 538 |
|
| 539 |
if (data[4]) { |
| 540 |
printf_err("Chassis Info Area parsing not yet implemented - sorry\n"); |
| 541 |
goto err; |
| 542 |
} |
| 543 |
|
| 544 |
|
| 545 |
if (data[5]) |
| 546 |
fru->MultiRecord_Area = parse_multiboard_area(&data[data[5] * 8]); |
| 547 |
|
| 548 |
return fru; |
| 549 |
|
| 550 |
err: |
| 551 |
free(fru); |
| 552 |
return NULL; |
| 553 |
|
| 554 |
} |
| 555 |
|
| 556 |
void free_FRU(struct FRU_DATA *fru) |
| 557 |
{ |
| 558 |
int j; |
| 559 |
|
| 560 |
free(fru->Board_Area->manufacturer); |
| 561 |
free(fru->Board_Area->product_name); |
| 562 |
free(fru->Board_Area->serial_number); |
| 563 |
free(fru->Board_Area->part_number); |
| 564 |
free(fru->Board_Area->FRU_file_ID); |
| 565 |
for(j = 0; j < CUSTOM_FIELDS; j++) |
| 566 |
free(fru->Board_Area->custom[j]); |
| 567 |
free(fru->Board_Area); |
| 568 |
|
| 569 |
for(j = 0; j < NUM_SUPPLIES; j++) |
| 570 |
free(fru->MultiRecord_Area->supplies[j]); |
| 571 |
free(fru->MultiRecord_Area->i2c_devices); |
| 572 |
|
| 573 |
free(fru->MultiRecord_Area->connector); |
| 574 |
free(fru->MultiRecord_Area); |
| 575 |
|
| 576 |
free(fru); |
| 577 |
|
| 578 |
} |
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
static unsigned int insert_str(unsigned char *buf, const unsigned char * str, bool force) |
| 585 |
{ |
| 586 |
int tmp; |
| 587 |
|
| 588 |
if (TYPE_CODE(str) == FRU_STRING_ASCII) |
| 589 |
tmp = strlen((const char *)&str[1]); |
| 590 |
else |
| 591 |
tmp = FIELD_LEN(str); |
| 592 |
|
| 593 |
|
| 594 |
if ((TYPE_CODE(str) != FRU_STRING_ASCII) || (tmp <= 0x3F && !force)) { |
| 595 |
|
| 596 |
buf[0] = tmp | (TYPE_CODE(str) << 6); |
| 597 |
memcpy(&buf[1], &str[1], tmp); |
| 598 |
} else { |
| 599 |
|
| 600 |
unsigned char *six = NULL; |
| 601 |
|
| 602 |
tmp = ascii2six(&six, (unsigned char *)&str[1], tmp); |
| 603 |
if (tmp < 0) { |
| 604 |
|
| 605 |
printf_warn("couldn't encode '%s' string\n", &str[1]); |
| 606 |
tmp = strlen((const char *)&str[1]); |
| 607 |
if (tmp > 0x3F) { |
| 608 |
printf_warn("fail : %d\n", tmp); |
| 609 |
printf_err("String too long to fit\n"); |
| 610 |
} |
| 611 |
buf[0] = tmp | (FRU_STRING_ASCII << 6); |
| 612 |
memcpy(&buf[1], &str[1], tmp); |
| 613 |
return tmp + 1; |
| 614 |
} |
| 615 |
if (tmp > 0x3F) { |
| 616 |
printf_warn("fail : %d\n", tmp); |
| 617 |
printf_err("String too long to fit\n"); |
| 618 |
} |
| 619 |
|
| 620 |
buf[0] = tmp | (FRU_STRING_SIXBIT << 6); |
| 621 |
memcpy(&buf[1], six, tmp); |
| 622 |
free(six); |
| 623 |
} |
| 624 |
|
| 625 |
|
| 626 |
return tmp + 1; |
| 627 |
} |
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
unsigned char * build_FRU_blob (struct FRU_DATA *fru, size_t *length, bool packed) |
| 633 |
{ |
| 634 |
unsigned char *p, *buf; |
| 635 |
unsigned int st, len, tmp, last = 0, i = 0, j; |
| 636 |
|
| 637 |
buf = calloc(1, 1024); |
| 638 |
len = 256; |
| 639 |
|
| 640 |
buf[0] = 0x01; |
| 641 |
i = 8; |
| 642 |
if (fru->Internal_Area) |
| 643 |
printf_err("Internal Use Area not yet implemented - sorry\n"); |
| 644 |
|
| 645 |
if (fru->Chassis_Info) |
| 646 |
printf_err("Chassis Info not yet implemented - sorry\n"); |
| 647 |
|
| 648 |
if (fru->Board_Area) { |
| 649 |
len = st = i; |
| 650 |
buf[3] = i / 8; |
| 651 |
buf[i] = 0x1; |
| 652 |
|
| 653 |
buf[i+2] = 25; |
| 654 |
buf[i+3] = (fru->Board_Area->mfg_date) & 0xFF; |
| 655 |
buf[i+4] = (fru->Board_Area->mfg_date >> 8) & 0xFF; |
| 656 |
buf[i+5] = (fru->Board_Area->mfg_date >> 16) & 0xFF; |
| 657 |
|
| 658 |
i += 6; |
| 659 |
i += insert_str(&buf[i], fru->Board_Area->manufacturer, packed); |
| 660 |
i += insert_str(&buf[i], fru->Board_Area->product_name, packed); |
| 661 |
i += insert_str(&buf[i], fru->Board_Area->serial_number, packed); |
| 662 |
i += insert_str(&buf[i], fru->Board_Area->part_number, packed); |
| 663 |
i += insert_str(&buf[i], fru->Board_Area->FRU_file_ID, packed); |
| 664 |
for (j = 0; j < CUSTOM_FIELDS; j++) { |
| 665 |
if (fru->Board_Area->custom[j]) { |
| 666 |
i += insert_str(&buf[i], fru->Board_Area->custom[j], packed); |
| 667 |
} |
| 668 |
} |
| 669 |
buf[i] = 0xC1; |
| 670 |
i++; |
| 671 |
i = (((i >> 3) + 1) << 3) - 1; |
| 672 |
len = i - st; |
| 673 |
buf[st + 1] = len / 8 + 1; |
| 674 |
buf[i] = 256 - calc_zero_checksum(&buf[st], len); |
| 675 |
i++; |
| 676 |
} |
| 677 |
if (fru->Product_Info) { |
| 678 |
} |
| 679 |
if (fru->MultiRecord_Area) { |
| 680 |
st = i; |
| 681 |
buf[5] = st / 8; |
| 682 |
for (tmp = 0; tmp < NUM_SUPPLIES; tmp++) { |
| 683 |
p = fru->MultiRecord_Area->supplies[tmp]; |
| 684 |
if (!p) |
| 685 |
continue; |
| 686 |
memcpy(&buf[i], p, p[2]+ 5); |
| 687 |
last = i + 1; |
| 688 |
i += p[2] + 5; |
| 689 |
} |
| 690 |
p = fru->MultiRecord_Area->connector; |
| 691 |
if (p) { |
| 692 |
memcpy(&buf[i], p, p[2]+ 5); |
| 693 |
last = i + 1; |
| 694 |
i += p[2] + 5; |
| 695 |
} |
| 696 |
p = fru->MultiRecord_Area->i2c_devices; |
| 697 |
if (p) { |
| 698 |
unsigned int len, oui = VITA_OUI; |
| 699 |
unsigned char *six = NULL; |
| 700 |
len = ascii2six(&six, p, strlen((char *)p)); |
| 701 |
|
| 702 |
|
| 703 |
sprintf((char *)&buf[i], "%c%c%c%c%c", MULTIRECORD_FMC, 0x02, len + 4, 0, 0); |
| 704 |
|
| 705 |
#if __BYTE_ORDER == __BIG_ENDIAN |
| 706 |
oui = __builtin_bswap32(oui); |
| 707 |
#endif |
| 708 |
memcpy(&buf[i+5], &oui, 3); |
| 709 |
|
| 710 |
sprintf((char *)&buf[i+8], "%c", (0x1 << 4) | (0)); |
| 711 |
|
| 712 |
memcpy(&buf[i+9], six, len); |
| 713 |
|
| 714 |
buf[i+3] = 0x100 - calc_zero_checksum(&buf[i+5], len + 3); |
| 715 |
|
| 716 |
buf[i+4] = 0x100 - calc_zero_checksum(&buf[i], 4); |
| 717 |
|
| 718 |
last = i + 1; |
| 719 |
i += len + 9; |
| 720 |
|
| 721 |
free(six); |
| 722 |
} |
| 723 |
if (last) { |
| 724 |
buf[last] = buf[last] | 0x80; |
| 725 |
|
| 726 |
buf[last + 3] = 0; |
| 727 |
buf[last + 3] = 0x100 - calc_zero_checksum(&buf[last - 1], 4); |
| 728 |
} |
| 729 |
} |
| 730 |
buf[7] = 256 - calc_zero_checksum(buf, 6); |
| 731 |
|
| 732 |
*length = i; |
| 733 |
return buf; |
| 734 |
} |