Commit 84645cc3 authored by Jonathan Currier's avatar Jonathan Currier
Browse files

initial hiomap-socket extraction

parent d7ad8158
ACLOCAL_AMFLAGS = -I m4
ibmrdir = $(libdir)/ipmi-bt-miniroute
ibmr_LTLIBRARIES = libhiomap-socket.la
libhiomap_socket_la_SOURCES = src/lib/hiomap-socket.c
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
AC_INIT([ipmi-hiomap-socket], [VERSION], [BUG-REPORT-ADDRESS])
AC_CONFIG_SRCDIR([src/lib/hiomap-socket.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 sys/socket.h unistd.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
AC_TYPE_UINT8_T
# Checks for library functions.
AC_CHECK_FUNCS([socket])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <hiomapd-socket.h>
#include <endian.h>
#include "ipmi-bt-miniroute/ipmi-packet.h"
static int hiomapd_socket = -1;
int connect_to_hiomapd(const char *s)
{
int sfd = socket(AF_UNIX, SOCK_SEQPACKET, 0);
struct sockaddr_un sa = {
.sun_family = AF_UNIX,
};
strncpy(sa.sun_path, s, sizeof(sa.sun_path));
if (connect(sfd, (void*)&sa, sizeof(sa)))
dprintf(2, "Error: connected failed with %m\n");
else
dprintf(1, "Socket connection successfull\n");
return sfd;
}
/* hit: hiomapd impi transport */
enum {
hit_reset = 1,
hit_get_info = 2,
hit_get_flash_info = 3,
hit_create_read_window = 4,
hit_close = 5,
hit_create_write_window = 6,
hit_mark_dirty = 7,
hit_flush = 8,
hit_ack = 9,
hit_erase = 10,
hit_get_flash_name = 11,
hit_lock = 12,
map_count
};
int hiomapd_ipmi_to_socket_lut[] = {
[hit_reset] = hust_reset,
[hit_get_info] = hust_getinfo,
[hit_get_flash_info] = hust_getflashinfo,
[hit_create_read_window] = hust_createreadwindow,
[hit_close] = hust_closewindow,
[hit_create_write_window] = hust_createwritewindow,
[hit_mark_dirty] = hust_markdirty,
[hit_flush] = hust_flush,
[hit_ack] = hust_ack,
[hit_erase] = hust_erase,
[hit_get_flash_name] = hust_getflashname,
[hit_lock] = hust_lock,
};
struct parm_desc {
int size;
};
struct {
int *in_descs;
int *out_descs;
} cmd_v2_coding_tbl[] = {
[hit_reset] = { .in_descs = NULL, .out_descs = NULL },
[hit_get_info] = { .in_descs = (int[]){ 1, 0}, .out_descs = (int[]){ 1, 1, 2, 0} },
[hit_get_flash_info] = { .in_descs = NULL, .out_descs = (int[]){ 2, 2, 0 } },
[hit_create_read_window] = { .in_descs = (int[]){ 2, 2, 0}, .out_descs = (int[]){ 2,2,2,0} },
[hit_close] = { .in_descs = NULL, .out_descs = NULL },
[hit_create_write_window] = { .in_descs = (int[]){ 2, 2, 0}, .out_descs = (int[]){ 2, 2, 2, 0} },
[hit_mark_dirty] = { .in_descs = (int[]){ 2, 2, 0}, .out_descs = NULL },
[hit_flush] = { .in_descs = NULL, .out_descs = NULL },
[hit_ack] = { .in_descs = (int[]){ 1, 0}, .out_descs = NULL },
[hit_erase] = { .in_descs = (int[]){ 2, 2, 0 }, .out_descs = NULL },
/* These are not v2 cmds */
// [hit_get_flash_name] = { .in_descs = NULL, .out_descs = NULL },
// [hit_lock] = { .in_descs = NULL, .out_descs = NULL },
[map_count] = { 0 }
};
void convert_size_one_in(struct unix_hiomapd_request *req, const uint8_t *in, int idx)
{
req->args[idx] = in[0];
}
void convert_size_one_out(struct unix_hiomapd_request *req, uint8_t *out, int idx)
{
out[0] = req->args[idx];
}
void convert_size_two_in(struct unix_hiomapd_request *req, const uint8_t *in, int idx)
{
uint16_t tmp;
memcpy(&tmp, in, sizeof(tmp));
tmp = le16toh(tmp);
req->args[idx] = tmp;
}
void convert_size_two_out(struct unix_hiomapd_request *req, uint8_t *out, int idx)
{
uint16_t tmp;
tmp = le16toh(req->args[idx]);
memcpy(out, &tmp, sizeof(tmp));
}
void convert_size_four_in(struct unix_hiomapd_request *req, const uint8_t *in, int idx)
{
uint32_t tmp;
memcpy(&tmp, in, sizeof(tmp));
tmp = le32toh(tmp);
req->args[idx] = in[0];
}
void convert_size_four_out(struct unix_hiomapd_request *req, uint8_t *out, int idx)
{
uint32_t tmp;
tmp = le32toh(req->args[idx]);
memcpy(out, &tmp, sizeof(tmp));
}
struct {
void (*in)(struct unix_hiomapd_request *req, const uint8_t *in, int idx);
void (*out)(struct unix_hiomapd_request *req, uint8_t *in, int idx);
} size_conv_tbl [] = {
[1] = { .in = convert_size_one_in, .out = convert_size_one_out},
[2] = { .in = convert_size_two_in, .out = convert_size_two_out},
[4] = { .in = convert_size_four_in, .out = convert_size_four_out},
};
int ibm_pnor_hiomapd_fnc(struct ipmi_req *ipmi_req)
{
int cmd;
int seq;
if (hiomapd_socket == -1)
hiomapd_socket = connect_to_hiomapd("/var/run/hiomapd");
/* at minimum there's an hiomapd cmd, and seq byte */
if (ipmi_req->len < (4 + 2))
return -1;
cmd = ipmi_req->payload[0];
seq = ipmi_req->payload[1];
if ((cmd < map_count) && hiomapd_ipmi_to_socket_lut[cmd])
{
uint8_t *pos;
int *desc;
struct unix_hiomapd_request req = {
.request = hiomapd_ipmi_to_socket_lut[cmd],
};
int idx;
/* Decode into the hiomapd socket struct */
/* We already decoded the first two bytes of payload,
* so skip them*/
for (pos = ipmi_req->payload + 2, desc = cmd_v2_coding_tbl[cmd].in_descs, idx = 0;
desc && desc[0];
pos+= desc[0], desc++, idx++)
{
size_conv_tbl[desc[0]].in(&req, pos, idx);
}
write(hiomapd_socket, &req, sizeof(req));
read(hiomapd_socket, &req, sizeof(req));
/* encode from the hiomapd socket struct to an IPMI response */
for (pos = ipmi_req->payload + 2, desc = cmd_v2_coding_tbl[cmd].out_descs, idx = 2;
desc && desc[0];
pos+= desc[0], desc++, idx++)
{
size_conv_tbl[desc[0]].out(&req, pos, idx);
}
/* args zero is the completion code.. */
//ipmi_req->cc = req.args[0];
/* it seems that errors are only reported if the read/write calls error */
ipmi_req->cc = 0;
/* bottom bit on the netfn is the response bit */
ipmi_req->netfn |= 1;
ipmi_req->len = 4 + 1 + (pos - ipmi_req->payload);
}
}
void init_lib()
{
register_netfn_cmd(0x3a, 0x5a, ibm_pnor_hiomapd_fnc);
}
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