diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2015-04-29 15:44:44 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2015-04-29 15:44:44 +0200 |
commit | b18f5bf2db0fba2e7e539f68645836036d940d26 (patch) | |
tree | 23c4dd8f3d273f34ef9bbe1799d1958685559915 /util/isensor.c | |
parent | a7f89980e5b3f4b9a74c70dbc5ffe8aabd28be28 (diff) |
Imported Upstream version 2.9.6upstream/2.9.6
Diffstat (limited to 'util/isensor.c')
-rw-r--r-- | util/isensor.c | 628 |
1 files changed, 333 insertions, 295 deletions
diff --git a/util/isensor.c b/util/isensor.c index ac93411..e5a80e0 100644 --- a/util/isensor.c +++ b/util/isensor.c @@ -247,7 +247,7 @@ char *decode_entity_id(int id) { * Global Data ************************/ static char *progname = "isensor"; -static char *progver = "2.93"; +static char *progver = "2.96"; #ifdef WIN32 static char savefile[] = "%ipmiutildir%\\thresholds.cmd"; #else @@ -1354,6 +1354,9 @@ int get_sdr_file(char *sdrfile, uchar **sdrlist) num = 0; while (fgets(buff, 255, fp)) { num++; } if (fdebug) printf("Reading %d SDRs from file %s\n",num,sdrfile); + if ((psdrcache != NULL) && (nsdrs > 0)) { /*already have sdrcache*/ + printf("get_sdr_file: Already have cache\n"); /*++++*/ + } sdrbuf = malloc(num * SDR_SZ); if (sdrbuf == NULL) { fclose(fp); @@ -1402,8 +1405,10 @@ int get_sdr_cache(uchar **pret) if ((psdrcache != NULL) && (nsdrs > 0)) { /*already have sdrcache*/ *pret = psdrcache; if (fdebug) printf("get_sdr_cache: already have cache (%p)\n",*pret); + printf("get_sdr_cache: Already have cache\n"); /*++++*/ return(0); } + else printf("get_sdr_cache: Allocating cache\n"); /*++++*/ rv = GetSDRRepositoryInfo(&n,&fdevsdrs); if (rv != 0) return(rv); @@ -1434,6 +1439,12 @@ int get_sdr_cache(uchar **pret) if (rv == 0xC5) { set_reserve(1); i--; } /*retry*/ else break; } else { /*success*/ + /* if sdrlen!=len, adjust */ + if ((len > 5) && (len != (psdr[4] + 5)) ) { + if (fdebug) printf("SDR[%x] adjust len from %d to %d\n", + recid,psdr[4]+5,len); + psdr[4] = len - 5; + } asz += len; if (recnext == recid) recid = 0xffff; else recid = recnext; @@ -1451,19 +1462,23 @@ int get_sdr_cache(uchar **pret) int find_nsdrs(uchar *pcache) { int num = 0; - int asz = 0; + ulong asz = 0; int i, len; uchar *sdr; ushort recid; if (pcache == NULL) return(num); - for (i = 0; asz < sz_sdrs; i++) + for (i = 0; (int)asz < sz_sdrs; i++) { sdr = &pcache[asz]; + if (sdr[2] != 0x51) { /* Dell SDR length error */ + printf("SDR[%x] length error at %ld\n",recid,asz); + sdr = &pcache[++asz]; /*try it if off-by-one*/ + } len = sdr[4] + 5; recid = sdr[0] + (sdr[1] << 8); + if (fdebug) printf("SDR[%x] len=%d i=%d offset=%lx\n",recid,len,i,asz); asz += len; - if (fdebug) printf("SDR[%x] len=%d i=%d\n", recid,len,i); } num = i; return(num); @@ -1565,13 +1580,15 @@ int find_sdr_next(uchar *psdr, uchar *pcache, ushort id) { // sdr = &pcache[i * SDR_SZ]; sdr = &pcache[asz]; + if (sdr[2] != 0x51) /* Dell SDR off-by-one error */ + sdr = &pcache[++asz]; len = sdr[4] + 5; recid = sdr[0] + (sdr[1] << 8); asz += len; // if (fdebug) printf("SDR[%x] len=%d id=%x i=%d imatch=%d\n", // recid,len,id,i,imatch); if (recid == id) imatch = i + 1; /*matches prev, return next one*/ - if (id == 0) { rv = 0; break; } + else if (id == 0) { rv = 0; break; } /* 0000 = first one */ if (i == imatch) { rv = 0; break; } } if (rv == 0) memcpy(psdr,sdr,len); @@ -2861,20 +2878,20 @@ ShowPowerOnHours(void) if (rc == 0 && cc == 0) { /* show the hours (32-bits) */ hrs = resp[1] | (resp[2] << 8) | (resp[3] << 16) | (resp[4] << 24); - if (resp[0] == 0) /*avoid div-by-zero*/ i = 1; - else if (resp[0] == 60) /*normal*/ i = 1; + /*60=normal, more is OOB, so avoid div-by-zero*/ + if ((resp[0] <= 0) || (resp[0] >= 60)) i = 1; else { i = 60 / resp[0]; hrs = hrs / i; } - printf(" SDR IPMI sensor: Power On Hours \t = %d hours\n", - hrs); + printf(" SDR IPMI sensor: Power On Hours \t = %d hours\n", + hrs); } if (fdebug) { - printf("PowerOnHours (rc=%d cc=%x len=%d): ",rc,cc,sresp); - if (rc == 0) - for (i = 0; i < sresp; i++) printf("%02x ",resp[i]); - printf("\n"); + printf("PowerOnHours (rc=%d cc=%x len=%d): ",rc,cc,sresp); + if (rc == 0) + for (i = 0; i < sresp; i++) printf("%02x ",resp[i]); + printf("\n"); } return(rc); } @@ -2895,16 +2912,16 @@ int SaveThreshold(int id, int sensor_num, int sensor_lo, int sensor_hi, histr[0] = 0; /*empty string*/ } else { if (sensor_lo != 0xff) { - sprintf(lostr,"-l 0x%02x",sensor_lo); + sprintf(lostr,"-l 0x%02x",sensor_lo); } else lostr[0] = 0; if (sensor_hi != 0xff) { - sprintf(histr,"-h 0x%02x",sensor_hi); + sprintf(histr,"-h 0x%02x",sensor_hi); } else histr[0] = 0; } fd = fopen(savefile,"a+"); if (fd == NULL) return(-1); fprintf(fd, "ipmiutil sensor -i 0x%04x -n 0x%02x %s %s\n", id, sensor_num, - lostr,histr); + lostr,histr); fclose(fd); return(rv); } @@ -2932,8 +2949,8 @@ static int get_picmg_addrinfo(uchar a1, uchar a2, uchar *addrdata) if (rv == 0 && cc != 0) rv = cc; if (rv == 0) { if (fdebug) { - printf("picmg_addr(%02x,%02x)",a1,a2); - dump_buf("picmg_addr",rdata,rlen,0); + printf("picmg_addr(%02x,%02x)",a1,a2); + dump_buf("picmg_addr",rdata,rlen,0); } memcpy(addrdata,rdata,rlen); } @@ -2965,55 +2982,64 @@ int read_sdr_binfile(char *binfile, uchar **pbufret, int *buflen) #ifdef WIN32 { ulong flen; - ret = get_filesize(binfile, &flen); + ret = get_filesize(binfile, &flen); if (ret == 0) len = flen; else { - ret = get_LastError(); - printf("Cannot get file size for %s, error %d\n",binfile,ret); + ret = get_LastError(); + printf("Cannot get file size for %s, error %d\n",binfile,ret); return(ret); - } + } } #endif - fp = fopen(binfile,"r"); + fp = fopen(binfile,"rb"); if (fp == NULL) { - ret = get_LastError(); - printf("Cannot open file %s, error %d\n",binfile,ret); + ret = get_LastError(); + printf("Cannot open file %s, error %d\n",binfile,ret); return(ret); } + fseek(fp, 0L, SEEK_SET); #ifndef WIN32 - { - struct stat st; - /* use fstat to get file size and allocate buffer */ - ret = fstat(fileno(fp), &st); - len = st.st_size; /*file size in bytes*/ - if (ret != 0) { - ret = get_LastError(); - printf("Cannot stat file %s, error %d\n",binfile,ret); + { /*not windows but Linux, etc.*/ + struct stat st; + /* use fstat to get file size and allocate buffer */ + ret = fstat(fileno(fp), &st); + len = st.st_size; /*file size in bytes*/ + if (ret != 0) { + ret = get_LastError(); + printf("Cannot stat file %s, error %d\n",binfile,ret); return(ret); - } + } } #endif - // len = nsdrs * SDR_SZ; /*estimate max size for n sdrs*/ + /* Could estimate size for nsdrs*SDR_SZ, but we don't yet know nsdrs. + * It is better to use the real file size detected above. */ sz_sdrs = len; pbuf = malloc(len); - if (fdebug) printf("restore: malloc(%d) pbuf=%p\n",len,pbuf); + if (fdebug) printf("sdr_binfile: malloc(%d) pbuf=%p\n",len,pbuf); if (pbuf == NULL) { ret = -1; fclose(fp); return(ret); } + psdrcache = pbuf; /*ok, so proceed with restore*/ ret = 0; len = (int)fread(pbuf, 1, sz_sdrs, fp); if (len <= 0) { - ret = get_LastError(); - printf("Error %d reading file %s\n",ret,binfile); - sz_sdrs = 0; /*for safety*/ + ret = get_LastError(); + printf("Error %d reading file %s\n",ret,binfile); + sz_sdrs = 0; /*for safety*/ + } else if (len < sz_sdrs) { + /* Show error if this happens in Windows */ + ret = get_LastError(); + printf("truncated fread(%s): attempted %d, got %d, error %d\n", + binfile,sz_sdrs,len,ret); + ret = 0; /*try to keep going*/ } fclose(fp); if (fdebug) { - printf("SDR buffer from file (len=%d,sz=%d)\n",len,sz_sdrs); - dump_buf("SDR buffer",pbuf,len,1); + printf("SDR buffer from file (len=%d,sz=%d)\n",len,sz_sdrs); + dump_buf("SDR buffer",pbuf,len,1); } *pbufret = pbuf; *buflen = len; @@ -3053,17 +3079,17 @@ int i_sensor(int argc, char **argv) if (strncmp(optarg,"0x",2) == 0) frearm = htoi(&optarg[2]); else frearm = htoi(optarg); /*was atoi()*/ break; - case 'c': fsimple = 1; break; /* Canonical/simple output*/ - case 'd': fdump = 1; /* Dump SDRs to a file*/ + case 'c': fsimple = 1; break; /* Canonical/simple output*/ + case 'd': fdump = 1; /* Dump SDRs to a file*/ binfile = optarg; break; - case 'b': fchild = 1; break; /* Bladed, so get child SDRs */ - case 'e': fchild = 1; break; /* Extra bladed child SDRs */ - case 'f': frestore = 1; /* Restore SDRs from a file*/ + case 'b': fchild = 1; break; /* Bladed, so get child SDRs */ + case 'e': fchild = 1; break; /* Extra bladed child SDRs */ + case 'f': frestore = 1; /* Restore SDRs from a file*/ binfile = optarg; break; case 's': fsimple = 1; break; /* Simple/canonical output */ /*fcanonical==fsimple*/ case 'g': - rv = get_group_id(optarg); + rv = get_group_id(optarg); if (rv < 0) { printf("Unrecognized sensor type group (%s)\n",optarg); ret = ERR_BAD_PARAM; @@ -3072,27 +3098,27 @@ int i_sensor(int argc, char **argv) if (fdebug) printf("num sensor type groups = %d\n",fshowgrp); break; case 'i': - fshowidx = 1; - get_idx_range(optarg); + fshowidx = 1; + get_idx_range(optarg); break; - case 'j': fjumpstart = 1; /* Load SDR cache from a file*/ + case 'j': fjumpstart = 1; /* Load SDR cache from a file*/ binfile = optarg; break; case 't': fshowthr = 1; break; case 'v': fshowthr = 1; sens_verbose = 1; break; case 'p': fsavethresh = 1; break; - case 'q': fshowthr = 2; fwrap = 1; break; + case 'q': fshowthr = 2; fwrap = 1; break; case 'r': frawsdr = 1; break; - case 'm': /* specific MC, 3-byte address, e.g. "409600" */ - g_bus = htoi(&optarg[0]); /*bus/channel*/ - g_sa = htoi(&optarg[2]); /*device slave address*/ - g_lun = htoi(&optarg[4]); /*LUN*/ + case 'm': /* specific MC, 3-byte address, e.g. "409600" */ + g_bus = htoi(&optarg[0]); /*bus/channel*/ + g_sa = htoi(&optarg[2]); /*device slave address*/ + g_lun = htoi(&optarg[4]); /*LUN*/ if (optarg[6] == 's') { - g_addrtype = ADDR_SMI; s1 = "SMI"; + g_addrtype = ADDR_SMI; s1 = "SMI"; } else { g_addrtype = ADDR_IPMB; s1 = "IPMB"; } fset_mc = 1; printf("set MC at %s bus=%x sa=%x lun=%x\n", - s1,g_bus,g_sa,g_lun); - break; + s1,g_bus,g_sa,g_lun); + break; case 'o': fgetmem = 1; break; @@ -3125,22 +3151,22 @@ int i_sensor(int argc, char **argv) case 'u': /* specify unique thresholds in hex or float */ /* raw hex format: 0xLNLCLUHNHCHU, all 6 required */ if (strncmp(optarg,"0x",2) == 0) { /*raw hex thresholds*/ - sensor_thr[0] = htoi(&optarg[2]); /*lo noncrit*/ - sensor_thr[1] = htoi(&optarg[4]); /*lo crit*/ - sensor_thr[2] = htoi(&optarg[6]); /*lo unrec*/ - sensor_thr[3] = htoi(&optarg[8]); /*hi noncrit*/ - sensor_thr[4] = htoi(&optarg[10]); /*hi crit*/ - sensor_thr[5] = htoi(&optarg[12]); /*hi unrec*/ + sensor_thr[0] = htoi(&optarg[2]); /*lo noncrit*/ + sensor_thr[1] = htoi(&optarg[4]); /*lo crit*/ + sensor_thr[2] = htoi(&optarg[6]); /*lo unrec*/ + sensor_thr[3] = htoi(&optarg[8]); /*hi noncrit*/ + sensor_thr[4] = htoi(&optarg[10]); /*hi crit*/ + sensor_thr[5] = htoi(&optarg[12]); /*hi unrec*/ /* validate sensor threshold ordering */ rv = validate_thresholds(&sensor_thr[0],0,NULL); - if (rv == 0) { - sensor_lo = sensor_thr[0]; - sensor_hi = sensor_thr[3]; + if (rv == 0) { + sensor_lo = sensor_thr[0]; + sensor_hi = sensor_thr[3]; fsetthresh = 3; /*indicates unique raw thresholds */ - } else { + } else { ret = ERR_BAD_PARAM; goto do_exit; - } + } } else { /* assume float input thresholds, with ':' separator*/ /* format LN:LC:LU:HN:HC:HU */ @@ -3166,64 +3192,64 @@ int i_sensor(int argc, char **argv) } /* validate sensor threshold ordering later */ // rv = validate_thresholds(&sensor_thrf[0],1,NULL); - // if (rv == 0) { - sensor_lo_f = sensor_thrf[0]; - sensor_hi_f = sensor_thrf[3]; + // if (rv == 0) { + sensor_lo_f = sensor_thrf[0]; + sensor_hi_f = sensor_thrf[3]; fsetthresh = 4; /*indicates unique float thresholds */ - // } else { + // } else { // ret = ERR_BAD_PARAM; // goto do_exit; - // } + // } } /*end-else -u float thresholds*/ break; - case 'w': fwrap = 1; break; - case 'x': fdebug = 1; break; + case 'w': fwrap = 1; break; + case 'x': fdebug = 1; break; case 'L': /* Loop */ - nloops = atoi(optarg); - fdoloop = 1; - break; - case 'V': /* priv level */ + nloops = atoi(optarg); + fdoloop = 1; + break; + case 'V': /* priv level */ fprivset = 1; - case 'N': /* nodename */ - case 'U': /* remote username */ - case 'P': /* remote password */ - case 'R': /* remote password */ - case 'E': /* get password from IPMI_PASSWORD environment var */ - case 'F': /* force driver type */ - case 'T': /* auth type */ - case 'J': /* cipher suite */ - case 'Y': /* prompt for remote password */ - case 'Z': /* set local MC address */ - parse_lan_options(c,optarg,fdebug); - break; - default: /*usage*/ - printf("Usage: %s [-abcdefghijlmnprstuvwxL -NUPREFTVY]\n",progname); - printf("where -x shows eXtra debug messages\n"); - printf(" -a snum reArms the sensor (snum) for events\n"); - printf(" -b show Bladed child MCs for PICMG (same as -e)\n"); - printf(" -c displays a simpler, Canonical output fmt\n"); - printf(" -d file Dump SDRs to a binary file\n"); + case 'N': /* nodename */ + case 'U': /* remote username */ + case 'P': /* remote password */ + case 'R': /* remote password */ + case 'E': /* get password from IPMI_PASSWORD environment var */ + case 'F': /* force driver type */ + case 'T': /* auth type */ + case 'J': /* cipher suite */ + case 'Y': /* prompt for remote password */ + case 'Z': /* set local MC address */ + parse_lan_options(c,optarg,fdebug); + break; + default: /*usage*/ + printf("Usage: %s [-abcdefghijlmnprstuvwxL -NUPREFTVY]\n",progname); + printf("where -x shows eXtra debug messages\n"); + printf(" -a snum reArms the sensor (snum) for events\n"); + printf(" -b show Bladed child MCs for PICMG (same as -e)\n"); + printf(" -c displays a simpler, Canonical output fmt\n"); + printf(" -d file Dump SDRs to a binary file\n"); printf(" -e show Every bladed child MC for PICMG\n"); // printf(" -f file Restore SDRs from a binary dump file\n"); - printf(" -g fan show only this sensor type group\n"); - printf(" -h tval specifies the Highest threshold to set\n"); - printf(" -i id only show these sensor ids\n"); - printf(" -j file Jump-start SDR cache from a binary file\n"); - printf(" -l tval specifies the Lowest threshold to set\n"); - printf(" -m002000 specific MC (bus 00,sa 20,lun 00)\n"); - printf(" -n snum specifies the sensor Number to set hi/lo\n"); - printf(" -o output memory DIMM information\n"); - printf(" -p persist the threshold being set\n"); - printf(" -q shows threshold values in d:d:d format\n"); - printf(" -r show Raw SDR bytes\n"); - printf(" -s displays a Simpler output format\n"); - printf(" -t shows Threshold values in text format\n"); - printf(" -u thr set Unique threshold values (e.g. 3:2:1:48:49:50)\n"); - printf(" -v Verbose: thresholds, max/min, hysteresis\n"); - printf(" -w Wrap thresholds on sensor line\n"); - printf(" -L n Loop n times\n"); - print_lan_opt_usage(); - ret = ERR_USAGE; + printf(" -g fan show only this sensor type group\n"); + printf(" -h tval specifies the Highest threshold to set\n"); + printf(" -i id only show these sensor ids\n"); + printf(" -j file Jump-start SDR cache from a binary file\n"); + printf(" -l tval specifies the Lowest threshold to set\n"); + printf(" -m002000 specific MC (bus 00,sa 20,lun 00)\n"); + printf(" -n snum specifies the sensor Number to set hi/lo\n"); + printf(" -o output memory DIMM information\n"); + printf(" -p persist the threshold being set\n"); + printf(" -q shows threshold values in d:d:d format\n"); + printf(" -r show Raw SDR bytes\n"); + printf(" -s displays a Simpler output format\n"); + printf(" -t shows Threshold values in text format\n"); + printf(" -u thr set Unique threshold values (e.g. 3:2:1:48:49:50)\n"); + printf(" -v Verbose: thresholds, max/min, hysteresis\n"); + printf(" -w Wrap thresholds on sensor line\n"); + printf(" -L n Loop n times\n"); + print_lan_opt_usage(0); + ret = ERR_USAGE; goto do_exit; } if (fjumpstart && fchild) { @@ -3234,19 +3260,19 @@ int i_sensor(int argc, char **argv) fremote = is_remote(); #ifndef WIN32 if (fremote == 0) { - /* only run this as superuser for accessing IPMI devices. */ - i = geteuid(); - if (i > 1) { - printf("Not superuser (%d)\n", i); - ret = ERR_NOT_ALLOWED; + /* only run this as superuser for accessing IPMI devices. */ + i = geteuid(); + if (i > 1) { + printf("Not superuser (%d)\n", i); + ret = ERR_NOT_ALLOWED; goto do_exit; - } + } } #endif if (fremote) { if (!fprivset) { /* on many systems, getting the SDR Reservation ID requires admin */ - /* if ((fsetthresh != 0) || (frearm != 0)) also require admin */ + /* if ((fsetthresh != 0) || (frearm != 0)) also require admin */ parse_lan_options('V',"4",0); } } @@ -3259,8 +3285,8 @@ int i_sensor(int argc, char **argv) ipmi_maj = devrec[4] & 0x0f; ipmi_min = devrec[4] >> 4; if ((devrec[1] & 0x80) == 0x80) fdevsdrs = 1; - vend_id = devrec[6] + (devrec[7] << 8) + (devrec[8] << 16); - prod_id = devrec[9] + (devrec[10] << 8); + vend_id = devrec[6] + (devrec[7] << 8) + (devrec[8] << 16); + prod_id = devrec[9] + (devrec[10] << 8); if (vend_id == VENDOR_NSC) { /*NSC mBMC*/ pstr = "mBMC"; fmBMC = 1; @@ -3271,11 +3297,14 @@ int i_sensor(int argc, char **argv) fmBMC = 0; if (is_romley(vend_id,prod_id)) fRomley = 1; if (prod_id == 0x003E || fRomley) /*Urbanna NSN2U,CG2100*/ - set_max_kcs_loops(URNLOOPS); /*longer KCS timeout*/ + set_max_kcs_loops(URNLOOPS); /*longer KCS timeout*/ + } else if ((vend_id == VENDOR_SUPERMICRO) + || (vend_id == VENDOR_SUPERMICROX)) { + set_max_kcs_loops(URNLOOPS); /*longer KCS timeout*/ } else { /* Other products */ pstr = "BMC"; fmBMC = 0; - if (vend_id == VENDOR_NEC) fdevsdrs = 0; + if (vend_id == VENDOR_NEC) fdevsdrs = 0; } show_devid( devrec[2], devrec[3], ipmi_maj, ipmi_min); // "-- %s version %x.%x, IPMI version %d.%d \n", pstr, @@ -3298,8 +3327,8 @@ int i_sensor(int argc, char **argv) /* fchild set above if -b is specified to get Blade child SDRs */ /* npass = 2 will get both SdrRep & DevSdr passes on CMM */ if (fpicmg && fdevsdrs) { - npass = 2; - g_addrtype = ADDR_IPMB; + npass = 2; + g_addrtype = ADDR_IPMB; } #endif g_sa = BMC_SA; @@ -3309,23 +3338,23 @@ int i_sensor(int argc, char **argv) if (fremote) printf("Cannot get memory DIMM information remotely.\n"); else { int msz; - char desc[80]; - char szstr[25]; + char desc[80]; + char szstr[25]; ret = -1; - for (j = 0; j < 1; j++) { - for (i = 0; i < 16; i++) { - rv = get_MemDesc(j, i, desc,&msz); - if (rv == 0) { - if (msz == 0) strcpy(szstr,"not present"); - else if (msz & 0x8000) - sprintf(szstr,"size=%dKB",(msz & 0x7FFF)); - else sprintf(szstr,"size=%dMB",msz); - printf("Memory Device (%d,%d): %s : %s\n", - j,i,desc,szstr); + for (j = 0; j < 1; j++) { + for (i = 0; i < 16; i++) { + rv = get_MemDesc(j, i, desc,&msz); + if (rv == 0) { + if (msz == 0) strcpy(szstr,"not present"); + else if (msz & 0x8000) + sprintf(szstr,"size=%dKB",(msz & 0x7FFF)); + else sprintf(szstr,"size=%dMB",msz); + printf("Memory Device (%d,%d): %s : %s\n", + j,i,desc,szstr); ret = 0; - } - } - } + } + } + } } /*end-else*/ goto do_exit; } @@ -3336,20 +3365,20 @@ int i_sensor(int argc, char **argv) int len; ret = get_sdr_cache(&pbuf); if (ret == 0) { - fp = fopen(binfile,"w"); - if (fp == NULL) { - ret = get_LastError(); - printf("Cannot open file %s, error %d\n",binfile,ret); - } else { - printf("Writing SDR size %d to %s ...\n",sz_sdrs,binfile); - len = (int)fwrite(pbuf, 1, sz_sdrs, fp); - fclose(fp); - if (len <= 0) { - ret = get_LastError(); - printf("Error %d writing file %s\n",ret,binfile); - } else ret = 0; - } - free_sdr_cache(pbuf); + fp = fopen(binfile,"wb"); + if (fp == NULL) { + ret = get_LastError(); + printf("Cannot open file %s, error %d\n",binfile,ret); + } else { + printf("Writing SDR size %d to %s ...\n",sz_sdrs,binfile); + len = (int)fwrite(pbuf, 1, sz_sdrs, fp); + fclose(fp); + if (len <= 0) { + ret = get_LastError(); + printf("Error %d writing file %s\n",ret,binfile); + } else ret = 0; + } + free_sdr_cache(pbuf); } goto do_exit; } /*endif fdump*/ @@ -3363,17 +3392,17 @@ int i_sensor(int argc, char **argv) ret = read_sdr_binfile(binfile,&pbuf,&slen); if (ret == 0) { /*successful, so write SDRs */ nsdrs = find_nsdrs(pbuf); - printf("Ready to restore %d SDRs\n",nsdrs); - set_reserve(1); - ret = sdr_clear_repo(fdevsdrs); + printf("Ready to restore %d SDRs\n",nsdrs); + set_reserve(1); + ret = sdr_clear_repo(fdevsdrs); if (ret != 0) { - printf("SDR Clear Repository error %d\n",ret); - goto do_exit; + printf("SDR Clear Repository error %d\n",ret); + goto do_exit; } id = 0; - while(find_sdr_next(sdr,pbuf,id) == 0) { + while(find_sdr_next(sdr,pbuf,id) == 0) { id = sdr[0] + (sdr[1] << 8); - if (fdebug) printf("adding SDR[%x]\n",id); + if (fdebug) printf("adding SDR[%x]\n",id); set_reserve(1); ret = sdr_add_record(sdr,fdevsdrs); if (ret != 0) { @@ -3394,7 +3423,7 @@ int i_sensor(int argc, char **argv) if (ret != 0) fjumpstart = 0; /* use normal method if error*/ else { /* set this as the SDR cache */ psdrcache = pbuf; - sz_sdrs = slen; + sz_sdrs = slen; nsdrs = find_nsdrs(pbuf); if (fdebug) printf("jumpstart cache: nsdrs=%d size=%d\n",nsdrs,slen); } @@ -3404,13 +3433,13 @@ int i_sensor(int argc, char **argv) { if (fjumpstart) ; /*already got this above*/ else { - ret = GetSDRRepositoryInfo(&j,&fdevsdrs); - if (fdebug) printf("GetSDRRepositoryInfo: ret=%x nSDRs=%d\n",ret,j); - if (ret == 0 && j == 0) { - printf("SDR Repository is empty\n"); - goto do_exit; - } - nsdrs = j; + ret = GetSDRRepositoryInfo(&j,&fdevsdrs); + if (fdebug) printf("GetSDRRepositoryInfo: ret=%x nSDRs=%d\n",ret,j); + if (ret == 0 && j == 0) { + printf("SDR Repository is empty\n"); + goto do_exit; + } + nsdrs = j; } /* show header for SDR records */ @@ -3427,43 +3456,52 @@ int i_sensor(int argc, char **argv) else recid = 0; while (recid != 0xffff) { - if (fjumpstart) { - ret = find_sdr_next(sdrdata,psdrcache,recid); - if (ret != 0) { ret = 0; break; } /*end of sdrs*/ - recnext = sdrdata[0] + (sdrdata[1] << 8); /*same as recid*/ + if (fjumpstart) { + ret = find_sdr_next(sdrdata,psdrcache,recid); + if (ret != 0) { /*end of sdrs*/ + if (fdebug) printf("find_sdr_next(%04x): ret = %d\n", recid,ret); + ret = 0; break; + } + recnext = sdrdata[0] + (sdrdata[1] << 8); /*same as recid*/ + if (fdebug) printf("find_sdr_next(%04x): ret = %d, next=%04x\n", + recid,ret,recnext); + if (recid > 0 && recnext == 0) { + if (fdebug) printf("Error recid=%04x recnext=%04x\n",recid,recnext); + ret = 0; break; + } sz = sdrdata[4] + 5; - } else { - ret = GetSDR(recid,&recnext,sdrdata,sizeof(sdrdata),&sz); - if (fdebug) - printf("GetSDR[%04x]: ret = %x, next=%x\n",recid,ret,recnext); - if (ret != 0) { - if (ret > 0) { /* ret is a completion code error */ - printf("%04x GetSDR error 0x%02x %s, rlen=%d\n",recid,ret, + } else { + ret = GetSDR(recid,&recnext,sdrdata,sizeof(sdrdata),&sz); + if (fdebug) + printf("GetSDR[%04x]: ret = %x, next=%x\n",recid,ret,recnext); + if (ret != 0) { + if (ret > 0) { /* ret is a completion code error */ + printf("%04x GetSDR error 0x%02x %s, rlen=%d\n",recid,ret, decode_cc((ushort)0,(uchar)ret),sz); if (ret == 0xC5) { /* lost Reservation ID, retry */ - /* This means that some other IPMI software has - * requested a Reservation before we finished, so - * we need to refresh the Reservation ID * retry. */ - fDoReserve = 1; /* get a new SDR Reservation ID */ - ret = GetSDR(recid,&recnext,sdrdata,sizeof(sdrdata),&sz); - if (fdebug) - printf("GetSDR[%04x]: ret = %x, next=%x\n",recid,ret, + /* This means that some other IPMI software has + * requested a Reservation before we finished, so + * we need to refresh the Reservation ID * retry. */ + fDoReserve = 1; /* get a new SDR Reservation ID */ + ret = GetSDR(recid,&recnext,sdrdata,sizeof(sdrdata),&sz); + if (fdebug) + printf("GetSDR[%04x]: ret = %x, next=%x\n",recid,ret, recnext); - } - } else printf("%04x GetSDR error %d, rlen = %d\n", recid,ret,sz); - if (sz < MIN_SDR_SZ) { /* don't have recnext, so abort */ - break; - } /* else fall through & continue */ - } - } /*end-else*/ - if (ret == 0) { /* (ret == 0) OK, got full SDR */ - if (fdebug) { - dump_buf("got SDR",sdrdata,sz,0); - } - if (sz < MIN_SDR_SZ) goto NextSdr; + } + } else printf("%04x GetSDR error %d, rlen = %d\n", recid,ret,sz); + if (sz < MIN_SDR_SZ) { /* don't have recnext, so abort */ + break; + } /* else fall through & continue */ + } + } /*end-else*/ + if (ret == 0) { /* (ret == 0) OK, got full SDR */ + if (fdebug) { + dump_buf("got SDR",sdrdata,sz,0); + } + if (sz < MIN_SDR_SZ) goto NextSdr; /* if recid == 0, get real record id */ if (recid == 0) recid = sdrdata[0] + (sdrdata[1] << 8); - if (fshowgrp > 0) { + if (fshowgrp > 0) { for (i = 0; i < fshowgrp; i++) { uchar styp; if (sdrdata[3] == 0x03) styp = sdrdata[10]; /*EvtOnly*/ @@ -3479,64 +3517,64 @@ int i_sensor(int argc, char **argv) if ((sensor_num == INIT_SNUM) || (sdrdata[7] == sensor_num) || fsetthresh) { /* if -n not set or if -n matches, parse and show the SDR */ - ShowSDR("",sdrdata); + ShowSDR("",sdrdata); } /* else filter SDRs if not matching -n sensor_num */ #ifdef PICMG_CHILD - /* - * Special logic for blade child MCs in PICMG ATCA systems - * if fchild, try all child MCs within the chassis. - * SDR type 12 capabilities bits (sdrdata[8]): - * 80 = Chassis Device - * 40 = Bridge - * 20 = IPMB Event Generator - * 10 = IPMB Event Receiver - * 08 = FRU Device - * 04 = SEL Device - * 02 = SDR Repository Device - * 01 = Sensor Device - * But all child MCs use Device SDRs anyway. - */ - if (fpicmg && fchild && (sdrdata[3] == 0x12)) { /* PICMG MC DLR */ - int _recid, _recnext, _sz; - uchar _sdrdata[MAX_SDR_SIZE]; - int devsdrs_save; - uchar cc; - - /* save the BMC globals, use IPMB MC */ - devsdrs_save = fdevsdrs; - fdevsdrs = 1; /* use Device SDRs for the children*/ - if (fdebug) - printf(" --- IPMB MC (sa=%02x cap=%02x id=%02x devsdrs=%d):\n", - sdrdata[5],sdrdata[8],sdrdata[12],fdevsdrs); - fDoReserve = 1; /* get a new SDR Reservation ID */ - ipmi_set_mc(PICMG_SLAVE_BUS,sdrdata[5],sdrdata[6],g_addrtype); - - _sz = 16; - ret = ipmi_cmd_mc(GET_DEVICE_ID,NULL,0,_sdrdata,&_sz,&cc,fdebug); - if (ret == 0 && cc == 0) { - /* Get the SDRs from the IPMB MC */ - _recid = 0; - while (_recid != 0xffff) - { - ret = GetSDR(_recid,&_recnext,_sdrdata,sizeof(_sdrdata),&_sz); - if (ret != 0) { - printf("%04x GetSDR error %d, rlen = %d\n",_recid,ret,_sz); - break; - } - else if (_sz >= MIN_SDR_SZ) + /* + * Special logic for blade child MCs in PICMG ATCA systems + * if fchild, try all child MCs within the chassis. + * SDR type 12 capabilities bits (sdrdata[8]): + * 80 = Chassis Device + * 40 = Bridge + * 20 = IPMB Event Generator + * 10 = IPMB Event Receiver + * 08 = FRU Device + * 04 = SEL Device + * 02 = SDR Repository Device + * 01 = Sensor Device + * But all child MCs use Device SDRs anyway. + */ + if (fpicmg && fchild && (sdrdata[3] == 0x12)) { /* PICMG MC DLR */ + int _recid, _recnext, _sz; + uchar _sdrdata[MAX_SDR_SIZE]; + int devsdrs_save; + uchar cc; + + /* save the BMC globals, use IPMB MC */ + devsdrs_save = fdevsdrs; + fdevsdrs = 1; /* use Device SDRs for the children*/ + if (fdebug) + printf(" --- IPMB MC (sa=%02x cap=%02x id=%02x devsdrs=%d):\n", + sdrdata[5],sdrdata[8],sdrdata[12],fdevsdrs); + fDoReserve = 1; /* get a new SDR Reservation ID */ + ipmi_set_mc(PICMG_SLAVE_BUS,sdrdata[5],sdrdata[6],g_addrtype); + + _sz = 16; + ret = ipmi_cmd_mc(GET_DEVICE_ID,NULL,0,_sdrdata,&_sz,&cc,fdebug); + if (ret == 0 && cc == 0) { + /* Get the SDRs from the IPMB MC */ + _recid = 0; + while (_recid != 0xffff) + { + ret = GetSDR(_recid,&_recnext,_sdrdata,sizeof(_sdrdata),&_sz); + if (ret != 0) { + printf("%04x GetSDR error %d, rlen = %d\n",_recid,ret,_sz); + break; + } + else if (_sz >= MIN_SDR_SZ) ShowSDR(" ",_sdrdata); - if (_recnext == _recid) _recid = 0xffff; - else _recid = _recnext; - } /*end while*/ - } /*endif ret==0*/ + if (_recnext == _recid) _recid = 0xffff; + else _recid = _recnext; + } /*end while*/ + } /*endif ret==0*/ - /* restore BMC globals */ - fdevsdrs = devsdrs_save; - ipmi_restore_mc(); - fDoReserve = 1; /* get a new SDR Reservation ID */ - } /*endif fpicmg && fchild*/ + /* restore BMC globals */ + fdevsdrs = devsdrs_save; + ipmi_restore_mc(); + fDoReserve = 1; /* get a new SDR Reservation ID */ + } /*endif fpicmg && fchild*/ #endif if (fdebug) printf("fsetthresh=%d snum=%02x(%02x) sa=%02x(%02x)\n", @@ -3546,21 +3584,21 @@ int i_sensor(int argc, char **argv) { /* setting threshold, compute threshold raw values */ if (fsetthresh == 2) { /*set from float*/ - if (fdebug) + if (fdebug) printf("lof=%.2f hif=%.2f\n", sensor_lo_f,sensor_hi_f); - if (sensor_lo_f != 0) - sensor_lo = FloatToRaw(sensor_lo_f,sdrdata,0); - if (sensor_hi_f != 0) - sensor_hi = FloatToRaw(sensor_hi_f,sdrdata,0); + if (sensor_lo_f != 0) + sensor_lo = FloatToRaw(sensor_lo_f,sdrdata,0); + if (sensor_hi_f != 0) + sensor_hi = FloatToRaw(sensor_hi_f,sdrdata,0); } else if (fsetthresh == 1) { /*raw thresholds*/ - if (sensor_hi != 0xff) + if (sensor_hi != 0xff) sensor_hi_f = RawToFloat(sensor_hi,sdrdata); - if (sensor_lo != 0xff) + if (sensor_lo != 0xff) sensor_lo_f = RawToFloat(sensor_lo,sdrdata); } else if (fsetthresh == 3) { /*unique raw thresholds*/ - if (sensor_hi != 0xff) + if (sensor_hi != 0xff) sensor_hi_f = RawToFloat(sensor_hi,sdrdata); - if (sensor_lo != 0xff) + if (sensor_lo != 0xff) sensor_lo_f = RawToFloat(sensor_lo,sdrdata); } else if (fsetthresh == 4) { /*set unique from float*/ i = fill_thresholds(&sensor_thrf[0], sdrdata); @@ -3575,23 +3613,23 @@ int i_sensor(int argc, char **argv) sensor_hi_f = sensor_thrf[j]; break; } } } - if (fdebug) + if (fdebug) printf("lof=%.2f hif=%.2f\n", sensor_lo_f,sensor_hi_f); /* convert thrf (float) to thr (raw) */ - if (sensor_lo_f != 0) { - sensor_lo = FloatToRaw(sensor_lo_f,sdrdata,0); - sensor_thr[0] = FloatToRaw(sensor_thrf[0],sdrdata,0); - sensor_thr[1] = FloatToRaw(sensor_thrf[1],sdrdata,0); - sensor_thr[2] = FloatToRaw(sensor_thrf[2],sdrdata,0); + if (sensor_lo_f != 0) { + sensor_lo = FloatToRaw(sensor_lo_f,sdrdata,0); + sensor_thr[0] = FloatToRaw(sensor_thrf[0],sdrdata,0); + sensor_thr[1] = FloatToRaw(sensor_thrf[1],sdrdata,0); + sensor_thr[2] = FloatToRaw(sensor_thrf[2],sdrdata,0); } - if (sensor_hi_f != 0) { - sensor_hi = FloatToRaw(sensor_hi_f,sdrdata,0); - sensor_thr[3] = FloatToRaw(sensor_thrf[3],sdrdata,0); - sensor_thr[4] = FloatToRaw(sensor_thrf[4],sdrdata,0); - sensor_thr[5] = FloatToRaw(sensor_thrf[5],sdrdata,0); + if (sensor_hi_f != 0) { + sensor_hi = FloatToRaw(sensor_hi_f,sdrdata,0); + sensor_thr[3] = FloatToRaw(sensor_thrf[3],sdrdata,0); + sensor_thr[4] = FloatToRaw(sensor_thrf[4],sdrdata,0); + sensor_thr[5] = FloatToRaw(sensor_thrf[5],sdrdata,0); } - /* validate threshold ordering */ - if (validate_thresholds(sensor_thrf,1,sdrdata) != 0) { + /* validate threshold ordering */ + if (validate_thresholds(sensor_thrf,1,sdrdata) != 0) { ret = ERR_BAD_PARAM; goto do_exit; } @@ -3603,30 +3641,30 @@ int i_sensor(int argc, char **argv) else fsetfound = recid; } } /*endif fsetthresh */ - } /*endif ok, got full SDR */ + } /*endif ok, got full SDR */ NextSdr: - if (fshowidx) { + if (fshowidx) { /* if we have already read the last in the range, done. */ if (recid >= sensor_idxN) break; // recnext = 0xffff; // break; } if (fjumpstart) recid = recnext; else { - if (recnext == recid) recid = 0xffff; /*break;*/ + if (recnext == recid) recid = 0xffff; /*break;*/ else recid = recnext; } } /*end while recid*/ if (fdoloop && (nloops > 1)) { printf("\n"); /* output an empty separator line */ - os_usleep(1,0); /*delay 1 sec between loops*/ + os_usleep(1,0); /*delay 1 sec between loops*/ } } /*end for nloops*/ if (npass > 1) { /* npass==2 for PICMG */ - /* Switch fdevsdrs from Device to Repository */ - if (fdevsdrs == 0) fdevsdrs = 1; - else fdevsdrs = 0; - fDoReserve = 1; /* get a new SDR Reservation ID */ + /* Switch fdevsdrs from Device to Repository */ + if (fdevsdrs == 0) fdevsdrs = 1; + else fdevsdrs = 0; + fDoReserve = 1; /* get a new SDR Reservation ID */ } } /*end for npass*/ @@ -3654,19 +3692,19 @@ NextSdr: printf(" set(%02x): %02x %02x \n", sensor_num,sensor_lo,sensor_hi); #endif - if (fsetthresh == 3 || fsetthresh == 4) { + if (fsetthresh == 3 || fsetthresh == 4) { /* apply unique sensor thresholds */ pset = &sensor_thr[0]; - } else pset = NULL; /* use just hi/lo */ + } else pset = NULL; /* use just hi/lo */ ret = SetSensorThresholds(sensor_num,sensor_hi,sensor_lo,tdata,pset); printf("SetSensorThreshold[%02x] to lo=%02x(%4.3f) hi=%02x(%4.3f), ret = %d\n", sensor_num,sensor_lo,sensor_lo_f,sensor_hi,sensor_hi_f,ret); - if (fsavethresh && ret == 0) { + if (fsavethresh && ret == 0) { recid = fsetfound; - rv = SaveThreshold(recid,sensor_num,sensor_lo,sensor_hi,pset); - if (rv == 0) - printf("Saved thresholds for sensor %02x\n",sensor_num); - } + rv = SaveThreshold(recid,sensor_num,sensor_lo,sensor_hi,pset); + if (rv == 0) + printf("Saved thresholds for sensor %02x\n",sensor_num); + } fsetthresh = 0; /*only set threshold once*/ } |