Commit 37780656 authored by Jonathan Currier's avatar Jonathan Currier

Initial implementation of IPMI/RTC backend

parent 270063ee
ACLOCAL_AMFLAGS = -I m4
ibmrdir = $(libdir)/ipmi-bt-miniroute
ibmr_LTLIBRARIES = libstorage-time.la
libstorage_time_la_SOURCES = src/lib/storage-time.c
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
AC_INIT([ipmi-openpower-storage-time], [VERSION], [BUG-REPORT-ADDRESS])
AC_CONFIG_SRCDIR([src/lib/storage-time.c])
AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE([1.11 parallel-tests foreign no-dist-gzip dist-xz color-tests subdir-objects])
AM_SILENT_RULES([yes])
AC_CONFIG_MACRO_DIRS([m4])
# Checks for programs.
AC_PROG_CC
LT_INIT
# Checks for libraries.
# Checks for header files.
AC_CHECK_HEADERS([string.h unistd.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_UINT32_T
AC_TYPE_UINT8_T
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <endian.h>
#include <time.h>
#include <stdint.h>
#include "ipmi-bt-miniroute/ipmi-packet.h"
int storage_time_get_sel(struct ipmi_req *ipmi_req);
int storage_time_set_sel(struct ipmi_req *ipmi_req);
int storage_time_get_sel_utc(struct ipmi_req *ipmi_req);
int storage_time_set_sel_utc(struct ipmi_req *ipmi_req);
/* We really should initialize this.
* Maybe save/load from a cfg file... not sure.
* Offset is here so that the host can set the time, without
* forcing the bmc's time */
static time_t offset = 0;
void init_lib()
{
static const int storage_netfn = 0x0a;
/* If time_t is smaller than 4 bytes.... well I give up. everything is
* undefined behavior at that point. */
if (sizeof(time_t) == 4)
dprintf(2, "WARNING: running on an ABI which will break in January of 2038\n");
register_netfn_cmd(storage_netfn, 0x48, storage_time_get_sel);
register_netfn_cmd(storage_netfn, 0x49, storage_time_set_sel);
register_netfn_cmd(storage_netfn, 0x5c, storage_time_get_sel_utc);
register_netfn_cmd(storage_netfn, 0x5d, storage_time_set_sel_utc);
}
int storage_time_get_sel(struct ipmi_req *ipmi_req)
{
time_t req_time = time(NULL) + offset;
uint32_t out_val = htole32(req_time);
memcpy(ipmi_req->payload, &out_val, sizeof(out_val));
ipmi_req->cc = 0;
/* bottom bit on the netfn is the response bit */
ipmi_req->netfn |= 1;
/* ipmi header is 4 bytes 1 byte completion code, then payload*/
ipmi_req->len = 4 + 1 + sizeof(out_val);
return 0;
}
int storage_time_set_sel(struct ipmi_req *ipmi_req)
{
time_t cur_time = time(NULL) + offset;
time_t set_time; // decode from the ipmi_req;
uint32_t tmp_time;
memcpy(&tmp_time, ipmi_req->payload, sizeof(tmp_time));
set_time = le32toh(tmp_time);
offset = set_time - cur_time;
ipmi_req->cc = 0;
/* bottom bit on the netfn is the response bit */
ipmi_req->netfn |= 1;
/* ipmi header is 4 bytes 1 byte completion code*/
ipmi_req->len = 4 + 1;
return 0;
}
int storage_time_get_sel_utc(struct ipmi_req *ipmi_req)
{
ipmi_req->cc = 0xc1;
/* bottom bit on the netfn is the response bit */
ipmi_req->netfn |= 1;
/* ipmi header is 4 bytes 1 byte completion code*/
ipmi_req->len = 4 + 1;
return 1;
}
int storage_time_set_sel_utc(struct ipmi_req *ipmi_req)
{
ipmi_req->cc = 0xc1;
/* bottom bit on the netfn is the response bit */
ipmi_req->netfn |= 1;
/* ipmi header is 4 bytes 1 byte completion code*/
ipmi_req->len = 4 + 1;
return 1;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment