diff options
author | Andrej Rode <andrej.rode@ettus.com> | 2017-03-27 18:03:52 -0700 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2017-12-22 15:03:45 -0800 |
commit | 6a12add1560545438e1bebc05efbafd05aace4f9 (patch) | |
tree | c94dbbbd4da0c7ef41fc8849f174875a13f0b511 /mpm/lib | |
parent | ba4fad345d7489b40a7dab83842ac21d13c4f460 (diff) | |
download | uhd-6a12add1560545438e1bebc05efbafd05aace4f9.tar.gz uhd-6a12add1560545438e1bebc05efbafd05aace4f9.tar.bz2 uhd-6a12add1560545438e1bebc05efbafd05aace4f9.zip |
mpm: mpm reorganization
Diffstat (limited to 'mpm/lib')
-rw-r--r-- | mpm/lib/CMakeLists.txt | 2 | ||||
-rw-r--r-- | mpm/lib/net_helper.cpp | 118 | ||||
-rw-r--r-- | mpm/lib/udev_helper.cpp | 93 |
3 files changed, 0 insertions, 213 deletions
diff --git a/mpm/lib/CMakeLists.txt b/mpm/lib/CMakeLists.txt index 649d944c9..cfdde2d03 100644 --- a/mpm/lib/CMakeLists.txt +++ b/mpm/lib/CMakeLists.txt @@ -25,7 +25,5 @@ ADD_SUBDIRECTORY(mykonos) ADD_SUBDIRECTORY(lmk04828) USRP_PERIPHS_ADD_OBJECT(periphs - net_helper.cpp - udev_helper.cpp xbar_iface.cpp ) diff --git a/mpm/lib/net_helper.cpp b/mpm/lib/net_helper.cpp deleted file mode 100644 index a40fd742d..000000000 --- a/mpm/lib/net_helper.cpp +++ /dev/null @@ -1,118 +0,0 @@ -// -// Copyright 2017 Ettus Research (National Instruments) -// -// 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 3 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, see <http://www.gnu.org/licenses/>. -// - -#include <mpm/net_helper.hpp> -#include <uhd/exception.hpp> -#include <boost/format.hpp> -#include <netdb.h> -#include <ifaddrs.h> -#include <linux/if_link.h> -#include <linux/if_packet.h> -#include <iomanip> -#include <iostream> -#include <string> -#include <sstream> -#include <cstring> -#include <cstdint> - -namespace mpm { -namespace network{ - -template <typename ArrayType> -std::string bytearray_to_string(const ArrayType array[], size_t elements) { - std::stringstream result; - for (size_t i = 0; i < elements; i++) { - result << std::uppercase << std::setfill('0') - << std::setw(sizeof(array[i]) * - 2) // always produce 2 hex values for each byte - << std::hex << +array[i]; // Implicit integer promotion - } - return result.str(); -} - -void print_net_ifaces(net_ifaces my_ifaces) { - /* take in a net_ifaces and pretty print information - about all detected network interfaces */ - for (const auto& iface : my_ifaces) { - std::cout << "interface: " << iface.first << std::endl; - std::cout << "\tMAC: " << iface.second.mac_addr << std::endl; - for (const auto& addr : iface.second.ip_addr) { - std::cout << "\tip address: " << addr << std::endl; - } - } -} - -net_ifaces get_net_map() { - /* Get a map containing a string and a net_iface struct - to describe all adresses assigned to a interface */ - struct ifaddrs *ifaddr, *ifa; - int family, s; - char host[NI_MAXHOST]; - net_ifaces net_map; - - if (getifaddrs(&ifaddr) == -1) { - throw uhd::system_error(str(boost::format("Error: %s") % strerror(errno))); - } - - /* Walk through linked list, maintaining head pointer so we - can free list later */ - - for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { - if (ifa->ifa_addr == NULL) - continue; - - /* Put the interaface name into the map, if it already exists - we get an iterator to the existing element */ - auto result = net_map.emplace( - std::make_pair(std::string(ifa->ifa_name), net_iface())); - auto current_iface = result.first; - - family = ifa->ifa_addr->sa_family; - if (family == AF_INET || family == AF_INET6) { - s = getnameinfo(ifa->ifa_addr, - (family == AF_INET) ? sizeof(struct sockaddr_in) - : sizeof(struct sockaddr_in6), - host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); - if (s != 0) { - printf("getnameinfo() failed: %s\n", gai_strerror(s)); - return net_map; - } - current_iface->second.ip_addr.push_back(std::string(host)); - } else if (family == AF_PACKET && ifa->ifa_data != NULL) { - struct sockaddr_ll* s = (struct sockaddr_ll*)ifa->ifa_addr; - uint8_t mac_addr[6]; - memcpy(&mac_addr, s->sll_addr, 6); - current_iface->second.mac_addr = bytearray_to_string(mac_addr, 6); - } - } - freeifaddrs(ifaddr); - return net_map; -} - -std::vector<std::string> get_if_addrs(const std::string& mac_addr) { - /* Convenience wrapper to return all adresses associated with one - mac address */ - net_ifaces my_map = get_net_map(); - for (const auto& iface : my_map) { // find - if (iface.second.mac_addr == mac_addr) { - return iface.second.ip_addr; - } - } - return std::vector<std::string>(); -} -} -} diff --git a/mpm/lib/udev_helper.cpp b/mpm/lib/udev_helper.cpp deleted file mode 100644 index 108b4b07a..000000000 --- a/mpm/lib/udev_helper.cpp +++ /dev/null @@ -1,93 +0,0 @@ -// -// Copyright 2017 Ettus Research (National Instruments) -// -// 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 3 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, see <http://www.gnu.org/licenses/>. -// - -#include "mpm/udev_helper.hpp" -#include <uhd/exception.hpp> -#include <boost/format.hpp> -#include <boost/make_shared.hpp> -#include <boost/crc.hpp> -#include <utility> -#include <iostream> -#include <string> -#include <cstring> -#include <fstream> - -using namespace mpm; - -udev_helper::udev_helper(){ - _udev = udev_new(); - if (!_udev) { - throw uhd::os_error("Failed to create udev!"); - } - _enumerate = udev_enumerate_new(_udev); - -} - -udev_helper::~udev_helper(){ - udev_enumerate_unref(_enumerate); - udev_unref(_udev); -} -std::string udev_helper::get_eeprom(const std::string &address){ - udev_list_entry *devices, *dev_list_entry; - udev_device *dev, *parent; - - parent = udev_device_new_from_subsystem_sysname(_udev, "platform", address.c_str()); - if (parent == NULL){ - return std::string(); - } - udev_enumerate_add_match_parent(_enumerate, parent); - udev_enumerate_add_match_subsystem(_enumerate, "nvmem"); - udev_enumerate_scan_devices(_enumerate); - - devices = udev_enumerate_get_list_entry(_enumerate); - if (devices == NULL){ - return std::string(); - } - udev_list_entry_foreach(dev_list_entry, devices) { - const char *path = NULL, *sys_path = NULL; - path = udev_list_entry_get_name(dev_list_entry); - dev = udev_device_new_from_syspath(_udev, path); - sys_path = udev_device_get_syspath(dev); - udev_device_unref(dev); - return "/sys" + std::string(sys_path) + "/nvmem"; - } - return std::string(); -} - -std::vector<std::string> udev_helper::get_spidev_nodes(const std::string &spi_master){ - udev_list_entry *devices, *dev_list_entry; - udev_device *dev, *parent; - - parent = udev_device_new_from_subsystem_sysname(_udev, "platform", spi_master.c_str()); - udev_enumerate_add_match_parent(_enumerate, parent); - udev_enumerate_add_match_subsystem(_enumerate, "spidev"); - udev_enumerate_scan_devices(_enumerate); - - devices = udev_enumerate_get_list_entry(_enumerate); - std::vector<std::string> found_dev_nodes; - if (devices != NULL){ - udev_list_entry_foreach(dev_list_entry, devices){ - const char *path, *dev_node; - path = udev_list_entry_get_name(dev_list_entry); - dev = udev_device_new_from_syspath(_udev, path); - dev_node = udev_device_get_devnode(dev); - found_dev_nodes.push_back(std::string(dev_node)); - udev_device_unref(dev); - } - } - return found_dev_nodes; -} |