~ubuntu-branches/ubuntu/vivid/ipmitool/vivid-updates

« back to all changes in this revision

Viewing changes to lib/ipmi_delloem.c

  • Committer: Package Import Robot
  • Author(s): Luk Claes
  • Date: 2013-05-07 18:12:12 UTC
  • mfrom: (5.1.11 raring-proposed)
  • Revision ID: package-import@ubuntu.com-20130507181212-fitwelheknk3tqnq
Tags: 1.8.12-1
Merge new upstream from Ubuntu (Closes: #692292).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************************
 
2
Copyright (c) 2008, Dell Inc
 
3
All rights reserved.
 
4
Redistribution and use in source and binary forms, with or without
 
5
modification, are permitted provided that the following conditions are met:
 
6
- Redistributions of source code must retain the above copyright notice,
 
7
this list of conditions and the following disclaimer.
 
8
 
 
9
- Redistributions in binary form must reproduce the above copyright notice,
 
10
this list of conditions and the following disclaimer in the documentation
 
11
and/or other materials provided with the distribution. 
 
12
- Neither the name of Dell Inc nor the names of its contributors
 
13
may be used to endorse or promote products derived from this software 
 
14
without specific prior written permission. 
 
15
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 
16
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 
17
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
18
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 
19
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 
20
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 
21
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 
22
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 
23
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 
24
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 
25
POSSIBILITY OF SUCH DAMAGE. 
 
26
 
 
27
 
 
28
******************************************************************/
 
29
/*
 
30
* Thursday Oct 7 17:30:12 2009
 
31
* <deepaganesh_paulraj@dell.com>
 
32
*
 
33
* This code implements a dell OEM proprietary commands.
 
34
* This Code is edited and Implemented the License feature for Delloem
 
35
* Author Harsha S <Harsha_S1@dell.com>
 
36
*/
 
37
 
 
38
#include <stdlib.h>
 
39
#include <stdio.h>
 
40
#include <string.h>
 
41
#include <sys/types.h>
 
42
#include <sys/socket.h>
 
43
#include <netinet/in.h>
 
44
#include <arpa/inet.h>
 
45
#include <errno.h>
 
46
#include <unistd.h>
 
47
#include <signal.h>
 
48
#include <ctype.h>
 
49
#include <limits.h>
 
50
#include <ipmitool/ipmi.h>
 
51
#include <ipmitool/ipmi_intf.h>
 
52
#include <ipmitool/helper.h>
 
53
#include <ipmitool/log.h>
 
54
#include <ipmitool/ipmi_sel.h>
 
55
#include <ipmitool/ipmi_delloem.h>
 
56
#include <ipmitool/ipmi_fru.h>
 
57
#include <ipmitool/ipmi_sdr.h>
 
58
#include <ipmitool/ipmi_mc.h>
 
59
#include <ipmitool/ipmi_sensor.h>
 
60
#include <ipmitool/ipmi_sel.h>
 
61
#include <ipmitool/bswap.h>
 
62
#include <ipmitool/ipmi_sdr.h>
 
63
#include <ipmitool/ipmi_entity.h>
 
64
#include <ipmitool/ipmi_fru.h>
 
65
#include <ipmitool/ipmi_sensor.h>
 
66
/*------------ipmi headers------------------*/
 
67
 
 
68
 
 
69
 
 
70
/*--------------time header-----------------*/
 
71
#include <time.h>
 
72
 
 
73
#define DELL_OEM_NETFN        (uint8_t)(0x30)
 
74
#define GET_IDRAC_VIRTUAL_MAC      (uint8_t)(0xC9)
 
75
// 11g Support Macros
 
76
#define INVALID                         -1
 
77
#define SHARED                          0
 
78
#define SHARED_WITH_FAILOVER_LOM2       1
 
79
#define DEDICATED                       2
 
80
#define SHARED_WITH_FAILOVER_ALL_LOMS   3
 
81
char AciveLOM_String [6] [10] = {"None","LOM1","LOM2","LOM3","LOM4","dedicated" };
 
82
 
 
83
/* 11g Support Strings for nic selection */
 
84
char NIC_Selection_Mode_String [4] [50] =       {
 
85
                                                "shared",
 
86
                                                "shared with failover lom2",
 
87
                                                "dedicated",
 
88
                                                "shared with Failover all loms"
 
89
                                                };
 
90
 
 
91
/* 11g Support Macros */
 
92
#define SHARED                          0
 
93
#define SHARED_WITH_FAILOVER_LOM2       1
 
94
#define DEDICATED                       2
 
95
#define SHARED_WITH_FAILOVER_ALL_LOMS   3
 
96
 
 
97
/* 12g Support Strings for nic selection */
 
98
#define INVAILD_FAILOVER_MODE           -2
 
99
#define INVAILD_FAILOVER_MODE_SETTINGS  -3
 
100
#define INVAILD_SHARED_MODE             -4
 
101
 
 
102
#define INVAILD_FAILOVER_MODE_STRING    "ERROR: Cannot set shared with failover lom same as current shared lom.\n"
 
103
#define INVAILD_FAILOVER_MODE_SET       "ERROR: Cannot set shared with failover loms when NIC is set to dedicated Mode.\n"
 
104
#define INVAILD_SHARED_MODE_SET_STRING  "ERROR: Cannot set shared Mode for Blades.\n"
 
105
 
 
106
 
 
107
char NIC_Selection_Mode_String_12g[] [50] =     {       
 
108
                                                                                                "dedicated",
 
109
                                                                                                "shared with lom1",  
 
110
                                                                                                "shared with lom2",
 
111
                                                                                                "shared with lom3",
 
112
                                                                                                "shared with lom4",
 
113
                                                                                                "shared with failover lom1",
 
114
                                                                                                "shared with failover lom2",
 
115
                                                                                                "shared with failover lom3",
 
116
                                                                                                "shared with failover lom4",
 
117
                                                                                                "shared with failover all loms"
 
118
                                                                                        };
 
119
 
 
120
static int current_arg =0;
 
121
uint8_t iDRAC_FLAG=0;
 
122
LCD_MODE lcd_mode;
 
123
static uint8_t LcdSupported=0;
 
124
static uint8_t SetLEDSupported=0;
 
125
 
 
126
volatile uint8_t IMC_Type = IMC_IDRAC_10G;
 
127
 
 
128
 
 
129
const struct vFlashstr vFlash_completion_code_vals[] = {
 
130
        {0x00, "SUCCESS"},
 
131
        {0x01, "NO_SD_CARD"},
 
132
        {0x63, "UNKNOWN_ERROR"},
 
133
        {0x00, NULL}
 
134
};
 
135
 
 
136
 
 
137
POWER_HEADROOM powerheadroom;
 
138
 
 
139
uint8_t PowercapSetable_flag=0;
 
140
uint8_t PowercapstatusFlag=0;
 
141
 
 
142
static void usage(void);
 
143
 
 
144
/* LCD Function prototypes */
 
145
static int ipmi_delloem_lcd_main (struct ipmi_intf * intf, int argc, char ** argv);
 
146
static void ipmi_lcd_get_platform_model_name (struct ipmi_intf * intf,char* lcdstring,
 
147
                        uint8_t max_length,uint8_t field_type);
 
148
static int ipmi_idracvalidator_command (struct ipmi_intf * intf);
 
149
static int ipmi_lcd_get_configure_command_wh (struct ipmi_intf * intf);
 
150
static int ipmi_lcd_get_configure_command (struct ipmi_intf * intf,uint8_t *command);
 
151
static int ipmi_lcd_set_configure_command (struct ipmi_intf * intf, int command);
 
152
static int ipmi_lcd_set_configure_command_wh (struct ipmi_intf * intf, uint32_t  mode,
 
153
                        uint16_t lcdquallifier,uint8_t errordisp);
 
154
static int ipmi_lcd_get_single_line_text (struct ipmi_intf * intf, char* lcdstring, uint8_t max_length);
 
155
static int ipmi_lcd_get_info_wh(struct ipmi_intf * intf);
 
156
static int ipmi_lcd_get_info(struct ipmi_intf * intf);
 
157
static int ipmi_lcd_get_status_val(struct ipmi_intf * intf, LCD_STATUS* lcdstatus);
 
158
static int IsLCDSupported ();
 
159
static void CheckLCDSupport(struct ipmi_intf * intf);
 
160
static void ipmi_lcd_status_print( LCD_STATUS lcdstatus);
 
161
static int ipmi_lcd_get_status(struct ipmi_intf * intf );
 
162
static int ipmi_lcd_set_kvm(struct ipmi_intf * intf, char status);
 
163
static int ipmi_lcd_set_lock(struct ipmi_intf * intf,  char lock);
 
164
static int ipmi_lcd_set_single_line_text (struct ipmi_intf * intf, char * text);
 
165
static int ipmi_lcd_set_text(struct ipmi_intf * intf, char * text, int line_number);
 
166
static int ipmi_lcd_configure_wh (struct ipmi_intf * intf, uint32_t  mode ,
 
167
                       uint16_t lcdquallifier, uint8_t errordisp, 
 
168
                       int8_t line_number, char * text);
 
169
static int ipmi_lcd_configure (struct ipmi_intf * intf, int command, 
 
170
                    int8_t line_number, char * text);
 
171
static void ipmi_lcd_usage(void);
 
172
 
 
173
/* MAC Function prototypes */
 
174
static int ipmi_delloem_mac_main (struct ipmi_intf * intf, int argc, char ** argv);
 
175
static int make_int(const char *str, int *value);
 
176
static void InitEmbeddedNICMacAddressValues ();
 
177
static int ipmi_macinfo_drac_idrac_virtual_mac(struct ipmi_intf* intf,uint8_t NicNum);
 
178
static int ipmi_macinfo_drac_idrac_mac(struct ipmi_intf* intf,uint8_t NicNum);
 
179
static int ipmi_macinfo_10g (struct ipmi_intf* intf, uint8_t NicNum);
 
180
static int ipmi_macinfo_11g (struct ipmi_intf* intf, uint8_t NicNum);
 
181
static int ipmi_macinfo (struct ipmi_intf* intf, uint8_t NicNum);
 
182
static void ipmi_mac_usage(void);
 
183
 
 
184
/* LAN Function prototypes */
 
185
static int ipmi_delloem_lan_main (struct ipmi_intf * intf, int argc, char ** argv);
 
186
static int IsLANSupported ();
 
187
static int get_nic_selection_mode (int current_arg, char ** argv);
 
188
static int ipmi_lan_set_nic_selection (struct ipmi_intf* intf, uint8_t nic_selection);
 
189
static int ipmi_lan_get_nic_selection (struct ipmi_intf* intf);
 
190
static int ipmi_lan_get_active_nic (struct ipmi_intf* intf);
 
191
static void ipmi_lan_usage(void);
 
192
static int ipmi_lan_set_nic_selection_12g (struct ipmi_intf* intf, uint8_t* nic_selection);
 
193
 
 
194
/* POwer monitor Function prototypes */
 
195
static int ipmi_delloem_powermonitor_main (struct ipmi_intf * intf, int argc, char ** argv);
 
196
static void ipmi_time_to_str(time_t rawTime, char* strTime);
 
197
static int ipmi_get_sensor_reading(struct ipmi_intf *intf ,
 
198
            unsigned char sensorNumber, 
 
199
                        SensorReadingType* pSensorReadingData);
 
200
static int ipmi_get_power_capstatus_command (struct ipmi_intf * intf);
 
201
static int ipmi_set_power_capstatus_command (struct ipmi_intf * intf,uint8_t val);
 
202
static int ipmi_powermgmt(struct ipmi_intf* intf);
 
203
static int ipmi_powermgmt_clear(struct ipmi_intf* intf,uint8_t clearValue);
 
204
static uint64_t watt_to_btuphr_conversion(uint32_t powerinwatt);
 
205
static uint32_t btuphr_to_watt_conversion(uint64_t powerinbtuphr);
 
206
static int ipmi_get_power_headroom_command (struct ipmi_intf * intf,uint8_t unit);
 
207
static int ipmi_get_power_consumption_data(struct ipmi_intf* intf,uint8_t unit);
 
208
static int ipmi_get_instan_power_consmpt_data(struct ipmi_intf* intf,
 
209
                        IPMI_INST_POWER_CONSUMPTION_DATA* instpowerconsumptiondata);
 
210
static void ipmi_print_get_instan_power_Amps_data(IPMI_INST_POWER_CONSUMPTION_DATA instpowerconsumptiondata);
 
211
static int ipmi_print_get_power_consmpt_data(struct ipmi_intf* intf,uint8_t  unit);
 
212
static int ipmi_get_avgpower_consmpt_history(struct ipmi_intf* intf,IPMI_AVGPOWER_CONSUMP_HISTORY* pavgpower );
 
213
static int ipmi_get_peakpower_consmpt_history(struct ipmi_intf* intf,IPMI_POWER_CONSUMP_HISTORY * pstPeakpower);
 
214
static int ipmi_get_minpower_consmpt_history(struct ipmi_intf* intf,IPMI_POWER_CONSUMP_HISTORY * pstMinpower);
 
215
static int ipmi_print_power_consmpt_history(struct ipmi_intf* intf,int unit );
 
216
static int ipmi_get_power_cap(struct ipmi_intf* intf,IPMI_POWER_CAP* ipmipowercap );
 
217
static int ipmi_print_power_cap(struct ipmi_intf* intf,uint8_t unit );
 
218
static int ipmi_set_power_cap(struct ipmi_intf* intf,int unit,int val );
 
219
static int getpowersupplyfruinfo(struct ipmi_intf *intf, uint8_t id, 
 
220
                       struct fru_header header, struct fru_info fru);
 
221
static void ipmi_powermonitor_usage(void);
 
222
 
 
223
/* vFlash Function prototypes */
 
224
static int ipmi_delloem_vFlash_main(struct ipmi_intf * intf, int argc, char ** argv);
 
225
const char * get_vFlash_compcode_str(uint8_t vflashcompcode, const struct vFlashstr *vs);
 
226
static int ipmi_get_sd_card_info(struct ipmi_intf* intf);
 
227
static int ipmi_delloem_vFlash_process(struct ipmi_intf* intf, int current_arg, char ** argv);
 
228
static void ipmi_vFlash_usage(void);
 
229
 
 
230
 
 
231
/* LED Function prototypes */
 
232
 
 
233
static int ipmi_getsesmask(int, char **);
 
234
static void CheckSetLEDSupport(struct ipmi_intf * intf);
 
235
static int IsSetLEDSupported(void);
 
236
static void ipmi_setled_usage(void);
 
237
static int ipmi_delloem_setled_main(struct ipmi_intf *intf, int argc, char ** argv);
 
238
static int ipmi_setled_state (struct ipmi_intf * intf, int bayId, int slotId, int state);
 
239
static int ipmi_getdrivemap (struct ipmi_intf * intf, int b, int d, int f, int *bayId, int *slotId);
 
240
 
 
241
/*****************************************************************
 
242
* Function Name:       ipmi_delloem_main
 
243
*
 
244
* Description:         This function processes the delloem command
 
245
* Input:               intf    - ipmi interface
 
246
                       argc    - no of arguments
 
247
                       argv    - argument string array
 
248
* Output:        
 
249
*
 
250
* Return:              return code     0 - success
 
251
*                                      -1 - failure
 
252
*
 
253
******************************************************************/
 
254
 
 
255
int
 
256
ipmi_delloem_main(struct ipmi_intf * intf, int argc, char ** argv)
 
257
{
 
258
    int rc = 0;
 
259
 
 
260
    if (argc == 0 || strncmp(argv[0], "help\0", 5) == 0) 
 
261
    {
 
262
        usage();
 
263
        return 0;
 
264
    }
 
265
 
 
266
    if (0 ==strncmp(argv[current_arg], "lcd\0", 4))
 
267
    {
 
268
        ipmi_delloem_lcd_main (intf,argc,argv);
 
269
    }
 
270
    /* mac address*/
 
271
    else if (strncmp(argv[current_arg], "mac\0", 4) == 0) 
 
272
    {
 
273
        ipmi_delloem_mac_main (intf,argc,argv);
 
274
    }
 
275
    /* lan address*/
 
276
    else if (strncmp(argv[current_arg], "lan\0", 4) == 0)
 
277
    {
 
278
        ipmi_delloem_lan_main (intf,argc,argv);
 
279
    }
 
280
    /* SetLED support */
 
281
    else if (strncmp(argv[current_arg], "setled\0", 7) == 0)
 
282
    {
 
283
        ipmi_delloem_setled_main (intf,argc,argv);
 
284
    }
 
285
    /*Powermanagement report processing*/
 
286
    else if (strncmp(argv[current_arg], "powermonitor\0", 13) == 0) 
 
287
    {
 
288
        ipmi_delloem_powermonitor_main (intf,argc,argv);
 
289
    }
 
290
        /* vFlash Support */    
 
291
        else if (strncmp(argv[current_arg], "vFlash\0", 7) == 0)
 
292
        {
 
293
        ipmi_delloem_vFlash_main (intf,argc,argv);      
 
294
        }
 
295
    else
 
296
    {
 
297
        usage();
 
298
        return -1;
 
299
    }
 
300
    return rc;
 
301
}
 
302
 
 
303
/*****************************************************************
 
304
* Function Name:     usage
 
305
*
 
306
* Description:       This function prints help message for delloem command
 
307
* Input:           
 
308
* Output:       
 
309
*
 
310
* Return:              
 
311
*
 
312
******************************************************************/
 
313
 
 
314
static void usage(void)
 
315
{
 
316
    lprintf(LOG_NOTICE, "");
 
317
    lprintf(LOG_NOTICE, "usage: delloem <command> [option...]");
 
318
    lprintf(LOG_NOTICE, "");
 
319
    lprintf(LOG_NOTICE, "commands:");
 
320
    lprintf(LOG_NOTICE, "    lcd");
 
321
    lprintf(LOG_NOTICE, "    mac");
 
322
    lprintf(LOG_NOTICE, "    lan");
 
323
    lprintf(LOG_NOTICE, "    setled");
 
324
    lprintf(LOG_NOTICE, "    powermonitor");
 
325
    lprintf(LOG_NOTICE, "    vFlash");
 
326
    lprintf(LOG_NOTICE, "");
 
327
    lprintf(LOG_NOTICE, "For help on individual commands type:");
 
328
    lprintf(LOG_NOTICE, "delloem <command> help");
 
329
 
 
330
}
 
331
 
 
332
/*****************************************************************
 
333
* Function Name:       ipmi_delloem_lcd_main
 
334
*
 
335
* Description:         This function processes the delloem lcd command
 
336
* Input:               intf    - ipmi interface
 
337
                       argc    - no of arguments
 
338
                       argv    - argument string array
 
339
* Output:        
 
340
*
 
341
* Return:              return code     0 - success
 
342
*                         -1 - failure
 
343
*
 
344
******************************************************************/
 
345
 
 
346
static int ipmi_delloem_lcd_main (struct ipmi_intf * intf, int argc, char ** argv)
 
347
{
 
348
    int rc = 0;
 
349
 
 
350
    current_arg++;
 
351
    if (argc < current_arg) 
 
352
    {
 
353
        usage();
 
354
        return -1;
 
355
    }
 
356
 
 
357
 
 
358
    /* ipmitool delloem lcd info*/
 
359
    if (argc == 1 || strcmp(argv[current_arg], "help") == 0)
 
360
    {
 
361
        ipmi_lcd_usage();
 
362
        return 0;
 
363
    }
 
364
    CheckLCDSupport (intf);
 
365
    ipmi_idracvalidator_command(intf);
 
366
    if (!IsLCDSupported()) {
 
367
        printf("lcd is not supported on this system.\n");
 
368
        return -1;
 
369
    }
 
370
    else if (strncmp(argv[current_arg], "info\0", 5) == 0) 
 
371
    {
 
372
        if((iDRAC_FLAG==IDRAC_11G) || (iDRAC_FLAG==IDRAC_12G) )
 
373
            rc = ipmi_lcd_get_info_wh(intf);
 
374
        else
 
375
            rc = ipmi_lcd_get_info(intf);
 
376
    }
 
377
    else if (strncmp(argv[current_arg], "status\0", 7) == 0)
 
378
    {
 
379
        rc = ipmi_lcd_get_status(intf);
 
380
    }
 
381
    /* ipmitool delloem lcd set*/
 
382
    else if (strncmp(argv[current_arg], "set\0", 4) == 0) 
 
383
    {
 
384
        uint8_t line_number = 0;
 
385
        current_arg++;
 
386
        if (argc <= current_arg) 
 
387
        {
 
388
            ipmi_lcd_usage();
 
389
            return -1;
 
390
        }
 
391
        if (strncmp(argv[current_arg], "line\0", 5) == 0) 
 
392
        {
 
393
            current_arg++;
 
394
            if (argc <= current_arg) {usage();return -1;}
 
395
            line_number = (uint8_t)strtoul(argv[current_arg], NULL, 0);
 
396
            current_arg++;
 
397
            if (argc <= current_arg) {usage();return -1;}
 
398
        }
 
399
 
 
400
 
 
401
                if ((strncmp(argv[current_arg], "mode\0", 5) == 0)&&((iDRAC_FLAG==IDRAC_11G) || (iDRAC_FLAG==IDRAC_12G) )) 
 
402
        {
 
403
            current_arg++;
 
404
            if (argc <= current_arg) 
 
405
            {
 
406
                ipmi_lcd_usage();
 
407
                return -1;
 
408
            }    
 
409
            if (argv[current_arg] == NULL)  
 
410
            {
 
411
                ipmi_lcd_usage();
 
412
                return -1;
 
413
            }
 
414
            if (strncmp(argv[current_arg], "none\0", 5) == 0) 
 
415
            {
 
416
                rc = ipmi_lcd_configure_wh (intf, IPMI_DELL_LCD_CONFIG_NONE,0xFF,0XFF, 0, NULL);
 
417
            }
 
418
            else if (strncmp(argv[current_arg], "modelname\0", 10) == 0) 
 
419
            {
 
420
                rc = ipmi_lcd_configure_wh (intf, IPMI_DELL_LCD_CONFIG_DEFAULT,0xFF,0XFF, 0, NULL);
 
421
            }
 
422
            else if (strncmp(argv[current_arg], "userdefined\0", 12) == 0) 
 
423
            {
 
424
                current_arg++;
 
425
                if (argc <= current_arg) 
 
426
                {
 
427
                    ipmi_lcd_usage();return -1;
 
428
                }
 
429
                rc = ipmi_lcd_configure_wh (intf, IPMI_DELL_LCD_CONFIG_USER_DEFINED,0xFF,0XFF, line_number, argv[current_arg]);
 
430
            }
 
431
            else if (strncmp(argv[current_arg], "ipv4address\0", 12) == 0) 
 
432
            {
 
433
                rc = ipmi_lcd_configure_wh (intf, IPMI_DELL_LCD_iDRAC_IPV4ADRESS  ,0xFF,0XFF, 0, NULL);
 
434
            }
 
435
            else if (strncmp(argv[current_arg], "macaddress\0", 11) == 0) 
 
436
            {
 
437
                rc = ipmi_lcd_configure_wh (intf, IPMI_DELL_LCD_IDRAC_MAC_ADDRESS,0xFF,0XFF, 0, NULL);
 
438
            }
 
439
            else if (strncmp(argv[current_arg], "systemname\0", 11) == 0) 
 
440
            {
 
441
                rc = ipmi_lcd_configure_wh (intf, IPMI_DELL_LCD_OS_SYSTEM_NAME,0xFF,0XFF, 0, NULL);
 
442
            }
 
443
            else if (strncmp(argv[current_arg], "servicetag\0", 11) == 0) 
 
444
            {
 
445
                rc = ipmi_lcd_configure_wh (intf, IPMI_DELL_LCD_SERVICE_TAG, 0xFF,0XFF,0, NULL);
 
446
            }
 
447
            else if (strncmp(argv[current_arg], "ipv6address\0", 12) == 0) 
 
448
            {
 
449
                rc = ipmi_lcd_configure_wh (intf, IPMI_DELL_LCD_iDRAC_IPV6ADRESS  ,0xFF,0XFF, 0, NULL);
 
450
            }
 
451
            else if (strncmp(argv[current_arg], "ambienttemp\0", 12) == 0) 
 
452
            {
 
453
                rc = ipmi_lcd_configure_wh (intf, IPMI_DELL_LCD_AMBEINT_TEMP, 0xFF,0XFF,0, NULL);
 
454
 
 
455
            }
 
456
            else if (strncmp(argv[current_arg], "systemwatt\0", 11) == 0) 
 
457
            {
 
458
                rc = ipmi_lcd_configure_wh (intf, IPMI_DELL_LCD_SYSTEM_WATTS , 0xFF,0XFF,0, NULL);
 
459
 
 
460
            }
 
461
            else if (strncmp(argv[current_arg], "assettag\0", 9) == 0) 
 
462
            {
 
463
                rc = ipmi_lcd_configure_wh (intf, IPMI_DELL_LCD_ASSET_TAG , 0xFF,0XFF,0, NULL);
 
464
 
 
465
            }
 
466
            else if (strncmp(argv[current_arg], "help\0", 5) == 0) 
 
467
            {
 
468
                ipmi_lcd_usage();
 
469
            }
 
470
            else
 
471
            {       
 
472
                ipmi_lcd_usage();
 
473
            }
 
474
        }
 
475
                else if ((strncmp(argv[current_arg], "lcdqualifier\0", 13)== 0) &&((iDRAC_FLAG==IDRAC_11G) || (iDRAC_FLAG==IDRAC_12G) ) )
 
476
        {
 
477
 
 
478
            current_arg++;
 
479
            if (argc <= current_arg) 
 
480
            {
 
481
                ipmi_lcd_usage();
 
482
                return -1;
 
483
            }
 
484
            if (argv[current_arg] == NULL) 
 
485
            {
 
486
                ipmi_lcd_usage();
 
487
                return -1;
 
488
            } 
 
489
 
 
490
            if (strncmp(argv[current_arg], "watt\0", 5) == 0) {
 
491
 
 
492
 
 
493
                rc = ipmi_lcd_configure_wh (intf, 0xFF,0x00,0XFF, 0, NULL);
 
494
            }
 
495
            else if (strncmp(argv[current_arg], "btuphr\0",7) == 0) {
 
496
                rc = ipmi_lcd_configure_wh (intf, 0xFF,0x01,0XFF, 0, NULL);
 
497
 
 
498
            } else if (strncmp(argv[current_arg], "celsius\0", 8) == 0) {
 
499
                rc = ipmi_lcd_configure_wh (intf, 0xFF,0x02,0xFF, 0, NULL);
 
500
            } else if (strncmp(argv[current_arg], "fahrenheit", 11) == 0) {
 
501
                rc = ipmi_lcd_configure_wh (intf, 0xFF,0x03,0xFF, 0, NULL);
 
502
 
 
503
            }else if (strncmp(argv[current_arg], "help\0", 5) == 0) {
 
504
                ipmi_lcd_usage();
 
505
            }
 
506
            else {  
 
507
                ipmi_lcd_usage();
 
508
            }
 
509
        }
 
510
                else if( (strncmp(argv[current_arg], "errordisplay\0", 13) == 0)&&((iDRAC_FLAG==IDRAC_11G) || (iDRAC_FLAG==IDRAC_12G) )) 
 
511
        {
 
512
 
 
513
            current_arg++;
 
514
            if (argc <= current_arg)
 
515
            {
 
516
                ipmi_lcd_usage();
 
517
                return -1;
 
518
            }
 
519
            if (argv[current_arg] == NULL) 
 
520
            { 
 
521
                ipmi_lcd_usage();
 
522
                return -1;
 
523
            } 
 
524
 
 
525
            if (strncmp(argv[current_arg], "sel\0", 4) == 0) 
 
526
            {
 
527
                rc = ipmi_lcd_configure_wh (intf, 0xFF,0xFF,IPMI_DELL_LCD_ERROR_DISP_SEL , 0, NULL);
 
528
            }
 
529
            else if (strncmp(argv[current_arg], "simple\0", 7) == 0) 
 
530
            {
 
531
                rc = ipmi_lcd_configure_wh (intf, 0xFF,0xFF,IPMI_DELL_LCD_ERROR_DISP_VERBOSE , 0, NULL);
 
532
 
 
533
            }
 
534
            else if (strncmp(argv[current_arg], "help\0", 5) == 0) 
 
535
            {
 
536
                ipmi_lcd_usage();
 
537
            }
 
538
            else 
 
539
            {       
 
540
                ipmi_lcd_usage();
 
541
            }
 
542
        }
 
543
 
 
544
        else if ((strncmp(argv[current_arg], "none\0", 5) == 0)&&(iDRAC_FLAG==0)) 
 
545
        {
 
546
            rc = ipmi_lcd_configure (intf, IPMI_DELL_LCD_CONFIG_NONE, 0, NULL);
 
547
        }
 
548
        else if ((strncmp(argv[current_arg], "default\0", 8) == 0)&&(iDRAC_FLAG==0)) 
 
549
        {
 
550
            rc = ipmi_lcd_configure (intf, IPMI_DELL_LCD_CONFIG_DEFAULT, 0, NULL);
 
551
 
 
552
        } 
 
553
        else if ((strncmp(argv[current_arg], "custom\0", 7) == 0)&&(iDRAC_FLAG==0))  
 
554
        {
 
555
            current_arg++;
 
556
            if (argc <= current_arg) 
 
557
            {
 
558
                ipmi_lcd_usage();
 
559
                return -1;
 
560
            }
 
561
            rc = ipmi_lcd_configure (intf, IPMI_DELL_LCD_CONFIG_USER_DEFINED, line_number, argv[current_arg]);
 
562
        } 
 
563
 
 
564
        else if (strncmp(argv[current_arg], "vkvm\0", 5) == 0) 
 
565
        {
 
566
            current_arg++;
 
567
            if (argc <= current_arg) 
 
568
            {
 
569
                ipmi_lcd_usage();
 
570
                return -1;
 
571
            }
 
572
 
 
573
            if (strncmp(argv[current_arg], "active\0", 7) == 0) 
 
574
            {
 
575
                rc = ipmi_lcd_set_kvm (intf, 1);
 
576
            }
 
577
            else if (strncmp(argv[current_arg], "inactive\0", 9)==0)
 
578
            {
 
579
                rc = ipmi_lcd_set_kvm (intf, 0);
 
580
 
 
581
            }
 
582
            else if (strncmp(argv[current_arg], "help\0", 5) == 0) 
 
583
            {
 
584
                ipmi_lcd_usage();
 
585
            }
 
586
            else 
 
587
            {       
 
588
                ipmi_lcd_usage();
 
589
            }
 
590
 
 
591
        }
 
592
        else if (strncmp(argv[current_arg], "frontpanelaccess\0", 17) == 0) 
 
593
        {
 
594
            current_arg++;
 
595
            if (argc <= current_arg) 
 
596
            {
 
597
                ipmi_lcd_usage();
 
598
                return -1;
 
599
            }
 
600
            if (strncmp(argv[current_arg], "viewandmodify\0", 14) == 0) 
 
601
            {
 
602
                rc = ipmi_lcd_set_lock (intf, 0);
 
603
            }
 
604
            else if (strncmp(argv[current_arg], "viewonly\0", 9)==0)
 
605
            {
 
606
                rc =  ipmi_lcd_set_lock (intf, 1);
 
607
 
 
608
            }
 
609
            else if (strncmp(argv[current_arg], "disabled\0", 9)==0)
 
610
            {
 
611
                rc =  ipmi_lcd_set_lock (intf, 2);
 
612
 
 
613
            }
 
614
            else if (strncmp(argv[current_arg], "help\0", 5) == 0) 
 
615
            {
 
616
                ipmi_lcd_usage();
 
617
            }
 
618
            else 
 
619
            {       
 
620
                ipmi_lcd_usage();
 
621
            }
 
622
 
 
623
        }
 
624
        else if( (strncmp(argv[current_arg], "help\0", 5) == 0)&&(iDRAC_FLAG==0))  
 
625
        {
 
626
            ipmi_lcd_usage();
 
627
        }
 
628
        else 
 
629
        {
 
630
            ipmi_lcd_usage();
 
631
            return -1;
 
632
        }
 
633
    } 
 
634
    else 
 
635
    {
 
636
        ipmi_lcd_usage();
 
637
        return -1;
 
638
    }
 
639
    return rc;
 
640
}
 
641
 
 
642
 
 
643
 
 
644
/*****************************************************************
 
645
* Function Name:      ipmi_lcd_get_platform_model_name
 
646
*
 
647
* Description: This function retrieves the platform model name, or any other parameter 
 
648
*              which stores  data in the same format
 
649
* Input:       intf         - pointer to interface
 
650
*              max_length   - length of the platform model string
 
651
*              field_type   - either hostname / platform model
 
652
* Output:      lcdstring    - hostname / platform model string
 
653
*
 
654
* Return:            
 
655
*
 
656
******************************************************************/ 
 
657
static void
 
658
ipmi_lcd_get_platform_model_name (struct ipmi_intf * intf, 
 
659
                          char* lcdstring, 
 
660
                                  uint8_t max_length, 
 
661
                                  uint8_t field_type)
 
662
{
 
663
    struct ipmi_rs * rsp = NULL;
 
664
    struct ipmi_rq req = {0};
 
665
    uint8_t data[4];
 
666
    IPMI_DELL_LCD_STRING * lcdstringblock;
 
667
    int lcdstring_len = 0;
 
668
    int bytes_copied = 0;
 
669
 
 
670
    int ii;
 
671
 
 
672
    for (ii = 0; ii < 4; ii++)
 
673
    {
 
674
        int bytes_to_copy;
 
675
                memset (&req,0,sizeof(req));
 
676
        req.msg.netfn = IPMI_NETFN_APP;
 
677
        req.msg.lun = 0;
 
678
        req.msg.cmd = IPMI_GET_SYS_INFO;
 
679
        req.msg.data_len = 4;
 
680
        req.msg.data = data;
 
681
        data[0] = 0;                            /* get parameter*/
 
682
        data[1] = field_type;
 
683
        data[2] = ii;
 
684
        data[3] = 0;
 
685
 
 
686
 
 
687
        rsp = intf->sendrecv(intf, &req);
 
688
        if (rsp == NULL) {
 
689
            lprintf(LOG_ERR, " Error getting platform model name");
 
690
        } else if (rsp->ccode > 0) {
 
691
            lprintf(LOG_ERR, " Error getting platform model name: %s",
 
692
                val2str(rsp->ccode, completion_code_vals));
 
693
        }
 
694
 
 
695
        lcdstringblock = (IPMI_DELL_LCD_STRING *) (void *) rsp->data;
 
696
 
 
697
        /* first block is different - 14 bytes*/
 
698
        if (0 == ii) {
 
699
            lcdstring_len = lcdstringblock->lcd_string.selector_0_string.length;
 
700
 
 
701
            lcdstring_len = MIN (lcdstring_len,max_length);
 
702
 
 
703
            bytes_to_copy = MIN(lcdstring_len, IPMI_DELL_LCD_STRING1_SIZE);
 
704
            memcpy (lcdstring, lcdstringblock->lcd_string.selector_0_string.data, bytes_to_copy);
 
705
        } else {
 
706
            int string_offset;
 
707
 
 
708
            bytes_to_copy = MIN(lcdstring_len - bytes_copied, IPMI_DELL_LCD_STRINGN_SIZE);
 
709
            if (bytes_to_copy < 1)
 
710
                break;
 
711
            string_offset = IPMI_DELL_LCD_STRING1_SIZE + IPMI_DELL_LCD_STRINGN_SIZE * (ii-1);
 
712
            memcpy (lcdstring+string_offset, lcdstringblock->lcd_string.selector_n_data, bytes_to_copy);
 
713
        }
 
714
 
 
715
 
 
716
        bytes_copied += bytes_to_copy;
 
717
 
 
718
        if (bytes_copied >= lcdstring_len)
 
719
 
 
720
            break;
 
721
    }
 
722
 
 
723
}
 
724
 
 
725
/*****************************************************************
 
726
* Function Name:    ipmi_idracvalidator_command
 
727
*
 
728
* Description:      This function returns the iDRAC6 type
 
729
* Input:            intf            - ipmi interface
 
730
* Output:       
 
731
*
 
732
* Return:           iDRAC6 type     1 - whoville 
 
733
*                                   0 - others
 
734
*
 
735
******************************************************************/
 
736
 
 
737
static int
 
738
ipmi_idracvalidator_command (struct ipmi_intf * intf)
 
739
{
 
740
    struct ipmi_rs * rsp = NULL;
 
741
    struct ipmi_rq req = {0};
 
742
    uint8_t data[4];
 
743
 
 
744
    memset (&req,0,sizeof(req));
 
745
    req.msg.netfn = IPMI_NETFN_APP;
 
746
    req.msg.lun = 0;
 
747
    req.msg.cmd = IPMI_GET_SYS_INFO;
 
748
    req.msg.data_len = 4;
 
749
    req.msg.data = data;
 
750
    data[0] = 0;
 
751
    data[1] = IPMI_DELL_IDRAC_VALIDATOR;
 
752
    data[2] = 2;
 
753
    data[3] = 0;
 
754
 
 
755
    rsp = intf->sendrecv(intf, &req);
 
756
    if (rsp == NULL) {
 
757
        /*lprintf(LOG_ERR, " Error getting IMC type"); */
 
758
        return -1;
 
759
    } else if (rsp->ccode > 0) {
 
760
        /*lprintf(LOG_ERR, " Error getting IMC type: %s",
 
761
        val2str(rsp->ccode, completion_code_vals));  */
 
762
        return -1;
 
763
        }
 
764
        /* Support the 11G Monolithic, modular, Maisy and Coaster */
 
765
        if( (IMC_IDRAC_11G_MONOLITHIC == rsp->data[10]) || (IMC_IDRAC_11G_MODULAR ==rsp->data[10])  ||
 
766
                (IMC_MASER_LITE_BMC == rsp->data[10]) || (IMC_MASER_LITE_NU ==rsp->data[10])    )
 
767
    {
 
768
                iDRAC_FLAG=IDRAC_11G;
 
769
    }
 
770
        else if( (IMC_IDRAC_12G_MONOLITHIC == rsp->data[10]) || (IMC_IDRAC_12G_MODULAR==rsp->data[10]) )
 
771
    {
 
772
                iDRAC_FLAG=IDRAC_12G;
 
773
    }
 
774
    else
 
775
    {
 
776
        iDRAC_FLAG=0;
 
777
    }       
 
778
    IMC_Type = rsp->data[10];
 
779
    
 
780
    return 0;
 
781
}
 
782
 
 
783
/*****************************************************************
 
784
* Function Name:    ipmi_lcd_get_configure_command_wh
 
785
*
 
786
* Description:      This function returns current lcd configuration for Dell OEM LCD command
 
787
* Input:            intf            - ipmi interface
 
788
* Global:           lcd_mode - lcd mode setting
 
789
* Output:    
 
790
*
 
791
* Return:           returns the current lcd configuration
 
792
*                   0 = User defined
 
793
*                   1 = Default
 
794
*                   2 = None
 
795
*
 
796
******************************************************************/ 
 
797
static int
 
798
ipmi_lcd_get_configure_command_wh (struct ipmi_intf * intf)
 
799
{
 
800
    struct ipmi_rs * rsp = NULL;
 
801
    struct ipmi_rq req = {0};
 
802
    uint8_t data[4];
 
803
 
 
804
    req.msg.netfn = IPMI_NETFN_APP;
 
805
    req.msg.lun = 0;
 
806
    req.msg.cmd = IPMI_GET_SYS_INFO;
 
807
    req.msg.data_len = 4;
 
808
    req.msg.data = data;
 
809
    data[0] = 0;
 
810
    data[1] = IPMI_DELL_LCD_CONFIG_SELECTOR;
 
811
    data[2] = 0;
 
812
    data[3] = 0;
 
813
 
 
814
    rsp = intf->sendrecv(intf, &req);
 
815
    if (rsp == NULL) {
 
816
        lprintf(LOG_ERR, " Error getting LCD configuration");
 
817
        return -1;
 
818
    }else if ((rsp->ccode == 0xc1)||(rsp->ccode == 0xcb)){
 
819
 
 
820
        lprintf(LOG_ERR, " Error getting LCD configuration: Command not supported on this system."); 
 
821
 
 
822
    } else if (rsp->ccode > 0) {
 
823
        lprintf(LOG_ERR, " Error getting LCD configuration: %s",
 
824
            val2str(rsp->ccode, completion_code_vals));
 
825
        return -1;
 
826
    }
 
827
 
 
828
    lcd_mode= *((LCD_MODE*)(rsp->data));
 
829
    return 0;
 
830
}
 
831
 
 
832
 
 
833
/*****************************************************************
 
834
* Function Name:    ipmi_lcd_get_configure_command
 
835
*
 
836
* Description:   This function returns current lcd configuration for Dell OEM LCD command
 
837
* Input:         intf            - ipmi interface
 
838
* Output:        command         - user defined / default / none / ipv4 / mac address / 
 
839
                 system name / service tag / ipv6 / temp / system watt / asset tag
 
840
*
 
841
* Return:             
 
842
*
 
843
******************************************************************/
 
844
 
 
845
static int
 
846
ipmi_lcd_get_configure_command (struct ipmi_intf * intf,
 
847
                                uint8_t *command)
 
848
{
 
849
    struct ipmi_rs * rsp = NULL;
 
850
    struct ipmi_rq req = {0};
 
851
    uint8_t data[4];
 
852
 
 
853
    req.msg.netfn = IPMI_NETFN_APP;
 
854
    req.msg.lun = 0;
 
855
    req.msg.cmd = IPMI_GET_SYS_INFO;
 
856
    req.msg.data_len = 4;
 
857
    req.msg.data = data;
 
858
    data[0] = 0;
 
859
    data[1] = IPMI_DELL_LCD_CONFIG_SELECTOR;
 
860
    data[2] = 0;
 
861
    data[3] = 0;
 
862
 
 
863
    rsp = intf->sendrecv(intf, &req);
 
864
    if (rsp == NULL)
 
865
    {
 
866
        lprintf(LOG_ERR, " Error getting LCD configuration");
 
867
        return -1;
 
868
    }
 
869
    else if ((rsp->ccode == 0xc1)||(rsp->ccode == 0xcb))
 
870
    {
 
871
        lprintf(LOG_ERR, " Error getting LCD configuration: Command not supported on this system."); 
 
872
        return -1;
 
873
    }
 
874
    else if (rsp->ccode > 0) 
 
875
    {
 
876
        lprintf(LOG_ERR, " Error getting LCD configuration: %s",
 
877
            val2str(rsp->ccode, completion_code_vals));
 
878
        return -1;
 
879
    }
 
880
 
 
881
    /* rsp->data[0] is the rev */
 
882
    *command = rsp->data[1];
 
883
 
 
884
    return 0;
 
885
}
 
886
 
 
887
/*****************************************************************
 
888
* Function Name:    ipmi_lcd_set_configure_command
 
889
*
 
890
* Description:      This function updates current lcd configuration 
 
891
* Input:            intf            - ipmi interface
 
892
*                   command         - user defined / default / none / ipv4 / mac address / 
 
893
*                        system name / service tag / ipv6 / temp / system watt / asset tag
 
894
* Output:
 
895
* Return:             
 
896
*
 
897
******************************************************************/
 
898
 
 
899
static int
 
900
ipmi_lcd_set_configure_command (struct ipmi_intf * intf, int command)
 
901
{
 
902
#define LSCC_DATA_LEN 2
 
903
 
 
904
    struct ipmi_rs * rsp = NULL;
 
905
    struct ipmi_rq req = {0};
 
906
    uint8_t data[2];
 
907
 
 
908
    req.msg.netfn = IPMI_NETFN_APP;
 
909
    req.msg.lun = 0;
 
910
    req.msg.cmd = IPMI_SET_SYS_INFO;
 
911
    req.msg.data_len = 2;
 
912
    req.msg.data = data;
 
913
    data[0] = IPMI_DELL_LCD_CONFIG_SELECTOR;
 
914
    data[1] = command;                      /* command - custom, default, none */
 
915
 
 
916
    rsp = intf->sendrecv(intf, &req);
 
917
    if (rsp == NULL) 
 
918
    {
 
919
        lprintf(LOG_ERR, " Error setting LCD configuration");
 
920
        return -1;
 
921
    }
 
922
    else if ((rsp->ccode == 0xc1)||(rsp->ccode == 0xcb))
 
923
    {
 
924
        lprintf(LOG_ERR, " Error setting LCD configuration: Command not supported on this system."); 
 
925
 
 
926
    }
 
927
    else if (rsp->ccode > 0) 
 
928
    {
 
929
        lprintf(LOG_ERR, " Error setting LCD configuration: %s",
 
930
            val2str(rsp->ccode, completion_code_vals));
 
931
 
 
932
        return -1;
 
933
    }
 
934
 
 
935
    return 0;
 
936
}
 
937
 
 
938
 
 
939
/*****************************************************************
 
940
* Function Name:    ipmi_lcd_set_configure_command
 
941
*
 
942
* Description:      This function updates current lcd configuration 
 
943
* Input:            intf            - ipmi interface
 
944
*                   mode            - user defined / default / none 
 
945
*                   lcdquallifier   - lcd quallifier id
 
946
*                   errordisp       - error number
 
947
* Output:
 
948
* Return:                
 
949
*
 
950
******************************************************************/ 
 
951
static int
 
952
ipmi_lcd_set_configure_command_wh (struct ipmi_intf * intf, 
 
953
                                   uint32_t  mode,
 
954
                                   uint16_t lcdquallifier,
 
955
                                   uint8_t errordisp)
 
956
{
 
957
#define LSCC_DATA_LEN 2
 
958
 
 
959
    struct ipmi_rs * rsp = NULL;
 
960
    struct ipmi_rq req = {0};
 
961
    uint8_t data[13];
 
962
 
 
963
    ipmi_lcd_get_configure_command_wh(intf);
 
964
    req.msg.netfn = IPMI_NETFN_APP;
 
965
    req.msg.lun = 0;
 
966
    req.msg.cmd = IPMI_SET_SYS_INFO;
 
967
    req.msg.data_len = 13;
 
968
    req.msg.data = data;
 
969
    data[0] = IPMI_DELL_LCD_CONFIG_SELECTOR;
 
970
 
 
971
    if(mode!=0xFF)
 
972
    {
 
973
 
 
974
        data[1] = mode&0xFF;                    /* command - custom, default, none*/
 
975
        data[2]=(mode&0xFF00)>>8;
 
976
        data[3]=(mode&0xFF0000)>>16;
 
977
        data[4]=(mode&0xFF000000)>>24;
 
978
    }
 
979
    else
 
980
    {
 
981
        data[1] = (lcd_mode.lcdmode)&0xFF;                      /* command - custom, default, none*/
 
982
        data[2]=((lcd_mode.lcdmode)&0xFF00)>>8;
 
983
        data[3]=((lcd_mode.lcdmode)&0xFF0000)>>16;
 
984
        data[4]=((lcd_mode.lcdmode)&0xFF000000)>>24;
 
985
    }
 
986
 
 
987
    if(lcdquallifier!=0xFF)
 
988
    {
 
989
        if(lcdquallifier==0x01)
 
990
        {
 
991
            data[5] =(lcd_mode.lcdquallifier)|0x01;                 /* command - custom, default, none*/
 
992
 
 
993
        }
 
994
        else  if(lcdquallifier==0x00)
 
995
        {
 
996
            data[5] =(lcd_mode.lcdquallifier)&0xFE;                 /* command - custom, default, none*/
 
997
        }
 
998
        else if (lcdquallifier==0x03)
 
999
        {
 
1000
            data[5] =(lcd_mode.lcdquallifier)|0x02;                 /* command - custom, default, none*/
 
1001
        }
 
1002
        else if (lcdquallifier==0x02)
 
1003
        {
 
1004
            data[5] =(lcd_mode.lcdquallifier)&0xFD; 
 
1005
        }
 
1006
    }
 
1007
    else
 
1008
    {
 
1009
        data[5]=lcd_mode.lcdquallifier;
 
1010
    }   
 
1011
    if(errordisp!=0xFF)
 
1012
    {
 
1013
        data[11]=errordisp;
 
1014
    }
 
1015
    else
 
1016
    {
 
1017
        data[11]=lcd_mode.error_display;
 
1018
    }
 
1019
    rsp = intf->sendrecv(intf, &req);
 
1020
    if (rsp == NULL) 
 
1021
    {
 
1022
        lprintf(LOG_ERR, " Error setting LCD configuration");
 
1023
        return -1;
 
1024
    }
 
1025
    else if ((rsp->ccode == 0xc1)||(rsp->ccode == 0xcb))
 
1026
    {
 
1027
        lprintf(LOG_ERR, " Error setting LCD configuration: Command not supported on this system."); 
 
1028
    }
 
1029
    else if (rsp->ccode > 0) 
 
1030
    {
 
1031
        lprintf(LOG_ERR, " Error setting LCD configuration: %s",
 
1032
            val2str(rsp->ccode, completion_code_vals));
 
1033
 
 
1034
        return -1;
 
1035
    }
 
1036
 
 
1037
    return 0;
 
1038
}
 
1039
 
 
1040
 
 
1041
 
 
1042
/*****************************************************************
 
1043
* Function Name:    ipmi_lcd_get_single_line_text
 
1044
*
 
1045
* Description:    This function updates current lcd configuration 
 
1046
* Input:          intf            - ipmi interface
 
1047
*                 lcdstring       - new string to be updated 
 
1048
*                 max_length      - length of the string
 
1049
* Output:
 
1050
* Return:              
 
1051
*
 
1052
******************************************************************/
 
1053
 
 
1054
static int
 
1055
ipmi_lcd_get_single_line_text (struct ipmi_intf * intf, char* lcdstring, uint8_t max_length)
 
1056
{
 
1057
    struct ipmi_rs * rsp = NULL;
 
1058
    struct ipmi_rq req = {0};
 
1059
    uint8_t data[4];
 
1060
    IPMI_DELL_LCD_STRING * lcdstringblock;
 
1061
    int lcdstring_len = 0;
 
1062
    int bytes_copied = 0;
 
1063
    int ii;
 
1064
 
 
1065
    for (ii = 0; ii < 4; ii++) {
 
1066
        int bytes_to_copy;
 
1067
 
 
1068
        req.msg.netfn = IPMI_NETFN_APP;
 
1069
        req.msg.lun = 0;
 
1070
        req.msg.cmd = IPMI_GET_SYS_INFO;
 
1071
        req.msg.data_len = 4;
 
1072
        req.msg.data = data;
 
1073
        data[0] = 0;                            /* get parameter*/
 
1074
        data[1] = IPMI_DELL_LCD_STRING_SELECTOR;
 
1075
        data[2] = ii;                           /* block selector*/
 
1076
        data[3] = 00;                           /* set selector (n/a)*/
 
1077
 
 
1078
        rsp = intf->sendrecv(intf, &req);
 
1079
        if (rsp == NULL) {
 
1080
            lprintf(LOG_ERR, " Error getting text data");
 
1081
            return -1;
 
1082
        } else if (rsp->ccode > 0) {
 
1083
            lprintf(LOG_ERR, " Error getting text data: %s",
 
1084
                val2str(rsp->ccode, completion_code_vals));
 
1085
            return -1;
 
1086
        }
 
1087
 
 
1088
        lcdstringblock = (IPMI_DELL_LCD_STRING *) (void *) rsp->data;
 
1089
 
 
1090
        /* first block is different - 14 bytes*/
 
1091
        if (0 == ii)
 
1092
        {
 
1093
            lcdstring_len = lcdstringblock->lcd_string.selector_0_string.length;
 
1094
 
 
1095
            if (lcdstring_len < 1 || lcdstring_len > max_length)
 
1096
                break;
 
1097
 
 
1098
            bytes_to_copy = MIN(lcdstring_len, IPMI_DELL_LCD_STRING1_SIZE);
 
1099
            memcpy (lcdstring, lcdstringblock->lcd_string.selector_0_string.data, bytes_to_copy);
 
1100
        }
 
1101
        else
 
1102
        {
 
1103
            int string_offset;
 
1104
 
 
1105
            bytes_to_copy = MIN(lcdstring_len - bytes_copied, IPMI_DELL_LCD_STRINGN_SIZE);
 
1106
            if (bytes_to_copy < 1)
 
1107
                break;
 
1108
            string_offset = IPMI_DELL_LCD_STRING1_SIZE + IPMI_DELL_LCD_STRINGN_SIZE * (ii-1);
 
1109
            memcpy (lcdstring+string_offset, lcdstringblock->lcd_string.selector_n_data, bytes_to_copy);
 
1110
        }
 
1111
 
 
1112
        bytes_copied += bytes_to_copy;
 
1113
        if (bytes_copied >= lcdstring_len)
 
1114
            break;
 
1115
    }
 
1116
    return 0;
 
1117
}
 
1118
 
 
1119
/*****************************************************************
 
1120
* Function Name:    ipmi_lcd_get_info_wh
 
1121
*
 
1122
* Description:     This function prints current lcd configuration for whoville platform
 
1123
* Input:           intf            - ipmi interface
 
1124
* Output:
 
1125
* Return:              
 
1126
*
 
1127
******************************************************************/
 
1128
 
 
1129
static int
 
1130
ipmi_lcd_get_info_wh(struct ipmi_intf * intf)
 
1131
 
 
1132
{
 
1133
    struct ipmi_rs * rsp = NULL;
 
1134
    struct ipmi_rq req = {0};
 
1135
    uint8_t data[4];
 
1136
    IPMI_DELL_LCD_CAPS* lcd_caps;
 
1137
    char lcdstring[IPMI_DELL_LCD_STRING_LENGTH_MAX+1] = {0};
 
1138
    int rc;
 
1139
 
 
1140
 
 
1141
    printf("LCD info\n");
 
1142
 
 
1143
    if (ipmi_lcd_get_configure_command_wh (intf) != 0) 
 
1144
    {
 
1145
        return -1;
 
1146
    }
 
1147
    else 
 
1148
    {
 
1149
        if (lcd_mode.lcdmode== IPMI_DELL_LCD_CONFIG_DEFAULT) 
 
1150
        {
 
1151
            char text[IPMI_DELL_LCD_STRING_LENGTH_MAX+1] = {0};
 
1152
 
 
1153
            ipmi_lcd_get_platform_model_name(intf, text, 
 
1154
                IPMI_DELL_LCD_STRING_LENGTH_MAX,
 
1155
                IPMI_DELL_PLATFORM_MODEL_NAME_SELECTOR);
 
1156
 
 
1157
            if (text == NULL)
 
1158
                return -1;
 
1159
            printf("    Setting:Model name\n");
 
1160
            printf("    Line 1:  %s\n", text);
 
1161
        }
 
1162
        else if (lcd_mode.lcdmode == IPMI_DELL_LCD_CONFIG_NONE) 
 
1163
        {
 
1164
            printf("    Setting:   none\n");
 
1165
        }
 
1166
        else if (lcd_mode.lcdmode == IPMI_DELL_LCD_CONFIG_USER_DEFINED) 
 
1167
        {
 
1168
            req.msg.netfn = IPMI_NETFN_APP;
 
1169
            req.msg.lun = 0;
 
1170
            req.msg.cmd = IPMI_GET_SYS_INFO;
 
1171
            req.msg.data_len = 4;
 
1172
            req.msg.data = data;
 
1173
            data[0] = 0;                            /* get parameter*/
 
1174
            data[1] = IPMI_DELL_LCD_GET_CAPS_SELECTOR;
 
1175
            data[2] = 0;                            /* set selector (n/a)*/
 
1176
            data[3] = 0;                            /* block selector (n/a)*/
 
1177
 
 
1178
            printf("    Setting: User defined\n");
 
1179
 
 
1180
            rsp = intf->sendrecv(intf, &req);
 
1181
            if (rsp == NULL)
 
1182
            {
 
1183
                lprintf(LOG_ERR, " Error getting LCD capabilities.");
 
1184
                return -1;
 
1185
            }
 
1186
            else if ((rsp->ccode == 0xc1)||(rsp->ccode == 0xcb))
 
1187
            {
 
1188
                lprintf(LOG_ERR, " Error getting LCD capabilities: Command not supported on this system.");
 
1189
            }
 
1190
            else if (rsp->ccode > 0) 
 
1191
            {
 
1192
                lprintf(LOG_ERR, " Error getting LCD capabilities: %s",
 
1193
                    val2str(rsp->ccode, completion_code_vals));
 
1194
                return -1;
 
1195
            }
 
1196
 
 
1197
            lcd_caps = (IPMI_DELL_LCD_CAPS *)rsp->data;
 
1198
            if (lcd_caps->number_lines > 0) 
 
1199
            {
 
1200
                memset(lcdstring, 0, IPMI_DELL_LCD_STRING_LENGTH_MAX+1);
 
1201
 
 
1202
                rc = ipmi_lcd_get_single_line_text (intf, lcdstring, lcd_caps->max_chars[0]);
 
1203
                printf("    Text:    %s\n", lcdstring);
 
1204
            }
 
1205
            else 
 
1206
            {
 
1207
                printf("    No lines to show\n");
 
1208
            }
 
1209
        }
 
1210
        else if (lcd_mode.lcdmode == IPMI_DELL_LCD_iDRAC_IPV4ADRESS) 
 
1211
        {
 
1212
            printf("    Setting:   IPV4 Address\n");
 
1213
        }
 
1214
        else if (lcd_mode.lcdmode == IPMI_DELL_LCD_IDRAC_MAC_ADDRESS) 
 
1215
        {
 
1216
            printf("    Setting:   MAC Address\n");
 
1217
        }
 
1218
        else if (lcd_mode.lcdmode == IPMI_DELL_LCD_OS_SYSTEM_NAME) 
 
1219
        {
 
1220
            printf("    Setting:   OS System Name\n");
 
1221
        }
 
1222
        else if (lcd_mode.lcdmode == IPMI_DELL_LCD_SERVICE_TAG) 
 
1223
        {
 
1224
            printf("    Setting:   System Tag\n");
 
1225
        }
 
1226
        else if (lcd_mode.lcdmode == IPMI_DELL_LCD_iDRAC_IPV6ADRESS) 
 
1227
        {
 
1228
            printf("    Setting:  IPV6 Address\n");
 
1229
        }
 
1230
        else if (lcd_mode.lcdmode == IPMI_DELL_LCD_ASSET_TAG) 
 
1231
                {
 
1232
                        printf("    Setting:  Asset Tag\n");
 
1233
                }
 
1234
        else if (lcd_mode.lcdmode == IPMI_DELL_LCD_AMBEINT_TEMP) 
 
1235
        {
 
1236
            printf("    Setting:  Ambient Temp\n");
 
1237
            if(lcd_mode.lcdquallifier&0x02)
 
1238
                printf("    Unit:  F\n");  
 
1239
            else
 
1240
                printf("    Unit:  C\n");  
 
1241
        }
 
1242
        else if (lcd_mode.lcdmode == IPMI_DELL_LCD_SYSTEM_WATTS)
 
1243
        {
 
1244
            printf("    Setting:  System Watts\n");
 
1245
 
 
1246
            if(lcd_mode.lcdquallifier&0x01)
 
1247
                printf("    Unit:  BTU/hr\n");  
 
1248
            else
 
1249
                printf("    Unit:  Watt\n"); 
 
1250
 
 
1251
        }
 
1252
        if(lcd_mode.error_display==IPMI_DELL_LCD_ERROR_DISP_SEL)
 
1253
            printf("    Error Display:  SEL\n");
 
1254
        else if(lcd_mode.error_display==IPMI_DELL_LCD_ERROR_DISP_VERBOSE)
 
1255
            printf("    Error Display:  Simple\n");
 
1256
    }
 
1257
 
 
1258
    return 0;
 
1259
}
 
1260
 
 
1261
/*****************************************************************
 
1262
* Function Name:    ipmi_lcd_get_info
 
1263
*
 
1264
* Description:      This function prints current lcd configuration for platform other than whoville
 
1265
* Input:            intf            - ipmi interface
 
1266
* Output:
 
1267
* Return:              
 
1268
*
 
1269
******************************************************************/
 
1270
static int ipmi_lcd_get_info(struct ipmi_intf * intf)
 
1271
{
 
1272
    struct ipmi_rs * rsp = NULL;
 
1273
    struct ipmi_rq req = {0};
 
1274
    uint8_t data[4];
 
1275
    IPMI_DELL_LCD_CAPS * lcd_caps;
 
1276
    uint8_t command = 0;
 
1277
    char lcdstring[IPMI_DELL_LCD_STRING_LENGTH_MAX+1] = {0};
 
1278
    int rc; 
 
1279
 
 
1280
    printf("LCD info\n");
 
1281
 
 
1282
    if (ipmi_lcd_get_configure_command (intf, &command) != 0)
 
1283
    {
 
1284
        return -1;
 
1285
    }
 
1286
    else
 
1287
    {
 
1288
        if (command == IPMI_DELL_LCD_CONFIG_DEFAULT)
 
1289
        {
 
1290
            memset (lcdstring,0,IPMI_DELL_LCD_STRING_LENGTH_MAX+1);
 
1291
 
 
1292
            ipmi_lcd_get_platform_model_name(intf, lcdstring, IPMI_DELL_LCD_STRING_LENGTH_MAX,
 
1293
                IPMI_DELL_PLATFORM_MODEL_NAME_SELECTOR);
 
1294
 
 
1295
            printf("    Setting: default\n");
 
1296
            printf("    Line 1:  %s\n", lcdstring);
 
1297
        }
 
1298
        else if (command == IPMI_DELL_LCD_CONFIG_NONE)
 
1299
        {
 
1300
            printf("    Setting:   none\n");
 
1301
        }
 
1302
        else if (command == IPMI_DELL_LCD_CONFIG_USER_DEFINED)
 
1303
        {
 
1304
            req.msg.netfn = IPMI_NETFN_APP;
 
1305
            req.msg.lun = 0;
 
1306
            req.msg.cmd = IPMI_GET_SYS_INFO;
 
1307
            req.msg.data_len = 4;
 
1308
            req.msg.data = data;
 
1309
            data[0] = 0;                            /* get parameter */
 
1310
            data[1] = IPMI_DELL_LCD_GET_CAPS_SELECTOR;
 
1311
            data[2] = 0;                            /* set selector (n/a) */
 
1312
            data[3] = 0;                            /* block selector (n/a) */
 
1313
 
 
1314
            printf("    Setting: custom\n");
 
1315
 
 
1316
            rsp = intf->sendrecv(intf, &req);
 
1317
            if (rsp == NULL)
 
1318
            {
 
1319
                lprintf(LOG_ERR, " Error getting LCD capabilities.");
 
1320
                return -1;
 
1321
            }
 
1322
            else if ((rsp->ccode == 0xc1)||(rsp->ccode == 0xcb))
 
1323
            {
 
1324
                lprintf(LOG_ERR, " Error getting LCD capabilities: Command not supported on this system.");
 
1325
            }
 
1326
            else if (rsp->ccode > 0)
 
1327
            {
 
1328
                lprintf(LOG_ERR, " Error getting LCD capabilities: %s",
 
1329
                    val2str(rsp->ccode, completion_code_vals));
 
1330
                return -1;
 
1331
            }
 
1332
 
 
1333
            lcd_caps = (IPMI_DELL_LCD_CAPS *)(void *)rsp->data;
 
1334
            if (lcd_caps->number_lines > 0)
 
1335
            {
 
1336
                memset (lcdstring,0,IPMI_DELL_LCD_STRING_LENGTH_MAX+1);
 
1337
                rc = ipmi_lcd_get_single_line_text (intf, lcdstring, lcd_caps->max_chars[0]);
 
1338
                printf("    Text:    %s\n", lcdstring);
 
1339
            }
 
1340
            else
 
1341
            {
 
1342
                printf("    No lines to show\n");
 
1343
            }
 
1344
        }
 
1345
    }
 
1346
 
 
1347
    return 0;
 
1348
}
 
1349
 
 
1350
/*****************************************************************
 
1351
* Function Name:    ipmi_lcd_get_status_val
 
1352
*
 
1353
* Description:      This function gets current lcd configuration 
 
1354
* Input:            intf            - ipmi interface
 
1355
* Output:           lcdstatus       - KVM Status & Lock Status
 
1356
* Return:           
 
1357
*
 
1358
******************************************************************/
 
1359
 
 
1360
static int
 
1361
ipmi_lcd_get_status_val(struct ipmi_intf * intf, LCD_STATUS* lcdstatus)
 
1362
{
 
1363
    struct ipmi_rs * rsp = NULL;
 
1364
    struct ipmi_rq req = {0};
 
1365
    uint8_t data[4];
 
1366
 
 
1367
 
 
1368
    req.msg.netfn = IPMI_NETFN_APP;
 
1369
    req.msg.lun = 0;
 
1370
    req.msg.cmd = IPMI_GET_SYS_INFO;
 
1371
    req.msg.data_len = 4;
 
1372
    req.msg.data = data;
 
1373
    data[0] = 0;                            /* get parameter */
 
1374
    data[1] = IPMI_DELL_LCD_STATUS_SELECTOR;
 
1375
    data[2] = 0;                            /* block selector */
 
1376
    data[3] = 0;            
 
1377
    /* set selector (n/a) */
 
1378
    rsp = intf->sendrecv(intf, &req);
 
1379
    if (rsp == NULL) 
 
1380
    {
 
1381
        lprintf(LOG_ERR, " Error getting LCD Status");
 
1382
        return -1;
 
1383
    }
 
1384
    else if ((rsp->ccode == 0xc1)||(rsp->ccode == 0xcb)) 
 
1385
    {
 
1386
        lprintf(LOG_ERR, " Error getting LCD status: Command not supported on this system.");
 
1387
        return -1;
 
1388
    }
 
1389
    else if (rsp->ccode > 0) 
 
1390
    {
 
1391
        lprintf(LOG_ERR, " Error getting LCD Status: %s",
 
1392
            val2str(rsp->ccode, completion_code_vals));
 
1393
        return -1;
 
1394
    }
 
1395
 
 
1396
    /*lcdstatus= (LCD_STATUS* ) rsp->data; */
 
1397
 
 
1398
    lcdstatus->vKVM_status=rsp->data[1];
 
1399
    lcdstatus->lock_status=rsp->data[2];
 
1400
 
 
1401
    return 0;
 
1402
}
 
1403
 
 
1404
 
 
1405
/*****************************************************************
 
1406
* Function Name:    IsLCDSupported
 
1407
*
 
1408
* Description:   This function returns whether lcd supported or not
 
1409
* Input:              
 
1410
* Output:       
 
1411
* Return:               
 
1412
*
 
1413
******************************************************************/
 
1414
static int IsLCDSupported ()
 
1415
{
 
1416
    return LcdSupported;
 
1417
}
 
1418
 
 
1419
/*****************************************************************
 
1420
* Function Name:         CheckLCDSupport
 
1421
*
 
1422
* Description:  This function checks whether lcd supported or not
 
1423
* Input:        intf            - ipmi interface
 
1424
* Output:       
 
1425
* Return:               
 
1426
*
 
1427
******************************************************************/
 
1428
static void CheckLCDSupport(struct ipmi_intf * intf)
 
1429
{
 
1430
    struct ipmi_rs * rsp = NULL;
 
1431
    struct ipmi_rq req = {0};
 
1432
    uint8_t data[4];
 
1433
 
 
1434
    LcdSupported = 0;
 
1435
 
 
1436
    req.msg.netfn = IPMI_NETFN_APP;
 
1437
    req.msg.lun = 0;
 
1438
    req.msg.cmd = IPMI_GET_SYS_INFO;
 
1439
    req.msg.data_len = 4;
 
1440
    req.msg.data = data;
 
1441
    data[0] = 0;                            /* get parameter */
 
1442
    data[1] = IPMI_DELL_LCD_STATUS_SELECTOR;
 
1443
    data[2] = 0;                            /* block selector */
 
1444
    data[3] = 0;            
 
1445
    rsp = intf->sendrecv(intf, &req);
 
1446
    if (rsp == NULL) 
 
1447
    {
 
1448
        return;
 
1449
    }
 
1450
    else if ((rsp->ccode == 0xc1)||(rsp->ccode == 0xcb)) 
 
1451
    {
 
1452
        return;
 
1453
    }
 
1454
    else if (rsp->ccode > 0) 
 
1455
    {
 
1456
        return;
 
1457
    }
 
1458
    LcdSupported = 1;       
 
1459
 
 
1460
}
 
1461
 
 
1462
/*****************************************************************
 
1463
* Function Name:     ipmi_lcd_status_print
 
1464
*
 
1465
* Description:    This function prints current lcd configuration KVM Status & Lock Status
 
1466
* Input:          lcdstatus - KVM Status & Lock Status
 
1467
* Output:   
 
1468
* Return:               
 
1469
*
 
1470
******************************************************************/
 
1471
 
 
1472
static void ipmi_lcd_status_print( LCD_STATUS lcdstatus)
 
1473
{
 
1474
    switch (lcdstatus.vKVM_status)
 
1475
    {
 
1476
    case 0x00: 
 
1477
        printf("LCD KVM Status :Inactive\n");
 
1478
        break;
 
1479
    case 0x01: 
 
1480
        printf("LCD KVM Status :Active\n");
 
1481
        break;
 
1482
    default:
 
1483
        printf("LCD KVM Status :Invalid Status\n");
 
1484
 
 
1485
        break;
 
1486
    }                       
 
1487
 
 
1488
    switch (lcdstatus.lock_status)
 
1489
    {
 
1490
    case 0x00: 
 
1491
        printf("LCD lock Status :View and modify\n");
 
1492
        break;
 
1493
    case 0x01: 
 
1494
        printf("LCD lock Status :View only\n");
 
1495
        break;
 
1496
    case 0x02:
 
1497
        printf("LCD lock Status :disabled\n");
 
1498
        break;
 
1499
    default:
 
1500
        printf("LCD lock Status :Invalid\n");
 
1501
        break;
 
1502
    }
 
1503
 
 
1504
}
 
1505
 
 
1506
/*****************************************************************
 
1507
* Function Name:     ipmi_lcd_get_status
 
1508
*
 
1509
* Description:      This function gets current lcd KVM active status & lcd access mode
 
1510
* Input:            intf            - ipmi interface
 
1511
* Output:       
 
1512
* Return:           -1 on error
 
1513
*                   0 if successful
 
1514
*
 
1515
******************************************************************/
 
1516
static int
 
1517
ipmi_lcd_get_status(struct ipmi_intf * intf )
 
1518
{
 
1519
    int rc=0;
 
1520
    LCD_STATUS  lcdstatus;
 
1521
 
 
1522
    rc =ipmi_lcd_get_status_val( intf, &lcdstatus);
 
1523
    if (rc <0)
 
1524
        return -1;
 
1525
    ipmi_lcd_status_print(lcdstatus);
 
1526
 
 
1527
    return rc;
 
1528
 
 
1529
}
 
1530
 
 
1531
/*****************************************************************
 
1532
* Function Name:     ipmi_lcd_set_kvm
 
1533
*
 
1534
* Description:       This function sets lcd KVM active status 
 
1535
* Input:             intf            - ipmi interface
 
1536
*                    status  - Inactive / Active
 
1537
* Output:    
 
1538
* Return:            -1 on error
 
1539
*                    0 if successful
 
1540
*
 
1541
******************************************************************/ 
 
1542
static int
 
1543
ipmi_lcd_set_kvm(struct ipmi_intf * intf, char status)
 
1544
{
 
1545
#define LSCC_DATA_LEN 2
 
1546
    LCD_STATUS lcdstatus;
 
1547
    int rc=0;
 
1548
    struct ipmi_rs * rsp = NULL;
 
1549
    struct ipmi_rq req = {0};
 
1550
    uint8_t data[5];
 
1551
    rc=ipmi_lcd_get_status_val(intf,&lcdstatus);
 
1552
    if (rc < 0)
 
1553
        return -1;
 
1554
    req.msg.netfn = IPMI_NETFN_APP;
 
1555
    req.msg.lun = 0;
 
1556
    req.msg.cmd = IPMI_SET_SYS_INFO;
 
1557
    req.msg.data_len = 5;
 
1558
    req.msg.data = data;
 
1559
    data[0] = IPMI_DELL_LCD_STATUS_SELECTOR;
 
1560
    data[1] = status;                       /* active- incative*/
 
1561
    data[2] = lcdstatus.lock_status;        /* full-veiw-locked */
 
1562
    rsp = intf->sendrecv(intf, &req);
 
1563
    if (rsp == NULL) {
 
1564
        lprintf(LOG_ERR, " Error setting LCD status");
 
1565
        rc= -1;
 
1566
    }else if ((rsp->ccode == 0xc1)||(rsp->ccode == 0xcb)) {
 
1567
        lprintf(LOG_ERR, " Error getting LCD status: Command not supported on this system.");
 
1568
        return -1;
 
1569
    } else if (rsp->ccode > 0) {
 
1570
        lprintf(LOG_ERR, " Error setting LCD status: %s",
 
1571
            val2str(rsp->ccode, completion_code_vals));
 
1572
 
 
1573
        rc= -1;
 
1574
    }
 
1575
 
 
1576
    return rc;
 
1577
}
 
1578
 
 
1579
/*****************************************************************
 
1580
* Function Name:   ipmi_lcd_set_lock
 
1581
*
 
1582
* Description:     This function sets lcd access mode 
 
1583
* Input:           intf            - ipmi interface
 
1584
*                  lock    - View and modify / View only / Diabled
 
1585
* Output:        
 
1586
* Return:          -1 on error
 
1587
*                  0 if successful
 
1588
*
 
1589
******************************************************************/ 
 
1590
static int
 
1591
ipmi_lcd_set_lock(struct ipmi_intf * intf,  char lock)
 
1592
{
 
1593
#define LSCC_DATA_LEN 2
 
1594
    LCD_STATUS lcdstatus;
 
1595
    int rc =0;
 
1596
    struct ipmi_rs * rsp = NULL;
 
1597
    struct ipmi_rq req = {0};
 
1598
    uint8_t data[5];
 
1599
    rc=ipmi_lcd_get_status_val(intf,&lcdstatus);
 
1600
    if (rc < 0)
 
1601
        return -1;
 
1602
    req.msg.netfn = IPMI_NETFN_APP;
 
1603
    req.msg.lun = 0;
 
1604
    req.msg.cmd = IPMI_SET_SYS_INFO;
 
1605
    req.msg.data_len = 5;
 
1606
    req.msg.data = data;
 
1607
    data[0] = IPMI_DELL_LCD_STATUS_SELECTOR;
 
1608
    data[1] = lcdstatus.vKVM_status;                        /* active- incative */
 
1609
    data[2] = lock;                 /* full- veiw-locked */
 
1610
    rsp = intf->sendrecv(intf, &req);
 
1611
    if (rsp == NULL)
 
1612
    {
 
1613
        lprintf(LOG_ERR, " Error setting LCD status");
 
1614
        rc= -1;
 
1615
    }
 
1616
    if ((rsp->ccode == 0xc1)||(rsp->ccode == 0xcb)) 
 
1617
    {
 
1618
        lprintf(LOG_ERR, " Error getting LCD status: Command not supported on this system.");
 
1619
        return -1;
 
1620
    }
 
1621
    else if (rsp->ccode > 0) 
 
1622
    {
 
1623
        lprintf(LOG_ERR, " Error setting LCD status: %s",
 
1624
            val2str(rsp->ccode, completion_code_vals));
 
1625
 
 
1626
        rc= -1;
 
1627
    }
 
1628
 
 
1629
    return rc;
 
1630
}
 
1631
 
 
1632
/*****************************************************************
 
1633
* Function Name:   ipmi_lcd_set_single_line_text
 
1634
*
 
1635
* Description:    This function sets lcd line text
 
1636
* Input:          intf            - ipmi interface
 
1637
*                 text    - lcd string
 
1638
* Output:   
 
1639
* Return:         -1 on error
 
1640
*                 0 if successful
 
1641
*
 
1642
******************************************************************/
 
1643
 
 
1644
static int 
 
1645
ipmi_lcd_set_single_line_text (struct ipmi_intf * intf, char * text)
 
1646
{
 
1647
    struct ipmi_rs * rsp = NULL;
 
1648
    struct ipmi_rq req = {0};
 
1649
    uint8_t data[18];
 
1650
    int bytes_to_store = strlen(text);
 
1651
    int bytes_stored = 0;
 
1652
    int ii;
 
1653
    int rc = 0;
 
1654
    if (bytes_to_store>IPMI_DELL_LCD_STRING_LENGTH_MAX)
 
1655
    {
 
1656
        lprintf(LOG_ERR, " Out of range Max limit is 62 characters");
 
1657
        return 1;
 
1658
 
 
1659
    }
 
1660
    else
 
1661
    {
 
1662
        bytes_to_store = MIN(bytes_to_store, IPMI_DELL_LCD_STRING_LENGTH_MAX);
 
1663
        for (ii = 0; ii < 4; ii++) {
 
1664
            /*first block, 2 bytes parms and 14 bytes data*/
 
1665
            if (0 == ii) {
 
1666
                int size_of_copy =  
 
1667
                    MIN((bytes_to_store - bytes_stored), IPMI_DELL_LCD_STRING1_SIZE);
 
1668
                if (size_of_copy < 0)           /* allow 0 string length*/
 
1669
                    break;
 
1670
                req.msg.netfn = IPMI_NETFN_APP;
 
1671
                req.msg.lun = 0;
 
1672
                req.msg.cmd = IPMI_SET_SYS_INFO;
 
1673
                req.msg.data_len = size_of_copy + 4; /* chars, selectors and sizes*/
 
1674
                req.msg.data = data;
 
1675
                data[0] = IPMI_DELL_LCD_STRING_SELECTOR;
 
1676
                data[1] = ii;                           /* block number to use (0)*/
 
1677
                data[2] = 0;                            /*string encoding*/
 
1678
                data[3] = bytes_to_store;       /* total string length*/
 
1679
                memcpy (data+4, text+bytes_stored, size_of_copy);
 
1680
                bytes_stored += size_of_copy;
 
1681
            } else {
 
1682
                int size_of_copy =  
 
1683
                    MIN((bytes_to_store - bytes_stored), IPMI_DELL_LCD_STRINGN_SIZE);
 
1684
                if (size_of_copy <= 0)
 
1685
                    break;
 
1686
                req.msg.netfn = IPMI_NETFN_APP;
 
1687
                req.msg.lun = 0;
 
1688
                req.msg.cmd = IPMI_SET_SYS_INFO;
 
1689
                req.msg.data_len = size_of_copy + 2;
 
1690
                req.msg.data = data;
 
1691
                data[0] = IPMI_DELL_LCD_STRING_SELECTOR;
 
1692
                data[1] = ii;                           /* block number to use (1,2,3)*/
 
1693
                memcpy (data+2, text+bytes_stored, size_of_copy);
 
1694
                bytes_stored += size_of_copy;
 
1695
            }
 
1696
 
 
1697
            rsp = intf->sendrecv(intf, &req);
 
1698
            if (rsp == NULL) {
 
1699
                lprintf(LOG_ERR, " Error setting text data");
 
1700
                rc = -1;
 
1701
            } else if (rsp->ccode > 0) {
 
1702
                lprintf(LOG_ERR, " Error setting text data: %s",
 
1703
                    val2str(rsp->ccode, completion_code_vals));
 
1704
                rc = -1;
 
1705
            }
 
1706
        }
 
1707
    }
 
1708
    return rc;
 
1709
}
 
1710
 
 
1711
/*****************************************************************
 
1712
* Function Name:   ipmi_lcd_set_text
 
1713
*
 
1714
* Description:     This function sets lcd line text
 
1715
* Input:           intf            - ipmi interface
 
1716
*                  text    - lcd string
 
1717
*                  line_number- line number
 
1718
 
 
1719
* Output:       
 
1720
* Return:          -1 on error
 
1721
*                  0 if successful
 
1722
*
 
1723
******************************************************************/
 
1724
 
 
1725
static int
 
1726
ipmi_lcd_set_text(struct ipmi_intf * intf, char * text, int line_number)
 
1727
{
 
1728
    int rc = 0;
 
1729
 
 
1730
    struct ipmi_rs * rsp = NULL;
 
1731
    struct ipmi_rq req = {0};
 
1732
    uint8_t data[4];
 
1733
    IPMI_DELL_LCD_CAPS * lcd_caps;
 
1734
 
 
1735
    req.msg.netfn = IPMI_NETFN_APP;
 
1736
    req.msg.lun = 0;
 
1737
    req.msg.cmd = IPMI_GET_SYS_INFO;
 
1738
    req.msg.data_len = 4;
 
1739
    req.msg.data = data;
 
1740
    data[0] = 0;                            /* get parameter*/
 
1741
    data[1] = IPMI_DELL_LCD_GET_CAPS_SELECTOR;
 
1742
    data[2] = 0;                            /* set selector (n/a)*/
 
1743
    data[3] = 0;                            /* block selector (n/a)*/
 
1744
 
 
1745
    rsp = intf->sendrecv(intf, &req);
 
1746
    if (rsp == NULL) 
 
1747
    {
 
1748
        lprintf(LOG_ERR, " Error getting LCD capabilities");
 
1749
        return -1;
 
1750
    }
 
1751
    else if (rsp->ccode > 0) 
 
1752
    {
 
1753
        lprintf(LOG_ERR, " Error getting LCD capabilities: %s",
 
1754
            val2str(rsp->ccode, completion_code_vals));
 
1755
 
 
1756
        return -1;
 
1757
    }
 
1758
 
 
1759
    lcd_caps = (IPMI_DELL_LCD_CAPS *)(void *)rsp->data;
 
1760
 
 
1761
    if (lcd_caps->number_lines > 0) {
 
1762
        rc = ipmi_lcd_set_single_line_text (intf, text);
 
1763
    } else {
 
1764
        lprintf(LOG_ERR, "LCD does not have any lines that can be set");
 
1765
        rc = -1;
 
1766
    }
 
1767
 
 
1768
 
 
1769
    return rc;
 
1770
}
 
1771
 
 
1772
/*****************************************************************
 
1773
* Function Name:   ipmi_lcd_configure_wh
 
1774
*
 
1775
* Description:     This function updates the current lcd configuration
 
1776
* Input:           intf            - ipmi interface
 
1777
*                  lcdquallifier- lcd quallifier
 
1778
*                  errordisp       - error number
 
1779
*                  line_number-line number
 
1780
*                  text            - lcd string
 
1781
* Output:   
 
1782
* Return:          -1 on error
 
1783
*                  0 if successful
 
1784
*
 
1785
******************************************************************/
 
1786
 
 
1787
static int
 
1788
ipmi_lcd_configure_wh (struct ipmi_intf * intf, uint32_t  mode ,
 
1789
                       uint16_t lcdquallifier, uint8_t errordisp, 
 
1790
                       int8_t line_number, char * text)
 
1791
{
 
1792
    int rc = 0;
 
1793
 
 
1794
 
 
1795
    if (IPMI_DELL_LCD_CONFIG_USER_DEFINED == mode)
 
1796
        /* Any error was reported earlier. */
 
1797
        rc = ipmi_lcd_set_text(intf, text, line_number);
 
1798
 
 
1799
 
 
1800
    if (rc == 0)
 
1801
 
 
1802
        rc = ipmi_lcd_set_configure_command_wh (intf, mode ,lcdquallifier,errordisp);
 
1803
 
 
1804
    return rc;
 
1805
}
 
1806
 
 
1807
 
 
1808
/*****************************************************************
 
1809
* Function Name:   ipmi_lcd_configure
 
1810
*
 
1811
* Description:     This function updates the current lcd configuration
 
1812
* Input:           intf            - ipmi interface
 
1813
*                  command- lcd command
 
1814
*                  line_number-line number
 
1815
*                  text            - lcd string
 
1816
* Output:   
 
1817
* Return:          -1 on error
 
1818
*                  0 if successful
 
1819
*
 
1820
******************************************************************/
 
1821
 
 
1822
static int
 
1823
ipmi_lcd_configure (struct ipmi_intf * intf, int command, 
 
1824
                    int8_t line_number, char * text)
 
1825
{
 
1826
    int rc = 0;
 
1827
 
 
1828
    if (IPMI_DELL_LCD_CONFIG_USER_DEFINED == command)
 
1829
        rc = ipmi_lcd_set_text(intf, text, line_number);
 
1830
 
 
1831
    if (rc == 0)
 
1832
        rc = ipmi_lcd_set_configure_command (intf, command);
 
1833
 
 
1834
    return rc;
 
1835
}
 
1836
 
 
1837
 
 
1838
/*****************************************************************
 
1839
* Function Name:   ipmi_lcd_usage
 
1840
*
 
1841
* Description:   This function prints help message for lcd command
 
1842
* Input:               
 
1843
* Output:       
 
1844
*
 
1845
* Return:              
 
1846
*
 
1847
******************************************************************/
 
1848
 
 
1849
static void
 
1850
ipmi_lcd_usage(void)
 
1851
{
 
1852
    lprintf(LOG_NOTICE, "");
 
1853
    lprintf(LOG_NOTICE, "Generic DELL HW:");
 
1854
    lprintf(LOG_NOTICE, "   lcd set {none}|{default}|{custom <text>}");
 
1855
    lprintf(LOG_NOTICE, "      Set LCD text displayed during non-fault conditions");
 
1856
 
 
1857
    lprintf(LOG_NOTICE, "");
 
1858
    lprintf(LOG_NOTICE, "iDRAC 11g or iDRAC 12g:");
 
1859
    lprintf(LOG_NOTICE, "   lcd set {mode}|{lcdqualifier}|{errordisplay}");
 
1860
    lprintf(LOG_NOTICE, "      Allows you to set the LCD mode and user-defined string.");
 
1861
    lprintf(LOG_NOTICE, "");
 
1862
    lprintf(LOG_NOTICE, "   lcd set mode {none}|{modelname}|{ipv4address}|{macaddress}|");
 
1863
    lprintf(LOG_NOTICE, "   {systemname}|{servicetag}|{ipv6address}|{ambienttemp}");
 
1864
    lprintf(LOG_NOTICE, "   {systemwatt }|{assettag}|{userdefined}<text>");
 
1865
    lprintf(LOG_NOTICE, "          Allows you to set the LCD display mode to any of the preceding parameters");
 
1866
    lprintf(LOG_NOTICE, "");
 
1867
    lprintf(LOG_NOTICE, "   lcd set lcdqualifier {watt}|{btuphr}|{celsius}|{fahrenheit}");
 
1868
    lprintf(LOG_NOTICE, "      Allows you to set the unit for the system ambient temperature mode.");
 
1869
    lprintf(LOG_NOTICE, "");
 
1870
    lprintf(LOG_NOTICE, "   lcd set errordisplay {sel}|{simple}");
 
1871
    lprintf(LOG_NOTICE, "      Allows you to set the error display.");
 
1872
    lprintf(LOG_NOTICE, "");
 
1873
    lprintf(LOG_NOTICE, "   lcd info");
 
1874
    lprintf(LOG_NOTICE, "      Show LCD text that is displayed during non-fault conditions");
 
1875
    lprintf(LOG_NOTICE, "");
 
1876
    lprintf(LOG_NOTICE, "");
 
1877
    lprintf(LOG_NOTICE, "   lcd set vkvm{active}|{inactive}");
 
1878
    lprintf(LOG_NOTICE, "           Set vKVM active and inactive, message will be displayed on lcd"); 
 
1879
    lprintf(LOG_NOTICE, " when vKVM is active and vKVM session is in progress");
 
1880
    lprintf(LOG_NOTICE, "");
 
1881
    lprintf(LOG_NOTICE, "   lcd set frontpanelaccess {viewandmodify}|{viewonly}|{disabled}");
 
1882
    lprintf(LOG_NOTICE, "      Set LCD mode to view and modify, view only or disabled ");
 
1883
    lprintf(LOG_NOTICE, "");
 
1884
    lprintf(LOG_NOTICE, "   lcd status");
 
1885
    lprintf(LOG_NOTICE, "           Show LCD Status for vKVM display<active|inactive>");
 
1886
    lprintf(LOG_NOTICE, "   and Front Panel access mode {viewandmodify}|{viewonly}|{disabled} ");
 
1887
    lprintf(LOG_NOTICE, "");
 
1888
}
 
1889
 
 
1890
/*****************************************************************
 
1891
* Function Name:       ipmi_delloem_mac_main
 
1892
*
 
1893
* Description:         This function processes the delloem mac command
 
1894
* Input:               intf    - ipmi interface
 
1895
                       argc    - no of arguments
 
1896
                       argv    - argument string array
 
1897
* Output:        
 
1898
*
 
1899
* Return:              return code     0 - success
 
1900
*                         -1 - failure
 
1901
*
 
1902
******************************************************************/
 
1903
 
 
1904
 
 
1905
static int ipmi_delloem_mac_main (struct ipmi_intf * intf, int argc, char ** argv)
 
1906
{
 
1907
    int rc = 0;
 
1908
        int currIdInt = -1;
 
1909
 
 
1910
    current_arg++;
 
1911
    if (argc > 1 && strcmp(argv[current_arg], "help") == 0)
 
1912
    {
 
1913
        ipmi_mac_usage();
 
1914
        return 0;
 
1915
    }
 
1916
    ipmi_idracvalidator_command(intf);
 
1917
    if (argc == 1)
 
1918
    {
 
1919
        rc = ipmi_macinfo(intf, 0xff);
 
1920
    }
 
1921
    else if (strncmp(argv[current_arg], "list\0", 5) == 0)
 
1922
    {
 
1923
        rc = ipmi_macinfo(intf, 0xff);
 
1924
    }
 
1925
    else if (strncmp(argv[current_arg], "get\0", 4) == 0)
 
1926
    {
 
1927
        current_arg++;
 
1928
        if (argv[current_arg] == NULL)
 
1929
        {
 
1930
            ipmi_mac_usage();
 
1931
            return -1;
 
1932
        }
 
1933
 
 
1934
                if(make_int(argv[current_arg],&currIdInt) < 0) {
 
1935
                        lprintf(LOG_ERR, "Invalid NIC number. The NIC number should be between 0-8\n");
 
1936
                        return -1;
 
1937
                }
 
1938
                if( (currIdInt > 8) || (currIdInt < 0) )
 
1939
        {
 
1940
            lprintf(LOG_ERR, "Invalid NIC number. The NIC number should be between 0-8\n");
 
1941
            return -1;
 
1942
        }
 
1943
        rc = ipmi_macinfo(intf, currIdInt);
 
1944
    }
 
1945
    else
 
1946
    {
 
1947
        ipmi_mac_usage();
 
1948
    }
 
1949
    return rc;
 
1950
}
 
1951
 
 
1952
 
 
1953
/*****************************************************************
 
1954
* Function Name:     make_int
 
1955
*
 
1956
* Description:   This function convert string into integer
 
1957
* Input:         str     - decimal number string
 
1958
* Output:        value   - integer value
 
1959
* Return:                
 
1960
*
 
1961
******************************************************************/
 
1962
static int make_int(const char *str, int *value)
 
1963
{
 
1964
    char *tmp=NULL;
 
1965
    *value = strtol(str,&tmp,0);
 
1966
    if ( tmp-str != strlen(str) )
 
1967
    {
 
1968
        return -1;
 
1969
    }
 
1970
    return 0;
 
1971
}
 
1972
 
 
1973
 
 
1974
 
 
1975
 
 
1976
 
 
1977
EmbeddedNICMacAddressType EmbeddedNICMacAddress;
 
1978
 
 
1979
EmbeddedNICMacAddressType_10G EmbeddedNICMacAddress_10G;
 
1980
 
 
1981
static void InitEmbeddedNICMacAddressValues ()
 
1982
{
 
1983
    uint8_t i;
 
1984
    uint8_t j;
 
1985
 
 
1986
 
 
1987
    for (i=0;i<MAX_LOM;i++)
 
1988
    {
 
1989
        EmbeddedNICMacAddress.LOMMacAddress[i].BladSlotNumber = 0;
 
1990
        EmbeddedNICMacAddress.LOMMacAddress[i].MacType = LOM_MACTYPE_RESERVED;
 
1991
        EmbeddedNICMacAddress.LOMMacAddress[i].EthernetStatus = LOM_ETHERNET_RESERVED;
 
1992
        EmbeddedNICMacAddress.LOMMacAddress[i].NICNumber = 0;
 
1993
        EmbeddedNICMacAddress.LOMMacAddress[i].Reserved = 0;
 
1994
        for (j=0;j<MACADDRESSLENGH;j++)
 
1995
        {
 
1996
            EmbeddedNICMacAddress.LOMMacAddress[i].MacAddressByte[j] = 0;
 
1997
            EmbeddedNICMacAddress_10G.MacAddress[i].MacAddressByte[j] = 0;
 
1998
        }
 
1999
    }
 
2000
}
 
2001
 
 
2002
uint8_t UseVirtualMacAddress = 0;
 
2003
#define VIRTUAL_MAC_OFFSET (2)
 
2004
static int ipmi_macinfo_drac_idrac_virtual_mac(struct ipmi_intf* intf,uint8_t NicNum)
 
2005
{
 
2006
    struct ipmi_rs * rsp;
 
2007
    struct ipmi_rq req;
 
2008
 
 
2009
    uint8_t msg_data[30];
 
2010
    uint8_t VirtualMacAddress [MACADDRESSLENGH];
 
2011
    uint8_t input_length=0;
 
2012
    uint8_t j;
 
2013
    uint8_t i;
 
2014
 
 
2015
    if (0xff==NicNum || IDRAC_NIC_NUMBER==NicNum )
 
2016
    {
 
2017
        UseVirtualMacAddress = 0;
 
2018
 
 
2019
        input_length = 0;
 
2020
        msg_data[input_length++] = 1; /*Get*/
 
2021
 
 
2022
        req.msg.netfn = DELL_OEM_NETFN;
 
2023
        req.msg.lun = 0;                
 
2024
        req.msg.cmd = GET_IDRAC_VIRTUAL_MAC;
 
2025
        req.msg.data = msg_data;
 
2026
        req.msg.data_len = input_length;
 
2027
 
 
2028
        rsp = intf->sendrecv(intf, &req);
 
2029
        if (rsp == NULL)
 
2030
        {
 
2031
            return -1;
 
2032
        }
 
2033
        if (rsp->ccode > 0) 
 
2034
        {
 
2035
            return -1;
 
2036
        }
 
2037
                if( (IMC_IDRAC_12G_MODULAR == IMC_Type) || (IMC_IDRAC_12G_MONOLITHIC== IMC_Type) ) {
 
2038
                        // Get the Chasiss Assigned MAC Addresss        for 12g Only
 
2039
                        memcpy(VirtualMacAddress,((rsp->data)+1),MACADDRESSLENGH);
 
2040
 
 
2041
                        for (i=0;i<MACADDRESSLENGH;i++)
 
2042
                        {
 
2043
                                if (0 != VirtualMacAddress [i])
 
2044
                                {
 
2045
                                        UseVirtualMacAddress = 1;
 
2046
                                }
 
2047
                        }
 
2048
                        // Get the Server Assigned MAC Addresss for 12g Only
 
2049
                        if(!UseVirtualMacAddress) {
 
2050
                                memcpy(VirtualMacAddress,((rsp->data)+1+MACADDRESSLENGH),MACADDRESSLENGH);
 
2051
 
 
2052
                                for (i=0;i<MACADDRESSLENGH;i++)
 
2053
                                {
 
2054
                                        if (0 != VirtualMacAddress [i])
 
2055
                                        {
 
2056
                                                UseVirtualMacAddress = 1;
 
2057
                                        }
 
2058
                                }
 
2059
                        }
 
2060
                } else {
 
2061
        memcpy(VirtualMacAddress,((rsp->data)+VIRTUAL_MAC_OFFSET),MACADDRESSLENGH);
 
2062
 
 
2063
        for (i=0;i<MACADDRESSLENGH;i++)
 
2064
        {
 
2065
            if (0 != VirtualMacAddress [i])
 
2066
            {
 
2067
                UseVirtualMacAddress = 1;
 
2068
            }       
 
2069
        }
 
2070
                }
 
2071
        if (0 == UseVirtualMacAddress)
 
2072
            return -1;              
 
2073
        if (IMC_IDRAC_10G == IMC_Type)
 
2074
                        printf ("\nDRAC MAC Address ");
 
2075
                else if ( (IMC_IDRAC_11G_MODULAR == IMC_Type) || (IMC_IDRAC_11G_MONOLITHIC== IMC_Type) )
 
2076
                        printf ("\niDRAC6 MAC Address ");
 
2077
                else if ( (IMC_IDRAC_12G_MODULAR == IMC_Type) || (IMC_IDRAC_12G_MONOLITHIC== IMC_Type) )
 
2078
                        printf ("\niDRAC7 MAC Address ");
 
2079
                else if ( (IMC_MASER_LITE_BMC== IMC_Type) || (IMC_MASER_LITE_NU== IMC_Type) )
 
2080
                        printf ("\nBMC MAC Address ");
 
2081
        else
 
2082
            printf ("\niDRAC6 MAC Address ");
 
2083
 
 
2084
        for (j=0;j<5;j++)
 
2085
            printf("%02x:",VirtualMacAddress[j]);
 
2086
        printf("%02x",VirtualMacAddress[j]);
 
2087
 
 
2088
        printf ("\n");        
 
2089
 
 
2090
    }  
 
2091
    return 0;
 
2092
}
 
2093
 
 
2094
 
 
2095
/*****************************************************************
 
2096
* Function Name:    ipmi_macinfo_drac_idrac_mac
 
2097
*
 
2098
* Description:      This function retrieves the mac address of DRAC or iDRAC
 
2099
* Input:            NicNum
 
2100
* Output:                 
 
2101
* Return:               
 
2102
*
 
2103
******************************************************************/
 
2104
 
 
2105
static int ipmi_macinfo_drac_idrac_mac(struct ipmi_intf* intf,uint8_t NicNum)
 
2106
{
 
2107
    struct ipmi_rs * rsp;
 
2108
    struct ipmi_rq req;
 
2109
 
 
2110
    uint8_t msg_data[30];
 
2111
    uint8_t input_length=0;
 
2112
    uint8_t iDRAC6MacAddressByte[MACADDRESSLENGH];
 
2113
    uint8_t j;
 
2114
 
 
2115
    ipmi_macinfo_drac_idrac_virtual_mac (intf,NicNum);
 
2116
 
 
2117
 
 
2118
    if ((0xff==NicNum || IDRAC_NIC_NUMBER==NicNum) && 0 == UseVirtualMacAddress)
 
2119
    {
 
2120
 
 
2121
        input_length = 0;
 
2122
 
 
2123
        msg_data[input_length++] = LAN_CHANNEL_NUMBER; 
 
2124
        msg_data[input_length++] = MAC_ADDR_PARAM;  
 
2125
        msg_data[input_length++] = 0x00;                        
 
2126
        msg_data[input_length++] = 0x00;                        
 
2127
 
 
2128
        req.msg.netfn = TRANSPORT_NETFN;
 
2129
        req.msg.lun = 0;                
 
2130
        req.msg.cmd = GET_LAN_PARAM_CMD;
 
2131
        req.msg.data = msg_data;
 
2132
        req.msg.data_len = input_length;
 
2133
 
 
2134
        rsp = intf->sendrecv(intf, &req);
 
2135
        if (rsp == NULL)
 
2136
        {
 
2137
            lprintf(LOG_ERR, " Error in getting MAC Address");
 
2138
            return -1;
 
2139
        }
 
2140
        if (rsp->ccode > 0) 
 
2141
        {
 
2142
            lprintf(LOG_ERR, " Error in getting MAC Address (%s) \n",
 
2143
                val2str(rsp->ccode, completion_code_vals) );
 
2144
            return -1;
 
2145
        }
 
2146
 
 
2147
        memcpy(iDRAC6MacAddressByte,((rsp->data)+PARAM_REV_OFFSET),MACADDRESSLENGH);
 
2148
 
 
2149
        if (IMC_IDRAC_10G == IMC_Type)
 
2150
            printf ("\nDRAC MAC Address ");
 
2151
                else if ((IMC_IDRAC_11G_MODULAR == IMC_Type) || (IMC_IDRAC_11G_MONOLITHIC== IMC_Type))
 
2152
                        printf ("\niDRAC6 MAC Address ");
 
2153
                else if ((IMC_IDRAC_12G_MODULAR == IMC_Type) || (IMC_IDRAC_12G_MONOLITHIC== IMC_Type))          
 
2154
                        printf ("\niDRAC7 MAC Address ");
 
2155
                else if ( (IMC_MASER_LITE_BMC== IMC_Type) || (IMC_MASER_LITE_NU== IMC_Type) )
 
2156
                        printf ("\n\rBMC MAC Address ");
 
2157
        else
 
2158
            printf ("\niDRAC6 MAC Address ");
 
2159
 
 
2160
        for (j=0;j<5;j++)
 
2161
            printf("%02x:",iDRAC6MacAddressByte[j]);
 
2162
        printf("%02x",iDRAC6MacAddressByte[j]);
 
2163
 
 
2164
        printf ("\n");        
 
2165
    }
 
2166
    return 0;
 
2167
}
 
2168
 
 
2169
 
 
2170
/*****************************************************************
 
2171
* Function Name:    ipmi_macinfo_10g
 
2172
*
 
2173
* Description:      This function retrieves the mac address of LOMs
 
2174
* Input:            intf      - ipmi interface
 
2175
                    NicNum    - NIC number
 
2176
* Output:               
 
2177
* Return:               
 
2178
*
 
2179
******************************************************************/
 
2180
 
 
2181
static int ipmi_macinfo_10g (struct ipmi_intf* intf, uint8_t NicNum)
 
2182
{
 
2183
    struct ipmi_rs * rsp;
 
2184
    struct ipmi_rq req;
 
2185
 
 
2186
    uint8_t msg_data[30];
 
2187
    uint8_t input_length=0;
 
2188
 
 
2189
    uint8_t j;
 
2190
    uint8_t i;
 
2191
 
 
2192
    uint8_t Total_No_NICs = 0;
 
2193
 
 
2194
 
 
2195
    InitEmbeddedNICMacAddressValues ();
 
2196
 
 
2197
    memset(msg_data, 0, sizeof(msg_data));
 
2198
    input_length = 0;
 
2199
    msg_data[input_length++] = 0x00; /* Get Parameter Command */
 
2200
    msg_data[input_length++] = EMB_NIC_MAC_ADDRESS_9G_10G;  /* OEM Param */
 
2201
 
 
2202
    msg_data[input_length++] = 0x00;         
 
2203
    msg_data[input_length++] = 0x00;         
 
2204
 
 
2205
    memset(&req, 0, sizeof(req));
 
2206
 
 
2207
    req.msg.netfn = IPMI_NETFN_APP;
 
2208
    req.msg.lun = 0;                
 
2209
    req.msg.cmd = IPMI_GET_SYS_INFO;
 
2210
    req.msg.data = msg_data;
 
2211
 
 
2212
 
 
2213
    req.msg.data_len = input_length;
 
2214
 
 
2215
    rsp = intf->sendrecv(intf, &req);
 
2216
    if (rsp == NULL) {
 
2217
        lprintf(LOG_ERR, " Error in getting MAC Address");
 
2218
        return -1;
 
2219
    }
 
2220
    if (rsp->ccode > 0) {
 
2221
        lprintf(LOG_ERR, " Error in getting MAC Address (%s) \n",
 
2222
            val2str(rsp->ccode, completion_code_vals) );
 
2223
        return -1;
 
2224
    }
 
2225
 
 
2226
    Total_No_NICs = (uint8_t) rsp->data[0+PARAM_REV_OFFSET]; /* Byte 1: Total Number of Embedded NICs */
 
2227
 
 
2228
    if (IDRAC_NIC_NUMBER != NicNum)
 
2229
    {
 
2230
        if (0xff == NicNum)
 
2231
        {
 
2232
            printf ("\nSystem LOMs");
 
2233
        }       
 
2234
        printf("\nNIC Number\tMAC Address\n");
 
2235
 
 
2236
 
 
2237
        memcpy(&EmbeddedNICMacAddress_10G,((rsp->data)+PARAM_REV_OFFSET+TOTAL_N0_NICS_INDEX),Total_No_NICs* MACADDRESSLENGH);
 
2238
 
 
2239
 
 
2240
        /*Read the LOM type and Mac Addresses */
 
2241
 
 
2242
        for (i=0;i<Total_No_NICs;i++)
 
2243
        {
 
2244
            if ((0xff==NicNum) || (i == NicNum)     )
 
2245
            {       
 
2246
                printf ("\n%d",i);
 
2247
                printf ("\t\t");
 
2248
                for (j=0;j<5;j++)
 
2249
                {
 
2250
                    printf("%02x:",EmbeddedNICMacAddress_10G.MacAddress[i].MacAddressByte[j]);
 
2251
                }       
 
2252
                printf("%02x",EmbeddedNICMacAddress_10G.MacAddress[i].MacAddressByte[j]);
 
2253
            }               
 
2254
        }
 
2255
        printf ("\n");
 
2256
 
 
2257
    }
 
2258
 
 
2259
    ipmi_macinfo_drac_idrac_mac(intf,NicNum);
 
2260
 
 
2261
 
 
2262
    return 0;
 
2263
}
 
2264
 
 
2265
 
 
2266
/*****************************************************************
 
2267
* Function Name:      ipmi_macinfo_11g
 
2268
*
 
2269
* Description:        This function retrieves the mac address of LOMs
 
2270
* Input:              intf - ipmi interface
 
2271
* Output:               
 
2272
* Return:               
 
2273
*
 
2274
******************************************************************/
 
2275
 
 
2276
static int ipmi_macinfo_11g (struct ipmi_intf* intf, uint8_t NicNum)
 
2277
{
 
2278
    struct ipmi_rs * rsp;
 
2279
    struct ipmi_rq req;
 
2280
 
 
2281
    uint8_t msg_data[30];
 
2282
    uint8_t input_length=0;
 
2283
 
 
2284
    uint8_t len;
 
2285
    uint8_t j;
 
2286
    uint8_t offset;
 
2287
    uint8_t maxlen;
 
2288
    uint8_t loop_count;
 
2289
    uint8_t i;
 
2290
 
 
2291
    offset = 0;
 
2292
    len = 8; /*eigher 8 or 16 */
 
2293
    maxlen = 64;
 
2294
    loop_count = maxlen / len;
 
2295
 
 
2296
    InitEmbeddedNICMacAddressValues ();
 
2297
 
 
2298
    memset(msg_data, 0, sizeof(msg_data));
 
2299
    input_length = 0;
 
2300
    msg_data[input_length++] = 0x00; /* Get Parameter Command */
 
2301
    msg_data[input_length++] = EMB_NIC_MAC_ADDRESS_11G;      /* OEM Param */
 
2302
 
 
2303
    msg_data[input_length++] = 0x00;      
 
2304
    msg_data[input_length++] = 0x00;      
 
2305
    msg_data[input_length++] = 0x00;      
 
2306
    msg_data[input_length++] = 0x00;      
 
2307
 
 
2308
    memset(&req, 0, sizeof(req));
 
2309
 
 
2310
    req.msg.netfn = IPMI_NETFN_APP;
 
2311
    req.msg.lun = 0;              
 
2312
    req.msg.cmd = IPMI_GET_SYS_INFO;
 
2313
    req.msg.data = msg_data;
 
2314
 
 
2315
 
 
2316
    req.msg.data_len = input_length;
 
2317
 
 
2318
    rsp = intf->sendrecv(intf, &req);
 
2319
    if (rsp == NULL) {
 
2320
        lprintf(LOG_ERR, " Error in getting MAC Address");
 
2321
        return -1;
 
2322
    }
 
2323
    if (rsp->ccode > 0) {
 
2324
        lprintf(LOG_ERR, " Error in getting MAC Address (%s) \n",
 
2325
            val2str(rsp->ccode, completion_code_vals) );
 
2326
        return -1;
 
2327
    }
 
2328
 
 
2329
    len = 8; /*eigher 8 or 16 */
 
2330
    maxlen = (uint8_t) rsp->data[0+PARAM_REV_OFFSET];
 
2331
    loop_count = maxlen / len;
 
2332
 
 
2333
    if (IDRAC_NIC_NUMBER != NicNum)
 
2334
    {
 
2335
        if (0xff == NicNum)
 
2336
        {
 
2337
            printf ("\nSystem LOMs");
 
2338
        }       
 
2339
        printf("\nNIC Number\tMAC Address\t\tStatus\n");
 
2340
 
 
2341
 
 
2342
        /*Read the LOM type and Mac Addresses */
 
2343
        offset=0;
 
2344
        for (i=0;i<loop_count;i++,offset=offset+len)
 
2345
        {
 
2346
            input_length = 4;
 
2347
            msg_data[input_length++] = offset;
 
2348
            msg_data[input_length++] = len;   
 
2349
 
 
2350
            req.msg.netfn = IPMI_NETFN_APP;
 
2351
            req.msg.lun = 0;
 
2352
            req.msg.cmd = IPMI_GET_SYS_INFO;
 
2353
            req.msg.data = msg_data;
 
2354
            req.msg.data_len = input_length;
 
2355
 
 
2356
            rsp = intf->sendrecv(intf, &req);
 
2357
            if (rsp == NULL) {
 
2358
                lprintf(LOG_ERR, " Error in getting MAC Address");
 
2359
                return -1;
 
2360
            }
 
2361
            if (rsp->ccode > 0) {
 
2362
                lprintf(LOG_ERR, " Error in getting MAC Address (%s) \n",
 
2363
                    val2str(rsp->ccode, completion_code_vals) );
 
2364
                return -1;
 
2365
 
 
2366
            }
 
2367
 
 
2368
            memcpy(&(EmbeddedNICMacAddress.LOMMacAddress[i]),((rsp->data)+PARAM_REV_OFFSET),len);
 
2369
 
 
2370
 
 
2371
            if (LOM_MACTYPE_ETHERNET == EmbeddedNICMacAddress.LOMMacAddress[i].MacType)
 
2372
            {
 
2373
 
 
2374
                if (    (0xff==NicNum) || (NicNum == EmbeddedNICMacAddress.LOMMacAddress[i].NICNumber)  )
 
2375
                {
 
2376
                    printf ("\n%d",EmbeddedNICMacAddress.LOMMacAddress[i].NICNumber);
 
2377
                    printf ("\t\t");
 
2378
                    for (j=0;j<5;j++)
 
2379
                        printf("%02x:",EmbeddedNICMacAddress.LOMMacAddress[i].MacAddressByte[j]);
 
2380
                    printf("%02x",EmbeddedNICMacAddress.LOMMacAddress[i].MacAddressByte[j]);
 
2381
 
 
2382
                    if (LOM_ETHERNET_ENABLED == EmbeddedNICMacAddress.LOMMacAddress[i].EthernetStatus)
 
2383
                        printf ("\tEnabled");
 
2384
                    else
 
2385
                        printf ("\tDisabled");
 
2386
                }
 
2387
            }
 
2388
 
 
2389
        }         
 
2390
        printf ("\n");
 
2391
 
 
2392
    }
 
2393
 
 
2394
    ipmi_macinfo_drac_idrac_mac(intf,NicNum);
 
2395
 
 
2396
    return 0;
 
2397
 
 
2398
}     
 
2399
 
 
2400
 
 
2401
 
 
2402
/*****************************************************************
 
2403
* Function Name:      ipmi_macinfo
 
2404
*
 
2405
* Description:     This function retrieves the mac address of LOMs
 
2406
* Input:           intf   - ipmi interface
 
2407
* Output:               
 
2408
* Return:               
 
2409
*
 
2410
******************************************************************/
 
2411
 
 
2412
static int ipmi_macinfo (struct ipmi_intf* intf, uint8_t NicNum)
 
2413
{
 
2414
    if (IMC_IDRAC_10G == IMC_Type)
 
2415
    {
 
2416
        return ipmi_macinfo_10g (intf,NicNum);
 
2417
    }
 
2418
        else if ((IMC_IDRAC_11G_MODULAR == IMC_Type || IMC_IDRAC_11G_MONOLITHIC== IMC_Type )  ||
 
2419
                        (IMC_IDRAC_12G_MODULAR == IMC_Type || IMC_IDRAC_12G_MONOLITHIC== IMC_Type ) ||
 
2420
                        (IMC_MASER_LITE_NU== IMC_Type || IMC_MASER_LITE_BMC== IMC_Type ))
 
2421
    {
 
2422
        return ipmi_macinfo_11g (intf,NicNum);
 
2423
    }
 
2424
    else
 
2425
    {
 
2426
        lprintf(LOG_ERR, " Error in getting MAC Address : Not supported platform");
 
2427
        return 0;
 
2428
    }       
 
2429
}
 
2430
 
 
2431
 
 
2432
/*****************************************************************
 
2433
* Function Name:     ipmi_mac_usage
 
2434
*
 
2435
* Description:   This function prints help message for mac command
 
2436
* Input:               
 
2437
* Output:       
 
2438
*
 
2439
* Return:              
 
2440
*
 
2441
******************************************************************/
 
2442
 
 
2443
static void
 
2444
ipmi_mac_usage(void)
 
2445
{
 
2446
    lprintf(LOG_NOTICE, "");
 
2447
    lprintf(LOG_NOTICE, "   mac list");
 
2448
    lprintf(LOG_NOTICE, "      Lists the MAC address of LOMs");
 
2449
    lprintf(LOG_NOTICE, "");
 
2450
    lprintf(LOG_NOTICE, "   mac get <NIC number>");
 
2451
    lprintf(LOG_NOTICE, "      Shows the MAC address of specified LOM. 0-7 System LOM, 8- DRAC/iDRAC.");
 
2452
    lprintf(LOG_NOTICE, "");
 
2453
}
 
2454
 
 
2455
/*****************************************************************
 
2456
* Function Name:       ipmi_delloem_lan_main
 
2457
*
 
2458
* Description:         This function processes the delloem lan command
 
2459
* Input:               intf    - ipmi interface
 
2460
                       argc    - no of arguments
 
2461
                       argv    - argument string array
 
2462
* Output:        
 
2463
*
 
2464
* Return:              return code     0 - success
 
2465
*                         -1 - failure
 
2466
*
 
2467
******************************************************************/
 
2468
 
 
2469
static int ipmi_delloem_lan_main (struct ipmi_intf * intf, int argc, char ** argv)
 
2470
{
 
2471
    int rc = 0;
 
2472
 
 
2473
    int nic_selection = 0;
 
2474
        char nic_set[2] = {0};
 
2475
    current_arg++;
 
2476
    if (argv[current_arg] == NULL || strcmp(argv[current_arg], "help") == 0)
 
2477
    {
 
2478
        ipmi_lan_usage();
 
2479
        return 0;
 
2480
    }
 
2481
    ipmi_idracvalidator_command(intf);
 
2482
    if (!IsLANSupported())
 
2483
    {
 
2484
        printf("lan is not supported on this system.\n");
 
2485
        return -1;
 
2486
    }
 
2487
    else if (strncmp(argv[current_arg], "set\0", 4) == 0)
 
2488
    {
 
2489
        current_arg++;
 
2490
        if (argv[current_arg] == NULL)
 
2491
        {
 
2492
            ipmi_lan_usage();
 
2493
            return -1;
 
2494
        }
 
2495
                if(iDRAC_FLAG == IDRAC_12G) {
 
2496
                        nic_selection = get_nic_selection_mode_12g(intf,current_arg,argv,nic_set);
 
2497
                        if (INVALID == nic_selection)
 
2498
                        {
 
2499
                                ipmi_lan_usage();
 
2500
                                return -1;
 
2501
                        } else if(INVAILD_FAILOVER_MODE == nic_selection) {
 
2502
                                printf(INVAILD_FAILOVER_MODE_STRING);
 
2503
                                return 0;
 
2504
                        } else if(INVAILD_FAILOVER_MODE_SETTINGS == nic_selection){
 
2505
                                printf(INVAILD_FAILOVER_MODE_SET);
 
2506
                                return 0;
 
2507
                        } else if(INVAILD_SHARED_MODE == nic_selection){
 
2508
                                printf(INVAILD_SHARED_MODE_SET_STRING);
 
2509
                                return 0;
 
2510
                        }
 
2511
 
 
2512
                        rc = ipmi_lan_set_nic_selection_12g(intf,nic_set);
 
2513
                }
 
2514
                else
 
2515
                {
 
2516
        nic_selection = get_nic_selection_mode(current_arg,argv);
 
2517
 
 
2518
 
 
2519
        if (INVALID == nic_selection)
 
2520
        {
 
2521
            ipmi_lan_usage();
 
2522
            return -1;
 
2523
                        }
 
2524
                        if(IMC_IDRAC_11G_MODULAR == IMC_Type) {
 
2525
                                printf(INVAILD_SHARED_MODE_SET_STRING);
 
2526
                                return 0;
 
2527
        }                               
 
2528
        rc = ipmi_lan_set_nic_selection(intf,nic_selection);
 
2529
                }               
 
2530
        return 0;                       
 
2531
    }
 
2532
    else if (strncmp(argv[current_arg], "get\0", 4) == 0)
 
2533
    {
 
2534
        current_arg++;
 
2535
        if (argv[current_arg] == NULL)
 
2536
        {
 
2537
            rc = ipmi_lan_get_nic_selection(intf);
 
2538
            return rc;
 
2539
        }
 
2540
        else if (strncmp(argv[current_arg], "active\0", 7) == 0)                
 
2541
        {
 
2542
            rc = ipmi_lan_get_active_nic(intf);
 
2543
            return rc;
 
2544
        }
 
2545
        else
 
2546
        {
 
2547
            ipmi_lan_usage();
 
2548
        }
 
2549
 
 
2550
    }
 
2551
    else
 
2552
    {
 
2553
        ipmi_lan_usage();
 
2554
        return -1;
 
2555
    }
 
2556
    return rc;
 
2557
}
 
2558
 
 
2559
 
 
2560
static int IsLANSupported ()
 
2561
{
 
2562
    if (IMC_IDRAC_11G_MODULAR == IMC_Type)
 
2563
        return 0;
 
2564
    return 1;
 
2565
}
 
2566
 
 
2567
 
 
2568
int get_nic_selection_mode_12g (struct ipmi_intf* intf,int current_arg, char ** argv, char *nic_set)
 
2569
{
 
2570
        int nic_selection_mode = 0;
 
2571
        int failover = 0;
 
2572
 
 
2573
        // First get the current settings.
 
2574
        struct ipmi_rs * rsp;
 
2575
        struct ipmi_rq req;
 
2576
 
 
2577
        uint8_t msg_data[30];
 
2578
        uint8_t input_length=0;
 
2579
        
 
2580
        input_length = 0;
 
2581
                
 
2582
        req.msg.netfn = DELL_OEM_NETFN;
 
2583
        req.msg.lun = 0;                
 
2584
        
 
2585
        req.msg.cmd = GET_NIC_SELECTION_12G_CMD;
 
2586
 
 
2587
        req.msg.data = msg_data;
 
2588
        req.msg.data_len = input_length;
 
2589
  
 
2590
        rsp = intf->sendrecv(intf, &req);
 
2591
        if (rsp == NULL)
 
2592
        {
 
2593
                lprintf(LOG_ERR, " Error in getting nic selection");
 
2594
                return -1;
 
2595
        }
 
2596
        else if (rsp->ccode > 0) 
 
2597
        {
 
2598
                lprintf(LOG_ERR, " Error in getting nic selection (%s) \n",
 
2599
                  val2str(rsp->ccode, completion_code_vals) );
 
2600
                return -1;
 
2601
        }
 
2602
        
 
2603
        nic_set[0] = rsp->data[0];
 
2604
        nic_set[1] = rsp->data[1];
 
2605
 
 
2606
        
 
2607
        if (NULL!= argv[current_arg] && 0 == strncmp(argv[current_arg], "dedicated\0", 10)) 
 
2608
        {
 
2609
                nic_set[0] = 1;
 
2610
                nic_set[1] = 0;
 
2611
                return 0;
 
2612
        }
 
2613
        if (NULL!= argv[current_arg] && 0 == strncmp(argv[current_arg], "shared\0", 7)) 
 
2614
        {
 
2615
                
 
2616
        }
 
2617
        else
 
2618
                return INVALID;
 
2619
        
 
2620
        current_arg++;  
 
2621
        if (NULL!= argv[current_arg] && 0 == strncmp(argv[current_arg], "with\0", 5)) 
 
2622
        {
 
2623
        }       
 
2624
        else
 
2625
                return INVALID;         
 
2626
        
 
2627
        current_arg++;  
 
2628
        if (NULL!= argv[current_arg] && 0 == strncmp(argv[current_arg], "failover\0", 9)) 
 
2629
        {
 
2630
                failover = 1;
 
2631
        }       
 
2632
        if(failover)
 
2633
                current_arg++;  
 
2634
        if (NULL!= argv[current_arg] && 0 == strncmp(argv[current_arg], "lom1\0", 5)) 
 
2635
        {
 
2636
                if(IMC_IDRAC_12G_MODULAR == IMC_Type)
 
2637
                {
 
2638
                        return INVAILD_SHARED_MODE;
 
2639
                }
 
2640
                if(failover) {
 
2641
                        if(nic_set[0] == 2)
 
2642
                        {
 
2643
                                return INVAILD_FAILOVER_MODE;
 
2644
                        } else if(nic_set[0] == 1) {
 
2645
                                return INVAILD_FAILOVER_MODE_SETTINGS;
 
2646
                        }
 
2647
                        nic_set[1] = 2;
 
2648
                }       
 
2649
                else {
 
2650
 
 
2651
                        nic_set[0] = 2;
 
2652
                        if(nic_set[1] == 2)
 
2653
                                nic_set[1] = 0;
 
2654
                }       
 
2655
                return 0;
 
2656
        }
 
2657
        else if (NULL!= argv[current_arg] && 0 == strncmp(argv[current_arg], "lom2\0", 5)) 
 
2658
        {
 
2659
        
 
2660
                if(IMC_IDRAC_12G_MODULAR == IMC_Type)
 
2661
                {
 
2662
                        return INVAILD_SHARED_MODE;
 
2663
                }
 
2664
                if(failover) {          
 
2665
                        if(nic_set[0] == 3)
 
2666
                        {
 
2667
                                return INVAILD_FAILOVER_MODE;
 
2668
                        } else if(nic_set[0] == 1) {
 
2669
                                return INVAILD_FAILOVER_MODE_SETTINGS;
 
2670
                        }
 
2671
                        nic_set[1] = 3;
 
2672
                }       
 
2673
                else {
 
2674
                        nic_set[0] = 3;
 
2675
                        if(nic_set[1] == 3)
 
2676
                                nic_set[1] = 0;
 
2677
                }       
 
2678
                return 0;
 
2679
        }
 
2680
        else if (NULL!= argv[current_arg] && 0 == strncmp(argv[current_arg], "lom3\0", 5)) 
 
2681
        {
 
2682
 
 
2683
                if(IMC_IDRAC_12G_MODULAR == IMC_Type)
 
2684
                {
 
2685
                        return INVAILD_SHARED_MODE;
 
2686
                }
 
2687
                if(failover) {  
 
2688
                        if(nic_set[0] == 4)
 
2689
                        {
 
2690
                                return INVAILD_FAILOVER_MODE;
 
2691
                        } else if(nic_set[0] == 1) {
 
2692
                                return INVAILD_FAILOVER_MODE_SETTINGS;
 
2693
                        }
 
2694
                        nic_set[1] = 4;
 
2695
 
 
2696
                }       
 
2697
                else {
 
2698
                        nic_set[0] = 4;
 
2699
                        if(nic_set[1] == 4)
 
2700
                                nic_set[1] = 0;
 
2701
 
 
2702
                }
 
2703
                return 0;
 
2704
        } 
 
2705
        else if (NULL!= argv[current_arg] && 0 == strncmp(argv[current_arg], "lom4\0", 5)) 
 
2706
        {
 
2707
        
 
2708
                if(IMC_IDRAC_12G_MODULAR == IMC_Type)
 
2709
                {
 
2710
                        return INVAILD_SHARED_MODE;
 
2711
                }
 
2712
                if(failover) {  
 
2713
                        if(nic_set[0] == 5)
 
2714
                        {
 
2715
                                return INVAILD_FAILOVER_MODE;
 
2716
                        } else if(nic_set[0] == 1) {
 
2717
                                return INVAILD_FAILOVER_MODE_SETTINGS;
 
2718
                        }
 
2719
                        nic_set[1] = 5;
 
2720
                }
 
2721
                else {
 
2722
                        nic_set[0] = 5;
 
2723
                        if(nic_set[1] == 5)
 
2724
                                nic_set[1] = 0;
 
2725
 
 
2726
                }       
 
2727
                return 0;
 
2728
        }       
 
2729
        else if (failover && NULL!= argv[current_arg] && 0 == strncmp(argv[current_arg], "none\0", 5)) 
 
2730
        {
 
2731
 
 
2732
                if(IMC_IDRAC_12G_MODULAR == IMC_Type)
 
2733
                {
 
2734
                        return INVAILD_SHARED_MODE;
 
2735
                }
 
2736
                if(failover) {  
 
2737
                        if(nic_set[0] == 1) {
 
2738
                                return INVAILD_FAILOVER_MODE_SETTINGS;
 
2739
                        }
 
2740
                        nic_set[1] = 0;
 
2741
                }       
 
2742
                return 0;
 
2743
        }       
 
2744
        else if (failover && NULL!= argv[current_arg] && 0 == strncmp(argv[current_arg], "all\0", 4)) 
 
2745
        {
 
2746
        }       
 
2747
        else
 
2748
                return INVALID; 
 
2749
        
 
2750
        current_arg++;  
 
2751
        if (failover && NULL!= argv[current_arg] && 0 == strncmp(argv[current_arg], "loms\0", 5)) 
 
2752
        {
 
2753
        
 
2754
                if(IMC_IDRAC_12G_MODULAR == IMC_Type)
 
2755
                {
 
2756
                        return INVAILD_SHARED_MODE;
 
2757
                }
 
2758
                if(nic_set[0] == 1) {
 
2759
                        return INVAILD_FAILOVER_MODE_SETTINGS;
 
2760
                }
 
2761
                nic_set[1] = 6;
 
2762
                return 0;
 
2763
        }       
 
2764
 
 
2765
        return INVALID;
 
2766
        
 
2767
}
 
2768
 
 
2769
 
 
2770
static int get_nic_selection_mode (int current_arg, char ** argv)
 
2771
{
 
2772
    int nic_selection_mode = 0;
 
2773
    if (NULL!= argv[current_arg] && 0 == strncmp(argv[current_arg], "dedicated\0", 10)) 
 
2774
    {
 
2775
        return DEDICATED;
 
2776
    }
 
2777
    if (NULL!= argv[current_arg] && 0 == strncmp(argv[current_arg], "shared\0", 7)) 
 
2778
    {
 
2779
        if (NULL == argv[current_arg+1] )
 
2780
            return SHARED;          
 
2781
    }
 
2782
    current_arg++;  
 
2783
    if (NULL!= argv[current_arg] && 0 == strncmp(argv[current_arg], "with\0", 5)) 
 
2784
    {
 
2785
    }       
 
2786
    else
 
2787
        return INVALID;         
 
2788
 
 
2789
    current_arg++;  
 
2790
    if (NULL!= argv[current_arg] && 0 == strncmp(argv[current_arg], "failover\0", 9)) 
 
2791
    {
 
2792
    }       
 
2793
    else
 
2794
        return INVALID;         
 
2795
 
 
2796
    current_arg++;  
 
2797
    if (NULL!= argv[current_arg] && 0 == strncmp(argv[current_arg], "lom2\0", 5)) 
 
2798
    {
 
2799
        return SHARED_WITH_FAILOVER_LOM2;
 
2800
    }       
 
2801
    else if (NULL!= argv[current_arg] && 0 == strncmp(argv[current_arg], "all\0", 4)) 
 
2802
    {
 
2803
    }       
 
2804
    else
 
2805
        return INVALID; 
 
2806
 
 
2807
    current_arg++;  
 
2808
    if (NULL!= argv[current_arg] && 0 == strncmp(argv[current_arg], "loms\0", 5)) 
 
2809
    {
 
2810
        return SHARED_WITH_FAILOVER_ALL_LOMS;
 
2811
    }       
 
2812
 
 
2813
    return INVALID;
 
2814
        
 
2815
}
 
2816
 
 
2817
 
 
2818
static int ipmi_lan_set_nic_selection_12g (struct ipmi_intf* intf, uint8_t* nic_selection)
 
2819
{
 
2820
        struct ipmi_rs * rsp;
 
2821
        struct ipmi_rq req;
 
2822
 
 
2823
        uint8_t msg_data[30];
 
2824
        uint8_t input_length=0;
 
2825
 
 
2826
        input_length = 0;
 
2827
                
 
2828
        msg_data[input_length++] = nic_selection[0]; 
 
2829
        msg_data[input_length++] = nic_selection[1]; 
 
2830
 
 
2831
        req.msg.netfn = DELL_OEM_NETFN;
 
2832
        req.msg.lun = 0;                
 
2833
        req.msg.cmd = SET_NIC_SELECTION_12G_CMD;
 
2834
        req.msg.data = msg_data;
 
2835
        req.msg.data_len = input_length;
 
2836
  
 
2837
        rsp = intf->sendrecv(intf, &req);
 
2838
        if (rsp == NULL)
 
2839
        {
 
2840
                lprintf(LOG_ERR, " Error in setting nic selection");
 
2841
                return -1;
 
2842
        }
 
2843
        // Check license only for setting the dedicated nic.
 
2844
        else if( (nic_selection[0] == 1) && ((iDRAC_FLAG == IDRAC_12G) && (rsp->ccode == LICENSE_NOT_SUPPORTED))) {
 
2845
                printf("FM001 : A required license is missing or expired\n");
 
2846
                return -1;      
 
2847
        } 
 
2848
        else if (rsp->ccode > 0) 
 
2849
        {
 
2850
                lprintf(LOG_ERR, " Error in setting nic selection (%s) \n",
 
2851
                  val2str(rsp->ccode, completion_code_vals) );
 
2852
                return -1;
 
2853
        }
 
2854
        printf("configured successfully");
 
2855
 
 
2856
        return 0;
 
2857
}
 
2858
 
 
2859
 
 
2860
static int ipmi_lan_set_nic_selection (struct ipmi_intf* intf, uint8_t nic_selection)
 
2861
{
 
2862
    struct ipmi_rs * rsp;
 
2863
    struct ipmi_rq req;
 
2864
 
 
2865
    uint8_t msg_data[30];
 
2866
    uint8_t input_length=0;
 
2867
 
 
2868
    input_length = 0;
 
2869
 
 
2870
    msg_data[input_length++] = nic_selection; 
 
2871
 
 
2872
        req.msg.netfn = DELL_OEM_NETFN;
 
2873
    req.msg.lun = 0;                
 
2874
    req.msg.cmd = SET_NIC_SELECTION_CMD;
 
2875
    req.msg.data = msg_data;
 
2876
    req.msg.data_len = input_length;
 
2877
 
 
2878
    rsp = intf->sendrecv(intf, &req);
 
2879
    if (rsp == NULL)
 
2880
    {
 
2881
        lprintf(LOG_ERR, " Error in setting nic selection");
 
2882
        return -1;
 
2883
    }
 
2884
    else if (rsp->ccode > 0) 
 
2885
    {
 
2886
        lprintf(LOG_ERR, " Error in setting nic selection (%s) \n",
 
2887
            val2str(rsp->ccode, completion_code_vals) );
 
2888
        return -1;
 
2889
    }
 
2890
    printf("configured successfully");
 
2891
 
 
2892
    return 0;
 
2893
}      
 
2894
 
 
2895
static int ipmi_lan_get_nic_selection (struct ipmi_intf* intf)
 
2896
{
 
2897
    uint8_t nic_selection=-1;
 
2898
        uint8_t nic_selection_failover = 0;
 
2899
 
 
2900
    struct ipmi_rs * rsp;
 
2901
    struct ipmi_rq req;
 
2902
 
 
2903
    uint8_t msg_data[30];
 
2904
    uint8_t input_length=0;
 
2905
 
 
2906
    input_length = 0;
 
2907
 
 
2908
        req.msg.netfn = DELL_OEM_NETFN;
 
2909
    req.msg.lun = 0;                
 
2910
        if(iDRAC_FLAG == IDRAC_12G)
 
2911
                req.msg.cmd = GET_NIC_SELECTION_12G_CMD;
 
2912
        else    
 
2913
    req.msg.cmd = GET_NIC_SELECTION_CMD;
 
2914
    req.msg.data = msg_data;
 
2915
    req.msg.data_len = input_length;
 
2916
 
 
2917
    rsp = intf->sendrecv(intf, &req);
 
2918
    if (rsp == NULL)
 
2919
    {
 
2920
        lprintf(LOG_ERR, " Error in getting nic selection");
 
2921
        return -1;
 
2922
    }
 
2923
    else if (rsp->ccode > 0) 
 
2924
    {
 
2925
        lprintf(LOG_ERR, " Error in getting nic selection (%s) \n",
 
2926
            val2str(rsp->ccode, completion_code_vals) );
 
2927
        return -1;
 
2928
    }
 
2929
    nic_selection = rsp->data[0];
 
2930
 
 
2931
        if(iDRAC_FLAG == IDRAC_12G)
 
2932
        {               
 
2933
                
 
2934
                nic_selection_failover = rsp->data[1];
 
2935
                if ((nic_selection < 6) && (nic_selection > 0) && (nic_selection_failover < 7))
 
2936
                {
 
2937
                        if(nic_selection == 1) {
 
2938
                                printf ("%s\n",NIC_Selection_Mode_String_12g[nic_selection-1]);
 
2939
                        } else if(nic_selection) {
 
2940
                                printf ("Shared LOM   :  %s\n",NIC_Selection_Mode_String_12g[nic_selection-1]);
 
2941
                                if(nic_selection_failover  == 0)
 
2942
                                        printf ("Failover LOM :  None\n");
 
2943
                                else if(nic_selection_failover   >= 2 && nic_selection_failover   <= 6)
 
2944
                                        printf ("Failover LOM :  %s\n",NIC_Selection_Mode_String_12g[nic_selection_failover + 3]);
 
2945
                        }
 
2946
                                
 
2947
                } 
 
2948
                else
 
2949
                {
 
2950
                        lprintf(LOG_ERR, " Error Outof bond Value received (%d) (%d) \n",nic_selection,nic_selection_failover);
 
2951
                        return -1;              
 
2952
                }
 
2953
        }
 
2954
        else
 
2955
        {
 
2956
                printf ("%s\n",NIC_Selection_Mode_String[nic_selection]);
 
2957
        }
 
2958
 
 
2959
    return 0;
 
2960
}      
 
2961
 
 
2962
static int ipmi_lan_get_active_nic (struct ipmi_intf* intf)
 
2963
{
 
2964
        uint8_t active_nic=0;
 
2965
        uint8_t current_lom =0;
 
2966
 
 
2967
    struct ipmi_rs * rsp;
 
2968
    struct ipmi_rq req;
 
2969
 
 
2970
    uint8_t msg_data[30];
 
2971
    uint8_t input_length=0;
 
2972
 
 
2973
    input_length = 0;
 
2974
 
 
2975
    msg_data[input_length++] = 0; /*Get Status*/
 
2976
    msg_data[input_length++] = 0; /*Reserved*/
 
2977
    msg_data[input_length++] = 0; /*Reserved*/        
 
2978
 
 
2979
        req.msg.netfn = DELL_OEM_NETFN;
 
2980
    req.msg.lun = 0;                
 
2981
    req.msg.cmd = GET_ACTIVE_NIC_CMD;
 
2982
    req.msg.data = msg_data;
 
2983
    req.msg.data_len = input_length;
 
2984
 
 
2985
    rsp = intf->sendrecv(intf, &req);
 
2986
    if (rsp == NULL)
 
2987
    {
 
2988
        lprintf(LOG_ERR, " Error in getting Active LOM Status");
 
2989
        return -1;
 
2990
    }
 
2991
    else if (rsp->ccode > 0) 
 
2992
    {
 
2993
        lprintf(LOG_ERR, " Error in getting Active LOM Status (%s) \n",
 
2994
            val2str(rsp->ccode, completion_code_vals) );
 
2995
        return -1;
 
2996
    }
 
2997
 
 
2998
        current_lom = rsp->data[0];
 
2999
 
 
3000
    input_length = 0;
 
3001
 
 
3002
        msg_data[input_length++] = 1; //Get Link status
 
3003
        msg_data[input_length++] = 0; //Reserved
 
3004
        msg_data[input_length++] = 0; //Reserved
 
3005
 
 
3006
        req.msg.netfn = DELL_OEM_NETFN;
 
3007
        req.msg.lun = 0;
 
3008
        req.msg.cmd = GET_ACTIVE_NIC_CMD;
 
3009
        req.msg.data = msg_data;
 
3010
        req.msg.data_len = input_length;
 
3011
 
 
3012
        rsp = intf->sendrecv(intf, &req);
 
3013
        if (rsp == NULL)
 
3014
        {
 
3015
                lprintf(LOG_ERR, " Error in getting Active LOM Status");
 
3016
                return -1;
 
3017
        }
 
3018
        else if (rsp->ccode > 0)
 
3019
        {
 
3020
                lprintf(LOG_ERR, " Error in getting Active LOM Status (%s) \n",
 
3021
                  val2str(rsp->ccode, completion_code_vals) );
 
3022
                return -1;
 
3023
        }
 
3024
        active_nic = rsp->data[1];
 
3025
        if (current_lom < 6 && active_nic)
 
3026
                printf ("\n%s\n",AciveLOM_String[current_lom]);
 
3027
        else
 
3028
                printf ("\n%s\n",AciveLOM_String[0]);
 
3029
 
 
3030
    return 0;
 
3031
}      
 
3032
 
 
3033
 
 
3034
static void
 
3035
ipmi_lan_usage(void)
 
3036
{
 
3037
    lprintf(LOG_NOTICE, "");
 
3038
    lprintf(LOG_NOTICE, "   lan set <Mode> ");
 
3039
 
 
3040
    lprintf(LOG_NOTICE, "      sets the NIC Selection Mode :");
 
3041
    lprintf(LOG_NOTICE, "          on iDRAC12g :");
 
3042
 
 
3043
    lprintf(LOG_NOTICE, "              dedicated, shared with lom1, shared with lom2,shared with lom3,shared ");
 
3044
    lprintf(LOG_NOTICE, "              with lom4,shared with failover lom1,shared with failover lom2,shared ");
 
3045
    lprintf(LOG_NOTICE, "              with failover lom3,shared with failover lom4,shared with Failover all ");
 
3046
    lprintf(LOG_NOTICE, "              loms, shared with Failover None).");
 
3047
    lprintf(LOG_NOTICE, "          on other systems :");
 
3048
    lprintf(LOG_NOTICE, "              dedicated, shared, shared with failover lom2,");
 
3049
    lprintf(LOG_NOTICE, "              shared with Failover all loms.");
 
3050
    lprintf(LOG_NOTICE, "");
 
3051
    lprintf(LOG_NOTICE, "   lan get ");
 
3052
    lprintf(LOG_NOTICE, "          on iDRAC12g :");
 
3053
    lprintf(LOG_NOTICE, "              returns the current NIC Selection Mode (dedicated, shared with lom1, shared ");
 
3054
    lprintf(LOG_NOTICE, "              with lom2, shared with lom3, shared with lom4,shared with failover lom1,");
 
3055
    lprintf(LOG_NOTICE, "              shared with failover lom2,shared with failover lom3,shared with failover ");
 
3056
    lprintf(LOG_NOTICE, "              lom4,shared with Failover all loms,shared with Failover None).");
 
3057
    lprintf(LOG_NOTICE, "          on other systems :");
 
3058
    lprintf(LOG_NOTICE, "              dedicated, shared, shared with failover,");
 
3059
    lprintf(LOG_NOTICE, "              lom2, shared with Failover all loms.");
 
3060
    lprintf(LOG_NOTICE, "");
 
3061
    lprintf(LOG_NOTICE, "   lan get active");
 
3062
    lprintf(LOG_NOTICE, "      returns the current active NIC (dedicated, LOM1, LOM2, LOM3, LOM4).");       
 
3063
    lprintf(LOG_NOTICE, "");
 
3064
 
 
3065
}
 
3066
 
 
3067
/*****************************************************************
 
3068
* Function Name:       ipmi_delloem_powermonitor_main
 
3069
*
 
3070
* Description:         This function processes the delloem powermonitor command
 
3071
* Input:               intf    - ipmi interface
 
3072
                       argc    - no of arguments
 
3073
                       argv    - argument string array
 
3074
* Output:        
 
3075
*
 
3076
* Return:              return code     0 - success
 
3077
*                         -1 - failure
 
3078
*
 
3079
******************************************************************/
 
3080
 
 
3081
static int ipmi_delloem_powermonitor_main (struct ipmi_intf * intf, int argc, char ** argv)
 
3082
{
 
3083
    int rc = 0;
 
3084
 
 
3085
    current_arg++;
 
3086
    if (argc > 1 && strcmp(argv[current_arg], "help") == 0)
 
3087
    {
 
3088
        ipmi_powermonitor_usage();
 
3089
        return 0;
 
3090
    }
 
3091
    ipmi_idracvalidator_command(intf);
 
3092
    if (argc == 1)
 
3093
    {
 
3094
        rc = ipmi_powermgmt(intf);
 
3095
    }
 
3096
    else if (strncmp(argv[current_arg], "status\0", 7) == 0) 
 
3097
    {
 
3098
        rc = ipmi_powermgmt(intf);
 
3099
    }
 
3100
 
 
3101
    else if (strncmp(argv[current_arg], "clear\0", 6) == 0) 
 
3102
    {
 
3103
        current_arg++;
 
3104
        if (argv[current_arg] == NULL) 
 
3105
        {
 
3106
            ipmi_powermonitor_usage();
 
3107
            return -1;
 
3108
        }
 
3109
        else if (strncmp(argv[current_arg], "peakpower\0", 10) == 0) 
 
3110
        {
 
3111
            rc = ipmi_powermgmt_clear(intf, 1);
 
3112
        }
 
3113
        else if (strncmp(argv[current_arg], "cumulativepower\0", 16) == 0) 
 
3114
        {
 
3115
            rc = ipmi_powermgmt_clear(intf, 0);
 
3116
        }
 
3117
        else 
 
3118
        {
 
3119
            ipmi_powermonitor_usage();
 
3120
            return -1;
 
3121
        }
 
3122
 
 
3123
    }
 
3124
 
 
3125
 
 
3126
    else if (strncmp(argv[current_arg], "powerconsumption\0", 17) == 0) 
 
3127
    {
 
3128
        current_arg++;
 
3129
 
 
3130
        if (argv[current_arg] == NULL)
 
3131
        {
 
3132
 
 
3133
            rc=ipmi_print_get_power_consmpt_data(intf,watt);
 
3134
 
 
3135
        }
 
3136
        else if (strncmp(argv[current_arg], "watt\0", 5) == 0) 
 
3137
        {
 
3138
 
 
3139
            rc = ipmi_print_get_power_consmpt_data(intf, watt);
 
3140
        }
 
3141
        else if (strncmp(argv[current_arg], "btuphr\0", 7) == 0) 
 
3142
        {
 
3143
            rc = ipmi_print_get_power_consmpt_data(intf, btuphr);
 
3144
        }
 
3145
        else
 
3146
        {
 
3147
            ipmi_powermonitor_usage();
 
3148
            return -1;
 
3149
        }
 
3150
    }
 
3151
    else if (strncmp(argv[current_arg], "powerconsumptionhistory\0", 23) == 0) 
 
3152
    {
 
3153
        current_arg++;
 
3154
        if (argv[current_arg] == NULL)
 
3155
        {
 
3156
            rc=ipmi_print_power_consmpt_history(intf,watt);
 
3157
 
 
3158
        }
 
3159
        else if (strncmp(argv[current_arg], "watt\0", 5) == 0) 
 
3160
        {
 
3161
            rc = ipmi_print_power_consmpt_history(intf, watt);
 
3162
        }
 
3163
        else if (strncmp(argv[current_arg], "btuphr\0", 7) == 0)
 
3164
        {
 
3165
            rc = ipmi_print_power_consmpt_history(intf, btuphr);
 
3166
        }
 
3167
        else
 
3168
        {
 
3169
            ipmi_powermonitor_usage();
 
3170
            return -1;
 
3171
        }
 
3172
 
 
3173
    }
 
3174
 
 
3175
    else if (strncmp(argv[current_arg], "getpowerbudget\0", 15) == 0)
 
3176
    {
 
3177
        current_arg++;
 
3178
        if (argv[current_arg] == NULL)
 
3179
        {
 
3180
            rc=ipmi_print_power_cap(intf,watt);
 
3181
 
 
3182
        }
 
3183
        else if (strncmp(argv[current_arg], "watt\0", 5) == 0)
 
3184
        {
 
3185
            rc = ipmi_print_power_cap(intf, watt);
 
3186
        }
 
3187
        else if (strncmp(argv[current_arg], "btuphr\0", 7) == 0)
 
3188
        {
 
3189
            rc = ipmi_print_power_cap(intf, btuphr);
 
3190
        }
 
3191
        else
 
3192
        {
 
3193
            ipmi_powermonitor_usage();
 
3194
            return -1;
 
3195
        }
 
3196
 
 
3197
    }
 
3198
 
 
3199
    else if (strncmp(argv[current_arg], "setpowerbudget\0", 15) == 0)
 
3200
    {
 
3201
        current_arg++;
 
3202
        int val;
 
3203
        if (argv[current_arg] == NULL)
 
3204
        { 
 
3205
            ipmi_powermonitor_usage();
 
3206
            return -1;
 
3207
        }
 
3208
                if (strchr(argv[current_arg], '.'))
 
3209
                {
 
3210
                        lprintf(LOG_ERR, " Cap value in Watts, Btu/hr or percent should be whole number");
 
3211
                        return -1;
 
3212
                }
 
3213
        make_int(argv[current_arg],&val);
 
3214
        current_arg++;
 
3215
        if (argv[current_arg] == NULL)
 
3216
        {       
 
3217
            ipmi_powermonitor_usage();
 
3218
        }
 
3219
        else if (strncmp(argv[current_arg], "watt\0", 5) == 0)
 
3220
        {
 
3221
            rc=ipmi_set_power_cap(intf,watt,val);
 
3222
        }
 
3223
        else if (strncmp(argv[current_arg], "btuphr\0", 7) == 0)
 
3224
        {
 
3225
            rc=ipmi_set_power_cap(intf, btuphr,val);
 
3226
        }
 
3227
        else if (strncmp(argv[current_arg], "percent\0", 8) == 0)
 
3228
        {
 
3229
            rc=ipmi_set_power_cap(intf,percent,val);
 
3230
        }
 
3231
        else
 
3232
        {
 
3233
            ipmi_powermonitor_usage();
 
3234
            return -1;
 
3235
        }
 
3236
 
 
3237
    }
 
3238
 
 
3239
    else if (strncmp(argv[current_arg], "enablepowercap\0", 15) == 0)
 
3240
    {
 
3241
        ipmi_set_power_capstatus_command(intf,1);
 
3242
    }
 
3243
 
 
3244
    else if (strncmp(argv[current_arg], "disablepowercap\0", 16) == 0)
 
3245
    {
 
3246
        ipmi_set_power_capstatus_command(intf,0);
 
3247
    }
 
3248
    else
 
3249
    {
 
3250
        ipmi_powermonitor_usage();
 
3251
        return -1;
 
3252
    }
 
3253
    return rc;
 
3254
}
 
3255
 
 
3256
 
 
3257
/*****************************************************************
 
3258
* Function Name:     ipmi_time_to_str
 
3259
*
 
3260
* Description:       This function converts ipmi time format into gmtime format
 
3261
* Input:             rawTime  - ipmi time format 
 
3262
* Output:            strTime  - gmtime format
 
3263
*
 
3264
* Return:              
 
3265
*
 
3266
******************************************************************/
 
3267
 
 
3268
static void
 
3269
ipmi_time_to_str(time_t rawTime, char* strTime)
 
3270
{
 
3271
    struct tm * tm;
 
3272
    char *temp;
 
3273
    tm = gmtime(&rawTime);
 
3274
 
 
3275
    temp = asctime(tm);
 
3276
 
 
3277
    strcpy(strTime,temp);
 
3278
}
 
3279
 
 
3280
/*****************************************************************
 
3281
* Function Name:      ipmi_get_sensor_reading
 
3282
*
 
3283
* Description:        This function retrieves a raw sensor reading
 
3284
* Input:              sensorOwner       - sensor owner id
 
3285
*                     sensorNumber      - sensor id
 
3286
*                     intf              - ipmi interface
 
3287
* Output:             sensorReadingData - ipmi response structure
 
3288
* Return:             1 on error
 
3289
*                     0 if successful
 
3290
*
 
3291
******************************************************************/
 
3292
static int
 
3293
ipmi_get_sensor_reading(struct ipmi_intf *intf ,
 
3294
                unsigned char sensorNumber,
 
3295
                        SensorReadingType* pSensorReadingData)
 
3296
{
 
3297
    struct ipmi_rq req;
 
3298
    struct ipmi_rs * rsp;
 
3299
    int rc = 0;
 
3300
 
 
3301
    memset(&req, 0, sizeof (req));
 
3302
    req.msg.netfn = IPMI_NETFN_SE;
 
3303
    req.msg.lun = 0;
 
3304
    req.msg.cmd = GET_SENSOR_READING;
 
3305
    req.msg.data = &sensorNumber;
 
3306
    req.msg.data_len = 1;
 
3307
 
 
3308
    if (NULL == pSensorReadingData)
 
3309
        return -1;
 
3310
    memset(pSensorReadingData,0, sizeof(SensorReadingType));        
 
3311
 
 
3312
    rsp = intf->sendrecv(intf, &req);
 
3313
    if (rsp == NULL) {
 
3314
        return 1;
 
3315
    } else if (rsp->ccode > 0) {
 
3316
        return 1;
 
3317
    }
 
3318
 
 
3319
    memcpy(pSensorReadingData, rsp->data, sizeof(SensorReadingType));
 
3320
 
 
3321
    /* if there is an error transmitting ipmi command, return error*/
 
3322
    if (rsp->ccode != 0) {
 
3323
        rc = 1;
 
3324
    }
 
3325
 
 
3326
    /* if sensor messages are disabled, return error*/
 
3327
    if ((!(rsp->data[1]& 0xC0)) || ((rsp->data[1] & 0x20))) {
 
3328
        rc =1;
 
3329
    }
 
3330
    return rc;
 
3331
}
 
3332
 
 
3333
 
 
3334
/*****************************************************************
 
3335
* Function Name:   ipmi_get_power_capstatus_command
 
3336
*
 
3337
* Description:     This function gets the power cap status
 
3338
* Input:           intf                 - ipmi interface
 
3339
* Global:          PowercapSetable_flag - power cap status
 
3340
* Output:                
 
3341
*
 
3342
* Return:              
 
3343
*
 
3344
******************************************************************/
 
3345
static int
 
3346
ipmi_get_power_capstatus_command (struct ipmi_intf * intf)
 
3347
{
 
3348
    struct ipmi_rs * rsp = NULL;
 
3349
    struct ipmi_rq req = {0};
 
3350
    uint8_t data[2];
 
3351
 
 
3352
    req.msg.netfn = DELL_OEM_NETFN;
 
3353
    req.msg.lun = 0;
 
3354
    req.msg.cmd = IPMI_DELL_POWER_CAP_STATUS;
 
3355
    req.msg.data_len = 2;
 
3356
    req.msg.data = data;
 
3357
    data[0] = 01;
 
3358
    data[1] = 0xFF;
 
3359
 
 
3360
    rsp = intf->sendrecv(intf, &req);
 
3361
    if (rsp == NULL) {
 
3362
        lprintf(LOG_ERR, " Error getting powercap status");
 
3363
                return -1;
 
3364
        } else if((iDRAC_FLAG == IDRAC_12G) && (rsp->ccode == LICENSE_NOT_SUPPORTED)) {
 
3365
                printf("FM001 : A required license is missing or expired\n");
 
3366
                return -1;      // Return Error as unlicensed
 
3367
    } else if (rsp->ccode > 0) {
 
3368
        lprintf(LOG_ERR, " Error getting powercap statusr: %s",
 
3369
            val2str(rsp->ccode, completion_code_vals));
 
3370
        return -1;
 
3371
    }
 
3372
    if (rsp->data[0]&0x02)
 
3373
        PowercapSetable_flag=1;
 
3374
    if(rsp->data[0]&0x01)
 
3375
        PowercapstatusFlag=1;
 
3376
    return 0;
 
3377
}
 
3378
 
 
3379
/*****************************************************************
 
3380
* Function Name:    ipmi_set_power_capstatus_command
 
3381
*
 
3382
* Description:      This function sets the power cap status
 
3383
* Input:            intf     - ipmi interface
 
3384
*                   val      - power cap status
 
3385
* Output:            
 
3386
*
 
3387
* Return:              
 
3388
*
 
3389
******************************************************************/
 
3390
 
 
3391
static int
 
3392
ipmi_set_power_capstatus_command (struct ipmi_intf * intf,uint8_t val)
 
3393
{
 
3394
    struct ipmi_rs * rsp = NULL;
 
3395
    struct ipmi_rq req = {0};
 
3396
    uint8_t data[2];
 
3397
        if(ipmi_get_power_capstatus_command(intf) < 0)
 
3398
                return -1;
 
3399
 
 
3400
    if (PowercapSetable_flag!=1)
 
3401
    {
 
3402
        lprintf(LOG_ERR, " Can not set powercap on this system");
 
3403
        return -1;
 
3404
    }
 
3405
    req.msg.netfn = DELL_OEM_NETFN;
 
3406
    req.msg.lun = 0;
 
3407
    req.msg.cmd = IPMI_DELL_POWER_CAP_STATUS;
 
3408
    req.msg.data_len = 2;
 
3409
    req.msg.data = data;
 
3410
 
 
3411
    data[0] = 00;
 
3412
    data[1] = val;
 
3413
 
 
3414
    rsp = intf->sendrecv(intf, &req);
 
3415
    if (rsp == NULL) {
 
3416
        lprintf(LOG_ERR, " Error setting powercap status");
 
3417
        return -1;
 
3418
        } else if((iDRAC_FLAG == IDRAC_12G) && (rsp->ccode == LICENSE_NOT_SUPPORTED)) {
 
3419
                printf("FM001 : A required license is missing or expired\n");
 
3420
                return -1;      //return unlicensed Error code
 
3421
    } else if (rsp->ccode > 0) {
 
3422
        lprintf(LOG_ERR, " Error setting powercap statusr: %s",
 
3423
            val2str(rsp->ccode, completion_code_vals));
 
3424
        return -1;
 
3425
    }
 
3426
 
 
3427
    return 0;
 
3428
}
 
3429
 
 
3430
 
 
3431
 
 
3432
/*****************************************************************
 
3433
* Function Name:    ipmi_powermgmt
 
3434
*
 
3435
* Description:      This function print the powermonitor details
 
3436
* Input:            intf     - ipmi interface
 
3437
* Output:              
 
3438
*
 
3439
* Return:              
 
3440
*
 
3441
******************************************************************/
 
3442
static int ipmi_powermgmt(struct ipmi_intf* intf)
 
3443
{
 
3444
    time_t now;
 
3445
    struct tm* tm;
 
3446
    char* dte;
 
3447
 
 
3448
    struct ipmi_rs * rsp;
 
3449
    struct ipmi_rq req;
 
3450
    uint8_t msg_data[2];
 
3451
    uint32_t cumStartTimeConv;
 
3452
    uint32_t cumReadingConv;
 
3453
    uint32_t maxPeakStartTimeConv;
 
3454
    uint32_t ampPeakTimeConv;
 
3455
    uint16_t ampReadingConv;
 
3456
    uint32_t wattPeakTimeConv;
 
3457
    uint32_t wattReadingConv;
 
3458
    uint32_t bmctimeconv;
 
3459
    uint32_t * bmctimeconvval;
 
3460
 
 
3461
    IPMI_POWER_MONITOR* pwrMonitorInfo;
 
3462
 
 
3463
 
 
3464
    char cumStartTime[26];
 
3465
    char maxPeakStartTime[26];
 
3466
    char ampPeakTime[26];
 
3467
    char wattPeakTime[26];
 
3468
    char bmctime[26];
 
3469
 
 
3470
    int ampReading;
 
3471
    int wattReading;
 
3472
    int ampReadingRemainder;
 
3473
 
 
3474
    now = time(0);
 
3475
    tm = gmtime(&now);
 
3476
    dte = asctime(tm);
 
3477
 
 
3478
    memset(&req, 0, sizeof(req));
 
3479
    req.msg.netfn = IPMI_NETFN_STORAGE;
 
3480
    req.msg.lun = 0;
 
3481
    req.msg.cmd = IPMI_CMD_GET_SEL_TIME;
 
3482
 
 
3483
    rsp = intf->sendrecv(intf, &req);
 
3484
    if (rsp == NULL) {
 
3485
        lprintf(LOG_ERR, " Error getting BMC time info.\n");
 
3486
        return -1;
 
3487
    } 
 
3488
    if (rsp->ccode != 0) {
 
3489
        printf("Error getting power management information, return code %x\n", rsp->ccode);
 
3490
        return -1;
 
3491
    }
 
3492
    bmctimeconvval=(uint32_t*)rsp->data;
 
3493
#if WORDS_BIGENDIAN
 
3494
    bmctimeconv=BSWAP_32(*bmctimeconvval);
 
3495
#else
 
3496
    bmctimeconv=*bmctimeconvval;
 
3497
#endif
 
3498
 
 
3499
    /* get powermanagement info*/
 
3500
    req.msg.netfn = DELL_OEM_NETFN;
 
3501
    req.msg.lun = 0x0;
 
3502
    req.msg.cmd = GET_PWRMGMT_INFO_CMD;
 
3503
    req.msg.data = msg_data;
 
3504
    req.msg.data_len = 2;
 
3505
 
 
3506
    memset(msg_data, 0, 2);
 
3507
    msg_data[0] = 0x07;     
 
3508
    msg_data[1] = 0x01;
 
3509
 
 
3510
    rsp = intf->sendrecv(intf, &req);
 
3511
    if (rsp == NULL) {
 
3512
        lprintf(LOG_ERR, " Error getting power management information.\n");
 
3513
        return -1;
 
3514
    } 
 
3515
 
 
3516
        if((iDRAC_FLAG == IDRAC_12G) && (rsp->ccode == LICENSE_NOT_SUPPORTED)) {
 
3517
                printf("FM001 : A required license is missing or expired\n");
 
3518
                return -1;      
 
3519
        } else if ((rsp->ccode == 0xc1)||(rsp->ccode == 0xcb)) {
 
3520
        lprintf(LOG_ERR, " Error getting power management information: Command not supported on this system.");
 
3521
        return -1;
 
3522
    }else if (rsp->ccode != 0) {
 
3523
        printf("Error getting power management information, return code %x\n", rsp->ccode);
 
3524
        return -1;
 
3525
    }
 
3526
 
 
3527
 
 
3528
 
 
3529
    pwrMonitorInfo = (IPMI_POWER_MONITOR*)rsp->data;
 
3530
#if WORDS_BIGENDIAN
 
3531
    cumStartTimeConv = BSWAP_32(pwrMonitorInfo->cumStartTime);
 
3532
    cumReadingConv = BSWAP_32(pwrMonitorInfo->cumReading);
 
3533
    maxPeakStartTimeConv = BSWAP_32(pwrMonitorInfo->maxPeakStartTime);
 
3534
    ampPeakTimeConv = BSWAP_32(pwrMonitorInfo->ampPeakTime);
 
3535
    ampReadingConv = BSWAP_16(pwrMonitorInfo->ampReading);
 
3536
    wattPeakTimeConv = BSWAP_32(pwrMonitorInfo->wattPeakTime);
 
3537
    wattReadingConv = BSWAP_16(pwrMonitorInfo->wattReading);
 
3538
#else
 
3539
    cumStartTimeConv = pwrMonitorInfo->cumStartTime;
 
3540
    cumReadingConv = pwrMonitorInfo->cumReading;
 
3541
    maxPeakStartTimeConv = pwrMonitorInfo->maxPeakStartTime;
 
3542
    ampPeakTimeConv = pwrMonitorInfo->ampPeakTime;
 
3543
    ampReadingConv = pwrMonitorInfo->ampReading;
 
3544
    wattPeakTimeConv = pwrMonitorInfo->wattPeakTime;
 
3545
    wattReadingConv = pwrMonitorInfo->wattReading;
 
3546
#endif
 
3547
 
 
3548
    ipmi_time_to_str(cumStartTimeConv, cumStartTime);
 
3549
 
 
3550
    ipmi_time_to_str(maxPeakStartTimeConv, maxPeakStartTime);
 
3551
    ipmi_time_to_str(ampPeakTimeConv, ampPeakTime);
 
3552
    ipmi_time_to_str(wattPeakTimeConv, wattPeakTime);
 
3553
    ipmi_time_to_str(bmctimeconv, bmctime);
 
3554
 
 
3555
 
 
3556
 
 
3557
    now = time(0);
 
3558
 
 
3559
    int remainder;
 
3560
 
 
3561
    remainder = (cumReadingConv % 1000);
 
3562
    cumReadingConv = cumReadingConv / 1000;
 
3563
    remainder = (remainder + 50) / 100;
 
3564
 
 
3565
    ampReading = ampReadingConv;
 
3566
    ampReadingRemainder = ampReading%10;
 
3567
    ampReading = ampReading/10;
 
3568
 
 
3569
    wattReading = wattReadingConv;
 
3570
 
 
3571
    printf("Power Tracking Statistics\n");
 
3572
    printf("Statistic      : Cumulative Energy Consumption\n");
 
3573
    printf("Start Time     : %s", cumStartTime);
 
3574
    printf("Finish Time    : %s", bmctime);
 
3575
    printf("Reading        : %d.%d kWh\n\n", cumReadingConv, remainder);
 
3576
 
 
3577
    printf("Statistic      : System Peak Power\n");
 
3578
    printf("Start Time     : %s", maxPeakStartTime);
 
3579
    printf("Peak Time      : %s", wattPeakTime);
 
3580
    printf("Peak Reading   : %d W\n\n", wattReading);
 
3581
 
 
3582
    printf("Statistic      : System Peak Amperage\n");
 
3583
    printf("Start Time     : %s", maxPeakStartTime);
 
3584
    printf("Peak Time      : %s", ampPeakTime);
 
3585
    printf("Peak Reading   : %d.%d A\n", ampReading, ampReadingRemainder);
 
3586
 
 
3587
 
 
3588
    return 0;
 
3589
 
 
3590
}
 
3591
/*****************************************************************
 
3592
* Function Name:    ipmi_powermgmt_clear
 
3593
*
 
3594
* Description:     This function clears peakpower / cumulativepower value
 
3595
* Input:           intf           - ipmi interface
 
3596
*                  clearValue     - peakpower / cumulativepower
 
3597
* Output:          
 
3598
*
 
3599
* Return:              
 
3600
*
 
3601
******************************************************************/
 
3602
static int
 
3603
ipmi_powermgmt_clear(struct ipmi_intf* intf,uint8_t clearValue)
 
3604
{
 
3605
    struct ipmi_rs * rsp;
 
3606
    struct ipmi_rq req;
 
3607
    uint8_t clearType;
 
3608
    uint8_t msg_data[3];
 
3609
 
 
3610
    if (clearValue) {
 
3611
        clearType = 2;
 
3612
    } else {
 
3613
        clearType = 1;
 
3614
    }
 
3615
 
 
3616
    /* clear powermanagement info*/
 
3617
    req.msg.netfn = DELL_OEM_NETFN;
 
3618
    req.msg.lun = 0;
 
3619
    req.msg.cmd = CLEAR_PWRMGMT_INFO_CMD;
 
3620
    req.msg.data = msg_data;
 
3621
    req.msg.data_len = 3;
 
3622
 
 
3623
 
 
3624
    memset(msg_data, 0, 3);
 
3625
    msg_data[0] = 0x07;
 
3626
    msg_data[1] = 0x01;
 
3627
    msg_data[2] = clearType;
 
3628
 
 
3629
 
 
3630
 
 
3631
    rsp = intf->sendrecv(intf, &req);
 
3632
    if (rsp == NULL) {
 
3633
        lprintf(LOG_ERR, " Error clearing power values.\n");
 
3634
        return -1;
 
3635
} else if((iDRAC_FLAG == IDRAC_12G) && (rsp->ccode == LICENSE_NOT_SUPPORTED)) {
 
3636
                printf("FM001 : A required license is missing or expired\n");
 
3637
                return -1;      
 
3638
    } else if (rsp->ccode == 0xc1) {
 
3639
        lprintf(LOG_ERR, " Error clearing power values, command not supported on this system.\n");
 
3640
        return -1;
 
3641
    } else if (rsp->ccode != 0){
 
3642
        lprintf(LOG_ERR, " Error clearing power values: %s",
 
3643
            val2str(rsp->ccode, completion_code_vals));
 
3644
        return -1;
 
3645
    }
 
3646
        return 0;
 
3647
 
 
3648
}
 
3649
 
 
3650
/*****************************************************************
 
3651
* Function Name:    watt_to_btuphr_conversion
 
3652
*
 
3653
* Description:      This function converts the power value in watt to btuphr
 
3654
* Input:            powerinwatt     - power in watt
 
3655
*                               
 
3656
* Output:           power in btuphr
 
3657
*
 
3658
* Return:              
 
3659
*
 
3660
******************************************************************/
 
3661
static uint64_t watt_to_btuphr_conversion(uint32_t powerinwatt)
 
3662
{
 
3663
    uint64_t powerinbtuphr;
 
3664
    powerinbtuphr=(3.413*powerinwatt);
 
3665
 
 
3666
    return(powerinbtuphr);
 
3667
 
 
3668
 
 
3669
}
 
3670
 
 
3671
/*****************************************************************
 
3672
* Function Name:    btuphr_to_watt_conversion
 
3673
*
 
3674
* Description:      This function converts the power value in  btuphr to watt
 
3675
* Input:            powerinbtuphr   - power in btuphr
 
3676
*                              
 
3677
* Output:           power in watt
 
3678
*
 
3679
* Return:                
 
3680
*
 
3681
******************************************************************/
 
3682
static uint32_t btuphr_to_watt_conversion(uint64_t powerinbtuphr)
 
3683
{
 
3684
    uint32_t powerinwatt;
 
3685
    /*returning the floor value*/
 
3686
    powerinwatt= (powerinbtuphr/3.413);
 
3687
    return (powerinwatt);
 
3688
}
 
3689
 
 
3690
/*****************************************************************
 
3691
* Function Name:        ipmi_get_power_headroom_command
 
3692
*
 
3693
* Description:          This function prints the Power consumption information
 
3694
* Input:                intf    - ipmi interface
 
3695
*                       unit    - watt / btuphr
 
3696
* Output:           
 
3697
*
 
3698
* Return:              
 
3699
*
 
3700
******************************************************************/
 
3701
static int ipmi_get_power_headroom_command (struct ipmi_intf * intf,uint8_t unit)
 
3702
{
 
3703
    struct ipmi_rs * rsp = NULL;
 
3704
    struct ipmi_rq req = {0};
 
3705
    uint64_t peakpowerheadroombtuphr;
 
3706
    uint64_t instantpowerhearoom;
 
3707
 
 
3708
    req.msg.netfn = DELL_OEM_NETFN;
 
3709
    req.msg.lun = 0;
 
3710
    req.msg.cmd = GET_PWR_HEADROOM_CMD;
 
3711
    req.msg.data_len = 0;
 
3712
 
 
3713
    rsp = intf->sendrecv(intf, &req);
 
3714
    if (rsp == NULL) {
 
3715
        lprintf(LOG_ERR, " Error getting power headroom status");
 
3716
        return -1;
 
3717
} else if((iDRAC_FLAG == IDRAC_12G) && (rsp->ccode == LICENSE_NOT_SUPPORTED)) {
 
3718
                printf("FM001 : A required license is missing or expired\n");
 
3719
                return -1;      
 
3720
    } else if ((rsp->ccode == 0xc1)||(rsp->ccode == 0xcb)){
 
3721
        lprintf(LOG_ERR, " Error getting power headroom status: Command not supported on this system ");
 
3722
        return -1;
 
3723
    } else if (rsp->ccode > 0) {
 
3724
        lprintf(LOG_ERR, " Error getting power headroom status: %s",
 
3725
            val2str(rsp->ccode, completion_code_vals));
 
3726
        return -1;
 
3727
    }
 
3728
    if(verbose>1)
 
3729
        printf("power headroom  Data               : %x %x %x %x ",
 
3730
        /*need to look into */                                                                  rsp->data[0], rsp->data[1], rsp->data[2], rsp->data[3]);
 
3731
    powerheadroom= *(( POWER_HEADROOM *)rsp->data);
 
3732
#if WORDS_BIGENDIAN
 
3733
    powerheadroom.instheadroom = BSWAP_16(powerheadroom.instheadroom);
 
3734
    powerheadroom.peakheadroom = BSWAP_16(powerheadroom.peakheadroom);
 
3735
#endif
 
3736
 
 
3737
    printf ("Headroom\n");
 
3738
    printf ("Statistic                     Reading\n");   
 
3739
 
 
3740
    if(unit == btuphr)
 
3741
    {
 
3742
        peakpowerheadroombtuphr=watt_to_btuphr_conversion(powerheadroom.peakheadroom);
 
3743
        instantpowerhearoom= watt_to_btuphr_conversion(powerheadroom.instheadroom);
 
3744
 
 
3745
        printf ("System Instantaneous Headroom : %lld BTU/hr\n",instantpowerhearoom);
 
3746
                printf ("System Peak Headroom          : %lld BTU/hr\n",peakpowerheadroombtuphr);
 
3747
        }
 
3748
        else
 
3749
        {
 
3750
        printf ("System Instantaneous Headroom : %d W\n",powerheadroom.instheadroom);
 
3751
                printf ("System Peak Headroom          : %d W\n",powerheadroom.peakheadroom);
 
3752
        }
 
3753
 
 
3754
    return 0;
 
3755
}
 
3756
 
 
3757
 
 
3758
 
 
3759
/*****************************************************************
 
3760
* Function Name:       ipmi_get_power_consumption_data
 
3761
*
 
3762
* Description:         This function updates the instant Power consumption information
 
3763
* Input:               intf - ipmi interface
 
3764
* Output:              power consumption current reading 
 
3765
*                      Assumption value will be in Watt.
 
3766
*
 
3767
* Return:               
 
3768
*
 
3769
******************************************************************/
 
3770
static int ipmi_get_power_consumption_data(struct ipmi_intf* intf,uint8_t unit)
 
3771
{
 
3772
    SensorReadingType sensorReadingData;
 
3773
 
 
3774
    struct ipmi_rs * rsp=NULL;
 
3775
    struct sdr_record_list *sdr;
 
3776
    int readingbtuphr=0;
 
3777
    int warning_threshbtuphr=0;
 
3778
    int failure_threshbtuphr=0;
 
3779
    int status=0;
 
3780
    int sensor_number = 0;
 
3781
 
 
3782
 
 
3783
    sdr = ipmi_sdr_find_sdr_byid(intf, "System Level");
 
3784
    if (NULL ==sdr)
 
3785
    {
 
3786
        printf ("Error : Can not access the System Level sensor data \n\n");
 
3787
        return -1;
 
3788
    }
 
3789
 
 
3790
    sensor_number = sdr->record.common->keys.sensor_num;
 
3791
    ipmi_get_sensor_reading (intf,sensor_number,&sensorReadingData);
 
3792
 
 
3793
    rsp = ipmi_sdr_get_sensor_thresholds(intf,
 
3794
        sdr->record.common->keys.sensor_num,
 
3795
        sdr->record.common->keys.owner_id,
 
3796
        sdr->record.common->keys.lun,
 
3797
        sdr->record.common->keys.channel);
 
3798
 
 
3799
    if (rsp != NULL && rsp->ccode == 0)
 
3800
    {
 
3801
        readingbtuphr=sdr_convert_sensor_reading
 
3802
            (sdr->record.full, sensorReadingData.sensorReading);
 
3803
        warning_threshbtuphr=sdr_convert_sensor_reading
 
3804
            (sdr->record.full, rsp->data[4]);
 
3805
        failure_threshbtuphr=sdr_convert_sensor_reading
 
3806
            (sdr->record.full, rsp->data[5]);                                                
 
3807
 
 
3808
        printf ("System Board System Level\n");
 
3809
        if (unit==btuphr)
 
3810
        {
 
3811
            readingbtuphr= watt_to_btuphr_conversion(readingbtuphr);
 
3812
            warning_threshbtuphr= watt_to_btuphr_conversion(warning_threshbtuphr);
 
3813
            failure_threshbtuphr= watt_to_btuphr_conversion( failure_threshbtuphr);
 
3814
 
 
3815
            printf ("Reading                        : %d BTU/hr\n",readingbtuphr);
 
3816
            printf ("Warning threshold      : %d BTU/hr\n",warning_threshbtuphr);
 
3817
            printf ("Failure threshold      : %d BTU/hr\n",failure_threshbtuphr);
 
3818
        }
 
3819
        else
 
3820
        {
 
3821
            printf ("Reading                        : %d W \n",readingbtuphr);              
 
3822
            printf ("Warning threshold      : %d W \n",(warning_threshbtuphr));
 
3823
            printf ("Failure threshold      : %d W \n",(failure_threshbtuphr));
 
3824
        }
 
3825
    }
 
3826
    else
 
3827
    {
 
3828
        printf ("Error : Can not access the System Level sensor data \n\n");
 
3829
        return -1;              
 
3830
    }       
 
3831
    return status;
 
3832
}
 
3833
 
 
3834
 
 
3835
 
 
3836
 
 
3837
/*****************************************************************
 
3838
* Function Name:      ipmi_get_instan_power_consmpt_data
 
3839
*
 
3840
* Description:        This function updates the instant Power consumption information
 
3841
* Input:              intf - ipmi interface
 
3842
* Output:             instpowerconsumptiondata - instant Power consumption information
 
3843
*
 
3844
* Return:              
 
3845
*
 
3846
******************************************************************/
 
3847
 
 
3848
static int ipmi_get_instan_power_consmpt_data(struct ipmi_intf* intf,
 
3849
                                              IPMI_INST_POWER_CONSUMPTION_DATA* instpowerconsumptiondata)
 
3850
{
 
3851
 
 
3852
    struct ipmi_rs * rsp;
 
3853
    struct ipmi_rq req={0};
 
3854
 
 
3855
    uint8_t msg_data[2];
 
3856
 
 
3857
 
 
3858
    /*get instantaneous power consumption command*/
 
3859
    req.msg.netfn = DELL_OEM_NETFN;
 
3860
    req.msg.lun = 0;
 
3861
    req.msg.cmd = GET_PWR_CONSUMPTION_CMD;
 
3862
 
 
3863
    req.msg.data = msg_data;
 
3864
    req.msg.data_len = 2;
 
3865
 
 
3866
 
 
3867
 
 
3868
    memset(msg_data, 0, 2);
 
3869
 
 
3870
    msg_data[0] = 0x0A;     
 
3871
    msg_data[1] = 0x00;
 
3872
 
 
3873
 
 
3874
    rsp = intf->sendrecv(intf, &req);
 
3875
    if (rsp == NULL) {
 
3876
        lprintf(LOG_ERR, " Error getting instantaneous power consumption data .\n");
 
3877
 
 
3878
        return -1;
 
3879
        } else if((iDRAC_FLAG == IDRAC_12G) && (rsp->ccode == LICENSE_NOT_SUPPORTED)) {
 
3880
                printf("FM001 : A required license is missing or expired\n");
 
3881
                return -1;      
 
3882
    } else if ((rsp->ccode == 0xc1)||(rsp->ccode == 0xcb)) {
 
3883
        lprintf(LOG_ERR, "  Error getting instantaneous power consumption data: Command not supported on this system.");
 
3884
        return -1;
 
3885
    } else if (rsp->ccode != 0){
 
3886
        lprintf(LOG_ERR, "  Error getting instantaneous power consumption data: %s",
 
3887
            val2str(rsp->ccode, completion_code_vals));
 
3888
 
 
3889
        return -1;
 
3890
    }
 
3891
 
 
3892
    * instpowerconsumptiondata = * ( (IPMI_INST_POWER_CONSUMPTION_DATA*) (rsp->data));
 
3893
#if WORDS_BIGENDIAN
 
3894
    instpowerconsumptiondata->instanpowerconsumption = BSWAP_16(instpowerconsumptiondata->instanpowerconsumption);
 
3895
    instpowerconsumptiondata->instanApms = BSWAP_16(instpowerconsumptiondata->instanApms);
 
3896
    instpowerconsumptiondata->resv1 = BSWAP_16(instpowerconsumptiondata->resv1);
 
3897
#endif
 
3898
 
 
3899
    return 0;
 
3900
 
 
3901
 
 
3902
}
 
3903
 
 
3904
 
 
3905
/*****************************************************************
 
3906
* Function Name:      ipmi_print_get_instan_power_Amps_data
 
3907
*
 
3908
* Description:        This function prints the instant Power consumption information
 
3909
* Input:              instpowerconsumptiondata - instant Power consumption information
 
3910
* Output:               
 
3911
*
 
3912
* Return:              
 
3913
*
 
3914
******************************************************************/
 
3915
static void ipmi_print_get_instan_power_Amps_data(IPMI_INST_POWER_CONSUMPTION_DATA instpowerconsumptiondata)
 
3916
{
 
3917
    uint16_t intampsval=0;
 
3918
    uint16_t decimalampsval=0;
 
3919
 
 
3920
 
 
3921
    if (instpowerconsumptiondata.instanApms>0)
 
3922
    {
 
3923
        decimalampsval=(instpowerconsumptiondata.instanApms%10);
 
3924
        intampsval=instpowerconsumptiondata.instanApms/10;
 
3925
    }
 
3926
    printf("\nAmperage value: %d.%d A \n",intampsval,decimalampsval);
 
3927
}
 
3928
/*****************************************************************
 
3929
* Function Name:     ipmi_print_get_power_consmpt_data
 
3930
*
 
3931
* Description:       This function prints the Power consumption information
 
3932
* Input:             intf            - ipmi interface
 
3933
*                    unit            - watt / btuphr 
 
3934
* Output:               
 
3935
*
 
3936
* Return:              
 
3937
*
 
3938
******************************************************************/
 
3939
static int ipmi_print_get_power_consmpt_data(struct ipmi_intf* intf,uint8_t  unit)
 
3940
{
 
3941
 
 
3942
    int rc = 0;
 
3943
 
 
3944
    IPMI_INST_POWER_CONSUMPTION_DATA instpowerconsumptiondata = {0,0,0,0};
 
3945
 
 
3946
    printf ("\nPower consumption information\n");
 
3947
 
 
3948
 
 
3949
    rc=ipmi_get_power_consumption_data(intf,unit);
 
3950
    if (-1 == rc)
 
3951
        return rc;
 
3952
 
 
3953
    rc=ipmi_get_instan_power_consmpt_data(intf,&instpowerconsumptiondata);
 
3954
    if (-1 == rc)
 
3955
        return rc;
 
3956
 
 
3957
    ipmi_print_get_instan_power_Amps_data(instpowerconsumptiondata);
 
3958
 
 
3959
 
 
3960
    rc=ipmi_get_power_headroom_command(intf,unit);      
 
3961
 
 
3962
    if (-1 == rc)
 
3963
        return rc;
 
3964
 
 
3965
    return rc;
 
3966
 
 
3967
 
 
3968
}
 
3969
 
 
3970
 
 
3971
/*****************************************************************
 
3972
* Function Name:   ipmi_get_avgpower_consmpt_history
 
3973
*
 
3974
* Description:     This function updates the average power consumption information
 
3975
* Input:           intf            - ipmi interface
 
3976
* Output:          pavgpower- average power consumption information
 
3977
*
 
3978
* Return:              
 
3979
*
 
3980
******************************************************************/
 
3981
static int ipmi_get_avgpower_consmpt_history(struct ipmi_intf* intf,IPMI_AVGPOWER_CONSUMP_HISTORY* pavgpower )
 
3982
{
 
3983
    struct ipmi_rs * rsp = NULL;
 
3984
    struct ipmi_rq req = {0};
 
3985
    uint8_t data[4];
 
3986
 
 
3987
    req.msg.netfn = IPMI_NETFN_APP;
 
3988
    req.msg.lun = 0;
 
3989
    req.msg.cmd = IPMI_GET_SYS_INFO;
 
3990
    req.msg.data_len = 4;
 
3991
    req.msg.data = data;
 
3992
    data[0] = 0;
 
3993
    data[1] = 0xeb;
 
3994
    data[2] = 0;
 
3995
    data[3] = 0;
 
3996
 
 
3997
    rsp = intf->sendrecv(intf, &req);
 
3998
 
 
3999
    if (rsp == NULL)
 
4000
    {
 
4001
        lprintf(LOG_ERR, " Error getting average power consumption history data .\n");
 
4002
        return -1;
 
4003
    } 
 
4004
        else if((iDRAC_FLAG == IDRAC_12G) &&  (rsp->ccode == LICENSE_NOT_SUPPORTED)) {
 
4005
                printf("FM001 : A required license is missing or expired\n");
 
4006
                return -1;      
 
4007
        } else if ((rsp->ccode == 0xc1)||(rsp->ccode == 0xcb))
 
4008
    {
 
4009
        lprintf(LOG_ERR, "  Error getting average power consumption  history data: Command not supported on this system.");
 
4010
        return -1;
 
4011
    }
 
4012
    else if (rsp->ccode != 0)
 
4013
    {
 
4014
        lprintf(LOG_ERR, "  Error getting average power consumption historydata: %s",
 
4015
            val2str(rsp->ccode, completion_code_vals));
 
4016
 
 
4017
        return -1;
 
4018
    }
 
4019
 
 
4020
    if (verbose > 1)
 
4021
    {
 
4022
        printf("Average power consumption history  Data               :%x %x %x %x %x %x %x\n\n",
 
4023
            rsp->data[0], rsp->data[1], rsp->data[2], rsp->data[3], 
 
4024
            rsp->data[4], rsp->data[5], rsp->data[6], rsp->data[7]);
 
4025
 
 
4026
    }
 
4027
 
 
4028
    *pavgpower = *( (IPMI_AVGPOWER_CONSUMP_HISTORY*) rsp->data);
 
4029
#if WORDS_BIGENDIAN
 
4030
    pavgpower->lastminutepower = BSWAP_16(pavgpower->lastminutepower);
 
4031
    pavgpower->lasthourpower = BSWAP_16(pavgpower->lasthourpower);
 
4032
    pavgpower->lastdaypower = BSWAP_16(pavgpower->lastdaypower);
 
4033
    pavgpower->lastweakpower = BSWAP_16(pavgpower->lastweakpower);
 
4034
#endif
 
4035
 
 
4036
    return 0;
 
4037
}
 
4038
 
 
4039
/*****************************************************************
 
4040
* Function Name:    ipmi_get_peakpower_consmpt_history
 
4041
*
 
4042
* Description:      This function updates the peak power consumption information
 
4043
* Input:            intf            - ipmi interface
 
4044
* Output:           pavgpower- peak power consumption information
 
4045
*
 
4046
* Return:         
 
4047
*
 
4048
******************************************************************/
 
4049
static int ipmi_get_peakpower_consmpt_history(struct ipmi_intf* intf,IPMI_POWER_CONSUMP_HISTORY * pstPeakpower)
 
4050
{
 
4051
 
 
4052
    struct ipmi_rs * rsp = NULL;
 
4053
    struct ipmi_rq req = {0};
 
4054
    uint8_t data[4];
 
4055
 
 
4056
    req.msg.netfn = IPMI_NETFN_APP;
 
4057
    req.msg.lun = 0;
 
4058
    req.msg.cmd = IPMI_GET_SYS_INFO;
 
4059
    req.msg.data_len = 4;
 
4060
    req.msg.data = data;
 
4061
    data[0] = 0;
 
4062
    data[1] = 0xec;
 
4063
    data[2] = 0;
 
4064
    data[3] = 0;
 
4065
 
 
4066
    rsp = intf->sendrecv(intf, &req);
 
4067
 
 
4068
    if (rsp == NULL)
 
4069
    {
 
4070
        lprintf(LOG_ERR, " Error getting  peak power consumption history data .\n");
 
4071
        return -1;
 
4072
    }
 
4073
        else if((iDRAC_FLAG == IDRAC_12G) && (rsp->ccode == LICENSE_NOT_SUPPORTED)) {
 
4074
                printf("FM001 : A required license is missing or expired\n");
 
4075
                return -1;      
 
4076
        } else if ((rsp->ccode == 0xc1)||(rsp->ccode == 0xcb))
 
4077
    {
 
4078
        lprintf(LOG_ERR, "  Error getting peak power consumption history data: Command not supported on this system.");
 
4079
        return -1;
 
4080
    }
 
4081
    else if (rsp->ccode != 0)
 
4082
    {
 
4083
        lprintf(LOG_ERR, "  Error getting peak power consumption history data: %s",
 
4084
            val2str(rsp->ccode, completion_code_vals));
 
4085
        return -1;
 
4086
    }
 
4087
 
 
4088
    if (verbose > 1)
 
4089
    {
 
4090
        printf("Peak power consmhistory  Data               : %x %x %x %x %x %x %x %x %x %x\n   %x %x %x %x %x %x %x %x %x %x %x %x %x\n\n",
 
4091
            rsp->data[0], rsp->data[1], rsp->data[2], rsp->data[3], 
 
4092
            rsp->data[4], rsp->data[5], rsp->data[6], rsp->data[7], 
 
4093
            rsp->data[8], rsp->data[9], rsp->data[10], rsp->data[11], 
 
4094
            rsp->data[12], rsp->data[13], rsp->data[14], rsp->data[15], 
 
4095
            rsp->data[16], rsp->data[17], rsp->data[18], rsp->data[19],  
 
4096
            rsp->data[20], rsp->data[21], rsp->data[22], rsp->data[23]
 
4097
        );
 
4098
 
 
4099
    }
 
4100
    *pstPeakpower =* ((IPMI_POWER_CONSUMP_HISTORY*)rsp->data);
 
4101
#if WORDS_BIGENDIAN
 
4102
    pstPeakpower->lastminutepower = BSWAP_16(pstPeakpower->lastminutepower);
 
4103
    pstPeakpower->lasthourpower = BSWAP_16(pstPeakpower->lasthourpower);
 
4104
    pstPeakpower->lastdaypower = BSWAP_16(pstPeakpower->lastdaypower);
 
4105
    pstPeakpower->lastweakpower = BSWAP_16(pstPeakpower->lastweakpower);
 
4106
    pstPeakpower->lastminutepowertime = BSWAP_32(pstPeakpower->lastminutepowertime);
 
4107
    pstPeakpower->lasthourpowertime = BSWAP_32(pstPeakpower->lasthourpowertime);
 
4108
    pstPeakpower->lastdaypowertime = BSWAP_32(pstPeakpower->lastdaypowertime);
 
4109
    pstPeakpower->lastweekpowertime = BSWAP_32(pstPeakpower->lastweekpowertime);
 
4110
#endif
 
4111
    return 0;
 
4112
}
 
4113
 
 
4114
 
 
4115
/*****************************************************************
 
4116
* Function Name:    ipmi_get_minpower_consmpt_history
 
4117
*
 
4118
* Description:      This function updates the peak power consumption information
 
4119
* Input:            intf            - ipmi interface
 
4120
* Output:           pavgpower- peak power consumption information
 
4121
*
 
4122
* Return:         
 
4123
*
 
4124
******************************************************************/
 
4125
static int ipmi_get_minpower_consmpt_history(struct ipmi_intf* intf,IPMI_POWER_CONSUMP_HISTORY * pstMinpower)
 
4126
{
 
4127
 
 
4128
    struct ipmi_rs * rsp = NULL;
 
4129
    struct ipmi_rq req = {0};
 
4130
    uint8_t data[4];
 
4131
 
 
4132
    req.msg.netfn = IPMI_NETFN_APP;
 
4133
    req.msg.lun = 0;
 
4134
    req.msg.cmd = IPMI_GET_SYS_INFO;
 
4135
    req.msg.data_len = 4;
 
4136
    req.msg.data = data;
 
4137
    data[0] = 0;
 
4138
    data[1] = 0xed;
 
4139
    data[2] = 0;
 
4140
    data[3] = 0;
 
4141
 
 
4142
    rsp = intf->sendrecv(intf, &req);
 
4143
 
 
4144
    if (rsp == NULL)
 
4145
    {
 
4146
        lprintf(LOG_ERR, " Error getting  peak power consumption history data .\n");
 
4147
        return -1;
 
4148
    }
 
4149
        else if((iDRAC_FLAG == IDRAC_12G) &&  (rsp->ccode == LICENSE_NOT_SUPPORTED)) {
 
4150
                printf("FM001 : A required license is missing or expired\n");
 
4151
                return -1;      
 
4152
        } else if ((rsp->ccode == 0xc1)||(rsp->ccode == 0xcb))
 
4153
    {
 
4154
        lprintf(LOG_ERR, "  Error getting peak power consumption history data: Command not supported on this system.");
 
4155
        return -1;
 
4156
    }
 
4157
    else if (rsp->ccode != 0)
 
4158
    {
 
4159
        lprintf(LOG_ERR, "  Error getting peak power consumption history data: %s",
 
4160
            val2str(rsp->ccode, completion_code_vals));
 
4161
        return -1;
 
4162
    }
 
4163
 
 
4164
    if (verbose > 1)
 
4165
    {
 
4166
        printf("Peak power consmhistory  Data               : %x %x %x %x %x %x %x %x %x %x\n   %x %x %x %x %x %x %x %x %x %x %x %x %x\n\n",
 
4167
            rsp->data[0], rsp->data[1], rsp->data[2], rsp->data[3], 
 
4168
            rsp->data[4], rsp->data[5], rsp->data[6], rsp->data[7], 
 
4169
            rsp->data[8], rsp->data[9], rsp->data[10], rsp->data[11], 
 
4170
            rsp->data[12], rsp->data[13], rsp->data[14], rsp->data[15], 
 
4171
            rsp->data[16], rsp->data[17], rsp->data[18], rsp->data[19],  
 
4172
            rsp->data[20], rsp->data[21], rsp->data[22], rsp->data[23]
 
4173
        );
 
4174
 
 
4175
    }
 
4176
    *pstMinpower =* ((IPMI_POWER_CONSUMP_HISTORY*)rsp->data);
 
4177
#if WORDS_BIGENDIAN
 
4178
    pstMinpower->lastminutepower = BSWAP_16(pstMinpower->lastminutepower);
 
4179
    pstMinpower->lasthourpower = BSWAP_16(pstMinpower->lasthourpower);
 
4180
    pstMinpower->lastdaypower = BSWAP_16(pstMinpower->lastdaypower);
 
4181
    pstMinpower->lastweakpower = BSWAP_16(pstMinpower->lastweakpower);
 
4182
    pstMinpower->lastminutepowertime = BSWAP_32(pstMinpower->lastminutepowertime);
 
4183
    pstMinpower->lasthourpowertime = BSWAP_32(pstMinpower->lasthourpowertime);
 
4184
    pstMinpower->lastdaypowertime = BSWAP_32(pstMinpower->lastdaypowertime);
 
4185
    pstMinpower->lastweekpowertime = BSWAP_32(pstMinpower->lastweekpowertime);
 
4186
#endif
 
4187
    return 0;
 
4188
}
 
4189
 
 
4190
 
 
4191
 
 
4192
/*****************************************************************
 
4193
* Function Name:    ipmi_print_power_consmpt_history
 
4194
*
 
4195
* Description:      This function print the average and peak power consumption information
 
4196
* Input:            intf      - ipmi interface
 
4197
*                   unit      - watt / btuphr
 
4198
* Output:                
 
4199
*
 
4200
* Return:              
 
4201
*
 
4202
******************************************************************/
 
4203
static int ipmi_print_power_consmpt_history(struct ipmi_intf* intf,int unit )
 
4204
{
 
4205
 
 
4206
    char timestr[30];
 
4207
 
 
4208
    uint32_t lastminutepeakpower;
 
4209
    uint32_t lasthourpeakpower;
 
4210
    uint32_t lastdaypeakpower;
 
4211
    uint32_t lastweekpeakpower;
 
4212
 
 
4213
    IPMI_AVGPOWER_CONSUMP_HISTORY avgpower;
 
4214
    IPMI_POWER_CONSUMP_HISTORY stMinpower;
 
4215
    IPMI_POWER_CONSUMP_HISTORY stPeakpower;
 
4216
 
 
4217
    uint64_t tempbtuphrconv;
 
4218
    int rc=0;
 
4219
 
 
4220
 
 
4221
    rc= ipmi_get_avgpower_consmpt_history(intf,&avgpower);    
 
4222
    if (-1 == rc)
 
4223
        return rc;
 
4224
 
 
4225
    rc= ipmi_get_peakpower_consmpt_history(intf,&stPeakpower);
 
4226
    if (-1 == rc)
 
4227
        return rc;
 
4228
 
 
4229
    rc= ipmi_get_minpower_consmpt_history(intf,&stMinpower);
 
4230
    if (-1 == rc)
 
4231
        return rc;
 
4232
 
 
4233
 
 
4234
    if(rc==0) 
 
4235
    {
 
4236
        printf ("Power Consumption History\n\n");
 
4237
        /* The fields are alligned manually changing the spaces will alter the alignment*/
 
4238
        printf ("Statistic                   Last Minute     Last Hour     Last Day     Last Week\n\n");
 
4239
 
 
4240
        if (unit ==btuphr)
 
4241
        {
 
4242
            printf ("Average Power Consumption  ");         
 
4243
            tempbtuphrconv=watt_to_btuphr_conversion(avgpower.lastminutepower);
 
4244
            printf ("%4lld BTU/hr     ",tempbtuphrconv);
 
4245
            tempbtuphrconv=watt_to_btuphr_conversion(avgpower.lasthourpower);
 
4246
            printf ("%4lld BTU/hr   ",tempbtuphrconv);
 
4247
            tempbtuphrconv=watt_to_btuphr_conversion(avgpower.lastdaypower);
 
4248
            printf ("%4lld BTU/hr  ",tempbtuphrconv);
 
4249
            tempbtuphrconv=watt_to_btuphr_conversion(avgpower.lastweakpower);
 
4250
            printf ("%4lld BTU/hr\n",tempbtuphrconv);
 
4251
 
 
4252
            printf ("Max Power Consumption      ");         
 
4253
            tempbtuphrconv=watt_to_btuphr_conversion(stPeakpower.lastminutepower);
 
4254
            printf ("%4lld BTU/hr     ",tempbtuphrconv);
 
4255
            tempbtuphrconv=watt_to_btuphr_conversion(stPeakpower.lasthourpower);
 
4256
            printf ("%4lld BTU/hr   ",tempbtuphrconv);
 
4257
            tempbtuphrconv=watt_to_btuphr_conversion(stPeakpower.lastdaypower);
 
4258
            printf ("%4lld BTU/hr  ",tempbtuphrconv);
 
4259
            tempbtuphrconv=watt_to_btuphr_conversion(stPeakpower.lastweakpower);
 
4260
            printf ("%4lld BTU/hr\n",tempbtuphrconv);
 
4261
 
 
4262
            printf ("Min Power Consumption      ");         
 
4263
            tempbtuphrconv=watt_to_btuphr_conversion(stMinpower.lastminutepower);
 
4264
            printf ("%4lld BTU/hr     ",tempbtuphrconv);
 
4265
            tempbtuphrconv=watt_to_btuphr_conversion(stMinpower.lasthourpower);
 
4266
            printf ("%4lld BTU/hr   ",tempbtuphrconv);
 
4267
            tempbtuphrconv=watt_to_btuphr_conversion(stMinpower.lastdaypower);
 
4268
            printf ("%4lld BTU/hr  ",tempbtuphrconv);
 
4269
            tempbtuphrconv=watt_to_btuphr_conversion(stMinpower.lastweakpower);
 
4270
            printf ("%4lld BTU/hr\n\n",tempbtuphrconv);
 
4271
 
 
4272
        }
 
4273
        else
 
4274
        {
 
4275
 
 
4276
            printf ("Average Power Consumption  ");         
 
4277
            tempbtuphrconv=(avgpower.lastminutepower);
 
4278
                        printf ("%4lld W          ",tempbtuphrconv);
 
4279
                        tempbtuphrconv=(avgpower.lasthourpower);
 
4280
                        printf ("%4lld W        ",tempbtuphrconv);
 
4281
                        tempbtuphrconv=(avgpower.lastdaypower);
 
4282
                        printf ("%4lld W       ",tempbtuphrconv);
 
4283
                        tempbtuphrconv=(avgpower.lastweakpower);
 
4284
                        printf ("%4lld W   \n",tempbtuphrconv);
 
4285
 
 
4286
                printf ("Max Power Consumption      ");         
 
4287
                        tempbtuphrconv=(stPeakpower.lastminutepower);
 
4288
                        printf ("%4lld W          ",tempbtuphrconv);
 
4289
                        tempbtuphrconv=(stPeakpower.lasthourpower);
 
4290
                        printf ("%4lld W        ",tempbtuphrconv);
 
4291
                        tempbtuphrconv=(stPeakpower.lastdaypower);
 
4292
                        printf ("%4lld W       ",tempbtuphrconv);
 
4293
                        tempbtuphrconv=(stPeakpower.lastweakpower);
 
4294
                        printf ("%4lld W   \n",tempbtuphrconv);
 
4295
 
 
4296
                printf ("Min Power Consumption      ");         
 
4297
                        tempbtuphrconv=(stMinpower.lastminutepower);
 
4298
                        printf ("%4lld W          ",tempbtuphrconv);
 
4299
                        tempbtuphrconv=(stMinpower.lasthourpower);
 
4300
                        printf ("%4lld W        ",tempbtuphrconv);
 
4301
                        tempbtuphrconv=(stMinpower.lastdaypower);
 
4302
                        printf ("%4lld W       ",tempbtuphrconv);
 
4303
                        tempbtuphrconv=(stMinpower.lastweakpower);
 
4304
                        printf ("%4lld W   \n\n",tempbtuphrconv);
 
4305
                }               
 
4306
                
 
4307
        lastminutepeakpower=stPeakpower.lastminutepowertime;
 
4308
        lasthourpeakpower=stPeakpower.lasthourpowertime;
 
4309
        lastdaypeakpower=stPeakpower.lastdaypowertime;
 
4310
        lastweekpeakpower=stPeakpower.lastweekpowertime;
 
4311
 
 
4312
        printf ("Max Power Time\n");
 
4313
        ipmi_time_to_str(lastminutepeakpower, timestr);         
 
4314
        printf ("Last Minute     : %s",timestr);
 
4315
        ipmi_time_to_str(lasthourpeakpower, timestr);           
 
4316
        printf ("Last Hour       : %s",timestr);
 
4317
        ipmi_time_to_str(lastdaypeakpower, timestr);            
 
4318
        printf ("Last Day        : %s",timestr);
 
4319
        ipmi_time_to_str(lastweekpeakpower, timestr);           
 
4320
        printf ("Last Week       : %s",timestr);                
 
4321
 
 
4322
 
 
4323
        lastminutepeakpower=stMinpower.lastminutepowertime;
 
4324
        lasthourpeakpower=stMinpower.lasthourpowertime;
 
4325
        lastdaypeakpower=stMinpower.lastdaypowertime;
 
4326
        lastweekpeakpower=stMinpower.lastweekpowertime; 
 
4327
 
 
4328
        printf ("Min Power Time\n");
 
4329
        ipmi_time_to_str(lastminutepeakpower, timestr);         
 
4330
        printf ("Last Minute     : %s",timestr);
 
4331
        ipmi_time_to_str(lasthourpeakpower, timestr);           
 
4332
        printf ("Last Hour       : %s",timestr);
 
4333
        ipmi_time_to_str(lastdaypeakpower, timestr);            
 
4334
        printf ("Last Day        : %s",timestr);
 
4335
        ipmi_time_to_str(lastweekpeakpower, timestr);           
 
4336
        printf ("Last Week       : %s",timestr);        
 
4337
 
 
4338
    }
 
4339
        return rc;
 
4340
 
 
4341
}
 
4342
 
 
4343
 
 
4344
 
 
4345
/*****************************************************************
 
4346
* Function Name:    ipmi_get_power_cap
 
4347
*
 
4348
* Description:      This function updates the power cap information
 
4349
* Input:            intf         - ipmi interface
 
4350
* Output:           ipmipowercap - power cap information
 
4351
*
 
4352
* Return:          
 
4353
*
 
4354
******************************************************************/
 
4355
 
 
4356
static int ipmi_get_power_cap(struct ipmi_intf* intf,IPMI_POWER_CAP* ipmipowercap )
 
4357
{
 
4358
    struct ipmi_rs * rsp=NULL;
 
4359
    struct ipmi_rq req={0};
 
4360
    uint64_t tempbtuphrconv;
 
4361
    uint8_t data[4];
 
4362
 
 
4363
    /* power supply rating command*/
 
4364
    req.msg.netfn = IPMI_NETFN_APP;
 
4365
    req.msg.lun = 0;
 
4366
    req.msg.cmd = IPMI_GET_SYS_INFO;
 
4367
    req.msg.data_len = 4;
 
4368
    req.msg.data = data;
 
4369
 
 
4370
    data[0] = 0;
 
4371
    data[1] = IPMI_DELL_POWER_CAP;
 
4372
    data[2] = 0;
 
4373
    data[3] = 0;
 
4374
 
 
4375
 
 
4376
    rsp = intf->sendrecv(intf, &req);
 
4377
 
 
4378
    if (rsp == NULL) {
 
4379
        lprintf(LOG_ERR, " Error getting power cap  .\n");
 
4380
        if (verbose > 1){
 
4381
            printf("power cap  Data               :%x %x %x %x %x %x %x %x %x %x ",
 
4382
                rsp->data[1], rsp->data[2], rsp->data[3], 
 
4383
                rsp->data[4], rsp->data[5], rsp->data[6], rsp->data[7], 
 
4384
                rsp->data[8], rsp->data[9], rsp->data[10],rsp->data[11]);
 
4385
        }
 
4386
        return -1;
 
4387
 
 
4388
        } else if((iDRAC_FLAG == IDRAC_12G) && (rsp->ccode == LICENSE_NOT_SUPPORTED)) {
 
4389
                printf("FM001 : A required license is missing or expired\n");
 
4390
                return -1;      
 
4391
    } else if ((rsp->ccode == 0xc1)||(rsp->ccode == 0xcb)) {
 
4392
 
 
4393
        lprintf(LOG_ERR, "  Error getting power cap: Command not supported on this system.");
 
4394
        if (verbose > 1){
 
4395
            printf("power cap  Data               :%x %x %x %x %x %x %x %x %x %x ",
 
4396
                rsp->data[1], rsp->data[2], rsp->data[3], 
 
4397
                rsp->data[4], rsp->data[5], rsp->data[6], rsp->data[7], 
 
4398
                rsp->data[8], rsp->data[9], rsp->data[10],rsp->data[11]);
 
4399
 
 
4400
        }
 
4401
        return -1;
 
4402
    } else if (rsp->ccode != 0){
 
4403
        lprintf(LOG_ERR, "  Error getting power cap: %s",
 
4404
            val2str(rsp->ccode, completion_code_vals));
 
4405
        if (verbose > 1){
 
4406
            printf("power cap  Data               :%x %x %x %x %x %x %x %x %x %x ",
 
4407
                rsp->data[1], rsp->data[2], rsp->data[3], 
 
4408
                rsp->data[4], rsp->data[5], rsp->data[6], rsp->data[7], 
 
4409
                rsp->data[8], rsp->data[9], rsp->data[10],rsp->data[11]);
 
4410
        }
 
4411
        return -1;
 
4412
    }
 
4413
    if (verbose > 1){
 
4414
        printf("power cap  Data               :%x %x %x %x %x %x %x %x %x %x ",
 
4415
            rsp->data[1], rsp->data[2], rsp->data[3], 
 
4416
            rsp->data[4], rsp->data[5], rsp->data[6], rsp->data[7], 
 
4417
            rsp->data[8], rsp->data[9], rsp->data[10],rsp->data[11]);
 
4418
 
 
4419
    }
 
4420
 
 
4421
    * ipmipowercap = *((IPMI_POWER_CAP*)(rsp->data));
 
4422
#if WORDS_BIGENDIAN
 
4423
    ipmipowercap->PowerCap = BSWAP_16(ipmipowercap->PowerCap);
 
4424
    ipmipowercap->MaximumPowerConsmp = BSWAP_16(ipmipowercap->MaximumPowerConsmp);
 
4425
    ipmipowercap->MinimumPowerConsmp = BSWAP_16(ipmipowercap->MinimumPowerConsmp);
 
4426
    ipmipowercap->totalnumpowersupp = BSWAP_16(ipmipowercap->totalnumpowersupp);
 
4427
    ipmipowercap->AvailablePower = BSWAP_16(ipmipowercap->AvailablePower);
 
4428
    ipmipowercap->SystemThrottling = BSWAP_16(ipmipowercap->SystemThrottling);
 
4429
    ipmipowercap->Resv = BSWAP_16(ipmipowercap->Resv);
 
4430
#endif
 
4431
 
 
4432
    return 0;
 
4433
}
 
4434
 
 
4435
/*****************************************************************
 
4436
* Function Name:    ipmi_print_power_cap
 
4437
*
 
4438
* Description:      This function print the power cap information
 
4439
* Input:            intf            - ipmi interface
 
4440
*                   unit            - watt / btuphr
 
4441
* Output:                
 
4442
* Return:               
 
4443
*
 
4444
******************************************************************/
 
4445
static int ipmi_print_power_cap(struct ipmi_intf* intf,uint8_t unit )
 
4446
{
 
4447
    uint64_t tempbtuphrconv;
 
4448
    int rc;
 
4449
    IPMI_POWER_CAP ipmipowercap;
 
4450
 
 
4451
        memset(&ipmipowercap,0,sizeof(ipmipowercap));
 
4452
    rc=ipmi_get_power_cap(intf,&ipmipowercap);
 
4453
 
 
4454
 
 
4455
    if (rc==0) 
 
4456
    {
 
4457
        if (unit ==btuphr){
 
4458
            tempbtuphrconv=watt_to_btuphr_conversion(ipmipowercap.MaximumPowerConsmp);
 
4459
                        printf ("Maximum power: %lld  BTU/hr\n",tempbtuphrconv);
 
4460
                        tempbtuphrconv=watt_to_btuphr_conversion(ipmipowercap.MinimumPowerConsmp);
 
4461
                        printf ("Minimum power: %lld  BTU/hr\n",tempbtuphrconv);
 
4462
                        tempbtuphrconv=watt_to_btuphr_conversion(ipmipowercap.PowerCap);
 
4463
                        printf ("Power cap    : %lld  BTU/hr\n",tempbtuphrconv);
 
4464
                }else{
 
4465
                
 
4466
                        printf ("Maximum power: %d Watt\n",ipmipowercap.MaximumPowerConsmp);
 
4467
                        printf ("Minimum power: %d Watt\n",ipmipowercap.MinimumPowerConsmp);
 
4468
                        printf ("Power cap    : %d Watt\n",ipmipowercap.PowerCap);
 
4469
        }
 
4470
    }
 
4471
    return rc;
 
4472
 
 
4473
}  
 
4474
 
 
4475
/*****************************************************************
 
4476
* Function Name:     ipmi_set_power_cap
 
4477
*
 
4478
* Description:       This function updates the power cap information
 
4479
* Input:             intf            - ipmi interface
 
4480
*                    unit            - watt / btuphr
 
4481
*                    val             - new power cap value
 
4482
* Output:          
 
4483
* Return:               
 
4484
*
 
4485
******************************************************************/
 
4486
static int ipmi_set_power_cap(struct ipmi_intf* intf,int unit,int val )
 
4487
{
 
4488
    struct ipmi_rs *rsp = NULL;
 
4489
    struct ipmi_rq req={0};;
 
4490
    uint8_t data[13];
 
4491
    uint16_t powercapval;
 
4492
    uint64_t maxpowerbtuphr;
 
4493
    uint64_t maxpowerbtuphr1;
 
4494
    uint64_t minpowerbtuphr;
 
4495
        IPMI_POWER_CAP ipmipowercap;
 
4496
 
 
4497
        if(ipmi_get_power_capstatus_command(intf) < 0)
 
4498
                return -1;      // Adding the failed condition check
 
4499
 
 
4500
    if (PowercapSetable_flag!=1)
 
4501
    {
 
4502
        lprintf(LOG_ERR, " Can not set powercap on this system");
 
4503
        return -1;
 
4504
    }
 
4505
    else if(PowercapstatusFlag!=1)
 
4506
    {
 
4507
        lprintf(LOG_ERR, " Power cap set feature is not enabled");
 
4508
        return -1;
 
4509
    }
 
4510
 
 
4511
    req.msg.netfn = IPMI_NETFN_APP;
 
4512
    req.msg.lun = 0;
 
4513
    req.msg.cmd = IPMI_GET_SYS_INFO;
 
4514
    req.msg.data_len = 4;
 
4515
    memset(data, 0, 4);
 
4516
    req.msg.data = data;
 
4517
 
 
4518
    data[0] = 0;
 
4519
    data[1] = IPMI_DELL_POWER_CAP;
 
4520
    data[2] = 0;
 
4521
    data[3] = 0;
 
4522
 
 
4523
    rsp = intf->sendrecv(intf, &req);
 
4524
    if (rsp == NULL) 
 
4525
    {
 
4526
        lprintf(LOG_ERR, " Error getting power cap  .\n");
 
4527
        if (verbose > 1)
 
4528
        {
 
4529
            printf("power cap  Data               :%x %x %x %x %x %x %x %x %x %x ",
 
4530
                rsp->data[1], rsp->data[2], rsp->data[3], 
 
4531
                rsp->data[4], rsp->data[5], rsp->data[6], rsp->data[7], 
 
4532
                rsp->data[8], rsp->data[9], rsp->data[10],rsp->data[11]);
 
4533
        }
 
4534
        return -1;
 
4535
                        
 
4536
        }
 
4537
        else if((iDRAC_FLAG == IDRAC_12G) && (rsp->ccode == LICENSE_NOT_SUPPORTED)) {
 
4538
                printf("FM001 : A required license is missing or expired\n");
 
4539
                return -1;      
 
4540
        } 
 
4541
    else if (rsp->ccode == 0xc1) 
 
4542
    {
 
4543
 
 
4544
        lprintf(LOG_ERR, "  Error getting power cap, command not supported on this system.\n");
 
4545
        if (verbose > 1){
 
4546
            printf("power cap  Data               :%x %x %x %x %x %x %x %x %x %x ",
 
4547
                rsp->data[1], rsp->data[2], rsp->data[3], 
 
4548
                rsp->data[4], rsp->data[5], rsp->data[6], rsp->data[7], 
 
4549
                rsp->data[8], rsp->data[9], rsp->data[10],rsp->data[11]);
 
4550
 
 
4551
        }
 
4552
        return -1;
 
4553
    }
 
4554
    else if (rsp->ccode != 0)
 
4555
    {
 
4556
        lprintf(LOG_ERR, "  Error getting power cap: %s",
 
4557
            val2str(rsp->ccode, completion_code_vals));
 
4558
        if (verbose > 1)
 
4559
        {
 
4560
            printf("power cap  Data               :%x %x %x %x %x %x %x %x %x %x ",
 
4561
                rsp->data[1], rsp->data[2], rsp->data[3], 
 
4562
                rsp->data[4], rsp->data[5], rsp->data[6], rsp->data[7], 
 
4563
                rsp->data[8], rsp->data[9], rsp->data[10],rsp->data[11]);
 
4564
        }
 
4565
        return -1;
 
4566
    }
 
4567
    if (verbose > 1)
 
4568
    {
 
4569
        printf("power cap  Data               :%x %x %x %x %x %x %x %x %x %x ",
 
4570
            rsp->data[1], rsp->data[2], rsp->data[3], 
 
4571
            rsp->data[4], rsp->data[5], rsp->data[6], rsp->data[7], 
 
4572
            rsp->data[8], rsp->data[9], rsp->data[10],rsp->data[11]);
 
4573
 
 
4574
    }
 
4575
 
 
4576
    ipmipowercap.PowerCap=((rsp->data[1]<<8)+rsp->data[2]);
 
4577
    ipmipowercap.unit=rsp->data[3];
 
4578
    ipmipowercap.MaximumPowerConsmp=((rsp->data[4]<<8)+rsp->data[5]);
 
4579
    ipmipowercap.MinimumPowerConsmp=((rsp->data[6]<<8)+rsp->data[7]);
 
4580
 
 
4581
    memset(data, 0, 13);
 
4582
    req.msg.netfn = IPMI_NETFN_APP;
 
4583
    req.msg.lun = 0;
 
4584
    req.msg.cmd = IPMI_SET_SYS_INFO;
 
4585
    req.msg.data_len = 13;
 
4586
    req.msg.data = data;
 
4587
    data[0] = IPMI_DELL_POWER_CAP;
 
4588
    powercapval=val;
 
4589
 
 
4590
 
 
4591
    data[1] = (powercapval&0XFF);                   
 
4592
    data[2] = ((powercapval&0XFF00)>>8);
 
4593
    data[3] = unit;
 
4594
 
 
4595
    data[4]=((ipmipowercap.MaximumPowerConsmp&0xFF));
 
4596
    data[5]=((ipmipowercap.MaximumPowerConsmp&0xFF00)>>8);
 
4597
    data[6]=((ipmipowercap.MinimumPowerConsmp&0xFF));
 
4598
    data[7]=((ipmipowercap.MinimumPowerConsmp&0xFF00)>>8);
 
4599
    data[8]=(ipmipowercap.totalnumpowersupp);
 
4600
    data[9]=((ipmipowercap.AvailablePower&0xFF));
 
4601
    data[10]=((ipmipowercap.AvailablePower&0xFF00)>>8);
 
4602
    data[11]=(ipmipowercap.SystemThrottling);
 
4603
    data[12]=0x00;
 
4604
 
 
4605
    ipmipowercap.MaximumPowerConsmp = BSWAP_16(ipmipowercap.MaximumPowerConsmp);
 
4606
    ipmipowercap.MinimumPowerConsmp = BSWAP_16(ipmipowercap.MinimumPowerConsmp);
 
4607
    ipmipowercap.PowerCap = BSWAP_16(ipmipowercap.PowerCap);
 
4608
    if(unit==btuphr)
 
4609
    {
 
4610
        val = btuphr_to_watt_conversion(val);
 
4611
 
 
4612
    }
 
4613
    else if(unit ==percent)
 
4614
    {
 
4615
        if((val <0)||(val>100))
 
4616
        {
 
4617
            lprintf(LOG_ERR, " Cap value is out of boundary conditon it should be between 0  - 100");
 
4618
            return -1;
 
4619
        }
 
4620
        val =( (val*(ipmipowercap.MaximumPowerConsmp -ipmipowercap.MinimumPowerConsmp))/100)+ipmipowercap.MinimumPowerConsmp;
 
4621
        lprintf(LOG_ERR, " Cap value in percentage is  %d ",val);
 
4622
        data[1] = (val&0XFF);                   
 
4623
        data[2] = ((val&0XFF00)>>8);
 
4624
        data[3] = watt;
 
4625
    }
 
4626
    if(((val<ipmipowercap.MinimumPowerConsmp)||(val>ipmipowercap.MaximumPowerConsmp))&&(unit==watt))
 
4627
    {
 
4628
        lprintf(LOG_ERR, " Cap value is out of boundary conditon it should be between %d  - %d",
 
4629
            ipmipowercap.MinimumPowerConsmp,ipmipowercap.MaximumPowerConsmp);
 
4630
        return -1;
 
4631
    }
 
4632
    else if(((val<ipmipowercap.MinimumPowerConsmp)||(val>ipmipowercap.MaximumPowerConsmp))&&(unit==btuphr))
 
4633
    {
 
4634
        minpowerbtuphr= watt_to_btuphr_conversion(ipmipowercap.MinimumPowerConsmp);
 
4635
        maxpowerbtuphr=watt_to_btuphr_conversion(ipmipowercap.MaximumPowerConsmp);
 
4636
        maxpowerbtuphr1= watt_to_btuphr_conversion(ipmipowercap.MaximumPowerConsmp);
 
4637
        lprintf(LOG_ERR, " Cap value is out of boundary conditon it should be between %d",
 
4638
            minpowerbtuphr);
 
4639
        lprintf(LOG_ERR, " -%d",
 
4640
            maxpowerbtuphr1);
 
4641
 
 
4642
        return -1;
 
4643
    }
 
4644
    rsp = intf->sendrecv(intf, &req);
 
4645
    if (rsp == NULL) 
 
4646
    {
 
4647
        lprintf(LOG_ERR, " Error setting power cap");
 
4648
        return -1;
 
4649
    }
 
4650
        else if((iDRAC_FLAG == IDRAC_12G) && (rsp->ccode == LICENSE_NOT_SUPPORTED)) {
 
4651
                printf("FM001 : A required license is missing or expired\n");
 
4652
                return -1;      
 
4653
        } 
 
4654
    else if (rsp->ccode > 0) 
 
4655
    {
 
4656
        lprintf(LOG_ERR, " Error setting power cap: %s",
 
4657
            val2str(rsp->ccode, completion_code_vals));
 
4658
        return -1;
 
4659
    }
 
4660
    if (verbose > 1)
 
4661
    {
 
4662
        printf("CC for setpowercap :%d ",rsp->ccode);
 
4663
    }
 
4664
    return 0;
 
4665
}
 
4666
 
 
4667
/*****************************************************************
 
4668
* Function Name:    getpowersupplyfruinfo
 
4669
*
 
4670
* Description:      This function retrieves the FRU header
 
4671
* Input:            intf    - ipmi interface
 
4672
*                   header  - watt / btuphr
 
4673
*                   fru     - FRU information
 
4674
* Output:           header  - FRU header
 
4675
* Return:           
 
4676
*
 
4677
******************************************************************/
 
4678
static int getpowersupplyfruinfo(struct ipmi_intf *intf, uint8_t id, 
 
4679
                         struct fru_header header, struct fru_info fru)
 
4680
{
 
4681
    struct ipmi_rs * rsp;
 
4682
    struct ipmi_rq req;
 
4683
 
 
4684
    uint8_t msg_data[4];
 
4685
 
 
4686
    memset(&fru, 0, sizeof(struct fru_info));
 
4687
    memset(&header, 0, sizeof(struct fru_header));
 
4688
 
 
4689
    /*
 
4690
    * get info about this FRU
 
4691
    */
 
4692
    memset(msg_data, 0, 4);
 
4693
    msg_data[0] = id;
 
4694
 
 
4695
    memset(&req, 0, sizeof(req));
 
4696
    req.msg.netfn = IPMI_NETFN_STORAGE;
 
4697
    req.msg.lun = 0;
 
4698
    req.msg.cmd = GET_FRU_INFO;
 
4699
    req.msg.data = msg_data;
 
4700
    req.msg.data_len = 1;
 
4701
 
 
4702
    rsp = intf->sendrecv(intf, &req);
 
4703
    if (rsp == NULL) {
 
4704
        printf(" Device not present (No Response)\n");
 
4705
        return -1;
 
4706
    }
 
4707
    if (rsp->ccode > 0) {
 
4708
        printf(" Device not present (%s)\n",
 
4709
            val2str(rsp->ccode, completion_code_vals));
 
4710
        return -1;
 
4711
    }
 
4712
 
 
4713
    fru.size = (rsp->data[1] << 8) | rsp->data[0];
 
4714
    fru.access = rsp->data[2] & 0x1;
 
4715
 
 
4716
    lprintf(LOG_DEBUG, "fru.size = %d bytes (accessed by %s)",
 
4717
        fru.size, fru.access ? "words" : "bytes");
 
4718
 
 
4719
    if (fru.size < 1) {
 
4720
        lprintf(LOG_ERR, " Invalid FRU size %d", fru.size);
 
4721
        return -1;
 
4722
    }
 
4723
 
 
4724
    /*
 
4725
    * retrieve the FRU header
 
4726
    */
 
4727
    msg_data[0] = id;
 
4728
    msg_data[1] = 0;
 
4729
    msg_data[2] = 0;
 
4730
    msg_data[3] = 8;
 
4731
 
 
4732
    memset(&req, 0, sizeof(req));
 
4733
    req.msg.netfn = IPMI_NETFN_STORAGE;
 
4734
    req.msg.lun = 0;
 
4735
    req.msg.cmd = GET_FRU_DATA;
 
4736
    req.msg.data = msg_data;
 
4737
    req.msg.data_len = 4;
 
4738
 
 
4739
    rsp = intf->sendrecv(intf, &req);
 
4740
    if (rsp == NULL) {
 
4741
        printf(" Device not present (No Response)\n");
 
4742
        return 1;
 
4743
    }
 
4744
    if (rsp->ccode > 0) {
 
4745
        printf(" Device not present (%s)\n",
 
4746
            val2str(rsp->ccode, completion_code_vals));
 
4747
        return 1;
 
4748
    }
 
4749
 
 
4750
    if (verbose > 1)
 
4751
        printbuf(rsp->data, rsp->data_len, "FRU DATA");
 
4752
 
 
4753
    memcpy(&header, rsp->data + 1, 8);
 
4754
 
 
4755
        return 0;
 
4756
 
 
4757
 
 
4758
}
 
4759
 
 
4760
/*****************************************************************
 
4761
* Function Name:   ipmi_powermonitor_usage
 
4762
*
 
4763
* Description:     This function prints help message for powermonitor command
 
4764
* Input:              
 
4765
* Output:       
 
4766
*
 
4767
* Return:              
 
4768
*
 
4769
******************************************************************/
 
4770
static void
 
4771
ipmi_powermonitor_usage(void)
 
4772
{
 
4773
    lprintf(LOG_NOTICE, "");
 
4774
    lprintf(LOG_NOTICE, "   powermonitor");
 
4775
    lprintf(LOG_NOTICE, "      Shows power tracking statistics ");
 
4776
    lprintf(LOG_NOTICE, "");
 
4777
    lprintf(LOG_NOTICE, "   powermonitor clear cumulativepower");
 
4778
    lprintf(LOG_NOTICE, "      Reset cumulative power reading");
 
4779
    lprintf(LOG_NOTICE, "");
 
4780
    lprintf(LOG_NOTICE, "   powermonitor clear peakpower");
 
4781
    lprintf(LOG_NOTICE, "      Reset peak power reading");
 
4782
    lprintf(LOG_NOTICE, "");
 
4783
    lprintf(LOG_NOTICE, "   powermonitor powerconsumption");
 
4784
    lprintf(LOG_NOTICE, "      Displays power consumption in <watt|btuphr>");
 
4785
    lprintf(LOG_NOTICE, "");
 
4786
    lprintf(LOG_NOTICE, "   powermonitor powerconsumptionhistory <watt|btuphr>");
 
4787
    lprintf(LOG_NOTICE, "      Displays power consumption history ");
 
4788
    lprintf(LOG_NOTICE, "");
 
4789
    lprintf(LOG_NOTICE, "   powermonitor getpowerbudget");
 
4790
    lprintf(LOG_NOTICE, "      Displays power cap in <watt|btuphr>");
 
4791
    lprintf(LOG_NOTICE, "");
 
4792
    lprintf(LOG_NOTICE, "   powermonitor setpowerbudget <val><watt|btuphr|percent>");
 
4793
    lprintf(LOG_NOTICE, "      Allows user to set the  power cap in <watt|BTU/hr|percentage>");
 
4794
    lprintf(LOG_NOTICE, "");
 
4795
    lprintf(LOG_NOTICE, "   powermonitor enablepowercap ");
 
4796
    lprintf(LOG_NOTICE, "      To enable set power cap");
 
4797
    lprintf(LOG_NOTICE, "");
 
4798
    lprintf(LOG_NOTICE, "   powermonitor disablepowercap ");
 
4799
    lprintf(LOG_NOTICE, "      To disable set power cap");
 
4800
    lprintf(LOG_NOTICE, "");
 
4801
 
 
4802
}
 
4803
/*****************************************************************
 
4804
* Function Name:           ipmi_delloem_vFlash_main
 
4805
*
 
4806
* Description:             This function processes the delloem vFlash command
 
4807
* Input:                           intf    - ipmi interface
 
4808
                                           argc    - no of arguments
 
4809
                                           argv    - argument string array
 
4810
* Output:                
 
4811
*
 
4812
* Return:                          return code     0 - success
 
4813
*                                                 -1 - failure
 
4814
*
 
4815
******************************************************************/
 
4816
 
 
4817
static int ipmi_delloem_vFlash_main (struct ipmi_intf * intf, int argc, char ** argv)
 
4818
{
 
4819
        int rc = 0;
 
4820
 
 
4821
        current_arg++;
 
4822
        rc = ipmi_delloem_vFlash_process(intf, current_arg, argv);
 
4823
        return rc;
 
4824
}
 
4825
 
 
4826
 
 
4827
 
 
4828
/*****************************************************************
 
4829
* Function Name:        get_vFlash_compcode_str
 
4830
*
 
4831
* Description:  This function maps the vFlash completion code
 
4832
*               to a string
 
4833
* Input : vFlash completion code and static array of codes vs strings
 
4834
* Output: -             
 
4835
* Return: returns the mapped string             
 
4836
*
 
4837
******************************************************************/
 
4838
const char * 
 
4839
get_vFlash_compcode_str(uint8_t vflashcompcode, const struct vFlashstr *vs)
 
4840
{
 
4841
        static char un_str[32];
 
4842
        int i;
 
4843
 
 
4844
        for (i = 0; vs[i].str != NULL; i++) {
 
4845
                if (vs[i].val == vflashcompcode)
 
4846
                        return vs[i].str;
 
4847
        }
 
4848
 
 
4849
        memset(un_str, 0, 32);
 
4850
        snprintf(un_str, 32, "Unknown (0x%02X)", vflashcompcode);
 
4851
 
 
4852
        return un_str;
 
4853
}
 
4854
 
 
4855
/*****************************************************************
 
4856
* Function Name:        ipmi_get_sd_card_info
 
4857
*
 
4858
* Description: This function prints the vFlash Extended SD card info
 
4859
* Input : ipmi interface
 
4860
* Output: prints the sd card extended info              
 
4861
* Return: 0 - success -1 - failure
 
4862
*
 
4863
******************************************************************/
 
4864
static int
 
4865
ipmi_get_sd_card_info(struct ipmi_intf* intf) {
 
4866
        struct ipmi_rs * rsp;
 
4867
        struct ipmi_rq req;
 
4868
 
 
4869
        uint8_t msg_data[2];
 
4870
        uint8_t input_length=0;
 
4871
        uint8_t cardstatus=0x00;
 
4872
 
 
4873
        IPMI_DELL_SDCARD_INFO * sdcardinfoblock;
 
4874
 
 
4875
        input_length = 2;
 
4876
        msg_data[0] = msg_data[1] = 0x00;
 
4877
 
 
4878
        req.msg.netfn = DELL_OEM_NETFN;
 
4879
        req.msg.lun = 0;
 
4880
        req.msg.cmd = IPMI_GET_EXT_SD_CARD_INFO;
 
4881
        req.msg.data = msg_data;
 
4882
        req.msg.data_len = input_length;
 
4883
 
 
4884
        rsp = intf->sendrecv(intf, &req);
 
4885
        if (rsp == NULL)
 
4886
        {
 
4887
                lprintf(LOG_ERR, " Error in getting SD Card Extended Information");
 
4888
                return -1;
 
4889
        }
 
4890
        else if (rsp->ccode > 0) 
 
4891
        {
 
4892
                lprintf(LOG_ERR, " Error in getting SD Card Extended Information (%s) \n",
 
4893
                                val2str(rsp->ccode, completion_code_vals) );
 
4894
                return -1;
 
4895
        }
 
4896
 
 
4897
        sdcardinfoblock = (IPMI_DELL_SDCARD_INFO *) (void *) rsp->data;
 
4898
 
 
4899
        if( (iDRAC_FLAG == IDRAC_12G) && (sdcardinfoblock->vflashcompcode == VFL_NOT_LICENSED))
 
4900
        {
 
4901
                printf("FM001 : A required license is missing or expired\n");
 
4902
                return -1;      
 
4903
        }
 
4904
        else if (sdcardinfoblock->vflashcompcode != 0x00)
 
4905
        {
 
4906
                lprintf(LOG_ERR, " Error in getting SD Card Extended Information (%s) \n", get_vFlash_compcode_str(sdcardinfoblock->vflashcompcode,
 
4907
                                        vFlash_completion_code_vals));
 
4908
                return -1;
 
4909
        }
 
4910
 
 
4911
        if (!(sdcardinfoblock->sdcardstatus & 0x04))
 
4912
        {
 
4913
                lprintf(LOG_ERR, " vFlash SD card is unavailable, please insert the card\n of size 256MB or greater\n");
 
4914
                return 0;
 
4915
        }
 
4916
 
 
4917
        printf("vFlash SD Card Properties\n");
 
4918
        printf("SD Card size       : %8dMB\n",sdcardinfoblock->sdcardsize);
 
4919
        printf("Available size     : %8dMB\n",sdcardinfoblock->sdcardavailsize);
 
4920
        printf("Initialized        : %10s\n", (sdcardinfoblock->sdcardstatus & 0x80) ?
 
4921
                        "Yes" : "No");
 
4922
        printf("Licensed           : %10s\n", (sdcardinfoblock->sdcardstatus & 0x40) ?
 
4923
                        "Yes" : "No");
 
4924
        printf("Attached           : %10s\n", (sdcardinfoblock->sdcardstatus & 0x20) ?
 
4925
                        "Yes" : "No");
 
4926
        printf("Enabled            : %10s\n", (sdcardinfoblock->sdcardstatus & 0x10) ?
 
4927
                        "Yes" : "No");
 
4928
        printf("Write Protected    : %10s\n", (sdcardinfoblock->sdcardstatus & 0x08) ?
 
4929
                        "Yes" : "No");
 
4930
        cardstatus = sdcardinfoblock->sdcardstatus & 0x03;
 
4931
        printf("Health             : %10s\n", ((0x00 == cardstatus
 
4932
                ) ? "OK" : ((cardstatus == 0x03) ? 
 
4933
                        "Undefined" : ((cardstatus == 0x02) ? 
 
4934
                                "Critical" : "Warning"))));
 
4935
        printf("Bootable partition : %10d\n",sdcardinfoblock->bootpartion);
 
4936
        return 0;
 
4937
}
 
4938
 
 
4939
/*****************************************************************
 
4940
* Function Name:        ipmi_delloem_vFlash_process
 
4941
*
 
4942
* Description:  This function processes the args for vFlash subcmd
 
4943
* Input : intf - ipmi interface, arg index, argv array
 
4944
* Output: prints help or error with help
 
4945
* Return: 0 - Success -1 - failure
 
4946
*
 
4947
******************************************************************/
 
4948
static int
 
4949
ipmi_delloem_vFlash_process(struct ipmi_intf* intf, int current_arg, char ** argv) {
 
4950
        int rc;
 
4951
 
 
4952
        if (strncmp(intf->name,"wmi\0",4) &&
 
4953
                strncmp(intf->name, "open\0",5))
 
4954
        {
 
4955
                lprintf(LOG_ERR, " vFlash support is enabled only for wmi and open interface.\n Its not enabled for lan and lanplus interface.");
 
4956
                return -1;
 
4957
        }
 
4958
 
 
4959
        if (argv[current_arg] == NULL || strcmp(argv[current_arg], "help") == 0)
 
4960
        {
 
4961
                ipmi_vFlash_usage();
 
4962
                return 0;
 
4963
        }
 
4964
        ipmi_idracvalidator_command(intf);
 
4965
        if (!strncmp(argv[current_arg], "info\0", 5))
 
4966
        {
 
4967
                current_arg++;
 
4968
                if (argv[current_arg] == NULL)
 
4969
                {
 
4970
                        ipmi_vFlash_usage();
 
4971
                        return -1;
 
4972
                }
 
4973
                else if (strncmp(argv[current_arg], "Card\0", 5) == 0)
 
4974
                {
 
4975
                        current_arg++;
 
4976
                        if (argv[current_arg] != NULL)
 
4977
                        {
 
4978
                                ipmi_vFlash_usage();
 
4979
                                return -1;
 
4980
                        }
 
4981
                        rc = ipmi_get_sd_card_info(intf);
 
4982
                        return rc;
 
4983
                }
 
4984
                else /* TBD: many sub commands are present */
 
4985
                {
 
4986
                        ipmi_vFlash_usage();
 
4987
                        return -1;
 
4988
                }
 
4989
        }
 
4990
        /* TBD other vFlash subcommands */
 
4991
        else
 
4992
        {
 
4993
                ipmi_vFlash_usage();
 
4994
                return -1;
 
4995
        }
 
4996
}
 
4997
 
 
4998
/*****************************************************************
 
4999
* Function Name:        ipmi_vFlash_usage
 
5000
*
 
5001
* Description:  This function displays the usage for using vFlash
 
5002
* Input : void
 
5003
* Output: prints help           
 
5004
* Return: void  
 
5005
*
 
5006
******************************************************************/
 
5007
static void
 
5008
ipmi_vFlash_usage(void)
 
5009
{
 
5010
        lprintf(LOG_NOTICE, "");
 
5011
        lprintf(LOG_NOTICE, "   vFlash info Card");
 
5012
        lprintf(LOG_NOTICE, "      Shows Extended SD Card information");
 
5013
        lprintf(LOG_NOTICE, "");
 
5014
}
 
5015
 
 
5016
/**********************************************************************
 
5017
* Function Name: ipmi_setled_usage
 
5018
*
 
5019
* Description:  This function prints help message for setled command
 
5020
* Input:
 
5021
* Output:
 
5022
*
 
5023
* Return:
 
5024
*
 
5025
***********************************************************************/
 
5026
static void
 
5027
ipmi_setled_usage(void)
 
5028
{
 
5029
    lprintf(LOG_NOTICE, "");
 
5030
    lprintf(LOG_NOTICE, "   setled <b:d.f> <state..>");
 
5031
    lprintf(LOG_NOTICE, "      Set backplane LED state");
 
5032
    lprintf(LOG_NOTICE, "      b:d.f = PCI Bus:Device.Function of drive (lspci format)");
 
5033
    lprintf(LOG_NOTICE, "      state = present|online|hotspare|identify|rebuilding|");
 
5034
    lprintf(LOG_NOTICE, "              fault|predict|critical|failed");
 
5035
    lprintf(LOG_NOTICE, "");
 
5036
}
 
5037
 
 
5038
static int
 
5039
IsSetLEDSupported(void)
 
5040
{
 
5041
    return SetLEDSupported;
 
5042
}
 
5043
 
 
5044
static void
 
5045
CheckSetLEDSupport(struct ipmi_intf * intf)
 
5046
{
 
5047
    struct ipmi_rs * rsp = NULL;
 
5048
    struct ipmi_rq req = {0};
 
5049
    uint8_t data[10];
 
5050
 
 
5051
    SetLEDSupported = 0;
 
5052
    req.msg.netfn = DELL_OEM_NETFN;
 
5053
    req.msg.lun = 0;
 
5054
    req.msg.cmd = 0xD5;                 /* Storage */
 
5055
    req.msg.data_len = 10;
 
5056
    req.msg.data = data;
 
5057
 
 
5058
    memset(data, 0, sizeof(data));
 
5059
    data[0] = 0x01;                        // get
 
5060
    data[1] = 0x00;                        // subcmd:get firmware version
 
5061
    data[2] = 0x08;                        // length lsb
 
5062
    data[3] = 0x00;                        // length msb
 
5063
    data[4] = 0x00;                        // offset lsb
 
5064
    data[5] = 0x00;                        // offset msb
 
5065
    data[6] = 0x00;                        // bay id
 
5066
    data[7] = 0x00;             
 
5067
    data[8] = 0x00;
 
5068
    data[9] = 0x00;
 
5069
 
 
5070
    rsp = intf->sendrecv(intf, &req);
 
5071
    if (rsp == NULL || rsp->ccode != 0)
 
5072
    {
 
5073
        return;
 
5074
    }
 
5075
    SetLEDSupported = 1;
 
5076
}
 
5077
 
 
5078
/*****************************************************************
 
5079
* Function Name:    ipmi_getdrivemap
 
5080
*
 
5081
* Description:      This function returns mapping of BDF to Bay:Slot
 
5082
* Input:            intf         - ipmi interface
 
5083
*                   bdf          - PCI Address of drive
 
5084
*                   *bay         - Returns bay ID
 
5085
                    *slot        - Returns slot ID
 
5086
* Output:           
 
5087
*
 
5088
* Return:          
 
5089
*
 
5090
******************************************************************/
 
5091
static int
 
5092
ipmi_getdrivemap(struct ipmi_intf * intf, int b, int d, int f, int *bay, int *slot)
 
5093
{
 
5094
    struct ipmi_rs * rsp = NULL;
 
5095
    struct ipmi_rq req = {0};
 
5096
    uint8_t data[8];
 
5097
 
 
5098
    /* Get mapping of BDF to bay:slot */
 
5099
    req.msg.netfn = DELL_OEM_NETFN;
 
5100
    req.msg.lun = 0;
 
5101
    req.msg.cmd = 0xD5;
 
5102
    req.msg.data_len = 8;
 
5103
    req.msg.data = data;
 
5104
 
 
5105
    memset(data, 0, sizeof(data));
 
5106
    data[0] = 0x01;             // get
 
5107
    data[1] = 0x07;             // storage map
 
5108
    data[2] = 0x06;             // length lsb
 
5109
    data[3] = 0x00;             // length msb
 
5110
    data[4] = 0x00;             // offset lsb
 
5111
    data[5] = 0x00;             // offset msb
 
5112
    data[6] = b;                // bus
 
5113
    data[7] = (d << 3) + f;     // devfn
 
5114
 
 
5115
    rsp = intf->sendrecv(intf, &req);
 
5116
 
 
5117
    if (rsp == NULL)
 
5118
    {
 
5119
        lprintf(LOG_ERR, " Error issuing getdrivemap command.\n");
 
5120
        return -1;
 
5121
    }
 
5122
    else if (rsp->ccode != 0)
 
5123
    {
 
5124
        lprintf(LOG_ERR, "  Error issuing getdrivemap command: %s",
 
5125
            val2str(rsp->ccode, completion_code_vals));
 
5126
        return -1;
 
5127
    }
 
5128
 
 
5129
    *bay = rsp->data[7];
 
5130
    *slot = rsp->data[8];
 
5131
    if (*bay == 0xFF || *slot == 0xFF)
 
5132
    {
 
5133
        lprintf(LOG_ERR, "Error could not get drive bay:slot mapping");
 
5134
        return -1;
 
5135
    }
 
5136
    return 0;
 
5137
}
 
5138
 
 
5139
/*****************************************************************
 
5140
* Function Name:    ipmi_setled_state
 
5141
*
 
5142
* Description:      This function updates the LED on the backplane
 
5143
* Input:            intf         - ipmi interface
 
5144
*                   bdf          - PCI Address of drive
 
5145
*                   state        - SES Flags state of drive
 
5146
* Output:           
 
5147
*
 
5148
* Return:          
 
5149
*
 
5150
******************************************************************/
 
5151
static int
 
5152
ipmi_setled_state (struct ipmi_intf * intf, int bayId, int slotId, int state)
 
5153
{
 
5154
    struct ipmi_rs * rsp = NULL;
 
5155
    struct ipmi_rq req = {0};
 
5156
    uint8_t data[20];
 
5157
 
 
5158
    /* Issue Drive Status Update to bay:slot */
 
5159
    req.msg.netfn = DELL_OEM_NETFN;
 
5160
    req.msg.lun = 0;
 
5161
    req.msg.cmd = 0xD5;
 
5162
    req.msg.data_len = 20;
 
5163
    req.msg.data = data;
 
5164
 
 
5165
    memset(data, 0, sizeof(data));
 
5166
    data[0] = 0x00;             // set
 
5167
    data[1] = 0x04;             // set drive status
 
5168
    data[2] = 0x0e;             // length lsb
 
5169
    data[3] = 0x00;             // length msb
 
5170
    data[4] = 0x00;             // offset lsb
 
5171
    data[5] = 0x00;             // offset msb
 
5172
    data[6] = 0x0e;             // length lsb
 
5173
    data[7] = 0x00;             // length msb
 
5174
    data[8] = bayId;            // bayid
 
5175
    data[9] = slotId;           // slotid
 
5176
    data[10] = state & 0xff;    // state LSB
 
5177
    data[11] = state >> 8;      // state MSB;
 
5178
 
 
5179
    rsp = intf->sendrecv(intf, &req);
 
5180
 
 
5181
    if (rsp == NULL)
 
5182
    {
 
5183
        lprintf(LOG_ERR, " Error issuing setled command.\n");
 
5184
        return -1;
 
5185
    }
 
5186
    else if (rsp->ccode != 0)
 
5187
    {
 
5188
        lprintf(LOG_ERR, "  Error issuing setled command: %s",
 
5189
            val2str(rsp->ccode, completion_code_vals));
 
5190
        return -1;
 
5191
    }
 
5192
    return 0;
 
5193
}
 
5194
 
 
5195
/*****************************************************************
 
5196
* Function Name:    ipmi_getsesmask
 
5197
*
 
5198
* Description:      This function calculates bits in SES drive update
 
5199
* Return:           Mask set with bits for SES backplane update
 
5200
*
 
5201
******************************************************************/
 
5202
static int ipmi_getsesmask(int argc, char **argv)
 
5203
{
 
5204
        int mask = 0;
 
5205
        
 
5206
        while (current_arg < argc) {
 
5207
                if (!strcmp(argv[current_arg], "present"))
 
5208
                        mask |= (1L << 0);
 
5209
                if (!strcmp(argv[current_arg], "online"))
 
5210
                        mask |= (1L << 1);
 
5211
                if (!strcmp(argv[current_arg], "hotspare"))
 
5212
                        mask |= (1L << 2);
 
5213
                if (!strcmp(argv[current_arg], "identify"))
 
5214
                        mask |= (1L << 3);
 
5215
                if (!strcmp(argv[current_arg], "rebuilding"))
 
5216
                        mask |= (1L << 4);
 
5217
                if (!strcmp(argv[current_arg], "fault"))
 
5218
                        mask |= (1L << 5);
 
5219
                if (!strcmp(argv[current_arg], "predict"))
 
5220
                        mask |= (1L << 6);
 
5221
                if (!strcmp(argv[current_arg], "critical"))
 
5222
                        mask |= (1L << 9);
 
5223
                if (!strcmp(argv[current_arg], "failed"))
 
5224
                        mask |= (1L << 10);
 
5225
                current_arg++;
 
5226
        }
 
5227
        return mask;
 
5228
}
 
5229
 
 
5230
/*****************************************************************
 
5231
* Function Name:       ipmi_delloem_setled_main
 
5232
*
 
5233
* Description:         This function processes the delloem setled command
 
5234
* Input:               intf    - ipmi interface
 
5235
                       argc    - no of arguments
 
5236
                       argv    - argument string array
 
5237
* Output:        
 
5238
*
 
5239
* Return:              return code     0 - success
 
5240
*                         -1 - failure
 
5241
*
 
5242
******************************************************************/
 
5243
static int
 
5244
ipmi_delloem_setled_main(struct ipmi_intf * intf, int argc, char ** argv)
 
5245
{
 
5246
    int b,d,f, mask;
 
5247
    int bayId, slotId;
 
5248
 
 
5249
    bayId = 0xFF;
 
5250
    slotId = 0xFF;
 
5251
 
 
5252
    current_arg++;
 
5253
    if (argc < current_arg) 
 
5254
    {
 
5255
        usage();
 
5256
        return -1;
 
5257
    }
 
5258
 
 
5259
    /* ipmitool delloem setled info*/
 
5260
    if (argc == 1 || strcmp(argv[current_arg], "help") == 0)
 
5261
    {
 
5262
        ipmi_setled_usage();
 
5263
        return 0;
 
5264
    }
 
5265
    CheckSetLEDSupport (intf);
 
5266
    if (!IsSetLEDSupported())
 
5267
    {
 
5268
        printf("'setled' is not supported on this system.\n");
 
5269
        return -1;
 
5270
    }
 
5271
    else if (sscanf(argv[current_arg], "%*x:%x:%x.%x", &b,&d,&f) == 3) {
 
5272
        /* We have bus/dev/function of drive */
 
5273
        current_arg++;
 
5274
        ipmi_getdrivemap (intf, b, d, f, &bayId, &slotId);
 
5275
    }
 
5276
    else if (sscanf(argv[current_arg], "%x:%x.%x", &b,&d,&f) == 3) {
 
5277
        /* We have bus/dev/function of drive */
 
5278
        current_arg++;
 
5279
    }
 
5280
    else {
 
5281
        ipmi_setled_usage();
 
5282
        return -1;
 
5283
    }
 
5284
    /* Get mask of SES flags */ 
 
5285
    mask = ipmi_getsesmask(argc, argv);
 
5286
 
 
5287
    /* Get drive mapping */
 
5288
    if (ipmi_getdrivemap (intf, b, d, f, &bayId, &slotId))
 
5289
        return -1;
 
5290
 
 
5291
    /* Set drive LEDs */
 
5292
    return ipmi_setled_state (intf, bayId, slotId, mask);
 
5293
}
 
5294
 
 
5295
 
 
5296
/*****************************************************************
 
5297
 * Function Name:       ipmi_getsysinfo
 
5298
 *
 
5299
 * Description:         This function processes the IPMI Get System Info command
 
5300
 * Input:               intf    - ipmi interface
 
5301
 *                      param   - Parameter # (0xC0..0xFF = OEM)
 
5302
 *                      block/set - Block/Set number of parameter
 
5303
 *                      len     - Length of buffer
 
5304
 *                      buffer  - Pointer to buffer
 
5305
 * Output:        
 
5306
 *
 
5307
 * Return:              return code     0 - success
 
5308
 *                         -1 - failure
 
5309
 *                         other = IPMI ccode
 
5310
 *
 
5311
 ******************************************************************/
 
5312
static int
 
5313
ipmi_getsysinfo(struct ipmi_intf * intf, int param, int block, int set, int len, void *buffer)
 
5314
{
 
5315
    uint8_t data[4];
 
5316
    struct ipmi_rs *rsp = NULL;
 
5317
    struct ipmi_rq req={0};
 
5318
 
 
5319
    memset(buffer, 0, len);
 
5320
    memset(data, 0, 4);
 
5321
    req.msg.netfn = IPMI_NETFN_APP;
 
5322
    req.msg.lun = 0;
 
5323
    req.msg.cmd = IPMI_GET_SYS_INFO;
 
5324
    req.msg.data_len = 4;
 
5325
    req.msg.data = data;
 
5326
    
 
5327
    data[0] = 0; // get/set
 
5328
    data[1] = param;
 
5329
    data[2] = block;
 
5330
    data[3] = set;
 
5331
 
 
5332
    rsp = intf->sendrecv(intf, &req);
 
5333
    if (rsp != NULL) {
 
5334
        if (rsp->ccode == 0) {
 
5335
            if (len > rsp->data_len)
 
5336
                len = rsp->data_len;
 
5337
            if (len && buffer)
 
5338
                memcpy(buffer, rsp->data, len);
 
5339
        }
 
5340
        return rsp->ccode;
 
5341
    }
 
5342
    return -1;
 
5343
}