#include "sensorhandler.hpp"

#include <malloc.h>

#include <phosphor-logging/lg2.hpp>

extern uint8_t find_type_for_sensor_number(uint8_t);

struct sensorRES_t
{
    uint8_t sensor_number;
    uint8_t operation;
    uint8_t sensor_reading;
    uint8_t assert_state7_0;
    uint8_t assert_state14_8;
    uint8_t deassert_state7_0;
    uint8_t deassert_state14_8;
    uint8_t event_data1;
    uint8_t event_data2;
    uint8_t event_data3;
} __attribute__((packed));

#define ISBITSET(x, y) (((x) >> (y)) & 0x01)
#define ASSERTINDEX 0
#define DEASSERTINDEX 1

// Sensor Type,  Offset, function handler, Dbus Method, Assert value, Deassert
// value
struct lookup_t
{
    uint8_t sensor_type;
    uint8_t offset;
    int (*func)(const sensorRES_t*, const lookup_t*, const char*);
    char member[16];
    char assertion[64];
    char deassertion[64];
};

extern int updateDbusInterface(uint8_t, const char*, const char*);

int set_sensor_dbus_state_simple(const sensorRES_t* pRec,
                                 const lookup_t* pTable, const char* value)
{
    return set_sensor_dbus_state_s(pRec->sensor_number, pTable->member, value);
}

struct event_data_t
{
    uint8_t data;
    char text[64];
};

event_data_t g_fwprogress02h[] = {
    {0x00, "Unspecified"},
    {0x01, "Memory Init"},
    {0x02, "HD Init"},
    {0x03, "Secondary Proc Init"},
    {0x04, "User Authentication"},
    {0x05, "User init system setup"},
    {0x06, "USB configuration"},
    {0x07, "PCI configuration"},
    {0x08, "Option ROM Init"},
    {0x09, "Video Init"},
    {0x0A, "Cache Init"},
    {0x0B, "SM Bus init"},
    {0x0C, "Keyboard Init"},
    {0x0D, "Embedded ctrl init"},
    {0x0E, "Docking station attachment"},
    {0x0F, "Enable docking station"},
    {0x10, "Docking station ejection"},
    {0x11, "Disabling docking station"},
    {0x12, "Calling OS Wakeup"},
    {0x13, "Starting OS"},
    {0x14, "Baseboard Init"},
    {0x15, ""},
    {0x16, "Floppy Init"},
    {0x17, "Keyboard Test"},
    {0x18, "Pointing Device Test"},
    {0x19, "Primary Proc Init"},
    {0xFF, "Unknown"}};

event_data_t g_fwprogress00h[] = {
    {0x00, "Unspecified."},
    {0x01, "No system memory detected"},
    {0x02, "No usable system memory"},
    {0x03, "Unrecoverable hard-disk/ATAPI/IDE"},
    {0x04, "Unrecoverable system-board"},
    {0x05, "Unrecoverable diskette"},
    {0x06, "Unrecoverable hard-disk controller"},
    {0x07, "Unrecoverable PS/2 or USB keyboard"},
    {0x08, "Removable boot media not found"},
    {0x09, "Unrecoverable video controller"},
    {0x0A, "No video device detected"},
    {0x0B, "Firmware ROM corruption detected"},
    {0x0C, "CPU voltage mismatch"},
    {0x0D, "CPU speed matching"},
    {0xFF, "unknown"},
};

char* event_data_lookup(event_data_t* p, uint8_t b)
{
    while (p->data != 0xFF)
    {
        if (p->data == b)
        {
            break;
        }
        p++;
    }

    return p->text;
}

//  The fw progress sensor contains some additional information that needs to be
//  processed prior to calling the dbus code.
int set_sensor_dbus_state_fwprogress(const sensorRES_t* pRec,
                                     const lookup_t* pTable, const char*)
{
    char valuestring[128];
    char* p = valuestring;

    switch (pTable->offset)
    {
        case 0x00:
            std::snprintf(
                p, sizeof(valuestring), "POST Error, %s",
                event_data_lookup(g_fwprogress00h, pRec->event_data2));
            break;
        case 0x01: /* Using g_fwprogress02h for 0x01 because that's what the
                      ipmi spec says to do */
            std::snprintf(
                p, sizeof(valuestring), "FW Hang, %s",
                event_data_lookup(g_fwprogress02h, pRec->event_data2));
            break;
        case 0x02:
            std::snprintf(
                p, sizeof(valuestring), "FW Progress, %s",
                event_data_lookup(g_fwprogress02h, pRec->event_data2));
            break;
        default:
            std::snprintf(
                p, sizeof(valuestring),
                "Internal warning, fw_progres offset unknown (0x%02x)",
                pTable->offset);
            break;
    }

    return set_sensor_dbus_state_s(pRec->sensor_number, pTable->member, p);
}

