<div class="socmaildefaultfont" dir="ltr" style="font-family:Arial;font-size:10.5pt" ><div dir="ltr" >Hi Cyril,</div>
<div dir="ltr" > </div>
<div dir="ltr" >This patch was checked in before the Patrick response..I am checking in new one.</div>
<div dir="ltr" > </div>
<div dir="ltr" >Regards</div>
<div dir="ltr" >Ratan Gupta</div>
<div dir="ltr" > </div>
<div dir="ltr" > </div>
<blockquote data-history-content-modified="1" dir="ltr" style="border-left:solid #aaaaaa 2px; margin-left:5px; padding-left:5px; direction:ltr; margin-right:0px" >----- Original message -----<br>From: Cyril Bur <cyrilbur@gmail.com><br>To: OpenBMC Patches <openbmc-patches@stwcx.xyz><br>Cc: openbmc@lists.ozlabs.org, Ratan K Gupta/India/IBM@IBMIN<br>Subject: Re: [PATCH phosphor-host-ipmid v2] Implement Network Override<br>Date: Fri, Jun 10, 2016 3:55 AM<br>
<div><font face="Default Monospace,Courier New,Courier,monospace" size="2" >On Wed, 8 Jun 2016 12:50:40 -0500<br>OpenBMC Patches <openbmc-patches@stwcx.xyz> wrote:<br><br>> From: ratagupt <ratagupt@in.ibm.com><br>><br><br>Still no. Please read the style guide also please see Patricks response about<br>your interesting use of c++ or rather c/c++ mess.<br><br>> ---<br>> chassishandler.C | 223 ++++++++++++++++++++++++++++++++++++++++++++++++++++---<br>> 1 file changed, 211 insertions(+), 12 deletions(-)<br>><br>> diff --git a/chassishandler.C b/chassishandler.C<br>> index d5b3404..af213b0 100644<br>> --- a/chassishandler.C<br>> +++ b/chassishandler.C<br>> @@ -3,15 +3,19 @@<br>> #include <stdio.h><br>> #include <string.h><br>> #include <stdint.h><br>> -<br>> -<br>> +#include <arpa/inet.h><br>> +#include <netinet/in.h><br>> +#include <string><br>> +using namespace std;<br>> //Defines<br>> -#define SET_PARM_VERSION 1<br>> -#define SET_PARM_BOOT_FLAGS_PERMANENT 0x40 //boot flags data1 7th bit on<br>> +#define SET_PARM_VERSION 0x01<br>> +#define SET_PARM_BOOT_FLAGS_PERMANENT 0x40 //boot flags data1 7th bit on<br>> #define SET_PARM_BOOT_FLAGS_VALID_ONE_TIME 0x80 //boot flags data1 8th bit on<br>> #define SET_PARM_BOOT_FLAGS_VALID_PERMANENT 0xC0 //boot flags data1 7 & 8 bit on<br>> <br>> -<br>> +#define SIZE_MAC 18<br>> +#define SIZE_HOST_NETWORK_DATA 26<br>> +#define SIZE_BOOT_OPTION SIZE_HOST_NETWORK_DATA<br>> <br>> // OpenBMC Chassis Manager dbus framework<br>> const char *chassis_bus_name = "org.openbmc.control.Chassis";<br>> @@ -233,14 +237,189 @@ struct get_sys_boot_options_t {<br>> struct get_sys_boot_options_response_t {<br>> uint8_t version;<br>> uint8_t parm;<br>> - uint8_t data[5];<br>> + uint8_t data[SIZE_BOOT_OPTION];<br>> } __attribute__ ((packed));<br>> <br>> struct set_sys_boot_options_t {<br>> uint8_t parameter;<br>> - uint8_t data[8];<br>> + uint8_t data[SIZE_BOOT_OPTION];<br>> } __attribute__ ((packed));<br>> <br>> +struct host_network_config_t {<br>> + string ipaddress;<br>> + string prefix;<br>> + string gateway;<br>> + string macaddress;<br>> + string isDHCP;<br>> +<br>> + host_network_config_t()<br>> + {<br>> + ipaddress = "";<br>> + prefix = "";<br>> + gateway = "";<br>> + macaddress = "";<br>> + isDHCP = "";<br>> + }<br>> +};<br>> +<br>> +uint8_t getHostNetworkData(get_sys_boot_options_response_t *respptr)<br>> +{<br>> + char *prop = NULL;<br>> +<br>> + uint8_t data[SIZE_BOOT_OPTION]={0x80,0x21, 0x70 ,0x62 ,0x21,0x00 ,0x01 ,0x06 ,0x04};<br>> +<br>> + int rc = dbus_get_property("network_config",&prop);<br>> +<br>> + if (rc < 0) {<br>> + fprintf(stderr, "Dbus get property(boot_flags) failed for get_sys_boot_options.\n");<br>> + return rc;<br>> + }<br>> +<br>> + /* network_config property Value would be in the form of<br>> + * ipaddress=1.1.1.1,prefix=16,gateway=2.2.2.2,mac=11:22:33:44:55:66,dhcp=0<br>> + */<br>> +<br>> + /* Parsing the string and fill the hostconfig structure with the<br>> + * values */<br>> +<br>> + host_network_config_t host_config;<br>> + string delimiter = ",";<br>> +<br>> + int pos = 0;<br>> + string token,name,value;<br>> + string conf_str(prop);<br>> + <br>> + printf ("Configuration String[%s]\n ",conf_str.c_str());<br>> +<br>> + while ((pos = conf_str.find(delimiter)) != std::string::npos) {<br>> +<br>> + token = conf_str.substr(0, pos);<br>> + int pos1 = token.find("=");<br>> +<br>> + name = token.substr(0,pos1);<br>> + value = token.substr(pos1+1,pos);<br>> +<br>> + if ( name == "ipaddress" )<br>> + host_config.ipaddress = value;<br>> + else if ( name == "prefix")<br>> + host_config.prefix = value;<br>> + else if ( name == "gateway" )<br>> + host_config.gateway = value;<br>> + else if ( name == "mac" )<br>> + host_config.macaddress = value;<br>> + else if ( name == "dhcp" )<br>> + host_config.isDHCP = value;<br>> +<br>> + conf_str.erase(0, pos + delimiter.length());<br>> + }<br>> +<br>> + //Converting the mac address as number//<br>> + //If there as an error in converting the mac as number we are not throwing<br>> + //error we would be sending 0's for the mac.<br>> + <br>> + char *tokptr = NULL;<br>> + char* digit = strtok_r((char *)host_config.macaddress.c_str(), ":", &tokptr);<br>> + if (digit == NULL)<br>> + {<br>> + fprintf(stderr, "Unexpected MAC format: %s", host_config.macaddress.c_str());<br>> + }<br>> + <br>> + //As 9 bytes are pre filled so staring from index 9.If there is a failure<br>> + //in the strtok_r then digit will be null then we don't need to do<br>> + //anything as data is prefilled with 0<br>> + <br>> + uint8_t index=9;<br>> + int resp_byte = 0;<br>> + while (digit != NULL)<br>> + {<br>> + resp_byte = strtoul(digit, NULL, 16);<br>> + memcpy((void*)&data[index], &resp_byte, 1);<br>> + index++;<br>> + digit = strtok_r(NULL, ":", &tokptr);<br>> + }<br>> +<br>> + //Conevrt the dhcp,ipaddress,mask and gateway as hex number<br>> + data[index++]=0x00;<br>> + sscanf(host_config.isDHCP.c_str(),"%02X",&data[index++]);<br>> +<br>> + inet_pton(AF_INET,host_config.ipaddress.c_str(),(void *)&data[index]);<br>> + index+=4;<br>> + sscanf(host_config.prefix.c_str(),"%02X",&data[index++]);<br>> + inet_pton(AF_INET,host_config.gateway.c_str(),(void *)&data[index]);<br>> + index+=4;<br>> + <br>> + <br>> + printf ("\n===Printing the IPMI Formatted Data========\n");<br>> +<br>> + for (int j = 0;j<index;j++)<br>> + printf("%02x ", data[j]);<br>> +<br>> + memcpy(respptr->data,data,SIZE_BOOT_OPTION);<br>> + return 0;<br>> +<br>> +}<br>> +<br>> +uint8_t setHostNetworkData(set_sys_boot_options_t * reqptr)<br>> +{<br>> + string host_network_config;<br>> + char mac[SIZE_MAC];<br>> + char ipAddress[INET_ADDRSTRLEN];<br>> + char gateway[INET_ADDRSTRLEN];<br>> + char prefix[1];<br>> + char dhcp[2];<br>> + uint32_t cookie = 0;<br>> +<br>> +<br>> + memset( mac ,0,SIZE_MAC );<br>> + memset(ipAddress,0,INET_ADDRSTRLEN);<br>> + memset(gateway,0,INET_ADDRSTRLEN);<br>> + memset(prefix,0,1);<br>> + memset(dhcp,0,2);<br>> +<br>> + uint8_t index = 9; <br>> + sscanf((char *)&(reqptr->data[1]),"%02X",&cookie);<br>> +<br>> + if ( !cookie) {<br>> + <br>> + snprintf(mac, SIZE_MAC, "%02x:%02x:%02x:%02x:%02x:%02x",<br>> + reqptr->data[index],<br>> + reqptr->data[index+1],<br>> + reqptr->data[index+2],<br>> + reqptr->data[index+3],<br>> + reqptr->data[index+4],<br>> + reqptr->data[index+5]);<br>> +<br>> +<br>> + snprintf(dhcp,2, "%d", reqptr->data[index+6]);<br>> +<br>> + snprintf(ipAddress, INET_ADDRSTRLEN, "%d.%d.%d.%d",<br>> + reqptr->data[index+8], reqptr->data[index+9], reqptr->data[index+10], reqptr->data[index+11]);<br>> +<br>> + snprintf(prefix, INET_ADDRSTRLEN, "%d", reqptr->data[index+12]);<br>> +<br>> +<br>> + snprintf(gateway, INET_ADDRSTRLEN, "%d.%d.%d.%d",<br>> + reqptr->data[index+13], reqptr->data[index+14], reqptr->data[index+15], reqptr->data[index+16]);<br>> + }<br>> +<br>> + host_network_config += "ipaddress="+string(ipAddress)+",prefix="+ \<br>> + string(prefix)+",gateway="+string(gateway)+\<br>> + ",mac="+string(mac)+",dhcp="+string(dhcp);<br>> +<br>> +<br>> + printf ("Network configuration changed: %s\n",host_network_config.c_str());<br>> +<br>> + int r = dbus_set_property("network_config",host_network_config.c_str());<br>> +<br>> + if (r < 0) {<br>> + fprintf(stderr, "Dbus set property(network_config) failed for set_sys_boot_options.\n");<br>> + r = IPMI_CC_UNSPECIFIED_ERROR;<br>> + }<br>> +<br>> + return r;<br>> +<br>> +}<br>> +<br>> ipmi_ret_t ipmi_chassis_wildcard(ipmi_netfn_t netfn, ipmi_cmd_t cmd,<br>> ipmi_request_t request, ipmi_response_t response,<br>> ipmi_data_len_t data_len, ipmi_context_t context)<br>> @@ -446,7 +625,18 @@ ipmi_ret_t ipmi_chassis_get_sys_boot_options(ipmi_netfn_t netfn, ipmi_cmd_t cmd,<br>> }<br>> <br>> <br>> - } else {<br>> + } else if ( reqptr->parameter == 0x61 ) {<br>> + resp->parm = 0x61;<br>> + int ret = getHostNetworkData(resp);<br>> + if (ret < 0) {<br>> + fprintf(stderr, "getHostNetworkData failed for get_sys_boot_options.\n");<br>> + rc = IPMI_CC_UNSPECIFIED_ERROR;<br>> +<br>> + }else<br>> + rc = IPMI_CC_OK;<br>> + }<br>> +<br>> + else {<br>> fprintf(stderr, "Unsupported parameter 0x%x\n", reqptr->parameter);<br>> }<br>> <br>> @@ -464,11 +654,10 @@ ipmi_ret_t ipmi_chassis_set_sys_boot_options(ipmi_netfn_t netfn, ipmi_cmd_t cmd,<br>> {<br>> ipmi_ret_t rc = IPMI_CC_OK;<br>> char *s;<br>> -<br>> - printf("IPMI SET_SYS_BOOT_OPTIONS\n");<br>> -<br>> set_sys_boot_options_t *reqptr = (set_sys_boot_options_t *) request;<br>> <br>> + printf("IPMI SET_SYS_BOOT_OPTIONS reqptr->parameter =[%d]\n",reqptr->parameter);<br>> +<br>> // This IPMI command does not have any resposne data<br>> *data_len = 0;<br>> <br>> @@ -476,6 +665,7 @@ ipmi_ret_t ipmi_chassis_set_sys_boot_options(ipmi_netfn_t netfn, ipmi_cmd_t cmd,<br>> * Parameter #5 means boot flags. Please refer to 28.13 of ipmi doc.<br>> * This is the only parameter used by petitboot.<br>> */<br>> +<br>> if (reqptr->parameter == 5) {<br>> <br>> s = get_boot_option_by_ipmi(((reqptr->data[1] & 0x3C) >> 2));<br>> @@ -507,7 +697,16 @@ ipmi_ret_t ipmi_chassis_set_sys_boot_options(ipmi_netfn_t netfn, ipmi_cmd_t cmd,<br>> rc = IPMI_CC_UNSPECIFIED_ERROR;<br>> }<br>> <br>> - } else {<br>> + }<br>> + else if ( reqptr->parameter == 0x61 ) {<br>> + printf("IPMI SET_SYS_BOOT_OPTIONS reqptr->parameter =[%d]\n",reqptr->parameter);<br>> + int ret = setHostNetworkData(reqptr);<br>> + if (ret < 0) {<br>> + fprintf(stderr, "setHostNetworkData failed for set_sys_boot_options.\n");<br>> + rc = IPMI_CC_UNSPECIFIED_ERROR;<br>> + }<br>> + } <br>> + else {<br>> fprintf(stderr, "Unsupported parameter 0x%x\n", reqptr->parameter);<br>> rc = IPMI_CC_PARM_NOT_SUPPORTED;<br>> }</font><br> </div></blockquote>
<div dir="ltr" > </div></div><BR>