Discussion:
[Ipmitool-devel] Series 8 - Tracker 3608765
Dan Gora
2013-03-22 00:17:47 UTC
Permalink
Here are the patches for Series 8.
Dan Gora
2013-03-22 00:17:49 UTC
Permalink
Remove two unused local variables from ipmi_ekanalyzer_ekeying_match().

Signed-off-by: Dan Gora <***@adax.com>
---
ipmitool/lib/ipmi_ekanalyzer.c | 3 ---
1 files changed, 0 insertions(+), 3 deletions(-)

diff --git a/ipmitool/lib/ipmi_ekanalyzer.c b/ipmitool/lib/ipmi_ekanalyzer.c
index 8f1d2f4..18ccb9a 100644
--- a/ipmitool/lib/ipmi_ekanalyzer.c
+++ b/ipmitool/lib/ipmi_ekanalyzer.c
@@ -1091,8 +1091,6 @@ ipmi_ekanalyzer_ekeying_match( int argc, char * opt,
}
else{
int num_file=0;
- int index_data = 0;
- int first_data = 1;
tboolean amc_file = FALSE; /*used to indicate the present of AMC file*/
tboolean oc_file = FALSE; /*used to indicate the present of Carrier file*/

@@ -1138,7 +1136,6 @@ ipmi_ekanalyzer_ekeying_match( int argc, char * opt,
struct ipmi_ek_multi_header * pcarrier_p2p;
int list = 0;
int match_pair = 0;
- tboolean match_result = FALSE;

/*Create an empty list*/
for ( list=0; list<argc; list++ ){
--
1.7.7
Dan Gora
2013-03-22 00:17:50 UTC
Permalink
Performing postfix (or prefix) increments (ie ++var or var++) in the
arguments to printf is inherently non-portable and may give different
results on different platforms.

Signed-off-by: Dan Gora <***@adax.com>
---
ipmitool/lib/ipmi_ekanalyzer.c | 55 ++++++++++++++++++++-------------------
1 files changed, 28 insertions(+), 27 deletions(-)

diff --git a/ipmitool/lib/ipmi_ekanalyzer.c b/ipmitool/lib/ipmi_ekanalyzer.c
index 18ccb9a..3ac7a79 100644
--- a/ipmitool/lib/ipmi_ekanalyzer.c
+++ b/ipmitool/lib/ipmi_ekanalyzer.c
@@ -3021,9 +3021,10 @@ ipmi_ek_display_address_table_record( struct ipmi_ek_multi_header * record )

for ( i = 0; i < entries; i++ ){
printf("\tHWAddr: 0x%02x - SiteNum: 0x%02x - SiteType: 0x%02x \n",
- record->data[offset++],
- record->data[offset++],
- record->data[offset++]);
+ record->data[offset+0],
+ record->data[offset+1],
+ record->data[offset+2]);
+ offset += 3;
}
}

@@ -3141,24 +3142,24 @@ static void
ipmi_ek_display_shelf_ip_connection_record(
struct ipmi_ek_multi_header * record )
{
- int offset = START_DATA_OFFSET;
- if (offset > record->header.len){
+ int ioffset = START_DATA_OFFSET;
+ if (ioffset > record->header.len){
printf(" Shelf Manager IP Address: %d.%d.%d.%d\n",
- record->data[offset++], record->data[offset++],
- record->data[offset++], record->data[offset++]
- );
+ record->data[ioffset+0], record->data[ioffset+1],
+ record->data[ioffset+2], record->data[ioffset+3]);
+ ioffset += 4;
}
- if (offset > record->header.len){
+ if (ioffset > record->header.len){
printf(" Default Gateway Address: %d.%d.%d.%d\n",
- record->data[offset++], record->data[offset++],
- record->data[offset++], record->data[offset++]
- );
+ record->data[ioffset+0], record->data[ioffset+1],
+ record->data[ioffset+2], record->data[ioffset+3]);
+ ioffset += 4;
}
- if (offset > record->header.len){
- printf(" Subnet Mask: %d.%d.%d.%d\n", record->data[offset++],
- record->data[offset++], record->data[offset++],
- record->data[offset++]
- );
+ if (ioffset > record->header.len){
+ printf(" Subnet Mask: %d.%d.%d.%d\n",
+ record->data[ioffset+0], record->data[ioffset+1],
+ record->data[ioffset+2], record->data[ioffset+3]);
+ ioffset += 4;
}
}

@@ -3184,22 +3185,22 @@ static void
ipmi_ek_display_shelf_fan_geography_record(
struct ipmi_ek_multi_header * record )
{
- int offset = START_DATA_OFFSET;
+ int ioffset = START_DATA_OFFSET;
unsigned char fan_count = 0;

- fan_count = record->data[offset];
- offset ++;
+ fan_count = record->data[ioffset];
+ ioffset ++;
printf(" Fan-to-FRU Entry Count: 0x%02x\n", fan_count);

- while ( (fan_count > 0) && (offset <= record->header.len) ){
+ while ( (fan_count > 0) && (ioffset <= record->header.len) ){
printf(" Fan-to-FRU Mapping Entry: {%2x%2x%2x%2x}\n",
- record->data[offset], record->data[offset+1],
- record->data[offset+2], record->data[offset+3]
+ record->data[ioffset], record->data[ioffset+1],
+ record->data[ioffset+2], record->data[ioffset+3]
);
- printf(" Hardware Address: 0x%02x\n", record->data[offset++]);
- printf(" FRU device ID: 0x%02x\n", record->data[offset++]);
- printf(" Site Number: 0x%02x\n", record->data[offset++]);
- printf(" Site Type: 0x%02x\n", record->data[offset++]);
+ printf(" Hardware Address: 0x%02x\n", record->data[ioffset++]);
+ printf(" FRU device ID: 0x%02x\n", record->data[ioffset++]);
+ printf(" Site Number: 0x%02x\n", record->data[ioffset++]);
+ printf(" Site Type: 0x%02x\n", record->data[ioffset++]);
fan_count --;
}
--
1.7.7
Dan Gora
2013-03-22 00:17:51 UTC
Permalink
Rewrote ipmi_ek_display_chassis_info_area,
ipmi_ek_display_product_info_area, and
ipmi_ekanalyzer_fru_file2structure to reverse the checks of error
conditions to reduce the amount of indentation required.

Signed-off-by: Dan Gora <***@adax.com>
---
ipmitool/lib/ipmi_ekanalyzer.c | 326 ++++++++++++++++++++--------------------
1 files changed, 163 insertions(+), 163 deletions(-)

diff --git a/ipmitool/lib/ipmi_ekanalyzer.c b/ipmitool/lib/ipmi_ekanalyzer.c
index 3ac7a79..b1c5cb2 100644
--- a/ipmitool/lib/ipmi_ekanalyzer.c
+++ b/ipmitool/lib/ipmi_ekanalyzer.c
@@ -2536,51 +2536,53 @@ ipmi_ek_display_fru_header_detail( char * filename )
*
***************************************************************************/
static void
-ipmi_ek_display_chassis_info_area( FILE * input_file, long offset )
+ipmi_ek_display_chassis_info_area(FILE * input_file, long offset)
{
- if ( input_file != NULL ){
- printf("%s\n", EQUAL_LINE_LIMITER);
- printf("Chassis Info Area\n");
- printf("%s\n", EQUAL_LINE_LIMITER);
+ unsigned char data = 0;
+ unsigned char ch_type = 0;
+ unsigned int len;
+ size_t file_offset;

- fseek (input_file, offset, SEEK_SET);
- if ( !feof(input_file) ){
- unsigned char data = 0;
- unsigned int len = 0;
+ if ( input_file == NULL )
+ return;

- fread (&data, 1, 1, input_file);
- printf("Format Version Number: %d\n", (data & 0x0f) );
- if ( !feof(input_file) ){
- fread (&len, 1, 1, input_file);
- /* len is in factor of 8 bytes */
- len = len * 8;
- printf("Area Length: %d\n", len);
- len -= 2;
- }
- if ( !feof(input_file) ){
- unsigned char ch_type = 0;
- size_t file_offset = ftell (input_file);
- /* Chassis Type*/
- fread (&ch_type, 1, 1, input_file);
- printf("Chassis Type: %d\n", ch_type);
- len --;
- /* Chassis Part Number*/
- file_offset = ipmi_ek_display_board_info_area ( input_file,
- "Chassis Part Number", &len);
- fseek (input_file, file_offset, SEEK_SET);
- /* Chassis Serial */
- file_offset = ipmi_ek_display_board_info_area ( input_file,
- "Chassis Serial Number", &len);
- fseek (input_file, file_offset, SEEK_SET);
- /* Custom product info area */
- file_offset = ipmi_ek_display_board_info_area (
- input_file, "Custom", &len);
- }
- }
- }
- else{
- lprintf(LOG_ERR, "Invalid Chassis Info Area!");
- }
+ printf("%s\n", EQUAL_LINE_LIMITER);
+ printf("Chassis Info Area\n");
+ printf("%s\n", EQUAL_LINE_LIMITER);
+
+ fseek (input_file, offset, SEEK_SET);
+ if ( feof(input_file) ) {
+ lprintf(LOG_ERR, "Invalid Chassis Info Area!");
+ return;
+ }
+
+ fread (&data, 1, 1, input_file);
+ printf("Format Version Number: %d\n", (data & 0x0f) );
+ if ( feof(input_file) )
+ return;
+
+ fread (&len, 1, 1, input_file);
+ /* len is in factor of 8 bytes */
+ len = len * 8;
+ printf("Area Length: %d\n", len);
+ len -= 2;
+ if ( feof(input_file) )
+ return;
+ /* Chassis Type*/
+ fread (&ch_type, 1, 1, input_file);
+ printf("Chassis Type: %d\n", ch_type);
+ len --;
+ /* Chassis Part Number*/
+ file_offset = ipmi_ek_display_board_info_area(input_file,
+ "Chassis Part Number", &len);
+ fseek (input_file, file_offset, SEEK_SET);
+ /* Chassis Serial */
+ file_offset = ipmi_ek_display_board_info_area(input_file,
+ "Chassis Serial Number", &len);
+ fseek (input_file, file_offset, SEEK_SET);
+ /* Custom product info area */
+ file_offset = ipmi_ek_display_board_info_area(input_file,
+ "Custom", &len);
}

/**************************************************************************
@@ -2726,68 +2728,70 @@ ipmi_ek_display_board_info_area( FILE * input_file, char * board_type,
static void
ipmi_ek_display_product_info_area( FILE * input_file, long offset )
{
- if ( input_file != NULL ){
- printf("%s\n", EQUAL_LINE_LIMITER);
- printf("Product Info Area\n");
- printf("%s\n", EQUAL_LINE_LIMITER);
+ unsigned char data = 0;
+ unsigned int len;
+ size_t file_offset = ftell (input_file);

- fseek (input_file, offset, SEEK_SET);
- if ( !feof(input_file) ){
- unsigned char data = 0;
- unsigned int len = 0;
+ if ( input_file == NULL )
+ return;

- fread (&data, 1, 1, input_file);
- printf("Format Version Number: %d\n", (data & 0x0f) );
- if ( !feof(input_file) ){
- fread (&len, 1, 1, input_file);
- /* length is in factor of 8 bytes */
- len = len * 8;
- printf("Area Length: %d\n", len);
- len -= 2; /* -1 byte of format version and -1 byte itself */
- }
- if ( !feof(input_file) ){
- size_t file_offset = ftell (input_file);
+ printf("%s\n", EQUAL_LINE_LIMITER);
+ printf("Product Info Area\n");
+ printf("%s\n", EQUAL_LINE_LIMITER);

- fread (&data, 1, 1, input_file);
- printf("Language Code: %d\n", data);
- len --;
- /* Product Mfg */
- file_offset = ipmi_ek_display_board_info_area ( input_file,
- "Product Manufacture Data", &len);
- fseek (input_file, file_offset, SEEK_SET);
- /* Product Name */
- file_offset = ipmi_ek_display_board_info_area ( input_file,
- "Product Name", &len);
- fseek (input_file, file_offset, SEEK_SET);
- /* Product Part */
- file_offset = ipmi_ek_display_board_info_area ( input_file,
- "Product Part/Model Number", &len);
- fseek (input_file, file_offset, SEEK_SET);
- /* Product Version */
- file_offset = ipmi_ek_display_board_info_area ( input_file,
- "Product Version", &len);
- fseek (input_file, file_offset, SEEK_SET);
- /* Product Serial */
- file_offset = ipmi_ek_display_board_info_area ( input_file,
- "Product Serial Number", &len);
- fseek (input_file, file_offset, SEEK_SET);
- /* Product Asset Tag */
- file_offset = ipmi_ek_display_board_info_area ( input_file,
- "Asset Tag", &len);
- fseek (input_file, file_offset, SEEK_SET);
- /* FRU file ID */
- file_offset = ipmi_ek_display_board_info_area (
- input_file, "FRU File ID", &len);
- fseek (input_file, file_offset, SEEK_SET);
- /* Custom product info area */
- file_offset = ipmi_ek_display_board_info_area (
- input_file, "Custom", &len);
- }
- }
- }
- else{
- lprintf(LOG_ERR, "Invalid Product Info Area!");
- }
+ fseek (input_file, offset, SEEK_SET);
+ if ( feof(input_file) ){
+ lprintf(LOG_ERR, "Invalid Product Info Area!");
+ return;
+ }
+
+ fread (&data, 1, 1, input_file);
+ printf("Format Version Number: %d\n", (data & 0x0f) );
+ if ( feof(input_file) )
+ return;
+
+ fread (&len, 1, 1, input_file);
+ /* length is in factor of 8 bytes */
+ len = len * 8;
+ printf("Area Length: %d\n", len);
+ len -= 2; /* -1 byte of format version and -1 byte itself */
+ if ( feof(input_file) )
+ return;
+
+ fread (&data, 1, 1, input_file);
+ printf("Language Code: %d\n", data);
+ len --;
+ /* Product Mfg */
+ file_offset = ipmi_ek_display_board_info_area ( input_file,
+ "Product Manufacture Data", &len);
+ fseek (input_file, file_offset, SEEK_SET);
+ /* Product Name */
+ file_offset = ipmi_ek_display_board_info_area ( input_file,
+ "Product Name", &len);
+ fseek (input_file, file_offset, SEEK_SET);
+ /* Product Part */
+ file_offset = ipmi_ek_display_board_info_area ( input_file,
+ "Product Part/Model Number", &len);
+ fseek (input_file, file_offset, SEEK_SET);
+ /* Product Version */
+ file_offset = ipmi_ek_display_board_info_area ( input_file,
+ "Product Version", &len);
+ fseek (input_file, file_offset, SEEK_SET);
+ /* Product Serial */
+ file_offset = ipmi_ek_display_board_info_area ( input_file,
+ "Product Serial Number", &len);
+ fseek (input_file, file_offset, SEEK_SET);
+ /* Product Asset Tag */
+ file_offset = ipmi_ek_display_board_info_area ( input_file,
+ "Asset Tag", &len);
+ fseek (input_file, file_offset, SEEK_SET);
+ /* FRU file ID */
+ file_offset = ipmi_ek_display_board_info_area (
+ input_file, "FRU File ID", &len);
+ fseek (input_file, file_offset, SEEK_SET);
+ /* Custom product info area */
+ file_offset = ipmi_ek_display_board_info_area (
+ input_file, "Custom", &len);
}

