ipmi_sel.c 86 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176
  1. /* -*-mode: C; indent-tabs-mode: t; -*-
  2. * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * Redistribution of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. *
  11. * Redistribution in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. *
  15. * Neither the name of Sun Microsystems, Inc. or the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * This software is provided "AS IS," without a warranty of any kind.
  20. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
  21. * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
  22. * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
  23. * SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE
  24. * FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
  25. * OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
  26. * SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA,
  27. * OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
  28. * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
  29. * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
  30. * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  31. */
  32. #define _BSD_SOURCE
  33. #include <string.h>
  34. #include <strings.h>
  35. #include <math.h>
  36. #define __USE_XOPEN /* glibc2 needs this for strptime */
  37. #include <time.h>
  38. #include <ctype.h>
  39. #include <errno.h>
  40. #include <ipmitool/helper.h>
  41. #include <ipmitool/log.h>
  42. #include <ipmitool/ipmi.h>
  43. #include <ipmitool/ipmi_mc.h>
  44. #include <ipmitool/ipmi_intf.h>
  45. #include <ipmitool/ipmi_sel.h>
  46. #include <ipmitool/ipmi_sel_supermicro.h>
  47. #include <ipmitool/ipmi_sdr.h>
  48. #include <ipmitool/ipmi_fru.h>
  49. #include <ipmitool/ipmi_sensor.h>
  50. #include <ipmitool/ipmi_strings.h>
  51. extern int verbose;
  52. static int sel_extended = 0;
  53. static int sel_oem_nrecs = 0;
  54. static IPMI_OEM sel_iana = IPMI_OEM_UNKNOWN;
  55. struct ipmi_sel_oem_msg_rec {
  56. int value[14];
  57. char *string[14];
  58. char *text;
  59. } *sel_oem_msg;
  60. #define SEL_BYTE(n) (n-3) /* So we can refer to byte positions in log entries (byte 3 is at index 0, etc) */
  61. // Definiation for the Decoding the SEL OEM Bytes for DELL Platfoms
  62. #define BIT(x) (1 << x) /* Select the Bit */
  63. #define SIZE_OF_DESC 128 /* Max Size of the description String to be displyed for the Each sel entry */
  64. #define MAX_CARDNO_STR 32 /* Max Size of Card number string */
  65. #define MAX_DIMM_STR 32 /* Max Size of DIMM string */
  66. #define MAX_CARD_STR 32 /* Max Size of Card string */
  67. /*
  68. * Reads values found in message translation file. XX is a wildcard, R means reserved.
  69. * Returns -1 for XX, -2 for R, -3 for non-hex (string), or positive integer from a hex value.
  70. */
  71. static int ipmi_sel_oem_readval(char *str)
  72. {
  73. int ret;
  74. if (!strcmp(str, "XX")) {
  75. return -1;
  76. }
  77. if (!strcmp(str, "R")) {
  78. return -2;
  79. }
  80. if (sscanf(str, "0x%x", &ret) != 1) {
  81. return -3;
  82. }
  83. return ret;
  84. }
  85. /*
  86. * This is where the magic happens. SEL_BYTE is a bit ugly, but it allows
  87. * reference to byte positions instead of array indexes which (hopefully)
  88. * helps make the code easier to read.
  89. */
  90. static int
  91. ipmi_sel_oem_match(uint8_t *evt, const struct ipmi_sel_oem_msg_rec *rec)
  92. {
  93. if (evt[2] == rec->value[SEL_BYTE(3)]
  94. && ((rec->value[SEL_BYTE(4)] < 0)
  95. || (evt[3] == rec->value[SEL_BYTE(4)]))
  96. && ((rec->value[SEL_BYTE(5)] < 0)
  97. || (evt[4] == rec->value[SEL_BYTE(5)]))
  98. && ((rec->value[SEL_BYTE(6)] < 0)
  99. || (evt[5] == rec->value[SEL_BYTE(6)]))
  100. && ((rec->value[SEL_BYTE(7)] < 0)
  101. || (evt[6] == rec->value[SEL_BYTE(7)]))
  102. && ((rec->value[SEL_BYTE(11)] < 0)
  103. || (evt[10] == rec->value[SEL_BYTE(11)]))
  104. && ((rec->value[SEL_BYTE(12)] < 0)
  105. || (evt[11] == rec->value[SEL_BYTE(12)]))) {
  106. return 1;
  107. } else {
  108. return 0;
  109. }
  110. }
  111. int ipmi_sel_oem_init(const char * filename)
  112. {
  113. FILE * fp;
  114. int i, j, k, n, byte;
  115. char buf[15][150];
  116. if (filename == NULL) {
  117. lprintf(LOG_ERR, "No SEL OEM filename provided");
  118. return -1;
  119. }
  120. fp = ipmi_open_file_read(filename);
  121. if (fp == NULL) {
  122. lprintf(LOG_ERR, "Could not open %s file", filename);
  123. return -1;
  124. }
  125. /* count number of records (lines) in input file */
  126. sel_oem_nrecs = 0;
  127. while (fscanf(fp, "%*[^\n]\n") == 0) {
  128. sel_oem_nrecs++;
  129. }
  130. printf("nrecs=%d\n", sel_oem_nrecs);
  131. rewind(fp);
  132. sel_oem_msg = (struct ipmi_sel_oem_msg_rec *)calloc(sel_oem_nrecs,
  133. sizeof(struct ipmi_sel_oem_msg_rec));
  134. for (i=0; i < sel_oem_nrecs; i++) {
  135. n=fscanf(fp, "\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\""
  136. "%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\""
  137. "%[^\"]\",\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",\""
  138. "%[^\"]\",\"%[^\"]\",\"%[^\"]\"\n",
  139. buf[0], buf[1], buf[2], buf[3], buf[4], buf[5],
  140. buf[6], buf[7], buf[8], buf[9], buf[10], buf[11],
  141. buf[12], buf[13], buf[14]);
  142. if (n != 15) {
  143. lprintf (LOG_ERR, "Encountered problems reading line %d of %s",
  144. i+1, filename);
  145. fclose(fp);
  146. fp = NULL;
  147. sel_oem_nrecs = 0;
  148. /* free all the memory allocated so far */
  149. for (j=0; j<i ; j++) {
  150. for (k=3; k<17; k++) {
  151. if (sel_oem_msg[j].value[SEL_BYTE(k)] == -3) {
  152. free(sel_oem_msg[j].string[SEL_BYTE(k)]);
  153. sel_oem_msg[j].string[SEL_BYTE(k)] = NULL;
  154. }
  155. }
  156. }
  157. free(sel_oem_msg);
  158. sel_oem_msg = NULL;
  159. return -1;
  160. }
  161. for (byte = 3; byte < 17; byte++) {
  162. if ((sel_oem_msg[i].value[SEL_BYTE(byte)] =
  163. ipmi_sel_oem_readval(buf[SEL_BYTE(byte)])) == -3) {
  164. sel_oem_msg[i].string[SEL_BYTE(byte)] =
  165. (char *)malloc(strlen(buf[SEL_BYTE(byte)]) + 1);
  166. strcpy(sel_oem_msg[i].string[SEL_BYTE(byte)],
  167. buf[SEL_BYTE(byte)]);
  168. }
  169. }
  170. sel_oem_msg[i].text = (char *)malloc(strlen(buf[SEL_BYTE(17)]) + 1);
  171. strcpy(sel_oem_msg[i].text, buf[SEL_BYTE(17)]);
  172. }
  173. fclose(fp);
  174. fp = NULL;
  175. return 0;
  176. }
  177. static void ipmi_sel_oem_message(struct sel_event_record * evt, int verbose)
  178. {
  179. /*
  180. * Note: although we have a verbose argument, currently the output
  181. * isn't affected by it.
  182. */
  183. int i, j;
  184. for (i=0; i < sel_oem_nrecs; i++) {
  185. if (ipmi_sel_oem_match((uint8_t *)evt, &sel_oem_msg[i])) {
  186. printf (csv_output ? ",\"%s\"" : " | %s", sel_oem_msg[i].text);
  187. for (j=4; j<17; j++) {
  188. if (sel_oem_msg[i].value[SEL_BYTE(j)] == -3) {
  189. printf (csv_output ? ",%s=0x%x" : " %s = 0x%x",
  190. sel_oem_msg[i].string[SEL_BYTE(j)],
  191. ((uint8_t *)evt)[SEL_BYTE(j)]);
  192. }
  193. }
  194. }
  195. }
  196. }
  197. static const struct valstr event_dir_vals[] = {
  198. { 0, "Assertion Event" },
  199. { 1, "Deassertion Event" },
  200. { 0, NULL },
  201. };
  202. static const char *
  203. ipmi_get_event_type(uint8_t code)
  204. {
  205. if (code == 0)
  206. return "Unspecified";
  207. if (code == 1)
  208. return "Threshold";
  209. if (code >= 0x02 && code <= 0x0b)
  210. return "Generic Discrete";
  211. if (code == 0x6f)
  212. return "Sensor-specific Discrete";
  213. if (code >= 0x70 && code <= 0x7f)
  214. return "OEM";
  215. return "Reserved";
  216. }
  217. static char *
  218. ipmi_sel_timestamp(uint32_t stamp)
  219. {
  220. static char tbuf[40];
  221. time_t s = (time_t)stamp;
  222. memset(tbuf, 0, 40);
  223. strftime(tbuf, sizeof(tbuf), "%m/%d/%Y %H:%M:%S", gmtime(&s));
  224. return tbuf;
  225. }
  226. static char *
  227. ipmi_sel_timestamp_date(uint32_t stamp)
  228. {
  229. static char tbuf[11];
  230. time_t s = (time_t)stamp;
  231. strftime(tbuf, sizeof(tbuf), "%m/%d/%Y", gmtime(&s));
  232. return tbuf;
  233. }
  234. static char *
  235. ipmi_sel_timestamp_time(uint32_t stamp)
  236. {
  237. static char tbuf[9];
  238. time_t s = (time_t)stamp;
  239. strftime(tbuf, sizeof(tbuf), "%H:%M:%S", gmtime(&s));
  240. return tbuf;
  241. }
  242. static char *
  243. hex2ascii (uint8_t * hexChars, uint8_t numBytes)
  244. {
  245. int count;
  246. static char hexString[SEL_OEM_NOTS_DATA_LEN+1]; /*Max Size*/
  247. if(numBytes > SEL_OEM_NOTS_DATA_LEN)
  248. numBytes = SEL_OEM_NOTS_DATA_LEN;
  249. for(count=0;count < numBytes;count++)
  250. {
  251. if((hexChars[count]<0x40)||(hexChars[count]>0x7e))
  252. hexString[count]='.';
  253. else
  254. hexString[count]=hexChars[count];
  255. }
  256. hexString[numBytes]='\0';
  257. return hexString;
  258. }
  259. IPMI_OEM
  260. ipmi_get_oem(struct ipmi_intf * intf)
  261. {
  262. /* Execute a Get Device ID command to determine the OEM */
  263. struct ipmi_rs * rsp;
  264. struct ipmi_rq req;
  265. struct ipm_devid_rsp *devid;
  266. if (intf->fd == 0) {
  267. if( sel_iana != IPMI_OEM_UNKNOWN ){
  268. return sel_iana;
  269. }
  270. return IPMI_OEM_UNKNOWN;
  271. }
  272. /*
  273. * Return the cached manufacturer id if the device is open and
  274. * we got an identified OEM owner. Otherwise just attempt to read
  275. * it.
  276. */
  277. if (intf->opened && intf->manufacturer_id != IPMI_OEM_UNKNOWN) {
  278. return intf->manufacturer_id;
  279. }
  280. memset(&req, 0, sizeof(req));
  281. req.msg.netfn = IPMI_NETFN_APP;
  282. req.msg.cmd = BMC_GET_DEVICE_ID;
  283. req.msg.data_len = 0;
  284. rsp = intf->sendrecv(intf, &req);
  285. if (rsp == NULL) {
  286. lprintf(LOG_ERR, "Get Device ID command failed");
  287. return IPMI_OEM_UNKNOWN;
  288. }
  289. if (rsp->ccode > 0) {
  290. lprintf(LOG_ERR, "Get Device ID command failed: %#x %s",
  291. rsp->ccode, val2str(rsp->ccode, completion_code_vals));
  292. return IPMI_OEM_UNKNOWN;
  293. }
  294. devid = (struct ipm_devid_rsp *) rsp->data;
  295. lprintf(LOG_DEBUG,"Iana: %u",
  296. IPM_DEV_MANUFACTURER_ID(devid->manufacturer_id));
  297. return IPM_DEV_MANUFACTURER_ID(devid->manufacturer_id);
  298. }
  299. static int
  300. ipmi_sel_add_entry(struct ipmi_intf * intf, struct sel_event_record * rec)
  301. {
  302. struct ipmi_rs * rsp;
  303. struct ipmi_rq req;
  304. memset(&req, 0, sizeof(req));
  305. req.msg.netfn = IPMI_NETFN_STORAGE;
  306. req.msg.cmd = IPMI_CMD_ADD_SEL_ENTRY;
  307. req.msg.data = (unsigned char *)rec;
  308. req.msg.data_len = 16;
  309. ipmi_sel_print_std_entry(intf, rec);
  310. rsp = intf->sendrecv(intf, &req);
  311. if (rsp == NULL) {
  312. lprintf(LOG_ERR, "Add SEL Entry failed");
  313. return -1;
  314. }
  315. else if (rsp->ccode > 0) {
  316. lprintf(LOG_ERR, "Add SEL Entry failed: %s",
  317. val2str(rsp->ccode, completion_code_vals));
  318. return -1;
  319. }
  320. return 0;
  321. }
  322. static int
  323. ipmi_sel_add_entries_fromfile(struct ipmi_intf * intf, const char * filename)
  324. {
  325. FILE * fp;
  326. char buf[1024];
  327. char * ptr, * tok;
  328. int i, j;
  329. int rc = 0;
  330. uint8_t rqdata[8];
  331. struct sel_event_record sel_event;
  332. if (filename == NULL)
  333. return -1;
  334. fp = ipmi_open_file_read(filename);
  335. if (fp == NULL)
  336. return -1;
  337. while (feof(fp) == 0) {
  338. if (fgets(buf, 1024, fp) == NULL)
  339. continue;
  340. /* clip off optional comment tail indicated by # */
  341. ptr = strchr(buf, '#');
  342. if (ptr)
  343. *ptr = '\0';
  344. else
  345. ptr = buf + strlen(buf);
  346. /* clip off trailing and leading whitespace */
  347. ptr--;
  348. while (isspace((int)*ptr) && ptr >= buf)
  349. *ptr-- = '\0';
  350. ptr = buf;
  351. while (isspace((int)*ptr))
  352. ptr++;
  353. if (strlen(ptr) == 0)
  354. continue;
  355. /* parse the event, 7 bytes with optional comment */
  356. /* 0x00 0x00 0x00 0x00 0x00 0x00 0x00 # event */
  357. i = 0;
  358. tok = strtok(ptr, " ");
  359. while (tok) {
  360. if (i == 7)
  361. break;
  362. j = i++;
  363. if (str2uchar(tok, &rqdata[j]) != 0) {
  364. break;
  365. }
  366. tok = strtok(NULL, " ");
  367. }
  368. if (i < 7) {
  369. lprintf(LOG_ERR, "Invalid Event: %s",
  370. buf2str(rqdata, sizeof(rqdata)));
  371. continue;
  372. }
  373. memset(&sel_event, 0, sizeof(struct sel_event_record));
  374. sel_event.record_id = 0x0000;
  375. sel_event.record_type = 0x02;
  376. /*
  377. * IPMI spec §32.1 generator ID
  378. * Bit 0 = 1 "Software defined"
  379. * Bit 1-7: SWID (IPMI spec §5.5), using 2 = "System management software"
  380. */
  381. sel_event.sel_type.standard_type.gen_id = 0x41;
  382. sel_event.sel_type.standard_type.evm_rev = rqdata[0];
  383. sel_event.sel_type.standard_type.sensor_type = rqdata[1];
  384. sel_event.sel_type.standard_type.sensor_num = rqdata[2];
  385. sel_event.sel_type.standard_type.event_type = rqdata[3] & 0x7f;
  386. sel_event.sel_type.standard_type.event_dir = (rqdata[3] & 0x80) >> 7;
  387. sel_event.sel_type.standard_type.event_data[0] = rqdata[4];
  388. sel_event.sel_type.standard_type.event_data[1] = rqdata[5];
  389. sel_event.sel_type.standard_type.event_data[2] = rqdata[6];
  390. rc = ipmi_sel_add_entry(intf, &sel_event);
  391. if (rc < 0)
  392. break;
  393. }
  394. fclose(fp);
  395. return rc;
  396. }
  397. static struct ipmi_event_sensor_types oem_kontron_event_reading_types[] __attribute__((unused)) = {
  398. { 0x70 , 0x00 , 0xff, "Code Assert" },
  399. { 0x71 , 0x00 , 0xff, "Code Assert" },
  400. { 0, 0, 0xFF, NULL }
  401. };
  402. char *
  403. get_kontron_evt_desc(struct ipmi_intf *intf, struct sel_event_record * rec)
  404. {
  405. char * description = NULL;
  406. /*
  407. * Kontron OEM events are described in the product's user manual, but are limited in favor of
  408. * sensor specific
  409. */
  410. /* Only standard records are defined so far */
  411. if( rec->record_type < 0xC0 ){
  412. const struct ipmi_event_sensor_types *st=NULL;
  413. for ( st=oem_kontron_event_types ; st->desc != NULL; st++){
  414. if (st->code == rec->sel_type.standard_type.event_type ){
  415. size_t len =strlen(st->desc);
  416. description = (char*)malloc( len + 1 );
  417. memcpy(description, st->desc , len);
  418. description[len] = 0;;
  419. return description;
  420. }
  421. }
  422. }
  423. return NULL;
  424. }
  425. char *
  426. get_newisys_evt_desc(struct ipmi_intf * intf, struct sel_event_record * rec)
  427. {
  428. /*
  429. * Newisys OEM event descriptions can be retrieved through an
  430. * OEM IPMI command.
  431. */
  432. struct ipmi_rs * rsp;
  433. struct ipmi_rq req;
  434. uint8_t msg_data[6];
  435. char * description = NULL;
  436. memset(&req, 0, sizeof(req));
  437. req.msg.netfn = 0x2E;
  438. req.msg.cmd = 0x01;
  439. req.msg.data_len = sizeof(msg_data);
  440. msg_data[0] = 0x15; /* IANA LSB */
  441. msg_data[1] = 0x24; /* IANA */
  442. msg_data[2] = 0x00; /* IANA MSB */
  443. msg_data[3] = 0x01; /* Subcommand */
  444. msg_data[4] = rec->record_id & 0x00FF; /* SEL Record ID LSB */
  445. msg_data[5] = (rec->record_id & 0xFF00) >> 8; /* SEL Record ID MSB */
  446. req.msg.data = msg_data;
  447. rsp = intf->sendrecv(intf, &req);
  448. if (rsp == NULL) {
  449. if (verbose)
  450. lprintf(LOG_ERR, "Error issuing OEM command");
  451. return NULL;
  452. }
  453. if (rsp->ccode > 0) {
  454. if (verbose)
  455. lprintf(LOG_ERR, "OEM command returned error code: %s",
  456. val2str(rsp->ccode, completion_code_vals));
  457. return NULL;
  458. }
  459. /* Verify our response before we use it */
  460. if (rsp->data_len < 5)
  461. {
  462. lprintf(LOG_ERR, "Newisys OEM response too short");
  463. return NULL;
  464. }
  465. else if (rsp->data_len != (4 + rsp->data[3]))
  466. {
  467. lprintf(LOG_ERR, "Newisys OEM response has unexpected length");
  468. return NULL;
  469. }
  470. else if (IPM_DEV_MANUFACTURER_ID(rsp->data) != IPMI_OEM_NEWISYS)
  471. {
  472. lprintf(LOG_ERR, "Newisys OEM response has unexpected length");
  473. return NULL;
  474. }
  475. description = (char*)malloc(rsp->data[3] + 1);
  476. memcpy(description, rsp->data + 4, rsp->data[3]);
  477. description[rsp->data[3]] = 0;;
  478. return description;
  479. }
  480. char *
  481. get_supermicro_evt_desc(struct ipmi_intf *intf, struct sel_event_record *rec)
  482. {
  483. struct ipmi_rs *rsp;
  484. struct ipmi_rq req;
  485. char *desc = NULL;
  486. int chipset_type = 4;
  487. int data1;
  488. int data2;
  489. int data3;
  490. int sensor_type;
  491. uint8_t i = 0;
  492. uint16_t oem_id = 0;
  493. /* Get the OEM event Bytes of the SEL Records byte 13, 14, 15 to
  494. * data1,data2,data3
  495. */
  496. data1 = rec->sel_type.standard_type.event_data[0];
  497. data2 = rec->sel_type.standard_type.event_data[1];
  498. data3 = rec->sel_type.standard_type.event_data[2];
  499. /* Check for the Standard Event type == 0x6F */
  500. if (rec->sel_type.standard_type.event_type != 0x6F) {
  501. return NULL;
  502. }
  503. /* Allocate mem for te Description string */
  504. desc = malloc(sizeof(char) * SIZE_OF_DESC);
  505. if (desc == NULL) {
  506. lprintf(LOG_ERR, "ipmitool: malloc failure");
  507. return NULL;
  508. }
  509. memset(desc, '\0', SIZE_OF_DESC);
  510. sensor_type = rec->sel_type.standard_type.sensor_type;
  511. switch (sensor_type) {
  512. case SENSOR_TYPE_MEMORY:
  513. memset(&req, 0, sizeof (req));
  514. req.msg.netfn = IPMI_NETFN_APP;
  515. req.msg.lun = 0;
  516. req.msg.cmd = BMC_GET_DEVICE_ID;
  517. req.msg.data = NULL;
  518. req.msg.data_len = 0;
  519. rsp = intf->sendrecv(intf, &req);
  520. if (rsp == NULL) {
  521. lprintf(LOG_ERR, " Error getting system info");
  522. if (desc != NULL) {
  523. free(desc);
  524. desc = NULL;
  525. }
  526. return NULL;
  527. } else if (rsp->ccode > 0) {
  528. lprintf(LOG_ERR, " Error getting system info: %s",
  529. val2str(rsp->ccode, completion_code_vals));
  530. if (desc != NULL) {
  531. free(desc);
  532. desc = NULL;
  533. }
  534. return NULL;
  535. }
  536. /* check the chipset type */
  537. oem_id = ipmi_get_oem_id(intf);
  538. if (oem_id == 0) {
  539. if (desc != NULL) {
  540. free(desc);
  541. desc = NULL;
  542. }
  543. return NULL;
  544. }
  545. for (i = 0; supermicro_X8[i] != 0xFFFF; i++) {
  546. if (oem_id == supermicro_X8[i]) {
  547. chipset_type = 0;
  548. break;
  549. }
  550. }
  551. for (i = 0; supermicro_older[i] != 0xFFFF; i++) {
  552. if (oem_id == supermicro_older[i]) {
  553. chipset_type = 0;
  554. break;
  555. }
  556. }
  557. for (i = 0; supermicro_romely[i] != 0xFFFF; i++) {
  558. if (oem_id == supermicro_romely[i]) {
  559. chipset_type = 1;
  560. break;
  561. }
  562. }
  563. for (i = 0; supermicro_x9[i] != 0xFFFF; i++) {
  564. if (oem_id == supermicro_x9[i]) {
  565. chipset_type = 2;
  566. break;
  567. }
  568. }
  569. for (i = 0; supermicro_brickland[i] != 0xFFFF; i++) {
  570. if (oem_id == supermicro_brickland[i]) {
  571. chipset_type = 3;
  572. break;
  573. }
  574. }
  575. for (i = 0; supermicro_x10QRH[i] != 0xFFFF; i++) {
  576. if (oem_id == supermicro_x10QRH[i]) {
  577. chipset_type = 4;
  578. break;
  579. }
  580. }
  581. for (i = 0; supermicro_x10QBL[i] != 0xFFFF; i++) {
  582. if (oem_id == supermicro_x10QBL[i]) {
  583. chipset_type = 4;
  584. break;
  585. }
  586. }
  587. for (i = 0; supermicro_x10OBi[i] != 0xFFFF; i++) {
  588. if (oem_id == supermicro_x10OBi[i]) {
  589. chipset_type = 5;
  590. break;
  591. }
  592. }
  593. if (chipset_type == 0) {
  594. snprintf(desc, SIZE_OF_DESC, "@DIMM%2X(CPU%x)",
  595. data2,
  596. (data3 & 0x03) + 1);
  597. } else if (chipset_type == 1) {
  598. snprintf(desc, SIZE_OF_DESC, "@DIMM%c%c(CPU%x)",
  599. (data2 >> 4) + 0x40 + (data3 & 0x3) * 4,
  600. (data2 & 0xf) + 0x27, (data3 & 0x03) + 1);
  601. } else if (chipset_type == 2) {
  602. snprintf(desc, SIZE_OF_DESC, "@DIMM%c%c(CPU%x)",
  603. (data2 >> 4) + 0x40 + (data3 & 0x3) * 3,
  604. (data2 & 0xf) + 0x27, (data3 & 0x03) + 1);
  605. } else if (chipset_type == 3) {
  606. snprintf(desc, SIZE_OF_DESC, "@DIMM%c%d(P%dM%d)",
  607. ((data2 & 0xf) >> 4) > 4
  608. ? '@' - 4 + ((data2 & 0xff) >> 4)
  609. : '@' + ((data2 & 0xff) >> 4),
  610. (data2 & 0xf) - 0x09, (data3 & 0x0f) + 1,
  611. (data2 & 0xff) >> 4 > 4 ? 2 : 1);
  612. } else if (chipset_type == 4) {
  613. snprintf(desc, SIZE_OF_DESC, "@DIMM%c%c(CPU%x)",
  614. (data2 >> 4) + 0x40,
  615. (data2 & 0xf) + 0x27, (data3 & 0x03) + 1);
  616. } else if (chipset_type == 5) {
  617. snprintf(desc, SIZE_OF_DESC, "@DIMM%c%c(CPU%x)",
  618. (data2 >> 4) + 0x40,
  619. (data2 & 0xf) + 0x27, (data3 & 0x07) + 1);
  620. } else {
  621. /* No description. */
  622. desc[0] = '\0';
  623. }
  624. break;
  625. case SENSOR_TYPE_SUPERMICRO_OEM:
  626. if (data1 == 0x80 && data3 == 0xFF) {
  627. if (data2 == 0x0) {
  628. snprintf(desc, SIZE_OF_DESC, "BMC unexpected reset");
  629. } else if (data2 == 0x1) {
  630. snprintf(desc, SIZE_OF_DESC, "BMC cold reset");
  631. } else if (data2 == 0x2) {
  632. snprintf(desc, SIZE_OF_DESC, "BMC warm reset");
  633. }
  634. }
  635. break;
  636. }
  637. return desc;
  638. }
  639. /*
  640. * Function : Decoding the SEL OEM Bytes for the DELL Platforms.
  641. * Description : The below fucntion will decode the SEL Events OEM Bytes for the Dell specific Sensors only.
  642. * The below function will append the additional information Strings/description to the normal sel desc.
  643. * With this the SEL will display additional information sent via OEM Bytes of the SEL Record.
  644. * NOTE : Specific to DELL Platforms only.
  645. * Returns : Pointer to the char string.
  646. */
  647. char * get_dell_evt_desc(struct ipmi_intf * intf, struct sel_event_record * rec)
  648. {
  649. int data1, data2, data3;
  650. int sensor_type;
  651. char *desc = NULL;
  652. unsigned char count;
  653. unsigned char node;
  654. unsigned char dimmNum;
  655. unsigned char dimmsPerNode;
  656. char dimmStr[MAX_DIMM_STR];
  657. char tmpdesc[SIZE_OF_DESC];
  658. char* str;
  659. unsigned char incr = 0;
  660. unsigned char i=0,j = 0;
  661. struct ipmi_rs *rsp;
  662. struct ipmi_rq req;
  663. char tmpData;
  664. int version;
  665. /* Get the OEM event Bytes of the SEL Records byte 13, 14, 15 to Data1,data2,data3 */
  666. data1 = rec->sel_type.standard_type.event_data[0];
  667. data2 = rec->sel_type.standard_type.event_data[1];
  668. data3 = rec->sel_type.standard_type.event_data[2];
  669. /* Check for the Standard Event type == 0x6F */
  670. if (0x6F == rec->sel_type.standard_type.event_type)
  671. {
  672. sensor_type = rec->sel_type.standard_type.sensor_type;
  673. /* Allocate mem for te Description string */
  674. desc = (char*)malloc(SIZE_OF_DESC);
  675. if(NULL == desc)
  676. return NULL;
  677. memset(desc,0,SIZE_OF_DESC);
  678. memset(tmpdesc,0,SIZE_OF_DESC);
  679. switch (sensor_type) {
  680. case SENSOR_TYPE_PROCESSOR: /* Processor/CPU related OEM Sel Byte Decoding for DELL Platforms only */
  681. if((OEM_CODE_IN_BYTE2 == (data1 & DATA_BYTE2_SPECIFIED_MASK)))
  682. {
  683. if(0x00 == (data1 & MASK_LOWER_NIBBLE))
  684. snprintf(desc,SIZE_OF_DESC,"CPU Internal Err | ");
  685. if(0x06 == (data1 & MASK_LOWER_NIBBLE))
  686. {
  687. snprintf(desc,SIZE_OF_DESC,"CPU Protocol Err | ");
  688. }
  689. /* change bit location to a number */
  690. for (count= 0; count < 8; count++)
  691. {
  692. if (BIT(count)& data2)
  693. {
  694. count++;
  695. /* 0x0A - CPU sensor number */
  696. if((0x06 == (data1 & MASK_LOWER_NIBBLE)) && (0x0A == rec->sel_type.standard_type.sensor_num))
  697. snprintf(desc,SIZE_OF_DESC,"FSB %d ",count); // Which CPU Has generated the FSB
  698. else
  699. snprintf(desc,SIZE_OF_DESC,"CPU %d | APIC ID %d ",count,data3); /* Specific CPU related info */
  700. break;
  701. }
  702. }
  703. }
  704. break;
  705. case SENSOR_TYPE_MEMORY: /* Memory or DIMM related OEM Sel Byte Decoding for DELL Platforms only */
  706. case SENSOR_TYPE_EVT_LOG: /* Events Logging for Memory or DIMM related OEM Sel Byte Decoding for DELL Platforms only */
  707. /* Get the current version of the IPMI Spec Based on that Decoding of memory info is done.*/
  708. memset(&req, 0, sizeof (req));
  709. req.msg.netfn = IPMI_NETFN_APP;
  710. req.msg.lun = 0;
  711. req.msg.cmd = BMC_GET_DEVICE_ID;
  712. req.msg.data = NULL;
  713. req.msg.data_len = 0;
  714. rsp = intf->sendrecv(intf, &req);
  715. if (NULL == rsp)
  716. {
  717. lprintf(LOG_ERR, " Error getting system info");
  718. if (desc != NULL) {
  719. free(desc);
  720. desc = NULL;
  721. }
  722. return NULL;
  723. }
  724. else if (rsp->ccode > 0)
  725. {
  726. lprintf(LOG_ERR, " Error getting system info: %s",
  727. val2str(rsp->ccode, completion_code_vals));
  728. if (desc != NULL) {
  729. free(desc);
  730. desc = NULL;
  731. }
  732. return NULL;
  733. }
  734. version = rsp->data[4];
  735. /* Memory DIMMS */
  736. if( (data1 & OEM_CODE_IN_BYTE2) || (data1 & OEM_CODE_IN_BYTE3 ) )
  737. {
  738. /* Memory Redundancy related oem bytes docoding .. */
  739. if( (SENSOR_TYPE_MEMORY == sensor_type) && (0x0B == rec->sel_type.standard_type.event_type) )
  740. {
  741. if(0x00 == (data1 & MASK_LOWER_NIBBLE))
  742. {
  743. snprintf(desc,SIZE_OF_DESC," Redundancy Regained | ");
  744. }
  745. else if(0x01 == (data1 & MASK_LOWER_NIBBLE))
  746. {
  747. snprintf(desc,SIZE_OF_DESC,"Redundancy Lost | ");
  748. }
  749. } /* Correctable and uncorrectable ECC Error Decoding */
  750. else if(SENSOR_TYPE_MEMORY == sensor_type)
  751. {
  752. if(0x00 == (data1 & MASK_LOWER_NIBBLE))
  753. {
  754. /* 0x1C - Memory Sensor Number */
  755. if(0x1C == rec->sel_type.standard_type.sensor_num)
  756. {
  757. /*Add the complete information about the Memory Configs.*/
  758. if((data1 & OEM_CODE_IN_BYTE2) && (data1 & OEM_CODE_IN_BYTE3 ))
  759. {
  760. count = 0;
  761. snprintf(desc,SIZE_OF_DESC,"CRC Error on:");
  762. for(i=0;i<4;i++)
  763. {
  764. if((BIT(i))&(data2))
  765. {
  766. if(count)
  767. {
  768. str = desc+strlen(desc);
  769. *str++ = ',';
  770. str = '\0';
  771. count = 0;
  772. }
  773. switch(i) /* Which type of memory config is present.. */
  774. {
  775. case 0: snprintf(tmpdesc,SIZE_OF_DESC,"South Bound Memory");
  776. strcat(desc,tmpdesc);
  777. count++;
  778. break;
  779. case 1: snprintf(tmpdesc,SIZE_OF_DESC,"South Bound Config");
  780. strcat(desc,tmpdesc);
  781. count++;
  782. break;
  783. case 2: snprintf(tmpdesc,SIZE_OF_DESC,"North Bound memory");
  784. strcat(desc,tmpdesc);
  785. count++;
  786. break;
  787. case 3: snprintf(tmpdesc,SIZE_OF_DESC,"North Bound memory-corr");
  788. strcat(desc,tmpdesc);
  789. count++;
  790. break;
  791. default:
  792. break;
  793. }
  794. }
  795. }
  796. if(data3>=0x00 && data3<0xFF)
  797. {
  798. snprintf(tmpdesc,SIZE_OF_DESC,"|Failing_Channel:%d",data3);
  799. strcat(desc,tmpdesc);
  800. }
  801. }
  802. break;
  803. }
  804. snprintf(desc,SIZE_OF_DESC,"Correctable ECC | ");
  805. }
  806. else if(0x01 == (data1 & MASK_LOWER_NIBBLE))
  807. {
  808. snprintf(desc,SIZE_OF_DESC,"UnCorrectable ECC | ");
  809. }
  810. } /* Corr Memory log disabled */
  811. else if(SENSOR_TYPE_EVT_LOG == sensor_type)
  812. {
  813. if(0x00 == (data1 & MASK_LOWER_NIBBLE))
  814. snprintf(desc,SIZE_OF_DESC,"Corr Memory Log Disabled | ");
  815. }
  816. }
  817. else
  818. {
  819. if(SENSOR_TYPE_SYS_EVENT == sensor_type)
  820. {
  821. if(0x02 == (data1 & MASK_LOWER_NIBBLE))
  822. snprintf(desc,SIZE_OF_DESC,"Unknown System Hardware Failure ");
  823. }
  824. if(SENSOR_TYPE_EVT_LOG == sensor_type)
  825. {
  826. if(0x03 == (data1 & MASK_LOWER_NIBBLE))
  827. snprintf(desc,SIZE_OF_DESC,"All Even Logging Dissabled");
  828. }
  829. }
  830. /*
  831. * Based on the above error, we need to find whcih memory slot or
  832. * Card has got the Errors/Sel Generated.
  833. */
  834. if(data1 & OEM_CODE_IN_BYTE2 )
  835. {
  836. /* Find the Card Type */
  837. if((0x0F != (data2 >> 4)) && ((data2 >> 4) < 0x08))
  838. {
  839. tmpData = ('A'+ (data2 >> 4));
  840. if( (SENSOR_TYPE_MEMORY == sensor_type) && (0x0B == rec->sel_type.standard_type.event_type) )
  841. {
  842. snprintf(tmpdesc, SIZE_OF_DESC, "Bad Card %c", tmpData);
  843. }
  844. else
  845. {
  846. snprintf(tmpdesc, SIZE_OF_DESC, "Card %c", tmpData);
  847. }
  848. strcat(desc, tmpdesc);
  849. } /* Find the Bank Number of the DIMM */
  850. if (0x0F != (data2 & MASK_LOWER_NIBBLE))
  851. {
  852. if(0x51 == version)
  853. {
  854. snprintf(tmpdesc, SIZE_OF_DESC, "Bank %d", ((data2 & 0x0F)+1));
  855. strcat(desc, tmpdesc);
  856. }
  857. else
  858. {
  859. incr = (data2 & 0x0f) << 3;
  860. }
  861. }
  862. }
  863. /* Find the DIMM Number of the Memory which has Generated the Fault or Sel */
  864. if(data1 & OEM_CODE_IN_BYTE3 )
  865. {
  866. // Based on the IPMI Spec Need Identify the DIMM Details.
  867. // For the SPEC 1.5 Only the DIMM Number is Valid.
  868. if(0x51 == version)
  869. {
  870. snprintf(tmpdesc, SIZE_OF_DESC, "DIMM %c", ('A'+ data3));
  871. strcat(desc, tmpdesc);
  872. }
  873. /* For the SPEC 2.0 Decode the DIMM Number as it supports more.*/
  874. else if( ((data2 >> 4) > 0x07) && (0x0F != (data2 >> 4) ))
  875. {
  876. strcpy(dimmStr, " DIMM");
  877. str = desc+strlen(desc);
  878. dimmsPerNode = 4;
  879. if(0x09 == (data2 >> 4)) dimmsPerNode = 6;
  880. else if(0x0A == (data2 >> 4)) dimmsPerNode = 8;
  881. else if(0x0B == (data2 >> 4)) dimmsPerNode = 9;
  882. else if(0x0C == (data2 >> 4)) dimmsPerNode = 12;
  883. else if(0x0D == (data2 >> 4)) dimmsPerNode = 24;
  884. else if(0x0E == (data2 >> 4)) dimmsPerNode = 3;
  885. count = 0;
  886. for (i = 0; i < 8; i++)
  887. {
  888. if (BIT(i) & data3)
  889. {
  890. if(count)
  891. {
  892. strcat(str,",");
  893. count = 0x00;
  894. }
  895. node = (incr + i)/dimmsPerNode;
  896. dimmNum = ((incr + i)%dimmsPerNode)+1;
  897. dimmStr[5] = node + 'A';
  898. sprintf(tmpdesc,"%d",dimmNum);
  899. for(j = 0; j < strlen(tmpdesc);j++)
  900. dimmStr[6+j] = tmpdesc[j];
  901. dimmStr[6+j] = '\0';
  902. strcat(str,dimmStr); // final DIMM Details.
  903. count++;
  904. }
  905. }
  906. }
  907. else
  908. {
  909. strcpy(dimmStr, " DIMM");
  910. str = desc+strlen(desc);
  911. count = 0;
  912. for (i = 0; i < 8; i++)
  913. {
  914. if (BIT(i) & data3)
  915. {
  916. // check if more than one DIMM, if so add a comma to the string.
  917. sprintf(tmpdesc,"%d",(i + incr + 1));
  918. if(count)
  919. {
  920. strcat(str,",");
  921. count = 0x00;
  922. }
  923. for(j = 0; j < strlen(tmpdesc);j++)
  924. dimmStr[5+j] = tmpdesc[j];
  925. dimmStr[5+j] = '\0';
  926. strcat(str, dimmStr);
  927. count++;
  928. }
  929. }
  930. }
  931. }
  932. break;
  933. /* Sensor In system charectorization Error Decoding.
  934. Sensor type 0x20*/
  935. case SENSOR_TYPE_TXT_CMD_ERROR:
  936. if((0x00 == (data1 & MASK_LOWER_NIBBLE))&&((data1 & OEM_CODE_IN_BYTE2) && (data1 & OEM_CODE_IN_BYTE3)))
  937. {
  938. switch(data3)
  939. {
  940. case 0x01:
  941. snprintf(desc,SIZE_OF_DESC,"BIOS TXT Error");
  942. break;
  943. case 0x02:
  944. snprintf(desc,SIZE_OF_DESC,"Processor/FIT TXT");
  945. break;
  946. case 0x03:
  947. snprintf(desc,SIZE_OF_DESC,"BIOS ACM TXT Error");
  948. break;
  949. case 0x04:
  950. snprintf(desc,SIZE_OF_DESC,"SINIT ACM TXT Error");
  951. break;
  952. case 0xff:
  953. snprintf(desc,SIZE_OF_DESC,"Unrecognized TT Error12");
  954. break;
  955. default:
  956. break;
  957. }
  958. }
  959. break;
  960. /* OS Watch Dog Timer Sel Events */
  961. case SENSOR_TYPE_WTDOG:
  962. if(SENSOR_TYPE_OEM_SEC_EVENT == data1)
  963. {
  964. if(0x04 == data2)
  965. {
  966. snprintf(desc,SIZE_OF_DESC,"Hard Reset|Interrupt type None,SMS/OS Timer used at expiration");
  967. }
  968. }
  969. break;
  970. /* This Event is for BMC to Othe Hardware or CPU . */
  971. case SENSOR_TYPE_VER_CHANGE:
  972. if((0x02 == (data1 & MASK_LOWER_NIBBLE))&&((data1 & OEM_CODE_IN_BYTE2) && (data1 & OEM_CODE_IN_BYTE3)))
  973. {
  974. if(0x02 == data2)
  975. {
  976. if(0x00 == data3)
  977. {
  978. snprintf(desc, SIZE_OF_DESC, "between BMC/iDRAC Firmware and other hardware");
  979. }
  980. else if(0x01 == data3)
  981. {
  982. snprintf(desc, SIZE_OF_DESC, "between BMC/iDRAC Firmware and CPU");
  983. }
  984. }
  985. }
  986. break;
  987. /* Flex or Mac tuning OEM Decoding for the DELL. */
  988. case SENSOR_TYPE_OEM_SEC_EVENT:
  989. /* 0x25 - Virtual MAC sensory number - Dell OEM */
  990. if(0x25 == rec->sel_type.standard_type.sensor_num)
  991. {
  992. if(0x01 == (data1 & MASK_LOWER_NIBBLE))
  993. {
  994. snprintf(desc, SIZE_OF_DESC, "Failed to program Virtual Mac Address");
  995. if((data1 & OEM_CODE_IN_BYTE2)&&(data1 & OEM_CODE_IN_BYTE3))
  996. {
  997. snprintf(tmpdesc, SIZE_OF_DESC, " at bus:%.2x device:%.2x function:%x",
  998. data3 &0x7F, (data2 >> 3) & 0x1F,
  999. data2 & 0x07);
  1000. strcat(desc,tmpdesc);
  1001. }
  1002. }
  1003. else if(0x02 == (data1 & MASK_LOWER_NIBBLE))
  1004. {
  1005. snprintf(desc, SIZE_OF_DESC, "Device option ROM failed to support link tuning or flex address");
  1006. }
  1007. else if(0x03 == (data1 & MASK_LOWER_NIBBLE))
  1008. {
  1009. snprintf(desc, SIZE_OF_DESC, "Failed to get link tuning or flex address data from BMC/iDRAC");
  1010. }
  1011. }
  1012. break;
  1013. case SENSOR_TYPE_CRIT_INTR:
  1014. case SENSOR_TYPE_OEM_NFATAL_ERROR: /* Non - Fatal PCIe Express Error Decoding */
  1015. case SENSOR_TYPE_OEM_FATAL_ERROR: /* Fatal IO Error Decoding */
  1016. /* 0x29 - QPI Linx Error Sensor Dell OEM */
  1017. if(0x29 == rec->sel_type.standard_type.sensor_num)
  1018. {
  1019. if((0x02 == (data1 & MASK_LOWER_NIBBLE))&&((data1 & OEM_CODE_IN_BYTE2) && (data1 & OEM_CODE_IN_BYTE3)))
  1020. {
  1021. snprintf(tmpdesc, SIZE_OF_DESC, "Partner-(LinkId:%d,AgentId:%d)|",(data2 & 0xC0),(data2 & 0x30));
  1022. strcat(desc,tmpdesc);
  1023. snprintf(tmpdesc, SIZE_OF_DESC, "ReportingAgent(LinkId:%d,AgentId:%d)|",(data2 & 0x0C),(data2 & 0x03));
  1024. strcat(desc,tmpdesc);
  1025. if(0x00 == (data3 & 0xFC))
  1026. {
  1027. snprintf(tmpdesc, SIZE_OF_DESC, "LinkWidthDegraded|");
  1028. strcat(desc,tmpdesc);
  1029. }
  1030. if(BIT(1)& data3)
  1031. {
  1032. snprintf(tmpdesc,SIZE_OF_DESC,"PA_Type:IOH|");
  1033. }
  1034. else
  1035. {
  1036. snprintf(tmpdesc,SIZE_OF_DESC,"PA-Type:CPU|");
  1037. }
  1038. strcat(desc,tmpdesc);
  1039. if(BIT(0)& data3)
  1040. {
  1041. snprintf(tmpdesc,SIZE_OF_DESC,"RA-Type:IOH");
  1042. }
  1043. else
  1044. {
  1045. snprintf(tmpdesc,SIZE_OF_DESC,"RA-Type:CPU");
  1046. }
  1047. strcat(desc,tmpdesc);
  1048. }
  1049. }
  1050. else
  1051. {
  1052. if(0x02 == (data1 & MASK_LOWER_NIBBLE))
  1053. {
  1054. sprintf(desc,"%s","IO channel Check NMI");
  1055. }
  1056. else
  1057. {
  1058. if(0x00 == (data1 & MASK_LOWER_NIBBLE))
  1059. {
  1060. snprintf(desc, SIZE_OF_DESC, "%s","PCIe Error |");
  1061. }
  1062. else if(0x01 == (data1 & MASK_LOWER_NIBBLE))
  1063. {
  1064. snprintf(desc, SIZE_OF_DESC, "%s","I/O Error |");
  1065. }
  1066. else if(0x04 == (data1 & MASK_LOWER_NIBBLE))
  1067. {
  1068. snprintf(desc, SIZE_OF_DESC, "%s","PCI PERR |");
  1069. }
  1070. else if(0x05 == (data1 & MASK_LOWER_NIBBLE))
  1071. {
  1072. snprintf(desc, SIZE_OF_DESC, "%s","PCI SERR |");
  1073. }
  1074. else
  1075. {
  1076. snprintf(desc, SIZE_OF_DESC, "%s"," ");
  1077. }
  1078. if (data3 & 0x80)
  1079. snprintf(tmpdesc, SIZE_OF_DESC, "Slot %d", data3 & 0x7F);
  1080. else
  1081. snprintf(tmpdesc, SIZE_OF_DESC, "PCI bus:%.2x device:%.2x function:%x",
  1082. data3 &0x7F, (data2 >> 3) & 0x1F,
  1083. data2 & 0x07);
  1084. strcat(desc,tmpdesc);
  1085. }
  1086. }
  1087. break;
  1088. /* POST Fatal Errors generated from the Server with much more info*/
  1089. case SENSOR_TYPE_FRM_PROG:
  1090. if((0x0F == (data1 & MASK_LOWER_NIBBLE))&&(data1 & OEM_CODE_IN_BYTE2))
  1091. {
  1092. switch(data2)
  1093. {
  1094. case 0x80:
  1095. snprintf(desc, SIZE_OF_DESC, "No memory is detected.");break;
  1096. case 0x81:
  1097. snprintf(desc,SIZE_OF_DESC, "Memory is detected but is not configurable.");break;
  1098. case 0x82:
  1099. snprintf(desc, SIZE_OF_DESC, "Memory is configured but not usable.");break;
  1100. case 0x83:
  1101. snprintf(desc, SIZE_OF_DESC, "System BIOS shadow failed.");break;
  1102. case 0x84:
  1103. snprintf(desc, SIZE_OF_DESC, "CMOS failed.");break;
  1104. case 0x85:
  1105. snprintf(desc, SIZE_OF_DESC, "DMA controller failed.");break;
  1106. case 0x86:
  1107. snprintf(desc, SIZE_OF_DESC, "Interrupt controller failed.");break;
  1108. case 0x87:
  1109. snprintf(desc, SIZE_OF_DESC, "Timer refresh failed.");break;
  1110. case 0x88:
  1111. snprintf(desc, SIZE_OF_DESC, "Programmable interval timer error.");break;
  1112. case 0x89:
  1113. snprintf(desc, SIZE_OF_DESC, "Parity error.");break;
  1114. case 0x8A:
  1115. snprintf(desc, SIZE_OF_DESC, "SIO failed.");break;
  1116. case 0x8B:
  1117. snprintf(desc, SIZE_OF_DESC, "Keyboard controller failed.");break;
  1118. case 0x8C:
  1119. snprintf(desc, SIZE_OF_DESC, "System management interrupt initialization failed.");break;
  1120. case 0x8D:
  1121. snprintf(desc, SIZE_OF_DESC, "TXT-SX Error.");break;
  1122. case 0xC0:
  1123. snprintf(desc, SIZE_OF_DESC, "Shutdown test failed.");break;
  1124. case 0xC1:
  1125. snprintf(desc, SIZE_OF_DESC, "BIOS POST memory test failed.");break;
  1126. case 0xC2:
  1127. snprintf(desc, SIZE_OF_DESC, "RAC configuration failed.");break;
  1128. case 0xC3:
  1129. snprintf(desc, SIZE_OF_DESC, "CPU configuration failed.");break;
  1130. case 0xC4:
  1131. snprintf(desc, SIZE_OF_DESC, "Incorrect memory configuration.");break;
  1132. case 0xFE:
  1133. snprintf(desc, SIZE_OF_DESC, "General failure after video.");
  1134. break;
  1135. }
  1136. }
  1137. break;
  1138. default:
  1139. break;
  1140. }
  1141. }
  1142. else
  1143. {
  1144. sensor_type = rec->sel_type.standard_type.event_type;
  1145. }
  1146. return desc;
  1147. }
  1148. char *
  1149. ipmi_get_oem_desc(struct ipmi_intf * intf, struct sel_event_record * rec)
  1150. {
  1151. char * desc = NULL;
  1152. switch (ipmi_get_oem(intf))
  1153. {
  1154. case IPMI_OEM_NEWISYS:
  1155. desc = get_newisys_evt_desc(intf, rec);
  1156. break;
  1157. case IPMI_OEM_KONTRON:
  1158. desc = get_kontron_evt_desc(intf, rec);
  1159. break;
  1160. case IPMI_OEM_DELL: // Dell Decoding of the OEM Bytes from SEL Record.
  1161. desc = get_dell_evt_desc(intf, rec);
  1162. break;
  1163. case IPMI_OEM_SUPERMICRO:
  1164. case IPMI_OEM_SUPERMICRO_47488:
  1165. desc = get_supermicro_evt_desc(intf, rec);
  1166. break;
  1167. case IPMI_OEM_UNKNOWN:
  1168. default:
  1169. break;
  1170. }
  1171. return desc;
  1172. }
  1173. const struct ipmi_event_sensor_types *
  1174. ipmi_get_first_event_sensor_type(struct ipmi_intf *intf,
  1175. uint8_t sensor_type, uint8_t event_type)
  1176. {
  1177. const struct ipmi_event_sensor_types *evt, *start, *next = NULL;
  1178. uint8_t code;
  1179. if (event_type == 0x6f) {
  1180. if (sensor_type >= 0xC0
  1181. && sensor_type < 0xF0
  1182. && ipmi_get_oem(intf) == IPMI_OEM_KONTRON) {
  1183. /* check Kontron OEM sensor event types */
  1184. start = oem_kontron_event_types;
  1185. } else if (intf->vita_avail) {
  1186. /* check VITA sensor event types first */
  1187. start = vita_sensor_event_types;
  1188. /* then check generic sensor types */
  1189. next = sensor_specific_event_types;
  1190. } else {
  1191. /* check generic sensor types */
  1192. start = sensor_specific_event_types;
  1193. }
  1194. code = sensor_type;
  1195. } else {
  1196. start = generic_event_types;
  1197. code = event_type;
  1198. }
  1199. for (evt = start; evt->desc != NULL || next != NULL; evt++) {
  1200. /* check if VITA sensor event types has finished */
  1201. if (evt->desc == NULL) {
  1202. /* proceed with next table */
  1203. evt = next;
  1204. next = NULL;
  1205. }
  1206. if (code == evt->code)
  1207. return evt;
  1208. }
  1209. return NULL;
  1210. }
  1211. const struct ipmi_event_sensor_types *
  1212. ipmi_get_next_event_sensor_type(const struct ipmi_event_sensor_types *evt)
  1213. {
  1214. const struct ipmi_event_sensor_types *start = evt;
  1215. for (evt = start + 1; evt->desc != NULL; evt++) {
  1216. if (evt->code == start->code) {
  1217. return evt;
  1218. }
  1219. }
  1220. return NULL;
  1221. }
  1222. void
  1223. ipmi_get_event_desc(struct ipmi_intf * intf, struct sel_event_record * rec, char ** desc)
  1224. {
  1225. uint8_t offset;
  1226. const struct ipmi_event_sensor_types *evt = NULL;
  1227. char *sfx = NULL; /* This will be assigned if the Platform is DELL,
  1228. additional info is appended to the current Description */
  1229. if (desc == NULL)
  1230. return;
  1231. *desc = NULL;
  1232. if ((rec->sel_type.standard_type.event_type >= 0x70) && (rec->sel_type.standard_type.event_type < 0x7F)) {
  1233. *desc = ipmi_get_oem_desc(intf, rec);
  1234. return;
  1235. } else if (rec->sel_type.standard_type.event_type == 0x6f) {
  1236. if( rec->sel_type.standard_type.sensor_type >= 0xC0 && rec->sel_type.standard_type.sensor_type < 0xF0) {
  1237. IPMI_OEM iana = ipmi_get_oem(intf);
  1238. switch(iana){
  1239. case IPMI_OEM_KONTRON:
  1240. lprintf(LOG_DEBUG, "oem sensor type %x %d using oem type supplied description",
  1241. rec->sel_type.standard_type.sensor_type , iana);
  1242. break;
  1243. case IPMI_OEM_DELL: /* OEM Bytes Decoding for DELLi */
  1244. if ( (OEM_CODE_IN_BYTE2 == (rec->sel_type.standard_type.event_data[0] & DATA_BYTE2_SPECIFIED_MASK)) ||
  1245. (OEM_CODE_IN_BYTE3 == (rec->sel_type.standard_type.event_data[0] & DATA_BYTE3_SPECIFIED_MASK)) )
  1246. {
  1247. sfx = ipmi_get_oem_desc(intf, rec);
  1248. }
  1249. break;
  1250. case IPMI_OEM_SUPERMICRO:
  1251. case IPMI_OEM_SUPERMICRO_47488:
  1252. sfx = ipmi_get_oem_desc(intf, rec);
  1253. break;
  1254. /* add your oem sensor assignation here */
  1255. default:
  1256. lprintf(LOG_DEBUG, "oem sensor type %x using standard type supplied description",
  1257. rec->sel_type.standard_type.sensor_type );
  1258. break;
  1259. }
  1260. } else {
  1261. switch (ipmi_get_oem(intf)) {
  1262. case IPMI_OEM_SUPERMICRO:
  1263. case IPMI_OEM_SUPERMICRO_47488:
  1264. sfx = ipmi_get_oem_desc(intf, rec);
  1265. break;
  1266. default:
  1267. break;
  1268. }
  1269. }
  1270. /*
  1271. * Check for the OEM DELL Interface based on the Dell Specific Vendor Code.
  1272. * If its Dell Platform, do the OEM Byte decode from the SEL Records.
  1273. * Additional information should be written by the ipmi_get_oem_desc()
  1274. */
  1275. if(ipmi_get_oem(intf) == IPMI_OEM_DELL) {
  1276. if ( (OEM_CODE_IN_BYTE2 == (rec->sel_type.standard_type.event_data[0] & DATA_BYTE2_SPECIFIED_MASK)) ||
  1277. (OEM_CODE_IN_BYTE3 == (rec->sel_type.standard_type.event_data[0] & DATA_BYTE3_SPECIFIED_MASK)) )
  1278. {
  1279. sfx = ipmi_get_oem_desc(intf, rec);
  1280. }
  1281. else if(SENSOR_TYPE_OEM_SEC_EVENT == rec->sel_type.standard_type.event_data[0])
  1282. {
  1283. /* 0x23 : Sensor Number.*/
  1284. if(0x23 == rec->sel_type.standard_type.sensor_num)
  1285. sfx = ipmi_get_oem_desc(intf, rec);
  1286. }
  1287. }
  1288. }
  1289. offset = rec->sel_type.standard_type.event_data[0] & 0xf;
  1290. for (evt = ipmi_get_first_event_sensor_type(intf,
  1291. rec->sel_type.standard_type.sensor_type,
  1292. rec->sel_type.standard_type.event_type);
  1293. evt != NULL; evt = ipmi_get_next_event_sensor_type(evt)) {
  1294. if ((evt->offset == offset && evt->desc != NULL) &&
  1295. ((evt->data == ALL_OFFSETS_SPECIFIED) ||
  1296. ((rec->sel_type.standard_type.event_data[0] & DATA_BYTE2_SPECIFIED_MASK) &&
  1297. (evt->data == rec->sel_type.standard_type.event_data[1]))))
  1298. {
  1299. /* Increase the Malloc size to current_size + Dellspecific description size */
  1300. *desc = (char *)malloc(strlen(evt->desc) + 48 + SIZE_OF_DESC);
  1301. if (NULL == *desc) {
  1302. lprintf(LOG_ERR, "ipmitool: malloc failure");
  1303. return;
  1304. }
  1305. memset(*desc, 0, strlen(evt->desc)+ 48 + SIZE_OF_DESC);
  1306. /*
  1307. * Additional info is present for the DELL Platforms.
  1308. * Append the same to the evt->desc string.
  1309. */
  1310. if (sfx) {
  1311. sprintf(*desc, "%s (%s)", evt->desc, sfx);
  1312. free(sfx);
  1313. sfx = NULL;
  1314. } else {
  1315. sprintf(*desc, "%s", evt->desc);
  1316. }
  1317. return;
  1318. }
  1319. }
  1320. /* The Above while Condition was not met beacouse the below sensor type were Newly defined OEM
  1321. Secondary Events. 0xC1, 0xC2, 0xC3. */
  1322. if((sfx) && (0x6F == rec->sel_type.standard_type.event_type))
  1323. {
  1324. uint8_t flag = 0x00;
  1325. switch(rec->sel_type.standard_type.sensor_type)
  1326. {
  1327. case SENSOR_TYPE_FRM_PROG:
  1328. if(0x0F == offset)
  1329. flag = 0x01;
  1330. break;
  1331. case SENSOR_TYPE_OEM_SEC_EVENT:
  1332. if((0x01 == offset) || (0x02 == offset) || (0x03 == offset))
  1333. flag = 0x01;
  1334. break;
  1335. case SENSOR_TYPE_OEM_NFATAL_ERROR:
  1336. if((0x00 == offset) || (0x02 == offset))
  1337. flag = 0x01;
  1338. break;
  1339. case SENSOR_TYPE_OEM_FATAL_ERROR:
  1340. if(0x01 == offset)
  1341. flag = 0x01;
  1342. break;
  1343. case SENSOR_TYPE_SUPERMICRO_OEM:
  1344. flag = 0x02;
  1345. break;
  1346. default:
  1347. break;
  1348. }
  1349. if(flag)
  1350. {
  1351. *desc = (char *)malloc( 48 + SIZE_OF_DESC);
  1352. if (NULL == *desc)
  1353. {
  1354. lprintf(LOG_ERR, "ipmitool: malloc failure");
  1355. return;
  1356. }
  1357. memset(*desc, 0, 48 + SIZE_OF_DESC);
  1358. if (flag == 0x02) {
  1359. sprintf(*desc, "%s", sfx);
  1360. return;
  1361. }
  1362. sprintf(*desc, "(%s)",sfx);
  1363. }
  1364. free(sfx);
  1365. sfx = NULL;
  1366. }
  1367. }
  1368. const char*
  1369. ipmi_get_generic_sensor_type(uint8_t code)
  1370. {
  1371. if (code <= SENSOR_TYPE_MAX) {
  1372. return ipmi_generic_sensor_type_vals[code];
  1373. }
  1374. return NULL;
  1375. }
  1376. const char *
  1377. ipmi_get_oem_sensor_type(struct ipmi_intf *intf, uint8_t code)
  1378. {
  1379. const struct oemvalstr *v, *found = NULL;
  1380. uint32_t iana = ipmi_get_oem(intf);
  1381. for (v = ipmi_oem_sensor_type_vals; v->str; v++) {
  1382. if (v->oem == iana && v->val == code) {
  1383. return v->str;
  1384. }
  1385. if ((intf->picmg_avail
  1386. && v->oem == IPMI_OEM_PICMG
  1387. && v->val == code)
  1388. || (intf->vita_avail
  1389. && v->oem == IPMI_OEM_VITA
  1390. && v->val == code)) {
  1391. found = v;
  1392. }
  1393. }
  1394. return found ? found->str : NULL;
  1395. }
  1396. const char *
  1397. ipmi_get_sensor_type(struct ipmi_intf *intf, uint8_t code)
  1398. {
  1399. const char *type;
  1400. if (code >= 0xC0) {
  1401. type = ipmi_get_oem_sensor_type(intf, code);
  1402. } else {
  1403. type = ipmi_get_generic_sensor_type(code);
  1404. }
  1405. if (type == NULL) {
  1406. type = "Unknown";
  1407. }
  1408. return type;
  1409. }
  1410. static int
  1411. ipmi_sel_get_info(struct ipmi_intf * intf)
  1412. {
  1413. struct ipmi_rs * rsp;
  1414. struct ipmi_rq req;
  1415. uint16_t e, version;
  1416. uint32_t f;
  1417. int pctfull = 0;
  1418. uint32_t fs = 0xffffffff;
  1419. uint32_t zeros = 0;
  1420. memset(&req, 0, sizeof(req));
  1421. req.msg.netfn = IPMI_NETFN_STORAGE;
  1422. req.msg.cmd = IPMI_CMD_GET_SEL_INFO;
  1423. rsp = intf->sendrecv(intf, &req);
  1424. if (rsp == NULL) {
  1425. lprintf(LOG_ERR, "Get SEL Info command failed");
  1426. return -1;
  1427. } else if (rsp->ccode > 0) {
  1428. lprintf(LOG_ERR, "Get SEL Info command failed: %s",
  1429. val2str(rsp->ccode, completion_code_vals));
  1430. return -1;
  1431. } else if (rsp->data_len != 14) {
  1432. lprintf(LOG_ERR, "Get SEL Info command failed: "
  1433. "Invalid data length %d", rsp->data_len);
  1434. return (-1);
  1435. }
  1436. if (verbose > 2)
  1437. printbuf(rsp->data, rsp->data_len, "sel_info");
  1438. printf("SEL Information\n");
  1439. version = rsp->data[0];
  1440. printf("Version : %d.%d (%s)\n",
  1441. version & 0xf, (version>>4) & 0xf,
  1442. (version == 0x51 || version == 0x02) ? "v1.5, v2 compliant" : "Unknown");
  1443. /* save the entry count and free space to determine percent full */
  1444. e = buf2short(rsp->data + 1);
  1445. f = buf2short(rsp->data + 3);
  1446. printf("Entries : %d\n", e);
  1447. printf("Free Space : %d bytes %s\n", f ,(f==65535 ? "or more" : "" ));
  1448. if (e) {
  1449. e *= 16; /* each entry takes 16 bytes */
  1450. f += e; /* this is supposed to give the total size ... */
  1451. pctfull = (int)(100 * ( (double)e / (double)f ));
  1452. }
  1453. if( f >= 65535 ) {
  1454. printf("Percent Used : %s\n", "unknown" );
  1455. }
  1456. else {
  1457. printf("Percent Used : %d%%\n", pctfull);
  1458. }
  1459. if ((!memcmp(rsp->data + 5, &fs, 4)) ||
  1460. (!memcmp(rsp->data + 5, &zeros, 4)))
  1461. printf("Last Add Time : Not Available\n");
  1462. else
  1463. printf("Last Add Time : %s\n",
  1464. ipmi_sel_timestamp(buf2long(rsp->data + 5)));
  1465. if ((!memcmp(rsp->data + 9, &fs, 4)) ||
  1466. (!memcmp(rsp->data + 9, &zeros, 4)))
  1467. printf("Last Del Time : Not Available\n");
  1468. else
  1469. printf("Last Del Time : %s\n",
  1470. ipmi_sel_timestamp(buf2long(rsp->data + 9)));
  1471. printf("Overflow : %s\n",
  1472. rsp->data[13] & 0x80 ? "true" : "false");
  1473. printf("Supported Cmds : ");
  1474. if (rsp->data[13] & 0x0f)
  1475. {
  1476. if (rsp->data[13] & 0x08)
  1477. printf("'Delete' ");
  1478. if (rsp->data[13] & 0x04)
  1479. printf("'Partial Add' ");
  1480. if (rsp->data[13] & 0x02)
  1481. printf("'Reserve' ");
  1482. if (rsp->data[13] & 0x01)
  1483. printf("'Get Alloc Info' ");
  1484. }
  1485. else
  1486. printf("None");
  1487. printf("\n");
  1488. /* get sel allocation info if supported */
  1489. if (rsp->data[13] & 1) {
  1490. memset(&req, 0, sizeof(req));
  1491. req.msg.netfn = IPMI_NETFN_STORAGE;
  1492. req.msg.cmd = IPMI_CMD_GET_SEL_ALLOC_INFO;
  1493. rsp = intf->sendrecv(intf, &req);
  1494. if (rsp == NULL) {
  1495. lprintf(LOG_ERR,
  1496. "Get SEL Allocation Info command failed");
  1497. return -1;
  1498. }
  1499. if (rsp->ccode > 0) {
  1500. lprintf(LOG_ERR,
  1501. "Get SEL Allocation Info command failed: %s",
  1502. val2str(rsp->ccode, completion_code_vals));
  1503. return -1;
  1504. }
  1505. printf("# of Alloc Units : %d\n", buf2short(rsp->data));
  1506. printf("Alloc Unit Size : %d\n", buf2short(rsp->data + 2));
  1507. printf("# Free Units : %d\n", buf2short(rsp->data + 4));
  1508. printf("Largest Free Blk : %d\n", buf2short(rsp->data + 6));
  1509. printf("Max Record Size : %d\n", rsp->data[8]);
  1510. }
  1511. return 0;
  1512. }
  1513. uint16_t
  1514. ipmi_sel_get_std_entry(struct ipmi_intf * intf, uint16_t id,
  1515. struct sel_event_record * evt)
  1516. {
  1517. struct ipmi_rq req;
  1518. struct ipmi_rs * rsp;
  1519. uint8_t msg_data[6];
  1520. uint16_t next;
  1521. int data_count;
  1522. memset(msg_data, 0, 6);
  1523. msg_data[0] = 0x00; /* no reserve id, not partial get */
  1524. msg_data[1] = 0x00;
  1525. msg_data[2] = id & 0xff;
  1526. msg_data[3] = (id >> 8) & 0xff;
  1527. msg_data[4] = 0x00; /* offset */
  1528. msg_data[5] = 0xff; /* length */
  1529. memset(&req, 0, sizeof(req));
  1530. req.msg.netfn = IPMI_NETFN_STORAGE;
  1531. req.msg.cmd = IPMI_CMD_GET_SEL_ENTRY;
  1532. req.msg.data = msg_data;
  1533. req.msg.data_len = 6;
  1534. rsp = intf->sendrecv(intf, &req);
  1535. if (rsp == NULL) {
  1536. lprintf(LOG_ERR, "Get SEL Entry %x command failed", id);
  1537. return 0;
  1538. }
  1539. if (rsp->ccode > 0) {
  1540. lprintf(LOG_ERR, "Get SEL Entry %x command failed: %s",
  1541. id, val2str(rsp->ccode, completion_code_vals));
  1542. return 0;
  1543. }
  1544. /* save next entry id */
  1545. next = (rsp->data[1] << 8) | rsp->data[0];
  1546. lprintf(LOG_DEBUG, "SEL Entry: %s", buf2str(rsp->data+2, rsp->data_len-2));
  1547. memset(evt, 0, sizeof(*evt));
  1548. /*Clear SEL Structure*/
  1549. evt->record_id = 0;
  1550. evt->record_type = 0;
  1551. if (evt->record_type < 0xc0)
  1552. {
  1553. evt->sel_type.standard_type.timestamp = 0;
  1554. evt->sel_type.standard_type.gen_id = 0;
  1555. evt->sel_type.standard_type.evm_rev = 0;
  1556. evt->sel_type.standard_type.sensor_type = 0;
  1557. evt->sel_type.standard_type.sensor_num = 0;
  1558. evt->sel_type.standard_type.event_type = 0;
  1559. evt->sel_type.standard_type.event_dir = 0;
  1560. evt->sel_type.standard_type.event_data[0] = 0;
  1561. evt->sel_type.standard_type.event_data[1] = 0;
  1562. evt->sel_type.standard_type.event_data[2] = 0;
  1563. }
  1564. else if (evt->record_type < 0xe0)
  1565. {
  1566. evt->sel_type.oem_ts_type.timestamp = 0;
  1567. evt->sel_type.oem_ts_type.manf_id[0] = 0;
  1568. evt->sel_type.oem_ts_type.manf_id[1] = 0;
  1569. evt->sel_type.oem_ts_type.manf_id[2] = 0;
  1570. for(data_count=0; data_count < SEL_OEM_TS_DATA_LEN ; data_count++)
  1571. evt->sel_type.oem_ts_type.oem_defined[data_count] = 0;
  1572. }
  1573. else
  1574. {
  1575. for(data_count=0; data_count < SEL_OEM_NOTS_DATA_LEN ; data_count++)
  1576. evt->sel_type.oem_nots_type.oem_defined[data_count] = 0;
  1577. }
  1578. /* save response into SEL event structure */
  1579. evt->record_id = (rsp->data[3] << 8) | rsp->data[2];
  1580. evt->record_type = rsp->data[4];
  1581. if (evt->record_type < 0xc0)
  1582. {
  1583. evt->sel_type.standard_type.timestamp = (rsp->data[8] << 24) | (rsp->data[7] << 16) |
  1584. (rsp->data[6] << 8) | rsp->data[5];
  1585. evt->sel_type.standard_type.gen_id = (rsp->data[10] << 8) | rsp->data[9];
  1586. evt->sel_type.standard_type.evm_rev = rsp->data[11];
  1587. evt->sel_type.standard_type.sensor_type = rsp->data[12];
  1588. evt->sel_type.standard_type.sensor_num = rsp->data[13];
  1589. evt->sel_type.standard_type.event_type = rsp->data[14] & 0x7f;
  1590. evt->sel_type.standard_type.event_dir = (rsp->data[14] & 0x80) >> 7;
  1591. evt->sel_type.standard_type.event_data[0] = rsp->data[15];
  1592. evt->sel_type.standard_type.event_data[1] = rsp->data[16];
  1593. evt->sel_type.standard_type.event_data[2] = rsp->data[17];
  1594. }
  1595. else if (evt->record_type < 0xe0)
  1596. {
  1597. evt->sel_type.oem_ts_type.timestamp= (rsp->data[8] << 24) | (rsp->data[7] << 16) |
  1598. (rsp->data[6] << 8) | rsp->data[5];
  1599. evt->sel_type.oem_ts_type.manf_id[0]= rsp->data[11];
  1600. evt->sel_type.oem_ts_type.manf_id[1]= rsp->data[10];
  1601. evt->sel_type.oem_ts_type.manf_id[2]= rsp->data[9];
  1602. for(data_count=0; data_count < SEL_OEM_TS_DATA_LEN ; data_count++)
  1603. evt->sel_type.oem_ts_type.oem_defined[data_count] = rsp->data[(data_count+12)];
  1604. }
  1605. else
  1606. {
  1607. for(data_count=0; data_count < SEL_OEM_NOTS_DATA_LEN ; data_count++)
  1608. evt->sel_type.oem_nots_type.oem_defined[data_count] = rsp->data[(data_count+5)];
  1609. }
  1610. return next;
  1611. }
  1612. static void
  1613. ipmi_sel_print_event_file(struct ipmi_intf * intf, struct sel_event_record * evt, FILE * fp)
  1614. {
  1615. char * description;
  1616. if (fp == NULL)
  1617. return;
  1618. ipmi_get_event_desc(intf, evt, &description);
  1619. fprintf(fp, "0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x # %s #0x%02x %s\n",
  1620. evt->sel_type.standard_type.evm_rev,
  1621. evt->sel_type.standard_type.sensor_type,
  1622. evt->sel_type.standard_type.sensor_num,
  1623. evt->sel_type.standard_type.event_type | (evt->sel_type.standard_type.event_dir << 7),
  1624. evt->sel_type.standard_type.event_data[0],
  1625. evt->sel_type.standard_type.event_data[1],
  1626. evt->sel_type.standard_type.event_data[2],
  1627. ipmi_get_sensor_type(intf, evt->sel_type.standard_type.sensor_type),
  1628. evt->sel_type.standard_type.sensor_num,
  1629. (description != NULL) ? description : "Unknown");
  1630. if (description != NULL) {
  1631. free(description);
  1632. description = NULL;
  1633. }
  1634. }
  1635. void
  1636. ipmi_sel_print_extended_entry(struct ipmi_intf * intf, struct sel_event_record * evt)
  1637. {
  1638. sel_extended++;
  1639. ipmi_sel_print_std_entry(intf, evt);
  1640. sel_extended--;
  1641. }
  1642. void
  1643. ipmi_sel_print_std_entry(struct ipmi_intf * intf, struct sel_event_record * evt)
  1644. {
  1645. char * description;
  1646. struct sdr_record_list * sdr = NULL;
  1647. int data_count;
  1648. if (sel_extended && (evt->record_type < 0xc0))
  1649. sdr = ipmi_sdr_find_sdr_bynumtype(intf, evt->sel_type.standard_type.gen_id, evt->sel_type.standard_type.sensor_num, evt->sel_type.standard_type.sensor_type);
  1650. if (!evt)
  1651. return;
  1652. if (csv_output)
  1653. printf("%x,", evt->record_id);
  1654. else
  1655. printf("%4x | ", evt->record_id);
  1656. if (evt->record_type == 0xf0)
  1657. {
  1658. if (csv_output)
  1659. printf(",,");
  1660. printf ("Linux kernel panic: %.11s\n", (char *) evt + 5);
  1661. return;
  1662. }
  1663. if (evt->record_type < 0xe0)
  1664. {
  1665. if ((evt->sel_type.standard_type.timestamp < 0x20000000)||(evt->sel_type.oem_ts_type.timestamp < 0x20000000)){
  1666. printf(" Pre-Init ");
  1667. if (csv_output)
  1668. printf(",");
  1669. else
  1670. printf(" |");
  1671. printf("%010d", evt->sel_type.standard_type.timestamp );
  1672. if (csv_output)
  1673. printf(",");
  1674. else
  1675. printf("| ");
  1676. }
  1677. else {
  1678. if (evt->record_type < 0xc0)
  1679. printf("%s", ipmi_sel_timestamp_date(evt->sel_type.standard_type.timestamp));
  1680. else
  1681. printf("%s", ipmi_sel_timestamp_date(evt->sel_type.oem_ts_type.timestamp));
  1682. if (csv_output)
  1683. printf(",");
  1684. else
  1685. printf(" | ");
  1686. if (evt->record_type < 0xc0)
  1687. printf("%s", ipmi_sel_timestamp_time(evt->sel_type.standard_type.timestamp));
  1688. else
  1689. printf("%s", ipmi_sel_timestamp_time(evt->sel_type.oem_ts_type.timestamp));
  1690. if (csv_output)
  1691. printf(",");
  1692. else
  1693. printf(" | ");
  1694. }
  1695. }
  1696. else
  1697. {
  1698. if (csv_output)
  1699. printf(",,");
  1700. }
  1701. if (evt->record_type >= 0xc0)
  1702. {
  1703. printf ("OEM record %02x", evt->record_type);
  1704. if (csv_output)
  1705. printf(",");
  1706. else
  1707. printf(" | ");
  1708. if(evt->record_type <= 0xdf)
  1709. {
  1710. printf ("%02x%02x%02x", evt->sel_type.oem_ts_type.manf_id[0], evt->sel_type.oem_ts_type.manf_id[1], evt->sel_type.oem_ts_type.manf_id[2]);
  1711. if (csv_output)
  1712. printf(",");
  1713. else
  1714. printf(" | ");
  1715. for(data_count=0;data_count < SEL_OEM_TS_DATA_LEN;data_count++)
  1716. printf("%02x", evt->sel_type.oem_ts_type.oem_defined[data_count]);
  1717. }
  1718. else
  1719. {
  1720. for(data_count=0;data_count < SEL_OEM_NOTS_DATA_LEN;data_count++)
  1721. printf("%02x", evt->sel_type.oem_nots_type.oem_defined[data_count]);
  1722. }
  1723. ipmi_sel_oem_message(evt, 0);
  1724. printf ("\n");
  1725. return;
  1726. }
  1727. /* lookup SDR entry based on sensor number and type */
  1728. if (sdr != NULL) {
  1729. printf("%s ", ipmi_get_sensor_type(intf,
  1730. evt->sel_type.standard_type.sensor_type));
  1731. switch (sdr->type) {
  1732. case SDR_RECORD_TYPE_FULL_SENSOR:
  1733. printf("%s", sdr->record.full->id_string);
  1734. break;
  1735. case SDR_RECORD_TYPE_COMPACT_SENSOR:
  1736. printf("%s", sdr->record.compact->id_string);
  1737. break;
  1738. case SDR_RECORD_TYPE_EVENTONLY_SENSOR:
  1739. printf("%s", sdr->record.eventonly->id_string);
  1740. break;
  1741. case SDR_RECORD_TYPE_FRU_DEVICE_LOCATOR:
  1742. printf("%s", sdr->record.fruloc->id_string);
  1743. break;
  1744. case SDR_RECORD_TYPE_MC_DEVICE_LOCATOR:
  1745. printf("%s", sdr->record.mcloc->id_string);
  1746. break;
  1747. case SDR_RECORD_TYPE_GENERIC_DEVICE_LOCATOR:
  1748. printf("%s", sdr->record.genloc->id_string);
  1749. break;
  1750. default:
  1751. printf("#%02x", evt->sel_type.standard_type.sensor_num);
  1752. break;
  1753. }
  1754. } else {
  1755. printf("%s", ipmi_get_sensor_type(intf,
  1756. evt->sel_type.standard_type.sensor_type));
  1757. if (evt->sel_type.standard_type.sensor_num != 0)
  1758. printf(" #0x%02x", evt->sel_type.standard_type.sensor_num);
  1759. }
  1760. if (csv_output)
  1761. printf(",");
  1762. else
  1763. printf(" | ");
  1764. ipmi_get_event_desc(intf, evt, &description);
  1765. if (description) {
  1766. printf("%s", description);
  1767. free(description);
  1768. description = NULL;
  1769. }
  1770. if (csv_output) {
  1771. printf(",");
  1772. } else {
  1773. printf(" | ");
  1774. }
  1775. if (evt->sel_type.standard_type.event_dir) {
  1776. printf("Deasserted");
  1777. } else {
  1778. printf("Asserted");
  1779. }
  1780. if (sdr != NULL && evt->sel_type.standard_type.event_type == 1) {
  1781. /*
  1782. * Threshold Event
  1783. */
  1784. float trigger_reading = 0.0;
  1785. float threshold_reading = 0.0;
  1786. uint8_t threshold_reading_provided = 0;
  1787. /* trigger reading in event data byte 2 */
  1788. if (((evt->sel_type.standard_type.event_data[0] >> 6) & 3) == 1) {
  1789. trigger_reading = sdr_convert_sensor_reading(
  1790. sdr->record.full, evt->sel_type.standard_type.event_data[1]);
  1791. }
  1792. /* trigger threshold in event data byte 3 */
  1793. if (((evt->sel_type.standard_type.event_data[0] >> 4) & 3) == 1) {
  1794. threshold_reading = sdr_convert_sensor_reading(
  1795. sdr->record.full, evt->sel_type.standard_type.event_data[2]);
  1796. threshold_reading_provided = 1;
  1797. }
  1798. if (csv_output)
  1799. printf(",");
  1800. else
  1801. printf(" | ");
  1802. printf("Reading %.*f",
  1803. (trigger_reading==(int)trigger_reading) ? 0 : 2,
  1804. trigger_reading);
  1805. if (threshold_reading_provided) {
  1806. printf(" %s Threshold %.*f %s",
  1807. ((evt->sel_type.standard_type.event_data[0] & 0xf) % 2) ? ">" : "<",
  1808. (threshold_reading==(int)threshold_reading) ? 0 : 2,
  1809. threshold_reading,
  1810. ipmi_sdr_get_unit_string(sdr->record.common->unit.pct,
  1811. sdr->record.common->unit.modifier,
  1812. sdr->record.common->unit.type.base,
  1813. sdr->record.common->unit.type.modifier));
  1814. }
  1815. }
  1816. else if (evt->sel_type.standard_type.event_type == 0x6f) {
  1817. int print_sensor = 1;
  1818. switch (ipmi_get_oem(intf)) {
  1819. case IPMI_OEM_SUPERMICRO:
  1820. case IPMI_OEM_SUPERMICRO_47488:
  1821. print_sensor = 0;
  1822. break;
  1823. default:
  1824. break;
  1825. }
  1826. /*
  1827. * Sensor-Specific Discrete
  1828. */
  1829. if (print_sensor && evt->sel_type.standard_type.sensor_type == 0xC && /*TODO*/
  1830. evt->sel_type.standard_type.sensor_num == 0 &&
  1831. (evt->sel_type.standard_type.event_data[0] & 0x30) == 0x20) {
  1832. /* break down memory ECC reporting if we can */
  1833. if (csv_output)
  1834. printf(",");
  1835. else
  1836. printf(" | ");
  1837. printf("CPU %d DIMM %d",
  1838. evt->sel_type.standard_type.event_data[2] & 0x0f,
  1839. (evt->sel_type.standard_type.event_data[2] & 0xf0) >> 4);
  1840. }
  1841. }
  1842. printf("\n");
  1843. }
  1844. void
  1845. ipmi_sel_print_std_entry_verbose(struct ipmi_intf * intf, struct sel_event_record * evt)
  1846. {
  1847. char * description;
  1848. int data_count;
  1849. if (!evt)
  1850. return;
  1851. printf("SEL Record ID : %04x\n", evt->record_id);
  1852. if (evt->record_type == 0xf0)
  1853. {
  1854. printf (" Record Type : Linux kernel panic (OEM record %02x)\n", evt->record_type);
  1855. printf (" Panic string : %.11s\n\n", (char *) evt + 5);
  1856. return;
  1857. }
  1858. printf(" Record Type : %02x", evt->record_type);
  1859. if (evt->record_type >= 0xc0)
  1860. {
  1861. if (evt->record_type < 0xe0)
  1862. printf(" (OEM timestamped)");
  1863. else
  1864. printf(" (OEM non-timestamped)");
  1865. }
  1866. printf("\n");
  1867. if (evt->record_type < 0xe0)
  1868. {
  1869. printf(" Timestamp : ");
  1870. if (evt->record_type < 0xc0)
  1871. printf("%s %s", ipmi_sel_timestamp_date(evt->sel_type.standard_type.timestamp),
  1872. ipmi_sel_timestamp_time(evt->sel_type.standard_type.timestamp));
  1873. else
  1874. printf("%s %s", ipmi_sel_timestamp_date(evt->sel_type.oem_ts_type.timestamp),
  1875. ipmi_sel_timestamp_time(evt->sel_type.oem_ts_type.timestamp));
  1876. printf("\n");
  1877. }
  1878. if (evt->record_type >= 0xc0)
  1879. {
  1880. if(evt->record_type <= 0xdf)
  1881. {
  1882. printf (" Manufactacturer ID : %02x%02x%02x\n", evt->sel_type.oem_ts_type.manf_id[0],
  1883. evt->sel_type.oem_ts_type.manf_id[1], evt->sel_type.oem_ts_type.manf_id[2]);
  1884. printf (" OEM Defined : ");
  1885. for(data_count=0;data_count < SEL_OEM_TS_DATA_LEN;data_count++)
  1886. printf("%02x", evt->sel_type.oem_ts_type.oem_defined[data_count]);
  1887. printf(" [%s]\n\n",hex2ascii (evt->sel_type.oem_ts_type.oem_defined, SEL_OEM_TS_DATA_LEN));
  1888. }
  1889. else
  1890. {
  1891. printf (" OEM Defined : ");
  1892. for(data_count=0;data_count < SEL_OEM_NOTS_DATA_LEN;data_count++)
  1893. printf("%02x", evt->sel_type.oem_nots_type.oem_defined[data_count]);
  1894. printf(" [%s]\n\n",hex2ascii (evt->sel_type.oem_nots_type.oem_defined, SEL_OEM_NOTS_DATA_LEN));
  1895. ipmi_sel_oem_message(evt, 1);
  1896. }
  1897. return;
  1898. }
  1899. printf(" Generator ID : %04x\n",
  1900. evt->sel_type.standard_type.gen_id);
  1901. printf(" EvM Revision : %02x\n",
  1902. evt->sel_type.standard_type.evm_rev);
  1903. printf(" Sensor Type : %s\n",
  1904. ipmi_get_sensor_type(intf,
  1905. evt->sel_type.standard_type.sensor_type));
  1906. printf(" Sensor Number : %02x\n",
  1907. evt->sel_type.standard_type.sensor_num);
  1908. printf(" Event Type : %s\n",
  1909. ipmi_get_event_type(evt->sel_type.standard_type.event_type));
  1910. printf(" Event Direction : %s\n",
  1911. val2str(evt->sel_type.standard_type.event_dir, event_dir_vals));
  1912. printf(" Event Data : %02x%02x%02x\n",
  1913. evt->sel_type.standard_type.event_data[0], evt->sel_type.standard_type.event_data[1], evt->sel_type.standard_type.event_data[2]);
  1914. ipmi_get_event_desc(intf, evt, &description);
  1915. printf(" Description : %s\n",
  1916. description ? description : "");
  1917. free(description);
  1918. description = NULL;
  1919. printf("\n");
  1920. }
  1921. void
  1922. ipmi_sel_print_extended_entry_verbose(struct ipmi_intf * intf, struct sel_event_record * evt)
  1923. {
  1924. struct sdr_record_list * sdr;
  1925. char * description;
  1926. if (!evt)
  1927. return;
  1928. sdr = ipmi_sdr_find_sdr_bynumtype(intf,
  1929. evt->sel_type.standard_type.gen_id,
  1930. evt->sel_type.standard_type.sensor_num,
  1931. evt->sel_type.standard_type.sensor_type);
  1932. if (sdr == NULL)
  1933. {
  1934. ipmi_sel_print_std_entry_verbose(intf, evt);
  1935. return;
  1936. }
  1937. printf("SEL Record ID : %04x\n", evt->record_id);
  1938. if (evt->record_type == 0xf0)
  1939. {
  1940. printf (" Record Type : "
  1941. "Linux kernel panic (OEM record %02x)\n",
  1942. evt->record_type);
  1943. printf (" Panic string : %.11s\n\n",
  1944. (char *) evt + 5);
  1945. return;
  1946. }
  1947. printf(" Record Type : %02x\n", evt->record_type);
  1948. if (evt->record_type < 0xe0)
  1949. {
  1950. printf(" Timestamp : ");
  1951. printf("%s %s\n", ipmi_sel_timestamp_date(evt->sel_type.standard_type.timestamp),
  1952. ipmi_sel_timestamp_time(evt->sel_type.standard_type.timestamp));
  1953. }
  1954. printf(" Generator ID : %04x\n",
  1955. evt->sel_type.standard_type.gen_id);
  1956. printf(" EvM Revision : %02x\n",
  1957. evt->sel_type.standard_type.evm_rev);
  1958. printf(" Sensor Type : %s\n",
  1959. ipmi_get_sensor_type(intf, evt->sel_type.standard_type.sensor_type));
  1960. printf(" Sensor Number : %02x\n",
  1961. evt->sel_type.standard_type.sensor_num);
  1962. printf(" Event Type : %s\n",
  1963. ipmi_get_event_type(evt->sel_type.standard_type.event_type));
  1964. printf(" Event Direction : %s\n",
  1965. val2str(evt->sel_type.standard_type.event_dir, event_dir_vals));
  1966. printf(" Event Data (RAW) : %02x%02x%02x\n",
  1967. evt->sel_type.standard_type.event_data[0], evt->sel_type.standard_type.event_data[1], evt->sel_type.standard_type.event_data[2]);
  1968. /* break down event data field
  1969. * as per IPMI Spec 2.0 Table 29-6 */
  1970. if (evt->sel_type.standard_type.event_type == 1 && sdr->type == SDR_RECORD_TYPE_FULL_SENSOR) {
  1971. /* Threshold */
  1972. switch ((evt->sel_type.standard_type.event_data[0] >> 6) & 3) { /* EV1[7:6] */
  1973. case 0:
  1974. /* unspecified byte 2 */
  1975. break;
  1976. case 1:
  1977. /* trigger reading in byte 2 */
  1978. printf(" Trigger Reading : %.3f",
  1979. sdr_convert_sensor_reading(sdr->record.full,
  1980. evt->sel_type.standard_type.event_data[1]));
  1981. /* determine units with possible modifiers */
  1982. printf ("%s\n", ipmi_sdr_get_unit_string(sdr->record.common->unit.pct,
  1983. sdr->record.common->unit.modifier,
  1984. sdr->record.common->unit.type.base,
  1985. sdr->record.common->unit.type.modifier));
  1986. break;
  1987. case 2:
  1988. /* oem code in byte 2 */
  1989. printf(" OEM Data : %02x\n",
  1990. evt->sel_type.standard_type.event_data[1]);
  1991. break;
  1992. case 3:
  1993. /* sensor-specific extension code in byte 2 */
  1994. printf(" Sensor Extension Code : %02x\n",
  1995. evt->sel_type.standard_type.event_data[1]);
  1996. break;
  1997. }
  1998. switch ((evt->sel_type.standard_type.event_data[0] >> 4) & 3) { /* EV1[5:4] */
  1999. case 0:
  2000. /* unspecified byte 3 */
  2001. break;
  2002. case 1:
  2003. /* trigger threshold value in byte 3 */
  2004. printf(" Trigger Threshold : %.3f",
  2005. sdr_convert_sensor_reading(sdr->record.full,
  2006. evt->sel_type.standard_type.event_data[2]));
  2007. /* determine units with possible modifiers */
  2008. printf ("%s\n", ipmi_sdr_get_unit_string(sdr->record.common->unit.pct,
  2009. sdr->record.common->unit.modifier,
  2010. sdr->record.common->unit.type.base,
  2011. sdr->record.common->unit.type.modifier));
  2012. break;
  2013. case 2:
  2014. /* OEM code in byte 3 */
  2015. printf(" OEM Data : %02x\n",
  2016. evt->sel_type.standard_type.event_data[2]);
  2017. break;
  2018. case 3:
  2019. /* sensor-specific extension code in byte 3 */
  2020. printf(" Sensor Extension Code : %02x\n",
  2021. evt->sel_type.standard_type.event_data[2]);
  2022. break;
  2023. }
  2024. } else if (evt->sel_type.standard_type.event_type >= 0x2 && evt->sel_type.standard_type.event_type <= 0xc) {
  2025. /* Generic Discrete */
  2026. } else if (evt->sel_type.standard_type.event_type == 0x6f) {
  2027. /* Sensor-Specific Discrete */
  2028. if (evt->sel_type.standard_type.sensor_type == 0xC &&
  2029. evt->sel_type.standard_type.sensor_num == 0 && /**** THIS LOOK TO BE OEM ****/
  2030. (evt->sel_type.standard_type.event_data[0] & 0x30) == 0x20)
  2031. {
  2032. /* break down memory ECC reporting if we can */
  2033. printf(" Event Data : CPU %d DIMM %d\n",
  2034. evt->sel_type.standard_type.event_data[2] & 0x0f,
  2035. (evt->sel_type.standard_type.event_data[2] & 0xf0) >> 4);
  2036. }
  2037. else if(
  2038. evt->sel_type.standard_type.sensor_type == 0x2b && /* Version change */
  2039. evt->sel_type.standard_type.event_data[0] == 0xC1 /* Data in Data 2 */
  2040. )
  2041. {
  2042. //evt->sel_type.standard_type.event_data[1]
  2043. }
  2044. else
  2045. {
  2046. /* FIXME : Add sensor specific discrete types */
  2047. printf(" Event Interpretation : Missing\n");
  2048. }
  2049. } else if (evt->sel_type.standard_type.event_type >= 0x70 && evt->sel_type.standard_type.event_type <= 0x7f) {
  2050. /* OEM */
  2051. } else {
  2052. printf(" Event Data : %02x%02x%02x\n",
  2053. evt->sel_type.standard_type.event_data[0], evt->sel_type.standard_type.event_data[1], evt->sel_type.standard_type.event_data[2]);
  2054. }
  2055. ipmi_get_event_desc(intf, evt, &description);
  2056. printf(" Description : %s\n",
  2057. description ? description : "");
  2058. free(description);
  2059. description = NULL;
  2060. printf("\n");
  2061. }
  2062. static int
  2063. __ipmi_sel_savelist_entries(struct ipmi_intf * intf, int count, const char * savefile,
  2064. int binary)
  2065. {
  2066. struct ipmi_rs * rsp;
  2067. struct ipmi_rq req;
  2068. uint16_t next_id = 0, curr_id = 0;
  2069. struct sel_event_record evt;
  2070. int n=0;
  2071. FILE * fp = NULL;
  2072. memset(&req, 0, sizeof(req));
  2073. req.msg.netfn = IPMI_NETFN_STORAGE;
  2074. req.msg.cmd = IPMI_CMD_GET_SEL_INFO;
  2075. rsp = intf->sendrecv(intf, &req);
  2076. if (rsp == NULL) {
  2077. lprintf(LOG_ERR, "Get SEL Info command failed");
  2078. return -1;
  2079. }
  2080. if (rsp->ccode > 0) {
  2081. lprintf(LOG_ERR, "Get SEL Info command failed: %s",
  2082. val2str(rsp->ccode, completion_code_vals));
  2083. return -1;
  2084. }
  2085. if (verbose > 2)
  2086. printbuf(rsp->data, rsp->data_len, "sel_info");
  2087. if (rsp->data[1] == 0 && rsp->data[2] == 0) {
  2088. lprintf(LOG_ERR, "SEL has no entries");
  2089. return 0;
  2090. }
  2091. memset(&req, 0, sizeof(req));
  2092. req.msg.netfn = IPMI_NETFN_STORAGE;
  2093. req.msg.cmd = IPMI_CMD_RESERVE_SEL;
  2094. rsp = intf->sendrecv(intf, &req);
  2095. if (rsp == NULL) {
  2096. lprintf(LOG_ERR, "Reserve SEL command failed");
  2097. return -1;
  2098. }
  2099. if (rsp->ccode > 0) {
  2100. lprintf(LOG_ERR, "Reserve SEL command failed: %s",
  2101. val2str(rsp->ccode, completion_code_vals));
  2102. return -1;
  2103. }
  2104. if (count < 0) {
  2105. /** Show only the most recent 'count' records. */
  2106. int i;
  2107. uint16_t entries;
  2108. req.msg.cmd = IPMI_CMD_GET_SEL_INFO;
  2109. rsp = intf->sendrecv(intf, &req);
  2110. if (rsp == NULL) {
  2111. lprintf(LOG_ERR, "Get SEL Info command failed");
  2112. return -1;
  2113. }
  2114. if (rsp->ccode > 0) {
  2115. lprintf(LOG_ERR, "Get SEL Info command failed: %s",
  2116. val2str(rsp->ccode, completion_code_vals));
  2117. return -1;
  2118. }
  2119. entries = buf2short(rsp->data + 1);
  2120. if (-count > entries)
  2121. count = -entries;
  2122. for(i = 0; i < entries + count; i++) {
  2123. next_id = ipmi_sel_get_std_entry(intf, next_id, &evt);
  2124. if (next_id == 0) {
  2125. /*
  2126. * usually next_id of zero means end but
  2127. * retry because some hardware has quirks
  2128. * and will return 0 randomly.
  2129. */
  2130. next_id = ipmi_sel_get_std_entry(intf, next_id, &evt);
  2131. if (next_id == 0) {
  2132. break;
  2133. }
  2134. }
  2135. }
  2136. }
  2137. if (savefile != NULL) {
  2138. fp = ipmi_open_file_write(savefile);
  2139. }
  2140. while (next_id != 0xffff) {
  2141. curr_id = next_id;
  2142. lprintf(LOG_DEBUG, "SEL Next ID: %04x", curr_id);
  2143. next_id = ipmi_sel_get_std_entry(intf, curr_id, &evt);
  2144. if (next_id == 0) {
  2145. /*
  2146. * usually next_id of zero means end but
  2147. * retry because some hardware has quirks
  2148. * and will return 0 randomly.
  2149. */
  2150. next_id = ipmi_sel_get_std_entry(intf, curr_id, &evt);
  2151. if (next_id == 0)
  2152. break;
  2153. }
  2154. if (verbose)
  2155. ipmi_sel_print_std_entry_verbose(intf, &evt);
  2156. else
  2157. ipmi_sel_print_std_entry(intf, &evt);
  2158. if (fp != NULL) {
  2159. if (binary)
  2160. fwrite(&evt, 1, 16, fp);
  2161. else
  2162. ipmi_sel_print_event_file(intf, &evt, fp);
  2163. }
  2164. if (++n == count) {
  2165. break;
  2166. }
  2167. }
  2168. if (fp != NULL)
  2169. fclose(fp);
  2170. return 0;
  2171. }
  2172. static int
  2173. ipmi_sel_list_entries(struct ipmi_intf * intf, int count)
  2174. {
  2175. return __ipmi_sel_savelist_entries(intf, count, NULL, 0);
  2176. }
  2177. static int
  2178. ipmi_sel_save_entries(struct ipmi_intf * intf, int count, const char * savefile)
  2179. {
  2180. return __ipmi_sel_savelist_entries(intf, count, savefile, 0);
  2181. }
  2182. /*
  2183. * ipmi_sel_interpret
  2184. *
  2185. * return 0 on success,
  2186. * -1 on error
  2187. */
  2188. static int
  2189. ipmi_sel_interpret(struct ipmi_intf *intf, unsigned long iana,
  2190. const char *readfile, const char *format)
  2191. {
  2192. FILE *fp = 0;
  2193. struct sel_event_record evt;
  2194. char *buffer = NULL;
  2195. char *cursor = NULL;
  2196. int status = 0;
  2197. /* since the interface is not used, iana is taken from
  2198. * the command line
  2199. */
  2200. sel_iana = iana;
  2201. if (strncmp("pps", format, 3) == 0) {
  2202. /* Parser for the following format */
  2203. /* 0x001F: Event: at Mar 27 06:41:10 2007;from:(0x9a,0,7);
  2204. * sensor:(0xc3,119); event:0x6f(asserted): 0xA3 0x00 0x88
  2205. * commonly found in PPS shelf managers
  2206. * Supports a tweak for hotswap events that are already interpreted.
  2207. */
  2208. fp = ipmi_open_file(readfile, 0);
  2209. if (fp == NULL) {
  2210. lprintf(LOG_ERR, "Failed to open file '%s' for reading.",
  2211. readfile);
  2212. return (-1);
  2213. }
  2214. buffer = (char *)malloc((size_t)256);
  2215. if (buffer == NULL) {
  2216. lprintf(LOG_ERR, "ipmitool: malloc failure");
  2217. fclose(fp);
  2218. return (-1);
  2219. }
  2220. do {
  2221. /* Only allow complete lines to be parsed,
  2222. * hardcoded maximum line length
  2223. */
  2224. if (fgets(buffer, 256, fp) == NULL) {
  2225. status = (-1);
  2226. break;
  2227. }
  2228. if (strlen(buffer) > 255) {
  2229. lprintf(LOG_ERR, "ipmitool: invalid entry found in file.");
  2230. continue;
  2231. }
  2232. cursor = buffer;
  2233. /* assume normal "System" event */
  2234. evt.record_type = 2;
  2235. errno = 0;
  2236. evt.record_id = strtol((const char *)cursor, (char **)NULL, 16);
  2237. if (errno != 0) {
  2238. lprintf(LOG_ERR, "Invalid record ID.");
  2239. status = (-1);
  2240. break;
  2241. }
  2242. evt.sel_type.standard_type.evm_rev = 4;
  2243. /* FIXME: convert*/
  2244. /* evt.sel_type.standard_type.timestamp; */
  2245. /* skip timestamp */
  2246. cursor = index((const char *)cursor, ';');
  2247. cursor++;
  2248. /* FIXME: parse originator */
  2249. evt.sel_type.standard_type.gen_id = 0x0020;
  2250. /* skip originator info */
  2251. cursor = index((const char *)cursor, ';');
  2252. cursor++;
  2253. /* Get sensor type */
  2254. cursor = index((const char *)cursor, '(');
  2255. cursor++;
  2256. errno = 0;
  2257. evt.sel_type.standard_type.sensor_type =
  2258. strtol((const char *)cursor, (char **)NULL, 16);
  2259. if (errno != 0) {
  2260. lprintf(LOG_ERR, "Invalid Sensor Type.");
  2261. status = (-1);
  2262. break;
  2263. }
  2264. cursor = index((const char *)cursor, ',');
  2265. cursor++;
  2266. errno = 0;
  2267. evt.sel_type.standard_type.sensor_num =
  2268. strtol((const char *)cursor, (char **)NULL, 10);
  2269. if (errno != 0) {
  2270. lprintf(LOG_ERR, "Invalid Sensor Number.");
  2271. status = (-1);
  2272. break;
  2273. }
  2274. /* skip to event type info */
  2275. cursor = index((const char *)cursor, ':');
  2276. cursor++;
  2277. errno = 0;
  2278. evt.sel_type.standard_type.event_type=
  2279. strtol((const char *)cursor, (char **)NULL, 16);
  2280. if (errno != 0) {
  2281. lprintf(LOG_ERR, "Invalid Event Type.");
  2282. status = (-1);
  2283. break;
  2284. }
  2285. /* skip to event dir info */
  2286. cursor = index((const char *)cursor, '(');
  2287. cursor++;
  2288. if (*cursor == 'a') {
  2289. evt.sel_type.standard_type.event_dir = 0;
  2290. } else {
  2291. evt.sel_type.standard_type.event_dir = 1;
  2292. }
  2293. /* skip to data info */
  2294. cursor = index((const char *)cursor, ' ');
  2295. cursor++;
  2296. if (evt.sel_type.standard_type.sensor_type == 0xF0) {
  2297. /* got to FRU id */
  2298. while (!isdigit(*cursor)) {
  2299. cursor++;
  2300. }
  2301. /* store FRUid */
  2302. errno = 0;
  2303. evt.sel_type.standard_type.event_data[2] =
  2304. strtol(cursor, (char **)NULL, 10);
  2305. if (errno != 0) {
  2306. lprintf(LOG_ERR, "Invalid Event Data#2.");
  2307. status = (-1);
  2308. break;
  2309. }
  2310. /* Get to previous state */
  2311. cursor = index((const char *)cursor, 'M');
  2312. cursor++;
  2313. /* Set previous state */
  2314. errno = 0;
  2315. evt.sel_type.standard_type.event_data[1] =
  2316. strtol(cursor, (char **)NULL, 10);
  2317. if (errno != 0) {
  2318. lprintf(LOG_ERR, "Invalid Event Data#1.");
  2319. status = (-1);
  2320. break;
  2321. }
  2322. /* Get to current state */
  2323. cursor = index((const char *)cursor, 'M');
  2324. cursor++;
  2325. /* Set current state */
  2326. errno = 0;
  2327. evt.sel_type.standard_type.event_data[0] =
  2328. 0xA0 | strtol(cursor, (char **)NULL, 10);
  2329. if (errno != 0) {
  2330. lprintf(LOG_ERR, "Invalid Event Data#0.");
  2331. status = (-1);
  2332. break;
  2333. }
  2334. /* skip to cause */
  2335. cursor = index((const char *)cursor, '=');
  2336. cursor++;
  2337. errno = 0;
  2338. evt.sel_type.standard_type.event_data[1] |=
  2339. (strtol(cursor, (char **)NULL, 16)) << 4;
  2340. if (errno != 0) {
  2341. lprintf(LOG_ERR, "Invalid Event Data#1.");
  2342. status = (-1);
  2343. break;
  2344. }
  2345. } else if (*cursor == '0') {
  2346. errno = 0;
  2347. evt.sel_type.standard_type.event_data[0] =
  2348. strtol((const char *)cursor, (char **)NULL, 16);
  2349. if (errno != 0) {
  2350. lprintf(LOG_ERR, "Invalid Event Data#0.");
  2351. status = (-1);
  2352. break;
  2353. }
  2354. cursor = index((const char *)cursor, ' ');
  2355. cursor++;
  2356. errno = 0;
  2357. evt.sel_type.standard_type.event_data[1] =
  2358. strtol((const char *)cursor, (char **)NULL, 16);
  2359. if (errno != 0) {
  2360. lprintf(LOG_ERR, "Invalid Event Data#1.");
  2361. status = (-1);
  2362. break;
  2363. }
  2364. cursor = index((const char *)cursor, ' ');
  2365. cursor++;
  2366. errno = 0;
  2367. evt.sel_type.standard_type.event_data[2] =
  2368. strtol((const char *)cursor, (char **)NULL, 16);
  2369. if (errno != 0) {
  2370. lprintf(LOG_ERR, "Invalid Event Data#2.");
  2371. status = (-1);
  2372. break;
  2373. }
  2374. } else {
  2375. lprintf(LOG_ERR, "ipmitool: can't guess format.");
  2376. }
  2377. /* parse the PPS line into a sel_event_record */
  2378. if (verbose) {
  2379. ipmi_sel_print_std_entry_verbose(intf, &evt);
  2380. } else {
  2381. ipmi_sel_print_std_entry(intf, &evt);
  2382. }
  2383. cursor = NULL;
  2384. } while (status == 0); /* until file is completely read */
  2385. cursor = NULL;
  2386. free(buffer);
  2387. buffer = NULL;
  2388. fclose(fp);
  2389. } else {
  2390. lprintf(LOG_ERR, "Given format '%s' is unknown.", format);
  2391. status = (-1);
  2392. }
  2393. return status;
  2394. }
  2395. static int
  2396. ipmi_sel_writeraw(struct ipmi_intf * intf, const char * savefile)
  2397. {
  2398. return __ipmi_sel_savelist_entries(intf, 0, savefile, 1);
  2399. }
  2400. static int
  2401. ipmi_sel_readraw(struct ipmi_intf * intf, const char * inputfile)
  2402. {
  2403. struct sel_event_record evt;
  2404. int ret = 0;
  2405. FILE* fp = 0;
  2406. fp = ipmi_open_file(inputfile, 0);
  2407. if (fp)
  2408. {
  2409. size_t bytesRead;
  2410. do {
  2411. if ((bytesRead = fread(&evt, 1, 16, fp)) == 16)
  2412. {
  2413. if (verbose)
  2414. ipmi_sel_print_std_entry_verbose(intf, &evt);
  2415. else
  2416. ipmi_sel_print_std_entry(intf, &evt);
  2417. }
  2418. else
  2419. {
  2420. if (bytesRead != 0)
  2421. {
  2422. lprintf(LOG_ERR, "ipmitool: incomplete record found in file.");
  2423. ret = -1;
  2424. }
  2425. break;
  2426. }
  2427. } while (1);
  2428. fclose(fp);
  2429. }
  2430. else
  2431. {
  2432. lprintf(LOG_ERR, "ipmitool: could not open input file.");
  2433. ret = -1;
  2434. }
  2435. return ret;
  2436. }
  2437. static uint16_t
  2438. ipmi_sel_reserve(struct ipmi_intf * intf)
  2439. {
  2440. struct ipmi_rs * rsp;
  2441. struct ipmi_rq req;
  2442. memset(&req, 0, sizeof(req));
  2443. req.msg.netfn = IPMI_NETFN_STORAGE;
  2444. req.msg.cmd = IPMI_CMD_RESERVE_SEL;
  2445. rsp = intf->sendrecv(intf, &req);
  2446. if (rsp == NULL) {
  2447. lprintf(LOG_WARN, "Unable to reserve SEL");
  2448. return 0;
  2449. }
  2450. if (rsp->ccode > 0) {
  2451. printf("Unable to reserve SEL: %s",
  2452. val2str(rsp->ccode, completion_code_vals));
  2453. return 0;
  2454. }
  2455. return (rsp->data[0] | (rsp->data[1] << 8));
  2456. }
  2457. /*
  2458. * ipmi_sel_get_time
  2459. *
  2460. * return 0 on success,
  2461. * -1 on error
  2462. */
  2463. static int
  2464. ipmi_sel_get_time(struct ipmi_intf * intf)
  2465. {
  2466. struct ipmi_rs * rsp;
  2467. struct ipmi_rq req;
  2468. static char tbuf[40];
  2469. uint32_t timei;
  2470. time_t time;
  2471. memset(&req, 0, sizeof(req));
  2472. req.msg.netfn = IPMI_NETFN_STORAGE;
  2473. req.msg.cmd = IPMI_GET_SEL_TIME;
  2474. rsp = intf->sendrecv(intf, &req);
  2475. if (rsp == NULL) {
  2476. lprintf(LOG_ERR, "Get SEL Time command failed");
  2477. return -1;
  2478. }
  2479. if (rsp->ccode > 0) {
  2480. lprintf(LOG_ERR, "Get SEL Time command failed: %s",
  2481. val2str(rsp->ccode, completion_code_vals));
  2482. return -1;
  2483. }
  2484. if (rsp->data_len != 4) {
  2485. lprintf(LOG_ERR, "Get SEL Time command failed: "
  2486. "Invalid data length %d", rsp->data_len);
  2487. return -1;
  2488. }
  2489. memcpy(&timei, rsp->data, 4);
  2490. #if WORDS_BIGENDIAN
  2491. time = (time_t)(BSWAP_32(timei));
  2492. #else
  2493. time = (time_t)timei;
  2494. #endif
  2495. strftime(tbuf, sizeof(tbuf), "%m/%d/%Y %H:%M:%S", gmtime(&time));
  2496. printf("%s\n", tbuf);
  2497. return 0;
  2498. }
  2499. /*
  2500. * ipmi_sel_set_time
  2501. *
  2502. * return 0 on success,
  2503. * -1 on error
  2504. */
  2505. static int
  2506. ipmi_sel_set_time(struct ipmi_intf * intf, const char * time_string)
  2507. {
  2508. struct ipmi_rs * rsp;
  2509. struct ipmi_rq req;
  2510. struct tm tm = {0};
  2511. time_t t;
  2512. uint32_t timei;
  2513. const char * time_format = "%m/%d/%Y %H:%M:%S";
  2514. memset(&req, 0, sizeof(req));
  2515. req.msg.netfn = IPMI_NETFN_STORAGE;
  2516. req.msg.cmd = IPMI_SET_SEL_TIME;
  2517. /* See if user requested set to current client system time */
  2518. if (strncasecmp(time_string, "now", 3) == 0) {
  2519. t = time(NULL);
  2520. }
  2521. else {
  2522. /* Now how do we get our time_t from our ascii version? */
  2523. if (strptime(time_string, time_format, &tm) == 0) {
  2524. lprintf(LOG_ERR, "Specified time could not be parsed");
  2525. return -1;
  2526. }
  2527. tm.tm_isdst = (-1); /* look up DST information */
  2528. t = mktime(&tm);
  2529. if (t < 0) {
  2530. lprintf(LOG_ERR, "Specified time could not be parsed");
  2531. return -1;
  2532. }
  2533. }
  2534. {
  2535. //modify UTC time to local time expressed in number of seconds from 1/1/70 0:0:0 1970 GMT
  2536. struct tm * tm_tmp = {0};
  2537. int gt_year,gt_yday,gt_hour,gt_min,lt_year,lt_yday,lt_hour,lt_min;
  2538. int delta_hour;
  2539. tm_tmp=gmtime(&t);
  2540. gt_year=tm_tmp->tm_year;
  2541. gt_yday=tm_tmp->tm_yday;
  2542. gt_hour=tm_tmp->tm_hour;
  2543. gt_min=tm_tmp->tm_min;
  2544. memset(&*tm_tmp, 0, sizeof(struct tm));
  2545. tm_tmp=localtime(&t);
  2546. lt_year=tm_tmp->tm_year;
  2547. lt_yday=tm_tmp->tm_yday;
  2548. lt_hour=tm_tmp->tm_hour;
  2549. lt_min=tm_tmp->tm_min;
  2550. delta_hour=lt_hour - gt_hour;
  2551. if ( (lt_year > gt_year) || ((lt_year == gt_year) && (lt_yday > gt_yday)) )
  2552. delta_hour += 24;
  2553. if ( (lt_year < gt_year) || ((lt_year == gt_year) && (lt_yday < gt_yday)) )
  2554. delta_hour -= 24;
  2555. t += (delta_hour * 60 * 60) + (lt_min - gt_min) * 60;
  2556. }
  2557. timei = (uint32_t)t;
  2558. req.msg.data = (uint8_t *)&timei;
  2559. req.msg.data_len = 4;
  2560. #if WORDS_BIGENDIAN
  2561. timei = BSWAP_32(timei);
  2562. #endif
  2563. rsp = intf->sendrecv(intf, &req);
  2564. if (rsp == NULL) {
  2565. lprintf(LOG_ERR, "Set SEL Time command failed");
  2566. return -1;
  2567. }
  2568. if (rsp->ccode > 0) {
  2569. lprintf(LOG_ERR, "Set SEL Time command failed: %s",
  2570. val2str(rsp->ccode, completion_code_vals));
  2571. return -1;
  2572. }
  2573. ipmi_sel_get_time(intf);
  2574. return 0;
  2575. }
  2576. static int
  2577. ipmi_sel_clear(struct ipmi_intf * intf)
  2578. {
  2579. struct ipmi_rs * rsp;
  2580. struct ipmi_rq req;
  2581. uint16_t reserve_id;
  2582. uint8_t msg_data[6];
  2583. reserve_id = ipmi_sel_reserve(intf);
  2584. if (reserve_id == 0)
  2585. return -1;
  2586. memset(msg_data, 0, 6);
  2587. msg_data[0] = reserve_id & 0xff;
  2588. msg_data[1] = reserve_id >> 8;
  2589. msg_data[2] = 'C';
  2590. msg_data[3] = 'L';
  2591. msg_data[4] = 'R';
  2592. msg_data[5] = 0xaa;
  2593. memset(&req, 0, sizeof(req));
  2594. req.msg.netfn = IPMI_NETFN_STORAGE;
  2595. req.msg.cmd = IPMI_CMD_CLEAR_SEL;
  2596. req.msg.data = msg_data;
  2597. req.msg.data_len = 6;
  2598. rsp = intf->sendrecv(intf, &req);
  2599. if (rsp == NULL) {
  2600. lprintf(LOG_ERR, "Unable to clear SEL");
  2601. return -1;
  2602. }
  2603. if (rsp->ccode > 0) {
  2604. lprintf(LOG_ERR, "Unable to clear SEL: %s",
  2605. val2str(rsp->ccode, completion_code_vals));
  2606. return -1;
  2607. }
  2608. printf("Clearing SEL. Please allow a few seconds to erase.\n");
  2609. return 0;
  2610. }
  2611. static int
  2612. ipmi_sel_delete(struct ipmi_intf * intf, int argc, char ** argv)
  2613. {
  2614. struct ipmi_rs * rsp;
  2615. struct ipmi_rq req;
  2616. uint16_t id;
  2617. uint8_t msg_data[4];
  2618. int rc = 0;
  2619. if (argc == 0 || strncmp(argv[0], "help", 4) == 0) {
  2620. lprintf(LOG_ERR, "usage: delete <id>...<id>\n");
  2621. return -1;
  2622. }
  2623. id = ipmi_sel_reserve(intf);
  2624. if (id == 0)
  2625. return -1;
  2626. memset(msg_data, 0, 4);
  2627. msg_data[0] = id & 0xff;
  2628. msg_data[1] = id >> 8;
  2629. for (; argc != 0; argc--)
  2630. {
  2631. if (str2ushort(argv[argc-1], &id) != 0) {
  2632. lprintf(LOG_ERR, "Given SEL ID '%s' is invalid.",
  2633. argv[argc-1]);
  2634. rc = (-1);
  2635. continue;
  2636. }
  2637. msg_data[2] = id & 0xff;
  2638. msg_data[3] = id >> 8;
  2639. memset(&req, 0, sizeof(req));
  2640. req.msg.netfn = IPMI_NETFN_STORAGE;
  2641. req.msg.cmd = IPMI_CMD_DELETE_SEL_ENTRY;
  2642. req.msg.data = msg_data;
  2643. req.msg.data_len = 4;
  2644. rsp = intf->sendrecv(intf, &req);
  2645. if (rsp == NULL) {
  2646. lprintf(LOG_ERR, "Unable to delete entry %d", id);
  2647. rc = -1;
  2648. }
  2649. else if (rsp->ccode > 0) {
  2650. lprintf(LOG_ERR, "Unable to delete entry %d: %s", id,
  2651. val2str(rsp->ccode, completion_code_vals));
  2652. rc = -1;
  2653. }
  2654. else {
  2655. printf("Deleted entry %d\n", id);
  2656. }
  2657. }
  2658. return rc;
  2659. }
  2660. static int
  2661. ipmi_sel_show_entry(struct ipmi_intf * intf, int argc, char ** argv)
  2662. {
  2663. struct entity_id entity;
  2664. struct sdr_record_list *entry;
  2665. struct sdr_record_list *list;
  2666. struct sdr_record_list *sdr;
  2667. struct sel_event_record evt;
  2668. int i;
  2669. int oldv;
  2670. int rc = 0;
  2671. uint16_t id;
  2672. if (argc == 0 || strncmp(argv[0], "help", 4) == 0) {
  2673. lprintf(LOG_ERR, "usage: sel get <id>...<id>");
  2674. return (-1);
  2675. }
  2676. if (ipmi_sel_reserve(intf) == 0) {
  2677. lprintf(LOG_ERR, "Unable to reserve SEL");
  2678. return (-1);
  2679. }
  2680. for (i = 0; i < argc; i++) {
  2681. if (str2ushort(argv[i], &id) != 0) {
  2682. lprintf(LOG_ERR, "Given SEL ID '%s' is invalid.",
  2683. argv[i]);
  2684. rc = (-1);
  2685. continue;
  2686. }
  2687. lprintf(LOG_DEBUG, "Looking up SEL entry 0x%x", id);
  2688. /* lookup SEL entry based on ID */
  2689. if (!ipmi_sel_get_std_entry(intf, id, &evt)) {
  2690. lprintf(LOG_DEBUG, "SEL Entry 0x%x not found.", id);
  2691. rc = (-1);
  2692. continue;
  2693. }
  2694. if (evt.sel_type.standard_type.sensor_num == 0
  2695. && evt.sel_type.standard_type.sensor_type == 0
  2696. && evt.record_type == 0) {
  2697. lprintf(LOG_WARN, "SEL Entry 0x%x not found", id);
  2698. rc = (-1);
  2699. continue;
  2700. }
  2701. /* lookup SDR entry based on sensor number and type */
  2702. ipmi_sel_print_extended_entry_verbose(intf, &evt);
  2703. sdr = ipmi_sdr_find_sdr_bynumtype(intf,
  2704. evt.sel_type.standard_type.gen_id,
  2705. evt.sel_type.standard_type.sensor_num,
  2706. evt.sel_type.standard_type.sensor_type);
  2707. if (sdr == NULL) {
  2708. continue;
  2709. }
  2710. /* print SDR entry */
  2711. oldv = verbose;
  2712. verbose = verbose ? verbose : 1;
  2713. switch (sdr->type) {
  2714. case SDR_RECORD_TYPE_FULL_SENSOR:
  2715. case SDR_RECORD_TYPE_COMPACT_SENSOR:
  2716. ipmi_sensor_print_fc(intf, sdr->record.common,
  2717. sdr->type);
  2718. entity.id = sdr->record.common->entity.id;
  2719. entity.instance = sdr->record.common->entity.instance;
  2720. break;
  2721. case SDR_RECORD_TYPE_EVENTONLY_SENSOR:
  2722. ipmi_sdr_print_sensor_eventonly(intf, sdr->record.eventonly);
  2723. entity.id = sdr->record.eventonly->entity.id;
  2724. entity.instance = sdr->record.eventonly->entity.instance;
  2725. break;
  2726. default:
  2727. verbose = oldv;
  2728. continue;
  2729. }
  2730. verbose = oldv;
  2731. /* lookup SDR entry based on entity id */
  2732. list = ipmi_sdr_find_sdr_byentity(intf, &entity);
  2733. for (entry=list; entry; entry=entry->next) {
  2734. /* print FRU devices we find for this entity */
  2735. if (entry->type == SDR_RECORD_TYPE_FRU_DEVICE_LOCATOR)
  2736. ipmi_fru_print(intf, entry->record.fruloc);
  2737. }
  2738. if ((argc > 1) && (i < (argc - 1))) {
  2739. printf("----------------------\n\n");
  2740. }
  2741. }
  2742. return rc;
  2743. }
  2744. int ipmi_sel_main(struct ipmi_intf * intf, int argc, char ** argv)
  2745. {
  2746. int rc = 0;
  2747. if (argc == 0)
  2748. rc = ipmi_sel_get_info(intf);
  2749. else if (strncmp(argv[0], "help", 4) == 0)
  2750. lprintf(LOG_ERR, "SEL Commands: "
  2751. "info clear delete list elist get add time save readraw writeraw interpret");
  2752. else if (strncmp(argv[0], "interpret", 9) == 0) {
  2753. uint32_t iana = 0;
  2754. if (argc < 4) {
  2755. lprintf(LOG_NOTICE, "usage: sel interpret iana filename format(pps)");
  2756. return 0;
  2757. }
  2758. if (str2uint(argv[1], &iana) != 0) {
  2759. lprintf(LOG_ERR, "Given IANA '%s' is invalid.",
  2760. argv[1]);
  2761. return (-1);
  2762. }
  2763. rc = ipmi_sel_interpret(intf, iana, argv[2], argv[3]);
  2764. }
  2765. else if (strncmp(argv[0], "info", 4) == 0)
  2766. rc = ipmi_sel_get_info(intf);
  2767. else if (strncmp(argv[0], "save", 4) == 0) {
  2768. if (argc < 2) {
  2769. lprintf(LOG_NOTICE, "usage: sel save <filename>");
  2770. return 0;
  2771. }
  2772. rc = ipmi_sel_save_entries(intf, 0, argv[1]);
  2773. }
  2774. else if (strncmp(argv[0], "add", 3) == 0) {
  2775. if (argc < 2) {
  2776. lprintf(LOG_NOTICE, "usage: sel add <filename>");
  2777. return 0;
  2778. }
  2779. rc = ipmi_sel_add_entries_fromfile(intf, argv[1]);
  2780. }
  2781. else if (strncmp(argv[0], "writeraw", 8) == 0) {
  2782. if (argc < 2) {
  2783. lprintf(LOG_NOTICE, "usage: sel writeraw <filename>");
  2784. return 0;
  2785. }
  2786. rc = ipmi_sel_writeraw(intf, argv[1]);
  2787. }
  2788. else if (strncmp(argv[0], "readraw", 7) == 0) {
  2789. if (argc < 2) {
  2790. lprintf(LOG_NOTICE, "usage: sel readraw <filename>");
  2791. return 0;
  2792. }
  2793. rc = ipmi_sel_readraw(intf, argv[1]);
  2794. }
  2795. else if (strncmp(argv[0], "ereadraw", 8) == 0) {
  2796. if (argc < 2) {
  2797. lprintf(LOG_NOTICE, "usage: sel ereadraw <filename>");
  2798. return 0;
  2799. }
  2800. sel_extended = 1;
  2801. rc = ipmi_sel_readraw(intf, argv[1]);
  2802. }
  2803. else if (strncmp(argv[0], "list", 4) == 0 ||
  2804. strncmp(argv[0], "elist", 5) == 0) {
  2805. /*
  2806. * Usage:
  2807. * list - show all SEL entries
  2808. * list first <n> - show the first (oldest) <n> SEL entries
  2809. * list last <n> - show the last (newsest) <n> SEL entries
  2810. */
  2811. int count = 0;
  2812. int sign = 1;
  2813. char *countstr = NULL;
  2814. if (strncmp(argv[0], "elist", 5) == 0)
  2815. sel_extended = 1;
  2816. else
  2817. sel_extended = 0;
  2818. if (argc == 2) {
  2819. countstr = argv[1];
  2820. }
  2821. else if (argc == 3) {
  2822. countstr = argv[2];
  2823. if (strncmp(argv[1], "last", 4) == 0) {
  2824. sign = -1;
  2825. }
  2826. else if (strncmp(argv[1], "first", 5) != 0) {
  2827. lprintf(LOG_ERR, "Unknown sel list option");
  2828. return -1;
  2829. }
  2830. }
  2831. if (countstr) {
  2832. if (str2int(countstr, &count) != 0) {
  2833. lprintf(LOG_ERR, "Numeric argument required; got '%s'",
  2834. countstr);
  2835. return -1;
  2836. }
  2837. }
  2838. count *= sign;
  2839. rc = ipmi_sel_list_entries(intf,count);
  2840. }
  2841. else if (strncmp(argv[0], "clear", 5) == 0)
  2842. rc = ipmi_sel_clear(intf);
  2843. else if (strncmp(argv[0], "delete", 6) == 0) {
  2844. if (argc < 2)
  2845. lprintf(LOG_ERR, "usage: sel delete <id>...<id>");
  2846. else
  2847. rc = ipmi_sel_delete(intf, argc-1, &argv[1]);
  2848. }
  2849. else if (strncmp(argv[0], "get", 3) == 0) {
  2850. if (argc < 2)
  2851. lprintf(LOG_ERR, "usage: sel get <entry>");
  2852. else
  2853. rc = ipmi_sel_show_entry(intf, argc-1, &argv[1]);
  2854. }
  2855. else if (strncmp(argv[0], "time", 4) == 0) {
  2856. if (argc < 2)
  2857. lprintf(LOG_ERR, "sel time commands: get set");
  2858. else if (strncmp(argv[1], "get", 3) == 0)
  2859. ipmi_sel_get_time(intf);
  2860. else if (strncmp(argv[1], "set", 3) == 0) {
  2861. if (argc < 3)
  2862. lprintf(LOG_ERR, "usage: sel time set \"mm/dd/yyyy hh:mm:ss\"");
  2863. else
  2864. rc = ipmi_sel_set_time(intf, argv[2]);
  2865. } else {
  2866. lprintf(LOG_ERR, "sel time commands: get set");
  2867. }
  2868. }
  2869. else {
  2870. lprintf(LOG_ERR, "Invalid SEL command: %s", argv[0]);
  2871. rc = -1;
  2872. }
  2873. return rc;
  2874. }