summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEd Tanous <ed.tanous@intel.com>2017-06-12 13:25:51 -0700
committerEd Tanous <ed.tanous@intel.com>2017-06-12 13:25:51 -0700
commitc9b5521eb8505c55784f1bb2743e7d8addb6e42e (patch)
tree403c8e85a81ed9213888d4bdc580ff75a61fba63 /src
parent4758d5be3debd098e3ce9ba703c75269ecf6f9b1 (diff)
downloadbmcweb-c9b5521eb8505c55784f1bb2743e7d8addb6e42e.tar.gz
bmcweb-c9b5521eb8505c55784f1bb2743e7d8addb6e42e.zip
incremental
Diffstat (limited to 'src')
-rw-r--r--src/dbus_main.cpp455
-rw-r--r--src/udpclient.cpp98
-rw-r--r--src/webserver_main.cpp79
3 files changed, 38 insertions, 594 deletions
diff --git a/src/dbus_main.cpp b/src/dbus_main.cpp
deleted file mode 100644
index 6cee92e..0000000
--- a/src/dbus_main.cpp
+++ /dev/null
@@ -1,455 +0,0 @@
-#define DBUS_API_SUBJECT_TO_CHANGE
-#include <dbus/dbus.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <iostream>
-#include <string>
-#include <vector>
-#include <boost/iostreams/stream.hpp>
-#include <boost/property_tree/ptree.hpp>
-#include <boost/property_tree/xml_parser.hpp>
-
-/**
- * Connect to the DBUS bus and send a broadcast signal
- */
-void sendsignal(char* sigvalue) {
- DBusMessage* msg;
- DBusMessageIter args;
- DBusConnection* conn;
- DBusError err;
- int ret;
- dbus_uint32_t serial = 0;
-
- printf("Sending signal with value %s\n", sigvalue);
-
- // initialise the error value
- dbus_error_init(&err);
-
- // connect to the DBUS system bus, and check for errors
- conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
- if (dbus_error_is_set(&err)) {
- fprintf(stderr, "Connection Error (%s)\n", err.message);
- dbus_error_free(&err);
- }
- if (NULL == conn) {
- exit(1);
- }
-
- // register our name on the bus, and check for errors
- ret = dbus_bus_request_name(conn, "test.signal.source",
- DBUS_NAME_FLAG_REPLACE_EXISTING, &err);
- if (dbus_error_is_set(&err)) {
- fprintf(stderr, "Name Error (%s)\n", err.message);
- dbus_error_free(&err);
- }
- if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) {
- exit(1);
- }
-
- // create a signal & check for errors
- msg = dbus_message_new_signal(
- "/test/signal/Object", // object name of the signal
- "test.signal.Type", // interface name of the signal
- "Test"); // name of the signal
- if (NULL == msg) {
- fprintf(stderr, "Message Null\n");
- exit(1);
- }
-
- // append arguments onto signal
- dbus_message_iter_init_append(msg, &args);
- if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &sigvalue)) {
- fprintf(stderr, "Out Of Memory!\n");
- exit(1);
- }
-
- // send the message and flush the connection
- if (!dbus_connection_send(conn, msg, &serial)) {
- fprintf(stderr, "Out Of Memory!\n");
- exit(1);
- }
- dbus_connection_flush(conn);
-
- printf("Signal Sent\n");
-
- // free the message and close the connection
- dbus_message_unref(msg);
- dbus_connection_close(conn);
-}
-
-/**
- * Call a method on a remote object
- */
-void query(const char* param) {
- DBusMessage* msg;
- DBusMessageIter args;
- DBusConnection* conn;
- DBusError err;
- DBusPendingCall* pending;
- int ret;
- bool stat;
- dbus_uint32_t level;
-
- printf("Calling remote method with %s\n", param);
-
- // initialiset the errors
- dbus_error_init(&err);
-
- // connect to the system bus and check for errors
- conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
- if (dbus_error_is_set(&err)) {
- fprintf(stderr, "Connection Error (%s)\n", err.message);
- dbus_error_free(&err);
- }
- if (NULL == conn) {
- exit(1);
- }
- /*
- // request our name on the bus
- ret = dbus_bus_request_name(conn, "test.method.caller",
- DBUS_NAME_FLAG_REPLACE_EXISTING , &err);
- if (dbus_error_is_set(&err)) {
- fprintf(stderr, "Name Error (%s)\n", err.message);
- dbus_error_free(&err);
- }
- if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) {
- exit(1);
- }
- */
-
- // create a new method call and check for errors
- msg = dbus_message_new_method_call(
- "org.freedesktop.Avahi", // target for the method call
- "/", // object to call on
- "org.freedesktop.Avahi.Server", // interface to call on
- "GetHostName"); // method name
- if (NULL == msg) {
- fprintf(stderr, "Message Null\n");
- exit(1);
- }
-
- // append arguments
- /*
- dbus_message_iter_init_append(msg, &args);
- if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &param)) {
- fprintf(stderr, "Out Of Memory!\n");
- exit(1);
- }
- */
- // send message and get a handle for a reply
- if (!dbus_connection_send_with_reply(conn, msg, &pending,
- -1)) { // -1 is default timeout
- fprintf(stderr, "Out Of Memory!\n");
- exit(1);
- }
- if (NULL == pending) {
- fprintf(stderr, "Pending Call Null\n");
- exit(1);
- }
- dbus_connection_flush(conn);
-
- printf("Request Sent\n");
-
- // free message
- dbus_message_unref(msg);
-
- // block until we recieve a reply
- dbus_pending_call_block(pending);
-
- // get the reply message
- msg = dbus_pending_call_steal_reply(pending);
- if (NULL == msg) {
- fprintf(stderr, "Reply Null\n");
- exit(1);
- }
- // free the pending message handle
- dbus_pending_call_unref(pending);
-
- // read the parameters
- char* str = NULL;
- if (!dbus_message_iter_init(msg, &args))
- fprintf(stderr, "Message has no arguments!\n");
- else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args))
- fprintf(stderr, "Argument is not boolean!\n");
- else
- dbus_message_iter_get_basic(&args, &str);
-
- printf("Got Reply: %s\n", str);
-
- // free reply and close connection
- dbus_message_unref(msg);
- dbus_connection_close(conn);
-}
-
-void list_names() {
- DBusError err;
-
- int ret;
- bool stat;
- dbus_uint32_t level;
-
- // initialiset the errors
- dbus_error_init(&err);
-
- // connect to the system bus and check for errors
- DBusConnection* conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
- if (dbus_error_is_set(&err)) {
- fprintf(stderr, "Connection Error (%s)\n", err.message);
- dbus_error_free(&err);
- }
- if (NULL == conn) {
- exit(1);
- }
-
- // create a new method call and check for errors
- DBusMessage* msg = dbus_message_new_method_call(
- "org.freedesktop.DBus", // target for the method call
- "/", // object to call on
- "org.freedesktop.DBus", // interface to call on
- "ListNames"); // method name
- if (NULL == msg) {
- fprintf(stderr, "Message Null\n");
- exit(1);
- }
-
- DBusPendingCall* pending;
- // send message and get a handle for a reply
- if (!dbus_connection_send_with_reply(conn, msg, &pending,
- -1)) { // -1 is default timeout
- fprintf(stderr, "Out Of Memory!\n");
- exit(1);
- }
- if (NULL == pending) {
- fprintf(stderr, "Pending Call Null\n");
- exit(1);
- }
- dbus_connection_flush(conn);
-
- // free message
- dbus_message_unref(msg);
-
- // block until we recieve a reply
- dbus_pending_call_block(pending);
-
- // get the reply message
- msg = dbus_pending_call_steal_reply(pending);
- if (NULL == msg) {
- fprintf(stderr, "Reply Null\n");
- exit(1);
- }
- // free the pending message handle
- dbus_pending_call_unref(pending);
-
- // read the parameters
- DBusMessageIter args;
- DBusMessageIter strings;
- char* paths = NULL;
- if (!dbus_message_iter_init(msg, &args)) {
- fprintf(stderr, "Message has no arguments!\n");
- }
- std::vector<std::string> names;
- do {
- dbus_message_iter_recurse(&args, &strings);
- do {
- dbus_message_iter_get_basic(&strings, &paths);
- names.emplace_back(paths);
- } while (dbus_message_iter_next(&strings));
- } while (dbus_message_iter_next(&args));
-
- // free reply and close connection
- dbus_message_unref(msg);
- dbus_connection_close(conn);
-}
-
-std::vector<std::string> read_dbus_xml_names(std::string& xml_data) {
- std::vector<std::string> values;
- // populate tree structure pt
- using boost::property_tree::ptree;
- ptree pt;
- boost::iostreams::stream<boost::iostreams::array_source> stream(
- xml_data.c_str(), xml_data.size());
- read_xml(stream, pt);
-
- // traverse node to find other nodes
- for (const auto& interface : pt.get_child("node")) {
- if (interface.first == "node") {
- auto t = interface.second.get<std::string>("<xmlattr>", "default");
- for (const auto& subnode : interface.second.get_child("<xmlattr>")) {
- if (subnode.first == "name") {
- auto t = subnode.second.get("", "unknown");
- values.emplace_back(std::move(t));
- }
- }
- }
- }
- return values;
-}
-
-using sensor_values=std::vector<std::pair<std::string, int32_t>>;
-
-sensor_values read_sensor_values() {
- sensor_values values;
- DBusError err;
-
- int ret;
- bool stat;
- dbus_uint32_t level;
-
- // initialiset the errors
- dbus_error_init(&err);
-
- // connect to the system bus and check for errors
- DBusConnection* conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
- if (dbus_error_is_set(&err)) {
- fprintf(stderr, "Connection Error (%s)\n", err.message);
- dbus_error_free(&err);
- }
- if (NULL == conn) {
- exit(1);
- }
-
- // create a new method call and check for errors
- DBusMessage* msg = dbus_message_new_method_call(
- "org.openbmc.Sensors", // target for the method call
- "/org/openbmc/sensors/tach", // object to call on
- "org.freedesktop.DBus.Introspectable", // interface to call on
- "Introspect"); // method name
- if (NULL == msg) {
- fprintf(stderr, "Message Null\n");
- exit(1);
- }
-
- DBusPendingCall* pending;
- // send message and get a handle for a reply
- if (!dbus_connection_send_with_reply(conn, msg, &pending,
- -1)) { // -1 is default timeout
- fprintf(stderr, "Out Of Memory!\n");
- exit(1);
- }
- if (NULL == pending) {
- fprintf(stderr, "Pending Call Null\n");
- exit(1);
- }
- dbus_connection_flush(conn);
-
- // free message
- dbus_message_unref(msg);
-
- // block until we recieve a reply
- dbus_pending_call_block(pending);
-
- // get the reply message
- msg = dbus_pending_call_steal_reply(pending);
- if (NULL == msg) {
- fprintf(stderr, "Reply Null\n");
- exit(1);
- }
- // free the pending message handle
- dbus_pending_call_unref(pending);
-
- // read the parameters
- DBusMessageIter args;
- char* xml_struct = NULL;
- if (!dbus_message_iter_init(msg, &args)) {
- fprintf(stderr, "Message has no arguments!\n");
- }
-
- // read the arguments
- if (!dbus_message_iter_init(msg, &args)) {
- fprintf(stderr, "Message has no arguments!\n");
- } else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args)) {
- fprintf(stderr, "Argument is not string!\n");
- } else {
- dbus_message_iter_get_basic(&args, &xml_struct);
- }
- std::vector<std::string> methods;
- if (xml_struct != NULL) {
- std::string xml_data(xml_struct);
- methods = read_dbus_xml_names(xml_data);
- }
-
- fprintf(stdout, "Found %ld sensors \n", methods.size());
-
- for (auto& method : methods) {
- // TODO(Ed) make sure sensor exposes SensorValue interface
- // create a new method call and check for errors
- DBusMessage* msg = dbus_message_new_method_call(
- "org.openbmc.Sensors", // target for the method call
- ("/org/openbmc/sensors/tach/" + method).c_str(), // object to call on
- "org.openbmc.SensorValue", // interface to call on
- "getValue"); // method name
- if (NULL == msg) {
- fprintf(stderr, "Message Null\n");
- exit(1);
- }
-
- DBusPendingCall* pending;
- // send message and get a handle for a reply
- if (!dbus_connection_send_with_reply(conn, msg, &pending,
- -1)) { // -1 is default timeout
- fprintf(stderr, "Out Of Memory!\n");
- exit(1);
- }
- if (NULL == pending) {
- fprintf(stderr, "Pending Call Null\n");
- exit(1);
- }
- dbus_connection_flush(conn);
-
- // free message
- dbus_message_unref(msg);
-
- // block until we recieve a reply
- dbus_pending_call_block(pending);
-
- // get the reply message
- msg = dbus_pending_call_steal_reply(pending);
- if (NULL == msg) {
- fprintf(stderr, "Reply Null\n");
- exit(1);
- }
- // free the pending message handle
- dbus_pending_call_unref(pending);
-
- // read the parameters
- DBusMessageIter args;
- int32_t value;
- if (!dbus_message_iter_init(msg, &args)) {
- fprintf(stderr, "Message has no arguments!\n");
- }
-
- // read the arguments
- if (!dbus_message_iter_init(msg, &args)) {
- fprintf(stderr, "Message has no arguments!\n");
- } else if (DBUS_TYPE_VARIANT != dbus_message_iter_get_arg_type(&args)) {
- fprintf(stderr, "Argument is not string!\n");
- } else {
- DBusMessageIter sub;
- dbus_message_iter_recurse(&args, &sub);
- auto type = dbus_message_iter_get_arg_type(&sub);
- if (DBUS_TYPE_INT32 != type) {
- fprintf(stderr, "Variant subType is not int32 it is %d\n", type);
- } else {
- dbus_message_iter_get_basic(&sub, &value);
- values.emplace_back(method.c_str(), value);
- }
- }
- }
-
- // free reply and close connection
- dbus_message_unref(msg);
- return values;
-}
-
-
-int main(int argc, char** argv) {
- auto values = read_sensor_values();
-
- for (auto value: values){
- std::cout << value.first << ": " << value.second << "\n";
- }
-
- return 0;
-} \ No newline at end of file
diff --git a/src/udpclient.cpp b/src/udpclient.cpp
deleted file mode 100644
index 9bebd6e..0000000
--- a/src/udpclient.cpp
+++ /dev/null
@@ -1,98 +0,0 @@
-//
-// client.cpp
-// ~~~~~~~~~~
-//
-// Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
-//
-// Distributed under the Boost Software License, Version 1.0. (See accompanying
-// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-//
-#include <array>
-#include <iostream>
-#include <boost/asio.hpp>
-
-using boost::asio::ip::udp;
-
-int main(int argc, char* argv[]) {
- try {
- boost::asio::io_service io_service;
-
- udp::resolver resolver(io_service);
- udp::resolver::query query(udp::v4(), "10.243.48.31", "623");
- udp::endpoint receiver_endpoint = *resolver.resolve(query);
-
- udp::socket socket(io_service);
- socket.open(udp::v4());
-
- std::string username = "root";
- std::string password = "two";
- uint8_t privilege_level = 4;
- uint8_t seq_number = 1;
- uint8_t command = 0x38; // AUTH_CAP_CMD
- // std::array<uint8_t> ChannelAuthCap{0x80 | (0x0f & channel),
- // privilege_level&0x0f};
-
- uint8_t srcaddr = 0x81; // 0xC8?
- uint8_t dstaddr = 0x20;
-
- uint8_t net_function = 0x06;
- uint8_t lun = 0;
-
- uint8_t netfn_lun = static_cast<uint8_t>((net_function << 2) + lun);
- uint8_t channel_number =
- 0x0E + 0x80; // E is defined in spec as this channel
- // 0x80 is requesting IPMI 2.0
- uint8_t byte1 = static_cast<uint8_t>(channel_number | 0x80);
- std::array<uint8_t, 2> payload{byte1, privilege_level};
-
- int payload_sum = 0;
- for (auto element : payload) {
- payload_sum += element;
- }
-
- uint8_t chk1 = (1 + ((~(dstaddr + netfn_lun)) & 0xff)) & 0xff;
- uint8_t chk2 = srcaddr + (seq_number << 2) + command + payload_sum;
- chk2 = (1 + ((~chk2) & 0xff)) & 0xff;
-
- uint8_t ptype = 0;
- uint8_t session_id = 0;
-
- uint8_t seq_number2 = 0;
- uint8_t seq_number_lun = (seq_number << 2) + lun;
-
- uint8_t seq2 = 0xff; //????
- uint8_t rmcp_class = 0x07;
-
- std::vector<uint8_t> send_buf = {
- 0x06, 0x00, seq2,
- rmcp_class, 0x06, ptype,
- session_id, seq_number2, 0x00,
- 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x09,
- 0x00, dstaddr, netfn_lun,
- chk1, srcaddr, seq_number_lun,
- command, channel_number, privilege_level,
- chk2};
-
- for (auto character : send_buf) {
- std::cout << std::hex << static_cast<unsigned>(character) << " ";
- }
- std::cout << std::endl;
- socket.send_to(boost::asio::buffer(send_buf), receiver_endpoint);
-
- boost::array<unsigned char, 32> recv_buf;
- udp::endpoint sender_endpoint;
- size_t len =
- socket.receive_from(boost::asio::buffer(recv_buf), sender_endpoint);
- std::cout << len;
- for (auto character : recv_buf) {
- std::cout << std::hex << static_cast<unsigned>(character) << " ";
- }
-
- std::cout << std::endl;
- } catch (std::exception& e) {
- std::cerr << e.what() << std::endl;
- }
-
- return 0;
-} \ No newline at end of file
diff --git a/src/webserver_main.cpp b/src/webserver_main.cpp
index 404e15c..0c173dd 100644
--- a/src/webserver_main.cpp
+++ b/src/webserver_main.cpp
@@ -30,10 +30,12 @@
#include <boost/asio.hpp>
#include <boost/endian/arithmetic.hpp>
-#include <dbus/dbus.h>
-#include <boost/iostreams/stream.hpp>
-#include <boost/property_tree/ptree.hpp>
-#include <boost/property_tree/xml_parser.hpp>
+#include <dbus/connection.hpp>
+#include <dbus/endpoint.hpp>
+#include <dbus/filter.hpp>
+#include <dbus/match.hpp>
+#include <dbus/message.hpp>
+#include <dbus/utility.hpp>
#include <iostream>
#include <memory>
@@ -42,30 +44,6 @@
using sensor_values = std::vector<std::pair<std::string, int32_t>>;
-std::vector<std::string> read_dbus_xml_names(std::string& xml_data) {
- std::vector<std::string> values;
- // populate tree structure pt
- using boost::property_tree::ptree;
- ptree pt;
- boost::iostreams::stream<boost::iostreams::array_source> stream(
- xml_data.c_str(), xml_data.size());
- read_xml(stream, pt);
-
- // traverse node to find other nodes
- for (const auto& interface : pt.get_child("node")) {
- if (interface.first == "node") {
- auto t = interface.second.get<std::string>("<xmlattr>", "default");
- for (const auto& subnode : interface.second.get_child("<xmlattr>")) {
- if (subnode.first == "name") {
- auto t = subnode.second.get("", "unknown");
- values.emplace_back(std::move(t));
- }
- }
- }
- }
- return values;
-}
-
sensor_values read_sensor_values() {
sensor_values values;
DBusError err;
@@ -144,7 +122,8 @@ sensor_values read_sensor_values() {
std::vector<std::string> methods;
if (xml_struct != NULL) {
std::string xml_data(xml_struct);
- methods = read_dbus_xml_names(xml_data);
+ std::vector<std::string> names;
+ dbus::read_dbus_xml_names(xml_data, methods);
}
fprintf(stdout, "Found %zd sensors \n", methods.size());
@@ -235,8 +214,7 @@ int main(int argc, char** argv) {
ensuressl::ensure_openssl_key_present_and_valid(ssl_pem_file);
}
- crow::App<
- crow::TokenAuthorizationMiddleware, crow::SecurityHeadersMiddleware>
+ crow::App<crow::TokenAuthorizationMiddleware, crow::SecurityHeadersMiddleware>
app;
crow::webassets::request_routes(app);
@@ -304,22 +282,41 @@ int main(int argc, char** argv) {
});
CROW_ROUTE(app, "/sensortest")
- ([]() {
- crow::json::wvalue j;
- auto values = read_sensor_values();
- for (auto& pair : values) {
- j[pair.first] = pair.second;
- }
+ ([](const crow::request& req, crow::response& res) {
+ dbus::connection system_bus(*req.io_service, dbus::bus::system);
+
+ dbus::endpoint test_daemon("org.freedesktop.DBus", "/",
+ "org.freedesktop.DBus");
+ dbus::message m = dbus::message::new_call(test_daemon, "ListNames");
+ system_bus.async_send(m, [&](const boost::system::error_code ec,
+ dbus::message r) {
+ std::vector<std::string> services;
+ //r.unpack(services);
+ for (auto& service : services) {
+ dbus::endpoint service_daemon(service, "/",
+ "org.freedesktop.DBus.Introspectable");
+ dbus::message m = dbus::message::new_call(service_daemon, "Introspect");
+ system_bus.async_send(
+ m, [&](const boost::system::error_code ec, dbus::message r) {
+ std::string xml;
+ r.unpack(xml);
+ std::vector<std::string> dbus_objects;
+ dbus::read_dbus_xml_names(xml, dbus_objects);
+
+
+ });
+ }
+
+ });
- return j;
});
CROW_ROUTE(app, "/intel/firmwareupload")
.methods("POST"_method)([](const crow::request& req) {
// TODO(ed) handle errors here (file exists already and is locked, ect)
- std::ofstream out(
- "/tmp/fw_update_image",
- std::ofstream::out | std::ofstream::binary | std::ofstream::trunc);
+ std::ofstream out("/tmp/fw_update_image", std::ofstream::out |
+ std::ofstream::binary |
+ std::ofstream::trunc);
out << req.body;
out.close();
OpenPOWER on IntegriCloud