zhangbo 5 years ago
parent
commit
81c6772cf4
6 changed files with 183 additions and 0 deletions
  1. 22 0
      app/bmc/Api.c
  2. 1 0
      app/bmc/Api.h
  3. 117 0
      app/bmc/Util.c
  4. 10 0
      app/bmc/Util.h
  5. BIN
      app/bmc/bmc_app
  6. 33 0
      app/bmc/msghndlr/Storlead/Storlead.c

+ 22 - 0
app/bmc/Api.c

@@ -560,6 +560,28 @@ char* getnetmask(char *netmask_buf)
     return netmask_buf;
 }
 
+char* getbroadcast(char *broadcast_buf)
+{
+    struct ifreq temp;
+    struct sockaddr_in *myaddr;
+    int fd = 0;
+    int ret = -1;
+    strcpy(temp.ifr_name, "eth0");
+    if((fd=socket(AF_INET, SOCK_STREAM, 0))<0)
+    {
+        return NULL;
+    }
+    ret = ioctl(fd, SIOCGIFBRDADDR, &temp);
+    close(fd);
+    if(ret < 0)
+        return NULL;
+    myaddr = (struct sockaddr_in *)&(temp.ifr_addr);
+    strcpy(broadcast_buf, (char*)inet_ntoa(myaddr->sin_addr));
+
+    return broadcast_buf;
+}
+
+
 char* getmac(char *mac_buf)
 {
     struct ifreq temp;

+ 1 - 0
app/bmc/Api.h

@@ -29,6 +29,7 @@ int PostEventMessage (uint8_t *EventMsg,uint8_t size);
 char* getip(char *ip_buf);
 int setip(char *ip);
 char* getnetmask(char *netmask_buf);
+char* getbroadcast(char *broadcast_buf);
 char* getmac(char *mac_buf);
 
 int FlushUserInfoTbl(void);

+ 117 - 0
app/bmc/Util.c

@@ -100,6 +100,123 @@ uint32_t TimeUpdate()
 //     return 0;
 // }
 
+
+/*
+    index = 0,1,2,3,4,5
+*/
+uint8_t mac2hex(const char *strMac, uint8_t index)
+{
+    int i = 0;
+    char    *pStr = (char *)strMac;
+    char    *pTmp = NULL;
+    uint8_t macByte = 0;;
+    char    tmp[3] = {0};
+
+    if(index > 5)
+    {
+        printf("Invalid index %d\n", index);
+        return -1;
+    }
+
+    //find
+    while(pStr)
+    {
+        if(i == index)
+            break;
+
+        if(*pStr == ':')
+            i++;
+        
+        pStr++;
+    }
+
+    if(*(pStr+1) == ':')
+    {
+        tmp[0] = *pStr;
+        tmp[1] = '\0';
+        tmp[2] = '\0';
+    }
+    else
+    {
+        tmp[0] = *pStr;
+        tmp[1] = *(pStr+1);
+        tmp[2] = '\0';
+    }
+
+    i=0;
+    macByte = 0;
+    while(tmp[i])
+    {
+        macByte = macByte<<4;
+        if((tmp[i]>='0') && (tmp[i]<='9'))
+            macByte += (tmp[i]-'0');
+        else if((tmp[i]>='a') && (tmp[i]<='f'))
+            macByte += (tmp[i]-'a') + 10;
+        else if((tmp[i]>='A') && (tmp[i]<='F'))
+            macByte += (tmp[i]-'A') + 10;
+
+        i++;
+    }
+
+    return macByte;     
+}
+
+/*
+    index = 0,1,2,3
+*/
+uint8_t ip2dec(const char *strIp, uint8_t index)
+{
+    int i = 0;
+    char    *pStr = (char *)strIp;
+    uint8_t ipByte = 0;;
+    char    tmp[4] = {0};
+
+    if(index > 3)
+    {
+        printf("Invalid index %d\n", index);
+        return -1;
+    }
+
+    //find
+    while(pStr)
+    {
+        if(i == index)
+            break;
+
+        if(*pStr == '.')
+            i++;
+        
+        pStr++;
+    }
+
+    if(*(pStr+1) == '.')
+    {
+        tmp[0] = *pStr;
+        tmp[1] = '\0';
+        tmp[2] = '\0';
+        tmp[3] = '\0';
+    }
+    else if(*(pStr+2) == '.')
+    {
+        tmp[0] = *pStr;
+        tmp[1] = *(pStr+1);
+        tmp[2] = '\0';
+        tmp[3] = '\0';
+    }
+    else
+    {
+        tmp[0] = *pStr;
+        tmp[1] = *(pStr+1);
+        tmp[2] = *(pStr+2);
+        tmp[3] = '\0';
+    }
+
+    ipByte = atoi(tmp);
+
+    return ipByte;     
+}
+
+
 int FlushUserInfo(void)
 {
     //TODO:

+ 10 - 0
app/bmc/Util.h

@@ -57,6 +57,16 @@
 
 // int GetJiffySysCtlvalue (const char *TagName, long long *SysVal);
 
+
+/*
+    index = 0,1,2,3,4,5
+*/
+uint8_t mac2hex(const char *strMac, uint8_t index);
+/*
+    index = 0,1,2,3
+*/
+uint8_t ip2dec(const char *strIp, uint8_t index);
+
 int FlushUserInfo(void);
 int FlushFRU(void);
 int FlushSDR(void);

BIN
app/bmc/bmc_app


+ 33 - 0
app/bmc/msghndlr/Storlead/Storlead.c

@@ -505,6 +505,39 @@ int Storlead_GetLanInfo(uint8_t *pReq, uint8_t ReqLen, uint8_t *pRes)
         return 1;
     }
 
+    //Update LanInfo
+    char ip_buf[16];
+    getip(ip_buf);
+    g_BMCInfo.IpmiConfig.LanInfo[index].IPAddr[0] = ip2dec(ip_buf, 0);
+    g_BMCInfo.IpmiConfig.LanInfo[index].IPAddr[1] = ip2dec(ip_buf, 1);
+    g_BMCInfo.IpmiConfig.LanInfo[index].IPAddr[2] = ip2dec(ip_buf, 2);
+    g_BMCInfo.IpmiConfig.LanInfo[index].IPAddr[3] = ip2dec(ip_buf, 3);
+
+    char mask_buf[16];
+    getnetmask(mask_buf);
+    g_BMCInfo.IpmiConfig.LanInfo[index].NetMask[0] = ip2dec(mask_buf, 0);
+    g_BMCInfo.IpmiConfig.LanInfo[index].NetMask[1] = ip2dec(mask_buf, 1);
+    g_BMCInfo.IpmiConfig.LanInfo[index].NetMask[2] = ip2dec(mask_buf, 2);
+    g_BMCInfo.IpmiConfig.LanInfo[index].NetMask[3] = ip2dec(mask_buf, 3);
+
+    char broadcast_buf[16];
+    getbroadcast(broadcast_buf);
+    g_BMCInfo.IpmiConfig.LanInfo[index].BroadCast[0] = ip2dec(broadcast_buf, 0);
+    g_BMCInfo.IpmiConfig.LanInfo[index].BroadCast[1] = ip2dec(broadcast_buf, 1);
+    g_BMCInfo.IpmiConfig.LanInfo[index].BroadCast[2] = ip2dec(broadcast_buf, 2);
+    g_BMCInfo.IpmiConfig.LanInfo[index].BroadCast[3] = ip2dec(broadcast_buf, 3);
+
+    char mac_buf[18];
+    getmac(mac_buf);
+    g_BMCInfo.IpmiConfig.LanInfo[index].MACAddr[0] = mac2hex(mac_buf, 0);
+    g_BMCInfo.IpmiConfig.LanInfo[index].MACAddr[1] = mac2hex(mac_buf, 1);
+    g_BMCInfo.IpmiConfig.LanInfo[index].MACAddr[2] = mac2hex(mac_buf, 2);
+    g_BMCInfo.IpmiConfig.LanInfo[index].MACAddr[3] = mac2hex(mac_buf, 3);
+    g_BMCInfo.IpmiConfig.LanInfo[index].MACAddr[4] = mac2hex(mac_buf, 4);
+    g_BMCInfo.IpmiConfig.LanInfo[index].MACAddr[5] = mac2hex(mac_buf, 5);
+
+    //TODO: get default GetWay
+
     memcpy(pRes+1, &g_BMCInfo.IpmiConfig.LanInfo[index], sizeof(LanInfo_T));
 
     return 1+sizeof(LanInfo_T);