/*
 * Copyright (c)  2018-present Facebook.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <ipmid/api.h>

#include <commandutils.hpp>

#define IPMI_CC_PARAMETER_NOT_SUPPORTED 0x80

namespace ipmi
{

void registerTransportFunctions() __attribute__((constructor));

// Transport Command Codes (IPMI/Table H-1)
enum
{
    CMD_TRANSPORT_GET_SOL_CONFIG = 0x22,
};

// SOL Configuration parameters (IPMI/Table 26-5)
enum
{
    SOL_PARAM_SET_IN_PROG,
    SOL_PARAM_SOL_ENABLE,
    SOL_PARAM_SOL_AUTH,
    SOL_PARAM_SOL_THRESHOLD,
    SOL_PARAM_SOL_RETRY,
    SOL_PARAM_SOL_BITRATE,
    SOL_PARAM_SOL_NV_BITRATE,
};

//----------------------------------------------------------------------
// Get SoL Config (IPMI/Section 26.3) (CMD_TRANSPORT_GET_SOL_CONFIG)
//----------------------------------------------------------------------
ipmi_ret_t ipmiTransGetSolConfig(ipmi_netfn_t, ipmi_cmd_t,
                                 ipmi_request_t request,
                                 ipmi_response_t response,
                                 ipmi_data_len_t data_len, ipmi_context_t)
{
    uint8_t* req = reinterpret_cast<uint8_t*>(request);
    uint8_t* res = reinterpret_cast<uint8_t*>(response);
    uint8_t param = req[0];
    uint8_t paramSel = req[1];

    *res++ = 0x01; // Parameter revision
    *data_len = 1;

    /* If request for revision only then return
     * with only one byte of data
     */
    if (param & 0x80)
        return IPMI_CC_OK;

    switch (paramSel)
    {
        case SOL_PARAM_SET_IN_PROG:
            *res++ = 0x00; // Set this value as (set complete)
            *data_len += 1;
            break;
        case SOL_PARAM_SOL_ENABLE:
            *res++ = 0x01; // Enable SoL payload
            *data_len += 1;
            break;
        case SOL_PARAM_SOL_AUTH:
            *res++ = 0x02; // Set as (User Level)
            *data_len += 1;
            break;
        case SOL_PARAM_SOL_THRESHOLD:
            *res++ = 0x00;
            /* Byte 2: Char send thresold: setting this value to 1 means
             * that BMC to send packet as soon as first character arrived.
             */
            *res++ = 0x01;
            *data_len += 2;
            break;
        case SOL_PARAM_SOL_RETRY:
            *res++ = 0x00; // Retry count: No retry after packet transmission.
            *res++ = 0x00; // Retry interval
            *data_len += 2;
            break;
        case SOL_PARAM_SOL_BITRATE:
        case SOL_PARAM_SOL_NV_BITRATE:
            *res++ = 0x09; // Bit rate: set as 57.6 kbps
            *data_len += 1;
            break;
        default:
            *data_len = 0;
            return IPMI_CC_PARAMETER_NOT_SUPPORTED;
            break;
    }

    return IPMI_CC_OK;
}

void registerTransportFunctions()
{
    ipmiPrintAndRegister(NETFUN_TRANSPORT, CMD_TRANSPORT_GET_SOL_CONFIG, NULL,
                         ipmiTransGetSolConfig,
                         PRIVILEGE_OPERATOR); // Get Sol Config

    return;
}
} // namespace ipmi
