ipmi_oem.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * Redistribution and use in source and binary forms, with or without
  3. * modification, are permitted provided that the following conditions
  4. * are met:
  5. *
  6. * Redistribution of source code must retain the above copyright
  7. * notice, this list of conditions and the following disclaimer.
  8. *
  9. * Redistribution in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * Neither the name of Sun Microsystems, Inc. or the names of
  14. * contributors may be used to endorse or promote products derived
  15. * from this software without specific prior written permission.
  16. *
  17. * This software is provided "AS IS," without a warranty of any kind.
  18. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
  19. * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
  20. * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
  21. * SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE
  22. * FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
  23. * OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
  24. * SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA,
  25. * OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
  26. * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
  27. * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
  28. * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  29. */
  30. #include <string.h>
  31. #include <ipmitool/ipmi.h>
  32. #include <ipmitool/ipmi_intf.h>
  33. #include <ipmitool/ipmi_constants.h>
  34. #include <ipmitool/log.h>
  35. #include <ipmitool/helper.h>
  36. #include <ipmitool/ipmi_sel.h>
  37. static int ipmi_oem_supermicro(struct ipmi_intf * intf);
  38. static int ipmi_oem_ibm(struct ipmi_intf * intf);
  39. static struct ipmi_oem_handle ipmi_oem_list[] = {
  40. {
  41. .name = "supermicro",
  42. .desc = "Supermicro IPMIv1.5 BMC with OEM LAN authentication support",
  43. .setup = ipmi_oem_supermicro,
  44. },
  45. {
  46. .name = "intelwv2",
  47. .desc = "Intel SE7501WV2 IPMIv1.5 BMC with extra LAN communication support",
  48. },
  49. {
  50. .name = "intelplus",
  51. .desc = "Intel IPMI 2.0 BMC with RMCP+ communication support",
  52. },
  53. {
  54. .name = "icts",
  55. .desc = "IPMI 2.0 ICTS compliance support",
  56. },
  57. {
  58. .name = "ibm",
  59. .desc = "IBM OEM support",
  60. .setup = ipmi_oem_ibm,
  61. },
  62. {
  63. .name = "i82571spt",
  64. .desc = "Intel 82571 MAC with integrated RMCP+ support in super pass-through mode",
  65. },
  66. {
  67. .name = "kontron",
  68. .desc = "Kontron OEM big buffer support"
  69. },
  70. { 0 }
  71. };
  72. /* Supermicro IPMIv2 BMCs use OEM authtype */
  73. static int
  74. ipmi_oem_supermicro(struct ipmi_intf * intf)
  75. {
  76. ipmi_intf_session_set_authtype(intf, IPMI_SESSION_AUTHTYPE_OEM);
  77. return 0;
  78. }
  79. static int
  80. ipmi_oem_ibm(struct ipmi_intf * intf)
  81. {
  82. char * filename;
  83. if ((filename = getenv("IPMI_OEM_IBM_DATAFILE")) == NULL) {
  84. lprintf(LOG_ERR, "Unable to read IPMI_OEM_IBM_DATAFILE from environment");
  85. return -1;
  86. }
  87. return ipmi_sel_oem_init((const char *)filename);
  88. }
  89. /* ipmi_oem_print - print list of OEM handles
  90. */
  91. void
  92. ipmi_oem_print(void)
  93. {
  94. struct ipmi_oem_handle * oem;
  95. lprintf(LOG_NOTICE, "\nOEM Support:");
  96. for (oem=ipmi_oem_list; oem->name != NULL && oem->desc != NULL; oem++) {
  97. lprintf(LOG_NOTICE, "\t%-12s %s", oem->name, oem->desc);
  98. }
  99. lprintf(LOG_NOTICE, "");
  100. }
  101. /* ipmi_oem_setup - do initial setup of OEM handle
  102. *
  103. * @intf: ipmi interface
  104. * @oemtype: OEM handle name
  105. *
  106. * returns 0 on success
  107. * returns -1 on error
  108. */
  109. int
  110. ipmi_oem_setup(struct ipmi_intf * intf, char * oemtype)
  111. {
  112. struct ipmi_oem_handle * oem;
  113. int rc = 0;
  114. if (oemtype == NULL ||
  115. strncmp(oemtype, "help", 4) == 0 ||
  116. strncmp(oemtype, "list", 4) == 0) {
  117. ipmi_oem_print();
  118. return -1;
  119. }
  120. for (oem=ipmi_oem_list; oem->name != NULL; oem++) {
  121. if (strncmp(oemtype, oem->name, strlen(oem->name)) == 0)
  122. break;
  123. }
  124. if (oem->name == NULL)
  125. return -1;
  126. /* save pointer for later use */
  127. intf->oem = oem;
  128. /* run optional setup function if it is defined */
  129. if (oem->setup != NULL) {
  130. lprintf(LOG_DEBUG, "Running OEM setup for \"%s\"", oem->desc);
  131. rc = oem->setup(intf);
  132. }
  133. return rc;
  134. }
  135. /* ipmi_oem_active - used to determine if a particular OEM type is set
  136. *
  137. * @intf: ipmi interface
  138. * @oemtype: string containing name of ipmi handle to check
  139. *
  140. * returns 1 if requested ipmi handle is active
  141. * returns 0 otherwise
  142. */
  143. int
  144. ipmi_oem_active(struct ipmi_intf * intf, const char * oemtype)
  145. {
  146. if (intf->oem == NULL)
  147. return 0;
  148. if (strncmp(intf->oem->name, oemtype, strlen(oemtype)) == 0)
  149. return 1;
  150. return 0;
  151. }