File fix_led_states.patch of Package ipmitool.3806

From: Jens Nyberg <jens.nyberg@ericsson.com>
Subject: ID:431 - Fix correct interpretation of led states
References: bsc#1011283
Patch-Mainline: IPMITOOL_1_8_17
Git-commit: cacdd1b6ec9bf04ea7dcaf6d66cc5cacbce56aa7
Git-repo: git.code.sf.net/p/ipmitool/source

Signed-off-by: Thomas Renninger <trenn@suse.de>

The LED state bits are not mutually exclusive. Bit [0] says LEDs can be
controlled locally and the state bit [1] says wheter the default local
settings or the override settings are used. This means that both bits can be
set at the same time.

Bit [2], the lamp test, indicates wether the test is in progress and logically
works the same as [1].

If bit [0] is not set then bit [1] and [2] has no meaning.

Signed-off-by: Jens Nyberg <jens.nyberg@ericsson.com>

Index: ipmitool-1.8.13/lib/ipmi_picmg.c
===================================================================
--- ipmitool-1.8.13.orig/lib/ipmi_picmg.c	2016-11-28 16:03:56.860278036 +0100
+++ ipmitool-1.8.13/lib/ipmi_picmg.c	2016-11-28 16:04:16.809411349 +0100
@@ -1303,49 +1303,53 @@ ipmi_picmg_get_led_state(struct ipmi_int
 	}
 
 	printf("LED states:						  %x	", rsp->data[1] );
-	if (rsp->data[1] == 0x1)
-		printf("[LOCAL CONTROL]\n");
-	else if (rsp->data[1] == 0x2)
-		printf("[OVERRIDE]\n");
-	else if (rsp->data[1] == 0x4)
-		printf("[LAMPTEST]\n");
-	else
-		printf("\n");
+
+	if (!(rsp->data[1] & 0x1)) {
+		printf("[NO LOCAL CONTROL]\n");
+		return 0;
+	}
+
+	printf("[LOCAL CONTROL");
+
+	if (rsp->data[1] & 0x2) {
+		printf("|OVERRIDE");
+	}
+
+	if (rsp->data[1] & 0x4) {
+		printf("|LAMPTEST");
+	}
+
+	printf("]\n");
 
 	printf("  Local Control function:     %x  ", rsp->data[2] );
-	if (rsp->data[2] == 0x0)
+	if (rsp->data[2] == 0x0) {
 		printf("[OFF]\n");
-	else if (rsp->data[2] == 0xff)
+	} else if (rsp->data[2] == 0xff) {
 		printf("[ON]\n");
-	else
+	} else {
 		printf("[BLINKING]\n");
+	}
 
 	printf("  Local Control On-Duration:  %x\n", rsp->data[3] );
 	printf("  Local Control Color:        %x  [%s]\n", rsp->data[4], led_color_str[ rsp->data[4] ]);
 
 	/* override state or lamp test */
-	if (rsp->data[1] == 0x02) {
+	if (rsp->data[1] & 0x02) {
 		printf("  Override function:     %x  ", rsp->data[5] );
-		if (rsp->data[2] == 0x0)
+		if (rsp->data[2] == 0x0) {
 			printf("[OFF]\n");
-		else if (rsp->data[2] == 0xff)
+		} else if (rsp->data[2] == 0xff) {
 			printf("[ON]\n");
-		else
+		} else {
 			printf("[BLINKING]\n");
+		}
 
 		printf("  Override On-Duration:  %x\n", rsp->data[6] );
 		printf("  Override Color:        %x  [%s]\n", rsp->data[7], led_color_str[ rsp->data[7] ]);
 
-	}else if (rsp->data[1] == 0x06) {
-		printf("  Override function:     %x  ", rsp->data[5] );
-		if (rsp->data[2] == 0x0)
-			printf("[OFF]\n");
-		else if (rsp->data[2] == 0xff)
-			printf("[ON]\n");
-		else
-			printf("[BLINKING]\n");
-		printf("  Override On-Duration:  %x\n", rsp->data[6] );
-		printf("  Override Color:        %x  [%s]\n", rsp->data[7], led_color_str[ rsp->data[7] ]);
+	}
+
+	if (rsp->data[1] & 0x04) {
 		printf("  Lamp test duration:    %x\n", rsp->data[8] );
 	}
 
openSUSE Build Service is sponsored by