1*c18ec02fSPetter Reinholdtsen /*
2*c18ec02fSPetter Reinholdtsen * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
3*c18ec02fSPetter Reinholdtsen *
4*c18ec02fSPetter Reinholdtsen * Redistribution and use in source and binary forms, with or without
5*c18ec02fSPetter Reinholdtsen * modification, are permitted provided that the following conditions
6*c18ec02fSPetter Reinholdtsen * are met:
7*c18ec02fSPetter Reinholdtsen *
8*c18ec02fSPetter Reinholdtsen * Redistribution of source code must retain the above copyright
9*c18ec02fSPetter Reinholdtsen * notice, this list of conditions and the following disclaimer.
10*c18ec02fSPetter Reinholdtsen *
11*c18ec02fSPetter Reinholdtsen * Redistribution in binary form must reproduce the above copyright
12*c18ec02fSPetter Reinholdtsen * notice, this list of conditions and the following disclaimer in the
13*c18ec02fSPetter Reinholdtsen * documentation and/or other materials provided with the distribution.
14*c18ec02fSPetter Reinholdtsen *
15*c18ec02fSPetter Reinholdtsen * Neither the name of Sun Microsystems, Inc. or the names of
16*c18ec02fSPetter Reinholdtsen * contributors may be used to endorse or promote products derived
17*c18ec02fSPetter Reinholdtsen * from this software without specific prior written permission.
18*c18ec02fSPetter Reinholdtsen *
19*c18ec02fSPetter Reinholdtsen * This software is provided "AS IS," without a warranty of any kind.
20*c18ec02fSPetter Reinholdtsen * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
21*c18ec02fSPetter Reinholdtsen * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
22*c18ec02fSPetter Reinholdtsen * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
23*c18ec02fSPetter Reinholdtsen * SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE
24*c18ec02fSPetter Reinholdtsen * FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
25*c18ec02fSPetter Reinholdtsen * OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
26*c18ec02fSPetter Reinholdtsen * SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA,
27*c18ec02fSPetter Reinholdtsen * OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
28*c18ec02fSPetter Reinholdtsen * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
29*c18ec02fSPetter Reinholdtsen * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
30*c18ec02fSPetter Reinholdtsen * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
31*c18ec02fSPetter Reinholdtsen */
32*c18ec02fSPetter Reinholdtsen
33*c18ec02fSPetter Reinholdtsen #include <stdlib.h>
34*c18ec02fSPetter Reinholdtsen #include <stdio.h>
35*c18ec02fSPetter Reinholdtsen #include <string.h>
36*c18ec02fSPetter Reinholdtsen #include <sys/types.h>
37*c18ec02fSPetter Reinholdtsen #include <sys/socket.h>
38*c18ec02fSPetter Reinholdtsen #include <netinet/in.h>
39*c18ec02fSPetter Reinholdtsen #include <arpa/inet.h>
40*c18ec02fSPetter Reinholdtsen #include <errno.h>
41*c18ec02fSPetter Reinholdtsen #include <unistd.h>
42*c18ec02fSPetter Reinholdtsen #include <signal.h>
43*c18ec02fSPetter Reinholdtsen
44*c18ec02fSPetter Reinholdtsen #include <ipmitool/ipmi.h>
45*c18ec02fSPetter Reinholdtsen #include <ipmitool/ipmi_intf.h>
46*c18ec02fSPetter Reinholdtsen #include <ipmitool/helper.h>
47*c18ec02fSPetter Reinholdtsen #include <ipmitool/log.h>
48*c18ec02fSPetter Reinholdtsen #include <ipmitool/ipmi_lanp.h>
49*c18ec02fSPetter Reinholdtsen #include <ipmitool/ipmi_session.h>
50*c18ec02fSPetter Reinholdtsen #include <ipmitool/ipmi_strings.h>
51*c18ec02fSPetter Reinholdtsen #include <ipmitool/bswap.h>
52*c18ec02fSPetter Reinholdtsen
53*c18ec02fSPetter Reinholdtsen
54*c18ec02fSPetter Reinholdtsen typedef enum {
55*c18ec02fSPetter Reinholdtsen IPMI_SESSION_REQUEST_CURRENT = 0,
56*c18ec02fSPetter Reinholdtsen IPMI_SESSION_REQUEST_ALL,
57*c18ec02fSPetter Reinholdtsen IPMI_SESSION_REQUEST_BY_ID,
58*c18ec02fSPetter Reinholdtsen IPMI_SESSION_REQUEST_BY_HANDLE
59*c18ec02fSPetter Reinholdtsen } Ipmi_Session_Request_Type;
60*c18ec02fSPetter Reinholdtsen
61*c18ec02fSPetter Reinholdtsen
62*c18ec02fSPetter Reinholdtsen
63*c18ec02fSPetter Reinholdtsen
64*c18ec02fSPetter Reinholdtsen /*
65*c18ec02fSPetter Reinholdtsen * print_session_info_csv
66*c18ec02fSPetter Reinholdtsen */
67*c18ec02fSPetter Reinholdtsen static void
print_session_info_csv(const struct get_session_info_rsp * session_info,int data_len)68*c18ec02fSPetter Reinholdtsen print_session_info_csv(const struct get_session_info_rsp * session_info,
69*c18ec02fSPetter Reinholdtsen int data_len)
70*c18ec02fSPetter Reinholdtsen {
71*c18ec02fSPetter Reinholdtsen char buffer[18];
72*c18ec02fSPetter Reinholdtsen uint16_t console_port_tmp;
73*c18ec02fSPetter Reinholdtsen
74*c18ec02fSPetter Reinholdtsen printf("%d", session_info->session_handle);
75*c18ec02fSPetter Reinholdtsen printf(",%d", session_info->session_slot_count);
76*c18ec02fSPetter Reinholdtsen printf(",%d", session_info->active_session_count);
77*c18ec02fSPetter Reinholdtsen
78*c18ec02fSPetter Reinholdtsen if (data_len == 3)
79*c18ec02fSPetter Reinholdtsen {
80*c18ec02fSPetter Reinholdtsen /* There is no session data here*/
81*c18ec02fSPetter Reinholdtsen printf("\n");
82*c18ec02fSPetter Reinholdtsen return;
83*c18ec02fSPetter Reinholdtsen }
84*c18ec02fSPetter Reinholdtsen
85*c18ec02fSPetter Reinholdtsen printf(",%d", session_info->user_id);
86*c18ec02fSPetter Reinholdtsen printf(",%s", val2str(session_info->privilege_level, ipmi_privlvl_vals));
87*c18ec02fSPetter Reinholdtsen
88*c18ec02fSPetter Reinholdtsen printf(",%s", session_info->auxiliary_data?
89*c18ec02fSPetter Reinholdtsen "IPMIv2/RMCP+" : "IPMIv1.5");
90*c18ec02fSPetter Reinholdtsen
91*c18ec02fSPetter Reinholdtsen printf(",0x%02x", session_info->channel_number);
92*c18ec02fSPetter Reinholdtsen
93*c18ec02fSPetter Reinholdtsen if (data_len == 18)
94*c18ec02fSPetter Reinholdtsen {
95*c18ec02fSPetter Reinholdtsen /* We have 802.3 LAN data */
96*c18ec02fSPetter Reinholdtsen printf(",%s",
97*c18ec02fSPetter Reinholdtsen inet_ntop(AF_INET,
98*c18ec02fSPetter Reinholdtsen &(session_info->channel_data.lan_data.console_ip),
99*c18ec02fSPetter Reinholdtsen buffer,
100*c18ec02fSPetter Reinholdtsen 16));
101*c18ec02fSPetter Reinholdtsen
102*c18ec02fSPetter Reinholdtsen printf(",%02x:%02x:%02x:%02x:%02x:%02x",
103*c18ec02fSPetter Reinholdtsen session_info->channel_data.lan_data.console_mac[0],
104*c18ec02fSPetter Reinholdtsen session_info->channel_data.lan_data.console_mac[1],
105*c18ec02fSPetter Reinholdtsen session_info->channel_data.lan_data.console_mac[2],
106*c18ec02fSPetter Reinholdtsen session_info->channel_data.lan_data.console_mac[3],
107*c18ec02fSPetter Reinholdtsen session_info->channel_data.lan_data.console_mac[4],
108*c18ec02fSPetter Reinholdtsen session_info->channel_data.lan_data.console_mac[5]);
109*c18ec02fSPetter Reinholdtsen
110*c18ec02fSPetter Reinholdtsen console_port_tmp = session_info->channel_data.lan_data.console_port;
111*c18ec02fSPetter Reinholdtsen #if WORDS_BIGENDIAN
112*c18ec02fSPetter Reinholdtsen console_port_tmp = BSWAP_16(console_port_tmp);
113*c18ec02fSPetter Reinholdtsen #endif
114*c18ec02fSPetter Reinholdtsen printf(",%d", console_port_tmp);
115*c18ec02fSPetter Reinholdtsen }
116*c18ec02fSPetter Reinholdtsen
117*c18ec02fSPetter Reinholdtsen
118*c18ec02fSPetter Reinholdtsen else if ((data_len == 12) || (data_len == 14))
119*c18ec02fSPetter Reinholdtsen {
120*c18ec02fSPetter Reinholdtsen /* Channel async serial/modem */
121*c18ec02fSPetter Reinholdtsen printf(",%s",
122*c18ec02fSPetter Reinholdtsen val2str(session_info->channel_data.modem_data.session_channel_activity_type,
123*c18ec02fSPetter Reinholdtsen ipmi_channel_activity_type_vals));
124*c18ec02fSPetter Reinholdtsen
125*c18ec02fSPetter Reinholdtsen printf(",%d",
126*c18ec02fSPetter Reinholdtsen session_info->channel_data.modem_data.destination_selector);
127*c18ec02fSPetter Reinholdtsen
128*c18ec02fSPetter Reinholdtsen printf(",%s",
129*c18ec02fSPetter Reinholdtsen inet_ntop(AF_INET,
130*c18ec02fSPetter Reinholdtsen &(session_info->channel_data.modem_data.console_ip),
131*c18ec02fSPetter Reinholdtsen buffer,
132*c18ec02fSPetter Reinholdtsen 16));
133*c18ec02fSPetter Reinholdtsen
134*c18ec02fSPetter Reinholdtsen if (data_len == 14)
135*c18ec02fSPetter Reinholdtsen {
136*c18ec02fSPetter Reinholdtsen /* Connection is PPP */
137*c18ec02fSPetter Reinholdtsen console_port_tmp = session_info->channel_data.lan_data.console_port;
138*c18ec02fSPetter Reinholdtsen #if WORDS_BIGENDIAN
139*c18ec02fSPetter Reinholdtsen console_port_tmp = BSWAP_16(console_port_tmp);
140*c18ec02fSPetter Reinholdtsen #endif
141*c18ec02fSPetter Reinholdtsen printf(",%d", console_port_tmp);
142*c18ec02fSPetter Reinholdtsen }
143*c18ec02fSPetter Reinholdtsen }
144*c18ec02fSPetter Reinholdtsen
145*c18ec02fSPetter Reinholdtsen printf("\n");
146*c18ec02fSPetter Reinholdtsen }
147*c18ec02fSPetter Reinholdtsen
148*c18ec02fSPetter Reinholdtsen
149*c18ec02fSPetter Reinholdtsen
150*c18ec02fSPetter Reinholdtsen /*
151*c18ec02fSPetter Reinholdtsen * print_session_info_verbose
152*c18ec02fSPetter Reinholdtsen */
153*c18ec02fSPetter Reinholdtsen static void
print_session_info_verbose(const struct get_session_info_rsp * session_info,int data_len)154*c18ec02fSPetter Reinholdtsen print_session_info_verbose(const struct get_session_info_rsp * session_info,
155*c18ec02fSPetter Reinholdtsen int data_len)
156*c18ec02fSPetter Reinholdtsen {
157*c18ec02fSPetter Reinholdtsen char buffer[18];
158*c18ec02fSPetter Reinholdtsen uint16_t console_port_tmp;
159*c18ec02fSPetter Reinholdtsen
160*c18ec02fSPetter Reinholdtsen printf("session handle : %d\n", session_info->session_handle);
161*c18ec02fSPetter Reinholdtsen printf("slot count : %d\n", session_info->session_slot_count);
162*c18ec02fSPetter Reinholdtsen printf("active sessions : %d\n", session_info->active_session_count);
163*c18ec02fSPetter Reinholdtsen
164*c18ec02fSPetter Reinholdtsen if (data_len == 3)
165*c18ec02fSPetter Reinholdtsen {
166*c18ec02fSPetter Reinholdtsen /* There is no session data here */
167*c18ec02fSPetter Reinholdtsen printf("\n");
168*c18ec02fSPetter Reinholdtsen return;
169*c18ec02fSPetter Reinholdtsen }
170*c18ec02fSPetter Reinholdtsen
171*c18ec02fSPetter Reinholdtsen printf("user id : %d\n", session_info->user_id);
172*c18ec02fSPetter Reinholdtsen printf("privilege level : %s\n",
173*c18ec02fSPetter Reinholdtsen val2str(session_info->privilege_level, ipmi_privlvl_vals));
174*c18ec02fSPetter Reinholdtsen
175*c18ec02fSPetter Reinholdtsen printf("session type : %s\n", session_info->auxiliary_data?
176*c18ec02fSPetter Reinholdtsen "IPMIv2/RMCP+" : "IPMIv1.5");
177*c18ec02fSPetter Reinholdtsen
178*c18ec02fSPetter Reinholdtsen printf("channel number : 0x%02x\n", session_info->channel_number);
179*c18ec02fSPetter Reinholdtsen
180*c18ec02fSPetter Reinholdtsen
181*c18ec02fSPetter Reinholdtsen if (data_len == 18)
182*c18ec02fSPetter Reinholdtsen {
183*c18ec02fSPetter Reinholdtsen /* We have 802.3 LAN data */
184*c18ec02fSPetter Reinholdtsen printf("console ip : %s\n",
185*c18ec02fSPetter Reinholdtsen inet_ntop(AF_INET,
186*c18ec02fSPetter Reinholdtsen &(session_info->channel_data.lan_data.console_ip),
187*c18ec02fSPetter Reinholdtsen buffer,
188*c18ec02fSPetter Reinholdtsen 16));
189*c18ec02fSPetter Reinholdtsen
190*c18ec02fSPetter Reinholdtsen printf("console mac : %02x:%02x:%02x:%02x:%02x:%02x\n",
191*c18ec02fSPetter Reinholdtsen session_info->channel_data.lan_data.console_mac[0],
192*c18ec02fSPetter Reinholdtsen session_info->channel_data.lan_data.console_mac[1],
193*c18ec02fSPetter Reinholdtsen session_info->channel_data.lan_data.console_mac[2],
194*c18ec02fSPetter Reinholdtsen session_info->channel_data.lan_data.console_mac[3],
195*c18ec02fSPetter Reinholdtsen session_info->channel_data.lan_data.console_mac[4],
196*c18ec02fSPetter Reinholdtsen session_info->channel_data.lan_data.console_mac[5]);
197*c18ec02fSPetter Reinholdtsen
198*c18ec02fSPetter Reinholdtsen console_port_tmp = session_info->channel_data.lan_data.console_port;
199*c18ec02fSPetter Reinholdtsen #if WORDS_BIGENDIAN
200*c18ec02fSPetter Reinholdtsen console_port_tmp = BSWAP_16(console_port_tmp);
201*c18ec02fSPetter Reinholdtsen #endif
202*c18ec02fSPetter Reinholdtsen printf("console port : %d\n", console_port_tmp);
203*c18ec02fSPetter Reinholdtsen }
204*c18ec02fSPetter Reinholdtsen
205*c18ec02fSPetter Reinholdtsen
206*c18ec02fSPetter Reinholdtsen else if ((data_len == 12) || (data_len == 14))
207*c18ec02fSPetter Reinholdtsen {
208*c18ec02fSPetter Reinholdtsen /* Channel async serial/modem */
209*c18ec02fSPetter Reinholdtsen printf("Session/Channel Activity Type : %s\n",
210*c18ec02fSPetter Reinholdtsen val2str(session_info->channel_data.modem_data.session_channel_activity_type,
211*c18ec02fSPetter Reinholdtsen ipmi_channel_activity_type_vals));
212*c18ec02fSPetter Reinholdtsen
213*c18ec02fSPetter Reinholdtsen printf("Destination selector : %d\n",
214*c18ec02fSPetter Reinholdtsen session_info->channel_data.modem_data.destination_selector);
215*c18ec02fSPetter Reinholdtsen
216*c18ec02fSPetter Reinholdtsen printf("console ip : %s\n",
217*c18ec02fSPetter Reinholdtsen inet_ntop(AF_INET,
218*c18ec02fSPetter Reinholdtsen &(session_info->channel_data.modem_data.console_ip),
219*c18ec02fSPetter Reinholdtsen buffer,
220*c18ec02fSPetter Reinholdtsen 16));
221*c18ec02fSPetter Reinholdtsen
222*c18ec02fSPetter Reinholdtsen if (data_len == 14)
223*c18ec02fSPetter Reinholdtsen {
224*c18ec02fSPetter Reinholdtsen /* Connection is PPP */
225*c18ec02fSPetter Reinholdtsen console_port_tmp = session_info->channel_data.lan_data.console_port;
226*c18ec02fSPetter Reinholdtsen #if WORDS_BIGENDIAN
227*c18ec02fSPetter Reinholdtsen console_port_tmp = BSWAP_16(console_port_tmp);
228*c18ec02fSPetter Reinholdtsen #endif
229*c18ec02fSPetter Reinholdtsen printf("console port : %d\n", console_port_tmp);
230*c18ec02fSPetter Reinholdtsen }
231*c18ec02fSPetter Reinholdtsen }
232*c18ec02fSPetter Reinholdtsen
233*c18ec02fSPetter Reinholdtsen printf("\n");
234*c18ec02fSPetter Reinholdtsen }
235*c18ec02fSPetter Reinholdtsen
236*c18ec02fSPetter Reinholdtsen
print_session_info(const struct get_session_info_rsp * session_info,int data_len)237*c18ec02fSPetter Reinholdtsen static void print_session_info(const struct get_session_info_rsp * session_info,
238*c18ec02fSPetter Reinholdtsen int data_len)
239*c18ec02fSPetter Reinholdtsen {
240*c18ec02fSPetter Reinholdtsen if (csv_output)
241*c18ec02fSPetter Reinholdtsen print_session_info_csv(session_info, data_len);
242*c18ec02fSPetter Reinholdtsen else
243*c18ec02fSPetter Reinholdtsen print_session_info_verbose(session_info, data_len);
244*c18ec02fSPetter Reinholdtsen }
245*c18ec02fSPetter Reinholdtsen
246*c18ec02fSPetter Reinholdtsen
247*c18ec02fSPetter Reinholdtsen /*
248*c18ec02fSPetter Reinholdtsen * ipmi_get_session_info
249*c18ec02fSPetter Reinholdtsen *
250*c18ec02fSPetter Reinholdtsen * returns 0 on success
251*c18ec02fSPetter Reinholdtsen * -1 on error
252*c18ec02fSPetter Reinholdtsen */
253*c18ec02fSPetter Reinholdtsen int
ipmi_get_session_info(struct ipmi_intf * intf,Ipmi_Session_Request_Type session_request_type,uint32_t id_or_handle)254*c18ec02fSPetter Reinholdtsen ipmi_get_session_info(struct ipmi_intf * intf,
255*c18ec02fSPetter Reinholdtsen Ipmi_Session_Request_Type session_request_type,
256*c18ec02fSPetter Reinholdtsen uint32_t id_or_handle)
257*c18ec02fSPetter Reinholdtsen {
258*c18ec02fSPetter Reinholdtsen int i, retval = 0;
259*c18ec02fSPetter Reinholdtsen
260*c18ec02fSPetter Reinholdtsen struct ipmi_rs * rsp;
261*c18ec02fSPetter Reinholdtsen struct ipmi_rq req;
262*c18ec02fSPetter Reinholdtsen uint8_t rqdata[5]; // max length of the variable length request
263*c18ec02fSPetter Reinholdtsen struct get_session_info_rsp session_info;
264*c18ec02fSPetter Reinholdtsen
265*c18ec02fSPetter Reinholdtsen memset(&req, 0, sizeof(req));
266*c18ec02fSPetter Reinholdtsen memset(&session_info, 0, sizeof(session_info));
267*c18ec02fSPetter Reinholdtsen req.msg.netfn = IPMI_NETFN_APP; // 0x06
268*c18ec02fSPetter Reinholdtsen req.msg.cmd = IPMI_GET_SESSION_INFO; // 0x3D
269*c18ec02fSPetter Reinholdtsen req.msg.data = rqdata;
270*c18ec02fSPetter Reinholdtsen
271*c18ec02fSPetter Reinholdtsen switch (session_request_type)
272*c18ec02fSPetter Reinholdtsen {
273*c18ec02fSPetter Reinholdtsen
274*c18ec02fSPetter Reinholdtsen case IPMI_SESSION_REQUEST_CURRENT:
275*c18ec02fSPetter Reinholdtsen case IPMI_SESSION_REQUEST_BY_ID:
276*c18ec02fSPetter Reinholdtsen case IPMI_SESSION_REQUEST_BY_HANDLE:
277*c18ec02fSPetter Reinholdtsen switch (session_request_type)
278*c18ec02fSPetter Reinholdtsen {
279*c18ec02fSPetter Reinholdtsen case IPMI_SESSION_REQUEST_CURRENT:
280*c18ec02fSPetter Reinholdtsen rqdata[0] = 0x00;
281*c18ec02fSPetter Reinholdtsen req.msg.data_len = 1;
282*c18ec02fSPetter Reinholdtsen break;
283*c18ec02fSPetter Reinholdtsen case IPMI_SESSION_REQUEST_BY_ID:
284*c18ec02fSPetter Reinholdtsen rqdata[0] = 0xFF;
285*c18ec02fSPetter Reinholdtsen rqdata[1] = id_or_handle & 0x000000FF;
286*c18ec02fSPetter Reinholdtsen rqdata[2] = (id_or_handle >> 8) & 0x000000FF;
287*c18ec02fSPetter Reinholdtsen rqdata[3] = (id_or_handle >> 16) & 0x000000FF;
288*c18ec02fSPetter Reinholdtsen rqdata[4] = (id_or_handle >> 24) & 0x000000FF;
289*c18ec02fSPetter Reinholdtsen req.msg.data_len = 5;
290*c18ec02fSPetter Reinholdtsen break;
291*c18ec02fSPetter Reinholdtsen case IPMI_SESSION_REQUEST_BY_HANDLE:
292*c18ec02fSPetter Reinholdtsen rqdata[0] = 0xFE;
293*c18ec02fSPetter Reinholdtsen rqdata[1] = (uint8_t)id_or_handle;
294*c18ec02fSPetter Reinholdtsen req.msg.data_len = 2;
295*c18ec02fSPetter Reinholdtsen break;
296*c18ec02fSPetter Reinholdtsen case IPMI_SESSION_REQUEST_ALL:
297*c18ec02fSPetter Reinholdtsen break;
298*c18ec02fSPetter Reinholdtsen }
299*c18ec02fSPetter Reinholdtsen
300*c18ec02fSPetter Reinholdtsen rsp = intf->sendrecv(intf, &req);
301*c18ec02fSPetter Reinholdtsen if (rsp == NULL)
302*c18ec02fSPetter Reinholdtsen {
303*c18ec02fSPetter Reinholdtsen lprintf(LOG_ERR, "Get Session Info command failed");
304*c18ec02fSPetter Reinholdtsen retval = -1;
305*c18ec02fSPetter Reinholdtsen }
306*c18ec02fSPetter Reinholdtsen else if (rsp->ccode > 0)
307*c18ec02fSPetter Reinholdtsen {
308*c18ec02fSPetter Reinholdtsen lprintf(LOG_ERR, "Get Session Info command failed: %s",
309*c18ec02fSPetter Reinholdtsen val2str(rsp->ccode, completion_code_vals));
310*c18ec02fSPetter Reinholdtsen retval = -1;
311*c18ec02fSPetter Reinholdtsen }
312*c18ec02fSPetter Reinholdtsen
313*c18ec02fSPetter Reinholdtsen if (retval < 0)
314*c18ec02fSPetter Reinholdtsen {
315*c18ec02fSPetter Reinholdtsen if ((session_request_type == IPMI_SESSION_REQUEST_CURRENT) &&
316*c18ec02fSPetter Reinholdtsen (strncmp(intf->name, "lan", 3) != 0))
317*c18ec02fSPetter Reinholdtsen lprintf(LOG_ERR, "It is likely that the channel in use "
318*c18ec02fSPetter Reinholdtsen "does not support sessions");
319*c18ec02fSPetter Reinholdtsen }
320*c18ec02fSPetter Reinholdtsen else
321*c18ec02fSPetter Reinholdtsen {
322*c18ec02fSPetter Reinholdtsen memcpy(&session_info, rsp->data, rsp->data_len);
323*c18ec02fSPetter Reinholdtsen print_session_info(&session_info, rsp->data_len);
324*c18ec02fSPetter Reinholdtsen }
325*c18ec02fSPetter Reinholdtsen break;
326*c18ec02fSPetter Reinholdtsen
327*c18ec02fSPetter Reinholdtsen case IPMI_SESSION_REQUEST_ALL:
328*c18ec02fSPetter Reinholdtsen req.msg.data_len = 1;
329*c18ec02fSPetter Reinholdtsen i = 1;
330*c18ec02fSPetter Reinholdtsen do
331*c18ec02fSPetter Reinholdtsen {
332*c18ec02fSPetter Reinholdtsen rqdata[0] = i++;
333*c18ec02fSPetter Reinholdtsen rsp = intf->sendrecv(intf, &req);
334*c18ec02fSPetter Reinholdtsen
335*c18ec02fSPetter Reinholdtsen if (rsp == NULL)
336*c18ec02fSPetter Reinholdtsen {
337*c18ec02fSPetter Reinholdtsen lprintf(LOG_ERR, "Get Session Info command failed");
338*c18ec02fSPetter Reinholdtsen retval = -1;
339*c18ec02fSPetter Reinholdtsen break;
340*c18ec02fSPetter Reinholdtsen }
341*c18ec02fSPetter Reinholdtsen else if (rsp->ccode > 0 && rsp->ccode != 0xCC && rsp->ccode != 0xCB)
342*c18ec02fSPetter Reinholdtsen {
343*c18ec02fSPetter Reinholdtsen lprintf(LOG_ERR, "Get Session Info command failed: %s",
344*c18ec02fSPetter Reinholdtsen val2str(rsp->ccode, completion_code_vals));
345*c18ec02fSPetter Reinholdtsen retval = -1;
346*c18ec02fSPetter Reinholdtsen break;
347*c18ec02fSPetter Reinholdtsen }
348*c18ec02fSPetter Reinholdtsen else if (rsp->data_len < 3)
349*c18ec02fSPetter Reinholdtsen {
350*c18ec02fSPetter Reinholdtsen retval = -1;
351*c18ec02fSPetter Reinholdtsen break;
352*c18ec02fSPetter Reinholdtsen }
353*c18ec02fSPetter Reinholdtsen
354*c18ec02fSPetter Reinholdtsen memcpy(&session_info, rsp->data, rsp->data_len);
355*c18ec02fSPetter Reinholdtsen print_session_info(&session_info, rsp->data_len);
356*c18ec02fSPetter Reinholdtsen
357*c18ec02fSPetter Reinholdtsen } while (i <= session_info.session_slot_count);
358*c18ec02fSPetter Reinholdtsen break;
359*c18ec02fSPetter Reinholdtsen }
360*c18ec02fSPetter Reinholdtsen
361*c18ec02fSPetter Reinholdtsen return retval;
362*c18ec02fSPetter Reinholdtsen }
363*c18ec02fSPetter Reinholdtsen
364*c18ec02fSPetter Reinholdtsen
365*c18ec02fSPetter Reinholdtsen
366*c18ec02fSPetter Reinholdtsen static void
printf_session_usage(void)367*c18ec02fSPetter Reinholdtsen printf_session_usage(void)
368*c18ec02fSPetter Reinholdtsen {
369*c18ec02fSPetter Reinholdtsen lprintf(LOG_NOTICE, "Session Commands: info <active | all | id 0xnnnnnnnn | handle 0xnn>");
370*c18ec02fSPetter Reinholdtsen }
371*c18ec02fSPetter Reinholdtsen
372*c18ec02fSPetter Reinholdtsen
373*c18ec02fSPetter Reinholdtsen int
ipmi_session_main(struct ipmi_intf * intf,int argc,char ** argv)374*c18ec02fSPetter Reinholdtsen ipmi_session_main(struct ipmi_intf * intf, int argc, char ** argv)
375*c18ec02fSPetter Reinholdtsen {
376*c18ec02fSPetter Reinholdtsen int retval = 0;
377*c18ec02fSPetter Reinholdtsen
378*c18ec02fSPetter Reinholdtsen if (argc == 0 || strncmp(argv[0], "help", 4) == 0)
379*c18ec02fSPetter Reinholdtsen {
380*c18ec02fSPetter Reinholdtsen printf_session_usage();
381*c18ec02fSPetter Reinholdtsen }
382*c18ec02fSPetter Reinholdtsen else if (strncmp(argv[0], "info", 4) == 0)
383*c18ec02fSPetter Reinholdtsen {
384*c18ec02fSPetter Reinholdtsen
385*c18ec02fSPetter Reinholdtsen if ((argc < 2) || strncmp(argv[1], "help", 4) == 0)
386*c18ec02fSPetter Reinholdtsen {
387*c18ec02fSPetter Reinholdtsen printf_session_usage();
388*c18ec02fSPetter Reinholdtsen }
389*c18ec02fSPetter Reinholdtsen else
390*c18ec02fSPetter Reinholdtsen {
391*c18ec02fSPetter Reinholdtsen Ipmi_Session_Request_Type session_request_type = 0;
392*c18ec02fSPetter Reinholdtsen uint32_t id_or_handle = 0;
393*c18ec02fSPetter Reinholdtsen
394*c18ec02fSPetter Reinholdtsen if (strncmp(argv[1], "active", 6) == 0)
395*c18ec02fSPetter Reinholdtsen session_request_type = IPMI_SESSION_REQUEST_CURRENT;
396*c18ec02fSPetter Reinholdtsen else if (strncmp(argv[1], "all", 3) == 0)
397*c18ec02fSPetter Reinholdtsen session_request_type = IPMI_SESSION_REQUEST_ALL;
398*c18ec02fSPetter Reinholdtsen else if (strncmp(argv[1], "id", 2) == 0)
399*c18ec02fSPetter Reinholdtsen {
400*c18ec02fSPetter Reinholdtsen if (argc >= 3)
401*c18ec02fSPetter Reinholdtsen {
402*c18ec02fSPetter Reinholdtsen session_request_type = IPMI_SESSION_REQUEST_BY_ID;
403*c18ec02fSPetter Reinholdtsen if (str2uint(argv[2], &id_or_handle) != 0) {
404*c18ec02fSPetter Reinholdtsen lprintf(LOG_ERR, "HEX number expected, but '%s' given.",
405*c18ec02fSPetter Reinholdtsen argv[2]);
406*c18ec02fSPetter Reinholdtsen printf_session_usage();
407*c18ec02fSPetter Reinholdtsen retval = -1;
408*c18ec02fSPetter Reinholdtsen }
409*c18ec02fSPetter Reinholdtsen }
410*c18ec02fSPetter Reinholdtsen else
411*c18ec02fSPetter Reinholdtsen {
412*c18ec02fSPetter Reinholdtsen lprintf(LOG_ERR, "Missing id argument");
413*c18ec02fSPetter Reinholdtsen printf_session_usage();
414*c18ec02fSPetter Reinholdtsen retval = -1;
415*c18ec02fSPetter Reinholdtsen }
416*c18ec02fSPetter Reinholdtsen }
417*c18ec02fSPetter Reinholdtsen else if (strncmp(argv[1], "handle", 6) == 0)
418*c18ec02fSPetter Reinholdtsen {
419*c18ec02fSPetter Reinholdtsen if (argc >= 3)
420*c18ec02fSPetter Reinholdtsen {
421*c18ec02fSPetter Reinholdtsen session_request_type = IPMI_SESSION_REQUEST_BY_HANDLE;
422*c18ec02fSPetter Reinholdtsen if (str2uint(argv[2], &id_or_handle) != 0) {
423*c18ec02fSPetter Reinholdtsen lprintf(LOG_ERR, "HEX number expected, but '%s' given.",
424*c18ec02fSPetter Reinholdtsen argv[2]);
425*c18ec02fSPetter Reinholdtsen printf_session_usage();
426*c18ec02fSPetter Reinholdtsen retval = -1;
427*c18ec02fSPetter Reinholdtsen }
428*c18ec02fSPetter Reinholdtsen }
429*c18ec02fSPetter Reinholdtsen else
430*c18ec02fSPetter Reinholdtsen {
431*c18ec02fSPetter Reinholdtsen lprintf(LOG_ERR, "Missing handle argument");
432*c18ec02fSPetter Reinholdtsen printf_session_usage();
433*c18ec02fSPetter Reinholdtsen retval = -1;
434*c18ec02fSPetter Reinholdtsen }
435*c18ec02fSPetter Reinholdtsen }
436*c18ec02fSPetter Reinholdtsen else
437*c18ec02fSPetter Reinholdtsen {
438*c18ec02fSPetter Reinholdtsen lprintf(LOG_ERR, "Invalid SESSION info parameter: %s", argv[1]);
439*c18ec02fSPetter Reinholdtsen printf_session_usage();
440*c18ec02fSPetter Reinholdtsen retval = -1;
441*c18ec02fSPetter Reinholdtsen }
442*c18ec02fSPetter Reinholdtsen
443*c18ec02fSPetter Reinholdtsen
444*c18ec02fSPetter Reinholdtsen if (retval == 0)
445*c18ec02fSPetter Reinholdtsen retval = ipmi_get_session_info(intf,
446*c18ec02fSPetter Reinholdtsen session_request_type,
447*c18ec02fSPetter Reinholdtsen id_or_handle);
448*c18ec02fSPetter Reinholdtsen }
449*c18ec02fSPetter Reinholdtsen }
450*c18ec02fSPetter Reinholdtsen else
451*c18ec02fSPetter Reinholdtsen {
452*c18ec02fSPetter Reinholdtsen lprintf(LOG_ERR, "Invalid SESSION command: %s", argv[0]);
453*c18ec02fSPetter Reinholdtsen printf_session_usage();
454*c18ec02fSPetter Reinholdtsen retval = -1;
455*c18ec02fSPetter Reinholdtsen }
456*c18ec02fSPetter Reinholdtsen
457*c18ec02fSPetter Reinholdtsen return retval;
458*c18ec02fSPetter Reinholdtsen }
459*c18ec02fSPetter Reinholdtsen
460