Create library for System Interface Commands.

There are IPMI commands like Read Event Message Buffer, Set BMC Global
Enables and Get Message Flags which is to be executed from host
interface only. So creating a separate library for these commands which
would be used only by phosphor-host-ipmid.

Change-Id: I14cb4019b9ab19c84e463e5a7820010f57f1c5eb
Signed-off-by: Tom Joseph <tomjoseph@in.ibm.com>
diff --git a/Makefile.am b/Makefile.am
index 4053e1b..8a220c5 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -36,6 +36,12 @@
 libapphandler_la_LDFLAGS = $(SYSTEMD_LIBS) $(libmapper_LIBS) -version-info 0:0:0 -shared
 libapphandler_la_CXXFLAGS = $(SYSTEMD_CFLAGS) $(libmapper_CFLAGS)
 
+libsysintfcmdsdir = ${libdir}/host-ipmid
+libsysintfcmds_LTLIBRARIES = libsysintfcmds.la
+libsysintfcmds_la_SOURCES = \
+	systemintfcmds.cpp
+libsysintfcmds_la_LDFLAGS = -version-info 0:0:0 -shared
+
 libhostservicedir = ${libdir}/host-ipmid
 libhostservice_LTLIBRARIES = libhostservice.la
 libhostservice_la_SOURCES = \
diff --git a/apphandler.cpp b/apphandler.cpp
index 28d97c9..394f716 100644
--- a/apphandler.cpp
+++ b/apphandler.cpp
@@ -31,76 +31,6 @@
    uint8_t aux[4];
 }__attribute__((packed)) ipmi_device_id_t;
 
-//---------------------------------------------------------------------
-// Called by Host on seeing a SMS_ATN bit set. Return a hardcoded
-// value of 0x2 indicating we need Host read some data.
-//-------------------------------------------------------------------
-ipmi_ret_t ipmi_app_get_msg_flags(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
-                             ipmi_request_t request, ipmi_response_t response,
-                             ipmi_data_len_t data_len, ipmi_context_t context)
-{
-	// Generic return from IPMI commands.
-    ipmi_ret_t rc = IPMI_CC_OK;
-
-    printf("IPMI APP GET MSG FLAGS returning with [bit:2] set\n");
-
-	// From IPMI spec V2.0 for Get Message Flags Command :
-	// bit:[1] from LSB : 1b = Event Message Buffer Full.
-	// Return as 0 if Event Message Buffer is not supported,
-	// or when the Event Message buffer is disabled.
-	// TODO. For now. assume its not disabled and send "0x2" anyway:
-
-	uint8_t set_event_msg_buffer_full = 0x2;
-    *data_len = sizeof(set_event_msg_buffer_full);
-
-    // Pack the actual response
-    memcpy(response, &set_event_msg_buffer_full, *data_len);
-
-    return rc;
-}
-
-//-------------------------------------------------------------------
-// Called by Host post response from Get_Message_Flags
-//-------------------------------------------------------------------
-ipmi_ret_t ipmi_app_read_event(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
-                             ipmi_request_t request, ipmi_response_t response,
-                             ipmi_data_len_t data_len, ipmi_context_t context)
-{
-    ipmi_ret_t rc = IPMI_CC_OK;
-    printf("IPMI APP READ EVENT command received\n");
-
-	// TODO : For now, this is catering only to the Soft Power Off via OEM SEL
-	//        mechanism. If we need to make this generically used for some
-	//        other conditions, then we can take advantage of context pointer.
-
-	struct oem_sel_timestamped soft_off = {0};
-    *data_len = sizeof(struct oem_sel_timestamped);
-
-	// either id[0] -or- id[1] can be filled in. We will use id[0]
-	soft_off.id[0]	 = SEL_OEM_ID_0;
-	soft_off.id[1]	 = SEL_OEM_ID_0;
-	soft_off.type	 = SEL_RECORD_TYPE_OEM;
-
-	// Following 3 bytes are from IANA Manufactre_Id field. See below
-	soft_off.manuf_id[0]= 0x41;
-	soft_off.manuf_id[1]= 0xA7;
-	soft_off.manuf_id[2]= 0x00;
-
-	// per IPMI spec NetFuntion for OEM
-	soft_off.netfun	 = 0x3A;
-
-	// Mechanism to kick start soft shutdown.
-	soft_off.cmd	 = CMD_POWER;
-	soft_off.data[0] = SOFT_OFF;
-
-	// All '0xFF' since unused.
-	memset(&soft_off.data[1], 0xFF, 3);
-
-    // Pack the actual response
-    memcpy(response, &soft_off, *data_len);
-    return rc;
-}
-
 ipmi_ret_t ipmi_app_set_acpi_power_state(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
                              ipmi_request_t request, ipmi_response_t response,
                              ipmi_data_len_t data_len, ipmi_context_t context)