/**************************************************************************
@@ -3875,71 +3879,67 @@ ipmi_ekanalyzer_fru_file2structure( char * filename,
struct ipmi_ek_multi_header ** list_record,
struct ipmi_ek_multi_header ** list_last )
{
- int return_status = ERROR_STATUS;
- FILE * input_file;
+ int return_status = ERROR_STATUS;
+ FILE * input_file;
+ unsigned char last_record = 0;
+ long multi_offset;
+ int record_count = 0;

+ input_file = fopen ( filename, "r");
+ if ( input_file == NULL ){
+ lprintf(LOG_ERR, "File: '%s' is not found", filename);
+ return ERROR_STATUS;
+ }

- input_file = fopen ( filename, "r");
- if ( input_file == NULL ){
- lprintf(LOG_ERR, "File: '%s' is not found", filename);
- return_status = ERROR_STATUS;
- }
- else{
- long multi_offset = 0;
- fseek ( input_file, START_DATA_OFFSET, SEEK_SET );
- fread ( &multi_offset, 1, 1, input_file );
- if ( multi_offset <= 0 ){
- lprintf(LOG_NOTICE, "There is no multi record in the file %s\n",
- filename);
- }
- else{
- int record_count = 0;
+ fseek ( input_file, START_DATA_OFFSET, SEEK_SET );
+ fread ( &multi_offset, 1, 1, input_file );
+ if ( data <= 0 ){
+ lprintf(LOG_NOTICE, "There is no multi record in the file %s\n",
+ filename);
+ fclose( input_file );
+ return OK_STATUS;
+ }
+ /*the offset value is in multiple of 8 bytes.*/
+ multi_offset = data * 8;
+ if ( verbose == LOG_DEBUG ) {
+ printf( "start multi offset = 0x%02lx\n", multi_offset );
+ }
+ fseek ( input_file, multi_offset, SEEK_SET );
+ while ( !feof( input_file ) ) {
+ *list_record = malloc ( sizeof (struct ipmi_ek_multi_header) );
+ fread ( &(*list_record)->header, START_DATA_OFFSET, 1, input_file);
+ if ( (*list_record)->header.len == 0 ){
+ record_count++;
+ continue;
+ }
+ (*list_record)->data = malloc((*list_record)->header.len);
+ if ( (*list_record)->data == NULL ){
+ lprintf(LOG_ERR, "Failed to allocation memory size %d\n",
+ (*list_record)->header.len);
+ record_count++;
+ continue;
+ }

- if ( verbose == LOG_DEBUG ){
- printf( "start multi offset = 0x%02lx\n", multi_offset );
- }
- /*the offset value is in multiple of 8 bytes.*/
- multi_offset = multi_offset * 8;
- fseek ( input_file, multi_offset, SEEK_SET );
- while ( !feof( input_file ) ){
- *list_record = malloc ( sizeof (struct ipmi_ek_multi_header) );
- fread ( &(*list_record)->header, START_DATA_OFFSET, 1, input_file);
- if ( (*list_record)->header.len > 0 ){
- (*list_record)->data =
- malloc ((*list_record)->header.len);
- if ( (*list_record)->data == NULL ){
- lprintf(LOG_ERR, "Lack of memory");
- }
- else{
- unsigned char last_record = 0;
-
- fread ( (*list_record)->data,
- ((*list_record)->header.len), 1, input_file);
- if ( verbose > 0 )
- printf("Record %d has length = %02x\n", record_count,
- (*list_record)->header.len);
- if ( verbose > 1 ){
- int i;
- printf("%02x\t", (*list_record)->header.type);
- for ( i = 0; i < ( (*list_record)->header.len ); i++ ){
- printf("%02x\t", (*list_record)->data[i]);
- }
- printf("\n");
- }
- ipmi_ek_add_record2list ( list_record, list_head, list_last );
- /*mask the 8th bits to see if it is the last record*/
- last_record = ((*list_record)->header.format) & 0x80;
- if ( last_record ){
- break;
- }
- }
- }
- record_count++;
- }
- }
- fclose( input_file );
- return_status = OK_STATUS;
- }
+ fread ( (*list_record)->data, ((*list_record)->header.len), 1,
+ input_file);
+ if ( verbose > 0 )
+ printf("Record %d has length = %02x\n", record_count,
+ (*list_record)->header.len);
+ if ( verbose > 1 ) {
+ int i;
+ printf("%02x\t", (*list_record)->header.type);
+ for ( i = 0; i < ( (*list_record)->header.len ); i++ ){
+ printf("%02x\t", (*list_record)->data[i]);
+ }
+ printf("\n");
+ }
+ ipmi_ek_add_record2list ( list_record, list_head, list_last );
+ /*mask the 8th bits to see if it is the last record*/
+ last_record = ((*list_record)->header.format) & 0x80;
+ if ( last_record )
+ break;
+ record_count++;
+ }
return return_status;
}
--
1.7.7
Dan Gora
2013-03-22 00:17:56 UTC
Permalink
Change the amc channel descriptor ports to be displayed in decimal
instead of hex. This matches the fru -v output in ipmitool.

Add decimal value of Link Asymetric Match values. So people don't have to
look up the value in the source or in the PIGMG spec.

