1 #include <stdio.h> 2 #include <string.h> 3 #include <stdint.h> 4 #include <time.h> 5 #include <sys/time.h> 6 #include <arpa/inet.h> 7 8 #include "storagehandler.h" 9 #include "storageaddsel.h" 10 #include "ipmid-api.h" 11 12 void register_netfn_storage_functions() __attribute__((constructor)); 13 14 15 unsigned int g_sel_time = 0xFFFFFFFF; 16 extern unsigned short g_sel_reserve; 17 18 ipmi_ret_t ipmi_storage_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd, 19 ipmi_request_t request, ipmi_response_t response, 20 ipmi_data_len_t data_len, ipmi_context_t context) 21 { 22 printf("Handling STORAGE WILDCARD Netfn:[0x%X], Cmd:[0x%X]\n",netfn, cmd); 23 // Status code. 24 ipmi_ret_t rc = IPMI_CC_OK; 25 *data_len = 0; 26 return rc; 27 } 28 29 ipmi_ret_t ipmi_storage_get_sel_time(ipmi_netfn_t netfn, ipmi_cmd_t cmd, 30 ipmi_request_t request, ipmi_response_t response, 31 ipmi_data_len_t data_len, ipmi_context_t context) 32 { 33 time_t currtime; 34 ipmi_ret_t rc = IPMI_CC_OK; 35 36 // Get current time in seconds since jan 1 1970 37 time(&currtime); 38 uint32_t resp = (uint32_t)currtime; 39 resp = htole32(resp); 40 41 printf("IPMI Handling GET-SEL-TIME\n"); 42 43 // From the IPMI Spec 2.0, response should be a 32-bit value 44 *data_len = sizeof(resp); 45 46 // Pack the actual response 47 memcpy(response, &resp, *data_len); 48 49 return rc; 50 } 51 52 ipmi_ret_t ipmi_storage_set_sel_time(ipmi_netfn_t netfn, ipmi_cmd_t cmd, 53 ipmi_request_t request, ipmi_response_t response, 54 ipmi_data_len_t data_len, ipmi_context_t context) 55 { 56 uint32_t* secs = (uint32_t*)request; 57 58 printf("Handling Set-SEL-Time:[0x%X], Cmd:[0x%X]\n",netfn, cmd); 59 printf("Data: 0x%X]\n",*secs); 60 61 struct timeval sel_time; 62 sel_time.tv_sec = le32toh(*secs); 63 sel_time.tv_usec = 0; 64 ipmi_ret_t rc = IPMI_CC_OK; 65 int rct = settimeofday(&sel_time, NULL); 66 67 if(rct == 0) 68 { 69 system("hwclock -w"); 70 } 71 else 72 { 73 printf("settimeofday() failed\n"); 74 rc = IPMI_CC_UNSPECIFIED_ERROR; 75 } 76 *data_len = 0; 77 return rc; 78 } 79 80 ipmi_ret_t ipmi_storage_get_sel_info(ipmi_netfn_t netfn, ipmi_cmd_t cmd, 81 ipmi_request_t request, ipmi_response_t response, 82 ipmi_data_len_t data_len, ipmi_context_t context) 83 { 84 85 ipmi_ret_t rc = IPMI_CC_OK; 86 unsigned char buf[] = {0x51,0,0,0xff, 0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0x06}; 87 88 printf("IPMI Handling GET-SEL-INFO\n"); 89 90 *data_len = sizeof(buf); 91 92 // TODO There is plently of work here. The SEL DB needs to hold a bunch 93 // of things in a header. Items like Time Stamp, number of entries, etc 94 // This is one place where the dbus object with the SEL information could 95 // mimic what IPMI needs. 96 97 // Pack the actual response 98 memcpy(response, &buf, *data_len); 99 100 return rc; 101 } 102 103 ipmi_ret_t ipmi_storage_reserve_sel(ipmi_netfn_t netfn, ipmi_cmd_t cmd, 104 ipmi_request_t request, ipmi_response_t response, 105 ipmi_data_len_t data_len, ipmi_context_t context) 106 { 107 unsigned short res_id; 108 109 ipmi_ret_t rc = IPMI_CC_OK; 110 111 // IPMI spec, Reservation ID, the value simply increases against each execution of reserve_sel command. 112 if( ++g_sel_reserve == 0) 113 g_sel_reserve = 1; 114 115 printf("IPMI Handling RESERVE-SEL 0x%04x\n", g_sel_reserve); 116 117 *data_len = sizeof(g_sel_reserve); 118 119 // Pack the actual response 120 memcpy(response, &g_sel_reserve, *data_len); 121 122 return rc; 123 } 124 125 ipmi_ret_t ipmi_storage_add_sel(ipmi_netfn_t netfn, ipmi_cmd_t cmd, 126 ipmi_request_t request, ipmi_response_t response, 127 ipmi_data_len_t data_len, ipmi_context_t context) 128 { 129 130 ipmi_ret_t rc = IPMI_CC_OK; 131 ipmi_add_sel_request_t *p = (ipmi_add_sel_request_t*) request; 132 uint16_t recordid; 133 134 recordid = ((uint16_t)p->eventdata[1] << 8) | p->eventdata[2]; 135 136 printf("IPMI Handling ADD-SEL for record 0x%04x\n", recordid); 137 138 *data_len = sizeof(g_sel_reserve); 139 140 // Pack the actual response 141 memcpy(response, &p->eventdata[1], 2); 142 143 send_esel(recordid); 144 145 return rc; 146 } 147 148 149 150 void register_netfn_storage_functions() 151 { 152 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_WILDCARD); 153 ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_WILDCARD, NULL, ipmi_storage_wildcard); 154 155 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_GET_SEL_TIME); 156 ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SEL_TIME, NULL, ipmi_storage_get_sel_time); 157 158 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_SET_SEL_TIME); 159 ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_SET_SEL_TIME, NULL, ipmi_storage_set_sel_time); 160 161 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_GET_SEL_INFO); 162 ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SEL_INFO, NULL, ipmi_storage_get_sel_info); 163 164 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_RESERVE_SEL); 165 ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_RESERVE_SEL, NULL, ipmi_storage_reserve_sel); 166 167 printf("Registering NetFn:[0x%X], Cmd:[0x%X]\n",NETFUN_STORAGE, IPMI_CMD_ADD_SEL); 168 ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_ADD_SEL, NULL, ipmi_storage_add_sel); 169 return; 170 } 171 172