-D OONF_NO_TESTING:Bool=true \
-D UCI:Bool=true \
-D OONF_APP_DEFAULT_CFG_HANDLER:String=uci \
- -D OONF_STATIC_PLUGINS:String="class;clock;duplicate_set;interface;layer2;packet_socket;rfc5444;socket;stream_socket;telnet;timer;viewer;os_clock;os_net;os_routing;os_system;nhdp;olsrv2;ff_dat_metric;neighbor_probing;nl80211_listener;link_config;layer2info;cfg_uciloader;nhdpinfo;olsrv2info" \
+ -D OONF_STATIC_PLUGINS:String="class;clock;duplicate_set;interface;layer2;packet_socket;rfc5444;socket;stream_socket;telnet;timer;viewer;os_clock;os_net;os_routing;os_system;nhdp;olsrv2;ff_dat_metric;neighbor_probing;nl80211_listener;link_config;layer2info;systeminfo;cfg_uciloader;nhdpinfo;olsrv2info" \
-D INSTALL_LIB_DIR:Path=lib/oonf \
-D INSTALL_INCLUDE_DIR:Path=include/oonf \
-D INSTALL_CMAKE_DIR:Path=lib/oonf \
}
/**
+ * @param pointer to storage object for time string
* @return pointer to string containing the current walltime
*/
-int
-oonf_log_get_walltime(struct autobuf *out) {
- struct timeval now;
+const char *
+oonf_log_get_walltime(struct oonf_walltime_str *buf) {
+struct timeval now;
struct tm *tm;
if (os_core_gettimeofday(&now)) {
- return -1;
+ return NULL;
}
tm = localtime(&now.tv_sec);
if (tm == NULL) {
- return -1;
+ return NULL;
}
- abuf_appendf(out, "%02d:%02d:%02d.%03ld",
+ snprintf(buf->buf, sizeof(buf->buf), "%02d:%02d:%02d.%03ld",
tm->tm_hour, tm->tm_min, tm->tm_sec, now.tv_usec / 1000);
- return 0;
+ return buf->buf;
}
/**
{
struct oonf_log_handler_entry *h, *iterator;
struct oonf_log_parameters param;
+ struct oonf_walltime_str tbuf;
char *last;
va_list ap;
int p1,p2;
/* generate log string */
abuf_clear(&_logbuffer);
if (!no_header) {
- oonf_log_get_walltime(&_logbuffer);
- p1 = abuf_getlen(&_logbuffer);
+ p1 = abuf_puts(&_logbuffer, oonf_log_get_walltime(&tbuf));
- abuf_appendf(&_logbuffer, " %s(%s) %s %d: ",
+ p2 = abuf_appendf(&_logbuffer, " %s(%s) %s %d: ",
LOG_SEVERITY_NAMES[severity], LOG_SOURCE_NAMES[source], file, line);
- p2 = abuf_getlen(&_logbuffer) - p1;
}
abuf_vappendf(&_logbuffer, format, ap);
void *custom;
};
+struct oonf_walltime_str {
+ char buf[sizeof("00:00:00.000")];
+};
+
#define OONF_FOR_ALL_LOGSEVERITIES(sev) for (sev = LOG_SEVERITY_MIN; sev <= LOG_SEVERITY_MAX; sev <<= 1)
EXPORT extern uint8_t log_global_mask[LOG_MAXIMUM_SOURCES];
EXPORT const struct oonf_appdata *oonf_log_get_appdata(void);
EXPORT const struct oonf_libdata *oonf_log_get_libdata(void);
EXPORT void oonf_log_printversion(struct autobuf *abuf);
-EXPORT int oonf_log_get_walltime(struct autobuf *abuf);
+EXPORT const char *oonf_log_get_walltime(struct oonf_walltime_str *);
EXPORT void oonf_log(enum oonf_log_severity, enum oonf_log_source, bool, const char *, int, const void *, size_t, const char *, ...)
__attribute__ ((format(printf, 8, 9)));
# add subdirectories
add_subdirectory(cfg_compact)
+add_subdirectory(dlep)
add_subdirectory(httptelnet)
add_subdirectory(layer2info)
add_subdirectory(layer2_generator)
add_subdirectory(link_config)
add_subdirectory(plugin_controller)
add_subdirectory(remotecontrol)
-add_subdirectory(dlep)
+add_subdirectory(systeminfo)
# UCI specific library necessary for Openwrt config loader
IF (UCI)
if (tb_msg[NL80211_ATTR_WIPHY_FREQ]) {
uint64_t freq[2], bandwidth[2];
- freq[0] = nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_FREQ]) * 1000000;
+ freq[0] = nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_FREQ]);
freq[1] = 0;
if (tb_msg[NL80211_ATTR_CHANNEL_WIDTH]) {
bandwidth[1] = bandwidth[0];
}
+ /* transform from MHz to Hz*/
+ freq[0] *= 1000000ull;
+ freq[0] *= 1000000ull;
+
interf->ifdata_changed |= nl80211_change_l2net_data(interf->l2net,
OONF_LAYER2_NET_FREQUENCY_1, freq[0]);
interf->ifdata_changed |= nl80211_change_l2net_data(interf->l2net,
_get_bandwidth(uint32_t width) {
switch (width) {
case NL80211_CHAN_WIDTH_5:
- return 5 * 1000000;
+ return 5ull * 1000000ull;
case NL80211_CHAN_WIDTH_10:
- return 10 * 1000000;
+ return 10ull * 1000000ull;
case NL80211_CHAN_WIDTH_20_NOHT:
- return 20 * 1000000;
+ return 20ull * 1000000ull;
case NL80211_CHAN_WIDTH_20:
- return 20 * 1000000;
+ return 20ull * 1000000ull;
case NL80211_CHAN_WIDTH_40:
- return 40 * 1000000;
+ return 40ull * 1000000ull;
case NL80211_CHAN_WIDTH_80:
- return 80 * 1000000;
+ return 80ull * 1000000ull;
case NL80211_CHAN_WIDTH_80P80:
- return 80 * 1000000;
+ return 80ull * 1000000ull;
case NL80211_CHAN_WIDTH_160:
- return 160 * 1000000;
+ return 160ull * 1000000ull;
default:
return 0;
}
--- /dev/null
+# set library parameters
+SET (name systeminfo)
+
+# use generic plugin maker
+oonf_create_plugin("${name}" "${name}.c" "${name}.h" "")
--- /dev/null
+
+/*
+ * The olsr.org Optimized Link-State Routing daemon version 2 (olsrd2)
+ * Copyright (c) 2004-2013, the olsr.org team - see HISTORY file
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of olsr.org, olsrd nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Visit http://www.olsr.org for more information.
+ *
+ * If you find this software useful feel free to make a donation
+ * to the project. For more information see the website or contact
+ * the copyright holders.
+ *
+ */
+
+#include <stdio.h>
+
+#include "common/common_types.h"
+#include "common/autobuf.h"
+#include "common/netaddr.h"
+#include "common/netaddr_acl.h"
+#include "common/string.h"
+#include "common/template.h"
+
+#include "core/oonf_logging.h"
+#include "core/oonf_subsystem.h"
+#include "subsystems/oonf_clock.h"
+#include "subsystems/oonf_telnet.h"
+#include "subsystems/oonf_viewer.h"
+
+#include "systeminfo/systeminfo.h"
+
+/* definitions */
+#define LOG_SYSTEMINFO _oonf_systeminfo_subsystem.logging
+
+/* name of telnet subcommands/JSON nodes */
+#define _JSON_NAME_TIME "time"
+
+/* prototypes */
+static int _init(void);
+static void _cleanup(void);
+
+static enum oonf_telnet_result _cb_systeminfo(struct oonf_telnet_data *con);
+static enum oonf_telnet_result _cb_systeminfo_help(struct oonf_telnet_data *con);
+
+static void _initialize_time_values(struct oonf_viewer_template *template);
+
+static int _cb_create_text_time(struct oonf_viewer_template *);
+
+/*
+ * list of template keys and corresponding buffers for values.
+ *
+ * The keys are API, so they should not be changed after published
+ */
+#define KEY_SYSTEM_TIME "system_time"
+#define KEY_INTERNAL_TIME "internal_time"
+
+/*
+ * buffer space for values that will be assembled
+ * into the output of the plugin
+ */
+static struct oonf_walltime_str _value_system_time;
+static struct isonumber_str _value_internal_time;
+
+/* definition of the template data entries for JSON and table output */
+static struct abuf_template_data_entry _tde_time_key[] = {
+ { KEY_SYSTEM_TIME, _value_system_time.buf, true },
+ { KEY_INTERNAL_TIME, _value_internal_time.buf, false },
+};
+
+static struct abuf_template_storage _template_storage;
+
+/* Template Data objects (contain one or more Template Data Entries) */
+static struct abuf_template_data _td_time[] = {
+ { _tde_time_key, ARRAYSIZE(_tde_time_key) },
+};
+
+/* OONF viewer templates (based on Template Data arrays) */
+static struct oonf_viewer_template _templates[] = {
+ {
+ .data = _td_time,
+ .data_size = ARRAYSIZE(_td_time),
+ .json_name = _JSON_NAME_TIME,
+ .cb_function = _cb_create_text_time,
+ },
+};
+
+/* telnet command of this plugin */
+static struct oonf_telnet_command _telnet_commands[] = {
+ TELNET_CMD(OONF_SYSTEMINFO_SUBSYSTEM, _cb_systeminfo,
+ "", .help_handler = _cb_systeminfo_help),
+};
+
+/* plugin declaration */
+static const char *_dependencies[] = {
+ OONF_CLOCK_SUBSYSTEM,
+ OONF_TELNET_SUBSYSTEM,
+ OONF_VIEWER_SUBSYSTEM,
+};
+
+struct oonf_subsystem _olsrv2_systeminfo_subsystem = {
+ .name = OONF_SYSTEMINFO_SUBSYSTEM,
+ .dependencies = _dependencies,
+ .dependencies_count = ARRAYSIZE(_dependencies),
+ .descr = "OLSRv2 system info plugin",
+ .author = "Henning Rogge",
+ .init = _init,
+ .cleanup = _cleanup,
+};
+DECLARE_OONF_PLUGIN(_olsrv2_systeminfo_subsystem);
+
+/**
+ * Initialize plugin
+ * @return -1 if an error happened, 0 otherwise
+ */
+static int
+_init(void) {
+ oonf_telnet_add(&_telnet_commands[0]);
+ return 0;
+}
+
+/**
+ * Cleanup plugin
+ */
+static void
+_cleanup(void) {
+ oonf_telnet_remove(&_telnet_commands[0]);
+}
+
+/**
+ * Callback for the telnet command of this plugin
+ * @param con pointer to telnet session data
+ * @return telnet result value
+ */
+static enum oonf_telnet_result
+_cb_systeminfo(struct oonf_telnet_data *con) {
+ int result;
+
+ /* call template based subcommands first */
+ result = oonf_viewer_call_subcommands(con->out, &_template_storage,
+ con->parameter, _templates, ARRAYSIZE(_templates));
+ if (result == 0) {
+ return TELNET_RESULT_ACTIVE;
+ }
+ if (result < 0) {
+ return TELNET_RESULT_INTERNAL_ERROR;
+ }
+
+ if (con->parameter == NULL || *con->parameter == 0) {
+ abuf_puts(con->out, "Error, '" OONF_SYSTEMINFO_SUBSYSTEM "' needs a parameter\n");
+ }
+ abuf_appendf(con->out, "Wrong parameter in command: %s\n", con->parameter);
+ return TELNET_RESULT_ACTIVE;
+}
+
+/**
+ * Callback for the help output of this plugin
+ * @param con pointer to telnet session data
+ * @return telnet result value
+ */
+static enum oonf_telnet_result
+_cb_systeminfo_help(struct oonf_telnet_data *con) {
+ const char *next;
+
+ /* skip the layer2info command */
+ next = str_hasnextword(con->parameter, OONF_SYSTEMINFO_SUBSYSTEM);
+
+ /* print out own help text */
+ abuf_puts(con->out, "System information command\n");
+ oonf_viewer_print_help(con->out, next, _templates, ARRAYSIZE(_templates));
+
+ return TELNET_RESULT_ACTIVE;
+}
+
+/**
+ * Initialize the value buffers for the time of the system
+ */
+static void
+_initialize_time_values(struct oonf_viewer_template *template) {
+ oonf_log_get_walltime(&_value_system_time);
+ isonumber_from_u64(&_value_internal_time, oonf_clock_getNow(),
+ "", 3, false, template->create_raw);
+}
+
+/**
+ * Callback to generate text/json description of current time
+ * @param template viewer template
+ * @return -1 if an error happened, 0 otherwise
+ */
+static int
+_cb_create_text_time(struct oonf_viewer_template *template) {
+ /* initialize values */
+ _initialize_time_values(template);
+
+ /* generate template output */
+ oonf_viewer_output_print_line(template);
+ return 0;
+}
--- /dev/null
+
+/*
+ * The olsr.org Optimized Link-State Routing daemon version 2 (olsrd2)
+ * Copyright (c) 2004-2013, the olsr.org team - see HISTORY file
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of olsr.org, olsrd nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Visit http://www.olsr.org for more information.
+ *
+ * If you find this software useful feel free to make a donation
+ * to the project. For more information see the website or contact
+ * the copyright holders.
+ *
+ */
+
+#ifndef SYSTEMINFO_H_
+#define SYSTEMINFO_H_
+
+#include "common/common_types.h"
+#include "core/oonf_subsystem.h"
+
+#define OONF_SYSTEMINFO_SUBSYSTEM "systeminfo"
+
+#endif /* SYSTEMINFO_H_ */
static enum oonf_telnet_result _cb_telnet_repeat(struct oonf_telnet_data *data);
static enum oonf_telnet_result _cb_telnet_timeout(struct oonf_telnet_data *data);
static enum oonf_telnet_result _cb_telnet_version(struct oonf_telnet_data *data);
-static enum oonf_telnet_result _cb_telnet_time(struct oonf_telnet_data *data);
/* configuration of telnet server */
static struct cfg_schema_entry _telnet_entries[] = {
TELNET_CMD("timeout", _cb_telnet_timeout,
"timeout <seconds> :Sets telnet session timeout"),
TELNET_CMD("version", _cb_telnet_version, "Displays version of the program"),
- TELNET_CMD("time", _cb_telnet_time, "Displays the current system and internal time,"
- " use 'json' parameter to get JSON output"),
-
};
/* subsystem definition */
return TELNET_RESULT_ACTIVE;
}
+#if 0
static enum oonf_telnet_result
_cb_telnet_time(struct oonf_telnet_data *data) {
- if (data->parameter && strcasecmp(data->parameter, "json") == 0) {
+ bool json = false, only_data = false;
+
+ json = data->parameter && strcasecmp(data->parameter, "json") == 0;
+ only_data = data->parameter && strcasecmp(data->parameter, "data") == 0;
+
+ if (json || only_data) {
/* JSON time output */
- abuf_puts(data->out, "time: {\n\t\"system\": \"");
+ if (!only_data) {
+ abuf_puts(data->out, "{\n");
+ }
+ abuf_puts(data->out,
+ "\"time\": {\n"
+ "\t\"system\": \"");
oonf_log_get_walltime(data->out);
- abuf_appendf(data->out, "\",\n\t\"internal\": %" PRIu64"\n}\n",
+ abuf_appendf(data->out,
+ "\",\n"
+ "\t\"internal\": %" PRIu64"\n"
+ "}\n",
oonf_clock_getNow());
+ if (!only_data) {
+ abuf_puts(data->out, "}\n");
+ }
}
else {
abuf_puts(data->out, "system time: ");
}
return TELNET_RESULT_ACTIVE;
}
+
+#endif
oonf_viewer_json_init_session(&template->_json, out);
/* start wrapper object */
- oonf_viewer_json_start_object(&template->_json);
+ if (!template->create_only_data) {
+ oonf_viewer_json_start_object(&template->_json);
+ }
/* start object with array */
oonf_viewer_json_start_array(&template->_json, template->json_name);
oonf_viewer_output_finish(struct oonf_viewer_template *template) {
if (template->create_json) {
oonf_viewer_json_end_array(&template->_json);
- oonf_viewer_json_end_object(&template->_json);
+ if (!template->create_only_data) {
+ oonf_viewer_json_end_object(&template->_json);
+ }
}
}
bool head = false;
bool json = false;
bool raw = false;
+ bool data = false;
if ((next = str_hasnextword(param, OONF_VIEWER_HEAD_FORMAT))) {
head = true;
json = true;
raw = true;
}
+ else if ((next = str_hasnextword(param, OONF_VIEWER_DATA_FORMAT))) {
+ json = true;
+ data = true;
+ }
+ else if ((next = str_hasnextword(param, OONF_VIEWER_DATA_RAW_FORMAT))) {
+ json = true;
+ raw = true;
+ data = true;
+ }
else {
next = param;
}
if ((ptr = str_hasnextword(next, templates[i].json_name))) {
templates[i].create_json = json;
templates[i].create_raw = raw;
+ templates[i].create_only_data = data;
if (oonf_viewer_output_prepare(&templates[i], storage, out, ptr)) {
return -1;
#define OONF_VIEWER_HEAD_FORMAT "head"
#define OONF_VIEWER_JSON_FORMAT "json"
#define OONF_VIEWER_JSON_RAW_FORMAT "jsonraw"
+#define OONF_VIEWER_DATA_FORMAT "data"
+#define OONF_VIEWER_DATA_RAW_FORMAT "dataraw"
/* This struct contains the session variables for JSON generation */
struct oonf_viewer_json_session {
/* true if isonumbers should be raw */
bool create_raw;
+ /* true if skips the enclosing JSON brackets */
+ bool create_only_data;
+
/* pointer to template data array to get key/value pairs */
struct abuf_template_data *data;
os_system
layer2info
nl80211_listener
+ systeminfo
nhdp
ff_dat_metric
link_config