@@ -694,21 +624,6 @@
     return rc;
 }
 
-ipmi_ret_t ipmi_app_set_bmc_global_enables(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
-                             ipmi_request_t request, ipmi_response_t response,
-                             ipmi_data_len_t data_len, ipmi_context_t context)
-{
-    ipmi_ret_t rc = IPMI_CC_OK;
-    *data_len = 0;
-
-    // Event and message logging enabled by default so return for now
-    printf("IPMI APP SET BMC GLOBAL ENABLES Ignoring for now\n");
-
-    return rc;
-}
-
-
-
 ipmi_ret_t ipmi_app_wildcard_handler(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
                               ipmi_request_t request, ipmi_response_t response,
                               ipmi_data_len_t data_len, ipmi_context_t context)
@@ -752,17 +667,6 @@
     printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_SET_ACPI);
     ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_ACPI, NULL, ipmi_app_set_acpi_power_state);
 
-    printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_READ_EVENT);
-    ipmi_register_callback(NETFUN_APP, IPMI_CMD_READ_EVENT, NULL, ipmi_app_read_event);
-
-    printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP,
-                                            IPMI_CMD_SET_BMC_GLOBAL_ENABLES);
-    ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_BMC_GLOBAL_ENABLES, NULL,
-                                            ipmi_app_set_bmc_global_enables);
-
-    printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_MSG_FLAGS);
-    ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_MSG_FLAGS, NULL, ipmi_app_get_msg_flags);
-
     printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP,
                                             IPMI_CMD_SET_CHAN_ACCESS);
     ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_CHAN_ACCESS, NULL,
@@ -771,8 +675,6 @@
     printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_CHAN_INFO);
     ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_CHAN_INFO, NULL, ipmi_app_channel_info);
 
-
-
     return;
 }
 
diff --git a/apphandler.h b/apphandler.h
index 5753c27..ec7d4b0 100644
--- a/apphandler.h
+++ b/apphandler.h
@@ -3,17 +3,6 @@
 
 #include <stdint.h>
 
-// These are per skiboot ipmi-sel code
-
-// OEM_SEL type with Timestamp
-#define SEL_OEM_ID_0		0x55
-// SEL type is OEM and -not- general SEL
-#define SEL_RECORD_TYPE_OEM	0xC0
-// Minor command for soft shurdown
-#define SOFT_OFF			0x00
-// Major command for Any kind of power ops
-#define CMD_POWER			0x04
-
 // IPMI commands for App net functions.
 enum ipmi_netfn_app_cmds
 {
@@ -24,31 +13,9 @@
     IPMI_CMD_GET_DEVICE_GUID        = 0x08,
     IPMI_CMD_RESET_WD               = 0x22,
     IPMI_CMD_SET_WD                 = 0x24,
-    IPMI_CMD_SET_BMC_GLOBAL_ENABLES = 0x2E,
-    IPMI_CMD_GET_MSG_FLAGS          = 0x31,
-    IPMI_CMD_READ_EVENT             = 0x35,
     IPMI_CMD_GET_CAP_BIT            = 0x36,
     IPMI_CMD_SET_CHAN_ACCESS        = 0x40,
     IPMI_CMD_GET_CHAN_INFO          = 0x42,
-
 };
 
