ipmi_intf.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /*
  2. * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * Redistribution of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. *
  11. * Redistribution in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. *
  15. * Neither the name of Sun Microsystems, Inc. or the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * This software is provided "AS IS," without a warranty of any kind.
  20. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
  21. * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
  22. * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
  23. * SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE
  24. * FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
  25. * OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
  26. * SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA,
  27. * OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
  28. * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
  29. * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
  30. * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  31. */
  32. #ifndef IPMI_INTF_H
  33. #define IPMI_INTF_H
  34. #include <ipmitool/ipmi.h>
  35. #include <ipmitool/ipmi_oem.h>
  36. #include <ipmitool/ipmi_constants.h>
  37. #include <sys/types.h>
  38. #include <arpa/inet.h>
  39. #include <sys/socket.h>
  40. #include <netinet/in.h>
  41. /*
  42. * An enumeration that describes every possible session state for
  43. * an IPMIv2 / RMCP+ session.
  44. */
  45. enum LANPLUS_SESSION_STATE {
  46. LANPLUS_STATE_PRESESSION = 0,
  47. LANPLUS_STATE_OPEN_SESSION_SENT,
  48. LANPLUS_STATE_OPEN_SESSION_RECEIEVED,
  49. LANPLUS_STATE_RAKP_1_SENT,
  50. LANPLUS_STATE_RAKP_2_RECEIVED,
  51. LANPLUS_STATE_RAKP_3_SENT,
  52. LANPLUS_STATE_ACTIVE,
  53. LANPLUS_STATE_CLOSE_SENT,
  54. };
  55. #define IPMI_AUTHCODE_BUFFER_SIZE 20
  56. #define IPMI_SIK_BUFFER_SIZE IPMI_MAX_MD_SIZE
  57. #define IPMI_KG_BUFFER_SIZE 21 /* key plus null byte */
  58. struct ipmi_session_params {
  59. char * hostname;
  60. uint8_t username[17];
  61. uint8_t authcode_set[IPMI_AUTHCODE_BUFFER_SIZE + 1];
  62. uint8_t authtype_set;
  63. uint8_t privlvl;
  64. uint8_t cipher_suite_id;
  65. char sol_escape_char;
  66. int password;
  67. int port;
  68. int retry;
  69. uint32_t timeout;
  70. uint8_t kg[IPMI_KG_BUFFER_SIZE]; /* BMC key */
  71. uint8_t lookupbit;
  72. };
  73. #define IPMI_AUTHSTATUS_PER_MSG_DISABLED 0x10
  74. #define IPMI_AUTHSTATUS_PER_USER_DISABLED 0x08
  75. #define IPMI_AUTHSTATUS_NONNULL_USERS_ENABLED 0x04
  76. #define IPMI_AUTHSTATUS_NULL_USERS_ENABLED 0x02
  77. #define IPMI_AUTHSTATUS_ANONYMOUS_USERS_ENABLED 0x01
  78. struct ipmi_session {
  79. int active;
  80. uint32_t session_id;
  81. uint32_t in_seq;
  82. uint32_t out_seq;
  83. uint8_t authcode[IPMI_AUTHCODE_BUFFER_SIZE + 1];
  84. uint8_t challenge[16];
  85. uint8_t authtype;
  86. uint8_t authstatus;
  87. uint8_t authextra;
  88. uint32_t timeout;
  89. struct sockaddr_storage addr;
  90. socklen_t addrlen;
  91. /*
  92. * This struct holds state data specific to IPMI v2 / RMCP+ sessions
  93. */
  94. struct {
  95. enum LANPLUS_SESSION_STATE session_state;
  96. /* These are the algorithms agreed upon for the session */
  97. uint8_t requested_auth_alg;
  98. uint8_t requested_integrity_alg;
  99. uint8_t requested_crypt_alg;
  100. uint8_t auth_alg;
  101. uint8_t integrity_alg;
  102. uint8_t crypt_alg;
  103. uint8_t max_priv_level;
  104. uint32_t console_id;
  105. uint32_t bmc_id;
  106. /*
  107. * Values required for RAKP mesages
  108. */
  109. /* Random number generated byt the console */
  110. uint8_t console_rand[16];
  111. /* Random number generated by the BMC */
  112. uint8_t bmc_rand[16];
  113. uint8_t bmc_guid[16];
  114. uint8_t requested_role; /* As sent in the RAKP 1 message */
  115. uint8_t rakp2_return_code;
  116. uint8_t sik[IPMI_SIK_BUFFER_SIZE]; /* Session integrity key */
  117. uint8_t sik_len; /* Session Integrity key length */
  118. uint8_t kg[IPMI_KG_BUFFER_SIZE]; /* BMC key */
  119. uint8_t k1[IPMI_MAX_MD_SIZE]; /* Used for Integrity checking? */
  120. uint8_t k1_len; /* K1 key length */
  121. uint8_t k2[IPMI_MAX_MD_SIZE]; /* First 16 bytes used for AES */
  122. uint8_t k2_len; /* K2 key length */
  123. } v2_data;
  124. /*
  125. * This data is specific to the Serial Over Lan session
  126. */
  127. struct {
  128. uint16_t max_inbound_payload_size;
  129. uint16_t max_outbound_payload_size;
  130. uint16_t port;
  131. uint8_t sequence_number;
  132. /* This data describes the last SOL packet */
  133. uint8_t last_received_sequence_number;
  134. uint8_t last_received_byte_count;
  135. void (*sol_input_handler)(struct ipmi_rs * rsp);
  136. } sol_data;
  137. };
  138. struct ipmi_cmd {
  139. int (*func)(struct ipmi_intf * intf, int argc, char ** argv);
  140. const char * name;
  141. const char * desc;
  142. };
  143. struct ipmi_intf_support {
  144. const char * name;
  145. int supported;
  146. };
  147. struct ipmi_intf {
  148. char name[16];
  149. char desc[128];
  150. char *devfile;
  151. int fd;
  152. int opened;
  153. int abort;
  154. int noanswer;
  155. int picmg_avail;
  156. int vita_avail;
  157. IPMI_OEM manufacturer_id;
  158. int ai_family;
  159. struct ipmi_session_params ssn_params;
  160. struct ipmi_session * session;
  161. struct ipmi_oem_handle * oem;
  162. struct ipmi_cmd * cmdlist;
  163. uint8_t target_ipmb_addr;
  164. uint32_t my_addr;
  165. uint32_t target_addr;
  166. uint8_t target_lun;
  167. uint8_t target_channel;
  168. uint32_t transit_addr;
  169. uint8_t transit_channel;
  170. uint16_t max_request_data_size;
  171. uint16_t max_response_data_size;
  172. uint8_t devnum;
  173. int (*setup)(struct ipmi_intf * intf);
  174. int (*open)(struct ipmi_intf * intf);
  175. void (*close)(struct ipmi_intf * intf);
  176. struct ipmi_rs *(*sendrecv)(struct ipmi_intf * intf, struct ipmi_rq * req);
  177. int (*sendrsp)(struct ipmi_intf * intf, struct ipmi_rs * rsp);
  178. struct ipmi_rs *(*recv_sol)(struct ipmi_intf * intf);
  179. struct ipmi_rs *(*send_sol)(struct ipmi_intf * intf, struct ipmi_v2_payload * payload);
  180. int (*keepalive)(struct ipmi_intf * intf);
  181. int (*set_my_addr)(struct ipmi_intf * intf, uint8_t addr);
  182. void (*set_max_request_data_size)(struct ipmi_intf * intf, uint16_t size);
  183. void (*set_max_response_data_size)(struct ipmi_intf * intf, uint16_t size);
  184. };
  185. struct ipmi_intf * ipmi_intf_load(char * name);
  186. void ipmi_intf_print(struct ipmi_intf_support * intflist);
  187. void ipmi_intf_session_set_hostname(struct ipmi_intf * intf, char * hostname);
  188. void ipmi_intf_session_set_username(struct ipmi_intf * intf, char * username);
  189. void ipmi_intf_session_set_password(struct ipmi_intf * intf, char * password);
  190. void ipmi_intf_session_set_privlvl(struct ipmi_intf * intf, uint8_t privlvl);
  191. void ipmi_intf_session_set_lookupbit(struct ipmi_intf * intf, uint8_t lookupbit);
  192. void ipmi_intf_session_set_cipher_suite_id(struct ipmi_intf * intf, uint8_t cipher_suite_id);
  193. void ipmi_intf_session_set_sol_escape_char(struct ipmi_intf * intf, char sol_escape_char);
  194. void ipmi_intf_session_set_kgkey(struct ipmi_intf *intf, const uint8_t *kgkey);
  195. void ipmi_intf_session_set_port(struct ipmi_intf * intf, int port);
  196. void ipmi_intf_session_set_authtype(struct ipmi_intf * intf, uint8_t authtype);
  197. void ipmi_intf_session_set_timeout(struct ipmi_intf * intf, uint32_t timeout);
  198. void ipmi_intf_session_set_retry(struct ipmi_intf * intf, int retry);
  199. void ipmi_intf_session_cleanup(struct ipmi_intf *intf);
  200. void ipmi_cleanup(struct ipmi_intf * intf);
  201. #if defined(IPMI_INTF_LAN) || defined (IPMI_INTF_LANPLUS)
  202. int ipmi_intf_socket_connect(struct ipmi_intf * intf);
  203. #endif
  204. #endif /* IPMI_INTF_H */