// Handling this special OEM sensor by coping what is in byte 4.  I also think
// that is odd considering byte 3 is for sensor reading.  This seems like a
// misuse of the IPMI spec
int set_sensor_dbus_state_osbootcount(const sensorRES_t* pRec, const lookup_t*,
                                      const char*)
{
    return set_sensor_dbus_state_y(pRec->sensor_number, "setValue",
                                   pRec->assert_state7_0);
}

int set_sensor_dbus_state_system_event(const sensorRES_t* pRec,
                                       const lookup_t* pTable, const char*)
{
    char valuestring[128];
    char* p = valuestring;

    switch (pTable->offset)
    {
        case 0x00:
            std::snprintf(p, sizeof(valuestring), "System Reconfigured");
            break;
        case 0x01:
            std::snprintf(p, sizeof(valuestring), "OEM Boot Event");
            break;
        case 0x02:
            std::snprintf(p, sizeof(valuestring),
                          "Undetermined System Hardware Failure");
            break;
        case 0x03:
            std::snprintf(
                p, sizeof(valuestring),
                "System Failure see error log for more details (0x%02x)",
                pRec->event_data2);
            break;
        case 0x04:
            std::snprintf(
                p, sizeof(valuestring),
                "System Failure see PEF error log for more details (0x%02x)",
                pRec->event_data2);
            break;
        default:
            std::snprintf(
                p, sizeof(valuestring),
                "Internal warning, system_event offset unknown (0x%02x)",
                pTable->offset);
            break;
    }

    return set_sensor_dbus_state_s(pRec->sensor_number, pTable->member, p);
}

//  This table lists only senors we care about telling dbus about.
//  Offset definition cab be found in section 42.2 of the IPMI 2.0
//  spec.  Add more if/when there are more items of interest.
lookup_t g_ipmidbuslookup[] = {

    {0xe9, 0x00, set_sensor_dbus_state_simple, "setValue", "Disabled",
     ""}, // OCC Inactive 0
    {0xe9, 0x01, set_sensor_dbus_state_simple, "setValue", "Enabled",
     ""}, // OCC Active 1
    // Turbo Allowed
    {0xda, 0x00, set_sensor_dbus_state_simple, "setValue", "True", "False"},
    // Power Supply Derating
    {0xb4, 0x00, set_sensor_dbus_state_simple, "setValue", "", ""},
    // Power Cap
    {0xC2, 0x00, set_sensor_dbus_state_simple, "setValue", "", ""},
    {0x07, 0x07, set_sensor_dbus_state_simple, "setPresent", "True", "False"},
    {0x07, 0x08, set_sensor_dbus_state_simple, "setFault", "True", "False"},
    {0x0C, 0x06, set_sensor_dbus_state_simple, "setPresent", "True", "False"},
    {0x0C, 0x04, set_sensor_dbus_state_simple, "setFault", "True", "False"},
    {0x0F, 0x02, set_sensor_dbus_state_fwprogress, "setValue", "True", "False"},
    {0x0F, 0x01, set_sensor_dbus_state_fwprogress, "setValue", "True", "False"},
    {0x0F, 0x00, set_sensor_dbus_state_fwprogress, "setValue", "True", "False"},
    {0xC7, 0x01, set_sensor_dbus_state_simple, "setFault", "True", "False"},
    {0xc3, 0x00, set_sensor_dbus_state_osbootcount, "setValue", "", ""},
    {0x1F, 0x00, set_sensor_dbus_state_simple, "setValue",
     "Boot completed (00)", ""},
    {0x1F, 0x01, set_sensor_dbus_state_simple, "setValue",
     "Boot completed (01)", ""},
    {0x1F, 0x02, set_sensor_dbus_state_simple, "setValue", "PXE boot completed",
     ""},
    {0x1F, 0x03, set_sensor_dbus_state_simple, "setValue",
     "Diagnostic boot completed", ""},
    {0x1F, 0x04, set_sensor_dbus_state_simple, "setValue",
     "CD-ROM boot completed", ""},
    {0x1F, 0x05, set_sensor_dbus_state_simple, "setValue", "ROM boot completed",
     ""},
    {0x1F, 0x06, set_sensor_dbus_state_simple, "setValue",
     "Boot completed (06)", ""},
    {0x12, 0x00, set_sensor_dbus_state_system_event, "setValue", "", ""},
    {0x12, 0x01, set_sensor_dbus_state_system_event, "setValue", "", ""},
    {0x12, 0x02, set_sensor_dbus_state_system_event, "setValue", "", ""},
    {0x12, 0x03, set_sensor_dbus_state_system_event, "setValue", "", ""},
    {0x12, 0x04, set_sensor_dbus_state_system_event, "setValue", "", ""},
    {0xCA, 0x00, set_sensor_dbus_state_simple, "setValue", "Disabled", ""},
    {0xCA, 0x01, set_sensor_dbus_state_simple, "setValue", "Enabled", ""},
    {0xFF, 0xFF, NULL, "", "", ""}};

