diff --git a/ipmitool/lib/ipmi_fru.c b/ipmitool/lib/ipmi_fru.c index eb5d583..071ac55 100644 --- a/ipmitool/lib/ipmi_fru.c +++ b/ipmitool/lib/ipmi_fru.c @@ -1,34 +1,34 @@ /* - * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * Redistribution of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * Redistribution in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of Sun Microsystems, Inc. or the names of - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * This software is provided "AS IS," without a warranty of any kind. - * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, - * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A - * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. - * SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE - * FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING - * OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL - * SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, - * OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR - * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF - * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, - * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - */ +* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* Redistribution of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* Redistribution in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* Neither the name of Sun Microsystems, Inc. or the names of +* contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* This software is provided "AS IS," without a warranty of any kind. +* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, +* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A +* PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. +* SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE +* FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING +* OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL +* SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, +* OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR +* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF +* LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, +* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. +*/ #include #include @@ -36,7 +36,7 @@ #include #include #include -#include /* IANA id strings */ +#include /* IANA id strings */ #include #include @@ -47,16 +47,16 @@ #endif /* - * Apparently some systems have problems with FRU access greater than 16 bytes - * at a time, even when using byte (not word) access. In order to ensure we - * work with the widest variety of hardware request size is capped at 16 bytes. - * Since this may result in slowdowns on some systems with lots of FRU data you - * can undefine this to enable larger (up to 32 bytes at a time) access. - * - * TODO: make this a command line option - */ +* Apparently some systems have problems with FRU access greater than 16 bytes +* at a time, even when using byte (not word) access. In order to ensure we +* work with the widest variety of hardware request size is capped at 16 bytes. +* Since this may result in slowdowns on some systems with lots of FRU data you +* can undefine this to enable larger (up to 32 bytes at a time) access. +* +* TODO: make this a command line option +*/ #define LIMIT_ALL_REQUEST_SIZE 1 -#define FRU_MULTIREC_CHUNK_SIZE (255 + sizeof(struct fru_multirec_header)) +#define FRU_MULTIREC_CHUNK_SIZE (255 + sizeof(struct fru_multirec_header)) static char fileName[512]; @@ -77,9 +77,9 @@ static void ipmi_fru_picmg_ext_print(uint8_t * fru_data, int off, int length); static int ipmi_fru_set_field_string(struct ipmi_intf * intf, unsigned char fruId, uint8_t f_type, uint8_t f_index, char *f_string); static int -ipmi_fru_set_field_string_rebuild(struct ipmi_intf * intf, uint8_t fruId, - struct fru_info fru, struct fru_header header, - uint8_t f_type, uint8_t f_index, char *f_string); +ipmi_fru_set_field_string_rebuild(struct ipmi_intf * intf, uint8_t fruId, + struct fru_info fru, struct fru_header header, + uint8_t f_type, uint8_t f_index, char *f_string); static void fru_area_print_multirec_bloc(struct ipmi_intf * intf, struct fru_info * fru, @@ -88,13 +88,13 @@ int read_fru_area(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id, uint32_t offset, uint32_t length, uint8_t *frubuf); -/* get_fru_area_str - Parse FRU area string from raw data - * - * @data: raw FRU data - * @offset: offset into data for area - * - * returns pointer to FRU area string - */ +/* get_fru_area_str - Parse FRU area string from raw data +* +* @data: raw FRU data +* @offset: offset into data for area +* +* returns pointer to FRU area string +*/ char * get_fru_area_str(uint8_t * data, uint32_t * offset) { static const char bcd_plus[] = "0123456789 -.:,_"; @@ -117,16 +117,16 @@ char * get_fru_area_str(uint8_t * data, uint32_t * offset) len &= 0x3f; switch (typecode) { - case 0: /* 00b: binary/unspecified */ + case 0: /* 00b: binary/unspecified */ /* hex dump -> 2x length */ size = (len*2); break; - case 2: /* 10b: 6-bit ASCII */ + case 2: /* 10b: 6-bit ASCII */ /* 4 chars per group of 1-3 bytes */ size = ((((len+2)*4)/3) & ~3); break; - case 3: /* 11b: 8-bit ASCII */ - case 1: /* 01b: BCD plus */ + case 3: /* 11b: 8-bit ASCII */ + case 1: /* 01b: BCD plus */ /* no length adjustment */ size = len; break; @@ -148,17 +148,17 @@ char * get_fru_area_str(uint8_t * data, uint32_t * offset) } switch (typecode) { - case 0: /* Binary */ + case 0: /* Binary */ strncpy(str, buf2str(&data[off], len), len*2); break; - case 1: /* BCD plus */ + case 1: /* BCD plus */ for (k=0; ksize + 1); - if (fru_data == NULL) { - lprintf(LOG_ERR, " Out of memory!"); - return NULL; - } + i = last_off = (header.offset.multi*8); + //fru_len = 0; - memset(fru_data, 0, fru->size + 1); + fru_data = malloc(fru->size + 1); + if (fru_data == NULL) { + lprintf(LOG_ERR, " Out of memory!"); + return NULL; + } - do { - h = (struct fru_multirec_header *) (fru_data + i); + memset(fru_data, 0, fru->size + 1); - // read area in (at most) FRU_MULTIREC_CHUNK_SIZE bytes at a time - if ((last_off < (i + sizeof(*h))) || (last_off < (i + h->len))) - { - len = fru->size - last_off; - if (len > FRU_MULTIREC_CHUNK_SIZE) - len = FRU_MULTIREC_CHUNK_SIZE; + do { + h = (struct fru_multirec_header *) (fru_data + i); - if (read_fru_area(intf, fru, id, last_off, len, fru_data) < 0) - break; + // read area in (at most) FRU_MULTIREC_CHUNK_SIZE bytes at a time + if ((last_off < (i + sizeof(*h))) || (last_off < (i + h->len))) + { + len = fru->size - last_off; + if (len > FRU_MULTIREC_CHUNK_SIZE) + len = FRU_MULTIREC_CHUNK_SIZE; - last_off += len; - } - - num_bloc++; - //printf("Bloc Numb : %i\n", counter); - //printf("Bloc Start: %i\n", i); - //printf("Bloc Size : %i\n", h->len); - //printf("\n"); - i += h->len + sizeof (struct fru_multirec_header); - } while (!(h->format & 0x80) && ( last_off < fru->size)); + if (read_fru_area(intf, fru, id, last_off, len, fru_data) < 0) + break; - lprintf(LOG_DEBUG ,"Multi-Record area ends at: %i (%xh)",i,i); + last_off += len; + } - if(fru->size > i) - { - // Bloc for remaining space - num_bloc ++; - } - } - else - { - /* Since there is no multi-rec area and no end delimiter, the remaining - space will be added to the last bloc */ - } + num_bloc++; + //printf("Bloc Numb : %i\n", counter); + //printf("Bloc Start: %i\n", i); + //printf("Bloc Size : %i\n", h->len); + //printf("\n"); + i += h->len + sizeof (struct fru_multirec_header); + } while (!(h->format & 0x80) && ( last_off < fru->size)); + + lprintf(LOG_DEBUG ,"Multi-Record area ends at: %i (%xh)",i,i); + + if(fru->size > i) + { + // Bloc for remaining space + num_bloc ++; + } + } + else + { + /* Since there is no multi-rec area and no end delimiter, the remaining + space will be added to the last bloc */ + } - /****************************************** - Malloc and fill up the bloc contents - *******************************************/ - p_bloc = malloc( sizeof( t_ipmi_fru_bloc ) * num_bloc ); - if(!p_bloc) - { - lprintf(LOG_ERR, " Unable to get memory to build Fru bloc"); - return NULL; - } + /****************************************** + Malloc and fill up the bloc contents + *******************************************/ + p_bloc = malloc( sizeof( t_ipmi_fru_bloc ) * num_bloc ); + if(!p_bloc) + { + lprintf(LOG_ERR, " Unable to get memory to build Fru bloc"); + return NULL; + } - // Common header - bloc_count = 0; - - p_bloc[bloc_count].start= 0; - p_bloc[bloc_count].size = 8; - strcpy((char *)p_bloc[bloc_count].blocId, "Common Header Section"); - bloc_count ++; + // Common header + bloc_count = 0; - // Internal - if( header.offset.internal ) - { - p_bloc[bloc_count].start = (header.offset.internal * 8); - p_bloc[bloc_count].size = 0; // Will be fillup later - strcpy((char *)p_bloc[bloc_count].blocId, "Internal Use Section"); - bloc_count ++; - } - // Chassis - if( header.offset.chassis ) - { - p_bloc[bloc_count].start = (header.offset.chassis * 8); - p_bloc[bloc_count].size = 0; // Will be fillup later - strcpy((char *)p_bloc[bloc_count].blocId, "Chassis Section"); - bloc_count ++; - } - // Board - if( header.offset.board ) - { - p_bloc[bloc_count].start = (header.offset.board * 8); - p_bloc[bloc_count].size = 0; // Will be fillup later - strcpy((char *)p_bloc[bloc_count].blocId, "Board Section"); - bloc_count ++; - } - // Product - if( header.offset.product ) - { - p_bloc[bloc_count].start = (header.offset.product * 8); - p_bloc[bloc_count].size = 0; // Will be fillup later - strcpy((char *)p_bloc[bloc_count].blocId, "Product Section"); - bloc_count ++; - } + p_bloc[bloc_count].start= 0; + p_bloc[bloc_count].size = 8; + strcpy((char *)p_bloc[bloc_count].blocId, "Common Header Section"); + bloc_count ++; - // Multi-Record Area - if( - ( header.offset.multi ) - && - ( fru_data ) - ) - { - uint32_t i = (header.offset.multi*8); - struct fru_multirec_header * h; + // Internal + if( header.offset.internal ) + { + p_bloc[bloc_count].start = (header.offset.internal * 8); + p_bloc[bloc_count].size = 0; // Will be fillup later + strcpy((char *)p_bloc[bloc_count].blocId, "Internal Use Section"); + bloc_count ++; + } + // Chassis + if( header.offset.chassis ) + { + p_bloc[bloc_count].start = (header.offset.chassis * 8); + p_bloc[bloc_count].size = 0; // Will be fillup later + strcpy((char *)p_bloc[bloc_count].blocId, "Chassis Section"); + bloc_count ++; + } + // Board + if( header.offset.board ) + { + p_bloc[bloc_count].start = (header.offset.board * 8); + p_bloc[bloc_count].size = 0; // Will be fillup later + strcpy((char *)p_bloc[bloc_count].blocId, "Board Section"); + bloc_count ++; + } + // Product + if( header.offset.product ) + { + p_bloc[bloc_count].start = (header.offset.product * 8); + p_bloc[bloc_count].size = 0; // Will be fillup later + strcpy((char *)p_bloc[bloc_count].blocId, "Product Section"); + bloc_count ++; + } - do { - h = (struct fru_multirec_header *) (fru_data + i); + // Multi-Record Area + if( + ( header.offset.multi ) + && + ( fru_data ) + ) + { + uint32_t i = (header.offset.multi*8); + struct fru_multirec_header * h; - p_bloc[bloc_count].start = i; - p_bloc[bloc_count].size = h->len + sizeof (struct fru_multirec_header); - sprintf((char *)p_bloc[bloc_count].blocId, "Multi-Rec Aread: Type %i", h->type); - bloc_count ++; - /*printf("Bloc Start: %i\n", i); - printf("Bloc Size : %i\n", h->len); - printf("\n");*/ + do { + h = (struct fru_multirec_header *) (fru_data + i); - i += h->len + sizeof (struct fru_multirec_header); - - } while (!(h->format & 0x80) && ( bloc_count < num_bloc ) ); + p_bloc[bloc_count].start = i; + p_bloc[bloc_count].size = h->len + sizeof (struct fru_multirec_header); + sprintf((char *)p_bloc[bloc_count].blocId, "Multi-Rec Aread: Type %i", h->type); + bloc_count ++; + /*printf("Bloc Start: %i\n", i); + printf("Bloc Size : %i\n", h->len); + printf("\n");*/ - lprintf(LOG_DEBUG ,"Multi-Record area ends at: %i (%xh)",i,i); - /* If last bloc size was defined and is not until the end, create a - last bloc with the remaining unused space */ + i += h->len + sizeof (struct fru_multirec_header); - if((fru->size > i) && (bloc_count < num_bloc)) - { - // Bloc for remaining space - p_bloc[bloc_count].start = i; - p_bloc[bloc_count].size = (fru->size - i); - sprintf((char *)p_bloc[bloc_count].blocId, "Unused space"); - bloc_count ++; - } - - free(fru_data); - } + } while (!(h->format & 0x80) && ( bloc_count < num_bloc ) ); - /* Fill up size for first bloc */ - { - unsigned short counter; - lprintf(LOG_DEBUG ,"\nNumber Bloc : %i\n", num_bloc); - for(counter = 0; counter < (num_bloc); counter ++) - { - /* If size where not initialized, do it. */ - if( p_bloc[counter].size == 0) - { - /* If not the last bloc, use the next bloc to determine the end */ - if((counter+1) < num_bloc) - { - p_bloc[counter].size = (p_bloc[counter+1].start - p_bloc[counter].start); - } - else - { - p_bloc[counter].size = (fru->size - p_bloc[counter].start); - } - } - lprintf(LOG_DEBUG ,"Bloc Numb : %i\n", counter); - lprintf(LOG_DEBUG ,"Bloc Id : %s\n", p_bloc[counter].blocId); - lprintf(LOG_DEBUG ,"Bloc Start: %i\n", p_bloc[counter].start); - lprintf(LOG_DEBUG ,"Bloc Size : %i\n", p_bloc[counter].size); - lprintf(LOG_DEBUG ,"\n"); - } - } + lprintf(LOG_DEBUG ,"Multi-Record area ends at: %i (%xh)",i,i); + /* If last bloc size was defined and is not until the end, create a + last bloc with the remaining unused space */ - (* ptr_number_bloc) = num_bloc; + if((fru->size > i) && (bloc_count < num_bloc)) + { + // Bloc for remaining space + p_bloc[bloc_count].start = i; + p_bloc[bloc_count].size = (fru->size - i); + sprintf((char *)p_bloc[bloc_count].blocId, "Unused space"); + bloc_count ++; + } - return p_bloc; + free(fru_data); + } + + /* Fill up size for first bloc */ + { + unsigned short counter; + lprintf(LOG_DEBUG ,"\nNumber Bloc : %i\n", num_bloc); + for(counter = 0; counter < (num_bloc); counter ++) + { + /* If size where not initialized, do it. */ + if( p_bloc[counter].size == 0) + { + /* If not the last bloc, use the next bloc to determine the end */ + if((counter+1) < num_bloc) + { + p_bloc[counter].size = (p_bloc[counter+1].start - p_bloc[counter].start); + } + else + { + p_bloc[counter].size = (fru->size - p_bloc[counter].start); + } + } + lprintf(LOG_DEBUG ,"Bloc Numb : %i\n", counter); + lprintf(LOG_DEBUG ,"Bloc Id : %s\n", p_bloc[counter].blocId); + lprintf(LOG_DEBUG ,"Bloc Start: %i\n", p_bloc[counter].start); + lprintf(LOG_DEBUG ,"Bloc Size : %i\n", p_bloc[counter].size); + lprintf(LOG_DEBUG ,"\n"); + } + } + + (* ptr_number_bloc) = num_bloc; + + return p_bloc; } - - int write_fru_area(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id, - uint16_t soffset, uint16_t doffset, + uint16_t soffset, uint16_t doffset, uint16_t length, uint8_t *pFrubuf) -{ /* +{ /* // fill in frubuf[offset:length] from the FRU[offset:length] // rc=1 on success */ @@ -490,16 +485,16 @@ write_fru_area(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id, struct ipmi_rq req; uint8_t msg_data[256]; uint8_t writeLength; - uint16_t num_bloc; + uint16_t num_bloc; - finish = doffset + length; /* destination offset */ + finish = doffset + length; /* destination offset */ if (finish > fru->size) { lprintf(LOG_ERROR, "Return error\n"); return -1; } - t_ipmi_fru_bloc * fru_bloc = build_fru_bloc(intf, fru, id, &num_bloc); + t_ipmi_fru_bloc * fru_bloc = build_fru_bloc(intf, fru, id, &num_bloc); memset(&req, 0, sizeof(req)); req.msg.netfn = IPMI_NETFN_STORAGE; @@ -511,19 +506,19 @@ write_fru_area(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id, #else if (fru->access && fru_data_rqst_size > 16) #endif - fru_data_rqst_size = 16; + fru_data_rqst_size = 16; - /* Check if we receive size in parameters */ - if(intf->channel_buf_size != 0) - { - fru_data_rqst_size = intf->channel_buf_size - 5; /* Plan for overhead */ - } + /* Check if we receive size in parameters */ + if(intf->channel_buf_size != 0) + { + fru_data_rqst_size = intf->channel_buf_size - 5; /* Plan for overhead */ + } do { - /* Temp init end_bloc to the end, if not found */ - uint16_t end_bloc = finish; - uint8_t protected_bloc = 0; - uint16_t found_bloc = 0xffff; + /* Temp init end_bloc to the end, if not found */ + uint16_t end_bloc = finish; + uint8_t protected_bloc = 0; + uint16_t found_bloc = 0xffff; /* real destination offset */ tmp = fru->access ? (doffset+off) >> 1 : (doffset+off); @@ -531,23 +526,23 @@ write_fru_area(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id, msg_data[1] = (uint8_t)tmp; msg_data[2] = (uint8_t)(tmp >> 8); - /* Write per bloc, try to find the end of a bloc*/ - { - uint16_t counter; - for(counter = 0; counter < (num_bloc); counter ++) - { - if( - (tmp >= fru_bloc[counter].start) - && - (tmp < (fru_bloc[counter].start + fru_bloc[counter].size)) - ) - { - found_bloc = counter; - end_bloc = (fru_bloc[counter].start + fru_bloc[counter].size); - counter = num_bloc; - } - } - } + /* Write per bloc, try to find the end of a bloc*/ + { + uint16_t counter; + for(counter = 0; counter < (num_bloc); counter ++) + { + if( + (tmp >= fru_bloc[counter].start) + && + (tmp < (fru_bloc[counter].start + fru_bloc[counter].size)) + ) + { + found_bloc = counter; + end_bloc = (fru_bloc[counter].start + fru_bloc[counter].size); + counter = num_bloc; + } + } + } tmp = end_bloc - (doffset+off); /* bytes remaining for the bloc */ if (tmp > fru_data_rqst_size) { @@ -558,63 +553,63 @@ write_fru_area(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id, memcpy(&msg_data[3], pFrubuf + soffset + off, (uint8_t)tmp); req.msg.data_len = tmp + 3; } - if(found_bloc == 0) - { - lprintf(LOG_INFO,"Writing %d bytes", (req.msg.data_len-3)); - } - else if(found_bloc != 0xFFFF) - { - lprintf(LOG_INFO,"Writing %d bytes (Bloc #%i: %s)", - (req.msg.data_len-3), - found_bloc, fru_bloc[found_bloc].blocId); - } + if(found_bloc == 0) + { + lprintf(LOG_INFO,"Writing %d bytes", (req.msg.data_len-3)); + } + else if(found_bloc != 0xFFFF) + { + lprintf(LOG_INFO,"Writing %d bytes (Bloc #%i: %s)", + (req.msg.data_len-3), + found_bloc, fru_bloc[found_bloc].blocId); + } writeLength = req.msg.data_len-3; - rsp = intf->sendrecv(intf, &req); + rsp = intf->sendrecv(intf, &req); if (!rsp) { break; } - if(rsp->ccode==0x80) // Write protected section - { - protected_bloc = 1; - } - else if ((rsp->ccode==0xc7 || rsp->ccode==0xc8 || rsp->ccode==0xca ) && - --fru_data_rqst_size > 8) { + if(rsp->ccode==0x80) // Write protected section + { + protected_bloc = 1; + } + else if ((rsp->ccode==0xc7 || rsp->ccode==0xc8 || rsp->ccode==0xca ) && + --fru_data_rqst_size > 8) { lprintf(LOG_NOTICE,"Bad CC -> %x\n", rsp->ccode); break; /*continue;*/ } else if (rsp->ccode > 0) break; - if(protected_bloc == 0) - { - lprintf(LOG_INFO,"Wrote %d bytes", writeLength); - off += writeLength; // Write OK, bloc not protected, continue - } - else - { - if(found_bloc != 0xffff) - { - // Bloc protected, advise user and jump over protected bloc - lprintf(LOG_INFO,"Bloc [%s] protected at offset: %i (size %i bytes)", - fru_bloc[found_bloc].blocId, - fru_bloc[found_bloc].start, - fru_bloc[found_bloc].size); - lprintf(LOG_INFO,"Jumping over this bloc"); - } - else - { - lprintf(LOG_INFO,"Remaining FRU is protected following offset: %i", - off); - - } - off = end_bloc; - } + if(protected_bloc == 0) + { + lprintf(LOG_INFO,"Wrote %d bytes", writeLength); + off += writeLength; // Write OK, bloc not protected, continue + } + else + { + if(found_bloc != 0xffff) + { + // Bloc protected, advise user and jump over protected bloc + lprintf(LOG_INFO,"Bloc [%s] protected at offset: %i (size %i bytes)", + fru_bloc[found_bloc].blocId, + fru_bloc[found_bloc].start, + fru_bloc[found_bloc].size); + lprintf(LOG_INFO,"Jumping over this bloc"); + } + else + { + lprintf(LOG_INFO,"Remaining FRU is protected following offset: %i", + off); + + } + off = end_bloc; + } } while ((doffset+off) < finish); - free(fru_bloc); + free(fru_bloc); return ((doffset+off) >= finish); } @@ -623,9 +618,9 @@ write_fru_area(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id, #if 0 int write_fru_area(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id, - uint16_t soffset, uint16_t doffset, + uint16_t soffset, uint16_t doffset, uint16_t length, uint8_t *pFrubuf) -{ /* +{ /* // fill in frubuf[offset:length] from the FRU[offset:length] // rc=1 on success */ @@ -636,7 +631,7 @@ write_fru_area(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id, uint8_t msg_data[25]; uint8_t writeLength; - finish = doffset + length; /* destination offset */ + finish = doffset + length; /* destination offset */ if (finish > fru->size) { printf("Return error\n"); @@ -652,7 +647,7 @@ write_fru_area(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id, #else if (fru->access && fru_data_rqst_size > 16) #endif - fru_data_rqst_size = 16; + fru_data_rqst_size = 16; do { /* real destination offset */ @@ -660,7 +655,7 @@ write_fru_area(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id, msg_data[0] = id; msg_data[1] = (uint8_t)tmp; msg_data[2] = (uint8_t)(tmp >> 8); - tmp = finish - (doffset+off); /* bytes remaining */ + tmp = finish - (doffset+off); /* bytes remaining */ if (tmp > 16) { lprintf(LOG_INFO,"Writing 16 bytes"); memcpy(&msg_data[3], pFrubuf + soffset + off, 16); @@ -679,7 +674,7 @@ write_fru_area(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id, break; } if ((rsp->ccode==0xc7 || rsp->ccode==0xc8 || rsp->ccode==0xca ) && - --fru_data_rqst_size > 8) { + --fru_data_rqst_size > 8) { lprintf(LOG_NOTICE,"Bad CC -> %x\n", rsp->ccode); break; /*continue;*/ } @@ -693,18 +688,18 @@ write_fru_area(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id, } #endif -/* read_fru_area - fill in frubuf[offset:length] from the FRU[offset:length] - * - * @intf: ipmi interface - * @fru: fru info - * @id: fru id - * @offset: offset into buffer - * @length: how much to read - * @frubuf: buffer read into - * - * returns -1 on error - * returns 0 if successful - */ +/* read_fru_area - fill in frubuf[offset:length] from the FRU[offset:length] +* +* @intf: ipmi interface +* @fru: fru info +* @id: fru id +* @offset: offset into buffer +* @length: how much to read +* @frubuf: buffer read into +* +* returns -1 on error +* returns 0 if successful +*/ int read_fru_area(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id, uint32_t offset, uint32_t length, uint8_t *frubuf) @@ -743,11 +738,11 @@ read_fru_area(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id, fru_data_rqst_size = 16; - /* Check if we receive size in parameters */ - if(intf->channel_buf_size != 0) - { - fru_data_rqst_size = intf->channel_buf_size - 9; /* Plan for overhead */ - } + /* Check if we receive size in parameters */ + if(intf->channel_buf_size != 0) + { + fru_data_rqst_size = intf->channel_buf_size - 9; /* Plan for overhead */ + } do { @@ -768,9 +763,9 @@ read_fru_area(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id, } if (rsp->ccode > 0) { /* if we get C7 or C8 or CA return code then we requested too - * many bytes at once so try again with smaller size */ + * many bytes at once so try again with smaller size */ if ((rsp->ccode == 0xc7 || rsp->ccode == 0xc8 || rsp->ccode == 0xca) && - (--fru_data_rqst_size > 8)) { + (--fru_data_rqst_size > 8)) { lprintf(LOG_INFO, "Retrying FRU read with request size %d", fru_data_rqst_size); continue; @@ -785,8 +780,8 @@ read_fru_area(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id, off += tmp; /* sometimes the size returned in the Info command - * is too large. return 0 so higher level function - * still attempts to parse what was returned */ + * is too large. return 0 so higher level function + * still attempts to parse what was returned */ if (tmp == 0 && off < finish) return 0; @@ -798,18 +793,18 @@ read_fru_area(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id, return 0; } -/* read_fru_area - fill in frubuf[offset:length] from the FRU[offset:length] - * - * @intf: ipmi interface - * @fru: fru info - * @id: fru id - * @offset: offset into buffer - * @length: how much to read - * @frubuf: buffer read into - * - * returns -1 on error - * returns 0 if successful - */ +/* read_fru_area - fill in frubuf[offset:length] from the FRU[offset:length] +* +* @intf: ipmi interface +* @fru: fru info +* @id: fru id +* @offset: offset into buffer +* @length: how much to read +* @frubuf: buffer read into +* +* returns -1 on error +* returns 0 if successful +*/ int read_fru_area_section(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id, uint32_t offset, uint32_t length, uint8_t *frubuf) @@ -864,9 +859,9 @@ read_fru_area_section(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id, } if (rsp->ccode > 0) { /* if we get C7 or C8 or CA return code then we requested too - * many bytes at once so try again with smaller size */ + * many bytes at once so try again with smaller size */ if ((rsp->ccode == 0xc7 || rsp->ccode == 0xc8 || rsp->ccode == 0xca) && - (--fru_data_rqst_size > 8)) { + (--fru_data_rqst_size > 8)) { lprintf(LOG_INFO, "Retrying FRU read with request size %d", fru_data_rqst_size); continue; @@ -881,8 +876,8 @@ read_fru_area_section(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id, off += tmp; /* sometimes the size returned in the Info command - * is too large. return 0 so higher level function - * still attempts to parse what was returned */ + * is too large. return 0 so higher level function + * still attempts to parse what was returned */ if (tmp == 0 && off < finish) return 0; @@ -894,7 +889,7 @@ read_fru_area_section(struct ipmi_intf * intf, struct fru_info *fru, uint8_t id, return 0; } - + static void fru_area_print_multirec_bloc(struct ipmi_intf * intf, struct fru_info * fru, uint8_t id, uint32_t offset) @@ -918,7 +913,7 @@ fru_area_print_multirec_bloc(struct ipmi_intf * intf, struct fru_info * fru, do { h = (struct fru_multirec_header *) (fru_data + i); - // read area in (at most) FRU_MULTIREC_CHUNK_SIZE bytes at a time + // read area in (at most) FRU_MULTIREC_CHUNK_SIZE bytes at a time if ((last_off < (i + sizeof(*h))) || (last_off < (i + h->len))) { len = fru->size - last_off; @@ -930,42 +925,42 @@ fru_area_print_multirec_bloc(struct ipmi_intf * intf, struct fru_info * fru, last_off += len; } - - //printf("Bloc Numb : %i\n", counter); - printf("Bloc Start: %i\n", i); - printf("Bloc Size : %i\n", h->len); - printf("\n"); + + //printf("Bloc Numb : %i\n", counter); + printf("Bloc Start: %i\n", i); + printf("Bloc Size : %i\n", h->len); + printf("\n"); i += h->len + sizeof (struct fru_multirec_header); } while (!(h->format & 0x80)); - i = offset; + i = offset; do { h = (struct fru_multirec_header *) (fru_data + i); - printf("Bloc Start: %i\n", i); - printf("Bloc Size : %i\n", h->len); - printf("\n"); + printf("Bloc Start: %i\n", i); + printf("Bloc Size : %i\n", h->len); + printf("\n"); i += h->len + sizeof (struct fru_multirec_header); } while (!(h->format & 0x80)); - lprintf(LOG_DEBUG ,"Multi-Record area ends at: %i (%xh)",i,i); + lprintf(LOG_DEBUG ,"Multi-Record area ends at: %i (%xh)",i,i); free(fru_data); } - -/* fru_area_print_chassis - Print FRU Chassis Area - * - * @intf: ipmi interface - * @fru: fru info - * @id: fru id - * @offset: offset pointer - */ + +/* fru_area_print_chassis - Print FRU Chassis Area +* +* @intf: ipmi interface +* @fru: fru info +* @id: fru id +* @offset: offset pointer +*/ static void fru_area_print_chassis(struct ipmi_intf * intf, struct fru_info * fru, - uint8_t id, uint32_t offset) + uint8_t id, uint32_t offset) { char * fru_area; uint8_t * fru_data; @@ -995,21 +990,21 @@ fru_area_print_chassis(struct ipmi_intf * intf, struct fru_info * fru, return; } - i++; /* skip fru area version */ + i++; /* skip fru area version */ area_len = fru_data[i++] * 8; /* fru area length */ - printf(" Chassis Type : %s\n", - chassis_type_desc[fru_data[i++]]); + printf(" Chassis Type : %s\n", + chassis_type_desc[fru_data[i++]]); fru_area = get_fru_area_str(fru_data, &i); if (fru_area != NULL && strlen(fru_area) > 0) { - printf(" Chassis Part Number : %s\n", fru_area); + printf(" Chassis Part Number : %s\n", fru_area); free(fru_area); } fru_area = get_fru_area_str(fru_data, &i); if (fru_area != NULL && strlen(fru_area) > 0) { - printf(" Chassis Serial : %s\n", fru_area); + printf(" Chassis Serial : %s\n", fru_area); free(fru_area); } @@ -1019,7 +1014,7 @@ fru_area_print_chassis(struct ipmi_intf * intf, struct fru_info * fru, int j = i; fru_area = get_fru_area_str(fru_data, &i); if (fru_area != NULL && strlen(fru_area) > 0) { - printf(" Chassis Extra : %s\n", fru_area); + printf(" Chassis Extra : %s\n", fru_area); free(fru_area); } if (i == j) @@ -1029,16 +1024,16 @@ fru_area_print_chassis(struct ipmi_intf * intf, struct fru_info * fru, free(fru_data); } -/* fru_area_print_board - Print FRU Board Area - * - * @intf: ipmi interface - * @fru: fru info - * @id: fru id - * @offset: offset pointer - */ +/* fru_area_print_board - Print FRU Board Area +* +* @intf: ipmi interface +* @fru: fru info +* @id: fru id +* @offset: offset pointer +*/ static void fru_area_print_board(struct ipmi_intf * intf, struct fru_info * fru, - uint8_t id, uint32_t offset) + uint8_t id, uint32_t offset) { char * fru_area; uint8_t * fru_data; @@ -1069,9 +1064,9 @@ fru_area_print_board(struct ipmi_intf * intf, struct fru_info * fru, return; } - i++; /* skip fru area version */ + i++; /* skip fru area version */ area_len = fru_data[i++] * 8; /* fru area length */ - i++; /* skip fru board language */ + i++; /* skip fru board language */ tval=((fru_data[i+2] << 16) + (fru_data[i+1] << 8) + (fru_data[i])); tval=tval * 60; tval=tval + secs_from_1970_1996; @@ -1105,7 +1100,7 @@ fru_area_print_board(struct ipmi_intf * intf, struct fru_info * fru, fru_area = get_fru_area_str(fru_data, &i); if (fru_area != NULL && strlen(fru_area) > 0) { if (verbose > 0) - printf(" Board FRU ID : %s\n", fru_area); + printf(" Board FRU ID : %s\n", fru_area); free(fru_area); } @@ -1125,16 +1120,16 @@ fru_area_print_board(struct ipmi_intf * intf, struct fru_info * fru, free(fru_data); } -/* fru_area_print_product - Print FRU Product Area - * - * @intf: ipmi interface - * @fru: fru info - * @id: fru id - * @offset: offset pointer - */ +/* fru_area_print_product - Print FRU Product Area +* +* @intf: ipmi interface +* @fru: fru info +* @id: fru id +* @offset: offset pointer +*/ static void fru_area_print_product(struct ipmi_intf * intf, struct fru_info * fru, - uint8_t id, uint32_t offset) + uint8_t id, uint32_t offset) { char * fru_area; uint8_t * fru_data; @@ -1164,9 +1159,9 @@ fru_area_print_product(struct ipmi_intf * intf, struct fru_info * fru, return; } - i++; /* skip fru area version */ + i++; /* skip fru area version */ area_len = fru_data[i++] * 8; /* fru area length */ - i++; /* skip fru board language */ + i++; /* skip fru board language */ fru_area = get_fru_area_str(fru_data, &i); if (fru_area != NULL && strlen(fru_area) > 0) { @@ -1227,15 +1222,13 @@ fru_area_print_product(struct ipmi_intf * intf, struct fru_info * fru, free(fru_data); } - - -/* fru_area_print_multirec - Print FRU Multi Record Area - * - * @intf: ipmi interface - * @fru: fru info - * @id: fru id - * @offset: offset pointer - */ +/* fru_area_print_multirec - Print FRU Multi Record Area +* +* @intf: ipmi interface +* @fru: fru info +* @id: fru id +* @offset: offset pointer +*/ static void fru_area_print_multirec(struct ipmi_intf * intf, struct fru_info * fru, uint8_t id, uint32_t offset) @@ -1283,36 +1276,36 @@ fru_area_print_multirec(struct ipmi_intf * intf, struct fru_info * fru, (fru_data + i + sizeof (struct fru_multirec_header)); #if WORDS_BIGENDIAN - ps->capacity = BSWAP_16(ps->capacity); - ps->peak_va = BSWAP_16(ps->peak_va); - ps->lowend_input1 = BSWAP_16(ps->lowend_input1); - ps->highend_input1 = BSWAP_16(ps->highend_input1); - ps->lowend_input2 = BSWAP_16(ps->lowend_input2); - ps->highend_input2 = BSWAP_16(ps->highend_input2); - ps->combined_capacity = BSWAP_16(ps->combined_capacity); - ps->peak_cap_ht = BSWAP_16(ps->peak_cap_ht); + ps->capacity = BSWAP_16(ps->capacity); + ps->peak_va = BSWAP_16(ps->peak_va); + ps->lowend_input1 = BSWAP_16(ps->lowend_input1); + ps->highend_input1 = BSWAP_16(ps->highend_input1); + ps->lowend_input2 = BSWAP_16(ps->lowend_input2); + ps->highend_input2 = BSWAP_16(ps->highend_input2); + ps->combined_capacity = BSWAP_16(ps->combined_capacity); + ps->peak_cap_ht = BSWAP_16(ps->peak_cap_ht); #endif - peak_hold_up_time = (ps->peak_cap_ht & 0xf000) >> 12; - peak_capacity = ps->peak_cap_ht & 0x0fff; + peak_hold_up_time = (ps->peak_cap_ht & 0xf000) >> 12; + peak_capacity = ps->peak_cap_ht & 0x0fff; printf (" Power Supply Record\n"); - printf (" Capacity : %d W\n", + printf (" Capacity : %d W\n", ps->capacity); - printf (" Peak VA : %d VA\n", + printf (" Peak VA : %d VA\n", ps->peak_va); - printf (" Inrush Current : %d A\n", + printf (" Inrush Current : %d A\n", ps->inrush_current); - printf (" Inrush Interval : %d ms\n", + printf (" Inrush Interval : %d ms\n", ps->inrush_interval); - printf (" Input Voltage Range 1 : %d-%d V\n", + printf (" Input Voltage Range 1 : %d-%d V\n", ps->lowend_input1 / 100, ps->highend_input1 / 100); - printf (" Input Voltage Range 2 : %d-%d V\n", + printf (" Input Voltage Range 2 : %d-%d V\n", ps->lowend_input2 / 100, ps->highend_input2 / 100); - printf (" Input Frequency Range : %d-%d Hz\n", + printf (" Input Frequency Range : %d-%d Hz\n", ps->lowend_freq, ps->highend_freq); - printf (" A/C Dropout Tolerance : %d ms\n", + printf (" A/C Dropout Tolerance : %d ms\n", ps->dropout_tolerance); - printf (" Flags : %s%s%s%s%s\n", + printf (" Flags : %s%s%s%s%s\n", ps->predictive_fail ? "'Predictive fail' " : "", ps->pfc ? "'Power factor correction' " : "", ps->autoswitch ? "'Autoswitch voltage' " : "", @@ -1320,19 +1313,19 @@ fru_area_print_multirec(struct ipmi_intf * intf, struct fru_info * fru, ps->predictive_fail ? ps->rps_threshold ? ps->tach ? "'Two pulses per rotation'" : "'One pulse per rotation'" : ps->tach ? "'Failure on pin de-assertion'" : "'Failure on pin assertion'" : ""); - printf (" Peak capacity : %d W\n", + printf (" Peak capacity : %d W\n", peak_capacity); - printf (" Peak capacity holdup : %d s\n", + printf (" Peak capacity holdup : %d s\n", peak_hold_up_time); if (ps->combined_capacity == 0) - printf (" Combined capacity : not specified\n"); + printf (" Combined capacity : not specified\n"); else - printf (" Combined capacity : %d W (%s and %s)\n", + printf (" Combined capacity : %d W (%s and %s)\n", ps->combined_capacity, combined_voltage_desc [ps->combined_voltage1], combined_voltage_desc [ps->combined_voltage2]); if (ps->predictive_fail) - printf (" Fan lower threshold : %d RPS\n", + printf (" Fan lower threshold : %d RPS\n", ps->rps_threshold); break; @@ -1341,30 +1334,30 @@ fru_area_print_multirec(struct ipmi_intf * intf, struct fru_info * fru, (fru_data + i + sizeof (struct fru_multirec_header)); #if WORDS_BIGENDIAN - dc->nominal_voltage = BSWAP_16(dc->nominal_voltage); - dc->max_neg_dev = BSWAP_16(dc->max_neg_dev); - dc->max_pos_dev = BSWAP_16(dc->max_pos_dev); - dc->ripple_and_noise = BSWAP_16(dc->ripple_and_noise); - dc->min_current = BSWAP_16(dc->min_current); - dc->max_current = BSWAP_16(dc->max_current); + dc->nominal_voltage = BSWAP_16(dc->nominal_voltage); + dc->max_neg_dev = BSWAP_16(dc->max_neg_dev); + dc->max_pos_dev = BSWAP_16(dc->max_pos_dev); + dc->ripple_and_noise = BSWAP_16(dc->ripple_and_noise); + dc->min_current = BSWAP_16(dc->min_current); + dc->max_current = BSWAP_16(dc->max_current); #endif printf (" DC Output Record\n"); - printf (" Output Number : %d\n", + printf (" Output Number : %d\n", dc->output_number); - printf (" Standby power : %s\n", + printf (" Standby power : %s\n", dc->standby ? "Yes" : "No"); - printf (" Nominal voltage : %.2f V\n", + printf (" Nominal voltage : %.2f V\n", (double) dc->nominal_voltage / 100); - printf (" Max negative deviation : %.2f V\n", + printf (" Max negative deviation : %.2f V\n", (double) dc->max_neg_dev / 100); - printf (" Max positive deviation : %.2f V\n", + printf (" Max positive deviation : %.2f V\n", (double) dc->max_pos_dev / 100); - printf (" Ripple and noise pk-pk : %d mV\n", + printf (" Ripple and noise pk-pk : %d mV\n", dc->ripple_and_noise); - printf (" Minimum current draw : %.3f A\n", + printf (" Minimum current draw : %.3f A\n", (double) dc->min_current / 1000); - printf (" Maximum current draw : %.3f A\n", + printf (" Maximum current draw : %.3f A\n", (double) dc->max_current / 1000); break; @@ -1373,47 +1366,47 @@ fru_area_print_multirec(struct ipmi_intf * intf, struct fru_info * fru, (fru_data + i + sizeof (struct fru_multirec_header)); #if WORDS_BIGENDIAN - dl->nominal_voltage = BSWAP_16(dl->nominal_voltage); - dl->min_voltage = BSWAP_16(dl->min_voltage); - dl->max_voltage = BSWAP_16(dl->max_voltage); - dl->ripple_and_noise = BSWAP_16(dl->ripple_and_noise); - dl->min_current = BSWAP_16(dl->min_current); - dl->max_current = BSWAP_16(dl->max_current); + dl->nominal_voltage = BSWAP_16(dl->nominal_voltage); + dl->min_voltage = BSWAP_16(dl->min_voltage); + dl->max_voltage = BSWAP_16(dl->max_voltage); + dl->ripple_and_noise = BSWAP_16(dl->ripple_and_noise); + dl->min_current = BSWAP_16(dl->min_current); + dl->max_current = BSWAP_16(dl->max_current); #endif printf (" DC Load Record\n"); - printf (" Output Number : %d\n", + printf (" Output Number : %d\n", dl->output_number); - printf (" Nominal voltage : %.2f V\n", + printf (" Nominal voltage : %.2f V\n", (double) dl->nominal_voltage / 100); - printf (" Min voltage allowed : %.2f V\n", + printf (" Min voltage allowed : %.2f V\n", (double) dl->min_voltage / 100); - printf (" Max voltage allowed : %.2f V\n", + printf (" Max voltage allowed : %.2f V\n", (double) dl->max_voltage / 100); - printf (" Ripple and noise pk-pk : %d mV\n", + printf (" Ripple and noise pk-pk : %d mV\n", dl->ripple_and_noise); - printf (" Minimum current load : %.3f A\n", + printf (" Minimum current load : %.3f A\n", (double) dl->min_current / 1000); - printf (" Maximum current load : %.3f A\n", + printf (" Maximum current load : %.3f A\n", (double) dl->max_current / 1000); break; case FRU_RECORD_TYPE_OEM_EXTENSION: { struct fru_multirec_oem_header *oh=(struct fru_multirec_oem_header *) - &fru_data[i + sizeof(struct fru_multirec_header)]; + &fru_data[i + sizeof(struct fru_multirec_header)]; uint32_t iana = oh->mfg_id[0] | oh->mfg_id[1]<<8 | oh->mfg_id[2]<<16; /* Now makes sure this is really PICMG record */ if( iana == IPMI_OEM_PICMG ){ - printf(" PICMG Extension Record\n"); + printf(" PICMG Extension Record\n"); ipmi_fru_picmg_ext_print(fru_data, - i + sizeof(struct fru_multirec_header), - h->len); + i + sizeof(struct fru_multirec_header), + h->len); } /* FIXME: Add OEM record support here */ else{ - printf(" OEM (%s) Record\n", val2str( iana, ipmi_oem_info)); + printf(" OEM (%s) Record\n", val2str( iana, ipmi_oem_info)); } } break; @@ -1421,20 +1414,20 @@ fru_area_print_multirec(struct ipmi_intf * intf, struct fru_info * fru, i += h->len + sizeof (struct fru_multirec_header); } while (!(h->format & 0x80)); - lprintf(LOG_DEBUG ,"Multi-Record area ends at: %i (%xh)",i,i); + lprintf(LOG_DEBUG ,"Multi-Record area ends at: %i (%xh)",i,i); free(fru_data); } /* ipmi_fru_query_new_value - Query new values to replace original FRU content - * - * @data: FRU data - * @offset: offset of the bytes to be modified in data - * @len: size of the modified data - * - * returns : TRUE if data changed - * returns : FALSE if data not changed - */ +* +* @data: FRU data +* @offset: offset of the bytes to be modified in data +* @len: size of the modified data +* +* returns : TRUE if data changed +* returns : FALSE if data not changed +*/ int ipmi_fru_query_new_value(uint8_t *data,int offset, size_t len) { int status=FALSE; @@ -1450,8 +1443,8 @@ int ipmi_fru_query_new_value(uint8_t *data,int offset, size_t len) unsigned int *holder; holder = malloc(len); - printf("Enter hex values for each of the %d entries (lsb first)," \ - " hit between entries\n",len); + printf("Enter hex values for each of the %d entries (lsb first)," \ + " hit between entries\n",len); /* I can't assign scanf' %x into a single char */ for( i=0;ifield1); printf(" Build Date: %*.*s\n", - OEM_KONTRON_FIELD_SIZE, + OEM_KONTRON_FIELD_SIZE, OEM_KONTRON_FIELD_SIZE, ((tOemKontronInformationRecordV0 *) pRecordData)->field2); printf(" Update Date: %*.*s\n", - OEM_KONTRON_FIELD_SIZE, + OEM_KONTRON_FIELD_SIZE, OEM_KONTRON_FIELD_SIZE, ((tOemKontronInformationRecordV0 *) pRecordData)->field3); printf(" Checksum: %*.*s\n\n", - OEM_KONTRON_FIELD_SIZE, + OEM_KONTRON_FIELD_SIZE, OEM_KONTRON_FIELD_SIZE, ((tOemKontronInformationRecordV0 *) pRecordData)->crc32); matchInstance++; @@ -1644,19 +1637,19 @@ static void ipmi_fru_oemkontron_get( int argc, char ** argv,uint8_t * fru_data, else if ( version == 1 ) { printf(" Version: %*.*s\n", - OEM_KONTRON_VERSION_FIELD_SIZE, + OEM_KONTRON_VERSION_FIELD_SIZE, OEM_KONTRON_VERSION_FIELD_SIZE, ((tOemKontronInformationRecordV1 *) pRecordData)->field1); printf(" Build Date: %*.*s\n", - OEM_KONTRON_FIELD_SIZE, + OEM_KONTRON_FIELD_SIZE, OEM_KONTRON_FIELD_SIZE, ((tOemKontronInformationRecordV1 *) pRecordData)->field2); printf(" Update Date: %*.*s\n", - OEM_KONTRON_FIELD_SIZE, + OEM_KONTRON_FIELD_SIZE, OEM_KONTRON_FIELD_SIZE, ((tOemKontronInformationRecordV1 *) pRecordData)->field3); printf(" Checksum: %*.*s\n\n", - OEM_KONTRON_FIELD_SIZE, + OEM_KONTRON_FIELD_SIZE, OEM_KONTRON_FIELD_SIZE, ((tOemKontronInformationRecordV1 *) pRecordData)->crc32); matchInstance++; @@ -1697,15 +1690,15 @@ static int ipmi_fru_oemkontron_edit( int argc, char ** argv,uint8_t * fru_data, if( argc \r\n"); printf("usage: oem 15000 3 0 "\ - " \r\n"); + " \r\n"); badParams = TRUE; return hasChanged; } if( atoi(argv[OEM_KONTRON_RECORDID_ARG_POS]) - == OEM_KONTRON_INFORMATION_RECORD){ + == OEM_KONTRON_INFORMATION_RECORD){ for(i=OEM_KONTRON_VERSION_ARG_POS;i<=OEM_KONTRON_CRC32_ARG_POS;i++){ - if( (strlen(argv[i]) != OEM_KONTRON_FIELD_SIZE) && - (strlen(argv[i]) != OEM_KONTRON_VERSION_FIELD_SIZE)) { + if( (strlen(argv[i]) != OEM_KONTRON_FIELD_SIZE) && + (strlen(argv[i]) != OEM_KONTRON_VERSION_FIELD_SIZE)) { printf("error: version fields must have %d characters\r\n", OEM_KONTRON_FIELD_SIZE); badParams = TRUE; @@ -1718,10 +1711,10 @@ static int ipmi_fru_oemkontron_edit( int argc, char ** argv,uint8_t * fru_data, if(!badParams){ if(oh->record_id == OEM_KONTRON_INFORMATION_RECORD ) { - uint8_t formatVersion = (uint8_t)atoi( argv[OEM_KONTRON_FORMAT_ARG_POS]); + uint8_t formatVersion = (uint8_t)atoi( argv[OEM_KONTRON_FORMAT_ARG_POS]); uint8_t version; - printf(" Kontron OEM Information Record\n"); + printf(" Kontron OEM Information Record\n"); version = oh->record_version; if( version == formatVersion ){ @@ -1734,7 +1727,7 @@ static int ipmi_fru_oemkontron_edit( int argc, char ** argv,uint8_t * fru_data, blockCount = fru_data[offset++]; - printf(" blockCount: %d\n",blockCount); + printf(" blockCount: %d\n",blockCount); for(blockIndex=0;blockIndexfield1 , - argv[OEM_KONTRON_VERSION_ARG_POS] , - OEM_KONTRON_FIELD_SIZE); - memcpy( ((tOemKontronInformationRecordV0 *) - pRecordData)->field2 , - argv[OEM_KONTRON_BUILDDATE_ARG_POS], - OEM_KONTRON_FIELD_SIZE); - memcpy( ((tOemKontronInformationRecordV0 *) - pRecordData)->field3 , - argv[OEM_KONTRON_UPDATEDATE_ARG_POS], - OEM_KONTRON_FIELD_SIZE); - memcpy( ((tOemKontronInformationRecordV0 *) - pRecordData)->crc32 , - argv[OEM_KONTRON_CRC32_ARG_POS] , - OEM_KONTRON_FIELD_SIZE); - } - else - { - memcpy( ((tOemKontronInformationRecordV1 *) - pRecordData)->field1 , - argv[OEM_KONTRON_VERSION_ARG_POS] , - OEM_KONTRON_VERSION_FIELD_SIZE); - memcpy( ((tOemKontronInformationRecordV1 *) - pRecordData)->field2 , - argv[OEM_KONTRON_BUILDDATE_ARG_POS], - OEM_KONTRON_FIELD_SIZE); - memcpy( ((tOemKontronInformationRecordV1 *) - pRecordData)->field3 , - argv[OEM_KONTRON_UPDATEDATE_ARG_POS], - OEM_KONTRON_FIELD_SIZE); - memcpy( ((tOemKontronInformationRecordV1 *) - pRecordData)->crc32 , - argv[OEM_KONTRON_CRC32_ARG_POS] , - OEM_KONTRON_FIELD_SIZE); - } + if( version == 0 ) + { + memcpy( ((tOemKontronInformationRecordV0 *) + pRecordData)->field1 , + argv[OEM_KONTRON_VERSION_ARG_POS] , + OEM_KONTRON_FIELD_SIZE); + memcpy( ((tOemKontronInformationRecordV0 *) + pRecordData)->field2 , + argv[OEM_KONTRON_BUILDDATE_ARG_POS], + OEM_KONTRON_FIELD_SIZE); + memcpy( ((tOemKontronInformationRecordV0 *) + pRecordData)->field3 , + argv[OEM_KONTRON_UPDATEDATE_ARG_POS], + OEM_KONTRON_FIELD_SIZE); + memcpy( ((tOemKontronInformationRecordV0 *) + pRecordData)->crc32 , + argv[OEM_KONTRON_CRC32_ARG_POS] , + OEM_KONTRON_FIELD_SIZE); + } + else + { + memcpy( ((tOemKontronInformationRecordV1 *) + pRecordData)->field1 , + argv[OEM_KONTRON_VERSION_ARG_POS] , + OEM_KONTRON_VERSION_FIELD_SIZE); + memcpy( ((tOemKontronInformationRecordV1 *) + pRecordData)->field2 , + argv[OEM_KONTRON_BUILDDATE_ARG_POS], + OEM_KONTRON_FIELD_SIZE); + memcpy( ((tOemKontronInformationRecordV1 *) + pRecordData)->field3 , + argv[OEM_KONTRON_UPDATEDATE_ARG_POS], + OEM_KONTRON_FIELD_SIZE); + memcpy( ((tOemKontronInformationRecordV1 *) + pRecordData)->crc32 , + argv[OEM_KONTRON_CRC32_ARG_POS] , + OEM_KONTRON_FIELD_SIZE); + } - matchInstance++; - hasChanged = TRUE; - } - else if(!strncmp((char *)argv[OEM_KONTRON_NAME_ARG_POS], - (const char *)(fru_data+offset), nameLen)){ - printf ("Skipped : %s [instance %d]\n",argv[OEM_KONTRON_NAME_ARG_POS], - matchInstance); - matchInstance++; - offset+=nameLen; - } - else { - offset+=nameLen; - } - - if( version == 0 ) - { - offset+= sizeof(tOemKontronInformationRecordV0); - } - else - { - offset+= sizeof(tOemKontronInformationRecordV1); - } - offset++; - } - else - { - printf (" Unsupported version %d\n",version); - } + matchInstance++; + hasChanged = TRUE; + } + else if(!strncmp((char *)argv[OEM_KONTRON_NAME_ARG_POS], + (const char *)(fru_data+offset), nameLen)){ + printf ("Skipped : %s [instance %d]\n",argv[OEM_KONTRON_NAME_ARG_POS], + matchInstance); + matchInstance++; + offset+=nameLen; + } + else { + offset+=nameLen; + } + + if( version == 0 ) + { + offset+= sizeof(tOemKontronInformationRecordV0); + } + else + { + offset+= sizeof(tOemKontronInformationRecordV1); + } + offset++; + } + else + { + printf (" Unsupported version %d\n",version); + } } } else{ - printf(" Version: %d\n",version); + printf(" Version: %d\n",version); } } if( hasChanged ){ @@ -1836,10 +1829,10 @@ static int ipmi_fru_oemkontron_edit( int argc, char ** argv,uint8_t * fru_data, lprintf(LOG_DEBUG,"Initial record checksum : %x",h->record_checksum); lprintf(LOG_DEBUG,"Initial header checksum : %x",h->header_checksum); for(index=0;indexrecord_checksum = ~record_checksum + 1; + h->record_checksum = ~record_checksum + 1; for(index=0;index<(sizeof(struct fru_multirec_header) -1);index++){ @@ -1847,7 +1840,7 @@ static int ipmi_fru_oemkontron_edit( int argc, char ** argv,uint8_t * fru_data, header_checksum+=data; } /* Update header checksum */ - h->header_checksum = ~header_checksum + 1; + h->header_checksum = ~header_checksum + 1; lprintf(LOG_DEBUG,"Final record checksum : %x",h->record_checksum); lprintf(LOG_DEBUG,"Final header checksum : %x",h->header_checksum); @@ -1859,17 +1852,17 @@ static int ipmi_fru_oemkontron_edit( int argc, char ** argv,uint8_t * fru_data, return hasChanged; } -/* ipmi_fru_picmg_ext_edit - Query new values to replace original FRU content - * - * @data: FRU data - * @offset: start of the current multi record (start of header) - * @len: len of the current record (excluding header) - * @h: pointer to record header - * @oh: pointer to OEM /PICMG header - * - * returns: TRUE if data changed - * returns: FALSE if data not changed - */ +/* ipmi_fru_picmg_ext_edit - Query new values to replace original FRU content +* +* @data: FRU data +* @offset: start of the current multi record (start of header) +* @len: len of the current record (excluding header) +* @h: pointer to record header +* @oh: pointer to OEM /PICMG header +* +* returns: TRUE if data changed +* returns: FALSE if data not changed +*/ static int ipmi_fru_picmg_ext_edit(uint8_t * fru_data, int off,int len, struct fru_multirec_header *h, @@ -1881,44 +1874,69 @@ static int ipmi_fru_picmg_ext_edit(uint8_t * fru_data, int length = len; offset += sizeof(struct fru_multirec_oem_header); - if(oh->record_id == FRU_AMC_ACTIVATION ) + switch (oh->record_id) { - printf(" FRU_AMC_ACTIVATION\n"); - { - int index=offset; - uint16_t max_current; + case FRU_AMC_ACTIVATION: + printf(" FRU_AMC_ACTIVATION\n"); + { + int index=offset; + uint16_t max_current; - max_current = fru_data[offset]; - max_current |= fru_data[++offset]<<8; + max_current = fru_data[offset]; + max_current |= fru_data[++offset]<<8; - printf(" Maximum Internal Current(@12V): %02.2f A (0x%02x)\n", - (float)(max_current) / 10.0f , max_current); + printf(" Maximum Internal Current(@12V): %.2f A (0x%02x)\n", + (float)max_current / 10.0f, max_current); - if( ipmi_fru_query_new_value(fru_data,index,2) ){ - max_current = fru_data[index]; - max_current |= fru_data[++index]<<8; - printf(" New Maximum Internal Current(@12V): %02.2f A (0x%02x)\n", - (float)(max_current) / 10.0f , max_current); - hasChanged = TRUE; + if( ipmi_fru_query_new_value(fru_data,index,2) ){ + max_current = fru_data[index]; + max_current |= fru_data[++index]<<8; + printf(" New Maximum Internal Current(@12V): %.2f A (0x%02x)\n", + (float)max_current / 10.0f, max_current); + hasChanged = TRUE; - } + } - printf(" Module Activation Readiness: %i sec.\n", fru_data[++offset]); - printf(" Descriptor Count: %i\n", fru_data[++offset]); - printf("\n"); - - for (++offset; - offset < (off + length); - offset += sizeof(struct fru_picmgext_activation_record)) { - struct fru_picmgext_activation_record * a = - (struct fru_picmgext_activation_record *) &fru_data[offset]; - - printf(" IPMB-Address: 0x%x\n", a->ibmb_addr); - printf(" Max. Module Current: %i A\n", a->max_module_curr/10); + printf(" Module Activation Readiness: %i sec.\n", fru_data[++offset]); + printf(" Descriptor Count: %i\n", fru_data[++offset]); printf("\n"); + + for (++offset; + offset < (off + length); + offset += sizeof(struct fru_picmgext_activation_record)) { + struct fru_picmgext_activation_record * a = + (struct fru_picmgext_activation_record *) &fru_data[offset]; + + printf(" IPMB-Address: 0x%x\n", a->ibmb_addr); + printf(" Max. Module Current: %.2f A\n", (float)a->max_module_curr / 10.0f); + + printf("\n"); + } } - } + break; + + case FRU_AMC_CURRENT: + printf(" FRU_AMC_CURRENT\n"); + { + int index=offset; + unsigned char current; + + current = fru_data[index]; + + printf(" Current draw(@12V): %.2f A (0x%02x)\n", + (float)current / 10.0f, current); + + if( ipmi_fru_query_new_value(fru_data, index, 1) ){ + current = fru_data[index]; + + printf(" New Current draw(@12V): %.2f A (0x%02x)\n", + (float)current / 10.0f, current); + hasChanged = TRUE; + } + } + break; } + if( hasChanged ){ uint8_t record_checksum =0; @@ -1928,10 +1946,10 @@ static int ipmi_fru_picmg_ext_edit(uint8_t * fru_data, lprintf(LOG_DEBUG,"Initial record checksum : %x",h->record_checksum); lprintf(LOG_DEBUG,"Initial header checksum : %x",h->header_checksum); for(index=0;indexrecord_checksum = ~record_checksum + 1; + h->record_checksum = ~record_checksum + 1; for(index=0;index<(sizeof(struct fru_multirec_header) -1);index++){ @@ -1939,7 +1957,7 @@ static int ipmi_fru_picmg_ext_edit(uint8_t * fru_data, header_checksum+=data; } /* Update header checksum */ - h->header_checksum = ~header_checksum + 1; + h->header_checksum = ~header_checksum + 1; lprintf(LOG_DEBUG,"Final record checksum : %x",h->record_checksum); lprintf(LOG_DEBUG,"Final header checksum : %x",h->header_checksum); @@ -1951,17 +1969,17 @@ static int ipmi_fru_picmg_ext_edit(uint8_t * fru_data, } /* ipmi_fru_picmg_ext_print - prints OEM fru record (PICMG) - * - * @fru_data: FRU data - * @offset: offset of the bytes to be modified in data - * @length: size of the record - * - * returns : n/a - */ +* +* @fru_data: FRU data +* @offset: offset of the bytes to be modified in data +* @length: size of the record +* +* returns : n/a +*/ static void ipmi_fru_picmg_ext_print(uint8_t * fru_data, int off, int length) { struct fru_multirec_oem_header *h; - int guid_count; + int guid_count; int offset = off; int start_offset = off; int i; @@ -1975,112 +1993,112 @@ static void ipmi_fru_picmg_ext_print(uint8_t * fru_data, int off, int length) case FRU_PICMG_BACKPLANE_P2P: { uint8_t index; - struct fru_picmgext_slot_desc * slot_d + struct fru_picmgext_slot_desc * slot_d = (struct fru_picmgext_slot_desc*) &fru_data[offset]; - offset += sizeof(struct fru_picmgext_slot_desc); - printf(" FRU_PICMG_BACKPLANE_P2P\n"); + offset += sizeof(struct fru_picmgext_slot_desc); + printf(" FRU_PICMG_BACKPLANE_P2P\n"); while (offset <= (start_offset+length)) { printf("\n"); - printf(" Channel Type: "); + printf(" Channel Type: "); switch ( slot_d -> chan_type ) { - case 0x00: - case 0x07: - printf("PICMG 2.9\n"); - break; - case 0x08: - printf("Single Port Fabric IF\n"); - break; - case 0x09: - printf("Double Port Fabric IF\n"); - break; - case 0x0a: - printf("Full Channel Fabric IF\n"); - break; - case 0x0b: - printf("Base IF\n"); - break; - case 0x0c: - printf("Update Channel IF\n"); - break; - default: - printf("Unknown IF\n"); - break; + case 0x00: + case 0x07: + printf("PICMG 2.9\n"); + break; + case 0x08: + printf("Single Port Fabric IF\n"); + break; + case 0x09: + printf("Double Port Fabric IF\n"); + break; + case 0x0a: + printf("Full Channel Fabric IF\n"); + break; + case 0x0b: + printf("Base IF\n"); + break; + case 0x0c: + printf("Update Channel IF\n"); + break; + default: + printf("Unknown IF\n"); + break; } - printf(" Slot Addr. : %02x\n", slot_d -> slot_addr ); - printf(" Channel Count: %i\n", slot_d -> chn_count); + printf(" Slot Addr. : %02x\n", slot_d -> slot_addr ); + printf(" Channel Count: %i\n", slot_d -> chn_count); for (index = 0; index < (slot_d -> chn_count); index++) { - struct fru_picmgext_chn_desc * d + struct fru_picmgext_chn_desc * d = (struct fru_picmgext_chn_desc *) &fru_data[offset]; if (verbose) - printf( " " - "Chn: %02x -> " - "Chn: %02x in " - "Slot: %02x\n", + printf( " " + "Chn: %02x -> " + "Chn: %02x in " + "Slot: %02x\n", d->local_chn, d->remote_chn, d->remote_slot); - offset += sizeof(struct fru_picmgext_chn_desc); + offset += sizeof(struct fru_picmgext_chn_desc); } slot_d = (struct fru_picmgext_slot_desc*) &fru_data[offset]; offset += sizeof(struct fru_picmgext_slot_desc); } } - break; + break; case FRU_PICMG_ADDRESS_TABLE: { unsigned char entries = 0; unsigned char i; - - printf(" FRU_PICMG_ADDRESS_TABLE\n"); - printf(" Type/Len: 0x%02x\n", fru_data[offset++]); - printf(" Shelf Addr: "); + printf(" FRU_PICMG_ADDRESS_TABLE\n"); + + printf(" Type/Len: 0x%02x\n", fru_data[offset++]); + printf(" Shelf Addr: "); for (i=0;i<20;i++) { printf("0x%02x ", fru_data[offset++]); } printf("\n"); entries = fru_data[offset++]; - printf(" Addr Table Entries: 0x%02x\n", entries); + printf(" Addr Table Entries: 0x%02x\n", entries); for (i=0; igrouping); - printf(" Link Type Extension: 0x%02x - ", d->ext); - if (d->type == FRU_PICMGEXT_LINK_TYPE_BASE){ - switch (d->ext) - { - case 0: - printf("10/100/1000BASE-T Link (four-pair)\n"); - break; - case 1: - printf("ShMC Cross-connect (two-pair)\n"); - break; - default: - printf("Unknwon\n"); - break; - } - }else if (d->type == FRU_PICMGEXT_LINK_TYPE_FABRIC_ETHERNET){ - switch (d->ext) - { - case 0: - printf("Fixed 1000Base-BX\n"); - break; - case 1: - printf("Fixed 10GBASE-BX4 [XAUI]\n"); - break; - case 2: - printf("FC-PI\n"); - break; - default: - printf("Unknwon\n"); - break; - } + printf(" Link Grouping ID: 0x%02x\n", d->grouping); + printf(" Link Type Extension: 0x%02x - ", d->ext); + if (d->type == FRU_PICMGEXT_LINK_TYPE_BASE){ + switch (d->ext) + { + case 0: + printf("10/100/1000BASE-T Link (four-pair)\n"); + break; + case 1: + printf("ShMC Cross-connect (two-pair)\n"); + break; + default: + printf("Unknwon\n"); + break; + } + }else if (d->type == FRU_PICMGEXT_LINK_TYPE_FABRIC_ETHERNET){ + switch (d->ext) + { + case 0: + printf("Fixed 1000Base-BX\n"); + break; + case 1: + printf("Fixed 10GBASE-BX4 [XAUI]\n"); + break; + case 2: + printf("FC-PI\n"); + break; + default: + printf("Unknwon\n"); + break; + } - }else if (d->type == FRU_PICMGEXT_LINK_TYPE_FABRIC_INFINIBAND){ - printf("Unknwon\n"); - }else if (d->type == FRU_PICMGEXT_LINK_TYPE_FABRIC_STAR){ - printf("Unknwon\n"); - }else if (d->type == FRU_PICMGEXT_LINK_TYPE_PCIE){ - printf("Unknwon\n"); - }else - { - printf("Unknwon\n"); - } + }else if (d->type == FRU_PICMGEXT_LINK_TYPE_FABRIC_INFINIBAND){ + printf("Unknwon\n"); + }else if (d->type == FRU_PICMGEXT_LINK_TYPE_FABRIC_STAR){ + printf("Unknwon\n"); + }else if (d->type == FRU_PICMGEXT_LINK_TYPE_PCIE){ + printf("Unknwon\n"); + }else + { + printf("Unknwon\n"); + } - printf(" Link Type: 0x%02x - ",d->type); - if (d->type == 0 || d->type == 0xff) - { - printf("Reserved\n"); - } - else if (d->type >= 0x06 && d->type <= 0xef) { - printf("Reserved\n"); - } - else if (d->type >= 0xf0 && d->type <= 0xfe) { - printf("OEM GUID Definition\n"); - } - else { - switch (d->type) - { - case FRU_PICMGEXT_LINK_TYPE_BASE: - printf("PICMG 3.0 Base Interface 10/100/1000\n"); - break; - case FRU_PICMGEXT_LINK_TYPE_FABRIC_ETHERNET: - printf("PICMG 3.1 Ethernet Fabric Interface\n"); - break; - case FRU_PICMGEXT_LINK_TYPE_FABRIC_INFINIBAND: - printf("PICMG 3.2 Infiniband Fabric Interface\n"); - break; - case FRU_PICMGEXT_LINK_TYPE_FABRIC_STAR: - printf("PICMG 3.3 Star Fabric Interface\n"); - break; - case FRU_PICMGEXT_LINK_TYPE_PCIE: - printf("PICMG 3.4 PCI Express Fabric Interface\n"); - break; - default: - printf("Invalid\n"); - break; - } - } - printf(" Link Designator: \n"); - printf(" Port Flag: 0x%02x\n", d->desig_port); - printf(" Interface: 0x%02x - ", d->desig_if); - switch (d->desig_if) - { - case FRU_PICMGEXT_DESIGN_IF_BASE: - printf("Base Interface\n"); - break; - case FRU_PICMGEXT_DESIGN_IF_FABRIC: - printf("Fabric Interface\n"); - break; - case FRU_PICMGEXT_DESIGN_IF_UPDATE_CHANNEL: - printf("Update Channel\n"); - break; - case FRU_PICMGEXT_DESIGN_IF_RESERVED: - printf("Reserved\n"); - break; - default: - printf("Invalid"); - break; - } - printf(" Channel Number: 0x%02x\n", d->desig_channel); - printf("\n"); - } + printf(" Link Type: 0x%02x - ",d->type); + if (d->type == 0 || d->type == 0xff) + { + printf("Reserved\n"); + } + else if (d->type >= 0x06 && d->type <= 0xef) { + printf("Reserved\n"); + } + else if (d->type >= 0xf0 && d->type <= 0xfe) { + printf("OEM GUID Definition\n"); + } + else { + switch (d->type) + { + case FRU_PICMGEXT_LINK_TYPE_BASE: + printf("PICMG 3.0 Base Interface 10/100/1000\n"); + break; + case FRU_PICMGEXT_LINK_TYPE_FABRIC_ETHERNET: + printf("PICMG 3.1 Ethernet Fabric Interface\n"); + break; + case FRU_PICMGEXT_LINK_TYPE_FABRIC_INFINIBAND: + printf("PICMG 3.2 Infiniband Fabric Interface\n"); + break; + case FRU_PICMGEXT_LINK_TYPE_FABRIC_STAR: + printf("PICMG 3.3 Star Fabric Interface\n"); + break; + case FRU_PICMGEXT_LINK_TYPE_PCIE: + printf("PICMG 3.4 PCI Express Fabric Interface\n"); + break; + default: + printf("Invalid\n"); + break; + } + } + printf(" Link Designator: \n"); + printf(" Port Flag: 0x%02x\n", d->desig_port); + printf(" Interface: 0x%02x - ", d->desig_if); + switch (d->desig_if) + { + case FRU_PICMGEXT_DESIGN_IF_BASE: + printf("Base Interface\n"); + break; + case FRU_PICMGEXT_DESIGN_IF_FABRIC: + printf("Fabric Interface\n"); + break; + case FRU_PICMGEXT_DESIGN_IF_UPDATE_CHANNEL: + printf("Update Channel\n"); + break; + case FRU_PICMGEXT_DESIGN_IF_RESERVED: + printf("Reserved\n"); + break; + default: + printf("Invalid"); + break; + } + printf(" Channel Number: 0x%02x\n", d->desig_channel); + printf("\n"); + } - break; + break; - case FRU_AMC_CURRENT: - { - unsigned char current; - printf(" FRU_AMC_CURRENT\n"); + case FRU_AMC_CURRENT: + { + unsigned char current; + printf(" FRU_AMC_CURRENT\n"); - //recVersion = fru_data[offset++]; - current = fru_data[offset]; - printf(" Current draw: %.1f A @ 12V => %.2f Watt\n", - (float) current/10.0, ((float)current/10.0)*12.0); - printf("\n"); - } - break; + current = fru_data[offset]; + printf(" Current draw(@12V): %.2f A [ %.2f Watt ]\n", + (float)current / 10.0f, + (float)current / 10.0f * 12.0f); + printf("\n"); + } + break; - case FRU_AMC_ACTIVATION: - printf(" FRU_AMC_ACTIVATION\n"); - { - uint16_t max_current; + case FRU_AMC_ACTIVATION: + printf(" FRU_AMC_ACTIVATION\n"); + { + uint16_t max_current; - max_current = fru_data[offset]; - max_current |= fru_data[++offset]<<8; - printf(" Maximum Internal Current(@12V): %.2f A [ %.2f Watt ]\n", - (float) max_current / 10, - (float) max_current / 10 * 12); - printf(" Module Activation Readiness: %i sec.\n", fru_data[++offset]); + max_current = fru_data[offset]; + max_current |= fru_data[++offset]<<8; + printf(" Maximum Internal Current(@12V): %.2f A [ %.2f Watt ]\n", + (float)max_current / 10.0f, + (float)max_current / 10.0f * 12.0f); - printf(" Descriptor Count: %i\n", fru_data[++offset]); - printf("\n"); + printf(" Module Activation Readiness: %i sec.\n", fru_data[++offset]); + printf(" Descriptor Count: %i\n", fru_data[++offset]); + printf("\n"); - for(++offset; offset < off + length; offset += sizeof(struct fru_picmgext_activation_record)) - { - struct fru_picmgext_activation_record * a = - (struct fru_picmgext_activation_record *) &fru_data[offset]; + for(++offset; offset < off + length; offset += sizeof(struct fru_picmgext_activation_record)) + { + struct fru_picmgext_activation_record * a = + (struct fru_picmgext_activation_record *) &fru_data[offset]; - printf(" IPMB-Address: 0x%x\n", a->ibmb_addr); - printf(" Max. Module Current: %.2f A\n", (float)a->max_module_curr/10); - printf("\n"); - } - } - break; + printf(" IPMB-Address: 0x%x\n", a->ibmb_addr); + printf(" Max. Module Current: %.2f A\n", (float)a->max_module_curr / 10.0f); + printf("\n"); + } + } + break; - case FRU_AMC_CARRIER_P2P: - printf(" FRU_CARRIER_P2P\n"); - { - uint16_t index; + case FRU_AMC_CARRIER_P2P: + printf(" FRU_CARRIER_P2P\n"); + { + uint16_t index; - for(; offset < off + length; ) - { - struct fru_picmgext_carrier_p2p_record * h = - (struct fru_picmgext_carrier_p2p_record *) &fru_data[offset]; + for(; offset < off + length; ) + { + struct fru_picmgext_carrier_p2p_record * h = + (struct fru_picmgext_carrier_p2p_record *) &fru_data[offset]; - printf("\n"); - printf(" Resource ID: %i", h->resource_id & 0x07); - printf(" Type: "); - if ((h->resource_id>>7) == 1) { - printf("AMC\n"); - } else { - printf("Local\n"); - } - printf(" Descriptor Count: %i\n", h->p2p_count); + printf("\n"); + printf(" Resource ID: %i", h->resource_id & 0x07); + printf(" Type: "); + if ((h->resource_id>>7) == 1) { + printf("AMC\n"); + } else { + printf("Local\n"); + } + printf(" Descriptor Count: %i\n", h->p2p_count); - offset += sizeof(struct fru_picmgext_carrier_p2p_record); + offset += sizeof(struct fru_picmgext_carrier_p2p_record); - for (index = 0; index < h->p2p_count; index++) - { - /* to solve little endian /big endian problem */ - unsigned char data[3]; - struct fru_picmgext_carrier_p2p_descriptor * desc; + for (index = 0; index < h->p2p_count; index++) + { + /* to solve little endian /big endian problem */ + unsigned char data[3]; + struct fru_picmgext_carrier_p2p_descriptor * desc; - #ifndef WORDS_BIGENDIAN - data[0] = fru_data[offset+0]; - data[1] = fru_data[offset+1]; - data[2] = fru_data[offset+2]; - #else - data[0] = fru_data[offset+2]; - data[1] = fru_data[offset+1]; - data[2] = fru_data[offset+0]; - #endif + #ifndef WORDS_BIGENDIAN + data[0] = fru_data[offset+0]; + data[1] = fru_data[offset+1]; + data[2] = fru_data[offset+2]; + #else + data[0] = fru_data[offset+2]; + data[1] = fru_data[offset+1]; + data[2] = fru_data[offset+0]; + #endif - desc = (struct fru_picmgext_carrier_p2p_descriptor*)&data; + desc = (struct fru_picmgext_carrier_p2p_descriptor*)&data; - printf(" Port: %02d\t-> Remote Port: %02d\t", - desc->local_port, desc->remote_port); - if((desc->remote_resource_id >> 7) == 1) - printf("[ AMC ID: %02d ]\n", desc->remote_resource_id & 0x0F); - else - printf("[ local ID: %02d ]\n", desc->remote_resource_id & 0x0F); + printf(" Port: %02d\t-> Remote Port: %02d\t", + desc->local_port, desc->remote_port); + if((desc->remote_resource_id >> 7) == 1) + printf("[ AMC ID: %02d ]\n", desc->remote_resource_id & 0x0F); + else + printf("[ local ID: %02d ]\n", desc->remote_resource_id & 0x0F); - offset += sizeof(struct fru_picmgext_carrier_p2p_descriptor); - } - } - } - break; + offset += sizeof(struct fru_picmgext_carrier_p2p_descriptor); + } + } + } + break; case FRU_AMC_P2P: printf(" FRU_AMC_P2P\n"); @@ -2351,7 +2369,7 @@ static void ipmi_fru_picmg_ext_print(uint8_t * fru_data, int off, int length) for (i = 0 ; i < guid_count; i++ ) { int j; - printf(" GUID %2d: ", i); + printf(" GUID %2d: ", i); for (j=0; j < sizeof(struct fru_picmgext_guid); j++) { printf("%02x", fru_data[offset+j]); @@ -2362,23 +2380,23 @@ static void ipmi_fru_picmg_ext_print(uint8_t * fru_data, int off, int length) } h = (struct fru_picmgext_amc_p2p_record *) &fru_data[offset]; - printf(" %s", (h->record_type?"AMC Module:":"On-Carrier Device")); - printf(" Recource ID: %i\n", h->resource_id); + printf(" %s", (h->record_type?"AMC Module:":"On-Carrier Device")); + printf(" Recource ID: %i\n", h->resource_id); - offset += sizeof(struct fru_picmgext_amc_p2p_record); + offset += sizeof(struct fru_picmgext_amc_p2p_record); - channel_count = fru_data[offset++]; - printf(" Descriptor Count: %i\n", channel_count); + channel_count = fru_data[offset++]; + printf(" Descriptor Count: %i\n", channel_count); - for (index=0 ;index < channel_count; index++) - { - struct fru_picmgext_amc_channel_desc_record * d = - (struct fru_picmgext_amc_channel_desc_record *) &fru_data[offset]; + for (index=0 ;index < channel_count; index++) + { + struct fru_picmgext_amc_channel_desc_record * d = + (struct fru_picmgext_amc_channel_desc_record *) &fru_data[offset]; - printf(" Lane 0 Port: %i\n", d->lane0port); - printf(" Lane 1 Port: %i\n", d->lane1port); - printf(" Lane 2 Port: %i\n", d->lane2port); - printf(" Lane 3 Port: %i\n\n", d->lane3port); + printf(" Lane 0 Port: %i\n", d->lane0port); + printf(" Lane 1 Port: %i\n", d->lane1port); + printf(" Lane 2 Port: %i\n", d->lane2port); + printf(" Lane 3 Port: %i\n\n", d->lane3port); offset += sizeof(struct fru_picmgext_amc_channel_desc_record); @@ -2389,122 +2407,122 @@ static void ipmi_fru_picmg_ext_print(uint8_t * fru_data, int off, int length) struct fru_picmgext_amc_link_desc_record * l = (struct fru_picmgext_amc_link_desc_record *) &fru_data[offset]; - printf(" Link Designator: Channel ID: %i\n" - " Port Flag 0: %s%s%s%s\n", - l->channel_id, - (l->port_flag_0)?"o":"-", - (l->port_flag_1)?"o":"-", - (l->port_flag_2)?"o":"-", - (l->port_flag_3)?"o":"-" ); + printf(" Link Designator: Channel ID: %i\n" + " Port Flag 0: %s%s%s%s\n", + l->channel_id, + (l->port_flag_0)?"o":"-", + (l->port_flag_1)?"o":"-", + (l->port_flag_2)?"o":"-", + (l->port_flag_3)?"o":"-" ); switch (l->type) { /* AMC.1 */ - case FRU_PICMGEXT_AMC_LINK_TYPE_PCIE: - printf(" Link Type: %02x - " - "AMC.1 PCI Express\n", l->type); - switch (l->type_ext) - { - case AMC_LINK_TYPE_EXT_PCIE_G1_NSSC: - printf(" Link Type Ext: %i - " - " Gen 1 capable - non SSC\n", l->type_ext); - break; + case FRU_PICMGEXT_AMC_LINK_TYPE_PCIE: + printf(" Link Type: %02x - " + "AMC.1 PCI Express\n", l->type); + switch (l->type_ext) + { + case AMC_LINK_TYPE_EXT_PCIE_G1_NSSC: + printf(" Link Type Ext: %i - " + " Gen 1 capable - non SSC\n", l->type_ext); + break; - case AMC_LINK_TYPE_EXT_PCIE_G1_SSC: - printf(" Link Type Ext: %i - " - " Gen 1 capable - SSC\n", l->type_ext); - break; + case AMC_LINK_TYPE_EXT_PCIE_G1_SSC: + printf(" Link Type Ext: %i - " + " Gen 1 capable - SSC\n", l->type_ext); + break; - case AMC_LINK_TYPE_EXT_PCIE_G2_NSSC: - printf(" Link Type Ext: %i - " - " Gen 2 capable - non SSC\n", l->type_ext); - break; - case AMC_LINK_TYPE_EXT_PCIE_G2_SSC: - printf(" Link Type Ext: %i - " - " Gen 2 capable - SSC\n", l->type_ext); - break; - default: - printf(" Link Type Ext: %i - " - " Invalid\n", l->type_ext); - break; - } + case AMC_LINK_TYPE_EXT_PCIE_G2_NSSC: + printf(" Link Type Ext: %i - " + " Gen 2 capable - non SSC\n", l->type_ext); + break; + case AMC_LINK_TYPE_EXT_PCIE_G2_SSC: + printf(" Link Type Ext: %i - " + " Gen 2 capable - SSC\n", l->type_ext); + break; + default: + printf(" Link Type Ext: %i - " + " Invalid\n", l->type_ext); + break; + } break; /* AMC.1 */ case FRU_PICMGEXT_AMC_LINK_TYPE_PCIE_AS1: - case FRU_PICMGEXT_AMC_LINK_TYPE_PCIE_AS2: - printf(" Link Type: %02x - " - "AMC.1 PCI Express Advanced Switching\n", l->type); - printf(" Link Type Ext: %i\n", l->type_ext); - break; - - /* AMC.2 */ - case FRU_PICMGEXT_AMC_LINK_TYPE_ETHERNET: - printf(" Link Type: %02x - " - "AMC.2 Ethernet\n", l->type); - switch (l->type_ext) - { - case AMC_LINK_TYPE_EXT_ETH_1000_BX: - printf(" Link Type Ext: %i - " - " 1000Base-Bx (SerDES Gigabit) Ethernet Link\n", l->type_ext); - break; - - case AMC_LINK_TYPE_EXT_ETH_10G_XAUI: - printf(" Link Type Ext: %i - " - " 10Gbit XAUI Ethernet Link\n", l->type_ext); - break; - - default: - printf(" Link Type Ext: %i - " - " Invalid\n", l->type_ext); - break; - } + case FRU_PICMGEXT_AMC_LINK_TYPE_PCIE_AS2: + printf(" Link Type: %02x - " + "AMC.1 PCI Express Advanced Switching\n", l->type); + printf(" Link Type Ext: %i\n", l->type_ext); break; - /* AMC.3 */ - case FRU_PICMGEXT_AMC_LINK_TYPE_STORAGE: - printf(" Link Type: %02x - " - "AMC.3 Storage\n", l->type); - switch (l->type_ext) - { - case AMC_LINK_TYPE_EXT_STORAGE_FC: - printf(" Link Type Ext: %i - " - " Fibre Channel\n", l->type_ext); - break; + /* AMC.2 */ + case FRU_PICMGEXT_AMC_LINK_TYPE_ETHERNET: + printf(" Link Type: %02x - " + "AMC.2 Ethernet\n", l->type); + switch (l->type_ext) + { + case AMC_LINK_TYPE_EXT_ETH_1000_BX: + printf(" Link Type Ext: %i - " + " 1000Base-Bx (SerDES Gigabit) Ethernet Link\n", l->type_ext); + break; - case AMC_LINK_TYPE_EXT_STORAGE_SATA: - printf(" Link Type Ext: %i - " - " Serial ATA\n", l->type_ext); - break; + case AMC_LINK_TYPE_EXT_ETH_10G_XAUI: + printf(" Link Type Ext: %i - " + " 10Gbit XAUI Ethernet Link\n", l->type_ext); + break; - case AMC_LINK_TYPE_EXT_STORAGE_SAS: - printf(" Link Type Ext: %i - " - " Serial Attached SCSI\n", l->type_ext); - break; + default: + printf(" Link Type Ext: %i - " + " Invalid\n", l->type_ext); + break; + } + break; - default: - printf(" Link Type Ext: %i - " - " Invalid\n", l->type_ext); - break; - } - break; + /* AMC.3 */ + case FRU_PICMGEXT_AMC_LINK_TYPE_STORAGE: + printf(" Link Type: %02x - " + "AMC.3 Storage\n", l->type); + switch (l->type_ext) + { + case AMC_LINK_TYPE_EXT_STORAGE_FC: + printf(" Link Type Ext: %i - " + " Fibre Channel\n", l->type_ext); + break; - /* AMC.4 */ - case FRU_PICMGEXT_AMC_LINK_TYPE_RAPIDIO: - printf(" Link Type: %02x - " - "AMC.4 Serial Rapid IO\n", l->type); - printf(" Link Type Ext: %i\n", l->type_ext); - break; - default: - printf(" Link Type: %02x - " - "reserved or OEM GUID", l->type); - printf(" Link Type Ext: %i\n", l->type_ext); - break; - } + case AMC_LINK_TYPE_EXT_STORAGE_SATA: + printf(" Link Type Ext: %i - " + " Serial ATA\n", l->type_ext); + break; - printf(" Link group Id: %i\n", l->group_id); - printf(" Link Asym Match: %i\n\n",l->asym_match); + case AMC_LINK_TYPE_EXT_STORAGE_SAS: + printf(" Link Type Ext: %i - " + " Serial Attached SCSI\n", l->type_ext); + break; + + default: + printf(" Link Type Ext: %i - " + " Invalid\n", l->type_ext); + break; + } + break; + + /* AMC.4 */ + case FRU_PICMGEXT_AMC_LINK_TYPE_RAPIDIO: + printf(" Link Type: %02x - " + "AMC.4 Serial Rapid IO\n", l->type); + printf(" Link Type Ext: %i\n", l->type_ext); + break; + default: + printf(" Link Type: %02x - " + "reserved or OEM GUID", l->type); + printf(" Link Type Ext: %i\n", l->type_ext); + break; + } + + printf(" Link group Id: %i\n", l->group_id); + printf(" Link Asym Match: %i\n\n",l->asym_match); offset += sizeof(struct fru_picmgext_amc_link_desc_record); } @@ -2516,135 +2534,135 @@ static void ipmi_fru_picmg_ext_print(uint8_t * fru_data, int off, int length) unsigned char extVersion; unsigned char siteCount; - printf(" FRU_CARRIER_INFO\n"); + printf(" FRU_CARRIER_INFO\n"); - extVersion = fru_data[offset++]; - siteCount = fru_data[offset++]; + extVersion = fru_data[offset++]; + siteCount = fru_data[offset++]; - printf(" AMC.0 extension version: R%d.%d\n", - (extVersion >> 0)& 0x0F, - (extVersion >> 4)& 0x0F ); - printf(" Carrier Sie Number Cnt: %d\n", siteCount); + printf(" AMC.0 extension version: R%d.%d\n", + (extVersion >> 0)& 0x0F, + (extVersion >> 4)& 0x0F ); + printf(" Carrier Sie Number Cnt: %d\n", siteCount); - for (i = 0 ; i < siteCount; i++ ){ - printf(" Site ID: %i \n", fru_data[offset++]); - } - printf("\n"); - } + for (i = 0 ; i < siteCount; i++ ){ + printf(" Site ID: %i \n", fru_data[offset++]); + } + printf("\n"); + } break; case FRU_PICMG_CLK_CARRIER_P2P: { unsigned char desc_count; int i,j; - printf(" FRU_PICMG_CLK_CARRIER_P2P\n"); + printf(" FRU_PICMG_CLK_CARRIER_P2P\n"); - desc_count = fru_data[offset++]; + desc_count = fru_data[offset++]; - for(i=0; i>6 == 0) {printf("On-Carrier-Device\n");} - else if((resource_id & 0xC0)>>6 == 1) {printf("AMC slot\n");} - else if((resource_id & 0xC0)>>6 == 2) {printf("Backplane\n");} - else{ printf("reserved\n");} - printf(" Channel Count: 0x%02x\n", channel_count); + printf("\n"); + printf(" Clock Resource ID: 0x%02x Type: ", resource_id); + if((resource_id & 0xC0)>>6 == 0) {printf("On-Carrier-Device\n");} + else if((resource_id & 0xC0)>>6 == 1) {printf("AMC slot\n");} + else if((resource_id & 0xC0)>>6 == 2) {printf("Backplane\n");} + else{ printf("reserved\n");} + printf(" Channel Count: 0x%02x\n", channel_count); - for(j=0; j", loc_channel); - printf(" remote CLKID: 0x%02x ", rem_channel); - if((rem_resource & 0xC0)>>6 == 0) {printf("[ Carrier-Dev");} - else if((rem_resource & 0xC0)>>6 == 1) {printf("[ AMC slot ");} - else if((rem_resource & 0xC0)>>6 == 2) {printf("[ Backplane ");} - else{ printf("reserved ");} - printf(" 0x%02x ]\n", rem_resource&0xF); - } - } + printf(" CLK-ID: 0x%02x ->", loc_channel); + printf(" remote CLKID: 0x%02x ", rem_channel); + if((rem_resource & 0xC0)>>6 == 0) {printf("[ Carrier-Dev");} + else if((rem_resource & 0xC0)>>6 == 1) {printf("[ AMC slot ");} + else if((rem_resource & 0xC0)>>6 == 2) {printf("[ Backplane ");} + else{ printf("reserved ");} + printf(" 0x%02x ]\n", rem_resource&0xF); + } + } printf("\n"); } break; case FRU_PICMG_CLK_CONFIG: { - unsigned char resource_id, descr_count; - int i,j; + unsigned char resource_id, descr_count; + int i,j; - printf(" FRU_PICMG_CLK_CONFIG\n"); + printf(" FRU_PICMG_CLK_CONFIG\n"); - resource_id = fru_data[offset++]; - descr_count = fru_data[offset++]; + resource_id = fru_data[offset++]; + descr_count = fru_data[offset++]; - printf("\n"); - printf(" Clock Resource ID: 0x%02x\n", resource_id); - printf(" Descr. Count: 0x%02x\n", descr_count); + printf("\n"); + printf(" Clock Resource ID: 0x%02x\n", resource_id); + printf(" Descr. Count: 0x%02x\n", descr_count); - for(i=0; i 1) & 1, - (feature&1)?"Source":"Receiver"); - printf(" Family: 0x%02x - AccLVL: 0x%02x\n", family, accuracy); - printf(" FRQ: %-9d - min: %-9d - max: %-9d\n", - (int)freq, (int)min_freq, (int)max_freq); - } - printf("\n"); + printf(" - Feature: 0x%02x - PLL: %x / Asym: %s\n", + feature, + (feature > 1) & 1, + (feature&1)?"Source":"Receiver"); + printf(" Family: 0x%02x - AccLVL: 0x%02x\n", family, accuracy); + printf(" FRQ: %-9d - min: %-9d - max: %-9d\n", + (int)freq, (int)min_freq, (int)max_freq); + } + printf("\n"); } printf("\n"); } @@ -2662,27 +2680,27 @@ static void ipmi_fru_picmg_ext_print(uint8_t * fru_data, int off, int length) case FRU_UTCA_CLOCK_MAPPING: case FRU_UTCA_MSG_BRIDGE_POLICY: case FRU_UTCA_OEM_MODULE_DESC: - printf(" Not implemented yet. uTCA specific record found!!\n"); - printf(" - Record ID: 0x%02x\n", h->record_id); + printf(" Not implemented yet. uTCA specific record found!!\n"); + printf(" - Record ID: 0x%02x\n", h->record_id); break; default: - printf(" Unknown OEM Extension Record ID: %x\n", h->record_id); + printf(" Unknown OEM Extension Record ID: %x\n", h->record_id); break; } } -/* __ipmi_fru_print - Do actual work to print a FRU by its ID - * - * @intf: ipmi interface - * @id: fru id - * - * returns -1 on error - * returns 0 if successful - * returns 1 if device not present - */ +/* __ipmi_fru_print - Do actual work to print a FRU by its ID +* +* @intf: ipmi interface +* @id: fru id +* +* returns -1 on error +* returns 0 if successful +* returns 1 if device not present +*/ static int __ipmi_fru_print(struct ipmi_intf * intf, uint8_t id) { @@ -2696,8 +2714,8 @@ __ipmi_fru_print(struct ipmi_intf * intf, uint8_t id) memset(&header, 0, sizeof(struct fru_header)); /* - * get info about this FRU - */ + * get info about this FRU + */ memset(msg_data, 0, 4); msg_data[0] = id; @@ -2730,8 +2748,8 @@ __ipmi_fru_print(struct ipmi_intf * intf, uint8_t id) } /* - * retrieve the FRU header - */ + * retrieve the FRU header + */ msg_data[0] = id; msg_data[1] = 0; msg_data[2] = 0; @@ -2750,7 +2768,7 @@ __ipmi_fru_print(struct ipmi_intf * intf, uint8_t id) } if (rsp->ccode > 0) { printf(" Device not present (%s)\n", - val2str(rsp->ccode, completion_code_vals)); + val2str(rsp->ccode, completion_code_vals)); return 1; } @@ -2766,56 +2784,56 @@ __ipmi_fru_print(struct ipmi_intf * intf, uint8_t id) } /* offsets need converted to bytes - * but that conversion is not done to the structure - * because we may end up with offset > 255 - * which would overflow our 1-byte offset field */ + * but that conversion is not done to the structure + * because we may end up with offset > 255 + * which would overflow our 1-byte offset field */ - lprintf(LOG_DEBUG, "fru.header.version: 0x%x", + lprintf(LOG_DEBUG, "fru.header.version: 0x%x", header.version); lprintf(LOG_DEBUG, "fru.header.offset.internal: 0x%x", header.offset.internal * 8); - lprintf(LOG_DEBUG, "fru.header.offset.chassis: 0x%x", + lprintf(LOG_DEBUG, "fru.header.offset.chassis: 0x%x", header.offset.chassis * 8); - lprintf(LOG_DEBUG, "fru.header.offset.board: 0x%x", + lprintf(LOG_DEBUG, "fru.header.offset.board: 0x%x", header.offset.board * 8); - lprintf(LOG_DEBUG, "fru.header.offset.product: 0x%x", + lprintf(LOG_DEBUG, "fru.header.offset.product: 0x%x", header.offset.product * 8); - lprintf(LOG_DEBUG, "fru.header.offset.multi: 0x%x", + lprintf(LOG_DEBUG, "fru.header.offset.multi: 0x%x", header.offset.multi * 8); /* - * rather than reading the entire part - * only read the areas we'll format - */ - /* chassis area */ + * rather than reading the entire part + * only read the areas we'll format + */ + /* chassis area */ if ((header.offset.chassis*8) >= sizeof(struct fru_header)) - fru_area_print_chassis(intf, &fru, id, header.offset.chassis*8); + fru_area_print_chassis(intf, &fru, id, header.offset.chassis*8); /* board area */ if ((header.offset.board*8) >= sizeof(struct fru_header)) - fru_area_print_board(intf, &fru, id, header.offset.board*8); + fru_area_print_board(intf, &fru, id, header.offset.board*8); /* product area */ if ((header.offset.product*8) >= sizeof(struct fru_header)) - fru_area_print_product(intf, &fru, id, header.offset.product*8); + fru_area_print_product(intf, &fru, id, header.offset.product*8); /* multirecord area */ if( verbose==0 ) /* scipp parsing multirecord */ - return 0; + return 0; - if ((header.offset.multi*8) >= sizeof(struct fru_header)) - fru_area_print_multirec(intf, &fru, id, header.offset.multi*8); + if ((header.offset.multi*8) >= sizeof(struct fru_header)) + fru_area_print_multirec(intf, &fru, id, header.offset.multi*8); return 0; } -/* ipmi_fru_print - Print a FRU from its SDR locator record - * - * @intf: ipmi interface - * @fru: SDR FRU Locator Record - * - * returns -1 on error - */ +/* ipmi_fru_print - Print a FRU from its SDR locator record +* +* @intf: ipmi interface +* @fru: SDR FRU Locator Record +* +* returns -1 on error +*/ int ipmi_fru_print(struct ipmi_intf * intf, struct sdr_record_fru_locator * fru) { @@ -2827,29 +2845,29 @@ ipmi_fru_print(struct ipmi_intf * intf, struct sdr_record_fru_locator * fru) return __ipmi_fru_print(intf, 0); /* Logical FRU Device - * dev_type == 0x10 - * modifier - * 0x00 = IPMI FRU Inventory - * 0x01 = DIMM Memory ID - * 0x02 = IPMI FRU Inventory - * 0x03 = System Processor FRU - * 0xff = unspecified - * - * EEPROM 24C01 or equivalent - * dev_type >= 0x08 && dev_type <= 0x0f - * modifier - * 0x00 = unspecified - * 0x01 = DIMM Memory ID - * 0x02 = IPMI FRU Inventory - * 0x03 = System Processor Cartridge - */ + * dev_type == 0x10 + * modifier + * 0x00 = IPMI FRU Inventory + * 0x01 = DIMM Memory ID + * 0x02 = IPMI FRU Inventory + * 0x03 = System Processor FRU + * 0xff = unspecified + * + * EEPROM 24C01 or equivalent + * dev_type >= 0x08 && dev_type <= 0x0f + * modifier + * 0x00 = unspecified + * 0x01 = DIMM Memory ID + * 0x02 = IPMI FRU Inventory + * 0x03 = System Processor Cartridge + */ if (fru->dev_type != 0x10 && - (fru->dev_type_modifier != 0x02 || - fru->dev_type < 0x08 || fru->dev_type > 0x0f)) + (fru->dev_type_modifier != 0x02 || + fru->dev_type < 0x08 || fru->dev_type > 0x0f)) return -1; if (fru->dev_slave_addr == IPMI_BMC_SLAVE_ADDR && - fru->device_id == 0) + fru->device_id == 0) return 0; memset(desc, 0, sizeof(desc)); @@ -2875,9 +2893,9 @@ ipmi_fru_print(struct ipmi_intf * intf, struct sdr_record_fru_locator * fru) default: if (verbose) printf(" Unsupported device 0x%02x " - "type 0x%02x with modifier 0x%02x\n", - fru->device_id, fru->dev_type, - fru->dev_type_modifier); + "type 0x%02x with modifier 0x%02x\n", + fru->device_id, fru->dev_type, + fru->dev_type_modifier); else printf(" Unsupported device\n"); } @@ -2887,11 +2905,11 @@ ipmi_fru_print(struct ipmi_intf * intf, struct sdr_record_fru_locator * fru) } /* ipmi_fru_print_all - Print builtin FRU + SDR FRU Locator records - * - * @intf: ipmi interface - * - * returns -1 on error - */ +* +* @intf: ipmi interface +* +* returns -1 on error +*/ static int ipmi_fru_print_all(struct ipmi_intf * intf) { @@ -2929,8 +2947,8 @@ ipmi_fru_print_all(struct ipmi_intf * intf) static void ipmi_fru_read_to_bin(struct ipmi_intf * intf, - char * pFileName, - uint8_t fruId) + char * pFileName, + uint8_t fruId) { struct ipmi_rs * rsp; struct ipmi_rq req; @@ -2959,13 +2977,13 @@ ipmi_fru_read_to_bin(struct ipmi_intf * intf, fru.access = rsp->data[2] & 0x1; if (verbose) { - printf("Fru Size = %d bytes\n",fru.size); + printf("Fru Size = %d bytes\n",fru.size); printf("Fru Access = %xh\n", fru.access); } pFruBuf = malloc(fru.size); if (pFruBuf != NULL) { - printf("Fru Size : %d bytes\n",fru.size); + printf("Fru Size : %d bytes\n",fru.size); read_fru_area(intf, &fru, fruId, 0, fru.size, pFruBuf); } else { lprintf(LOG_ERR, "Cannot allocate %d bytes\n", fru.size); @@ -3016,14 +3034,14 @@ ipmi_fru_write_from_bin(struct ipmi_intf * intf, if (rsp->ccode) { if (rsp->ccode == 0xc3) - printf(" Timeout accessing FRU info. (Device not present?)\n"); + printf(" Timeout accessing FRU info. (Device not present?)\n"); return; } fru.size = (rsp->data[1] << 8) | rsp->data[0]; fru.access = rsp->data[2] & 0x1; if (verbose) { - printf("Fru Size = %d bytes\n", fru.size); + printf("Fru Size = %d bytes\n", fru.size); printf("Fru Access = %xh\n", fru.access); } @@ -3036,8 +3054,8 @@ ipmi_fru_write_from_bin(struct ipmi_intf * intf, pFile = fopen(pFileName, "rb"); if (pFile != NULL) { len = fread(pFruBuf, 1, fru.size, pFile); - printf("Fru Size : %d bytes\n", fru.size); - printf("Size to Write : %d bytes\n", len); + printf("Fru Size : %d bytes\n", fru.size); + printf("Size to Write : %d bytes\n", len); fclose(pFile); } else { lprintf(LOG_ERR, "Error opening file %s\n", pFileName); @@ -3051,20 +3069,18 @@ ipmi_fru_write_from_bin(struct ipmi_intf * intf, free(pFruBuf); } - - -/* ipmi_fru_edit_multirec - Query new values to replace original FRU content - * - * @intf: interface to use - * @id: FRU id to work on - * - * returns: nothing - */ +/* ipmi_fru_edit_multirec - Query new values to replace original FRU content +* +* @intf: interface to use +* @id: FRU id to work on +* +* returns: nothing +*/ /* Work in progress, copy paste most of the stuff for other functions in this file ... not elegant yet */ static int ipmi_fru_edit_multirec(struct ipmi_intf * intf, uint8_t id , - int argc, char ** argv) + int argc, char ** argv) { struct ipmi_rs * rsp; @@ -3078,11 +3094,11 @@ ipmi_fru_edit_multirec(struct ipmi_intf * intf, uint8_t id , uint32_t fruMultiRecSize = 0; struct fru_info fruInfo; retStatus = ipmi_fru_get_multirec_location_from_fru(intf, id, &fruInfo, - &offFruMultiRec, - &fruMultiRecSize); + &offFruMultiRec, + &fruMultiRecSize); - lprintf(LOG_DEBUG, "FRU Size : %lu\n", fruMultiRecSize); + lprintf(LOG_DEBUG, "FRU Size : %lu\n", fruMultiRecSize); lprintf(LOG_DEBUG, "Multi Rec offset: %lu\n", offFruMultiRec); { @@ -3092,8 +3108,8 @@ ipmi_fru_edit_multirec(struct ipmi_intf * intf, uint8_t id , memset(&header, 0, sizeof(struct fru_header)); /* - * get info about this FRU - */ + * get info about this FRU + */ memset(msg_data, 0, 4); msg_data[0] = id; @@ -3159,10 +3175,10 @@ ipmi_fru_edit_multirec(struct ipmi_intf * intf, uint8_t id , last_off += len; } - if( h->type == FRU_RECORD_TYPE_OEM_EXTENSION ){ + if( h->type == FRU_RECORD_TYPE_OEM_EXTENSION ){ struct fru_multirec_oem_header *oh=(struct fru_multirec_oem_header *) - &fru_data[i + sizeof(struct fru_multirec_header)]; + &fru_data[i + sizeof(struct fru_multirec_header)]; uint32_t iana = oh->mfg_id[0] | oh->mfg_id[1]<<8 | oh->mfg_id[2]<<16; uint32_t suppliedIana = 0 ; @@ -3170,8 +3186,8 @@ ipmi_fru_edit_multirec(struct ipmi_intf * intf, uint8_t id , /* Default to PICMG for backward compatibility */ if( argc <=2 ) { - suppliedIana = IPMI_OEM_PICMG; - } else { + suppliedIana = IPMI_OEM_PICMG; + } else { if( !strncmp( argv[2] , "oem" , 3 )) { /* Expect IANA number next */ if( argc <= 3 ) { @@ -3189,17 +3205,17 @@ ipmi_fru_edit_multirec(struct ipmi_intf * intf, uint8_t id , if( iana == IPMI_OEM_PICMG ){ if( ipmi_fru_picmg_ext_edit(fru_data, - i + sizeof(struct fru_multirec_header), - h->len, h, oh )){ + i + sizeof(struct fru_multirec_header), + h->len, h, oh )){ /* The fru changed */ write_fru_area(intf,&fru,id, i,i, h->len+ sizeof(struct fru_multirec_header), fru_data); } } - else if( iana == IPMI_OEM_KONTRON ) { + else if( iana == IPMI_OEM_KONTRON ) { if( ipmi_fru_oemkontron_edit( argc,argv,fru_data, - i + sizeof(struct fru_multirec_header), - h->len, h, oh )){ + i + sizeof(struct fru_multirec_header), + h->len, h, oh )){ /* The fru changed */ write_fru_area(intf,&fru,id, i,i, h->len+ sizeof(struct fru_multirec_header), fru_data); @@ -3207,8 +3223,8 @@ ipmi_fru_edit_multirec(struct ipmi_intf * intf, uint8_t id , } /* FIXME: Add OEM record support here */ else{ - printf(" OEM IANA (%s) Record not support in this mode\n", - val2str( iana, ipmi_oem_info)); + printf(" OEM IANA (%s) Record not support in this mode\n", + val2str( iana, ipmi_oem_info)); error = 1; } } @@ -3221,18 +3237,18 @@ ipmi_fru_edit_multirec(struct ipmi_intf * intf, uint8_t id , return 0; } -/* ipmi_fru_get_multirec - Query new values to replace original FRU content - * - * @intf: interface to use - * @id: FRU id to work on - * - * returns: nothing - */ +/* ipmi_fru_get_multirec - Query new values to replace original FRU content +* +* @intf: interface to use +* @id: FRU id to work on +* +* returns: nothing +*/ /* Work in progress, copy paste most of the stuff for other functions in this file ... not elegant yet */ static int ipmi_fru_get_multirec(struct ipmi_intf * intf, uint8_t id , - int argc, char ** argv) + int argc, char ** argv) { struct ipmi_rs * rsp; @@ -3246,11 +3262,11 @@ ipmi_fru_get_multirec(struct ipmi_intf * intf, uint8_t id , uint32_t fruMultiRecSize = 0; struct fru_info fruInfo; retStatus = ipmi_fru_get_multirec_location_from_fru(intf, id, &fruInfo, - &offFruMultiRec, - &fruMultiRecSize); + &offFruMultiRec, + &fruMultiRecSize); - lprintf(LOG_DEBUG, "FRU Size : %lu\n", fruMultiRecSize); + lprintf(LOG_DEBUG, "FRU Size : %lu\n", fruMultiRecSize); lprintf(LOG_DEBUG, "Multi Rec offset: %lu\n", offFruMultiRec); { @@ -3260,8 +3276,8 @@ ipmi_fru_get_multirec(struct ipmi_intf * intf, uint8_t id , memset(&header, 0, sizeof(struct fru_header)); /* - * get info about this FRU - */ + * get info about this FRU + */ memset(msg_data, 0, 4); msg_data[0] = id; @@ -3327,10 +3343,10 @@ ipmi_fru_get_multirec(struct ipmi_intf * intf, uint8_t id , last_off += len; } - if( h->type == FRU_RECORD_TYPE_OEM_EXTENSION ){ + if( h->type == FRU_RECORD_TYPE_OEM_EXTENSION ){ struct fru_multirec_oem_header *oh=(struct fru_multirec_oem_header *) - &fru_data[i + sizeof(struct fru_multirec_header)]; + &fru_data[i + sizeof(struct fru_multirec_header)]; uint32_t iana = oh->mfg_id[0] | oh->mfg_id[1]<<8 | oh->mfg_id[2]<<16; uint32_t suppliedIana = 0 ; @@ -3351,13 +3367,13 @@ ipmi_fru_get_multirec(struct ipmi_intf * intf, uint8_t id , if( iana == IPMI_OEM_KONTRON ) { ipmi_fru_oemkontron_get( argc,argv,fru_data, - i + sizeof(struct fru_multirec_header), - h->len, h, oh ); + i + sizeof(struct fru_multirec_header), + h->len, h, oh ); } /* FIXME: Add OEM record support here */ else{ - printf(" OEM IANA (%s) Record not supported in this mode\n", - val2str( iana, ipmi_oem_info)); + printf(" OEM IANA (%s) Record not supported in this mode\n", + val2str( iana, ipmi_oem_info)); error = 1; } } @@ -3370,11 +3386,10 @@ ipmi_fru_get_multirec(struct ipmi_intf * intf, uint8_t id , return 0; } - static int ipmi_fru_upg_ekeying(struct ipmi_intf * intf, - char * pFileName, - uint8_t fruId) + char * pFileName, + uint8_t fruId) { uint16_t retStatus = 0; uint32_t offFruMultiRec; @@ -3384,26 +3399,26 @@ ipmi_fru_upg_ekeying(struct ipmi_intf * intf, struct fru_info fruInfo; uint8_t *buf = NULL; retStatus = ipmi_fru_get_multirec_location_from_fru(intf, fruId, &fruInfo, - &offFruMultiRec, - &fruMultiRecSize); + &offFruMultiRec, + &fruMultiRecSize); - lprintf(LOG_DEBUG, "FRU Size : %lu\n", fruMultiRecSize); + lprintf(LOG_DEBUG, "FRU Size : %lu\n", fruMultiRecSize); lprintf(LOG_DEBUG, "Multi Rec offset: %lu\n", offFruMultiRec); if (retStatus == 0) { retStatus = - ipmi_fru_get_multirec_size_from_file(pFileName, - &fileMultiRecSize, - &offFileMultiRec); + ipmi_fru_get_multirec_size_from_file(pFileName, + &fileMultiRecSize, + &offFileMultiRec); } if (retStatus == 0) { buf = malloc(fileMultiRecSize); if (buf) { retStatus = - ipmi_fru_get_multirec_from_file(pFileName, buf, - fileMultiRecSize, - offFileMultiRec); + ipmi_fru_get_multirec_from_file(pFileName, buf, + fileMultiRecSize, + offFileMultiRec); } else { printf("Error allocating memory for multirec buffer\n"); @@ -3416,7 +3431,7 @@ ipmi_fru_upg_ekeying(struct ipmi_intf * intf, ipmi_fru_get_adjust_size_from_buffer(buf, &fileMultiRecSize); if (buf) write_fru_area(intf, &fruInfo, fruId, 0, offFruMultiRec, - fileMultiRecSize, buf); + fileMultiRecSize, buf); } if(retStatus == 0 ) @@ -3432,8 +3447,8 @@ ipmi_fru_upg_ekeying(struct ipmi_intf * intf, static int ipmi_fru_get_multirec_size_from_file(char * pFileName, - uint32_t * pSize, - uint32_t * pOffset) + uint32_t * pSize, + uint32_t * pOffset) { struct fru_header header; FILE * pFile; @@ -3473,11 +3488,11 @@ ipmi_fru_get_multirec_size_from_file(char * pFileName, end = (header.offset.chassis * 8); if (((header.offset.board * 8) > (header.offset.board * 8)) && - ((header.offset.board * 8) < end)) + ((header.offset.board * 8) < end)) end = (header.offset.board * 8); if (((header.offset.product * 8) > (header.offset.product * 8)) && - ((header.offset.product * 8) < end)) + ((header.offset.product * 8) < end)) end = (header.offset.product * 8); *pSize = end - (header.offset.multi * 8); @@ -3488,7 +3503,7 @@ ipmi_fru_get_multirec_size_from_file(char * pFileName, static void ipmi_fru_get_adjust_size_from_buffer(uint8_t * fru_data, - uint32_t *pSize) + uint32_t *pSize) { struct fru_multirec_header * head; #define CHUNK_SIZE (255 + sizeof(struct fru_multirec_header)) @@ -3504,7 +3519,7 @@ ipmi_fru_get_adjust_size_from_buffer(uint8_t * fru_data, if(verbose ) printf("Adding ("); - for (counter = 0; counter < sizeof(struct fru_multirec_header); counter++) { + for (counter = 0; counter < sizeof(struct fru_multirec_header); counter++) { if(verbose ) printf(" %02X", *(fru_data + count + counter)); checksum += *(fru_data + count + counter); @@ -3523,7 +3538,7 @@ ipmi_fru_get_adjust_size_from_buffer(uint8_t * fru_data, if (verbose > 1 && checksum == 0) { for(counter = 0; counter < head->len; counter++) { printf(" %02X", *(fru_data + count + counter + - sizeof(struct fru_multirec_header))); + sizeof(struct fru_multirec_header))); } } if(verbose ) @@ -3597,7 +3612,7 @@ ipmi_fru_get_multirec_location_from_fru(struct ipmi_intf * intf, if (rsp->ccode == 0xc3) printf (" Timeout accessing FRU info. (Device not present?)\n"); else - printf (" CCODE = 0x%02x\n", rsp->ccode); + printf (" CCODE = 0x%02x\n", rsp->ccode); return -1; } pFruInfo->size = (rsp->data[1] << 8) | rsp->data[0]; @@ -3605,7 +3620,7 @@ ipmi_fru_get_multirec_location_from_fru(struct ipmi_intf * intf, if (verbose > 1) printf("pFruInfo->size = %d bytes (accessed by %s)\n", - pFruInfo->size, pFruInfo->access ? "words" : "bytes"); + pFruInfo->size, pFruInfo->access ? "words" : "bytes"); if (!pFruInfo->size) return -1; @@ -3645,19 +3660,19 @@ ipmi_fru_get_multirec_location_from_fru(struct ipmi_intf * intf, /* Retreive length */ if (((header.offset.internal * 8) > (header.offset.internal * 8)) && - ((header.offset.internal * 8) < end)) + ((header.offset.internal * 8) < end)) end = (header.offset.internal * 8); if (((header.offset.chassis * 8) > (header.offset.chassis * 8)) && - ((header.offset.chassis * 8) < end)) + ((header.offset.chassis * 8) < end)) end = (header.offset.chassis * 8); if (((header.offset.board * 8) > (header.offset.board * 8)) && - ((header.offset.board * 8) < end)) + ((header.offset.board * 8) < end)) end = (header.offset.board * 8); if (((header.offset.product * 8) > (header.offset.product * 8)) && - ((header.offset.product * 8) < end)) + ((header.offset.product * 8) < end)) end = (header.offset.product * 8); *pRetSize = end; @@ -3666,38 +3681,37 @@ ipmi_fru_get_multirec_location_from_fru(struct ipmi_intf * intf, return 0; } - -/* ipmi_fru_get_internal_use_offset - Retreive internal use offset - * - * @intf: ipmi interface - * @id: fru id - * - * returns -1 on error - * returns 0 if successful - * returns 1 if device not present - */ +/* ipmi_fru_get_internal_use_offset - Retreive internal use offset +* +* @intf: ipmi interface +* @id: fru id +* +* returns -1 on error +* returns 0 if successful +* returns 1 if device not present +*/ static int -ipmi_fru_get_internal_use_info( struct ipmi_intf * intf, - uint8_t id, - struct fru_info * fru, - uint16_t * size, - uint16_t * offset) +ipmi_fru_get_internal_use_info( struct ipmi_intf * intf, + uint8_t id, + struct fru_info * fru, + uint16_t * size, + uint16_t * offset) { struct ipmi_rs * rsp; struct ipmi_rq req; struct fru_header header; uint8_t msg_data[4]; - // Init output value - * offset = 0; - * size = 0; + // Init output value + * offset = 0; + * size = 0; memset(fru, 0, sizeof(struct fru_info)); memset(&header, 0, sizeof(struct fru_header)); /* - * get info about this FRU - */ + * get info about this FRU + */ memset(msg_data, 0, 4); msg_data[0] = id; @@ -3730,8 +3744,8 @@ ipmi_fru_get_internal_use_info( struct ipmi_intf * intf, } /* - * retrieve the FRU header - */ + * retrieve the FRU header + */ msg_data[0] = id; msg_data[1] = 0; msg_data[2] = 0; @@ -3750,7 +3764,7 @@ ipmi_fru_get_internal_use_info( struct ipmi_intf * intf, } if (rsp->ccode > 0) { printf(" Device not present (%s)\n", - val2str(rsp->ccode, completion_code_vals)); + val2str(rsp->ccode, completion_code_vals)); return 1; } @@ -3765,249 +3779,244 @@ ipmi_fru_get_internal_use_info( struct ipmi_intf * intf, return -1; } - - lprintf(LOG_DEBUG, "fru.header.version: 0x%x", + lprintf(LOG_DEBUG, "fru.header.version: 0x%x", header.version); lprintf(LOG_DEBUG, "fru.header.offset.internal: 0x%x", header.offset.internal * 8); - lprintf(LOG_DEBUG, "fru.header.offset.chassis: 0x%x", + lprintf(LOG_DEBUG, "fru.header.offset.chassis: 0x%x", header.offset.chassis * 8); - lprintf(LOG_DEBUG, "fru.header.offset.board: 0x%x", + lprintf(LOG_DEBUG, "fru.header.offset.board: 0x%x", header.offset.board * 8); - lprintf(LOG_DEBUG, "fru.header.offset.product: 0x%x", + lprintf(LOG_DEBUG, "fru.header.offset.product: 0x%x", header.offset.product * 8); - lprintf(LOG_DEBUG, "fru.header.offset.multi: 0x%x", + lprintf(LOG_DEBUG, "fru.header.offset.multi: 0x%x", header.offset.multi * 8); - if((header.offset.internal*8) == 0) - { - * size = 0; - * offset = 0; - } - else - { - (* offset) = (header.offset.internal*8); + if((header.offset.internal*8) == 0) + { + * size = 0; + * offset = 0; + } + else + { + (* offset) = (header.offset.internal*8); - if(header.offset.chassis != 0) - { - (* size) = ((header.offset.chassis*8)-(* offset)); - } - else if(header.offset.board != 0) - { - (* size) = ((header.offset.board*8)-(* offset)); - } - else if(header.offset.product != 0) - { - (* size) = ((header.offset.product*8)-(* offset)); - } - else if(header.offset.multi != 0) - { - (* size) = ((header.offset.multi*8)-(* offset)); - } - else - { - (* size) = (fru->size - (* offset)); - } - } - return 0; + if(header.offset.chassis != 0) + { + (* size) = ((header.offset.chassis*8)-(* offset)); + } + else if(header.offset.board != 0) + { + (* size) = ((header.offset.board*8)-(* offset)); + } + else if(header.offset.product != 0) + { + (* size) = ((header.offset.product*8)-(* offset)); + } + else if(header.offset.multi != 0) + { + (* size) = ((header.offset.multi*8)-(* offset)); + } + else + { + (* size) = (fru->size - (* offset)); + } + } + return 0; } - -/* ipmi_fru_info_internal_use - print internal use info - * - * @intf: ipmi interface - * @id: fru id - * - * returns -1 on error - * returns 0 if successful - * returns 1 if device not present - */ +/* ipmi_fru_info_internal_use - print internal use info +* +* @intf: ipmi interface +* @id: fru id +* +* returns -1 on error +* returns 0 if successful +* returns 1 if device not present +*/ static int ipmi_fru_info_internal_use(struct ipmi_intf * intf, uint8_t id) { - struct fru_info fru; - uint16_t size; - uint16_t offset; - int rc = 0; + struct fru_info fru; + uint16_t size; + uint16_t offset; + int rc = 0; - rc = ipmi_fru_get_internal_use_info(intf, id, &fru, &size, &offset); + rc = ipmi_fru_get_internal_use_info(intf, id, &fru, &size, &offset); - if(rc == 0) - { - lprintf(LOG_DEBUG, "Internal Use Area Offset: %i", offset); - printf( "Internal Use Area Size : %i\n", size); - } - else - { + if(rc == 0) + { + lprintf(LOG_DEBUG, "Internal Use Area Offset: %i", offset); + printf( "Internal Use Area Size : %i\n", size); + } + else + { lprintf(LOG_ERR, "Cannot access internal use area"); - return -1; - } - return 0; + return -1; + } + return 0; } - -/* ipmi_fru_read_internal_use - print internal use are in hex or file - * - * @intf: ipmi interface - * @id: fru id - * - * returns -1 on error - * returns 0 if successful - * returns 1 if device not present - */ +/* ipmi_fru_read_internal_use - print internal use are in hex or file +* +* @intf: ipmi interface +* @id: fru id +* +* returns -1 on error +* returns 0 if successful +* returns 1 if device not present +*/ static int ipmi_fru_read_internal_use(struct ipmi_intf * intf, uint8_t id, char * pFileName) { - struct fru_info fru; - uint16_t size; - uint16_t offset; - int rc = 0; + struct fru_info fru; + uint16_t size; + uint16_t offset; + int rc = 0; - rc = ipmi_fru_get_internal_use_info(intf, id, &fru, &size, &offset); + rc = ipmi_fru_get_internal_use_info(intf, id, &fru, &size, &offset); - if(rc == 0) - { - uint8_t * frubuf; + if(rc == 0) + { + uint8_t * frubuf; - lprintf(LOG_DEBUG, "Internal Use Area Offset: %i", offset); - printf( "Internal Use Area Size : %i\n", size); + lprintf(LOG_DEBUG, "Internal Use Area Offset: %i", offset); + printf( "Internal Use Area Size : %i\n", size); - frubuf = malloc( size ); - if(frubuf) - { - rc = read_fru_area_section(intf, &fru, id, offset, size, frubuf); + frubuf = malloc( size ); + if(frubuf) + { + rc = read_fru_area_section(intf, &fru, id, offset, size, frubuf); - if(rc == 0) - { - if(pFileName == NULL) - { - uint16_t counter; - for(counter = 0; counter < size; counter ++) - { - if((counter % 16) == 0) - printf("\n%02i- ", (counter / 16)); - printf("%02X ", frubuf[counter]); - } - } - else - { - FILE * pFile; - pFile = fopen(pFileName,"wb"); - if (pFile) - { - fwrite(frubuf, size, 1, pFile); - printf("Done\n"); - } - else - { - lprintf(LOG_ERR, "Error opening file %s\n", pFileName); - free(frubuf); - return -1; - } - fclose(pFile); - } - } - printf("\n"); + if(rc == 0) + { + if(pFileName == NULL) + { + uint16_t counter; + for(counter = 0; counter < size; counter ++) + { + if((counter % 16) == 0) + printf("\n%02i- ", (counter / 16)); + printf("%02X ", frubuf[counter]); + } + } + else + { + FILE * pFile; + pFile = fopen(pFileName,"wb"); + if (pFile) + { + fwrite(frubuf, size, 1, pFile); + printf("Done\n"); + } + else + { + lprintf(LOG_ERR, "Error opening file %s\n", pFileName); + free(frubuf); + return -1; + } + fclose(pFile); + } + } + printf("\n"); - free(frubuf); - } + free(frubuf); + } - } - else - { + } + else + { lprintf(LOG_ERR, "Cannot access internal use area"); - } - return 0; + } + return 0; } -/* ipmi_fru_write_internal_use - print internal use are in hex or file - * - * @intf: ipmi interface - * @id: fru id - * - * returns -1 on error - * returns 0 if successful - * returns 1 if device not present - */ +/* ipmi_fru_write_internal_use - print internal use are in hex or file +* +* @intf: ipmi interface +* @id: fru id +* +* returns -1 on error +* returns 0 if successful +* returns 1 if device not present +*/ static int ipmi_fru_write_internal_use(struct ipmi_intf * intf, uint8_t id, char * pFileName) { - struct fru_info fru; - uint16_t size; - uint16_t offset; - int rc = 0; + struct fru_info fru; + uint16_t size; + uint16_t offset; + int rc = 0; - rc = ipmi_fru_get_internal_use_info(intf, id, &fru, &size, &offset); + rc = ipmi_fru_get_internal_use_info(intf, id, &fru, &size, &offset); - if(rc == 0) - { - uint8_t * frubuf; - FILE * fp; - uint32_t fileLength = 0; + if(rc == 0) + { + uint8_t * frubuf; + FILE * fp; + uint32_t fileLength = 0; - lprintf(LOG_DEBUG, "Internal Use Area Offset: %i", offset); - printf( "Internal Use Area Size : %i\n", size); + lprintf(LOG_DEBUG, "Internal Use Area Offset: %i", offset); + printf( "Internal Use Area Size : %i\n", size); - fp = fopen(pFileName, "r"); + fp = fopen(pFileName, "r"); - if(fp) - { - /* Retreive file length, check if it's fits the Eeprom Size */ - fseek(fp, 0 ,SEEK_END); - fileLength = ftell(fp); + if(fp) + { + /* Retreive file length, check if it's fits the Eeprom Size */ + fseek(fp, 0 ,SEEK_END); + fileLength = ftell(fp); - lprintf(LOG_ERR, "File Size: %i", fileLength); - lprintf(LOG_ERR, "Area Size: %i", size); - if(fileLength != size) - { - lprintf(LOG_ERR, "File size does not fit Eeprom Size"); - fclose(fp); - fp = NULL; - } - else - { - fseek(fp, 0 ,SEEK_SET); - } - } + lprintf(LOG_ERR, "File Size: %i", fileLength); + lprintf(LOG_ERR, "Area Size: %i", size); + if(fileLength != size) + { + lprintf(LOG_ERR, "File size does not fit Eeprom Size"); + fclose(fp); + fp = NULL; + } + else + { + fseek(fp, 0 ,SEEK_SET); + } + } - if(fp) - { - frubuf = malloc( size ); - if(frubuf) - { - uint16_t fru_read_size; - fru_read_size = fread(frubuf, 1, size, fp); + if(fp) + { + frubuf = malloc( size ); + if(frubuf) + { + uint16_t fru_read_size; + fru_read_size = fread(frubuf, 1, size, fp); - if(fru_read_size == size) - { - rc = write_fru_area(intf, &fru, id, 0, offset, size, frubuf); + if(fru_read_size == size) + { + rc = write_fru_area(intf, &fru, id, 0, offset, size, frubuf); - if(rc == 0) - { - lprintf(LOG_INFO, "Done\n"); - } - } - else - { - lprintf(LOG_ERR, "Unable to read file: %i\n", fru_read_size); - } + if(rc == 0) + { + lprintf(LOG_INFO, "Done\n"); + } + } + else + { + lprintf(LOG_ERR, "Unable to read file: %i\n", fru_read_size); + } - free(frubuf); - } - fclose(fp); - fp = NULL; - } - } - else - { + free(frubuf); + } + fclose(fp); + fp = NULL; + } + } + else + { lprintf(LOG_ERR, "Cannot access internal use area"); - } - return 0; + } + return 0; } - - int ipmi_fru_main(struct ipmi_intf * intf, int argc, char ** argv) { @@ -4017,10 +4026,10 @@ ipmi_fru_main(struct ipmi_intf * intf, int argc, char ** argv) rc = ipmi_fru_print_all(intf); } else if (strncmp(argv[0], "help", 4) == 0) { - lprintf(LOG_ERR, "FRU Commands: print read write upgEkey edit internaluse"); + lprintf(LOG_ERR, "FRU Commands: print read write upgEkey edit internaluse"); } else if (strncmp(argv[0], "print", 5) == 0 || - strncmp(argv[0], "list", 4) == 0) { + strncmp(argv[0], "list", 4) == 0) { if (argc > 1) { rc = __ipmi_fru_print(intf, strtol(argv[1], NULL, 0)); } else { @@ -4036,8 +4045,8 @@ ipmi_fru_main(struct ipmi_intf * intf, int argc, char ** argv) fruId = atoi(argv[1]); strcpy(fileName, argv[2]); if (verbose){ - printf("Fru Id : %d\n", fruId); - printf("Fru File : %s\n", fileName); + printf("Fru Id : %d\n", fruId); + printf("Fru File : %s\n", fileName); } ipmi_fru_read_to_bin(intf, fileName, fruId); } @@ -4058,8 +4067,8 @@ ipmi_fru_main(struct ipmi_intf * intf, int argc, char ** argv) fruId = atoi(argv[1]); strcpy(fileName, argv[2]); if (verbose) { - printf("Fru Id : %d\n", fruId); - printf("Fru File : %s\n", fileName); + printf("Fru Id : %d\n", fruId); + printf("Fru File : %s\n", fileName); } ipmi_fru_write_from_bin(intf, fileName, fruId); } else { @@ -4080,49 +4089,49 @@ ipmi_fru_main(struct ipmi_intf * intf, int argc, char ** argv) } else if (!strncmp(argv[0], "internaluse", 11)) { - if ( - (argc >= 3) - && - (!strncmp(argv[2], "info", 4)) - ) - { - ipmi_fru_info_internal_use(intf, atoi(argv[1])); - } - else if ( - (argc >= 3) - && - (!strncmp(argv[2], "print", 5)) - ) - { - ipmi_fru_read_internal_use(intf, atoi(argv[1]), NULL); - } + if ( + (argc >= 3) + && + (!strncmp(argv[2], "info", 4)) + ) + { + ipmi_fru_info_internal_use(intf, atoi(argv[1])); + } else if ( - (argc >= 4) - && - (!strncmp(argv[2], "read", 4)) - && - (strlen(argv[3]) > 0) - ) - { - strcpy(fileName, argv[3]); - lprintf(LOG_DEBUG, "Fru Id : %d", atoi(argv[1])); - lprintf(LOG_DEBUG, "Fru File : %s", fileName); - ipmi_fru_read_internal_use(intf, atoi(argv[1]), fileName); - } + (argc >= 3) + && + (!strncmp(argv[2], "print", 5)) + ) + { + ipmi_fru_read_internal_use(intf, atoi(argv[1]), NULL); + } else if ( - (argc >= 4) - && - (!strncmp(argv[2], "write", 5)) - && - (strlen(argv[3]) > 0) - ) - { + (argc >= 4) + && + (!strncmp(argv[2], "read", 4)) + && + (strlen(argv[3]) > 0) + ) + { strcpy(fileName, argv[3]); - lprintf(LOG_DEBUG, "Fru Id : %d", atoi(argv[1])); - lprintf(LOG_DEBUG, "Fru File : %s", fileName); - ipmi_fru_write_internal_use(intf, atoi(argv[1]), fileName); - } - else + lprintf(LOG_DEBUG, "Fru Id : %d", atoi(argv[1])); + lprintf(LOG_DEBUG, "Fru File : %s", fileName); + ipmi_fru_read_internal_use(intf, atoi(argv[1]), fileName); + } + else if ( + (argc >= 4) + && + (!strncmp(argv[2], "write", 5)) + && + (strlen(argv[3]) > 0) + ) + { + strcpy(fileName, argv[3]); + lprintf(LOG_DEBUG, "Fru Id : %d", atoi(argv[1])); + lprintf(LOG_DEBUG, "Fru File : %s", fileName); + ipmi_fru_write_internal_use(intf, atoi(argv[1]), fileName); + } + else { printf("fru internaluse info - get internal use area size\n"); printf("fru internaluse print - print internal use area in hex\n"); @@ -4136,38 +4145,38 @@ ipmi_fru_main(struct ipmi_intf * intf, int argc, char ** argv) if ((argc >= 2) && (strncmp(argv[1], "help", 4) == 0)) { lprintf(LOG_ERR, "edit commands:"); lprintf(LOG_ERR, " edit - interactively edit records"); - lprintf(LOG_ERR, + lprintf(LOG_ERR, " edit field
- edit FRU string"); - lprintf(LOG_ERR, + lprintf(LOG_ERR, " edit oem iana - limited OEM support"); } else { - uint8_t fruId = 0; + uint8_t fruId = 0; - if ((argc >= 2) && (strlen(argv[1]) > 0)) { - fruId = atoi(argv[1]); - if (verbose) { - printf("Fru Id : %d\n", fruId); + if ((argc >= 2) && (strlen(argv[1]) > 0)) { + fruId = atoi(argv[1]); + if (verbose) { + printf("Fru Id : %d\n", fruId); + } + } else { + printf("Using default FRU id: %d\n", fruId); } - } else { - printf("Using default FRU id: %d\n", fruId); - } - if ((argc >= 3) && (strlen(argv[1]) > 0)) { - if (!strncmp(argv[2], "field", 5)){ - if (argc == 6) { - ipmi_fru_set_field_string(intf, fruId,\ - *argv[3], *argv[4], (char *) argv[5]); + if ((argc >= 3) && (strlen(argv[1]) > 0)) { + if (!strncmp(argv[2], "field", 5)){ + if (argc == 6) { + ipmi_fru_set_field_string(intf, fruId,\ + *argv[3], *argv[4], (char *) argv[5]); + } + else { + printf("fru edit [fruid] field [section] [index] [string]\n"); + } + }else if (!strncmp(argv[2], "oem", 3)){ + ipmi_fru_edit_multirec(intf,fruId, argc, argv); } - else { - printf("fru edit [fruid] field [section] [index] [string]\n"); - } - }else if (!strncmp(argv[2], "oem", 3)){ + } else { ipmi_fru_edit_multirec(intf,fruId, argc, argv); } - } else { - ipmi_fru_edit_multirec(intf,fruId, argc, argv); - } } } @@ -4185,7 +4194,7 @@ ipmi_fru_main(struct ipmi_intf * intf, int argc, char ** argv) if ((argc >= 2) && (strlen(argv[1]) > 0)) { fruId = atoi(argv[1]); if (verbose) { - printf("Fru Id : %d\n", fruId); + printf("Fru Id : %d\n", fruId); } } else { printf("Using default FRU id: %d\n", fruId); @@ -4203,25 +4212,26 @@ ipmi_fru_main(struct ipmi_intf * intf, int argc, char ** argv) } else { lprintf(LOG_ERR, "Invalid FRU command: %s", argv[0]); - lprintf(LOG_ERR, "FRU Commands: print read write upgEkey edit"); + lprintf(LOG_ERR, "FRU Commands: print read write upgEkey edit"); rc = -1; } return rc; } + /* ipmi_fru_set_field_string - Set a field string to a new value, Need to be the same size. If - * size if not equal, the function ipmi_fru_set_field_string_rebuild - * will be called. - * - * @intf: ipmi interface - * @id: fru id - * @f_type: Type of the Field : c=Chassis b=Board p=Product - * @f_index: findex of the field, zero indexed. - * @f_string: NULL terminated string - * - * returns -1 on error - * returns 1 if successful - */ +* size if not equal, the function ipmi_fru_set_field_string_rebuild +* will be called. +* +* @intf: ipmi interface +* @id: fru id +* @f_type: Type of the Field : c=Chassis b=Board p=Product +* @f_index: findex of the field, zero indexed. +* @f_string: NULL terminated string +* +* returns -1 on error +* returns 1 if successful +*/ static int ipmi_fru_set_field_string(struct ipmi_intf * intf, uint8_t fruId, uint8_t f_type, uint8_t f_index, char *f_string) @@ -4234,7 +4244,7 @@ f_type, uint8_t f_index, char *f_string) uint8_t msg_data[4]; uint8_t checksum; int i = 0; - uint8_t *fru_data, *fru_area = NULL; + uint8_t *fru_data, *fru_area = NULL; uint32_t fru_field_offset, fru_field_offset_tmp; uint32_t fru_section_len, header_offset; @@ -4260,7 +4270,7 @@ f_type, uint8_t f_index, char *f_string) return(-1); } - fru.size = (rsp->data[1] << 8) | rsp->data[0]; + fru.size = (rsp->data[1] << 8) | rsp->data[0]; fru.access = rsp->data[2] & 0x1; if (fru.size < 1) { @@ -4268,8 +4278,8 @@ f_type, uint8_t f_index, char *f_string) return -1; } /* - * retrieve the FRU header - */ + * retrieve the FRU header + */ msg_data[0] = fruId; msg_data[1] = 0; msg_data[2] = 0; @@ -4290,7 +4300,7 @@ f_type, uint8_t f_index, char *f_string) if (rsp->ccode > 0) { printf(" Device not present (%s)\n", - val2str(rsp->ccode, completion_code_vals)); + val2str(rsp->ccode, completion_code_vals)); return(-1); } @@ -4366,78 +4376,78 @@ f_type, uint8_t f_index, char *f_string) if ( strlen((const char *)fru_area) == strlen((const char *)f_string) ) { - printf("Updating Field '%s' with '%s' ...\n", fru_area, f_string ); - memcpy(fru_data + fru_field_offset_tmp + 1, - f_string, strlen(f_string)); + printf("Updating Field '%s' with '%s' ...\n", fru_area, f_string ); + memcpy(fru_data + fru_field_offset_tmp + 1, + f_string, strlen(f_string)); - checksum = 0; - /* Calculate Header Checksum */ - for( i = header_offset; i < header_offset - + fru_section_len - 1; i ++ ) - { - checksum += fru_data[i]; - } - checksum = (~checksum) + 1; - fru_data[header_offset + fru_section_len - 1] = checksum; + checksum = 0; + /* Calculate Header Checksum */ + for( i = header_offset; i < header_offset + + fru_section_len - 1; i ++ ) + { + checksum += fru_data[i]; + } + checksum = (~checksum) + 1; + fru_data[header_offset + fru_section_len - 1] = checksum; - /* Write the updated section to the FRU data */ - if( write_fru_area(intf, &fru, fruId, header_offset, - header_offset, fru_section_len, fru_data) < 0 ) - { - printf("Write to FRU data failed.\n"); - free(fru_data); - return -1; - } + /* Write the updated section to the FRU data */ + if( write_fru_area(intf, &fru, fruId, header_offset, + header_offset, fru_section_len, fru_data) < 0 ) + { + printf("Write to FRU data failed.\n"); + free(fru_data); + return -1; + } } else { - free(fru_data); /* Free data, will be rebuild in function */ + free(fru_data); /* Free data, will be rebuild in function */ - printf("String size are not equal, resizing fru to fit new string\n"); + printf("String size are not equal, resizing fru to fit new string\n"); - if( - ipmi_fru_set_field_string_rebuild(intf,fruId,fru,header,f_type,f_index,f_string) - ) - { - return -1; - } + if( + ipmi_fru_set_field_string_rebuild(intf,fruId,fru,header,f_type,f_index,f_string) + ) + { + return -1; + } } free(fru_data); return 1; } -/* - This function can update a string within of the following section when the size is not equal: - - Chassis - Product - Board +/* + This function can update a string within of the following section when the size is not equal: + + Chassis + Product + Board */ /* ipmi_fru_set_field_string_rebuild - Set a field string to a new value, When size are not - * the same size. - * - * This function can update a string within of the following section when the size is not equal: - * - * - Chassis - * - Product - * - Board - * - * @intf: ipmi interface - * @fruId: fru id - * @fru: info about fru - * @header: contain the header of the FRU - * @f_type: Type of the Field : c=Chassis b=Board p=Product - * @f_index: findex of the field, zero indexed. - * @f_string: NULL terminated string - * - * returns -1 on error - * returns 1 if successful - */ - +* the same size. +* +* This function can update a string within of the following section when the size is not equal: +* +* - Chassis +* - Product +* - Board +* +* @intf: ipmi interface +* @fruId: fru id +* @fru: info about fru +* @header: contain the header of the FRU +* @f_type: Type of the Field : c=Chassis b=Board p=Product +* @f_index: findex of the field, zero indexed. +* @f_string: NULL terminated string +* +* returns -1 on error +* returns 1 if successful +*/ + #define DBG_RESIZE_FRU static int -ipmi_fru_set_field_string_rebuild(struct ipmi_intf * intf, uint8_t fruId, - struct fru_info fru, struct fru_header header, - uint8_t f_type, uint8_t f_index, char *f_string) +ipmi_fru_set_field_string_rebuild(struct ipmi_intf * intf, uint8_t fruId, + struct fru_info fru, struct fru_header header, + uint8_t f_type, uint8_t f_index, char *f_string) { struct ipmi_rs *rsp; struct ipmi_rq req; @@ -4445,18 +4455,18 @@ ipmi_fru_set_field_string_rebuild(struct ipmi_intf * intf, uint8_t fruId, uint8_t msg_data[4]; uint8_t checksum; int i = 0; - uint8_t *fru_data_old, *fru_data_new, *fru_area = NULL; + uint8_t *fru_data_old, *fru_data_new, *fru_area = NULL; uint32_t fru_field_offset, fru_field_offset_tmp; uint32_t fru_section_len, old_section_len, header_offset; - uint32_t chassis_offset, board_offset, product_offset; - uint32_t chassis_len, board_len, product_len, product_len_new; - int num_byte_change = 0, padding_len = 0; - uint32_t counter; - unsigned char cksum; + uint32_t chassis_offset, board_offset, product_offset; + uint32_t chassis_len, board_len, product_len, product_len_new; + int num_byte_change = 0, padding_len = 0; + uint32_t counter; + unsigned char cksum; fru_data_old = calloc( fru.size, sizeof(uint8_t) ); - fru_data_new = malloc( fru.size ); + fru_data_new = malloc( fru.size ); if( fru_data_old == NULL || fru_data_new == NULL ) { @@ -4464,69 +4474,69 @@ ipmi_fru_set_field_string_rebuild(struct ipmi_intf * intf, uint8_t fruId, return(-1); } - /************************* - 1) Read ALL FRU */ - printf("Read All FRU area\n"); - printf("Fru Size : %lu bytes\n", fru.size); + /************************* + 1) Read ALL FRU */ + printf("Read All FRU area\n"); + printf("Fru Size : %lu bytes\n", fru.size); - /* Read current fru data */ - read_fru_area(intf ,&fru, fruId, 0, fru.size , fru_data_old); + /* Read current fru data */ + read_fru_area(intf ,&fru, fruId, 0, fru.size , fru_data_old); - #ifdef DBG_RESIZE_FRU - printf("Copy to new FRU\n"); - #endif + #ifdef DBG_RESIZE_FRU + printf("Copy to new FRU\n"); + #endif - /************************* - 2) Copy all FRU to new FRU */ - memcpy(fru_data_new, fru_data_old, fru.size); + /************************* + 2) Copy all FRU to new FRU */ + memcpy(fru_data_new, fru_data_old, fru.size); - /* Build location of all modifiable components */ - chassis_offset = (header.offset.chassis * 8); - board_offset = (header.offset.board * 8); - product_offset = (header.offset.product * 8); + /* Build location of all modifiable components */ + chassis_offset = (header.offset.chassis * 8); + board_offset = (header.offset.board * 8); + product_offset = (header.offset.product * 8); - /* Retrieve length of all modifiable components */ - chassis_len = *(fru_data_old + chassis_offset + 1) * 8; - board_len = *(fru_data_old + board_offset + 1) * 8; - product_len = *(fru_data_old + product_offset + 1) * 8; - product_len_new = product_len; + /* Retrieve length of all modifiable components */ + chassis_len = *(fru_data_old + chassis_offset + 1) * 8; + board_len = *(fru_data_old + board_offset + 1) * 8; + product_len = *(fru_data_old + product_offset + 1) * 8; + product_len_new = product_len; - /* Chassis type field */ - if (f_type == 'c' ) - { + /* Chassis type field */ + if (f_type == 'c' ) + { header_offset = chassis_offset; fru_field_offset = chassis_offset + 3; fru_section_len = chassis_len; } /* Board type field */ - else if (f_type == 'b' ) - { + else if (f_type == 'b' ) + { header_offset = board_offset; fru_field_offset = board_offset + 6; fru_section_len = board_len; } /* Product type field */ - else if (f_type == 'p' ) - { + else if (f_type == 'p' ) + { header_offset = product_offset; fru_field_offset = product_offset + 3; fru_section_len = product_len; } else { - printf("Wrong field type."); + printf("Wrong field type."); return -1; } - /* Keep length for future old section display */ - old_section_len = fru_section_len; + /* Keep length for future old section display */ + old_section_len = fru_section_len; - /************************* - 3) Seek to field index */ + /************************* + 3) Seek to field index */ for( i=0; i<=f_index; i++ ) { fru_field_offset_tmp = fru_field_offset; - fru_area = (uint8_t *) get_fru_area_str(fru_data_old, &fru_field_offset); + fru_area = (uint8_t *) get_fru_area_str(fru_data_old, &fru_field_offset); } if( (fru_area == NULL ) || strlen((const char *)fru_area) == 0 ) { @@ -4534,254 +4544,253 @@ ipmi_fru_set_field_string_rebuild(struct ipmi_intf * intf, uint8_t fruId, return -1; } + #ifdef DBG_RESIZE_FRU + printf("Section Length: %lu\n", fru_section_len); + #endif - #ifdef DBG_RESIZE_FRU - printf("Section Length: %lu\n", fru_section_len); - #endif + /************************* + 4) Check number of padding bytes and bytes changed */ + for(counter = 2; counter < fru_section_len; counter ++) + { + if(*(fru_data_old + (header_offset + fru_section_len - counter)) == 0) + padding_len ++; + else + break; + } + num_byte_change = strlen(f_string) - strlen(fru_area); - /************************* - 4) Check number of padding bytes and bytes changed */ - for(counter = 2; counter < fru_section_len; counter ++) - { - if(*(fru_data_old + (header_offset + fru_section_len - counter)) == 0) - padding_len ++; - else - break; - } - num_byte_change = strlen(f_string) - strlen(fru_area); + #ifdef DBG_RESIZE_FRU + printf("Padding Length: %u\n", padding_len); + printf("NumByte Change: %i\n", num_byte_change); + printf("Start SecChnge: %x\n", *(fru_data_old + fru_field_offset_tmp)); + printf("End SecChnge : %x\n", *(fru_data_old + fru_field_offset_tmp + strlen(f_string) + 1)); - #ifdef DBG_RESIZE_FRU - printf("Padding Length: %u\n", padding_len); - printf("NumByte Change: %i\n", num_byte_change); - printf("Start SecChnge: %x\n", *(fru_data_old + fru_field_offset_tmp)); - printf("End SecChnge : %x\n", *(fru_data_old + fru_field_offset_tmp + strlen(f_string) + 1)); + printf("Start Section : %x\n", *(fru_data_old + header_offset)); + printf("End Sec wo Pad: %x\n", *(fru_data_old + header_offset + fru_section_len - 2 - padding_len)); + printf("End Section : %x\n", *(fru_data_old + header_offset + fru_section_len - 1)); + #endif - printf("Start Section : %x\n", *(fru_data_old + header_offset)); - printf("End Sec wo Pad: %x\n", *(fru_data_old + header_offset + fru_section_len - 2 - padding_len)); - printf("End Section : %x\n", *(fru_data_old + header_offset + fru_section_len - 1)); - #endif + /* Calculate New Padding Length */ + padding_len -= num_byte_change; - /* Calculate New Padding Length */ - padding_len -= num_byte_change; - - #ifdef DBG_RESIZE_FRU - printf("New Padding Length: %i\n", padding_len); - #endif + #ifdef DBG_RESIZE_FRU + printf("New Padding Length: %i\n", padding_len); + #endif - /************************* - 5) Check if section must be resize. This occur when padding length is not between 0 and 7 */ - if( (padding_len < 0) || (padding_len >= 8)) - { - uint32_t remaining_offset = ((header.offset.product * 8) + product_len); - int change_size_by_8; + /************************* + 5) Check if section must be resize. This occur when padding length is not between 0 and 7 */ + if( (padding_len < 0) || (padding_len >= 8)) + { + uint32_t remaining_offset = ((header.offset.product * 8) + product_len); + int change_size_by_8; - if(padding_len >= 8) - { - /* Section must be set smaller */ - change_size_by_8 = ((padding_len) / 8) * (-1); - } - else - { - /* Section must be set bigger */ - change_size_by_8 = 1 + (((padding_len+1) / 8) * (-1)); - } + if(padding_len >= 8) + { + /* Section must be set smaller */ + change_size_by_8 = ((padding_len) / 8) * (-1); + } + else + { + /* Section must be set bigger */ + change_size_by_8 = 1 + (((padding_len+1) / 8) * (-1)); + } - /* Recalculate padding and section length base on the section changes */ - fru_section_len += (change_size_by_8 * 8); - padding_len += (change_size_by_8 * 8); + /* Recalculate padding and section length base on the section changes */ + fru_section_len += (change_size_by_8 * 8); + padding_len += (change_size_by_8 * 8); - #ifdef DBG_RESIZE_FRU - printf("change_size_by_8: %i\n", change_size_by_8); - printf("New Padding Length: %i\n", padding_len); - printf("change_size_by_8: %i\n", change_size_by_8); - printf("header.offset.board: %i\n", header.offset.board); - #endif + #ifdef DBG_RESIZE_FRU + printf("change_size_by_8: %i\n", change_size_by_8); + printf("New Padding Length: %i\n", padding_len); + printf("change_size_by_8: %i\n", change_size_by_8); + printf("header.offset.board: %i\n", header.offset.board); + #endif - /* Must move sections */ - /* Section that can be modified are as follow - Chassis - Board - product */ + /* Must move sections */ + /* Section that can be modified are as follow + Chassis + Board + product */ - /* Chassis type field */ - if (f_type == 'c' ) - { - printf("Moving Section Chassis, from %i to %i\n", - ((header.offset.board) * 8), - ((header.offset.board + change_size_by_8) * 8) - ); - memcpy( - (fru_data_new + ((header.offset.board + change_size_by_8) * 8)), - (fru_data_old + (header.offset.board) * 8), - board_len - ); - header.offset.board += change_size_by_8; - } - /* Board type field */ - if ((f_type == 'c' ) || (f_type == 'b' )) - { - printf("Moving Section Product, from %i to %i\n", - ((header.offset.product) * 8), - ((header.offset.product + change_size_by_8) * 8) - ); - memcpy( - (fru_data_new + ((header.offset.product + change_size_by_8) * 8)), - (fru_data_old + (header.offset.product) * 8), - product_len - ); - header.offset.product += change_size_by_8; - } + /* Chassis type field */ + if (f_type == 'c' ) + { + printf("Moving Section Chassis, from %i to %i\n", + ((header.offset.board) * 8), + ((header.offset.board + change_size_by_8) * 8) + ); + memcpy( + (fru_data_new + ((header.offset.board + change_size_by_8) * 8)), + (fru_data_old + (header.offset.board) * 8), + board_len + ); + header.offset.board += change_size_by_8; + } + /* Board type field */ + if ((f_type == 'c' ) || (f_type == 'b' )) + { + printf("Moving Section Product, from %i to %i\n", + ((header.offset.product) * 8), + ((header.offset.product + change_size_by_8) * 8) + ); + memcpy( + (fru_data_new + ((header.offset.product + change_size_by_8) * 8)), + (fru_data_old + (header.offset.product) * 8), + product_len + ); + header.offset.product += change_size_by_8; + } - /* Adjust length of the section */ - if (f_type == 'c') - { - *(fru_data_new + chassis_offset + 1) += change_size_by_8; - } - else if( f_type == 'b') - { - *(fru_data_new + board_offset + 1) += change_size_by_8; - } - else if( f_type == 'p') - { - *(fru_data_new + product_offset + 1) += change_size_by_8; - product_len_new = *(fru_data_new + product_offset + 1) * 8; - } + /* Adjust length of the section */ + if (f_type == 'c') + { + *(fru_data_new + chassis_offset + 1) += change_size_by_8; + } + else if( f_type == 'b') + { + *(fru_data_new + board_offset + 1) += change_size_by_8; + } + else if( f_type == 'p') + { + *(fru_data_new + product_offset + 1) += change_size_by_8; + product_len_new = *(fru_data_new + product_offset + 1) * 8; + } - /* Rebuild Header checksum */ - { - unsigned char * pfru_header = (unsigned char *) &header; - header.checksum = 0; - for(counter = 0; counter < (sizeof(struct fru_header) -1); counter ++) - { - header.checksum += pfru_header[counter]; - } - header.checksum = (0 - header.checksum); - memcpy(fru_data_new, pfru_header, sizeof(struct fru_header)); - } + /* Rebuild Header checksum */ + { + unsigned char * pfru_header = (unsigned char *) &header; + header.checksum = 0; + for(counter = 0; counter < (sizeof(struct fru_header) -1); counter ++) + { + header.checksum += pfru_header[counter]; + } + header.checksum = (0 - header.checksum); + memcpy(fru_data_new, pfru_header, sizeof(struct fru_header)); + } - /* Move remaining sections in 1 copy */ - printf("Moving Remaining Bytes (Multi-Rec , etc..), from %i to %i\n", - remaining_offset, - ((header.offset.product) * 8) + product_len_new - ); - if(((header.offset.product * 8) + product_len_new - remaining_offset) < 0) - { - memcpy( - fru_data_new + (header.offset.product * 8) + product_len_new, - fru_data_old + remaining_offset, - fru.size - remaining_offset - ); - } - else - { - memcpy( - fru_data_new + (header.offset.product * 8) + product_len_new, - fru_data_old + remaining_offset, - fru.size - ((header.offset.product * 8) + product_len_new) - ); - } - } + /* Move remaining sections in 1 copy */ + printf("Moving Remaining Bytes (Multi-Rec , etc..), from %i to %i\n", + remaining_offset, + ((header.offset.product) * 8) + product_len_new + ); + if(((header.offset.product * 8) + product_len_new - remaining_offset) < 0) + { + memcpy( + fru_data_new + (header.offset.product * 8) + product_len_new, + fru_data_old + remaining_offset, + fru.size - remaining_offset + ); + } + else + { + memcpy( + fru_data_new + (header.offset.product * 8) + product_len_new, + fru_data_old + remaining_offset, + fru.size - ((header.offset.product * 8) + product_len_new) + ); + } + } - /* Update only if it's fits padding length as defined in the spec, otherwise, it's an internal - error */ - /************************* - 6) Update Field and sections */ - if( (padding_len >=0) && (padding_len < 8)) - { - /* Do not requires any change in other section */ + /* Update only if it's fits padding length as defined in the spec, otherwise, it's an internal + error */ + /************************* + 6) Update Field and sections */ + if( (padding_len >=0) && (padding_len < 8)) + { + /* Do not requires any change in other section */ - /* Change field length */ - printf("Updating Field : '%s' with '%s' ... (Length from '%x' to '%x')\n", - fru_area, f_string, *(fru_data_old + fru_field_offset_tmp), (0xc0 + strlen(f_string))); - *(fru_data_new + fru_field_offset_tmp) = (0xc0 + strlen(f_string)); - memcpy(fru_data_new + fru_field_offset_tmp + 1, f_string, strlen(f_string)); + /* Change field length */ + printf("Updating Field : '%s' with '%s' ... (Length from '%x' to '%x')\n", + fru_area, f_string, *(fru_data_old + fru_field_offset_tmp), (0xc0 + strlen(f_string))); + *(fru_data_new + fru_field_offset_tmp) = (0xc0 + strlen(f_string)); + memcpy(fru_data_new + fru_field_offset_tmp + 1, f_string, strlen(f_string)); - /* Copy remaing bytes in section */ - #ifdef DBG_RESIZE_FRU - printf("Copying remaining of sections: %lu \n", - ( - (fru_data_old + header_offset + fru_section_len - 1) - - - (fru_data_old + fru_field_offset_tmp + strlen(f_string) + 1) - )); - #endif + /* Copy remaing bytes in section */ + #ifdef DBG_RESIZE_FRU + printf("Copying remaining of sections: %lu \n", + ( + (fru_data_old + header_offset + fru_section_len - 1) + - + (fru_data_old + fru_field_offset_tmp + strlen(f_string) + 1) + ) + ); + #endif - memcpy( - (fru_data_new + fru_field_offset_tmp + 1 + strlen(f_string)), - (fru_data_old + fru_field_offset_tmp + 1 + strlen(fru_area)), - ( - (fru_data_old + header_offset + fru_section_len - 1) - - - (fru_data_old + fru_field_offset_tmp + strlen(f_string) + 1) - ) - ); - + memcpy( + (fru_data_new + fru_field_offset_tmp + 1 + strlen(f_string)), + (fru_data_old + fru_field_offset_tmp + 1 + strlen(fru_area)), + ( + (fru_data_old + header_offset + fru_section_len - 1) + - + (fru_data_old + fru_field_offset_tmp + strlen(f_string) + 1) + ) + ); - /* Add Padding if required */ - for(counter = 0; counter < padding_len; counter ++) - { - *(fru_data_new + header_offset + fru_section_len - 1 - padding_len+ counter) = 0; - } + /* Add Padding if required */ + for(counter = 0; counter < padding_len; counter ++) + { + *(fru_data_new + header_offset + fru_section_len - 1 - padding_len+ counter) = 0; + } - /* Calculate New Checksum */ - cksum = 0; - for( counter = 0; counter