All of the information about communicating with some address through some interface is contained in the structure "struct ipmi_intf" (ipmi interface), which is defined in ipmi_intf.h and requires the library libintf.a (the library is in src/plugins/.libs). The intf library has functionalitly to connect in several different ways, which are listed in src/plugins; we use the lan interface. To load a selected interface, use the following code:
struct ipmi_intf *intf;
intf = ipmi_intf_load(strdup("lan"));
The method ipmi_intf_load returns a pointer to a structure which contains pointers to specialized functions such as open and sendrecv. These functions have the same names and parameter list among all of the interfaces; since ipmitool is written in C, there are not any classes or possibility of overloading functions, so ipmi_intf_load simply loads the proper interface library and uses its functions.
All of the necessary addresses and attributes are sored in (or referenced by) variables in the ipmi_intf structure. These variables are set by a series of functions, the most important of which are:
ipmi_intf_session_set_hostname(intf, ip_address);
ipmi_intf_session_set_password(intf, "");
ipmi_intf_session_set_privlvl(intf, IPMI_SESSION_PRIV_ADMIN);
ipmi_intf_session_set_lookupbit(intf, 0x10);
ipmi_intf_session_set_cipher_suite_id(intf, 3);
there are also variables that are set one at a time:
intf->target_addr = (uint8_t)strtol(TARGET_ADDR, NULL, 0);
intf->transit_addr = (uint8_t)strtol(TRANSIT_ADDR, NULL, 0);
intf->transit_channel = (uint8_t)strtol(TRANSIT_CHANNEL, NULL, 0);
intf->target_channel = (uint8_t)strtol(TARGET_CHANNEL, NULL, 0);
Finally, to make contact with the address, use "intf->open(intf)" which will return a negative integer if a connection cannot be esablished. Examples of everything explained so far may be found in lib/ipmi_main.c in the ipmi_main function or in src/dtcreg/dtcreg.cc (from the dtcreg library) in the dtc_open function.
The functions required for sending a raw IPMI command (0x1 for read, 0x2 for write, etc) are defined in lib/ipmi_raw.c. The most basic function is ipmi_raw_main, which accepts a pointer to the interface (ipmi_intf *), and a C style argc and **argv. The function parses argv for a set of tags defined for ipmitool and prints to standard output the result (if the read command is passed). Therefore, it is useful to ignore this function and create one based on its code. |