void reportSensorEventAssert(const sensorRES_t* pRec, int index)
{
    lookup_t* pTable = &g_ipmidbuslookup[index];
    (*pTable->func)(pRec, pTable, pTable->assertion);
}
void reportSensorEventDeassert(const sensorRES_t* pRec, int index)
{
    lookup_t* pTable = &g_ipmidbuslookup[index];
    (*pTable->func)(pRec, pTable, pTable->deassertion);
}

int findindex(const uint8_t sensor_type, int offset, int* index)
{
    int i = 0, rc = 0;
    lookup_t* pTable = g_ipmidbuslookup;

    do
    {
        if (((pTable + i)->sensor_type == sensor_type) &&
            ((pTable + i)->offset == offset))
        {
            rc = 1;
            *index = i;
            break;
        }
        i++;
    } while ((pTable + i)->sensor_type != 0xFF);

    return rc;
}

bool shouldReport(uint8_t sensorType, int offset, int* index)
{
    bool rc = false;

    if (findindex(sensorType, offset, index))
    {
        rc = true;
    }
    if (rc == false)
    {
#ifdef __IPMI_DEBUG__
        lg2::debug("LOOKATME: Sensor should not be reported, "
                   "sensor type: {SENSORTYPE}, offset: {OFFSET}",
                   SENSORTYPE, lg2::hex, sensorType, "OFFSET", lg2::hex,
                   offset);
#endif
    }

    return rc;
}

int updateSensorRecordFromSSRAESC(const void* record)
{
    auto pRec = static_cast<const sensorRES_t*>(record);
    uint8_t stype;
    int index;

    stype = find_type_for_sensor_number(pRec->sensor_number);

    // 0xC3 types use the assertion7_0 for the value to be set
    // so skip the reseach and call the correct event reporting
    // function
    if (stype == 0xC3)
    {
        shouldReport(stype, 0x00, &index);
        reportSensorEventAssert(pRec, index);
    }
    else
    {
        // Scroll through each bit position .  Determine
        // if any bit is either asserted or Deasserted.
        for (int i = 0; i < 8; i++)
        {
            if ((ISBITSET(pRec->assert_state7_0, i)) &&
                (shouldReport(stype, i, &index)))
            {
                reportSensorEventAssert(pRec, index);
            }
            if ((ISBITSET(pRec->assert_state14_8, i)) &&
                (shouldReport(stype, i + 8, &index)))
            {
                reportSensorEventAssert(pRec, index);
            }
            if ((ISBITSET(pRec->deassert_state7_0, i)) &&
                (shouldReport(stype, i, &index)))
            {
                reportSensorEventDeassert(pRec, index);
            }
            if ((ISBITSET(pRec->deassert_state14_8, i)) &&
                (shouldReport(stype, i + 8, &index)))
            {
                reportSensorEventDeassert(pRec, index);
            }
        }
    }

    return 0;
}
