blob: f42d4a891f3e9d0ba52753852940c6d074bf5502 [file] [log] [blame]
Chris Austenf79a21f2015-10-13 14:41:40 -05001#include <cstdlib>
2#include <cstring>
3#include <fstream>
4#include <iostream>
5#include <vector>
6#include <host-ipmid/ipmid-api.h>
7#include "oemhandler.h"
8
9using namespace std;
10
11const char* g_filepath = "/tmp/";
12
13const char * getFilePath(void) { return g_filepath; }
14
15// Number of bytes without the IPMI completion code
16#define MAXRESPONSE 2
17
18
19
20// Returns the length of the file
21std::ifstream::pos_type filesize(const char* filename)
22{
23 std::ifstream in(filename, std::ifstream::ate | std::ifstream::binary);
24 return in.tellg();
25}
26
27
28// Compares a string to the data in a file.
29// Returns 0 if complete match
30int compareData(const char *filename, const char *string, size_t len)
31{
32
33 std::ifstream in(filename, std::ifstream::ate | std::ifstream::binary);
34 std::streamsize size = in.tellg();
35
36 std::vector<char> buffer(size);
37
38 in.read(buffer.data(), size);
39
40 if (!std::memcmp(string, buffer.data(), len))
41 return -1;
42
43
44 return 0;
45}
46
47
48void test_multiwrite(unsigned int segment, const char *pString) {
49
50 uint8_t request[1024];
51 uint8_t response[MAXRESPONSE];
52 size_t len, totalString;
53 ipmi_ret_t rc;
54 uint16_t i=0, j;
55
56 esel_request_t requestheader[] = {0,0,0,0,0,0};
57 esel_request_t *pReqHdr = requestheader;
58 uint8_t firstime[] = { 0x00, 0x00, 0xdf, 0x00, 0x00, 0x00, 0x00, 0x20,
59 0x00, 0x04, 0x0c, 0x1e, 0x07, 0xaa, 0x00, 0x00};
60
61 ipmi_request_t pRequest = request;
62 ipmi_response_t pResponse = response;
63 ipmi_data_len_t pLen = &len;
64
65 totalString = strlen(pString);
66
67 std::memcpy(pRequest, requestheader, sizeof(requestheader));
68 std::memcpy(&request[sizeof(requestheader)], firstime, sizeof(firstime));
69
70 *pLen = sizeof(requestheader) + sizeof(firstime);
71
72 rc = ipmi_ibm_oem_partial_esel(0x3E, 0xF0, pRequest, pResponse, pLen, NULL);
73 if (rc != IPMI_CC_OK) { printf("Error completion code returned %d\n", rc);}
74 if (len != 2) { printf("Error data buffer length failed len\n");}
75
76 pReqHdr->selrecordls = response[0];
77 pReqHdr->selrecordms = response[1];
78
79
80 for (i=0; i<totalString; i+=segment) {
81
82 pReqHdr->offsetls = (i&0x00FF);
83 pReqHdr->offsetms = ((i&0xFF00) >> 8);
84
85 // printf("Record id msls 0x%02x%02x\n", pReqHdr->selrecordms, pReqHdr->selrecordls);
86 // printf("Offset 0x%04x , msls = 0x%02x%02x\n", i, pReqHdr->offsetms , pReqHdr->offsetls);
87
88 if (i+segment > totalString) {
89 j = totalString-i;
90 } else {
91 j = segment;
92 }
93
94 std::memcpy(pRequest, requestheader, sizeof(requestheader));
95 std::memcpy(&request[sizeof(requestheader)], pString+i, j);
96 len = sizeof(*requestheader) + j;
97
98 rc = ipmi_ibm_oem_partial_esel(0x3E, 0xF0, pRequest, pResponse, pLen, NULL);
99
100 if (rc != IPMI_CC_OK) { printf("Error completion code returned %d\n", rc);}
101 if (len != 2) { printf("Error data buffer length failed\n");}
102
103 pReqHdr->selrecordls = response[0];
104 pReqHdr->selrecordms = response[1];
105
106
107 }
108
109
110 if (filesize("/tmp/esel0100") != (unsigned int) strlen(pString)) { printf("Error fileszie mismatch\n");}
111
112 // /tmp/esel000 should be identical to the incoming string
113 rc = compareData("/tmp/esel0100",pString,strlen(pString));
114 if (rc != 0) {printf("Data miscompare %d\n",rc);}
115
116 return;
117}
118
119
120
121// Method that gets called by shared libraries to get their command handlers registered
122void ipmi_register_callback(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
123 ipmi_context_t context, ipmid_callback_t handler)
124{
125}
126
127
128int main()
129{
130
131 const char* shortstring = "C";
132 const char* longstring = "The President is very much a figurehead - he wields no real power whatsoever. He is apparently chosen by the government, but the qualities he is required to display are not those of leadership but those of finely judged outrage. For this reason the President is always a controversial choice, always an infuriating but fascinating character. His job is not to wield power but to draw attention away from it.";
133
134 test_multiwrite(1, shortstring);
135
136 test_multiwrite(10, longstring);
137 test_multiwrite(1, longstring);
138 test_multiwrite(100, longstring);
139
140 return 0;
141}