ipmi_pef.c 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550
  1. /*
  2. * Copyright (c) 2004 Dell Computers. 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 Dell Computers, 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. * DELL COMPUTERS ("DELL") 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. * DELL 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 DELL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  31. */
  32. #include <string.h>
  33. #include <math.h>
  34. #include <time.h>
  35. #include <ipmitool/bswap.h>
  36. #include <ipmitool/helper.h>
  37. #include <ipmitool/ipmi.h>
  38. #include <ipmitool/ipmi_channel.h>
  39. #include <ipmitool/ipmi_intf.h>
  40. #include <ipmitool/ipmi_mc.h>
  41. #include <ipmitool/ipmi_pef.h>
  42. #include <ipmitool/ipmi_sel.h>
  43. #include <ipmitool/log.h>
  44. extern int verbose;
  45. /*
  46. // common kywd/value printf() templates
  47. */
  48. static const char * pef_fld_fmts[][2] = {
  49. {"%-*s : %u\n", " | %u"}, /* F_DEC: unsigned value */
  50. {"%-*s : %d\n", " | %d"}, /* F_INT: signed value */
  51. {"%-*s : %s\n", " | %s"}, /* F_STR: string value */
  52. {"%-*s : 0x%x\n", " | 0x%x"}, /* F_HEX: "N hex digits" */
  53. {"%-*s : 0x%04x\n", " | 0x%04x"}, /* F_2XD: "2 hex digits" */
  54. {"%-*s : 0x%02x\n", " | 0x%02x"}, /* F_1XD: "1 hex digit" */
  55. {"%-*s : %02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\n",
  56. " | %02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x"},
  57. };
  58. typedef enum {
  59. F_DEC,
  60. F_INT,
  61. F_STR,
  62. F_HEX,
  63. F_2XD,
  64. F_1XD,
  65. F_UID,
  66. } fmt_e;
  67. #define KYWD_LENGTH 24
  68. static int first_field = 1;
  69. static const char * pef_flag_fmts[][3] = {
  70. {"", "false", "true"},
  71. {"supported", "un", ""},
  72. {"active", "in", ""},
  73. {"abled", "dis", "en"},
  74. };
  75. static const char * listitem[] = {" | %s", ",%s", "%s"};
  76. static int ipmi_pef2_list_filters(struct ipmi_intf *);
  77. const char *
  78. ipmi_pef_bit_desc(struct bit_desc_map * map, uint32_t value)
  79. { /*
  80. // return description/text label(s) for the given value.
  81. // NB: uses a static buffer
  82. */
  83. static char buf[128];
  84. char * p;
  85. struct desc_map * pmap;
  86. uint32_t match, index;
  87. *(p = buf) = '\0';
  88. index = 2;
  89. for (pmap=map->desc_maps; pmap && pmap->desc; pmap++) {
  90. if (map->desc_map_type == BIT_DESC_MAP_LIST)
  91. match = (value == pmap->mask);
  92. else
  93. match = ((value & pmap->mask) == pmap->mask);
  94. if (match) {
  95. sprintf(p, listitem[index], pmap->desc);
  96. p = strchr(p, '\0');
  97. if (map->desc_map_type != BIT_DESC_MAP_ALL)
  98. break;
  99. index = 1;
  100. }
  101. }
  102. if (p == buf)
  103. return("None");
  104. return((const char *)buf);
  105. }
  106. void
  107. ipmi_pef_print_flags(struct bit_desc_map * map, flg_e type, uint32_t val)
  108. { /*
  109. // print features/flags, using val (a bitmask), according to map.
  110. // observe the verbose flag, and print any labels, etc. based on type
  111. */
  112. struct desc_map * pmap;
  113. uint32_t maskval, index;
  114. index = 0;
  115. for (pmap=map->desc_maps; pmap && pmap->desc; pmap++) {
  116. maskval = (val & pmap->mask);
  117. if (verbose)
  118. printf("%-*s : %s%s\n", KYWD_LENGTH,
  119. ipmi_pef_bit_desc(map, pmap->mask),
  120. pef_flag_fmts[type][1 + (maskval != 0)],
  121. pef_flag_fmts[type][0]);
  122. else if (maskval != 0) {
  123. printf(listitem[index], ipmi_pef_bit_desc(map, maskval));
  124. index = 1;
  125. }
  126. }
  127. }
  128. static void
  129. ipmi_pef_print_field(const char * fmt[2], const char * label, unsigned long val)
  130. { /*
  131. // print a 'field' (observes 'verbose' flag)
  132. */
  133. if (verbose)
  134. printf(fmt[0], KYWD_LENGTH, label, val);
  135. else if (first_field)
  136. printf(&fmt[1][2], val); /* skip field separator */
  137. else
  138. printf(fmt[1], val);
  139. first_field = 0;
  140. }
  141. void
  142. ipmi_pef_print_dec(const char * text, uint32_t val)
  143. { /* unsigned */
  144. ipmi_pef_print_field(pef_fld_fmts[F_DEC], text, val);
  145. }
  146. void
  147. ipmi_pef_print_int(const char * text, uint32_t val)
  148. { /* signed */
  149. ipmi_pef_print_field(pef_fld_fmts[F_INT], text, val);
  150. }
  151. void
  152. ipmi_pef_print_hex(const char * text, uint32_t val)
  153. { /* hex */
  154. ipmi_pef_print_field(pef_fld_fmts[F_HEX], text, val);
  155. }
  156. void
  157. ipmi_pef_print_str(const char * text, const char * val)
  158. { /* string */
  159. ipmi_pef_print_field(pef_fld_fmts[F_STR], text, (unsigned long)val);
  160. }
  161. void
  162. ipmi_pef_print_2xd(const char * text, uint8_t u1, uint8_t u2)
  163. { /* 2 hex digits */
  164. uint32_t val = ((u1 << 8) + u2) & 0xffff;
  165. ipmi_pef_print_field(pef_fld_fmts[F_2XD], text, val);
  166. }
  167. void
  168. ipmi_pef_print_1xd(const char * text, uint32_t val)
  169. { /* 1 hex digit */
  170. ipmi_pef_print_field(pef_fld_fmts[F_1XD], text, val);
  171. }
  172. /* ipmi_pef_print_guid - print-out GUID. */
  173. static int
  174. ipmi_pef_print_guid(uint8_t *guid)
  175. {
  176. if (guid == NULL) {
  177. return (-1);
  178. }
  179. if (verbose) {
  180. printf("%-*s : %02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\n",
  181. KYWD_LENGTH, "System GUID",
  182. guid[0], guid[1], guid[2], guid[3], guid[4],
  183. guid[5], guid[6], guid[7], guid[8], guid[9],
  184. guid[10],guid[11], guid[12], guid[13], guid[14],
  185. guid[15]);
  186. } else {
  187. printf(" | %02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
  188. guid[0], guid[1], guid[2], guid[3], guid[4],
  189. guid[5], guid[6], guid[7], guid[8], guid[9],
  190. guid[10], guid[11], guid[12], guid[13], guid[14],
  191. guid[15]);
  192. }
  193. return 0;
  194. }
  195. static struct ipmi_rs *
  196. ipmi_pef_msg_exchange(struct ipmi_intf * intf, struct ipmi_rq * req, char * txt)
  197. { /*
  198. // common IPMItool rqst/resp handling
  199. */
  200. struct ipmi_rs * rsp = intf->sendrecv(intf, req);
  201. if (!rsp) {
  202. return(NULL);
  203. } else if (rsp->ccode == 0x80) {
  204. return(NULL); /* Do not output error, just unsupported parameters */
  205. } else if (rsp->ccode) {
  206. lprintf(LOG_ERR, " **Error %x in '%s' command", rsp->ccode, txt);
  207. return(NULL);
  208. }
  209. if (verbose > 2) {
  210. printbuf(rsp->data, rsp->data_len, txt);
  211. }
  212. return(rsp);
  213. }
  214. /* _ipmi_get_pef_capabilities - Requests and returns result of (30.1) Get PEF
  215. * Capabilities.
  216. *
  217. * @pcap - pointer where to store results.
  218. *
  219. * returns - negative number means error, positive is a ccode.
  220. */
  221. int
  222. _ipmi_get_pef_capabilities(struct ipmi_intf *intf,
  223. struct pef_capabilities *pcap)
  224. {
  225. struct ipmi_rs *rsp;
  226. struct ipmi_rq req;
  227. if (pcap == NULL) {
  228. return (-3);
  229. }
  230. memset(pcap, 0, sizeof(struct pef_capabilities));
  231. memset(&req, 0, sizeof(req));
  232. req.msg.netfn = IPMI_NETFN_SE;
  233. req.msg.cmd = IPMI_CMD_GET_PEF_CAPABILITIES;
  234. rsp = intf->sendrecv(intf, &req);
  235. if (rsp == NULL) {
  236. return (-1);
  237. } else if (rsp->ccode != 0) {
  238. return rsp->ccode;
  239. } else if (rsp->data_len != 3) {
  240. return (-2);
  241. }
  242. pcap->version = rsp->data[0];
  243. pcap->actions = rsp->data[1];
  244. pcap->event_filter_count = rsp->data[2];
  245. return 0;
  246. }
  247. /* _ipmi_get_pef_filter_entry - Fetches one Entry from Event Filter Table
  248. * identified by Filter ID.
  249. *
  250. * @filter_id - Filter ID of Entry in Event Filter Table.
  251. * @filter_entry - Pointer where to copy Filter Entry data.
  252. *
  253. * returns - negative number means error, positive is a ccode.
  254. */
  255. static int
  256. _ipmi_get_pef_filter_entry(struct ipmi_intf *intf, uint8_t filter_id,
  257. struct pef_cfgparm_filter_table_entry *filter_entry)
  258. {
  259. struct ipmi_rs *rsp;
  260. struct ipmi_rq req;
  261. uint8_t data[3];
  262. uint8_t data_len = 3 * sizeof(uint8_t);
  263. int dest_size;
  264. if (filter_entry == NULL) {
  265. return (-3);
  266. }
  267. dest_size = (int)sizeof(struct pef_cfgparm_filter_table_entry);
  268. memset(filter_entry, 0, dest_size);
  269. memset(&data, 0, data_len);
  270. data[0] = PEF_CFGPARM_ID_PEF_FILTER_TABLE_ENTRY;
  271. data[1] = filter_id;
  272. memset(&req, 0, sizeof(req));
  273. req.msg.netfn = IPMI_NETFN_SE;
  274. req.msg.cmd = IPMI_CMD_GET_PEF_CONFIG_PARMS;
  275. req.msg.data = (uint8_t *)&data;
  276. req.msg.data_len = data_len;
  277. rsp = intf->sendrecv(intf, &req);
  278. if (rsp == NULL) {
  279. return (-1);
  280. } else if (rsp->ccode != 0) {
  281. return rsp->ccode;
  282. } else if (rsp->data_len != 22 || (rsp->data_len - 1) != dest_size) {
  283. return (-2);
  284. }
  285. memcpy(filter_entry, &rsp->data[1], dest_size);
  286. return 0;
  287. }
  288. /* _ipmi_get_pef_filter_entry_cfg - Fetches configuration of one Entry from
  289. * Event Filter Table identified by Filter ID.
  290. *
  291. * @filter_id - Filter ID of Entry in Event Filter Table.
  292. * @filter_entry_cfg - Pointer where to copy Filter Entry configuration.
  293. *
  294. * returns - negative number means error, positive is a ccode.
  295. */
  296. int
  297. _ipmi_get_pef_filter_entry_cfg(struct ipmi_intf *intf, uint8_t filter_id,
  298. struct pef_cfgparm_filter_table_data_1 *filter_cfg)
  299. {
  300. struct ipmi_rs *rsp;
  301. struct ipmi_rq req;
  302. uint8_t data[3];
  303. uint8_t data_len = 3 * sizeof(uint8_t);
  304. int dest_size;
  305. if (filter_cfg == NULL) {
  306. return (-3);
  307. }
  308. dest_size = (int)sizeof(struct pef_cfgparm_filter_table_data_1);
  309. memset(filter_cfg, 0, dest_size);
  310. memset(&data, 0, data_len);
  311. data[0] = PEF_CFGPARM_ID_PEF_FILTER_TABLE_DATA_1;
  312. data[1] = filter_id;
  313. memset(&req, 0, sizeof(req));
  314. req.msg.netfn = IPMI_NETFN_SE;
  315. req.msg.cmd = IPMI_CMD_GET_PEF_CONFIG_PARMS;
  316. req.msg.data = (uint8_t *)&data;
  317. req.msg.data_len = data_len;
  318. rsp = intf->sendrecv(intf, &req);
  319. if (rsp == NULL) {
  320. return (-1);
  321. } else if (rsp->ccode != 0) {
  322. return rsp->ccode;
  323. } else if (rsp->data_len != 3 || (rsp->data_len - 1) != dest_size) {
  324. return (-2);
  325. }
  326. memcpy(filter_cfg, &rsp->data[1], dest_size);
  327. return 0;
  328. }
  329. /* _ipmi_get_pef_policy_entry - Fetches one Entry from Alert Policy Table
  330. * identified by Policy ID.
  331. *
  332. * @policy_id - Policy ID of Entry in Alert Policy Table.
  333. * @policy_entry - Pointer where to copy Policy Entry data.
  334. *
  335. * returns - negative number means error, positive is a ccode.
  336. */
  337. static int
  338. _ipmi_get_pef_policy_entry(struct ipmi_intf *intf, uint8_t policy_id,
  339. struct pef_cfgparm_policy_table_entry *policy_entry)
  340. {
  341. struct ipmi_rs *rsp;
  342. struct ipmi_rq req;
  343. uint8_t data[3];
  344. uint8_t data_len = 3 * sizeof(uint8_t);
  345. int dest_size;
  346. if (policy_entry == NULL) {
  347. return (-3);
  348. }
  349. dest_size = (int)sizeof(struct pef_cfgparm_policy_table_entry);
  350. memset(policy_entry, 0, dest_size);
  351. memset(&data, 0, data_len);
  352. data[0] = PEF_CFGPARM_ID_PEF_ALERT_POLICY_TABLE_ENTRY;
  353. data[1] = policy_id & PEF_POLICY_TABLE_ID_MASK;
  354. memset(&req, 0, sizeof(req));
  355. req.msg.netfn = IPMI_NETFN_SE;
  356. req.msg.cmd = IPMI_CMD_GET_PEF_CONFIG_PARMS;
  357. req.msg.data = (uint8_t *)&data;
  358. req.msg.data_len = data_len;
  359. rsp = intf->sendrecv(intf, &req);
  360. if (rsp == NULL) {
  361. return (-1);
  362. } else if (rsp->ccode != 0) {
  363. return rsp->ccode;
  364. } else if (rsp->data_len != 5 || (rsp->data_len - 1) != dest_size) {
  365. return (-2);
  366. }
  367. memcpy(policy_entry, &rsp->data[1], dest_size);
  368. return 0;
  369. }
  370. /* _ipmi_get_pef_filter_table_size - Fetch the Number of Event Filter Entries.
  371. * If the number is 0, it means feature is not supported.
  372. *
  373. * @table_size - ptr to where to store number of entries.
  374. *
  375. * returns - negative number means error, positive is a ccode.
  376. */
  377. static int
  378. _ipmi_get_pef_filter_table_size(struct ipmi_intf *intf, uint8_t *table_size)
  379. {
  380. struct ipmi_rs *rsp;
  381. struct ipmi_rq req;
  382. struct pef_cfgparm_selector psel;
  383. if (table_size == NULL) {
  384. return (-3);
  385. }
  386. *table_size = 0;
  387. memset(&psel, 0, sizeof(psel));
  388. psel.id = PEF_CFGPARM_ID_PEF_FILTER_TABLE_SIZE;
  389. memset(&req, 0, sizeof(req));
  390. req.msg.netfn = IPMI_NETFN_SE;
  391. req.msg.cmd = IPMI_CMD_GET_PEF_CONFIG_PARMS;
  392. req.msg.data = (uint8_t *)&psel;
  393. req.msg.data_len = sizeof(psel);
  394. rsp = intf->sendrecv(intf, &req);
  395. if (rsp == NULL) {
  396. return (-1);
  397. } else if (rsp->ccode != 0) {
  398. return rsp->ccode;
  399. } else if (rsp->data_len != 2) {
  400. return (-2);
  401. }
  402. *table_size = rsp->data[1] & 0x7F;
  403. return 0;
  404. }
  405. /* _ipmi_get_pef_policy_table_size - Fetch the Number of Alert Policy Entries. If the
  406. * number is 0, it means feature is not supported.
  407. *
  408. * @table_size - ptr to where to store number of entries.
  409. *
  410. * returns - negative number means error, positive is a ccode.
  411. */
  412. static int
  413. _ipmi_get_pef_policy_table_size(struct ipmi_intf *intf, uint8_t *table_size)
  414. {
  415. struct ipmi_rs *rsp;
  416. struct ipmi_rq req;
  417. struct pef_cfgparm_selector psel;
  418. if (table_size == NULL) {
  419. return (-3);
  420. }
  421. *table_size = 0;
  422. memset(&psel, 0, sizeof(psel));
  423. psel.id = PEF_CFGPARM_ID_PEF_ALERT_POLICY_TABLE_SIZE;
  424. memset(&req, 0, sizeof(req));
  425. req.msg.netfn = IPMI_NETFN_SE;
  426. req.msg.cmd = IPMI_CMD_GET_PEF_CONFIG_PARMS;
  427. req.msg.data = (uint8_t *)&psel;
  428. req.msg.data_len = sizeof(psel);
  429. rsp = intf->sendrecv(intf, &req);
  430. if (rsp == NULL) {
  431. return (-1);
  432. } else if (rsp->ccode != 0) {
  433. return rsp->ccode;
  434. } else if (rsp->data_len != 2) {
  435. return (-2);
  436. }
  437. *table_size = rsp->data[1] & 0x7F;
  438. return 0;
  439. }
  440. /* _ipmi_get_pef_system_guid - Fetches System GUID from PEF. This configuration
  441. * parameter is optional. If data1 is 0x0, then this GUID is ignored by BMC.
  442. *
  443. * @system_guid - pointer where to store received data.
  444. *
  445. * returns - negative number means error, positive is a ccode.
  446. */
  447. int
  448. _ipmi_get_pef_system_guid(struct ipmi_intf *intf,
  449. struct pef_cfgparm_system_guid *system_guid)
  450. {
  451. struct ipmi_rs *rsp;
  452. struct ipmi_rq req;
  453. struct pef_cfgparm_selector psel;
  454. if (system_guid == NULL) {
  455. return (-3);
  456. }
  457. memset(system_guid, 0, sizeof(struct pef_cfgparm_system_guid));
  458. memset(&psel, 0, sizeof(psel));
  459. psel.id = PEF_CFGPARM_ID_SYSTEM_GUID;
  460. memset(&req, 0, sizeof(req));
  461. req.msg.netfn = IPMI_NETFN_SE;
  462. req.msg.cmd = IPMI_CMD_GET_PEF_CONFIG_PARMS;
  463. req.msg.data = (uint8_t *)&psel;
  464. req.msg.data_len = sizeof(psel);
  465. rsp = intf->sendrecv(intf, &req);
  466. if (rsp == NULL) {
  467. return (-1);
  468. } else if (rsp->ccode != 0) {
  469. return rsp->ccode;
  470. } else if (rsp->data_len != 18
  471. || (rsp->data_len - 2) != sizeof(system_guid->guid)) {
  472. return (-2);
  473. }
  474. system_guid->data1 = rsp->data[1] & 0x1;
  475. memcpy(system_guid->guid, &rsp->data[2], sizeof(system_guid->guid));
  476. return 0;
  477. }
  478. /* _ipmi_set_pef_filter_entry_cfg - Sets/updates configuration of Entry in Event
  479. * Filter Table identified by Filter ID.
  480. *
  481. * @filter_id - ID of Entry in Event Filter Table to be updated
  482. * @filter_cfg - Pointer to configuration data.
  483. *
  484. * returns - negative number means error, positive is a ccode.
  485. */
  486. static int
  487. _ipmi_set_pef_filter_entry_cfg(struct ipmi_intf *intf, uint8_t filter_id,
  488. struct pef_cfgparm_filter_table_data_1 *filter_cfg)
  489. {
  490. struct ipmi_rs *rsp;
  491. struct ipmi_rq req;
  492. uint8_t data[3];
  493. uint8_t data_len = 3 * sizeof(uint8_t);
  494. if (filter_cfg == NULL) {
  495. return (-3);
  496. }
  497. memset(&req, 0, sizeof(req));
  498. req.msg.netfn = IPMI_NETFN_SE;
  499. req.msg.cmd = IPMI_CMD_SET_PEF_CONFIG_PARMS;
  500. req.msg.data = (uint8_t *)&data;
  501. req.msg.data_len = data_len;
  502. memset(&data, 0, data_len);
  503. data[0] = PEF_CFGPARM_ID_PEF_FILTER_TABLE_DATA_1;
  504. data[1] = filter_id;
  505. data[2] = filter_cfg->cfg;
  506. rsp = intf->sendrecv(intf, &req);
  507. if (rsp == NULL) {
  508. return (-1);
  509. } else if (rsp->ccode != 0) {
  510. return rsp->ccode;
  511. }
  512. return 0;
  513. }
  514. /* _ipmi_set_pef_policy_entry - Sets/updates Entry in Alert Policy Table identified by
  515. * Policy ID.
  516. *
  517. * @policy_id - Policy ID of Entry in Alert Policy Table to be updated
  518. * @policy_entry - Pointer to data.
  519. *
  520. * returns - negative number means error, positive is a ccode.
  521. */
  522. static int
  523. _ipmi_set_pef_policy_entry(struct ipmi_intf *intf, uint8_t policy_id,
  524. struct pef_cfgparm_policy_table_entry *policy_entry)
  525. {
  526. struct ipmi_rs *rsp;
  527. struct ipmi_rq req;
  528. struct pef_cfgparm_set_policy_table_entry payload;
  529. if (policy_entry == NULL) {
  530. return (-3);
  531. }
  532. memset(&req, 0, sizeof(req));
  533. req.msg.netfn = IPMI_NETFN_SE;
  534. req.msg.cmd = IPMI_CMD_SET_PEF_CONFIG_PARMS;
  535. req.msg.data = (uint8_t *)&payload;
  536. req.msg.data_len = sizeof(payload);
  537. memset(&payload, 0, sizeof(payload));
  538. payload.param_selector = PEF_CFGPARM_ID_PEF_ALERT_POLICY_TABLE_ENTRY;
  539. payload.policy_id = policy_id & PEF_POLICY_TABLE_ID_MASK;
  540. memcpy(&payload.entry, &policy_entry->entry,
  541. sizeof(policy_entry->entry));
  542. rsp = intf->sendrecv(intf, &req);
  543. if (rsp == NULL) {
  544. return (-1);
  545. } else if (rsp->ccode != 0) {
  546. return rsp->ccode;
  547. }
  548. return 0;
  549. }
  550. static void
  551. ipmi_pef_print_oem_lan_dest(struct ipmi_intf *intf, uint8_t ch, uint8_t dest)
  552. {
  553. char address[128];
  554. int len;
  555. int rc;
  556. int rlen;
  557. int set;
  558. uint8_t data[32];
  559. if (ipmi_get_oem(intf) != IPMI_OEM_DELL) {
  560. return;
  561. }
  562. /* Get # of IPV6 trap destinations */
  563. rc = ipmi_mc_getsysinfo(intf, IPMI_SYSINFO_DELL_IPV6_COUNT, 0x00, 0x00, 4, data);
  564. if (rc != 0 || dest > data[0]) {
  565. return;
  566. }
  567. ipmi_pef_print_str("Alert destination type", "xxx");
  568. ipmi_pef_print_str("PET Community", "xxx");
  569. ipmi_pef_print_dec("ACK timeout/retry (secs)", 0);
  570. ipmi_pef_print_dec("Retries", 0);
  571. /* Get IPv6 destination string (may be in multiple sets) */
  572. memset(address, 0, sizeof(address));
  573. memset(data, 0, sizeof(data));
  574. rc = ipmi_mc_getsysinfo(intf, IPMI_SYSINFO_DELL_IPV6_DESTADDR, 0x00, dest, 19, data);
  575. if (rc != 0) {
  576. return;
  577. }
  578. /* Total length of IPv6 string */
  579. len = data[4];
  580. if ((rlen = len) > (IPMI_SYSINFO_SET0_SIZE-3)) {
  581. /* First set has 11 bytes */
  582. rlen = IPMI_SYSINFO_SET0_SIZE - 3;
  583. }
  584. memcpy(address, data + 8, rlen);
  585. for (set = 1; len > 11; set++) {
  586. rc = ipmi_mc_getsysinfo(intf, IPMI_SYSINFO_DELL_IPV6_DESTADDR, set, dest, 19, data);
  587. if ((rlen = len - 11) >= (IPMI_SYSINFO_SETN_SIZE - 2)) {
  588. /* Remaining sets have 14 bytes */
  589. rlen = IPMI_SYSINFO_SETN_SIZE - 2;
  590. }
  591. memcpy(address + (set * 11), data + 3, rlen);
  592. len -= rlen+3;
  593. }
  594. ipmi_pef_print_str("IPv6 Address", address);
  595. }
  596. /* TODO - rewrite */
  597. static void
  598. ipmi_pef_print_lan_dest(struct ipmi_intf * intf, uint8_t ch, uint8_t dest)
  599. { /*
  600. // print LAN alert destination info
  601. */
  602. struct ipmi_rs * rsp;
  603. struct ipmi_rq req;
  604. struct pef_lan_cfgparm_selector lsel;
  605. struct pef_lan_cfgparm_dest_type * ptype;
  606. struct pef_lan_cfgparm_dest_info * pinfo;
  607. char buf[32];
  608. uint8_t dsttype, timeout, retries;
  609. memset(&lsel, 0, sizeof(lsel));
  610. lsel.id = PEF_LAN_CFGPARM_ID_DEST_COUNT;
  611. lsel.ch = ch;
  612. memset(&req, 0, sizeof(req));
  613. req.msg.netfn = IPMI_NETFN_TRANSPORT;
  614. req.msg.cmd = IPMI_CMD_LAN_GET_CONFIG;
  615. req.msg.data = (uint8_t *)&lsel;
  616. req.msg.data_len = sizeof(lsel);
  617. rsp = ipmi_pef_msg_exchange(intf, &req, "Alert destination count");
  618. if (!rsp) {
  619. lprintf(LOG_ERR, " **Error retrieving %s",
  620. "Alert destination count");
  621. return;
  622. }
  623. lsel.id = PEF_LAN_CFGPARM_ID_DESTTYPE;
  624. lsel.set = dest;
  625. rsp = ipmi_pef_msg_exchange(intf, &req, "Alert destination type");
  626. if (!rsp || rsp->data[1] != lsel.set) {
  627. lprintf(LOG_ERR, " **Error retrieving %s",
  628. "Alert destination type");
  629. return;
  630. }
  631. ptype = (struct pef_lan_cfgparm_dest_type *)&rsp->data[1];
  632. dsttype = (ptype->dest_type & PEF_LAN_DEST_TYPE_MASK);
  633. timeout = ptype->alert_timeout;
  634. retries = (ptype->retries & PEF_LAN_RETRIES_MASK);
  635. ipmi_pef_print_str("Alert destination type",
  636. ipmi_pef_bit_desc(&pef_b2s_lan_desttype, dsttype));
  637. if (dsttype == PEF_LAN_DEST_TYPE_PET) {
  638. lsel.id = PEF_LAN_CFGPARM_ID_PET_COMMUNITY;
  639. lsel.set = 0;
  640. rsp = ipmi_pef_msg_exchange(intf, &req, "PET community");
  641. if (!rsp)
  642. lprintf(LOG_ERR, " **Error retrieving %s",
  643. "PET community");
  644. else {
  645. rsp->data[19] = '\0';
  646. ipmi_pef_print_str("PET Community", (const char *)&rsp->data[1]);
  647. }
  648. }
  649. ipmi_pef_print_dec("ACK timeout/retry (secs)", timeout);
  650. ipmi_pef_print_dec("Retries", retries);
  651. lsel.id = PEF_LAN_CFGPARM_ID_DESTADDR;
  652. lsel.set = dest;
  653. rsp = ipmi_pef_msg_exchange(intf, &req, "Alert destination info");
  654. if (!rsp || rsp->data[1] != lsel.set)
  655. lprintf(LOG_ERR, " **Error retrieving %s",
  656. "Alert destination info");
  657. else {
  658. pinfo = (struct pef_lan_cfgparm_dest_info *)&rsp->data[1];
  659. sprintf(buf, "%u.%u.%u.%u",
  660. pinfo->ip[0], pinfo->ip[1], pinfo->ip[2], pinfo->ip[3]);
  661. ipmi_pef_print_str("IP address", buf);
  662. ipmi_pef_print_str("MAC address", mac2str(pinfo->mac));
  663. }
  664. }
  665. static void
  666. ipmi_pef_print_serial_dest_dial(struct ipmi_intf *intf, char *label,
  667. struct pef_serial_cfgparm_selector *ssel)
  668. { /*
  669. // print a dial string
  670. */
  671. #define BLOCK_SIZE 16
  672. struct ipmi_rs * rsp;
  673. struct ipmi_rq req;
  674. struct pef_serial_cfgparm_selector tmp;
  675. char * p, strval[(6 * BLOCK_SIZE) + 1];
  676. memset(&tmp, 0, sizeof(tmp));
  677. tmp.id = PEF_SERIAL_CFGPARM_ID_DEST_DIAL_STRING_COUNT;
  678. memset(&req, 0, sizeof(req));
  679. req.msg.netfn = IPMI_NETFN_TRANSPORT;
  680. req.msg.cmd = IPMI_CMD_SERIAL_GET_CONFIG;
  681. req.msg.data = (uint8_t *)&tmp;
  682. req.msg.data_len = sizeof(tmp);
  683. rsp = ipmi_pef_msg_exchange(intf, &req, "Dial string count");
  684. if (!rsp || (rsp->data[1] & PEF_SERIAL_DIAL_STRING_COUNT_MASK) == 0)
  685. return; /* sssh, not supported */
  686. memcpy(&tmp, ssel, sizeof(tmp));
  687. tmp.id = PEF_SERIAL_CFGPARM_ID_DEST_DIAL_STRING;
  688. tmp.block = 1;
  689. memset(strval, 0, sizeof(strval));
  690. p = strval;
  691. for (;;) {
  692. rsp = ipmi_pef_msg_exchange(intf, &req, label);
  693. if (!rsp
  694. || (rsp->data[1] != ssel->id)
  695. || (rsp->data[2] != tmp.block)) {
  696. lprintf(LOG_ERR, " **Error retrieving %s", label);
  697. return;
  698. }
  699. memcpy(p, &rsp->data[3], BLOCK_SIZE);
  700. if (strchr(p, '\0') <= (p + BLOCK_SIZE))
  701. break;
  702. if ((p += BLOCK_SIZE) >= &strval[sizeof(strval)-1])
  703. break;
  704. tmp.block++;
  705. }
  706. ipmi_pef_print_str(label, strval);
  707. #undef BLOCK_SIZE
  708. }
  709. static void
  710. ipmi_pef_print_serial_dest_tap(struct ipmi_intf *intf,
  711. struct pef_serial_cfgparm_selector *ssel)
  712. { /*
  713. // print TAP destination info
  714. */
  715. struct ipmi_rs * rsp;
  716. struct ipmi_rq req;
  717. struct pef_serial_cfgparm_selector tmp;
  718. struct pef_serial_cfgparm_tap_svc_settings * pset;
  719. uint8_t dialstr_id, setting_id;
  720. memset(&tmp, 0, sizeof(tmp));
  721. tmp.id = PEF_SERIAL_CFGPARM_ID_TAP_ACCT_COUNT;
  722. memset(&req, 0, sizeof(req));
  723. req.msg.netfn = IPMI_NETFN_TRANSPORT;
  724. req.msg.cmd = IPMI_CMD_SERIAL_GET_CONFIG;
  725. req.msg.data = (uint8_t *)&tmp;
  726. req.msg.data_len = sizeof(tmp);
  727. rsp = ipmi_pef_msg_exchange(intf, &req, "Number of TAP accounts");
  728. if (!rsp || (rsp->data[1] & PEF_SERIAL_TAP_ACCT_COUNT_MASK) == 0)
  729. return; /* sssh, not supported */
  730. memcpy(&tmp, ssel, sizeof(tmp));
  731. tmp.id = PEF_SERIAL_CFGPARM_ID_TAP_ACCT_INFO;
  732. rsp = ipmi_pef_msg_exchange(intf, &req, "TAP account info");
  733. if (!rsp || (rsp->data[1] != tmp.set)) {
  734. lprintf(LOG_ERR, " **Error retrieving %s",
  735. "TAP account info");
  736. return;
  737. }
  738. dialstr_id = (rsp->data[2] & PEF_SERIAL_TAP_ACCT_INFO_DIAL_STRING_ID_MASK);
  739. dialstr_id >>= PEF_SERIAL_TAP_ACCT_INFO_DIAL_STRING_ID_SHIFT;
  740. setting_id = (rsp->data[2] & PEF_SERIAL_TAP_ACCT_INFO_SVC_SETTINGS_ID_MASK);
  741. tmp.set = dialstr_id;
  742. ipmi_pef_print_serial_dest_dial(intf, "TAP Dial string", &tmp);
  743. tmp.set = setting_id;
  744. rsp = ipmi_pef_msg_exchange(intf, &req, "TAP service settings");
  745. if (!rsp || (rsp->data[1] != tmp.set)) {
  746. lprintf(LOG_ERR, " **Error retrieving %s",
  747. "TAP service settings");
  748. return;
  749. }
  750. pset = (struct pef_serial_cfgparm_tap_svc_settings *)&rsp->data[1];
  751. ipmi_pef_print_str("TAP confirmation",
  752. ipmi_pef_bit_desc(&pef_b2s_tap_svc_confirm, pset->confirmation_flags));
  753. /* TODO : additional TAP settings? */
  754. }
  755. /*
  756. static void
  757. ipmi_pef_print_serial_dest_ppp(struct ipmi_intf *intf,
  758. struct pef_serial_cfgparm_selector *ssel)
  759. {
  760. }
  761. static void
  762. ipmi_pef_print_serial_dest_callback(struct ipmi_intf *intf,
  763. struct pef_serial_cfgparm_selector *ssel)
  764. }
  765. */
  766. static void
  767. ipmi_pef_print_serial_dest(struct ipmi_intf *intf, uint8_t ch, uint8_t dest)
  768. { /*
  769. // print Serial/PPP alert destination info
  770. */
  771. struct ipmi_rs * rsp;
  772. struct ipmi_rq req;
  773. struct pef_serial_cfgparm_selector ssel;
  774. uint8_t tbl_size, wrk;
  775. struct pef_serial_cfgparm_dest_info * pinfo;
  776. memset(&ssel, 0, sizeof(ssel));
  777. ssel.id = PEF_SERIAL_CFGPARM_ID_DEST_COUNT;
  778. ssel.ch = ch;
  779. memset(&req, 0, sizeof(req));
  780. req.msg.netfn = IPMI_NETFN_TRANSPORT;
  781. req.msg.cmd = IPMI_CMD_SERIAL_GET_CONFIG;
  782. req.msg.data = (uint8_t *)&ssel;
  783. req.msg.data_len = sizeof(ssel);
  784. rsp = ipmi_pef_msg_exchange(intf, &req, "Alert destination count");
  785. if (!rsp) {
  786. lprintf(LOG_ERR, " **Error retrieving %s",
  787. "Alert destination count");
  788. return;
  789. }
  790. tbl_size = (rsp->data[1] & PEF_SERIAL_DEST_TABLE_SIZE_MASK);
  791. if (!dest || tbl_size == 0) /* Page alerting not supported */
  792. return;
  793. if (dest > tbl_size) {
  794. ipmi_pef_print_oem_lan_dest(intf, ch, dest - tbl_size);
  795. return;
  796. }
  797. ssel.id = PEF_SERIAL_CFGPARM_ID_DESTINFO;
  798. ssel.set = dest;
  799. rsp = ipmi_pef_msg_exchange(intf, &req, "Alert destination info");
  800. if (!rsp || rsp->data[1] != ssel.set)
  801. lprintf(LOG_ERR, " **Error retrieving %s",
  802. "Alert destination info");
  803. else {
  804. pinfo = (struct pef_serial_cfgparm_dest_info *)rsp->data;
  805. wrk = (pinfo->dest_type & PEF_SERIAL_DEST_TYPE_MASK);
  806. ipmi_pef_print_str("Alert destination type",
  807. ipmi_pef_bit_desc(&pef_b2s_serial_desttype, wrk));
  808. ipmi_pef_print_dec("ACK timeout (secs)",
  809. pinfo->alert_timeout);
  810. ipmi_pef_print_dec("Retries",
  811. (pinfo->retries & PEF_SERIAL_RETRIES_MASK));
  812. switch (wrk) {
  813. case PEF_SERIAL_DEST_TYPE_DIAL:
  814. ipmi_pef_print_serial_dest_dial(intf, "Serial dial string", &ssel);
  815. break;
  816. case PEF_SERIAL_DEST_TYPE_TAP:
  817. ipmi_pef_print_serial_dest_tap(intf, &ssel);
  818. break;
  819. case PEF_SERIAL_DEST_TYPE_PPP:
  820. /* ipmi_pef_print_serial_dest_ppp(intf, &ssel); */
  821. break;
  822. case PEF_SERIAL_DEST_TYPE_BASIC_CALLBACK:
  823. case PEF_SERIAL_DEST_TYPE_PPP_CALLBACK:
  824. /* ipmi_pef_print_serial_dest_callback(intf, &ssel); */
  825. break;
  826. }
  827. }
  828. }
  829. static void
  830. ipmi_pef_print_dest(struct ipmi_intf * intf, uint8_t ch, uint8_t dest)
  831. { /*
  832. // print generic alert destination info
  833. */
  834. ipmi_pef_print_dec("Destination ID", dest);
  835. }
  836. void
  837. ipmi_pef_print_event_info(struct pef_cfgparm_filter_table_entry * pef, char * buf)
  838. { /*
  839. // print PEF entry Event info: class, severity, trigger, etc.
  840. */
  841. static char * classes[] = {"Discrete", "Threshold", "OEM"};
  842. uint16_t offmask;
  843. char * p;
  844. unsigned int i;
  845. uint8_t t;
  846. ipmi_pef_print_str("Event severity",
  847. ipmi_pef_bit_desc(&pef_b2s_severities, pef->entry.severity));
  848. t = pef->entry.event_trigger;
  849. if (t == PEF_EVENT_TRIGGER_THRESHOLD)
  850. i = 1;
  851. else if (t > PEF_EVENT_TRIGGER_SENSOR_SPECIFIC)
  852. i = 2;
  853. else
  854. i = 0;
  855. ipmi_pef_print_str("Event class", classes[i]);
  856. offmask = ((pef->entry.event_data_1_offset_mask[1] << 8)
  857. + pef->entry.event_data_1_offset_mask[0]);
  858. if (offmask == 0xffff || t == PEF_EVENT_TRIGGER_MATCH_ANY)
  859. strcpy(buf, "Any");
  860. else if (t == PEF_EVENT_TRIGGER_UNSPECIFIED)
  861. strcpy(buf, "Unspecified");
  862. else if (t == PEF_EVENT_TRIGGER_SENSOR_SPECIFIC)
  863. strcpy(buf, "Sensor-specific");
  864. else if (t > PEF_EVENT_TRIGGER_SENSOR_SPECIFIC)
  865. strcpy(buf, "OEM");
  866. else {
  867. sprintf(buf, "(0x%02x/0x%04x)", t, offmask);
  868. p = strchr(buf, '\0');
  869. for (i=0; i<PEF_B2S_GENERIC_ER_ENTRIES; i++) {
  870. if (offmask & 1) {
  871. if ((t-1) >= PEF_B2S_GENERIC_ER_ENTRIES) {
  872. sprintf(p, ", Unrecognized event trigger");
  873. } else {
  874. sprintf(p, ",%s", ipmi_pef_bit_desc(pef_b2s_generic_ER[t-1], i));
  875. }
  876. p = strchr(p, '\0');
  877. }
  878. offmask >>= 1;
  879. }
  880. }
  881. ipmi_pef_print_str("Event trigger(s)", buf);
  882. }
  883. /* ipmi_pef_print_filter_entry - Print-out Entry of Event Filter Table. */
  884. static void
  885. ipmi_pef_print_filter_entry(struct pef_cfgparm_filter_table_entry *filter_entry)
  886. {
  887. char buf[128];
  888. uint8_t filter_enabled;
  889. uint8_t set;
  890. ipmi_pef_print_dec("PEF Filter Table entry", filter_entry->data1);
  891. filter_enabled = filter_entry->entry.config & PEF_CONFIG_ENABLED;
  892. sprintf(buf, "%sabled", (filter_enabled ? "en" : "dis"));
  893. switch (filter_entry->entry.config & 0x60) {
  894. case 0x40:
  895. strcat(buf, ", pre-configured");
  896. break;
  897. case 0x00:
  898. strcat(buf, ", configurable");
  899. break;
  900. default:
  901. /* Covers 0x60 and 0x20 which are reserved */
  902. strcat(buf, ", reserved");
  903. break;
  904. }
  905. ipmi_pef_print_str("Status", buf);
  906. if (!filter_enabled) {
  907. return;
  908. }
  909. ipmi_pef_print_str("Sensor type",
  910. ipmi_pef_bit_desc(&pef_b2s_sensortypes,
  911. filter_entry->entry.sensor_type));
  912. if (filter_entry->entry.sensor_number == PEF_SENSOR_NUMBER_MATCH_ANY) {
  913. ipmi_pef_print_str("Sensor number", "Any");
  914. } else {
  915. ipmi_pef_print_dec("Sensor number",
  916. filter_entry->entry.sensor_number);
  917. }
  918. ipmi_pef_print_event_info(filter_entry, buf);
  919. ipmi_pef_print_str("Action",
  920. ipmi_pef_bit_desc(&pef_b2s_actions,
  921. filter_entry->entry.action));
  922. if (filter_entry->entry.action & PEF_ACTION_ALERT) {
  923. set = (filter_entry->entry.policy_number & PEF_POLICY_NUMBER_MASK);
  924. ipmi_pef_print_int("Policy set", set);
  925. }
  926. }
  927. /* ipmi_pef2_filter_enable - Enable/Disable specific PEF Event Filter.
  928. *
  929. * @enable - enable(1) or disable(0) PEF Event Filter.
  930. * @filter_id - Filter ID of Entry in Event Filter Table.
  931. *
  932. * returns - 0 on success, any other value means error.
  933. */
  934. static int
  935. ipmi_pef2_filter_enable(struct ipmi_intf *intf, uint8_t enable, uint8_t filter_id)
  936. {
  937. struct pef_cfgparm_filter_table_data_1 filter_cfg;
  938. int rc;
  939. uint8_t filter_table_size;
  940. rc = _ipmi_get_pef_filter_table_size(intf, &filter_table_size);
  941. if (eval_ccode(rc) != 0) {
  942. return (-1);
  943. } else if (filter_table_size == 0) {
  944. lprintf(LOG_ERR, "PEF Filter isn't supported.");
  945. return (-1);
  946. } else if (filter_id > filter_table_size) {
  947. lprintf(LOG_ERR,
  948. "PEF Filter ID out of range. Valid range is (1..%d).",
  949. filter_table_size);
  950. return (-1);
  951. }
  952. memset(&filter_cfg, 0, sizeof(filter_cfg));
  953. rc = _ipmi_set_pef_filter_entry_cfg(intf, filter_id, &filter_cfg);
  954. if (eval_ccode(rc) != 0) {
  955. return (-1);
  956. }
  957. if (enable != 0) {
  958. /* Enable */
  959. filter_cfg.cfg |= PEF_FILTER_ENABLED;
  960. } else {
  961. /* Disable */
  962. filter_cfg.cfg &= PEF_FILTER_DISABLED;
  963. }
  964. rc = _ipmi_set_pef_filter_entry_cfg(intf, filter_id, &filter_cfg);
  965. if (eval_ccode(rc) != 0) {
  966. lprintf(LOG_ERR, "Failed to %s PEF Filter ID %d.",
  967. enable ? "enable" : "disable",
  968. filter_id);
  969. return (-1);
  970. }
  971. printf("PEF Filter ID %" PRIu8 " is %s now.\n", filter_id,
  972. enable ? "enabled" : "disabled");
  973. return rc;
  974. }
  975. void
  976. ipmi_pef2_filter_help(void)
  977. {
  978. lprintf(LOG_NOTICE,
  979. "usage: pef filter help");
  980. lprintf(LOG_NOTICE,
  981. " pef filter list");
  982. lprintf(LOG_NOTICE,
  983. " pef filter enable <id = 1..n>");
  984. lprintf(LOG_NOTICE,
  985. " pef filter disable <id = 1..n>");
  986. lprintf(LOG_NOTICE,
  987. " pef filter create <id = 1..n> <params>");
  988. lprintf(LOG_NOTICE,
  989. " pef filter delete <id = 1..n>");
  990. }
  991. /* ipmi_pef2_filter - Handle processing of "filter" CLI args. */
  992. int
  993. ipmi_pef2_filter(struct ipmi_intf *intf, int argc, char **argv)
  994. {
  995. int rc = 0;
  996. if (argc < 1) {
  997. lprintf(LOG_ERR, "Not enough parameters given.");
  998. ipmi_pef2_filter_help();
  999. rc = (-1);
  1000. } else if (!strncmp(argv[0], "help\0", 5)) {
  1001. ipmi_pef2_filter_help();
  1002. rc = 0;
  1003. } else if (!strncmp(argv[0], "list\0", 5)) {
  1004. rc = ipmi_pef2_list_filters(intf);
  1005. } else if (!strncmp(argv[0], "enable\0", 7)
  1006. ||(!strncmp(argv[0], "disable\0", 8))) {
  1007. uint8_t enable;
  1008. uint8_t filter_id;
  1009. if (argc != 2) {
  1010. lprintf(LOG_ERR, "Not enough arguments given.");
  1011. ipmi_pef2_filter_help();
  1012. return (-1);
  1013. }
  1014. if (str2uchar(argv[1], &filter_id) != 0) {
  1015. lprintf(LOG_ERR, "Invalid PEF Event Filter ID given: %s", argv[1]);
  1016. return (-1);
  1017. } else if (filter_id < 1) {
  1018. lprintf(LOG_ERR, "PEF Event Filter ID out of range. "
  1019. "Valid range is <1..255>.");
  1020. return (-1);
  1021. }
  1022. if (!strncmp(argv[0], "enable\0", 7)) {
  1023. enable = 1;
  1024. } else {
  1025. enable = 0;
  1026. }
  1027. rc = ipmi_pef2_filter_enable(intf, enable, filter_id);
  1028. } else if (!strncmp(argv[0], "create\0", 7)) {
  1029. lprintf(LOG_ERR, "Not implemented.");
  1030. rc = 1;
  1031. } else if (!strncmp(argv[0], "delete\0", 7)) {
  1032. lprintf(LOG_ERR, "Not implemented.");
  1033. rc = 1;
  1034. } else {
  1035. lprintf(LOG_ERR, "Invalid PEF Filter command: %s", argv[0]);
  1036. ipmi_pef2_filter_help();
  1037. rc = 1;
  1038. }
  1039. return rc;
  1040. }
  1041. /* ipmi_pef2_get_info - Reports PEF capabilities + System GUID */
  1042. static int
  1043. ipmi_pef2_get_info(struct ipmi_intf *intf)
  1044. {
  1045. struct pef_capabilities pcap;
  1046. struct pef_cfgparm_system_guid psys_guid;
  1047. struct ipmi_guid_t guid;
  1048. int rc;
  1049. uint8_t *guid_ptr = NULL;
  1050. uint8_t policy_table_size;
  1051. rc = _ipmi_get_pef_policy_table_size(intf, &policy_table_size);
  1052. if (eval_ccode(rc) != 0) {
  1053. lprintf(LOG_WARN, "Failed to get size of PEF Policy Table.");
  1054. policy_table_size = 0;
  1055. }
  1056. rc = _ipmi_get_pef_capabilities(intf, &pcap);
  1057. if (eval_ccode(rc) != 0) {
  1058. lprintf(LOG_ERR, "Failed to get PEF Capabilities.");
  1059. return (-1);
  1060. }
  1061. ipmi_pef_print_1xd("Version", pcap.version);
  1062. ipmi_pef_print_dec("PEF Event Filter count",
  1063. pcap.event_filter_count);
  1064. ipmi_pef_print_dec("PEF Alert Policy Table size",
  1065. policy_table_size);
  1066. rc = _ipmi_get_pef_system_guid(intf, &psys_guid);
  1067. if (rc != 0x80 && eval_ccode(rc) != 0) {
  1068. lprintf(LOG_ERR, "Failed to get PEF System GUID. %i", rc);
  1069. return (-1);
  1070. } else if (psys_guid.data1 == 0x1) {
  1071. /* IPMI_CMD_GET_SYSTEM_GUID */
  1072. guid_ptr = &psys_guid.guid[0];
  1073. } else {
  1074. rc = _ipmi_mc_get_guid(intf, &guid);
  1075. if (rc == 0) {
  1076. guid_ptr = (uint8_t *)&guid;
  1077. }
  1078. }
  1079. /* Got GUID? */
  1080. if (guid_ptr) {
  1081. ipmi_pef_print_guid(guid_ptr);
  1082. }
  1083. ipmi_pef_print_flags(&pef_b2s_actions, P_SUPP, pcap.actions);
  1084. return 0;
  1085. }
  1086. /* ipmi_pef2_get_status - TODO rewrite - report the PEF status */
  1087. static int
  1088. ipmi_pef2_get_status(struct ipmi_intf *intf)
  1089. {
  1090. struct ipmi_rs *rsp;
  1091. struct ipmi_rq req;
  1092. struct pef_cfgparm_selector psel;
  1093. char tbuf[40];
  1094. uint32_t timei;
  1095. time_t ts;
  1096. memset(&req, 0, sizeof(req));
  1097. req.msg.netfn = IPMI_NETFN_SE;
  1098. req.msg.cmd = IPMI_CMD_GET_LAST_PROCESSED_EVT_ID;
  1099. rsp = ipmi_pef_msg_exchange(intf, &req, "Last S/W processed ID");
  1100. if (!rsp) {
  1101. lprintf(LOG_ERR, " **Error retrieving %s",
  1102. "Last S/W processed ID");
  1103. return (-1);
  1104. }
  1105. memcpy(&timei, rsp->data, sizeof(timei));
  1106. #if WORDS_BIGENDIAN
  1107. timei = BSWAP_32(timei);
  1108. #endif
  1109. ts = (time_t)timei;
  1110. strftime(tbuf, sizeof(tbuf), "%m/%d/%Y %H:%M:%S", gmtime(&ts));
  1111. ipmi_pef_print_str("Last SEL addition", tbuf);
  1112. ipmi_pef_print_2xd("Last SEL record ID", rsp->data[5], rsp->data[4]);
  1113. ipmi_pef_print_2xd("Last S/W processed ID", rsp->data[7], rsp->data[6]);
  1114. ipmi_pef_print_2xd("Last BMC processed ID", rsp->data[9], rsp->data[8]);
  1115. memset(&psel, 0, sizeof(psel));
  1116. psel.id = PEF_CFGPARM_ID_PEF_CONTROL;
  1117. memset(&req, 0, sizeof(req));
  1118. req.msg.netfn = IPMI_NETFN_SE;
  1119. req.msg.cmd = IPMI_CMD_GET_PEF_CONFIG_PARMS;
  1120. req.msg.data = (uint8_t *)&psel;
  1121. req.msg.data_len = sizeof(psel);
  1122. rsp = ipmi_pef_msg_exchange(intf, &req, "PEF control");
  1123. if (!rsp) {
  1124. lprintf(LOG_ERR, " **Error retrieving %s",
  1125. "PEF control");
  1126. return (-1);
  1127. }
  1128. ipmi_pef_print_flags(&pef_b2s_control, P_ABLE, rsp->data[1]);
  1129. psel.id = PEF_CFGPARM_ID_PEF_ACTION;
  1130. rsp = ipmi_pef_msg_exchange(intf, &req, "PEF action");
  1131. if (!rsp) {
  1132. lprintf(LOG_ERR, " **Error retrieving %s",
  1133. "PEF action");
  1134. return (-1);
  1135. }
  1136. ipmi_pef_print_flags(&pef_b2s_actions, P_ACTV, rsp->data[1]);
  1137. return 0;
  1138. }
  1139. /* ipmi_pef2_list_filters - List all entries in PEF Event Filter Table. */
  1140. static int
  1141. ipmi_pef2_list_filters(struct ipmi_intf *intf)
  1142. {
  1143. struct pef_capabilities pcap;
  1144. struct pef_cfgparm_filter_table_entry filter_entry;
  1145. int rc;
  1146. uint8_t i;
  1147. rc = _ipmi_get_pef_capabilities(intf, &pcap);
  1148. if (eval_ccode(rc) != 0) {
  1149. return (-1);
  1150. } else if (pcap.event_filter_count == 0) {
  1151. lprintf(LOG_ERR, "PEF Event Filtering isn't supported.");
  1152. return (-1);
  1153. }
  1154. for (i = 1; i <= pcap.event_filter_count; i++) {
  1155. first_field = 1;
  1156. rc = _ipmi_get_pef_filter_entry(intf, i, &filter_entry);
  1157. if (eval_ccode(rc) != 0) {
  1158. lprintf(LOG_ERR, "Failed to get PEF Event Filter Entry %i.",
  1159. i);
  1160. continue;
  1161. }
  1162. ipmi_pef_print_filter_entry(&filter_entry);
  1163. printf("\n");
  1164. }
  1165. return 0;
  1166. }
  1167. /* ipmi_pef2_list_policies - List Entries in PEF Alert Policy Table. */
  1168. static int
  1169. ipmi_pef2_list_policies(struct ipmi_intf *intf)
  1170. {
  1171. struct channel_info_t channel_info;
  1172. struct pef_cfgparm_policy_table_entry entry;
  1173. int rc;
  1174. uint8_t dest;
  1175. uint8_t i;
  1176. uint8_t policy_table_size;
  1177. rc = _ipmi_get_pef_policy_table_size(intf, &policy_table_size);
  1178. if (eval_ccode(rc) != 0) {
  1179. return (-1);
  1180. } else if (policy_table_size == 0) {
  1181. lprintf(LOG_ERR, "PEF Alert Policy isn't supported.");
  1182. return (-1);
  1183. }
  1184. for (i = 1; i <= policy_table_size; i++) {
  1185. first_field = 1;
  1186. rc = _ipmi_get_pef_policy_entry(intf, i, &entry);
  1187. if (eval_ccode(rc) != 0) {
  1188. continue;
  1189. }
  1190. ipmi_pef_print_dec("Alert policy table entry",
  1191. (entry.data1 & PEF_POLICY_TABLE_ID_MASK));
  1192. ipmi_pef_print_dec("Policy set",
  1193. (entry.entry.policy & PEF_POLICY_ID_MASK) >> PEF_POLICY_ID_SHIFT);
  1194. ipmi_pef_print_str("State",
  1195. entry.entry.policy & PEF_POLICY_ENABLED ? "enabled" : "disabled");
  1196. ipmi_pef_print_str("Policy entry rule",
  1197. ipmi_pef_bit_desc(&pef_b2s_policies,
  1198. (entry.entry.policy & PEF_POLICY_FLAGS_MASK)));
  1199. if (entry.entry.alert_string_key & PEF_POLICY_EVENT_SPECIFIC) {
  1200. ipmi_pef_print_str("Event-specific", "true");
  1201. }
  1202. channel_info.channel = ((entry.entry.chan_dest &
  1203. PEF_POLICY_CHANNEL_MASK) >>
  1204. PEF_POLICY_CHANNEL_SHIFT);
  1205. rc = _ipmi_get_channel_info(intf, &channel_info);
  1206. if (eval_ccode(rc) != 0) {
  1207. continue;
  1208. }
  1209. ipmi_pef_print_dec("Channel number", channel_info.channel);
  1210. ipmi_pef_print_str("Channel medium",
  1211. ipmi_pef_bit_desc(&pef_b2s_ch_medium,
  1212. channel_info.medium));
  1213. dest = entry.entry.chan_dest & PEF_POLICY_DESTINATION_MASK;
  1214. switch (channel_info.medium) {
  1215. case PEF_CH_MEDIUM_TYPE_LAN:
  1216. ipmi_pef_print_lan_dest(intf, channel_info.channel,
  1217. dest);
  1218. break;
  1219. case PEF_CH_MEDIUM_TYPE_SERIAL:
  1220. ipmi_pef_print_serial_dest(intf, channel_info.channel,
  1221. dest);
  1222. break;
  1223. default:
  1224. ipmi_pef_print_dest(intf, channel_info.channel, dest);
  1225. break;
  1226. }
  1227. printf("\n");
  1228. }
  1229. return 0;
  1230. }
  1231. void
  1232. ipmi_pef2_policy_help(void)
  1233. {
  1234. lprintf(LOG_NOTICE,
  1235. "usage: pef policy help");
  1236. lprintf(LOG_NOTICE,
  1237. " pef policy list");
  1238. lprintf(LOG_NOTICE,
  1239. " pef policy enable <id = 1..n>");
  1240. lprintf(LOG_NOTICE,
  1241. " pef policy disable <id = 1..n>");
  1242. lprintf(LOG_NOTICE,
  1243. " pef policy create <id = 1..n> <params>");
  1244. lprintf(LOG_NOTICE,
  1245. " pef policy delete <id = 1..n>");
  1246. }
  1247. /* ipmi_pef2_policy_enable - Enable/Disable specific PEF policy
  1248. *
  1249. * @enable - enable(1) or disable(0) PEF Alert Policy
  1250. * @policy_id - Policy ID of Entry in Alert Policy Table.
  1251. *
  1252. * returns - 0 on success, any other value means error.
  1253. */
  1254. static int
  1255. ipmi_pef2_policy_enable(struct ipmi_intf *intf, int enable, uint8_t policy_id)
  1256. {
  1257. struct pef_cfgparm_policy_table_entry policy_entry;
  1258. int rc;
  1259. uint8_t policy_table_size;
  1260. rc = _ipmi_get_pef_policy_table_size(intf, &policy_table_size);
  1261. if (eval_ccode(rc) != 0) {
  1262. return (-1);
  1263. } else if (policy_table_size == 0) {
  1264. lprintf(LOG_ERR, "PEF Policy isn't supported.");
  1265. return (-1);
  1266. } else if (policy_id > policy_table_size) {
  1267. lprintf(LOG_ERR,
  1268. "PEF Policy ID out of range. Valid range is (1..%d).",
  1269. policy_table_size);
  1270. return (-1);
  1271. }
  1272. memset(&policy_entry, 0, sizeof(policy_entry));
  1273. rc = _ipmi_get_pef_policy_entry(intf, policy_id, &policy_entry);
  1274. if (eval_ccode(rc) != 0) {
  1275. return (-1);
  1276. }
  1277. if (enable != 0) {
  1278. /* Enable */
  1279. policy_entry.entry.policy |= PEF_POLICY_ENABLED;
  1280. } else {
  1281. /* Disable */
  1282. policy_entry.entry.policy &= PEF_POLICY_DISABLED;
  1283. }
  1284. rc = _ipmi_set_pef_policy_entry(intf, policy_id, &policy_entry);
  1285. if (eval_ccode(rc) != 0) {
  1286. lprintf(LOG_ERR, "Failed to %s PEF Policy ID %d.",
  1287. enable ? "enable" : "disable",
  1288. policy_id);
  1289. return (-1);
  1290. }
  1291. printf("PEF Policy ID %" PRIu8 " is %s now.\n", policy_id,
  1292. enable ? "enabled" : "disabled");
  1293. return rc;
  1294. }
  1295. /* ipmi_pef2_policy - Handle processing of "policy" CLI args. */
  1296. int
  1297. ipmi_pef2_policy(struct ipmi_intf *intf, int argc, char **argv)
  1298. {
  1299. int rc = 0;
  1300. if (argc < 1) {
  1301. lprintf(LOG_ERR, "Not enough parameters given.");
  1302. ipmi_pef2_policy_help();
  1303. rc = (-1);
  1304. } else if (!strncmp(argv[0], "help\0", 5)) {
  1305. ipmi_pef2_policy_help();
  1306. rc = 0;
  1307. } else if (!strncmp(argv[0], "list\0", 5)) {
  1308. rc = ipmi_pef2_list_policies(intf);
  1309. } else if (!strncmp(argv[0], "enable\0", 7)
  1310. || !strncmp(argv[0], "disable\0", 8)) {
  1311. uint8_t enable;
  1312. uint8_t policy_id;
  1313. if (argc != 2) {
  1314. lprintf(LOG_ERR, "Not enough arguments given.");
  1315. ipmi_pef2_policy_help();
  1316. return (-1);
  1317. }
  1318. if (str2uchar(argv[1], &policy_id) != 0) {
  1319. lprintf(LOG_ERR, "Invalid PEF Policy ID given: %s", argv[1]);
  1320. return (-1);
  1321. } else if (policy_id < 1 || policy_id > 127) {
  1322. lprintf(LOG_ERR, "PEF Policy ID out of range. Valid range is <1..127>.");
  1323. return (-1);
  1324. }
  1325. if (!strncmp(argv[0], "enable\0", 7)) {
  1326. enable = 1;
  1327. } else {
  1328. enable = 0;
  1329. }
  1330. rc = ipmi_pef2_policy_enable(intf, enable, policy_id);
  1331. } else if (!strncmp(argv[0], "create\0", 7)) {
  1332. lprintf(LOG_ERR, "Not implemented.");
  1333. rc = 1;
  1334. } else if (!strncmp(argv[0], "delete\0", 7)) {
  1335. lprintf(LOG_ERR, "Not implemented.");
  1336. rc = 1;
  1337. } else {
  1338. lprintf(LOG_ERR, "Invalid PEF Policy command: %s", argv[0]);
  1339. ipmi_pef2_policy_help();
  1340. rc = 1;
  1341. }
  1342. return rc;
  1343. }
  1344. /* ipmi_pef2_help - print-out help text. */
  1345. void
  1346. ipmi_pef2_help(void)
  1347. {
  1348. lprintf(LOG_NOTICE,
  1349. "usage: pef help");
  1350. lprintf(LOG_NOTICE,
  1351. " pef capabilities");
  1352. lprintf(LOG_NOTICE,
  1353. " pef event <params>");
  1354. lprintf(LOG_NOTICE,
  1355. " pef filter list");
  1356. lprintf(LOG_NOTICE,
  1357. " pef filter enable <id = 1..n>");
  1358. lprintf(LOG_NOTICE,
  1359. " pef filter disable <id = 1..n>");
  1360. lprintf(LOG_NOTICE,
  1361. " pef filter create <id = 1..n> <params>");
  1362. lprintf(LOG_NOTICE,
  1363. " pef filter delete <id = 1..n>");
  1364. lprintf(LOG_NOTICE,
  1365. " pef info");
  1366. lprintf(LOG_NOTICE,
  1367. " pef policy list");
  1368. lprintf(LOG_NOTICE,
  1369. " pef policy enable <id = 1..n>");
  1370. lprintf(LOG_NOTICE,
  1371. " pef policy disable <id = 1..n>");
  1372. lprintf(LOG_NOTICE,
  1373. " pef policy create <id = 1..n> <params>");
  1374. lprintf(LOG_NOTICE,
  1375. " pef policy delete <id = 1..n>");
  1376. lprintf(LOG_NOTICE,
  1377. " pef pet ack <params>");
  1378. lprintf(LOG_NOTICE,
  1379. " pef status");
  1380. lprintf(LOG_NOTICE,
  1381. " pef timer get");
  1382. lprintf(LOG_NOTICE,
  1383. " pef timer set <0x00-0xFF>");
  1384. }
  1385. int ipmi_pef_main(struct ipmi_intf *intf, int argc, char **argv)
  1386. {
  1387. int rc = 0;
  1388. if (argc < 1) {
  1389. lprintf(LOG_ERR, "Not enough parameters given.");
  1390. ipmi_pef2_help();
  1391. rc = (-1);
  1392. } else if (!strncmp(argv[0], "help\0", 5)) {
  1393. ipmi_pef2_help();
  1394. rc = 0;
  1395. } else if (!strncmp(argv[0], "capabilities\0", 13)) {
  1396. /* rc = ipmi_pef2_get_capabilities(intf); */
  1397. lprintf(LOG_ERR, "Not implemented.");
  1398. rc = 1;
  1399. } else if (!strncmp(argv[0], "event\0", 6)) {
  1400. /* rc = ipmi_pef2_event(intf, (argc - 1), ++argv); */
  1401. lprintf(LOG_ERR, "Not implemented.");
  1402. rc = 1;
  1403. } else if (!strncmp(argv[0], "filter\0", 7)) {
  1404. rc = ipmi_pef2_filter(intf, (argc - 1), ++argv);
  1405. } else if (!strncmp(argv[0], "info\0", 5)) {
  1406. rc = ipmi_pef2_get_info(intf);
  1407. } else if (!strncmp(argv[0], "pet\0", 4)) {
  1408. /* rc = ipmi_pef2_pet(intf, (argc - 1), ++argv); */
  1409. lprintf(LOG_ERR, "Not implemented.");
  1410. rc = 1;
  1411. } else if (!strncmp(argv[0], "policy\0", 7)) {
  1412. rc = ipmi_pef2_policy(intf, (argc - 1), ++argv);
  1413. } else if (!strncmp(argv[0], "status\0", 7)) {
  1414. rc = ipmi_pef2_get_status(intf);
  1415. } else if (!strncmp(argv[0], "timer\0", 6)) {
  1416. /* rc = ipmi_pef2_timer(intf, (argc - 1), ++argv); */
  1417. lprintf(LOG_ERR, "Not implemented.");
  1418. rc = 1;
  1419. } else {
  1420. lprintf(LOG_ERR, "Invalid PEF command: '%s'\n", argv[0]);
  1421. rc = (-1);
  1422. }
  1423. return rc;
  1424. }