Signed-off-by: Dan Gora <***@adax.com>
---
ipmitool/lib/ipmi_ekanalyzer.c | 29 +++++++++++++++++------------
1 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/ipmitool/lib/ipmi_ekanalyzer.c b/ipmitool/lib/ipmi_ekanalyzer.c
index f61387f..3218413 100644
--- a/ipmitool/lib/ipmi_ekanalyzer.c
+++ b/ipmitool/lib/ipmi_ekanalyzer.c
@@ -2110,21 +2110,24 @@ ipmi_ek_display_link_descriptor( int file_type, unsigned char rsc_id,
printf(" - Link Type extension: %s\n",
val2str (link_desc.type_ext, ipmi_ekanalyzer_extension_PCIE) );
printf(" - Link Group ID: %d || ", link_desc.group_id );
- printf("Link Asym. Match: %s\n",
+ printf("Link Asym. Match: %d - %s\n",
+ link_desc.asym_match,
val2str (link_desc.asym_match, ipmi_ekanalyzer_asym_PCIE) );
break;
case FRU_PICMGEXT_AMC_LINK_TYPE_ETHERNET:
printf(" - Link Type extension: %s\n",
val2str (link_desc.type_ext, ipmi_ekanalyzer_extension_ETHERNET) );
printf(" - Link Group ID: %d || ", link_desc.group_id );
- printf("Link Asym. Match: %s\n",
+ printf("Link Asym. Match: %d - %s\n",
+ link_desc.asym_match,
val2str (link_desc.asym_match, ipmi_ekanalyzer_asym_PCIE) );
break;
case FRU_PICMGEXT_AMC_LINK_TYPE_STORAGE:
printf(" - Link Type extension: %s\n",
val2str (link_desc.type_ext, ipmi_ekanalyzer_extension_STORAGE) );
printf(" - Link Group ID: %d || ", link_desc.group_id );
- printf("Link Asym. Match: %s\n",
+ printf("Link Asym. Match: %d - %s\n",
+ link_desc.asym_match,
val2str (link_desc.asym_match, ipmi_ekanalyzer_asym_STORAGE) );
break;
default:
@@ -3629,12 +3632,11 @@ ipmi_ek_display_amc_p2p_record( struct ipmi_ek_multi_header * record )
data = record->data[index_data] |
(record->data[index_data + 1] << 8) |
(record->data[index_data + 2] << 16);
- /*Warning: For gcc version between 4.0 and 4.3 this code doesnt work*/
ch_desc = ( struct fru_picmgext_amc_channel_desc_record * ) &data;
- printf(" Lane 0 Port: 0x%02x\n", ch_desc->lane0port);
- printf(" Lane 1 Port: 0x%02x\n", ch_desc->lane1port);
- printf(" Lane 2 Port: 0x%02x\n", ch_desc->lane2port);
- printf(" Lane 3 Port: 0x%02x\n\n", ch_desc->lane3port);
+ printf(" Lane 0 Port: %d\n", ch_desc->lane0port);
+ printf(" Lane 1 Port: %d\n", ch_desc->lane1port);
+ printf(" Lane 2 Port: %d\n", ch_desc->lane2port);
+ printf(" Lane 3 Port: %d\n\n", ch_desc->lane3port);
index_data += FRU_PICMGEXT_AMC_CHANNEL_DESC_RECORD_SIZE;
}
}
@@ -3661,7 +3663,8 @@ ipmi_ek_display_amc_p2p_record( struct ipmi_ek_multi_header * record )
printf("\t- Link Type extension: %s\n",
val2str (link_desc->type_ext, ipmi_ekanalyzer_extension_PCIE));
printf("\t- Link Group ID: %d\n ", link_desc->group_id );
- printf("\t- Link Asym. Match: %s\n",
+ printf("\t- Link Asym. Match: %d - %s\n",
+ link_desc->asym_match,
val2str (link_desc->asym_match, ipmi_ekanalyzer_asym_PCIE));
break;
case FRU_PICMGEXT_AMC_LINK_TYPE_ETHERNET:
@@ -3669,7 +3672,8 @@ ipmi_ek_display_amc_p2p_record( struct ipmi_ek_multi_header * record )
val2str (link_desc->type_ext,
ipmi_ekanalyzer_extension_ETHERNET));
printf("\t- Link Group ID: %d \n", link_desc->group_id );
- printf("\t- Link Asym. Match: %s\n",
+ printf("\t- Link Asym. Match: %d - %s\n",
+ link_desc->asym_match,
val2str (link_desc->asym_match, ipmi_ekanalyzer_asym_PCIE));
break;
case FRU_PICMGEXT_AMC_LINK_TYPE_STORAGE:
@@ -3677,11 +3681,12 @@ ipmi_ek_display_amc_p2p_record( struct ipmi_ek_multi_header * record )
val2str (link_desc->type_ext,
ipmi_ekanalyzer_extension_STORAGE));
printf("\t- Link Group ID: %d \n", link_desc->group_id );
- printf("\t- Link Asym. Match: %s\n",
+ printf("\t- Link Asym. Match: %d - %s\n",
+ link_desc->asym_match,
val2str (link_desc->asym_match, ipmi_ekanalyzer_asym_STORAGE));
break;
default:
- printf("\t- Link Type extension: %i\n", link_desc->type_ext );
+ printf("\t- Link Type extension: %i (Unknown)\n", link_desc->type_ext );
printf("\t- Link Group ID: %d \n", link_desc->group_id );
printf("\t- Link Asym. Match: %i\n", link_desc->asym_match);
break;
--
1.7.7
Dan Gora
2013-03-22 00:17:57 UTC
Permalink
ipmi_ekanalyzer_fru_file2structure would return ERROR_STATUS even if
it finished sucessfully.

Signed-off-by: Dan Gora <***@adax.com>
---
ipmitool/lib/ipmi_ekanalyzer.c | 5 ++---
1 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/ipmitool/lib/ipmi_ekanalyzer.c b/ipmitool/lib/ipmi_ekanalyzer.c
index 3218413..6529dd8 100644
--- a/ipmitool/lib/ipmi_ekanalyzer.c
+++ b/ipmitool/lib/ipmi_ekanalyzer.c
@@ -3939,7 +3939,6 @@ ipmi_ekanalyzer_fru_file2structure( char * filename,
struct ipmi_ek_multi_header ** list_record,
struct ipmi_ek_multi_header ** list_last )
{
- int return_status = ERROR_STATUS;
FILE * input_file;
char data;
unsigned char last_record = 0;
@@ -3958,7 +3957,7 @@ ipmi_ekanalyzer_fru_file2structure( char * filename,
lprintf(LOG_NOTICE, "There is no multi record in the file %s\n",
filename);
fclose( input_file );
- return OK_STATUS;
+ return ERROR_STATUS;
}
/*the offset value is in multiple of 8 bytes.*/
multi_offset = data * 8;
@@ -4001,7 +4000,7 @@ ipmi_ekanalyzer_fru_file2structure( char * filename,
break;
record_count++;
}
- return return_status;
+ return OK_STATUS;
}
--
1.7.7
Dan Gora
2013-03-22 00:17:55 UTC
Permalink
Due to a bug in gcc where unaligned bit fields were not packed correctly
before gcc 4.4, we changed the fru_picmgext_amc_channel_desc_record
and fru_picmgext_amc_link_desc_record structures to use
larger types to be packed correctly. This then requires
us to use the FRU_PICMGEXT_AMC_CHANNEL_DESC_RECORD_SIZE and
FRU_PICMGEXT_AMC_LINK_DESC_RECORD_SIZE defines instead of sizeof for
these structures.

Updated ipmi_ek_create_amc_p2p_record() and
ipmi_ek_display_amc_p2p_record() to read data in the correct byte order
on both big and little endian machines.

Signed-off-by: Dan Gora <***@adax.com>
---
ipmitool/lib/ipmi_ekanalyzer.c | 90 ++++++++++++++++++++++++++++-----------
1 files changed, 64 insertions(+), 26 deletions(-)

diff --git a/ipmitool/lib/ipmi_ekanalyzer.c b/ipmitool/lib/ipmi_ekanalyzer.c
index fb4f66a..f61387f 100644
--- a/ipmitool/lib/ipmi_ekanalyzer.c
+++ b/ipmitool/lib/ipmi_ekanalyzer.c
@@ -2226,7 +2226,7 @@ ipmi_ek_create_amc_p2p_record( struct ipmi_ek_multi_header * record,
/*Calculate link descriptor count*/
amc_record->link_desc_count = ( (record->header.len) - 8 -
(SIZE_OF_GUID*amc_record->guid_count) -
- ( sizeof(struct fru_picmgext_amc_channel_desc_record)*
+ (FRU_PICMGEXT_AMC_CHANNEL_DESC_RECORD_SIZE *
amc_record->ch_count )
)/5 ;
}
@@ -2235,7 +2235,7 @@ ipmi_ek_create_amc_p2p_record( struct ipmi_ek_multi_header * record,
amc_record->ch_count = record->data[index_data++];
/*Calculate link descriptor count see spec AMC.0 for detail*/
amc_record->link_desc_count = ( (record->header.len) - 8 -
- ( sizeof(struct fru_picmgext_amc_channel_desc_record)*
+ (FRU_PICMGEXT_AMC_CHANNEL_DESC_RECORD_SIZE *
amc_record->ch_count )
) / 5;
}
@@ -2245,10 +2245,20 @@ ipmi_ek_create_amc_p2p_record( struct ipmi_ek_multi_header * record,
amc_record->ch_desc = malloc ( (amc_record->ch_count) * \
sizeof(struct fru_picmgext_amc_channel_desc_record));
for (ch_index = 0; ch_index < amc_record->ch_count; ch_index++){
- memcpy(&amc_record->ch_desc[ch_index], &record->data[index_data],
- sizeof(struct fru_picmgext_amc_channel_desc_record) );
-
- index_data += sizeof(struct fru_picmgext_amc_channel_desc_record) ;
+ unsigned int data;
+ struct fru_picmgext_amc_channel_desc_record *src, *dst;
+ data = record->data[index_data] |
+ (record->data[index_data + 1] << 8) |
+ (record->data[index_data + 2] << 16);
+
+ src = (struct fru_picmgext_amc_channel_desc_record *) &data;
+ dst = (struct fru_picmgext_amc_channel_desc_record *)
+ &amc_record->ch_desc[ch_index];
+ dst->lane0port = src->lane0port;
+ dst->lane1port = src->lane1port;
+ dst->lane2port = src->lane2port;
+ dst->lane3port = src->lane3port;
+ index_data += FRU_PICMGEXT_AMC_CHANNEL_DESC_RECORD_SIZE;
}
}
if (amc_record->link_desc_count > 0){
@@ -2256,9 +2266,27 @@ ipmi_ek_create_amc_p2p_record( struct ipmi_ek_multi_header * record,
amc_record->link_desc = malloc ( amc_record->link_desc_count *
sizeof(struct fru_picmgext_amc_link_desc_record) );
for (i = 0; i< amc_record->link_desc_count; i++ ){
- memcpy (&amc_record->link_desc[i], &record->data[index_data],
- sizeof(struct fru_picmgext_amc_link_desc_record) );
- index_data += sizeof (struct fru_picmgext_amc_link_desc_record);
+ unsigned int data[2];
+ struct fru_picmgext_amc_link_desc_record *src, *dst;
+ data[0] = record->data[index_data] |
+ (record->data[index_data + 1] << 8) |
+ (record->data[index_data + 2] << 16) |
+ (record->data[index_data + 3] << 24);
+ data[1] = record->data[index_data + 4];
+ src = (struct fru_picmgext_amc_link_desc_record*) &data;
+ dst = (struct fru_picmgext_amc_link_desc_record*)
+ &amc_record->link_desc[i];
+
+ dst->channel_id = src->channel_id;
+ dst->port_flag_0 = src->port_flag_0;
+ dst->port_flag_1 = src->port_flag_1;
+ dst->port_flag_2 = src->port_flag_2;
+ dst->port_flag_3 = src->port_flag_3;
+ dst->type = src->type;
+ dst->type_ext = src->type_ext;
+ dst->group_id = src->group_id;
+ dst->asym_match = src->asym_match;
+ index_data += FRU_PICMGEXT_AMC_LINK_DESC_RECORD_SIZE;
}
}
else{
@@ -3592,31 +3620,41 @@ ipmi_ek_display_amc_p2p_record( struct ipmi_ek_multi_header * record )

if ( ch_count > 0 ){
for ( index = 0; index < ch_count; index++ ){
+ unsigned int data;
struct fru_picmgext_amc_channel_desc_record * ch_desc;
printf(" AMC Channel Descriptor {%02x%02x%02x}\n",
record->data[index_data+2], record->data[index_data+1],
record->data[index_data]
);
+ data = record->data[index_data] |
+ (record->data[index_data + 1] << 8) |
+ (record->data[index_data + 2] << 16);
/*Warning: For gcc version between 4.0 and 4.3 this code doesnt work*/
- ch_desc = ( struct fru_picmgext_amc_channel_desc_record * )\
- &record->data[index_data];
+ ch_desc = ( struct fru_picmgext_amc_channel_desc_record * ) &data;
printf(" Lane 0 Port: 0x%02x\n", ch_desc->lane0port);
printf(" Lane 1 Port: 0x%02x\n", ch_desc->lane1port);
printf(" Lane 2 Port: 0x%02x\n", ch_desc->lane2port);
printf(" Lane 3 Port: 0x%02x\n\n", ch_desc->lane3port);
- index_data += sizeof (struct fru_picmgext_amc_channel_desc_record) ;
+ index_data += FRU_PICMGEXT_AMC_CHANNEL_DESC_RECORD_SIZE;
}
}
while ( index_data < record->header.len ){
/*Warning: For gcc version between 4.0 and 4.3 this code doesnt work*/
- struct fru_picmgext_amc_link_desc_record * link_desc =
- (struct fru_picmgext_amc_link_desc_record *)&record->data[index_data];
+ unsigned int data[2];
+ struct fru_picmgext_amc_link_desc_record *link_desc;
+ data[0] = record->data[index_data] |
+ (record->data[index_data + 1] << 8) |
+ (record->data[index_data + 2] << 16) |
+ (record->data[index_data + 3] << 24);
+ data[1] = record->data[index_data + 4];
+
+ link_desc = (struct fru_picmgext_amc_link_desc_record *) &data[0];

- printf(" AMC Link Descriptor:\n" );
+ printf(" AMC Link Descriptor:\n" );

- printf("\t- Link Type: %s \n",
- val2str (link_desc->type, ipmi_ekanalyzer_link_type));
- switch ( link_desc->type ){
+ printf("\t- Link Type: %s \n",
+ val2str (link_desc->type, ipmi_ekanalyzer_link_type));
+ switch ( link_desc->type ) {
case FRU_PICMGEXT_AMC_LINK_TYPE_PCIE:
case FRU_PICMGEXT_AMC_LINK_TYPE_PCIE_AS1:
case FRU_PICMGEXT_AMC_LINK_TYPE_PCIE_AS2:
@@ -3647,14 +3685,14 @@ ipmi_ek_display_amc_p2p_record( struct ipmi_ek_multi_header * record )
printf("\t- Link Group ID: %d \n", link_desc->group_id );
printf("\t- Link Asym. Match: %i\n", link_desc->asym_match);
break;
- }
- printf("\t- AMC Link Designator:\n");
- printf("\t Channel ID: %i\n", link_desc->channel_id);
- printf("\t\t Lane 0: %s\n", (link_desc->port_flag_0)?"enable":"disable");
- printf("\t\t Lane 1: %s\n", (link_desc->port_flag_1)?"enable":"disable");
- printf("\t\t Lane 2: %s\n", (link_desc->port_flag_2)?"enable":"disable");
- printf("\t\t Lane 3: %s\n", (link_desc->port_flag_3)?"enable":"disable");
- index_data += sizeof (struct fru_picmgext_amc_link_desc_record);
+ }
+ printf("\t- AMC Link Designator:\n");
+ printf("\t Channel ID: %i\n", link_desc->channel_id);
+ printf("\t\t Lane 0: %s\n", (link_desc->port_flag_0)?"enable":"disable");
+ printf("\t\t Lane 1: %s\n", (link_desc->port_flag_1)?"enable":"disable");
+ printf("\t\t Lane 2: %s\n", (link_desc->port_flag_2)?"enable":"disable");
+ printf("\t\t Lane 3: %s\n", (link_desc->port_flag_3)?"enable":"disable");
+ index_data += FRU_PICMGEXT_AMC_LINK_DESC_RECORD_SIZE;
}
}
--
1.7.7
Dan Gora
2013-03-22 00:17:58 UTC
Permalink
If the offset was greater than 127, then the multi_offset would end
up being a negative value, which is not what we want.

Signed-off-by: Dan Gora <***@adax.com>
---
ipmitool/lib/ipmi_ekanalyzer.c | 9 +++++----
1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/ipmitool/lib/ipmi_ekanalyzer.c b/ipmitool/lib/ipmi_ekanalyzer.c
index 6529dd8..2da4650 100644
--- a/ipmitool/lib/ipmi_ekanalyzer.c
+++ b/ipmitool/lib/ipmi_ekanalyzer.c
@@ -3940,9 +3940,9 @@ ipmi_ekanalyzer_fru_file2structure( char * filename,
struct ipmi_ek_multi_header ** list_last )
{
FILE * input_file;
- char data;
+ unsigned char data;
unsigned char last_record = 0;
- int multi_offset;
+ unsigned int multi_offset;
int record_count = 0;

input_file = fopen ( filename, "r");
@@ -3987,9 +3987,10 @@ ipmi_ekanalyzer_fru_file2structure( char * filename,
(*list_record)->header.len);
if ( verbose > 1 ) {
int i;
- printf("%02x\t", (*list_record)->header.type);
+ printf("Type: %02x\t", (*list_record)->header.type);
for ( i = 0; i < ( (*list_record)->header.len ); i++ ){
- printf("%02x\t", (*list_record)->data[i]);
+ printf("0x%04x: %02x\t",
+ i, (*list_record)->data[i]);
}
printf("\n");
}
--
1.7.7
Zdenek Styblik
2013-04-01 18:48:26 UTC
Permalink
Post by Dan Gora
If the offset was greater than 127, then the multi_offset would end
up being a negative value, which is not what we want.
Dan,

I actually don't understand this patch. Please, can you dumb it down for me?
Also, given your description, I actually don't think problem has been
fixed. Shouldn't there, somewhere, be a check whether offset is less
than 127? Because what you've described is integer *flow going on.

Regards,
Z.
Post by Dan Gora
---
ipmitool/lib/ipmi_ekanalyzer.c | 9 +++++----
1 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/ipmitool/lib/ipmi_ekanalyzer.c b/ipmitool/lib/ipmi_ekanalyzer.c
index 6529dd8..2da4650 100644
--- a/ipmitool/lib/ipmi_ekanalyzer.c
+++ b/ipmitool/lib/ipmi_ekanalyzer.c
@@ -3940,9 +3940,9 @@ ipmi_ekanalyzer_fru_file2structure( char * filename,
struct ipmi_ek_multi_header ** list_last )
{
FILE * input_file;
- char data;
+ unsigned char data;
unsigned char last_record = 0;
- int multi_offset;
+ unsigned int multi_offset;
int record_count = 0;
input_file = fopen ( filename, "r");
@@ -3987,9 +3987,10 @@ ipmi_ekanalyzer_fru_file2structure( char * filename,
(*list_record)->header.len);
if ( verbose > 1 ) {
int i;
- printf("%02x\t", (*list_record)->header.type);
+ printf("Type: %02x\t", (*list_record)->header.type);
for ( i = 0; i < ( (*list_record)->header.len ); i++ ){
- printf("%02x\t", (*list_record)->data[i]);
+ printf("0x%04x: %02x\t",
+ i, (*list_record)->data[i]);
}
printf("\n");
}
--
1.7.7
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Ipmitool-devel mailing list
https://lists.sourceforge.net/lists/listinfo/ipmitool-devel
Dan Gora
2013-04-01 18:59:31 UTC
Permalink
Post by Zdenek Styblik
Post by Dan Gora
If the offset was greater than 127, then the multi_offset would end
up being a negative value, which is not what we want.
Dan,
I actually don't understand this patch. Please, can you dumb it down for me?
Also, given your description, I actually don't think problem has been
fixed. Shouldn't there, somewhere, be a check whether offset is less
than 127? Because what you've described is integer *flow going on.
Here's the patched code:

FILE * input_file;
unsigned char data;
unsigned char last_record = 0;
unsigned int multi_offset;
int record_count = 0;

input_file = fopen ( filename, "r");
if ( input_file == NULL ){
lprintf(LOG_ERR, "File: '%s' is not found", filename);
return ERROR_STATUS;
}

fseek ( input_file, START_DATA_OFFSET, SEEK_SET );
fread ( &data, 1, 1, input_file );
if ( data <= 0 ){
lprintf(LOG_NOTICE, "There is no multi record in the file %s\n",
filename);
fclose( input_file );
return ERROR_STATUS;
}
/*the offset value is in multiple of 8 bytes.*/
multi_offset = data * 8;
if ( verbose == LOG_DEBUG ) {
printf( "start multi offset = 0x%02lx\n", multi_offset );
}
fseek ( input_file, multi_offset, SEEK_SET );
while ( !feof( input_file ) ) {
*list_record = malloc ( sizeof (struct ipmi_ek_multi_header) );
fread ( &(*list_record)->header, START_DATA_OFFSET, 1,
input_file);
if ( (*list_record)->header.len == 0 ){
record_count++;
continue;
}


So, 'data' is 1 byte long and it's reading an offset field. The
offset cannot be negative, but it *could* (I guess, in theory, but it
probably never is in practice) be greater than 127. Since the offset
is always positive you want 'data' and 'multi_offset' to be positive,
so we should use unsigned types for these. If 'data' was 128 or more,
it would have yielded a negative offset for the fseek in "fseek (
input_file, multi_offset, SEEK_SET );"

I didn't actually see this bug, but it looked wrong. The offset
should never be negative, but there's nothing saying that it has to be
less than 128.

thanks
d
Zdenek Styblik
2013-04-01 19:10:43 UTC
Permalink
Post by Dan Gora
Post by Zdenek Styblik
Post by Dan Gora
If the offset was greater than 127, then the multi_offset would end
up being a negative value, which is not what we want.
Dan,
I actually don't understand this patch. Please, can you dumb it down for me?
Also, given your description, I actually don't think problem has been
fixed. Shouldn't there, somewhere, be a check whether offset is less
than 127? Because what you've described is integer *flow going on.
I've moved up the following piece of text.
Post by Dan Gora
I didn't actually see this bug, but it looked wrong. The offset
should never be negative, but there's nothing saying that it has to be
less than 128.
Alright, that was my point. Some comments follow.
Post by Dan Gora
FILE * input_file;
unsigned char data;
unsigned char last_record = 0;
unsigned int multi_offset;
int record_count = 0;
input_file = fopen ( filename, "r");
if ( input_file == NULL ){
lprintf(LOG_ERR, "File: '%s' is not found", filename);
return ERROR_STATUS;
}
fseek ( input_file, START_DATA_OFFSET, SEEK_SET );
fread ( &data, 1, 1, input_file );
if ( data <= 0 ){
This has to be changed to: ``if (data == 0)'' or ``if (data < 1)''
since 'data' is unsigned now or it will yield compiler warning.
Post by Dan Gora
lprintf(LOG_NOTICE, "There is no multi record in the file %s\n",
filename);
This LOG_NOTICE -> LOG_ERR
Post by Dan Gora
fclose( input_file );
return ERROR_STATUS;
}
/*the offset value is in multiple of 8 bytes.*/
multi_offset = data * 8;
if ( verbose == LOG_DEBUG ) {
This looks odd to me. I mean, I've seen code like ``if (verbose)'' or
``if (verbose > 2)'' or whatever, but nothing like this. I think this
is wrong.
Post by Dan Gora
printf( "start multi offset = 0x%02lx\n", multi_offset );
}
fseek ( input_file, multi_offset, SEEK_SET );
while ( !feof( input_file ) ) {
*list_record = malloc ( sizeof (struct ipmi_ek_multi_header) );
fread ( &(*list_record)->header, START_DATA_OFFSET, 1,
input_file);
if ( (*list_record)->header.len == 0 ){
record_count++;
continue;
}
So, 'data' is 1 byte long and it's reading an offset field. The
offset cannot be negative, but it *could* (I guess, in theory, but it
probably never is in practice) be greater than 127. Since the offset
is always positive you want 'data' and 'multi_offset' to be positive,
so we should use unsigned types for these. If 'data' was 128 or more,
it would have yielded a negative offset for the fseek in "fseek (
input_file, multi_offset, SEEK_SET );"
thanks
d
Z.
Dan Gora
2013-04-01 19:16:47 UTC
Permalink
Post by Zdenek Styblik
Post by Dan Gora
FILE * input_file;
unsigned char data;
unsigned char last_record = 0;
unsigned int multi_offset;
int record_count = 0;
input_file = fopen ( filename, "r");
if ( input_file == NULL ){
lprintf(LOG_ERR, "File: '%s' is not found", filename);
return ERROR_STATUS;
}
fseek ( input_file, START_DATA_OFFSET, SEEK_SET );
fread ( &data, 1, 1, input_file );
if ( data <= 0 ){
This has to be changed to: ``if (data == 0)'' or ``if (data < 1)''
since 'data' is unsigned now or it will yield compiler warning.
Ok, sure...
I guess that this check was saving it from being negative before the
patch as well, which kind of defeats the whole purpose of this patch,
but as long as we're here...
Post by Zdenek Styblik
Post by Dan Gora
lprintf(LOG_NOTICE, "There is no multi record in the file %s\n",
filename);
This LOG_NOTICE -> LOG_ERR
Ok, but I didn't write this :) I'll change it though.
Post by Zdenek Styblik
Post by Dan Gora
fclose( input_file );
return ERROR_STATUS;
}
/*the offset value is in multiple of 8 bytes.*/
multi_offset = data * 8;
if ( verbose == LOG_DEBUG ) {
This looks odd to me. I mean, I've seen code like ``if (verbose)'' or
``if (verbose > 2)'' or whatever, but nothing like this. I think this
is wrong.
Ok, again, this wasn't part of my patch, it was already like this!

I'll change this too though if you want.

thanks!
d
Dan Gora
2013-03-22 00:18:00 UTC
Permalink
Signed-off-by: Dan Gora <***@adax.com>
---
ipmitool/lib/ipmi_ekanalyzer.c | 167 ++++++++++++++++++++--------------------
1 files changed, 84 insertions(+), 83 deletions(-)

diff --git a/ipmitool/lib/ipmi_ekanalyzer.c b/ipmitool/lib/ipmi_ekanalyzer.c
index 34b6cb6..9fd4be1 100644
--- a/ipmitool/lib/ipmi_ekanalyzer.c
+++ b/ipmitool/lib/ipmi_ekanalyzer.c
@@ -2210,93 +2210,94 @@ static int
ipmi_ek_create_amc_p2p_record( struct ipmi_ek_multi_header * record,
struct ipmi_ek_amc_p2p_connectivity_record * amc_record )
{
- int return_status = OK_STATUS;
- int index_data = START_DATA_OFFSET;
+ int return_status = OK_STATUS;
+ int index_data = START_DATA_OFFSET;

- amc_record->guid_count = record->data[index_data++];
- if ( amc_record->guid_count > 0){
- int index_oem = 0;
- amc_record->oem_guid = malloc (amc_record->guid_count * \
- sizeof(struct fru_picmgext_guid) );
- for (index_oem = 0; index_oem < amc_record->guid_count; index_oem++){
- memcpy ( &amc_record->oem_guid[index_oem].guid,
- &record->data[index_data],
- SIZE_OF_GUID );
- index_data += (int)SIZE_OF_GUID;
- }
- amc_record->rsc_id = record->data[index_data++];
- amc_record->ch_count = record->data[index_data++];
- /*Calculate link descriptor count*/
- amc_record->link_desc_count = ( (record->header.len) - 8 -
- (SIZE_OF_GUID*amc_record->guid_count) -
- (FRU_PICMGEXT_AMC_CHANNEL_DESC_RECORD_SIZE *
- amc_record->ch_count )
- )/5 ;
- }
- else{
- amc_record->rsc_id = record->data[index_data++];
- amc_record->ch_count = record->data[index_data++];
- /*Calculate link descriptor count see spec AMC.0 for detail*/
- amc_record->link_desc_count = ( (record->header.len) - 8 -
- (FRU_PICMGEXT_AMC_CHANNEL_DESC_RECORD_SIZE *
- amc_record->ch_count )
- ) / 5;
- }
+ amc_record->guid_count = record->data[index_data++];

- if (amc_record->ch_count > 0){
- int ch_index = 0;
- amc_record->ch_desc = malloc ( (amc_record->ch_count) * \
- sizeof(struct fru_picmgext_amc_channel_desc_record));
- for (ch_index = 0; ch_index < amc_record->ch_count; ch_index++){
- unsigned int data;
- struct fru_picmgext_amc_channel_desc_record *src, *dst;
- data = record->data[index_data] |
- (record->data[index_data + 1] << 8) |
- (record->data[index_data + 2] << 16);
-
- src = (struct fru_picmgext_amc_channel_desc_record *) &data;
- dst = (struct fru_picmgext_amc_channel_desc_record *)
- &amc_record->ch_desc[ch_index];
- dst->lane0port = src->lane0port;
- dst->lane1port = src->lane1port;
- dst->lane2port = src->lane2port;
- dst->lane3port = src->lane3port;
- index_data += FRU_PICMGEXT_AMC_CHANNEL_DESC_RECORD_SIZE;
- }
- }
- if (amc_record->link_desc_count > 0){
- int i=0;
- amc_record->link_desc = malloc ( amc_record->link_desc_count *
- sizeof(struct fru_picmgext_amc_link_desc_record) );
- for (i = 0; i< amc_record->link_desc_count; i++ ){
- unsigned int data[2];
- struct fru_picmgext_amc_link_desc_record *src, *dst;
- data[0] = record->data[index_data] |
- (record->data[index_data + 1] << 8) |
- (record->data[index_data + 2] << 16) |
- (record->data[index_data + 3] << 24);
- data[1] = record->data[index_data + 4];
- src = (struct fru_picmgext_amc_link_desc_record*) &data;
- dst = (struct fru_picmgext_amc_link_desc_record*)
- &amc_record->link_desc[i];
+ if ( amc_record->guid_count > 0) {
+ int index_oem = 0;
+ amc_record->oem_guid = malloc (amc_record->guid_count * \
+ sizeof(struct fru_picmgext_guid) );
+ for (index_oem = 0; index_oem < amc_record->guid_count;
+ index_oem++) {
+ memcpy ( &amc_record->oem_guid[index_oem].guid,
+ &record->data[index_data], SIZE_OF_GUID );
+ index_data += SIZE_OF_GUID;
+ }
+ amc_record->rsc_id = record->data[index_data++];
+ amc_record->ch_count = record->data[index_data++];
+ /*Calculate link descriptor count*/
+ amc_record->link_desc_count = ((record->header.len) - 8 -
+ (SIZE_OF_GUID*amc_record->guid_count) -
+ (FRU_PICMGEXT_AMC_CHANNEL_DESC_RECORD_SIZE *
+ amc_record->ch_count)) / 5;
+ } else {
+ amc_record->rsc_id = record->data[index_data++];
+ amc_record->ch_count = record->data[index_data++];
+ /*Calculate link descriptor count see spec AMC.0 for detail*/
+ amc_record->link_desc_count = ((record->header.len) - 8 -
+ (FRU_PICMGEXT_AMC_CHANNEL_DESC_RECORD_SIZE *
+ amc_record->ch_count)) / 5;
+ }

- dst->channel_id = src->channel_id;
- dst->port_flag_0 = src->port_flag_0;
- dst->port_flag_1 = src->port_flag_1;
- dst->port_flag_2 = src->port_flag_2;
- dst->port_flag_3 = src->port_flag_3;
- dst->type = src->type;
- dst->type_ext = src->type_ext;
- dst->group_id = src->group_id;
- dst->asym_match = src->asym_match;
- index_data += FRU_PICMGEXT_AMC_LINK_DESC_RECORD_SIZE;
- }
- }
- else{
- return_status = ERROR_STATUS;
- }
+ if (amc_record->ch_count > 0) {
+ int ch_index;
+ amc_record->ch_desc = malloc((amc_record->ch_count) *
+ sizeof(struct fru_picmgext_amc_channel_desc_record));
+ for (ch_index = 0; ch_index < amc_record->ch_count;
+ ch_index++) {
+ unsigned int data;
+ struct fru_picmgext_amc_channel_desc_record *src, *dst;
+ data = record->data[index_data] |
+ (record->data[index_data + 1] << 8) |
+ (record->data[index_data + 2] << 16);

- return return_status;
+ src = (struct fru_picmgext_amc_channel_desc_record *)
+ &data;
+ dst = (struct fru_picmgext_amc_channel_desc_record *)
+ &amc_record->ch_desc[ch_index];
+ dst->lane0port = src->lane0port;
+ dst->lane1port = src->lane1port;
+ dst->lane2port = src->lane2port;
+ dst->lane3port = src->lane3port;
+ index_data += FRU_PICMGEXT_AMC_CHANNEL_DESC_RECORD_SIZE;
+ }
+ }
+
+ if (amc_record->link_desc_count > 0) {
+ int i;
+ amc_record->link_desc = malloc(amc_record->link_desc_count *
+ sizeof(struct fru_picmgext_amc_link_desc_record));
+ for (i = 0; i < amc_record->link_desc_count; i++) {
+ unsigned int data[2];
+ struct fru_picmgext_amc_link_desc_record *src, *dst;
+ data[0] = record->data[index_data] |
+ (record->data[index_data + 1] << 8) |
+ (record->data[index_data + 2] << 16) |
+ (record->data[index_data + 3] << 24);
+ data[1] = record->data[index_data + 4];
+ src = (struct fru_picmgext_amc_link_desc_record*) &data;
+ dst = (struct fru_picmgext_amc_link_desc_record*)
+ &amc_record->link_desc[i];
+
+ dst->channel_id = src->channel_id;
+ dst->port_flag_0 = src->port_flag_0;
+ dst->port_flag_1 = src->port_flag_1;
+ dst->port_flag_2 = src->port_flag_2;
+ dst->port_flag_3 = src->port_flag_3;
+ dst->type = src->type;
+ dst->type_ext = src->type_ext;
+ dst->group_id = src->group_id;
+ dst->asym_match = src->asym_match;
+ index_data += FRU_PICMGEXT_AMC_LINK_DESC_RECORD_SIZE;
+ }
+ }
+ else {
+ return_status = ERROR_STATUS;
+ }
+
+ return return_status;
}

/**************************************************************************
--
1.7.7
Dan Gora
2013-03-22 00:17:48 UTC
Permalink
Changed to ipmi_ek_display_carrier_connectivity.

Signed-off-by: Dan Gora <***@adax.com>
---
ipmitool/lib/ipmi_ekanalyzer.c | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/ipmitool/lib/ipmi_ekanalyzer.c b/ipmitool/lib/ipmi_ekanalyzer.c
index 6c77c7e..8f1d2f4 100644
--- a/ipmitool/lib/ipmi_ekanalyzer.c
+++ b/ipmitool/lib/ipmi_ekanalyzer.c
@@ -288,7 +288,7 @@ static tboolean ipmi_ek_display_link_descriptor( int file_type,
static void ipmi_ek_display_oem_guid(
struct ipmi_ek_amc_p2p_connectivity_record amc_record1 );

-static int ipmi_ek_diplay_carrier_connectivity(
+static int ipmi_ek_display_carrier_connectivity(
struct ipmi_ek_multi_header * record );

static int ipmi_ek_display_power( int argc, char * opt,
@@ -730,7 +730,7 @@ ipmi_ekanalyzer_print( int argc, char * opt, char ** filename, int * file_type )
printf("
Dan Gora
2013-03-22 00:17:52 UTC
Permalink
Previous versions were not setting the file_offset properly if a Custom
board type was found, which would prevent subsequent dissectors from
operating properly and terminating the output of 'ipmitool ekanalyze
frushow oc=<atca carrier fruinfo>' early.

Rewrote ipmi_ek_display_board_info_area() to fix indentation and
to properly set the file_offset and end the while loop if a Custom
board_type was found.

Previous versions were also abusing the board_length variable,
treating it as an int and using it to break out of the loop.

Signed-off-by: Dan Gora <***@adax.com>
---
ipmitool/lib/ipmi_ekanalyzer.c | 180 ++++++++++++++++++++-------------------
1 files changed, 92 insertions(+), 88 deletions(-)

diff --git a/ipmitool/lib/ipmi_ekanalyzer.c b/ipmitool/lib/ipmi_ekanalyzer.c
index b1c5cb2..2fcf4e5 100644
--- a/ipmitool/lib/ipmi_ekanalyzer.c
+++ b/ipmitool/lib/ipmi_ekanalyzer.c
@@ -2611,98 +2611,102 @@ static size_t
ipmi_ek_display_board_info_area( FILE * input_file, char * board_type,
unsigned int * board_length )
{
- size_t file_offset = ftell (input_file);
- unsigned char len = 0;
- /* Board length*/
- if ( !feof(input_file) ){
- fread ( &len, 1, 1, input_file );
- (*board_length)--;
- }
- /* Board Data */
- if ( !feof(input_file) ){
- unsigned int size_board = 0;
+ size_t file_offset = ftell (input_file);
+ unsigned char len = 0;
+ unsigned int size_board = 0;

- /*Bit 5:0 of Board Mfg type represent legnth*/
- size_board = (len & 0x3f);
- if (size_board > 0){
- if ( strncmp( board_type, "Custom", 6 ) == 0 ){
- #define NO_MORE_INFO_FIELD 0xc1
- while ( !feof(input_file) && (board_length > 0) ){
- if (len != NO_MORE_INFO_FIELD){
- printf("Additional Custom Mfg. length: 0x%02x\n", len);
- if ( (size_board > 0) && (size_board < (*board_length)) ){
- unsigned char * additional_data = NULL;
- int i=0;
- additional_data = malloc (size_board);
- if (additional_data != NULL){
- fread ( additional_data, size_board, 1, input_file );
- printf("Additional Custom Mfg. Data: %02x",
- additional_data[0]);
- for ( i =1; i<size_board; i++){
- printf("-%02x", additional_data[i]);
- }
- printf("\n");
- free (additional_data);
- (*board_length) -= size_board;
- }
- }
- else{
- printf("No Additional Custom Mfg. %d\n", *board_length);
- board_length = 0;
- }
- }
- else{
- unsigned char padding;
- /*take the rest of data in the area minus 1 byte of checksum*/
- printf("Additional Custom Mfg. length: 0x%02x\n", len);
- padding = (*board_length) - 1;
- /*we reach the end of the record, so its length is set to 0*/
- board_length = 0;
- if ( ( padding > 0 ) && ( !feof(input_file) ) ){
- printf("Unused space: %d (bytes)\n", padding);
- fseek (input_file, padding, SEEK_CUR);
- }
- if ( !feof(input_file) ){
- unsigned char checksum = 0;
- fread ( &checksum, 1, 1, input_file );
- printf("Checksum: 0x%02x\n", checksum);
+ /* Board length*/
+ if ( !feof(input_file) ){
+ fread ( &len, 1, 1, input_file );
+ (*board_length)--;
+ }
+ /* Board Data */
+ if ( feof(input_file) ) {
+ printf("No Board Data found!\n");
+ goto out;
+ }

- }
- }
- }
- }
- else{
- unsigned char * data;
- unsigned int i=0;
- #define TYPE_CODE 0xc0 /*Language code*/
+ /*Bit 5:0 of Board Mfg type represent legnth*/
+ size_board = (len & 0x3f);
+ if (size_board == 0) {
+ printf("%s: None\n", board_type);
+ goto out;
+ }

- data = malloc (size_board);
- fread ( data, size_board, 1, input_file );
- printf("%s type: 0x%02x\n", board_type, len);
- printf("%s: ", board_type);
- for ( i = 0; i < size_board; i++ ){
- if ( (len & TYPE_CODE) == TYPE_CODE ){
- printf("%c", data[i]);
- }
- /*other than language code (binary, BCD, ASCII 6 bit...) is not
- * supported */
- else{
- printf("%02x", data[i]);
- }
- }
- printf("\n");
- free (data);
- (*board_length) -= size_board;
- file_offset = ftell (input_file);
- }
- }
- else{
- printf("%s: None\n", board_type);
- file_offset = ftell (input_file);
- }
- }
+ if ( strncmp( board_type, "Custom", 6 ) != 0 ) {
+ unsigned char *data;
+ unsigned int i=0;
+#define TYPE_CODE 0xc0 /*Language code*/
+
+ data = malloc (size_board);
+ fread ( data, size_board, 1, input_file );
+ printf("%s type: 0x%02x\n", board_type, len);
+ printf("%s: ", board_type);
+ for ( i = 0; i < size_board; i++ ) {
+ if ( (len & TYPE_CODE) == TYPE_CODE ){
+ printf("%c", data[i]);
+ }
+ /*other than language code (binary, BCD,
+ * ASCII 6 bit...) is not supported */
+ else {
+ printf("%02x", data[i]);
+ }
+ }
+ printf("\n");
+ free (data);
+ (*board_length) -= size_board;
+ goto out;
+ }
+#define NO_MORE_INFO_FIELD 0xc1
+ while ( !feof(input_file) ) {
+ if (len == NO_MORE_INFO_FIELD) {
+ unsigned char padding;
+ /* take the rest of data in the area minus 1 byte of
+ * checksum*/
+ printf("Additional Custom Mfg. length: 0x%02x\n", len);
+ padding = (*board_length) - 1;
+ if ( ( padding > 0 ) && ( !feof(input_file) ) ){
+ printf("Unused space: %d (bytes)\n", padding);
+ fseek (input_file, padding, SEEK_CUR);
+ }
+ if ( !feof(input_file) ){
+ unsigned char checksum = 0;
+ fread ( &checksum, 1, 1, input_file );
+ printf("Checksum: 0x%02x\n", checksum);
+ }
+ goto out;
+ }
+ printf("Additional Custom Mfg. length: 0x%02x\n", len);
+ if ( (size_board > 0) && (size_board < (*board_length)) ) {
+ unsigned char * additional_data = NULL;
+ unsigned int i=0;
+ additional_data = malloc (size_board);
+ if (additional_data == NULL) {
+ printf("Failed to allocate memory size %d!\n",
+ size_board);
+ goto out;
+ }
+
+ fread ( additional_data, size_board, 1, input_file );
+ printf("Additional Custom Mfg. Data: %02x",
+ additional_data[0]);
+ for (i = 1; i < size_board; i++){
+ printf("-%02x", additional_data[i]);
+ }
+ printf("\n");
+ free (additional_data);
+ (*board_length) -= size_board;
+ }
+ else {
+ printf("No Additional Custom Mfg. %d\n", *board_length);
+ file_offset = ftell (input_file);
+ return file_offset;
+ }
+ }

- return file_offset;
+out:
+ file_offset = ftell(input_file);
+ return file_offset;
}

/**************************************************************************
--
1.7.7
Zdenek Styblik
2013-04-15 19:03:06 UTC
Permalink
Post by Dan Gora
Previous versions were not setting the file_offset properly if a Custom
board type was found, which would prevent subsequent dissectors from
operating properly and terminating the output of 'ipmitool ekanalyze
frushow oc=<atca carrier fruinfo>' early.
Rewrote ipmi_ek_display_board_info_area() to fix indentation and
to properly set the file_offset and end the while loop if a Custom
board_type was found.
Previous versions were also abusing the board_length variable,
treating it as an int and using it to break out of the loop.
---
Attached is a patch which addresses couple issues:
* malloc() is being checked
* returned size on error is (-1)
* possible segfault if one of parameters is NULL

Regards,
Z.
Post by Dan Gora
ipmitool/lib/ipmi_ekanalyzer.c | 180 ++++++++++++++++++++-------------------
1 files changed, 92 insertions(+), 88 deletions(-)
diff --git a/ipmitool/lib/ipmi_ekanalyzer.c b/ipmitool/lib/ipmi_ekanalyzer.c
index b1c5cb2..2fcf4e5 100644
--- a/ipmitool/lib/ipmi_ekanalyzer.c
+++ b/ipmitool/lib/ipmi_ekanalyzer.c
@@ -2611,98 +2611,102 @@ static size_t
ipmi_ek_display_board_info_area( FILE * input_file, char * board_type,
unsigned int * board_length )
{
- size_t file_offset = ftell (input_file);
- unsigned char len = 0;
- /* Board length*/
- if ( !feof(input_file) ){
- fread ( &len, 1, 1, input_file );
- (*board_length)--;
- }
- /* Board Data */
- if ( !feof(input_file) ){
- unsigned int size_board = 0;
+ size_t file_offset = ftell (input_file);
+ unsigned char len = 0;
+ unsigned int size_board = 0;
- /*Bit 5:0 of Board Mfg type represent legnth*/
- size_board = (len & 0x3f);
- if (size_board > 0){
- if ( strncmp( board_type, "Custom", 6 ) == 0 ){
- #define NO_MORE_INFO_FIELD 0xc1
- while ( !feof(input_file) && (board_length > 0) ){
- if (len != NO_MORE_INFO_FIELD){
- printf("Additional Custom Mfg. length: 0x%02x\n", len);
- if ( (size_board > 0) && (size_board < (*board_length)) ){
- unsigned char * additional_data = NULL;
- int i=0;
- additional_data = malloc (size_board);
- if (additional_data != NULL){
- fread ( additional_data, size_board, 1, input_file );
- printf("Additional Custom Mfg. Data: %02x",
- additional_data[0]);
- for ( i =1; i<size_board; i++){
- printf("-%02x", additional_data[i]);
- }
- printf("\n");
- free (additional_data);
- (*board_length) -= size_board;
- }
- }
- else{
- printf("No Additional Custom Mfg. %d\n", *board_length);
- board_length = 0;
- }
- }
- else{
- unsigned char padding;
- /*take the rest of data in the area minus 1 byte of checksum*/
- printf("Additional Custom Mfg. length: 0x%02x\n", len);
- padding = (*board_length) - 1;
- /*we reach the end of the record, so its length is set to 0*/
- board_length = 0;
- if ( ( padding > 0 ) && ( !feof(input_file) ) ){
- printf("Unused space: %d (bytes)\n", padding);
- fseek (input_file, padding, SEEK_CUR);
- }
- if ( !feof(input_file) ){
- unsigned char checksum = 0;
- fread ( &checksum, 1, 1, input_file );
- printf("Checksum: 0x%02x\n", checksum);
+ /* Board length*/
+ if ( !feof(input_file) ){
+ fread ( &len, 1, 1, input_file );
+ (*board_length)--;
+ }
+ /* Board Data */
+ if ( feof(input_file) ) {
+ printf("No Board Data found!\n");
+ goto out;
+ }
- }
- }
- }
- }
- else{
- unsigned char * data;
- unsigned int i=0;
- #define TYPE_CODE 0xc0 /*Language code*/
+ /*Bit 5:0 of Board Mfg type represent legnth*/
+ size_board = (len & 0x3f);
+ if (size_board == 0) {
+ printf("%s: None\n", board_type);
+ goto out;
+ }
- data = malloc (size_board);
- fread ( data, size_board, 1, input_file );
- printf("%s type: 0x%02x\n", board_type, len);
- printf("%s: ", board_type);
- for ( i = 0; i < size_board; i++ ){
- if ( (len & TYPE_CODE) == TYPE_CODE ){
- printf("%c", data[i]);
- }
- /*other than language code (binary, BCD, ASCII 6 bit...) is not
- * supported */
- else{
- printf("%02x", data[i]);
- }
- }
- printf("\n");
- free (data);
- (*board_length) -= size_board;
- file_offset = ftell (input_file);
- }
- }
- else{
- printf("%s: None\n", board_type);
- file_offset = ftell (input_file);
- }
- }
+ if ( strncmp( board_type, "Custom", 6 ) != 0 ) {
+ unsigned char *data;
+ unsigned int i=0;
+#define TYPE_CODE 0xc0 /*Language code*/
+
+ data = malloc (size_board);
+ fread ( data, size_board, 1, input_file );
+ printf("%s type: 0x%02x\n", board_type, len);
+ printf("%s: ", board_type);
+ for ( i = 0; i < size_board; i++ ) {
+ if ( (len & TYPE_CODE) == TYPE_CODE ){
+ printf("%c", data[i]);
+ }
+ /*other than language code (binary, BCD,
+ * ASCII 6 bit...) is not supported */
+ else {
+ printf("%02x", data[i]);
+ }
+ }
+ printf("\n");
+ free (data);
+ (*board_length) -= size_board;
+ goto out;
+ }
+#define NO_MORE_INFO_FIELD 0xc1
+ while ( !feof(input_file) ) {
+ if (len == NO_MORE_INFO_FIELD) {
+ unsigned char padding;
+ /* take the rest of data in the area minus 1 byte of
+ * checksum*/
+ printf("Additional Custom Mfg. length: 0x%02x\n", len);
+ padding = (*board_length) - 1;
+ if ( ( padding > 0 ) && ( !feof(input_file) ) ){
+ printf("Unused space: %d (bytes)\n", padding);
+ fseek (input_file, padding, SEEK_CUR);
+ }
+ if ( !feof(input_file) ){
+ unsigned char checksum = 0;
+ fread ( &checksum, 1, 1, input_file );
+ printf("Checksum: 0x%02x\n", checksum);
+ }
+ goto out;
+ }
+ printf("Additional Custom Mfg. length: 0x%02x\n", len);
+ if ( (size_board > 0) && (size_board < (*board_length)) ) {
+ unsigned char * additional_data = NULL;
+ unsigned int i=0;
+ additional_data = malloc (size_board);
+ if (additional_data == NULL) {
+ printf("Failed to allocate memory size %d!\n",
+ size_board);
+ goto out;
+ }
+
+ fread ( additional_data, size_board, 1, input_file );
+ printf("Additional Custom Mfg. Data: %02x",
+ additional_data[0]);
+ for (i = 1; i < size_board; i++){
+ printf("-%02x", additional_data[i]);
+ }
+ printf("\n");
+ free (additional_data);
+ (*board_length) -= size_board;
+ }
+ else {
+ printf("No Additional Custom Mfg. %d\n", *board_length);
+ file_offset = ftell (input_file);
+ return file_offset;
+ }
+ }
- return file_offset;
+ file_offset = ftell(input_file);
+ return file_offset;
}
/**************************************************************************
--
1.7.7
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Ipmitool-devel mailing list
https://lists.sourceforge.net/lists/listinfo/ipmitool-devel
Dan Gora
2013-03-22 00:17:53 UTC
Permalink
Fixed bugs in ipmi_ek_display_chassis_info_area(),
ipmi_ek_display_product_info_area(), and
ipmi_ekanalyzer_fru_file2structure() where fread was being called to
read one byte of data into a int or long data type. This would result
in the value being byte swapped since the byte was read into the most
significant byte of the int (ie byte 0) on big endian machines.

Signed-off-by: Dan Gora <***@adax.com>
---
ipmitool/lib/ipmi_ekanalyzer.c | 17 +++++++++++------
1 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/ipmitool/lib/ipmi_ekanalyzer.c b/ipmitool/lib/ipmi_ekanalyzer.c
index 2fcf4e5..448b308 100644
--- a/ipmitool/lib/ipmi_ekanalyzer.c
+++ b/ipmitool/lib/ipmi_ekanalyzer.c
@@ -2539,6 +2539,7 @@ static void
ipmi_ek_display_chassis_info_area(FILE * input_file, long offset)
{
unsigned char data = 0;
+ unsigned char clen = 0;
unsigned char ch_type = 0;
unsigned int len;
size_t file_offset;
@@ -2561,9 +2562,9 @@ ipmi_ek_display_chassis_info_area(FILE * input_file, long offset)
if ( feof(input_file) )
return;

- fread (&len, 1, 1, input_file);
+ fread (&clen, 1, 1, input_file);
/* len is in factor of 8 bytes */
- len = len * 8;
+ len = clen * 8;
printf("Area Length: %d\n", len);
len -= 2;
if ( feof(input_file) )
@@ -2733,6 +2734,7 @@ static void
ipmi_ek_display_product_info_area( FILE * input_file, long offset )
{
unsigned char data = 0;
+ unsigned char clen = 0;
unsigned int len;
size_t file_offset = ftell (input_file);

@@ -2754,9 +2756,11 @@ ipmi_ek_display_product_info_area( FILE * input_file, long offset )
if ( feof(input_file) )
return;

- fread (&len, 1, 1, input_file);
+ /* Have to read this into a char or else
+ * it ends up byte swapped on big endian machines */
+ fread (&clen, 1, 1, input_file);
/* length is in factor of 8 bytes */
- len = len * 8;
+ len = clen * 8;
printf("Area Length: %d\n", len);
len -= 2; /* -1 byte of format version and -1 byte itself */
if ( feof(input_file) )
@@ -3885,8 +3889,9 @@ ipmi_ekanalyzer_fru_file2structure( char * filename,
{
int return_status = ERROR_STATUS;
FILE * input_file;
+ char data;
unsigned char last_record = 0;
- long multi_offset;
+ int multi_offset;
int record_count = 0;

input_file = fopen ( filename, "r");
@@ -3896,7 +3901,7 @@ ipmi_ekanalyzer_fru_file2structure( char * filename,
}

fseek ( input_file, START_DATA_OFFSET, SEEK_SET );
- fread ( &multi_offset, 1, 1, input_file );
+ fread ( &data, 1, 1, input_file );
if ( data <= 0 ){
lprintf(LOG_NOTICE, "There is no multi record in the file %s\n",
filename);
--
1.7.7
Dan Gora
2013-03-22 00:17:54 UTC
Permalink
Fixed a bug where the carrier connectivity point to point descriptor
was not being displayed properly when compiled on big endian machines.

Signed-off-by: Dan Gora <***@adax.com>
---
ipmitool/lib/ipmi_ekanalyzer.c | 39 ++++++++++++++++++++++++---------------
1 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/ipmitool/lib/ipmi_ekanalyzer.c b/ipmitool/lib/ipmi_ekanalyzer.c
index 448b308..fb4f66a 100644
--- a/ipmitool/lib/ipmi_ekanalyzer.c
+++ b/ipmitool/lib/ipmi_ekanalyzer.c
@@ -798,7 +798,7 @@ ipmi_ek_display_carrier_connectivity( struct ipmi_ek_multi_header * record )
{
int return_value = ERROR_STATUS;
struct fru_picmgext_carrier_p2p_record rsc_desc;
- struct fru_picmgext_carrier_p2p_descriptor port_desc;
+ struct fru_picmgext_carrier_p2p_descriptor *port_desc;

if ( record == NULL ){
lprintf(LOG_ERR, "P2P connectivity record is invalid\n");
@@ -843,20 +843,29 @@ ipmi_ek_display_carrier_connectivity( struct ipmi_ek_multi_header * record )
(rsc_desc.resource_id & 0x0f));
}
while ( rsc_desc.p2p_count > 0 ){
- memcpy ( &port_desc, &record->data[offset],
- sizeof ( struct fru_picmgext_carrier_p2p_descriptor ) );
- offset += sizeof ( struct fru_picmgext_carrier_p2p_descriptor );
- if ( (port_desc.remote_resource_id & AMC_MODULE) == AMC_MODULE ){
- printf("\tPort %d =====> %s, Port %d\n", port_desc.local_port,
- val2str( (port_desc.remote_resource_id & 0x0f),
- ipmi_ekanalyzer_module_type), port_desc.remote_port );
- }
- else{
- printf("\tPort %d =====> On Carrier Device ID %d, Port %d\n",
- port_desc.local_port,(port_desc.remote_resource_id & 0x0f),
- port_desc.remote_port );
- }
- rsc_desc.p2p_count--;
+ unsigned char data[3];
+#ifndef WORDS_BIGENDIAN
+ data[0] = record->data[offset+0];
+ data[1] = record->data[offset+1];
+ data[2] = record->data[offset+2];
+#else
+ data[0] = record->data[offset+2];
+ data[1] = record->data[offset+1];
+ data[2] = record->data[offset+0];
+#endif
+ port_desc = (struct fru_picmgext_carrier_p2p_descriptor*) data;
+ offset += sizeof ( struct fru_picmgext_carrier_p2p_descriptor );
+ if ( (port_desc->remote_resource_id & AMC_MODULE) == AMC_MODULE ){
+ printf("\tPort %d =====> %s, Port %d\n", port_desc->local_port,
+ val2str( (port_desc->remote_resource_id & 0x0f),
+ ipmi_ekanalyzer_module_type), port_desc->remote_port );
+ }
+ else {
+ printf("\tPort %d =====> On Carrier Device ID %d, Port %d\n",
+ port_desc->local_port,(port_desc->remote_resource_id & 0x0f),
+ port_desc->remote_port );
+ }
+ rsc_desc.p2p_count--;
}
}
return_value = OK_STATUS;
--
1.7.7
Dan Gora
2013-03-22 00:17:59 UTC
Permalink
Format the records a little more clearly by adding offsets.

Signed-off-by: Dan Gora <***@adax.com>
---
ipmitool/lib/ipmi_ekanalyzer.c | 10 ++++++----
1 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/ipmitool/lib/ipmi_ekanalyzer.c b/ipmitool/lib/ipmi_ekanalyzer.c
index 2da4650..34b6cb6 100644
--- a/ipmitool/lib/ipmi_ekanalyzer.c
+++ b/ipmitool/lib/ipmi_ekanalyzer.c
@@ -3987,12 +3987,14 @@ ipmi_ekanalyzer_fru_file2structure( char * filename,
(*list_record)->header.len);
if ( verbose > 1 ) {
int i;
- printf("Type: %02x\t", (*list_record)->header.type);
+ printf("Type: %02x", (*list_record)->header.type);
for ( i = 0; i < ( (*list_record)->header.len ); i++ ){
- printf("0x%04x: %02x\t",
- i, (*list_record)->data[i]);
+ if (!(i % 8))
+ printf("\n0x%02x: ", i);
+ printf("%02x ",
+ (*list_record)->data[i]);
}
- printf("\n");
+ printf("\n\n");
}
ipmi_ek_add_record2list ( list_record, list_head, list_last );
/*mask the 8th bits to see if it is the last record*/
--
1.7.7
Zdenek Styblik
2013-04-22 10:43:07 UTC
Permalink
Post by Dan Gora
Format the records a little more clearly by adding offsets.
Please, can you post output of proposed change? I'm not convinced
removing '\t' is good idea since there seem to be no other delimiters
in code that follows. It seems to me output is going to be something
like ``Type: 0x0A0x0F'' or ``Type: 0x0A\n0x0F:''
Also, having '\n\n' seems to be redundant. Is it really necessary to
have two empty lines?

Thanks,
Z.
Post by Dan Gora
---
ipmitool/lib/ipmi_ekanalyzer.c | 10 ++++++----
1 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/ipmitool/lib/ipmi_ekanalyzer.c b/ipmitool/lib/ipmi_ekanalyzer.c
index 2da4650..34b6cb6 100644
--- a/ipmitool/lib/ipmi_ekanalyzer.c
+++ b/ipmitool/lib/ipmi_ekanalyzer.c
@@ -3987,12 +3987,14 @@ ipmi_ekanalyzer_fru_file2structure( char * filename,
(*list_record)->header.len);
if ( verbose > 1 ) {
int i;
- printf("Type: %02x\t", (*list_record)->header.type);
+ printf("Type: %02x", (*list_record)->header.type);
for ( i = 0; i < ( (*list_record)->header.len ); i++ ){
- printf("0x%04x: %02x\t",
- i, (*list_record)->data[i]);
+ if (!(i % 8))
+ printf("\n0x%02x: ", i);
+ printf("%02x ",
+ (*list_record)->data[i]);
}
- printf("\n");
+ printf("\n\n");
}
ipmi_ek_add_record2list ( list_record, list_head, list_last );
/*mask the 8th bits to see if it is the last record*/
--
1.7.7
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Ipmitool-devel mailing list
https://lists.sourceforge.net/lists/listinfo/ipmitool-devel
Dan Gora
2013-04-22 19:39:54 UTC
Permalink
On Mon, Apr 22, 2013 at 7:43 AM, Zdenek Styblik
Post by Zdenek Styblik
Post by Dan Gora
Format the records a little more clearly by adding offsets.
Please, can you post output of proposed change? I'm not convinced
removing '\t' is good idea since there seem to be no other delimiters
in code that follows. It seems to me output is going to be something
Is \n not a delimiter? I suggest that you actually apply the patch
and read it again.
Post by Zdenek Styblik
``Type: 0x0A\n0x0F:''
Post by Dan Gora
+ if (!(i % 8))
+ printf("\n0x%02x: ", i);
Also, having '\n\n' seems to be redundant. Is it really necessary to
have two empty lines?
There is one empty line.. The first \n is a carriage return for the
end of the last line of output. The second gives you one empty line

dan
Post by Zdenek Styblik
Thanks,
Z.
Post by Dan Gora
---
ipmitool/lib/ipmi_ekanalyzer.c | 10 ++++++----
1 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/ipmitool/lib/ipmi_ekanalyzer.c b/ipmitool/lib/ipmi_ekanalyzer.c
index 2da4650..34b6cb6 100644
--- a/ipmitool/lib/ipmi_ekanalyzer.c
+++ b/ipmitool/lib/ipmi_ekanalyzer.c
@@ -3987,12 +3987,14 @@ ipmi_ekanalyzer_fru_file2structure( char * filename,
(*list_record)->header.len);
if ( verbose > 1 ) {
int i;
- printf("Type: %02x\t", (*list_record)->header.type);
+ printf("Type: %02x", (*list_record)->header.type);
for ( i = 0; i < ( (*list_record)->header.len ); i++ ){
- printf("0x%04x: %02x\t",
- i, (*list_record)->data[i]);
+ if (!(i % 8))
+ printf("\n0x%02x: ", i);
+ printf("%02x ",
+ (*list_record)->data[i]);
}
- printf("\n");
+ printf("\n\n");
}
ipmi_ek_add_record2list ( list_record, list_head, list_last );
/*mask the 8th bits to see if it is the last record*/
--
1.7.7
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Ipmitool-devel mailing list
https://lists.sourceforge.net/lists/listinfo/ipmitool-devel
--
Dan Gora
Software Engineer

Adax, Inc.
Av Dona Maria Alves, 1070 Casa 5
Centro
Ubatuba, SP
CEP 11680-000
Brasil

Tel: +55 (12) 3833-1021 (Brazil and outside of US)
: +1 (510) 859-4801 (Inside of US)
: dan_gora (Skype)

email: ***@adax.com
Zdenek Styblik
2013-04-22 19:57:28 UTC
Permalink
Post by Dan Gora
On Mon, Apr 22, 2013 at 7:43 AM, Zdenek Styblik
Post by Zdenek Styblik
Post by Dan Gora
Format the records a little more clearly by adding offsets.
Please, can you post output of proposed change? I'm not convinced
removing '\t' is good idea since there seem to be no other delimiters
in code that follows. It seems to me output is going to be something
Is \n not a delimiter? I suggest that you actually apply the patch
and read it again.
Dan,

thank you for your suggestion. I've misinterpreted the meaning of the
diff on my big screen LCD.
Anyway, I've created small test code, produced some output, and it
indeed looks just fine. Patch is ok and there is no reason why it
shouldn't be committed.

Best regards,
Z.
Post by Dan Gora
Post by Zdenek Styblik
``Type: 0x0A\n0x0F:''
Post by Dan Gora
+ if (!(i % 8))
+ printf("\n0x%02x: ", i);
Also, having '\n\n' seems to be redundant. Is it really necessary to
have two empty lines?
There is one empty line.. The first \n is a carriage return for the
end of the last line of output. The second gives you one empty line
dan
Post by Zdenek Styblik
Thanks,
Z.
Post by Dan Gora
---
ipmitool/lib/ipmi_ekanalyzer.c | 10 ++++++----
1 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/ipmitool/lib/ipmi_ekanalyzer.c b/ipmitool/lib/ipmi_ekanalyzer.c
index 2da4650..34b6cb6 100644
--- a/ipmitool/lib/ipmi_ekanalyzer.c
+++ b/ipmitool/lib/ipmi_ekanalyzer.c
@@ -3987,12 +3987,14 @@ ipmi_ekanalyzer_fru_file2structure( char * filename,
(*list_record)->header.len);
if ( verbose > 1 ) {
int i;
- printf("Type: %02x\t", (*list_record)->header.type);
+ printf("Type: %02x", (*list_record)->header.type);
for ( i = 0; i < ( (*list_record)->header.len ); i++ ){
- printf("0x%04x: %02x\t",
- i, (*list_record)->data[i]);
+ if (!(i % 8))
+ printf("\n0x%02x: ", i);
+ printf("%02x ",
+ (*list_record)->data[i]);
}
- printf("\n");
+ printf("\n\n");
}
ipmi_ek_add_record2list ( list_record, list_head, list_last );
/*mask the 8th bits to see if it is the last record*/
--
1.7.7
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Ipmitool-devel mailing list
https://lists.sourceforge.net/lists/listinfo/ipmitool-devel
--
Dan Gora
Software Engineer
Adax, Inc.
Av Dona Maria Alves, 1070 Casa 5
Centro
Ubatuba, SP
CEP 11680-000
Brasil
Tel: +55 (12) 3833-1021 (Brazil and outside of US)
: +1 (510) 859-4801 (Inside of US)
: dan_gora (Skype)
Loading...