Get Channel Authentication Capabilities Implementation

Change-Id: Id8fa42814fe210ca8f9dbb14de746c66e391d334
Signed-off-by: Tom Joseph <tomjoseph@in.ibm.com>
diff --git a/command/channel_auth.cpp b/command/channel_auth.cpp
new file mode 100644
index 0000000..e9a91e6
--- /dev/null
+++ b/command/channel_auth.cpp
@@ -0,0 +1,54 @@
+#include "channel_auth.hpp"
+
+#include <iostream>
+
+#include <host-ipmid/ipmid-api.h>
+
+namespace command
+{
+
+std::vector<uint8_t> GetChannelCapabilities(std::vector<uint8_t>& inPayload,
+                                            const message::Handler& handler)
+{
+    std::cout << ">> GetChannelCapabilities\n";
+
+    std::vector<uint8_t> outPayload(sizeof(GetChannelCapabilitiesResp));
+    auto response = reinterpret_cast<GetChannelCapabilitiesResp*>
+                    (outPayload.data());
+
+    // A canned response, since there is no user and channel management.
+    response->completionCode = IPMI_CC_OK ;
+
+    // Channel Number 1 is arbitarily applied to primary LAN channel;
+    response->channelNumber = 1;
+
+    response->ipmiVersion = 1 ;     //IPMI v2.0 extended capabilities available.
+    response->reserved1 = 0;
+    response->oem = 0;
+    response->straightKey = 0;
+    response->reserved2 = 0;
+    response->md5 = 0;
+    response->md2 = 0;
+
+
+    response->reserved3 = 0;
+    response->KGStatus = 0;         //KG is set to default
+    response->perMessageAuth = 0;   //Per-message Authentication is enabled
+    response->userAuth = 0;         //User Level Authentication is enabled
+    response->nonNullUsers = 1;     //Non-null usernames enabled
+    response->nullUsers = 1;        //Null usernames enabled
+    response->anonymousLogin = 0;   //Anonymous Login disabled
+
+    response->reserved4 = 0;
+    response->extCapabilities = 0x2;    //Channel supports IPMI v2.0 connections
+
+    response->oemID[0] = 0;
+    response->oemID[1] = 0;
+    response->oemID[2] = 0;
+    response->oemAuxillary = 0;
+
+    std::cout << "<< GetChannelCapabilities\n";
+    return outPayload;
+}
+
+} // namespace command
diff --git a/command/channel_auth.hpp b/command/channel_auth.hpp
new file mode 100644
index 0000000..1d1d5c4
--- /dev/null
+++ b/command/channel_auth.hpp
@@ -0,0 +1,124 @@
+#pragma once
+
+#include <vector>
+
+#include "message_handler.hpp"
+
+namespace command
+{
+
+/*
+ * @ struct GetChannelCapabilitiesReq
+ *
+ * IPMI Request data for Get Channel Authentication Capabilities command
+ */
+struct GetChannelCapabilitiesReq
+{
+    uint8_t channelNumber;
+    uint8_t reqMaxPrivLevel;
+} __attribute__((packed));
+
+/*
+ * @ struct GetChannelCapabilitiesResp
+ *
+ * IPMI Response data for Get Channel Authentication Capabilities command
+ */
+struct GetChannelCapabilitiesResp
+{
+    uint8_t completionCode;     // Completion Code
+
+    uint8_t channelNumber;      // Channel number that the request was
+    // received on
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+    uint8_t none : 1;
+    uint8_t md2 : 1;
+    uint8_t md5 : 1;
+    uint8_t reserved2 : 1;
+    uint8_t straightKey : 1;   // Straight password/key support
+    // Support OEM identified by the IANA OEM ID in RMCP+ ping response
+    uint8_t oem : 1;
+    uint8_t reserved1 : 1;
+    uint8_t ipmiVersion : 1;    // 0b = IPMIV1.5 support only, 1B = IPMI V2.0
+    // support
+#endif
+
+#if BYTE_ORDER == BIG_ENDIAN
+    uint8_t ipmiVersion : 1;    // 0b = IPMIV1.5 support only, 1B = IPMI V2.0
+    // support
+    uint8_t reserved1 : 1;
+    // Support OEM identified by the IANA OEM ID in RMCP+ ping response
+    uint8_t oem : 1;
+    uint8_t straightKey : 1;   // Straight password/key support
+    uint8_t reserved2 : 1;
+    uint8_t md5 : 1;
+    uint8_t md2 : 1;
+    uint8_t none : 1;
+#endif
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+    // Two key login status . only for IPMI V2.0 RMCP+ RAKP
+    uint8_t KGStatus : 1;
+    uint8_t perMessageAuth : 1; // Per-message authentication support
+    uint8_t userAuth : 1;       // User - level authentication status
+    // Anonymous login status for non_null usernames enabled/disabled
+    uint8_t nonNullUsers : 1;
+    // Anonymous login status for null user names enabled/disabled
+    uint8_t nullUsers : 1;
+    // Anonymous login status for anonymous login enabled/disabled
+    uint8_t anonymousLogin : 1;
+    uint8_t reserved3 : 2;
+#endif
+
+#if BYTE_ORDER == BIG_ENDIAN
+    uint8_t reserved3 : 2;
+    // Anonymous login status for anonymous login enabled/disabled
+    uint8_t anonymousLogin : 1;
+    // Anonymous login status for null user names enabled/disabled
+    uint8_t nullUsers : 1;
+    // Anonymous login status for non_null usernames enabled/disabled
+    uint8_t nonNullUsers : 1;
+    uint8_t userAuth : 1;       // User - level authentication status
+    uint8_t perMessageAuth : 1; // Per-message authentication support
+    // Two key login status . only for IPMI V2.0 RMCP+ RAKP
+    uint8_t KGStatus : 1;
+#endif
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+    // Extended capabilities will be present only if IPMI version is V2.0
+    uint8_t extCapabilities : 2; // Channel support for IPMI V2.0 connections
+    uint8_t reserved4 : 6;
+#endif
+
+#if BYTE_ORDER == BIG_ENDIAN
+    // Extended capabilities will be present only if IPMI version is V2.0
+    uint8_t reserved4 : 6;
+    uint8_t extCapabilities : 2; // Channel support for IPMI V2.0 connections
+#endif
+
+    // Below 4 bytes will all the 0's if no OEM authentication type available.
+    uint8_t oemID[3];  // IANA enterprise number for OEM/organization
+    uint8_t oemAuxillary;  // Addition OEM specific information..
+} __attribute__((packed));
+
+/*
+ * @brief Get Channel Authentication Capabilities
+ *
+ * This message exchange provides a way for a remote console to discover what
+ * IPMI version is supported i.e. whether or not the BMC supports the IPMI
+ * v2.0 / RMCP+ packet format. It also provides information that the remote
+ * console can use to determine whether anonymous, “one-key”, or “two-key”
+ * logins are used.This information can guide a remote console in how it
+ * presents queries to users for username and password information. This is a
+ * ‘session-less’ command that the BMC accepts in both IPMI v1.5 and v2.0/RMCP+
+ * packet formats.
+ *
+ * @param[in] inPayload - Request Data for the command
+ * @param[in] handler - Reference to the Message Handler
+ *
+ * @return Response data for the command
+ */
+std::vector<uint8_t> GetChannelCapabilities(std::vector<uint8_t>& inPayload,
+                                            const message::Handler& handler);
+
+} // namespace command