diff options
author | Tian Fang <tfang@fb.com> | 2015-12-14 22:08:40 -0800 |
---|---|---|
committer | Tian Fang <tfang@fb.com> | 2015-12-15 09:49:21 -0800 |
commit | e65a7944211c70f6b5cfb6cedd73cc31105319de (patch) | |
tree | 067082251bc52bc6c09ca87feaa1352d0468a5ac /meta-facebook/meta-yosemite/recipes-yosemite/ipmid/files | |
parent | 8a67fbdd0e251bb34d55992b0771edba1837d589 (diff) | |
download | ast2050-yocto-openbmc-e65a7944211c70f6b5cfb6cedd73cc31105319de.zip ast2050-yocto-openbmc-e65a7944211c70f6b5cfb6cedd73cc31105319de.tar.gz |
Sync to internal OpenBMC repo f926614
Diffstat (limited to 'meta-facebook/meta-yosemite/recipes-yosemite/ipmid/files')
4 files changed, 157 insertions, 21 deletions
diff --git a/meta-facebook/meta-yosemite/recipes-yosemite/ipmid/files/bic.c b/meta-facebook/meta-yosemite/recipes-yosemite/ipmid/files/bic.c index 5af03ce..938e076 100644 --- a/meta-facebook/meta-yosemite/recipes-yosemite/ipmid/files/bic.c +++ b/meta-facebook/meta-yosemite/recipes-yosemite/ipmid/files/bic.c @@ -42,7 +42,7 @@ lib_gpio_intr_handle(unsigned char *request, unsigned char req_len, // TODO: Need to update to reuse the socket instead of creating new if ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { - syslog(LOG_ALERT, "lib_gpio_intr_handle: socket() failed\n"); + syslog(LOG_WARNING, "lib_gpio_intr_handle: socket() failed\n"); return; } @@ -51,12 +51,12 @@ lib_gpio_intr_handle(unsigned char *request, unsigned char req_len, len = strlen(remote.sun_path) + sizeof(remote.sun_family); if (connect(sockfd, (struct sockaddr *)&remote, len) == -1) { - syslog(LOG_ALERT, "lib_gpio_intr_handle: connect() failed\n"); + syslog(LOG_WARNING, "lib_gpio_intr_handle: connect() failed\n"); return; } if (send(sockfd, request, req_len, 0) == -1) { - syslog(LOG_ALERT, "lib_gpio_intr_handle: send() failed\n"); + syslog(LOG_WARNING, "lib_gpio_intr_handle: send() failed\n"); return; } @@ -64,9 +64,9 @@ lib_gpio_intr_handle(unsigned char *request, unsigned char req_len, *res_len = t; } else { if (t < 0) { - syslog(LOG_ALERT, "lib_gpio_intr_handle: recv() failed\n"); + syslog(LOG_WARNING, "lib_gpio_intr_handle: recv() failed\n"); } else { - printf("Server closed connection"); + syslog(LOG_WARNING, "Server closed connection"); } return; diff --git a/meta-facebook/meta-yosemite/recipes-yosemite/ipmid/files/fruid.c b/meta-facebook/meta-yosemite/recipes-yosemite/ipmid/files/fruid.c index 04772d7..d3fb856 100644 --- a/meta-facebook/meta-yosemite/recipes-yosemite/ipmid/files/fruid.c +++ b/meta-facebook/meta-yosemite/recipes-yosemite/ipmid/files/fruid.c @@ -34,12 +34,15 @@ #include "fruid.h" #define EEPROM_SPB "/sys/class/i2c-adapter/i2c-8/8-0051/eeprom" +#define EEPROM_NIC "/sys/class/i2c-adapter/i2c-12/12-0051/eeprom" #define BIN_SPB "/tmp/fruid_spb.bin" +#define BIN_NIC "/tmp/fruid_nic.bin" #define NAME_SPB "Side Plane Board" +#define NAME_NIC "Mezz Card" -#define BUF_SIZE 1024 +#define FRUID_SIZE 256 /* * copy_eeprom_to_bin - copy the eeprom to binary file im /tmp directory @@ -54,7 +57,7 @@ int copy_eeprom_to_bin(const char * eeprom_file, const char * bin_file) { int eeprom; int bin; - uint64_t tmp[BUF_SIZE]; + uint64_t tmp[FRUID_SIZE]; ssize_t bytes_rd, bytes_wr; errno = 0; @@ -75,13 +78,18 @@ int copy_eeprom_to_bin(const char * eeprom_file, const char * bin_file) { return errno; } - while ((bytes_rd = read(eeprom, tmp, BUF_SIZE)) > 0) { - bytes_wr = write(bin, tmp, bytes_rd); - if (bytes_wr != bytes_rd) { - syslog(LOG_ERR, "copy_eeprom_to_bin: write to %s file failed: %s", - bin_file, strerror(errno)); - return errno; - } + bytes_rd = read(eeprom, tmp, FRUID_SIZE); + if (bytes_rd != FRUID_SIZE) { + syslog(LOG_ERR, "copy_eeprom_to_bin: write to %s file failed: %s", + eeprom_file, strerror(errno)); + return errno; + } + + bytes_wr = write(bin, tmp, bytes_rd); + if (bytes_wr != bytes_rd) { + syslog(LOG_ERR, "copy_eeprom_to_bin: write to %s file failed: %s", + bin_file, strerror(errno)); + return errno; } close(bin); @@ -97,6 +105,7 @@ int plat_fruid_init(void) { int ret; ret = copy_eeprom_to_bin(EEPROM_SPB, BIN_SPB); + ret = copy_eeprom_to_bin(EEPROM_NIC, BIN_NIC); return ret; } diff --git a/meta-facebook/meta-yosemite/recipes-yosemite/ipmid/files/lan.c b/meta-facebook/meta-yosemite/recipes-yosemite/ipmid/files/lan.c new file mode 100644 index 0000000..3b36046 --- /dev/null +++ b/meta-facebook/meta-yosemite/recipes-yosemite/ipmid/files/lan.c @@ -0,0 +1,127 @@ +/* + * lan.c + * + * Copyright 2015-present Facebook. All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#define _GNU_SOURCE /* To get defns of NI_MAXSERV and NI_MAXHOST */ +#include <arpa/inet.h> +#include <sys/socket.h> +#include <netdb.h> +#include <ifaddrs.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <net/if.h> +#include <linux/if_link.h> +#include <sys/ioctl.h> +#include <stdbool.h> +#include <openbmc/ipmi.h> + +#define ETH_INTF_NAME "eth0" + +#define IPV6_LINK_LOCAL_BYTE1 0xFE +#define IPV6_LINK_LOCAL_BYTE2 0x80 + +#define BYTE_MASK 0xFF +#define BYTE1_OFFSET 8 +#define BYTE2_OFFSET 16 +#define BYTE3_OFFSET 24 + +void plat_lan_init(lan_config_t *lan) +{ + struct ifaddrs *ifaddr, *ifa; + struct sockaddr_in *addr; + struct sockaddr_in6 *addr6; + int family, s, n, i; + unsigned long ip; + unsigned char *ip6; + int sd; + struct ifreq ifr; + uint8_t mac_addr[6]; + uint8_t eui_64_addr[8] = {0x0}; + bool slaac_flag = false; + char test[64]; + + if (getifaddrs(&ifaddr) == -1) { + return; + } + + for (ifa = ifaddr, n = 0; ifa != NULL; ifa = ifa->ifa_next, n++) { + if (ifa->ifa_addr == NULL) { + continue; + } + + if (strcmp(ifa->ifa_name, ETH_INTF_NAME)) { + continue; + } + + family = ifa->ifa_addr->sa_family; + + if (family == AF_INET) { + addr = (struct sockaddr_in*) ifa->ifa_addr; + ip = addr->sin_addr.s_addr; + + // copy the ip address from long to byte array with MSB first + lan->ip_addr[3] = (ip >> BYTE3_OFFSET) & BYTE_MASK; + lan->ip_addr[2] = (ip >> BYTE2_OFFSET) & BYTE_MASK; + lan->ip_addr[1] = (ip >> BYTE1_OFFSET) & BYTE_MASK; + lan->ip_addr[0] = ip & BYTE_MASK; + } else if (family == AF_INET6) { + addr6 = (struct sockaddr_in6*) ifa->ifa_addr; + ip6 = addr6->sin6_addr.s6_addr; + + // If the address is Link Local, Ignore it + if ((ip6[0] == IPV6_LINK_LOCAL_BYTE1) && (ip6[1] == IPV6_LINK_LOCAL_BYTE2)) { + continue; + } + + // Get the MAC address + sd = socket(PF_INET, SOCK_DGRAM, 0); + strcpy(ifr.ifr_name, ifa->ifa_name); + if(ioctl(sd, SIOCGIFHWADDR, &ifr) != -1) { + uint8_t* mac_addr = (uint8_t*)ifr.ifr_hwaddr.sa_data; + + /* + * SLAAC address has lower 8B as follows: + * 3B == First 24b MAC address + * 2B == FFFE + * 3B == Last 24b MAC address + */ + memcpy((void *)&eui_64_addr[0], (void *)&mac_addr[0], 3); + eui_64_addr[3] = 0xFF; + eui_64_addr[4] = 0xFE; + memcpy((void *)&eui_64_addr[5], (void *)&mac_addr[3], 3); + eui_64_addr[0] += 2; + + // Check if the address is SLAAC address. If yes, skip it. + if (!memcmp((void *)&ip6[8], (void *)eui_64_addr, 8)) { + slaac_flag = true; + } + } + + if (slaac_flag) + continue; + + // copy the ip address from array with MSB first + memcpy(lan->ip6_addr, ip6, SIZE_IP6_ADDR); + } + } + + freeifaddrs(ifaddr); +} diff --git a/meta-facebook/meta-yosemite/recipes-yosemite/ipmid/files/sensor.c b/meta-facebook/meta-yosemite/recipes-yosemite/ipmid/files/sensor.c index 16cf98e..57ab5ec 100644 --- a/meta-facebook/meta-yosemite/recipes-yosemite/ipmid/files/sensor.c +++ b/meta-facebook/meta-yosemite/recipes-yosemite/ipmid/files/sensor.c @@ -81,7 +81,7 @@ populate_mgmt_sensors(void) { // Add this sensor to the global table if (g_sensor_mgmt.num >= SENSOR_MGMT_MAX) { - syslog(LOG_ALERT, "populate_mgmt_sensors: num exceeded\n"); + syslog(LOG_WARNING, "populate_mgmt_sensors: num exceeded\n"); return; } @@ -126,7 +126,7 @@ populate_disc_sensors(void) { // Add this sensor to the global table if (g_sensor_disc.num >= SENSOR_DISC_MAX) { - syslog(LOG_ALERT, "populate_disc_sensors: num exceeded\n"); + syslog(LOG_WARNING, "populate_disc_sensors: num exceeded\n"); return; } @@ -166,7 +166,7 @@ populate_disc_sensors(void) { // Add this sensor to the global table if (g_sensor_disc.num >= SENSOR_DISC_MAX) { - syslog(LOG_ALERT, "populate_disc_sensors: num exceeded\n"); + syslog(LOG_WARNING, "populate_disc_sensors: num exceeded\n"); return; } @@ -207,7 +207,7 @@ populate_disc_sensors(void) { // Add this sensor to the global table if (g_sensor_disc.num >= SENSOR_DISC_MAX) { - syslog(LOG_ALERT, "populate_disc_sensors: num exceeded\n"); + syslog(LOG_WARNING, "populate_disc_sensors: num exceeded\n"); return; } @@ -245,7 +245,7 @@ populate_disc_sensors(void) { // Add this sensor to the global table if (g_sensor_disc.num >= SENSOR_DISC_MAX) { - syslog(LOG_ALERT, "populate_disc_sensors: num exceeded\n"); + syslog(LOG_WARNING, "populate_disc_sensors: num exceeded\n"); return; } @@ -282,7 +282,7 @@ populate_disc_sensors(void) { // Add this sensor to the global table if (g_sensor_disc.num >= SENSOR_DISC_MAX) { - syslog(LOG_ALERT, "populate_disc_sensors: num exceeded\n"); + syslog(LOG_WARNING, "populate_disc_sensors: num exceeded\n"); return; } @@ -323,7 +323,7 @@ populate_disc_sensors(void) { // Add this sensor to the global table if (g_sensor_disc.num >= SENSOR_DISC_MAX) { - syslog(LOG_ALERT, "populate_disc_sensors: num exceeded\n"); + syslog(LOG_WARNING, "populate_disc_sensors: num exceeded\n"); return; } |