ipmi_vita.c 26 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012
  1. /*
  2. * Copyright (c) 2014 Pigeon Point Systems. All right 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 Pigeon Point Systems, 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. * PIGEON POINT SYSTEMS ("PPS") 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. * PPS 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 PPS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  31. */
  32. #include <ipmitool/ipmi_intf.h>
  33. #include <ipmitool/ipmi_picmg.h>
  34. #include <ipmitool/ipmi_vita.h>
  35. #include <ipmitool/ipmi_fru.h>
  36. #include <ipmitool/ipmi_strings.h>
  37. #include <ipmitool/log.h>
  38. /* Handled VITA 46.11 commands */
  39. #define VITA_CMD_HELP 0
  40. #define VITA_CMD_PROPERTIES 1
  41. #define VITA_CMD_FRUCONTROL 2
  42. #define VITA_CMD_ADDRINFO 3
  43. #define VITA_CMD_ACTIVATE 4
  44. #define VITA_CMD_DEACTIVATE 5
  45. #define VITA_CMD_POLICY_GET 6
  46. #define VITA_CMD_POLICY_SET 7
  47. #define VITA_CMD_LED_PROP 8
  48. #define VITA_CMD_LED_CAP 9
  49. #define VITA_CMD_LED_GET 10
  50. #define VITA_CMD_LED_SET 11
  51. #define VITA_CMD_UNKNOWN 255
  52. /* VITA 46.11 Site Type strings */
  53. static struct valstr vita_site_types[] = {
  54. { VITA_FRONT_VPX_MODULE, "Front Loading VPX Plug-In Module" },
  55. { VITA_POWER_ENTRY, "Power Entry Module" },
  56. { VITA_CHASSIS_FRU, "Chassic FRU Information Module" },
  57. { VITA_DEDICATED_CHMC, "Dedicated Chassis Manager" },
  58. { VITA_FAN_TRAY, "Fan Tray" },
  59. { VITA_FAN_TRAY_FILTER, "Fan Tray Filter" },
  60. { VITA_ALARM_PANEL, "Alarm Panel" },
  61. { VITA_XMC, "XMC" },
  62. { VITA_VPX_RTM, "VPX Rear Transition Module" },
  63. { VITA_FRONT_VME_MODULE, "Front Loading VME Plug-In Module" },
  64. { VITA_FRONT_VXS_MODULE, "Front Loading VXS Plug-In Module" },
  65. { VITA_POWER_SUPPLY, "Power Supply" },
  66. { VITA_FRONT_VITA62_MODULE, "Front Loading VITA 62 Module\n" },
  67. { VITA_71_MODULE, "VITA 71 Module\n" },
  68. { VITA_FMC, "FMC\n" },
  69. { 0, NULL }
  70. };
  71. /* VITA 46.11 command help strings */
  72. static struct valstr vita_help_strings[] = {
  73. {
  74. VITA_CMD_HELP,
  75. "VITA commands:\n"
  76. " properties - get VSO properties\n"
  77. " frucontrol - FRU control\n"
  78. " addrinfo - get address information\n"
  79. " activate - activate a FRU\n"
  80. " deactivate - deactivate a FRU\n"
  81. " policy get - get the FRU activation policy\n"
  82. " policy set - set the FRU activation policy\n"
  83. " led prop - get led properties\n"
  84. " led cap - get led color capabilities\n"
  85. " led get - get led state\n"
  86. " led set - set led state"
  87. },
  88. {
  89. VITA_CMD_FRUCONTROL,
  90. "usage: frucontrol <FRU-ID> <OPTION>\n"
  91. " OPTION: 0 - Cold Reset\n"
  92. " 1 - Warm Reset\n"
  93. " 2 - Graceful Reboot\n"
  94. " 3 - Issue Diagnostic Interrupt"
  95. },
  96. {
  97. VITA_CMD_ADDRINFO,
  98. "usage: addrinfo [<FRU-ID>]"
  99. },
  100. {
  101. VITA_CMD_ACTIVATE,
  102. "usage: activate <FRU-ID>"
  103. },
  104. {
  105. VITA_CMD_DEACTIVATE,
  106. "usage: deactivate <FRU-ID>"
  107. },
  108. {
  109. VITA_CMD_POLICY_GET,
  110. "usage: policy get <FRU-ID>"
  111. },
  112. {
  113. VITA_CMD_POLICY_SET,
  114. "usage: policy set <FRU-ID> <MASK> <VALUE>\n"
  115. " MASK: [3] affect the Default-Activation-Locked Policy Bit\n"
  116. " [2] affect the Commanded-Deactivation-Ignored Policy Bit\n"
  117. " [1] affect the Deactivation-Locked Policy Bit\n"
  118. " [0] affect the Activation-Locked Policy Bit\n"
  119. " VALUE: [3] value for the Default-Activation-Locked Policy Bit\n"
  120. " [2] value for the Commanded-Deactivation-Ignored Policy Bit\n"
  121. " [1] value for the Deactivation-Locked Policy Bit\n"
  122. " [0] value for the Activation-Locked Policy Bit"
  123. },
  124. {
  125. VITA_CMD_LED_PROP,
  126. "usage: led prop <FRU-ID>"
  127. },
  128. {
  129. VITA_CMD_LED_CAP,
  130. "usage: led cap <FRU-ID> <LED-ID"
  131. },
  132. {
  133. VITA_CMD_LED_GET,
  134. "usage: led get <FRU-ID> <LED-ID",
  135. },
  136. {
  137. VITA_CMD_LED_SET,
  138. "usage: led set <FRU-ID> <LED-ID> <FUNCTION> <DURATION> <COLOR>\n"
  139. " <FRU-ID>\n"
  140. " <LED-ID> 0-0xFE: Specified LED\n"
  141. " 0xFF: All LEDs under management control\n"
  142. " <FUNCTION> 0: LED OFF override\n"
  143. " 1 - 250: LED blinking override (off duration)\n"
  144. " 251: LED Lamp Test\n"
  145. " 252: LED restore to local control\n"
  146. " 255: LED ON override\n"
  147. " <DURATION> 1 - 127: LED Lamp Test / on duration\n"
  148. " <COLOR> 1: BLUE\n"
  149. " 2: RED\n"
  150. " 3: GREEN\n"
  151. " 4: AMBER\n"
  152. " 5: ORANGE\n"
  153. " 6: WHITE\n"
  154. " 0xE: do not change\n"
  155. " 0xF: use default color"
  156. },
  157. {
  158. VITA_CMD_UNKNOWN,
  159. "Unknown command"
  160. },
  161. { 0, NULL }
  162. };
  163. /* check if VITA 46.11 is supported */
  164. uint8_t
  165. vita_discover(struct ipmi_intf *intf)
  166. {
  167. struct ipmi_rq req;
  168. struct ipmi_rs *rsp;
  169. unsigned char msg_data;
  170. int vita_avail = 0;
  171. memset(&req, 0, sizeof(req));
  172. req.msg.netfn = IPMI_NETFN_PICMG;
  173. req.msg.cmd = VITA_GET_VSO_CAPABILITIES_CMD;
  174. req.msg.data = &msg_data;
  175. req.msg.data_len = 1;
  176. msg_data = GROUP_EXT_VITA;
  177. lprintf(LOG_INFO, "Running Get VSO Capabilities my_addr %#x, "
  178. "transit %#x, target %#x",
  179. intf->my_addr, intf->transit_addr, intf->target_addr);
  180. rsp = intf->sendrecv(intf, &req);
  181. if (rsp == NULL) {
  182. lprintf(LOG_ERR, "No valid response received");
  183. } else if (rsp->ccode == 0xC1) {
  184. lprintf(LOG_INFO, "Invalid completion code received: %s",
  185. val2str(rsp->ccode, completion_code_vals));
  186. } else if (rsp->ccode == 0xCC) {
  187. lprintf(LOG_INFO, "Invalid data field received: %s",
  188. val2str(rsp->ccode, completion_code_vals));
  189. } else if (rsp->ccode != 0) {
  190. lprintf(LOG_INFO, "Invalid completion code received: %s",
  191. val2str(rsp->ccode, completion_code_vals));
  192. } else if (rsp->data_len < 5) {
  193. lprintf(LOG_INFO, "Invalid response length %d",
  194. rsp->data_len);
  195. } else if (rsp->data[0] != GROUP_EXT_VITA) {
  196. lprintf(LOG_INFO, "Invalid group extension %#x",
  197. rsp->data[0]);
  198. } else if ((rsp->data[3] & 0x03) != 0) {
  199. lprintf(LOG_INFO, "Unknown VSO Standard %d",
  200. (rsp->data[3] & 0x03));
  201. } else if ((rsp->data[4] & 0x0F) != 1) {
  202. lprintf(LOG_INFO, "Unknown VSO Specification Revision %d.%d",
  203. (rsp->data[4] & 0x0F), (rsp->data[4] >> 4));
  204. } else {
  205. vita_avail = 1;
  206. lprintf(LOG_INFO, "Discovered VITA 46.11 Revision %d.%d",
  207. (rsp->data[4] & 0x0F), (rsp->data[4] >> 4));
  208. }
  209. return vita_avail;
  210. }
  211. uint8_t
  212. ipmi_vita_ipmb_address(struct ipmi_intf *intf)
  213. {
  214. struct ipmi_rq req;
  215. struct ipmi_rs *rsp;
  216. unsigned char msg_data;
  217. memset(&req, 0, sizeof(req));
  218. req.msg.netfn = IPMI_NETFN_PICMG;
  219. req.msg.cmd = VITA_GET_FRU_ADDRESS_INFO_CMD;
  220. req.msg.data = &msg_data;
  221. req.msg.data_len = 1;
  222. msg_data = GROUP_EXT_VITA;
  223. rsp = intf->sendrecv(intf, &req);
  224. if (rsp == NULL) {
  225. lprintf(LOG_ERR, "No valid response received");
  226. } else if (rsp->ccode != 0) {
  227. lprintf(LOG_ERR, "Invalid completion code received: %s",
  228. val2str(rsp->ccode, completion_code_vals));
  229. } else if (rsp->data_len < 7) {
  230. lprintf(LOG_ERR, "Invalid response length %d",
  231. rsp->data_len);
  232. } else if (rsp->data[0] != GROUP_EXT_VITA) {
  233. lprintf(LOG_ERR, "Invalid group extension %#x",
  234. rsp->data[0]);
  235. } else {
  236. return rsp->data[2];
  237. }
  238. return 0;
  239. }
  240. static int
  241. ipmi_vita_getaddr(struct ipmi_intf *intf, int argc, char **argv)
  242. {
  243. struct ipmi_rs *rsp;
  244. struct ipmi_rq req;
  245. unsigned char msg_data[2];
  246. memset(&req, 0, sizeof(req));
  247. req.msg.netfn = IPMI_NETFN_PICMG;
  248. req.msg.cmd = VITA_GET_FRU_ADDRESS_INFO_CMD;
  249. req.msg.data = msg_data;
  250. req.msg.data_len = 2;
  251. msg_data[0] = GROUP_EXT_VITA; /* VITA identifier */
  252. msg_data[1] = 0; /* default FRU ID */
  253. if (argc > 0) {
  254. /* validate and get FRU Device ID */
  255. if (is_fru_id(argv[0], &msg_data[1]) != 0) {
  256. return -1;
  257. }
  258. }
  259. rsp = intf->sendrecv(intf, &req);
  260. if (rsp == NULL) {
  261. lprintf(LOG_ERR, "No valid response received");
  262. return -1;
  263. } else if (rsp->ccode != 0) {
  264. lprintf(LOG_ERR, "Invalid completion code received: %s",
  265. val2str(rsp->ccode, completion_code_vals));
  266. return -1;
  267. } else if (rsp->data_len < 7) {
  268. lprintf(LOG_ERR, "Invalid response length %d",
  269. rsp->data_len);
  270. return -1;
  271. } else if (rsp->data[0] != GROUP_EXT_VITA) {
  272. lprintf(LOG_ERR, "Invalid group extension %#x",
  273. rsp->data[0]);
  274. return -1;
  275. }
  276. printf("Hardware Address : 0x%02x\n", rsp->data[1]);
  277. printf("IPMB-0 Address : 0x%02x\n", rsp->data[2]);
  278. printf("FRU ID : 0x%02x\n", rsp->data[4]);
  279. printf("Site ID : 0x%02x\n", rsp->data[5]);
  280. printf("Site Type : %s\n", val2str(rsp->data[6],
  281. vita_site_types));
  282. if (rsp->data_len > 8) {
  283. printf("Channel 7 Address: 0x%02x\n", rsp->data[8]);
  284. }
  285. return 0;
  286. }
  287. static int
  288. ipmi_vita_get_vso_capabilities(struct ipmi_intf *intf)
  289. {
  290. struct ipmi_rs *rsp;
  291. struct ipmi_rq req;
  292. unsigned char msg_data, tmp;
  293. memset(&req, 0, sizeof(req));
  294. req.msg.netfn = IPMI_NETFN_PICMG;
  295. req.msg.cmd = VITA_GET_VSO_CAPABILITIES_CMD;
  296. req.msg.data = &msg_data;
  297. req.msg.data_len = 1;
  298. msg_data = GROUP_EXT_VITA; /* VITA identifier */
  299. rsp = intf->sendrecv(intf, &req);
  300. if (rsp == NULL) {
  301. lprintf(LOG_ERR, "No valid response received.");
  302. return -1;
  303. } else if (rsp->ccode != 0) {
  304. lprintf(LOG_ERR, "Invalid completion code received: %s",
  305. val2str(rsp->ccode, completion_code_vals));
  306. return -1;
  307. } else if (rsp->data_len < 5) {
  308. lprintf(LOG_ERR, "Invalid response length %d", rsp->data_len);
  309. return -1;
  310. } else if (rsp->data[0] != GROUP_EXT_VITA) {
  311. lprintf(LOG_ERR, "Invalid group extension %#x", rsp->data[0]);
  312. return -1;
  313. }
  314. printf("VSO Identifier : 0x%02x\n", rsp->data[0]);
  315. printf("IPMC Identifier : 0x%02x\n", rsp->data[1]);
  316. printf(" Tier %d\n", (rsp->data[1] & 0x03) + 1);
  317. printf(" Layer %d\n", ((rsp->data[1] & 0x30) >> 4) + 1);
  318. printf("IPMB Capabilities : 0x%02x\n", rsp->data[2]);
  319. tmp = (rsp->data[2] & 0x30) >> 4;
  320. printf(" Frequency %skHz\n",
  321. tmp == 0 ? "100" : tmp == 1 ? "400" : "RESERVED");
  322. tmp = rsp->data[2] & 3;
  323. if (tmp == 1) {
  324. printf(" 2 IPMB interfaces supported\n");
  325. } else if (tmp == 0) {
  326. printf(" 1 IPMB interface supported\n");
  327. }
  328. printf("VSO Standard : %s\n",
  329. (rsp->data[3] & 0x3) == 0 ? "VITA 46.11" : "RESERVED");
  330. printf("VSO Spec Revision : %d.%d\n", rsp->data[4] & 0xf,
  331. rsp->data[4] >> 4);
  332. printf("Max FRU Device ID : 0x%02x\n", rsp->data[5]);
  333. printf("FRU Device ID : 0x%02x\n", rsp->data[6]);
  334. return 0;
  335. }
  336. static int
  337. ipmi_vita_set_fru_activation(struct ipmi_intf *intf,
  338. char **argv, unsigned char command)
  339. {
  340. struct ipmi_rs *rsp;
  341. struct ipmi_rq req;
  342. unsigned char msg_data[3];
  343. memset(&req, 0, sizeof(req));
  344. req.msg.netfn = IPMI_NETFN_PICMG;
  345. req.msg.cmd = VITA_SET_FRU_ACTIVATION_CMD;
  346. req.msg.data = msg_data;
  347. req.msg.data_len = 3;
  348. msg_data[0] = GROUP_EXT_VITA; /* VITA identifier */
  349. if (is_fru_id(argv[0], &msg_data[1]) != 0) { /* FRU ID */
  350. return -1;
  351. }
  352. msg_data[2] = command; /* command */
  353. rsp = intf->sendrecv(intf, &req);
  354. if (rsp == NULL) {
  355. lprintf(LOG_ERR, "No valid response received.");
  356. return -1;
  357. } else if (rsp->ccode != 0) {
  358. lprintf(LOG_ERR, "Invalid completion code received: %s",
  359. val2str(rsp->ccode, completion_code_vals));
  360. return -1;
  361. } else if (rsp->data_len < 1) {
  362. lprintf(LOG_ERR, "Invalid response length %d", rsp->data_len);
  363. return -1;
  364. } else if (rsp->data[0] != GROUP_EXT_VITA) {
  365. lprintf(LOG_ERR, "Invalid group extension %#x", rsp->data[0]);
  366. return -1;
  367. }
  368. printf("FRU has been successfully %s\n",
  369. command ? "activated" : "deactivated");
  370. return 0;
  371. }
  372. static int
  373. ipmi_vita_get_fru_state_policy_bits(struct ipmi_intf *intf, char **argv)
  374. {
  375. struct ipmi_rs *rsp;
  376. struct ipmi_rq req;
  377. unsigned char msg_data[2];
  378. memset(&req, 0, sizeof(req));
  379. req.msg.netfn = IPMI_NETFN_PICMG;
  380. req.msg.cmd = VITA_GET_FRU_STATE_POLICY_BITS_CMD;
  381. req.msg.data = msg_data;
  382. req.msg.data_len = 2;
  383. msg_data[0] = GROUP_EXT_VITA; /* VITA identifier */
  384. if (is_fru_id(argv[0], &msg_data[1]) != 0) { /* FRU ID */
  385. return -1;
  386. }
  387. rsp = intf->sendrecv(intf, &req);
  388. if (rsp == NULL) {
  389. lprintf(LOG_ERR, "No valid response received.");
  390. return -1;
  391. } else if (rsp->ccode != 0) {
  392. lprintf(LOG_ERR, "Invalid completion code received: %s",
  393. val2str(rsp->ccode, completion_code_vals));
  394. return -1;
  395. } else if (rsp->data_len < 2) {
  396. lprintf(LOG_ERR, "Invalid response length %d", rsp->data_len);
  397. return -1;
  398. } else if (rsp->data[0] != GROUP_EXT_VITA) {
  399. lprintf(LOG_ERR, "Invalid group extension %#x", rsp->data[0]);
  400. return -1;
  401. }
  402. printf("FRU State Policy Bits: %xh\n", rsp->data[1]);
  403. printf(" Default-Activation-Locked Policy Bit is %d\n",
  404. rsp->data[1] & 0x08 ? 1 : 0);
  405. printf(" Commanded-Deactivation-Ignored Policy Bit is %d\n",
  406. rsp->data[1] & 0x04 ? 1 : 0);
  407. printf(" Deactivation-Locked Policy Bit is %d\n",
  408. rsp->data[1] & 0x02 ? 1 : 0);
  409. printf(" Activation-Locked Policy Bit is %d\n",
  410. rsp->data[1] & 0x01);
  411. return 0;
  412. }
  413. static int
  414. ipmi_vita_set_fru_state_policy_bits(struct ipmi_intf *intf, char **argv)
  415. {
  416. struct ipmi_rs *rsp;
  417. struct ipmi_rq req;
  418. unsigned char msg_data[4];
  419. memset(&req, 0, sizeof(req));
  420. req.msg.netfn = IPMI_NETFN_PICMG;
  421. req.msg.cmd = VITA_SET_FRU_STATE_POLICY_BITS_CMD;
  422. req.msg.data = msg_data;
  423. req.msg.data_len = 4;
  424. msg_data[0] = GROUP_EXT_VITA; /* VITA identifier */
  425. if (is_fru_id(argv[0], &msg_data[1]) != 0) { /* FRU ID */
  426. return -1;
  427. }
  428. if (str2uchar(argv[1], &msg_data[2]) != 0) { /* bits mask */
  429. return -1;
  430. }
  431. if (str2uchar(argv[2], &msg_data[3]) != 0) { /* bits */
  432. return -1;
  433. }
  434. rsp = intf->sendrecv(intf, &req);
  435. if (rsp == NULL) {
  436. lprintf(LOG_ERR, "No valid response received.");
  437. return -1;
  438. } else if (rsp->ccode != 0) {
  439. lprintf(LOG_ERR, "Invalid completion code received: %s",
  440. val2str(rsp->ccode, completion_code_vals));
  441. return -1;
  442. } else if (rsp->data_len < 1) {
  443. lprintf(LOG_ERR, "Invalid response length %d", rsp->data_len);
  444. return -1;
  445. } else if (rsp->data[0] != GROUP_EXT_VITA) {
  446. lprintf(LOG_ERR, "Invalid group extension %#x", rsp->data[0]);
  447. return -1;
  448. }
  449. printf("FRU state policy bits have been updated\n");
  450. return 0;
  451. }
  452. static int
  453. ipmi_vita_get_led_properties(struct ipmi_intf *intf, char **argv)
  454. {
  455. struct ipmi_rs *rsp;
  456. struct ipmi_rq req;
  457. unsigned char msg_data[2];
  458. memset(&req, 0, sizeof(req));
  459. req.msg.netfn = IPMI_NETFN_PICMG;
  460. req.msg.cmd = VITA_GET_FRU_LED_PROPERTIES_CMD;
  461. req.msg.data = msg_data;
  462. req.msg.data_len = 2;
  463. msg_data[0] = GROUP_EXT_VITA; /* VITA identifier */
  464. if (is_fru_id(argv[0], &msg_data[1]) != 0) { /* FRU ID */
  465. return -1;
  466. }
  467. rsp = intf->sendrecv(intf, &req);
  468. if (rsp == NULL) {
  469. lprintf(LOG_ERR, "No valid response received.");
  470. return -1;
  471. } else if (rsp->ccode != 0) {
  472. lprintf(LOG_ERR, "Invalid completion code received: %s",
  473. val2str(rsp->ccode, completion_code_vals));
  474. return -1;
  475. } else if (rsp->data_len < 3) {
  476. lprintf(LOG_ERR, "Invalid response length %d", rsp->data_len);
  477. return -1;
  478. } else if (rsp->data[0] != GROUP_EXT_VITA) {
  479. lprintf(LOG_ERR, "Invalid group extension %#x", rsp->data[0]);
  480. return -1;
  481. }
  482. printf("LED Count: %#x\n", rsp->data[2]);
  483. return 0;
  484. }
  485. static int
  486. ipmi_vita_get_led_color_capabilities(struct ipmi_intf *intf, char **argv)
  487. {
  488. struct ipmi_rs *rsp;
  489. struct ipmi_rq req;
  490. unsigned char msg_data[3];
  491. int i;
  492. memset(&req, 0, sizeof(req));
  493. req.msg.netfn = IPMI_NETFN_PICMG;
  494. req.msg.cmd = VITA_GET_LED_COLOR_CAPABILITIES_CMD;
  495. req.msg.data = msg_data;
  496. req.msg.data_len = 3;
  497. msg_data[0] = GROUP_EXT_VITA; /* VITA identifier */
  498. if (is_fru_id(argv[0], &msg_data[1]) != 0) { /* FRU ID */
  499. return -1;
  500. }
  501. if (str2uchar(argv[1], &msg_data[2]) != 0) { /* LED-ID */
  502. return -1;
  503. }
  504. rsp = intf->sendrecv(intf, &req);
  505. if (rsp == NULL) {
  506. lprintf(LOG_ERR, "No valid response received.");
  507. return -1;
  508. } else if (rsp->ccode != 0) {
  509. lprintf(LOG_ERR, "Invalid completion code received: %s",
  510. val2str(rsp->ccode, completion_code_vals));
  511. return -1;
  512. } else if (rsp->data_len < 4) {
  513. lprintf(LOG_ERR, "Invalid response length %d", rsp->data_len);
  514. return -1;
  515. } else if (rsp->data[0] != GROUP_EXT_VITA) {
  516. lprintf(LOG_ERR, "Invalid group extension %#x", rsp->data[0]);
  517. return -1;
  518. }
  519. printf("LED Color Capabilities: ");
  520. for (i = 0; i < 8; i++) {
  521. if (rsp->data[1] & (0x01 << i)) {
  522. printf("%s, ", led_color_str[i]);
  523. }
  524. }
  525. putchar('\n');
  526. printf("Default LED Color in\n");
  527. printf(" LOCAL control: %s\n", led_color_str[rsp->data[2]]);
  528. printf(" OVERRIDE state: %s\n", led_color_str[rsp->data[3]]);
  529. if (rsp->data_len == 5) {
  530. printf("LED flags:\n");
  531. if (rsp->data[4] & 2) {
  532. printf(" [HW RESTRICT]\n");
  533. }
  534. if (rsp->data[4] & 1) {
  535. printf(" [PAYLOAD PWR]\n");
  536. }
  537. }
  538. return 0;
  539. }
  540. static int
  541. ipmi_vita_get_led_state(struct ipmi_intf *intf, char **argv)
  542. {
  543. struct ipmi_rs *rsp;
  544. struct ipmi_rq req;
  545. unsigned char msg_data[3];
  546. memset(&req, 0, sizeof(req));
  547. req.msg.netfn = IPMI_NETFN_PICMG;
  548. req.msg.cmd = VITA_GET_FRU_LED_STATE_CMD;
  549. req.msg.data = msg_data;
  550. req.msg.data_len = 3;
  551. msg_data[0] = GROUP_EXT_VITA; /* VITA identifier */
  552. if (is_fru_id(argv[0], &msg_data[1]) != 0) { /* FRU ID */
  553. return -1;
  554. }
  555. if (str2uchar(argv[1], &msg_data[2]) != 0) { /* LED-ID */
  556. return -1;
  557. }
  558. rsp = intf->sendrecv(intf, &req);
  559. if (rsp == NULL) {
  560. lprintf(LOG_ERR, "No valid response received.");
  561. return -1;
  562. } else if (rsp->ccode != 0) {
  563. lprintf(LOG_ERR, "Invalid completion code received: %s",
  564. val2str(rsp->ccode, completion_code_vals));
  565. return -1;
  566. } else if (rsp->data_len < 5
  567. || ((rsp->data[1] & 0x2) && rsp->data_len < 8)
  568. || ((rsp->data[1] & 0x4) && rsp->data_len < 9)) {
  569. lprintf(LOG_ERR, "Invalid response length %d", rsp->data_len);
  570. return -1;
  571. } else if (rsp->data[0] != GROUP_EXT_VITA) {
  572. lprintf(LOG_ERR, "Invalid group extension %#x", rsp->data[0]);
  573. return -1;
  574. }
  575. printf("LED states: %x\t", rsp->data[1]);
  576. if (rsp->data[1] & 0x1) {
  577. printf("[LOCAL CONTROL] ");
  578. }
  579. if (rsp->data[1] & 0x2) {
  580. printf("[OVERRIDE] ");
  581. }
  582. if (rsp->data[1] & 0x4) {
  583. printf("[LAMPTEST] ");
  584. }
  585. if (rsp->data[1] & 0x8) {
  586. printf("[HW RESTRICT] ");
  587. }
  588. putchar('\n');
  589. if (rsp->data[1] & 1) {
  590. printf(" Local Control function: %x\t", rsp->data[2]);
  591. if (rsp->data[2] == 0x0) {
  592. printf("[OFF]\n");
  593. } else if (rsp->data[2] == 0xff) {
  594. printf("[ON]\n");
  595. } else {
  596. printf("[BLINKING]\n");
  597. }
  598. printf(" Local Control On-Duration: %x\n", rsp->data[3]);
  599. printf(" Local Control Color: %x\t[%s]\n",
  600. rsp->data[4], led_color_str[rsp->data[4] & 7]);
  601. }
  602. /* override state or lamp test */
  603. if (rsp->data[1] & 0x06) {
  604. printf(" Override function: %x\t", rsp->data[5]);
  605. if (rsp->data[5] == 0x0) {
  606. printf("[OFF]\n");
  607. } else if (rsp->data[5] == 0xff) {
  608. printf("[ON]\n");
  609. } else {
  610. printf("[BLINKING]\n");
  611. }
  612. printf(" Override On-Duration: %x\n", rsp->data[6]);
  613. printf(" Override Color: %x\t[%s]\n",
  614. rsp->data[7], led_color_str[rsp->data[7] & 7]);
  615. if (rsp->data[1] == 0x04) {
  616. printf(" Lamp test duration: %x\n", rsp->data[8]);
  617. }
  618. }
  619. return 0;
  620. }
  621. static int
  622. ipmi_vita_set_led_state(struct ipmi_intf *intf, char **argv)
  623. {
  624. struct ipmi_rs *rsp;
  625. struct ipmi_rq req;
  626. unsigned char msg_data[6];
  627. memset(&req, 0, sizeof(req));
  628. req.msg.netfn = IPMI_NETFN_PICMG;
  629. req.msg.cmd = VITA_SET_FRU_LED_STATE_CMD;
  630. req.msg.data = msg_data;
  631. req.msg.data_len = 6;
  632. msg_data[0] = GROUP_EXT_VITA; /* VITA identifier */
  633. if (is_fru_id(argv[0], &msg_data[1]) != 0) { /* FRU ID */
  634. return -1;
  635. }
  636. if (str2uchar(argv[1], &msg_data[2]) != 0) { /* LED-ID */
  637. return -1;
  638. }
  639. if (str2uchar(argv[2], &msg_data[3]) != 0) { /* LED function */
  640. return -1;
  641. }
  642. if (str2uchar(argv[3], &msg_data[4]) != 0) { /* LED on duration */
  643. return -1;
  644. }
  645. if (str2uchar(argv[4], &msg_data[5]) != 0) { /* LED color */
  646. return -1;
  647. }
  648. rsp = intf->sendrecv(intf, &req);
  649. if (rsp == NULL) {
  650. lprintf(LOG_ERR, "No valid response received.");
  651. return -1;
  652. } else if (rsp->ccode != 0) {
  653. lprintf(LOG_ERR, "Invalid completion code received: %s",
  654. val2str(rsp->ccode, completion_code_vals));
  655. return -1;
  656. } else if (rsp->data_len < 1) {
  657. lprintf(LOG_ERR, "Invalid response length %d", rsp->data_len);
  658. return -1;
  659. } else if (rsp->data[0] != GROUP_EXT_VITA) {
  660. lprintf(LOG_ERR, "Invalid group extension %#x", rsp->data[0]);
  661. return -1;
  662. }
  663. printf("LED state has been updated\n");
  664. return 0;
  665. }
  666. static int
  667. ipmi_vita_fru_control(struct ipmi_intf *intf, char **argv)
  668. {
  669. struct ipmi_rs *rsp;
  670. struct ipmi_rq req;
  671. unsigned char msg_data[3];
  672. memset(&req, 0, sizeof(req));
  673. req.msg.netfn = IPMI_NETFN_PICMG;
  674. req.msg.cmd = VITA_FRU_CONTROL_CMD;
  675. req.msg.data = msg_data;
  676. req.msg.data_len = 3;
  677. msg_data[0] = GROUP_EXT_VITA; /* VITA identifier */
  678. if (is_fru_id(argv[0], &msg_data[1]) != 0) { /* FRU ID */
  679. return -1;
  680. }
  681. if (str2uchar(argv[1], &msg_data[2]) != 0) { /* control option */
  682. return -1;
  683. }
  684. printf("FRU Device Id: %d FRU Control Option: %s\n", msg_data[1],
  685. val2str(msg_data[2], picmg_frucontrol_vals));
  686. rsp = intf->sendrecv(intf, &req);
  687. if (rsp == NULL) {
  688. lprintf(LOG_ERR, "No valid response received.");
  689. return -1;
  690. } else if (rsp->ccode != 0) {
  691. lprintf(LOG_ERR, "Invalid completion code received: %s",
  692. val2str(rsp->ccode, completion_code_vals));
  693. return -1;
  694. } else if (rsp->data_len < 1) {
  695. lprintf(LOG_ERR, "Invalid response length %d", rsp->data_len);
  696. return -1;
  697. } else if (rsp->data[0] != GROUP_EXT_VITA) {
  698. lprintf(LOG_ERR, "Invalid group extension %#x", rsp->data[0]);
  699. return -1;
  700. }
  701. printf("FRU Control: ok\n");
  702. return 0;
  703. }
  704. static int
  705. ipmi_vita_get_cmd(int argc, char **argv)
  706. {
  707. if (argc < 1 || !strncmp(argv[0], "help", 4)) {
  708. return VITA_CMD_HELP;
  709. }
  710. /* Get VSO Properties */
  711. if (!strncmp(argv[0], "properties", 10)) {
  712. return VITA_CMD_PROPERTIES;
  713. }
  714. /* FRU Control command */
  715. if (!strncmp(argv[0], "frucontrol", 10)) {
  716. return VITA_CMD_FRUCONTROL;
  717. }
  718. /* Get FRU Address Info command */
  719. if (!strncmp(argv[0], "addrinfo", 8)) {
  720. return VITA_CMD_ADDRINFO;
  721. }
  722. /* Set FRU Activation (activate) command */
  723. if (!strncmp(argv[0], "activate", 8)) {
  724. return VITA_CMD_ACTIVATE;
  725. }
  726. /* Set FRU Activation (deactivate) command */
  727. if (!strncmp(argv[0], "deactivate", 10)) {
  728. return VITA_CMD_DEACTIVATE;
  729. }
  730. /* FRU State Policy Bits commands */
  731. if (!strncmp(argv[0], "policy", 6)) {
  732. if (argc < 2) {
  733. return VITA_CMD_UNKNOWN;
  734. }
  735. /* Get FRU State Policy Bits command */
  736. if (!strncmp(argv[1], "get", 3)) {
  737. return VITA_CMD_POLICY_GET;
  738. }
  739. /* Set FRU State Policy Bits command */
  740. if (!strncmp(argv[1], "set", 3)) {
  741. return VITA_CMD_POLICY_SET;
  742. }
  743. /* unknown command */
  744. return VITA_CMD_UNKNOWN;
  745. }
  746. /* FRU LED commands */
  747. if (!strncmp(argv[0], "led", 3)) {
  748. if (argc < 2) {
  749. return VITA_CMD_UNKNOWN;
  750. }
  751. /* FRU LED Get Properties */
  752. if (!strncmp(argv[1], "prop", 4)) {
  753. return VITA_CMD_LED_PROP;
  754. }
  755. /* FRU LED Get Capabilities */
  756. if (!strncmp(argv[1], "cap", 3)) {
  757. return VITA_CMD_LED_CAP;
  758. }
  759. /* FRU LED Get State */
  760. if (!strncmp(argv[1], "get", 3)) {
  761. return VITA_CMD_LED_GET;
  762. }
  763. /* FRU LED Set State */
  764. if (!strncmp(argv[1], "set", 3)) {
  765. return VITA_CMD_LED_SET;
  766. }
  767. /* unknown command */
  768. return VITA_CMD_UNKNOWN;
  769. }
  770. /* unknown command */
  771. return VITA_CMD_UNKNOWN;
  772. }
  773. int
  774. ipmi_vita_main (struct ipmi_intf *intf, int argc, char **argv)
  775. {
  776. int rc = -1, show_help = 0;
  777. int cmd = ipmi_vita_get_cmd(argc, argv);
  778. switch (cmd) {
  779. case VITA_CMD_HELP:
  780. cmd = ipmi_vita_get_cmd(argc - 1, &argv[1]);
  781. show_help = 1;
  782. rc = 0;
  783. break;
  784. case VITA_CMD_PROPERTIES:
  785. rc = ipmi_vita_get_vso_capabilities(intf);
  786. break;
  787. case VITA_CMD_FRUCONTROL:
  788. if (argc > 2) {
  789. rc = ipmi_vita_fru_control(intf, &argv[1]);
  790. } else {
  791. show_help = 1;
  792. }
  793. break;
  794. case VITA_CMD_ADDRINFO:
  795. rc = ipmi_vita_getaddr(intf, argc - 1, &argv[1]);
  796. break;
  797. case VITA_CMD_ACTIVATE:
  798. if (argc > 1) {
  799. rc = ipmi_vita_set_fru_activation(intf, &argv[1], 1);
  800. } else {
  801. show_help = 1;
  802. }
  803. break;
  804. case VITA_CMD_DEACTIVATE:
  805. if (argc > 1) {
  806. rc = ipmi_vita_set_fru_activation(intf, &argv[1], 0);
  807. } else {
  808. show_help = 1;
  809. }
  810. break;
  811. case VITA_CMD_POLICY_GET:
  812. if (argc > 2) {
  813. rc = ipmi_vita_get_fru_state_policy_bits(intf,
  814. &argv[2]);
  815. } else {
  816. show_help = 1;
  817. }
  818. break;
  819. case VITA_CMD_POLICY_SET:
  820. if (argc > 4) {
  821. rc = ipmi_vita_set_fru_state_policy_bits(intf,
  822. &argv[2]);
  823. } else {
  824. show_help = 1;
  825. }
  826. break;
  827. case VITA_CMD_LED_PROP:
  828. if (argc > 2) {
  829. rc = ipmi_vita_get_led_properties(intf, &argv[2]);
  830. } else {
  831. show_help = 1;
  832. }
  833. break;
  834. case VITA_CMD_LED_CAP:
  835. if (argc > 3) {
  836. rc = ipmi_vita_get_led_color_capabilities(intf,
  837. &argv[2]);
  838. } else {
  839. show_help = 1;
  840. }
  841. break;
  842. case VITA_CMD_LED_GET:
  843. if (argc > 3) {
  844. rc = ipmi_vita_get_led_state(intf, &argv[2]);
  845. } else {
  846. show_help = 1;
  847. }
  848. break;
  849. case VITA_CMD_LED_SET:
  850. if (argc > 6) {
  851. rc = ipmi_vita_set_led_state(intf, &argv[2]);
  852. } else {
  853. show_help = 1;
  854. }
  855. break;
  856. default:
  857. lprintf(LOG_NOTICE, "Unknown command");
  858. cmd = VITA_CMD_HELP;
  859. show_help = 1;
  860. break;
  861. }
  862. if (show_help) {
  863. lprintf(LOG_NOTICE, "%s", val2str(cmd, vita_help_strings));
  864. }
  865. return rc;
  866. }