-// A Mechanism to tell host to shtudown hosts by sending this PEM SEL. Really
-// the only used fields by skiboot are:
-// id[0] / id[1] for ID_0 , ID_1
-// type : SEL_RECORD_TYPE_OEM as standard SELs are ignored by skiboot
-// cmd : CMD_POWER for power functions
-// data[0], specific commands.  example Soft power off. power cycle, etc.
-struct oem_sel_timestamped
-{
-	/* SEL header */
-	uint8_t id[2];
-	uint8_t type;
-	uint8_t manuf_id[3];
-	uint8_t timestamp[4];
-	/* OEM SEL data (6 bytes) follows */
-	uint8_t netfun;
-	uint8_t cmd;
-	uint8_t data[4];
-};
 #endif
diff --git a/systemintfcmds.cpp b/systemintfcmds.cpp
new file mode 100644
index 0000000..d920f95
--- /dev/null
+++ b/systemintfcmds.cpp
@@ -0,0 +1,109 @@
+#include "systemintfcmds.h"
+#include "host-ipmid/ipmid-api.h"
+
+#include <stdio.h>
+
+void register_netfn_app_functions() __attribute__((constructor));
+
+//-------------------------------------------------------------------
+// Called by Host post response from Get_Message_Flags
+//-------------------------------------------------------------------
+ipmi_ret_t ipmi_app_read_event(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
+                             ipmi_request_t request, ipmi_response_t response,
+                             ipmi_data_len_t data_len, ipmi_context_t context)
+{
+    ipmi_ret_t rc = IPMI_CC_OK;
+    printf("IPMI APP READ EVENT command received\n");
+
+    // TODO : For now, this is catering only to the Soft Power Off via OEM SEL
+    //        mechanism. If we need to make this generically used for some
+    //        other conditions, then we can take advantage of context pointer.
+
+    struct oem_sel_timestamped soft_off = {0};
+    *data_len = sizeof(struct oem_sel_timestamped);
+
+    // either id[0] -or- id[1] can be filled in. We will use id[0]
+    soft_off.id[0]   = SEL_OEM_ID_0;
+    soft_off.id[1]   = SEL_OEM_ID_0;
+    soft_off.type    = SEL_RECORD_TYPE_OEM;
+
+    // Following 3 bytes are from IANA Manufactre_Id field. See below
+    soft_off.manuf_id[0]= 0x41;
+    soft_off.manuf_id[1]= 0xA7;
+    soft_off.manuf_id[2]= 0x00;
+
+    // per IPMI spec NetFuntion for OEM
+    soft_off.netfun  = 0x3A;
+
+    // Mechanism to kick start soft shutdown.
+    soft_off.cmd     = CMD_POWER;
+    soft_off.data[0] = SOFT_OFF;
+
+    // All '0xFF' since unused.
+    memset(&soft_off.data[1], 0xFF, 3);
+
+    // Pack the actual response
+    memcpy(response, &soft_off, *data_len);
+    return rc;
+}
+
+//---------------------------------------------------------------------
+// Called by Host on seeing a SMS_ATN bit set. Return a hardcoded
+// value of 0x2 indicating we need Host read some data.
+//-------------------------------------------------------------------
+ipmi_ret_t ipmi_app_get_msg_flags(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
+                             ipmi_request_t request, ipmi_response_t response,
+                             ipmi_data_len_t data_len, ipmi_context_t context)
+{
+    // Generic return from IPMI commands.
+    ipmi_ret_t rc = IPMI_CC_OK;
+
+    printf("IPMI APP GET MSG FLAGS returning with [bit:2] set\n");
+
+    // From IPMI spec V2.0 for Get Message Flags Command :
+    // bit:[1] from LSB : 1b = Event Message Buffer Full.
+    // Return as 0 if Event Message Buffer is not supported,
+    // or when the Event Message buffer is disabled.
+    // TODO. For now. assume its not disabled and send "0x2" anyway:
+
+    uint8_t set_event_msg_buffer_full = 0x2;
+    *data_len = sizeof(set_event_msg_buffer_full);
+
+    // Pack the actual response
+    memcpy(response, &set_event_msg_buffer_full, *data_len);
+
+    return rc;
+}
+
+ipmi_ret_t ipmi_app_set_bmc_global_enables(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
+                             ipmi_request_t request, ipmi_response_t response,
+                             ipmi_data_len_t data_len, ipmi_context_t context)
+{
+    ipmi_ret_t rc = IPMI_CC_OK;
+    *data_len = 0;
+
+    // Event and message logging enabled by default so return for now
+    printf("IPMI APP SET BMC GLOBAL ENABLES Ignoring for now\n");
+
+    return rc;
+}
+
+void register_netfn_app_functions()
+{
+
+    // <Read Event Message Buffer>
+    printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_READ_EVENT);
+    ipmi_register_callback(NETFUN_APP, IPMI_CMD_READ_EVENT, NULL, ipmi_app_read_event);
+
+    // <Set BMC Global Enables>
+    printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP,
+                                            IPMI_CMD_SET_BMC_GLOBAL_ENABLES);
+    ipmi_register_callback(NETFUN_APP, IPMI_CMD_SET_BMC_GLOBAL_ENABLES, NULL,
+                           ipmi_app_set_bmc_global_enables);
+
+    // <Get Message Flags>
+    printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_APP, IPMI_CMD_GET_MSG_FLAGS);
+    ipmi_register_callback(NETFUN_APP, IPMI_CMD_GET_MSG_FLAGS, NULL, ipmi_app_get_msg_flags);
+
+    return;
+}
diff --git a/systemintfcmds.h b/systemintfcmds.h
new file mode 100644
index 0000000..19526f6
--- /dev/null
+++ b/systemintfcmds.h
@@ -0,0 +1,44 @@
+#ifndef __SYSTEM_INTF_CMDS_HANDLER_H__
+#define __SYSTEM_INTF_CMDS_HANDLER_H__
+
+#include <stdint.h>
+
+// These are per skiboot ipmi-sel code
+
+// OEM_SEL type with Timestamp
+#define SEL_OEM_ID_0        0x55
+// SEL type is OEM and -not- general SEL
+#define SEL_RECORD_TYPE_OEM 0xC0
+// Minor command for soft shurdown
+#define SOFT_OFF            0x00
+// Major command for Any kind of power ops
+#define CMD_POWER           0x04
+
+// IPMI commands used via System Interface functions.
+enum ipmi_netfn_system_intf_cmds
+{
+    IPMI_CMD_SET_BMC_GLOBAL_ENABLES = 0x2E,
+    IPMI_CMD_GET_MSG_FLAGS          = 0x31,
+    IPMI_CMD_READ_EVENT             = 0x35,
+};
+
+// A Mechanism to tell host to shtudown hosts by sending this PEM SEL. Really
+// the only used fields by skiboot are:
+// id[0] / id[1] for ID_0 , ID_1
+// type : SEL_RECORD_TYPE_OEM as standard SELs are ignored by skiboot
+// cmd : CMD_POWER for power functions
+// data[0], specific commands.  example Soft power off. power cycle, etc.
+struct oem_sel_timestamped
+{
+    /* SEL header */
+    uint8_t id[2];
+    uint8_t type;
+    uint8_t manuf_id[3];
+    uint8_t timestamp[4];
+    /* OEM SEL data (6 bytes) follows */
+    uint8_t netfun;
+    uint8_t cmd;
+    uint8_t data[4];
+};
+
+#endif