summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLubomir Rintel <lkundrak@v3.sk>2018-05-14 09:45:14 +0200
committerLubomir Rintel <lkundrak@v3.sk>2018-05-18 19:06:31 +0200
commitdb7d26e79f2cba6500dd9e0f333d3d319575f4ef (patch)
tree41c95565d2c49a8fc45ae8153b0cd10b9445289a
parentd428c668cb1310d151936f7316231112f1be481b (diff)
-rw-r--r--Makefile.am17
-rw-r--r--src/platform/tests/iwp.c118
-rw-r--r--src/platform/tests/wpan.c314
3 files changed, 447 insertions, 2 deletions
diff --git a/Makefile.am b/Makefile.am
index 000b0fd49..f26496d80 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -2941,7 +2941,8 @@ src_platform_tests_libadd = \
$(LIBUDEV_LIBS)
check_programs_norun += \
- src/platform/tests/monitor
+ src/platform/tests/monitor \
+ src/platform/tests/iwp
check_programs += \
src/platform/tests/test-link-fake \
@@ -2953,12 +2954,17 @@ check_programs += \
src/platform/tests/test-route-fake \
src/platform/tests/test-route-linux \
src/platform/tests/test-cleanup-fake \
- src/platform/tests/test-cleanup-linux
+ src/platform/tests/test-cleanup-linux \
+ src/platform/tests/wpan
src_platform_tests_monitor_CPPFLAGS = $(src_tests_cppflags)
src_platform_tests_monitor_LDFLAGS = $(src_platform_tests_ldflags)
src_platform_tests_monitor_LDADD = $(src_platform_tests_libadd)
+src_platform_tests_iwp_CPPFLAGS = $(src_tests_cppflags)
+src_platform_tests_iwp_LDFLAGS = $(src_platform_tests_ldflags)
+src_platform_tests_iwp_LDADD = $(src_platform_tests_libadd)
+
src_platform_tests_test_link_fake_SOURCES = src/platform/tests/test-link.c
src_platform_tests_test_link_fake_CPPFLAGS = $(src_tests_cppflags_fake)
src_platform_tests_test_link_fake_LDFLAGS = $(src_platform_tests_ldflags)
@@ -2999,6 +3005,12 @@ src_platform_tests_test_cleanup_linux_CPPFLAGS = $(src_tests_cppflags_linux)
src_platform_tests_test_cleanup_linux_LDFLAGS = $(src_platform_tests_ldflags)
src_platform_tests_test_cleanup_linux_LDADD = $(src_platform_tests_libadd)
+src_platform_tests_wpan_SOURCES = src/platform/tests/wpan.c
+src_platform_tests_wpan_CPPFLAGS = $(src_cppflags)
+#src_platform_tests_wpan_LDFLAGS = $(src_platform_tests_ldflags)
+#src_platform_tests_wpan_LDADD = $(src_platform_tests_libadd)
+src_platform_tests_wpan_LDADD = src/libNetworkManagerBase.la
+
src_platform_tests_test_nmp_object_CPPFLAGS = $(src_tests_cppflags)
src_platform_tests_test_nmp_object_LDFLAGS = $(src_platform_tests_ldflags)
src_platform_tests_test_nmp_object_LDADD = src/libNetworkManagerTest.la
@@ -3008,6 +3020,7 @@ src_platform_tests_test_general_LDFLAGS = $(src_platform_tests_ldflags)
src_platform_tests_test_general_LDADD = src/libNetworkManagerTest.la
$(src_platform_tests_monitor_OBJECTS): $(libnm_core_lib_h_pub_mkenums)
+$(src_platform_tests_iwp_OBJECTS): $(libnm_core_lib_h_pub_mkenums)
$(src_platform_tests_test_link_fake_OBJECTS): $(libnm_core_lib_h_pub_mkenums)
$(src_platform_tests_test_link_linux_OBJECTS): $(libnm_core_lib_h_pub_mkenums)
$(src_platform_tests_test_address_fake_OBJECTS): $(libnm_core_lib_h_pub_mkenums)
diff --git a/src/platform/tests/iwp.c b/src/platform/tests/iwp.c
new file mode 100644
index 000000000..50a400795
--- /dev/null
+++ b/src/platform/tests/iwp.c
@@ -0,0 +1,118 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/*
+ * 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright 2015 Red Hat, Inc.
+ */
+
+#include "nm-default.h"
+
+#include <stdlib.h>
+#include <syslog.h>
+
+#include "platform/nm-linux-platform.h"
+
+#include "nm-test-utils-core.h"
+
+NMTST_DEFINE ();
+
+static struct {
+ gboolean persist;
+} global_opt = {
+ .persist = TRUE,
+};
+
+static gboolean
+read_argv (int *argc, char ***argv)
+{
+ GOptionContext *context;
+ GOptionEntry options[] = {
+ { "no-persist", 'P', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &global_opt.persist, "Exit after processing netlink messages", NULL },
+ { 0 },
+ };
+ gs_free_error GError *error = NULL;
+
+ context = g_option_context_new (NULL);
+ g_option_context_set_summary (context, "Monitor netlink events in NMPlatform.");
+ g_option_context_add_main_entries (context, options, NULL);
+
+ if (!g_option_context_parse (context, argc, argv, &error)) {
+ g_warning ("Error parsing command line arguments: %s", error->message);
+ g_option_context_free (context);
+ return FALSE;
+ }
+
+ g_option_context_free (context);
+ return TRUE;
+}
+
+int
+main (int argc, char **argv)
+{
+ GMainLoop *loop;
+
+#if 0
+ if (!g_getenv ("G_MESSAGES_DEBUG"))
+ g_setenv ("G_MESSAGES_DEBUG", "all", TRUE);
+#endif
+
+ nmtst_init_with_logging (&argc, &argv, "DEBUG", "ALL");
+
+ if (!read_argv (&argc, &argv))
+ return 2;
+
+ nm_log_info (LOGD_PLATFORM, "platform monitor start");
+
+ loop = g_main_loop_new (NULL, FALSE);
+
+ nm_linux_platform_setup ();
+
+ nm_platform_check_kernel_support (NM_PLATFORM_GET, ~((NMPlatformKernelSupportFlags) 0));
+
+#if 0
+ if (global_opt.persist)
+ g_main_loop_run (loop);
+#endif
+
+{
+ int ifindex;
+ guint8 bssid[ETH_ALEN];
+
+ ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, "wlan0");
+
+ g_printerr (">>> %d <<<\n", ifindex);
+ if (nm_platform_wifi_get_bssid (NM_PLATFORM_GET, ifindex, bssid)) {
+ char *bssid_str = nm_utils_hwaddr_ntoa (bssid, ETH_ALEN);
+ g_printerr (">>> %s <<<\n", bssid_str);
+ g_free (bssid_str);
+ } else {
+ g_printerr (">>> :( <<<\n");
+ }
+
+}
+
+{
+ int ifindex;
+
+ ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, "wpan0");
+
+ g_printerr (">>> %d <<<\n", ifindex);
+ g_printerr (">>> %d <<<\n", nm_platform_wpan_get_pan_id (NM_PLATFORM_GET, ifindex));
+}
+
+ g_main_loop_unref (loop);
+
+ return EXIT_SUCCESS;
+}
diff --git a/src/platform/tests/wpan.c b/src/platform/tests/wpan.c
new file mode 100644
index 000000000..925fb4e7b
--- /dev/null
+++ b/src/platform/tests/wpan.c
@@ -0,0 +1,314 @@
+/*
+ * 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright 2018 Red Hat, Inc.
+ */
+
+#include "nm-default.h"
+
+#include <linux/if.h>
+#if 0
+
+#include <sched.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <linux/if_tun.h>
+
+#include "platform/nmp-object.h"
+#include "platform/nmp-netns.h"
+#include "platform/nm-platform-utils.h"
+
+#include "test-common.h"
+#include "nm-test-utils-core.h"
+#endif
+
+#include "platform/nm-netlink.h"
+#include "platform/nl802154.h"
+
+static int
+error_handler (struct sockaddr_nl *nla, struct nlmsgerr *err, void *arg)
+{
+ g_printerr ("(%s) {%d}\n", __func__, err->error);
+ return NL_SKIP;
+}
+
+static int
+finish_handler (struct nl_msg *msg, void *arg)
+{
+ g_printerr ("(%s)\n", __func__);
+ return NL_SKIP;
+}
+
+static int
+ack_handler (struct nl_msg *msg, void *arg)
+{
+ g_printerr ("(%s)\n", __func__);
+ return NL_SKIP;
+}
+
+static int
+valid_handler (struct nl_msg *msg, void *arg)
+{
+ struct genlmsghdr *gnlh = nlmsg_data (nlmsg_hdr (msg));
+ struct nlattr *tb[NL802154_ATTR_MAX + 1] = { 0, };
+ static const struct nla_policy nl802154_policy[NL802154_ATTR_MAX + 1] = {
+ [NL802154_ATTR_WPAN_PHY] = { .type = NLA_U32 },
+ [NL802154_ATTR_IFINDEX] = { .type = NLA_U32 },
+ [NL802154_ATTR_IFTYPE] = { .type = NLA_U32 },
+ [NL802154_ATTR_IFNAME] = { .type = NLA_NUL_STRING },
+ [NL802154_ATTR_WPAN_DEV] = { .type = NLA_U64 },
+ [NL802154_ATTR_PAN_ID] = { .type = NLA_U16 },
+ [NL802154_ATTR_SHORT_ADDR] = { .type = NLA_U16 },
+ [NL802154_ATTR_MAX_FRAME_RETRIES] = { .type = NLA_S8 },
+ [NL802154_ATTR_MIN_BE] = { .type = NLA_U8 },
+ [NL802154_ATTR_MAX_BE] = { .type = NLA_U8 },
+ [NL802154_ATTR_MAX_CSMA_BACKOFFS] = { .type = NLA_U8 },
+ [NL802154_ATTR_LBT_MODE] = { .type = NLA_U8 },
+ [NL802154_ATTR_GENERATION] = { .type = NLA_U32 },
+ [NL802154_ATTR_EXTENDED_ADDR] = { .type = NLA_U64 },
+ [NL802154_ATTR_ACKREQ_DEFAULT] = { .type = NLA_U8 },
+ };
+ int i;
+
+ g_printerr ("(%s)\n", __func__);
+ g_printerr ("===\n");
+
+ if (nla_parse (tb, NL802154_ATTR_MAX, genlmsg_attrdata (gnlh, 0),
+ genlmsg_attrlen (gnlh, 0), nl802154_policy) < 0)
+ return NL_SKIP;
+
+ g_printerr ("===\n");
+ for (i = 0; i < G_N_ELEMENTS (tb); i++) {
+ if (!tb[i])
+ continue;
+ g_printerr ("* %d: %d %d\n", i, tb[i]->nla_len, tb[i]->nla_type);
+ }
+
+
+
+
+ if (tb[NL802154_ATTR_WPAN_PHY]) {
+ g_printerr ("NL802154_ATTR_WPAN_PHY = 0x%x\n", nla_get_u32 (tb[NL802154_ATTR_WPAN_PHY]));
+ }
+
+ if (tb[NL802154_ATTR_IFINDEX]) {
+ g_printerr ("NL802154_ATTR_IFINDEX = 0x%x\n", nla_get_u32 (tb[NL802154_ATTR_IFINDEX]));
+ }
+
+ if (tb[NL802154_ATTR_IFTYPE]) {
+ g_printerr ("NL802154_ATTR_IFTYPE = 0x%x\n", nla_get_u32 (tb[NL802154_ATTR_IFTYPE]));
+ }
+
+ if (tb[NL802154_ATTR_IFNAME]) {
+ g_printerr ("NL802154_ATTR_IFNAME = '%s'\n", nla_get_string (tb[NL802154_ATTR_IFNAME]));
+ }
+
+ if (tb[NL802154_ATTR_WPAN_DEV]) {
+ g_printerr ("NL802154_ATTR_WPAN_DEV = 0x%lx\n", nla_get_u64 (tb[NL802154_ATTR_WPAN_DEV]));
+ }
+
+ if (tb[NL802154_ATTR_PAN_ID]) {
+ g_printerr ("NL802154_ATTR_PAN_ID = 0x%x\n", nla_get_u16 (tb[NL802154_ATTR_PAN_ID]));
+ }
+
+ if (tb[NL802154_ATTR_SHORT_ADDR]) {
+ g_printerr ("NL802154_ATTR_SHORT_ADDR = 0x%x\n", nla_get_u16 (tb[NL802154_ATTR_SHORT_ADDR]));
+ }
+
+ if (tb[NL802154_ATTR_MAX_FRAME_RETRIES]) {
+ g_printerr ("NL802154_ATTR_MAX_FRAME_RETRIES = 0x%x\n", nla_get_s8 (tb[NL802154_ATTR_MAX_FRAME_RETRIES]));
+ }
+
+ if (tb[NL802154_ATTR_MIN_BE]) {
+ g_printerr ("NL802154_ATTR_MIN_BE = 0x%x\n", nla_get_u8 (tb[NL802154_ATTR_MIN_BE]));
+ }
+
+ if (tb[NL802154_ATTR_MAX_BE]) {
+ g_printerr ("NL802154_ATTR_MAX_BE = 0x%x\n", nla_get_u8 (tb[NL802154_ATTR_MAX_BE]));
+ }
+
+ if (tb[NL802154_ATTR_MAX_CSMA_BACKOFFS]) {
+ g_printerr ("NL802154_ATTR_MAX_CSMA_BACKOFFS = 0x%x\n", nla_get_u8 (tb[NL802154_ATTR_MAX_CSMA_BACKOFFS]));
+ }
+
+ if (tb[NL802154_ATTR_LBT_MODE]) {
+ g_printerr ("NL802154_ATTR_LBT_MODE = 0x%x\n", nla_get_u8 (tb[NL802154_ATTR_LBT_MODE]));
+ }
+
+ if (tb[NL802154_ATTR_GENERATION]) {
+ g_printerr ("NL802154_ATTR_GENERATION = 0x%x\n", nla_get_u32 (tb[NL802154_ATTR_GENERATION]));
+ }
+
+ if (tb[NL802154_ATTR_EXTENDED_ADDR]) {
+ g_printerr ("NL802154_ATTR_EXTENDED_ADDR = 0x%lx\n", nla_get_u64 (tb[NL802154_ATTR_EXTENDED_ADDR]));
+ }
+
+ if (tb[NL802154_ATTR_ACKREQ_DEFAULT]) {
+ g_printerr ("NL802154_ATTR_ACKREQ_DEFAULT = 0x%x\n", nla_get_u8 (tb[NL802154_ATTR_ACKREQ_DEFAULT]));
+ }
+
+ return NL_SKIP;
+}
+
+static void
+info (struct nl_sock *sock, int id)
+{
+ struct nl_msg *msg;
+ const struct nl_cb cb = {
+ .err_cb = error_handler,
+ .err_arg = NULL,
+ .finish_cb = finish_handler,
+ .finish_arg = NULL,
+ .ack_cb = ack_handler,
+ .ack_arg = NULL,
+ .valid_cb = valid_handler,
+ .valid_arg = NULL,
+ };
+
+ msg = nlmsg_alloc ();
+
+ genlmsg_put (msg, 0, 0, id, 0, 0, NL802154_CMD_GET_INTERFACE, 0);
+ NLA_PUT_U32 (msg, NL802154_ATTR_IFINDEX, 10);
+
+ nl_send_auto (sock, msg);
+
+
+ while (1) {
+ g_printerr ("===========================================================\n");
+ nl_recvmsgs (sock, &cb);
+ }
+
+ return;
+goto nla_put_failure;
+nla_put_failure:
+ g_return_if_reached ();
+}
+
+int
+main (int argc, char *argv[])
+{
+#if 0
+ const struct nl_cb cb = { 0, };
+ struct nl_msg *msg;
+#endif
+ struct nl_sock *sock;
+ int id;
+
+#if 0
+ int done = 0;
+ const struct nl_cb cb = {
+ .err_cb = error_handler,
+ .err_arg = &done,
+ .finish_cb = finish_handler,
+ .finish_arg = &done,
+ .ack_cb = ack_handler,
+ .ack_arg = &done,
+ .valid_cb = valid_handler,
+ .valid_arg = valid_data,
+ };
+#endif
+
+
+ sock = nl_socket_alloc ();
+
+ nl_connect (sock, NETLINK_GENERIC);
+ id = genl_ctrl_resolve (sock, "nl802154");
+ g_printerr ("0x%x\n", id);
+
+
+#if 0
+ enum {
+ CTRL_CMD_UNSPEC,
+ CTRL_CMD_NEWFAMILY,
+ CTRL_CMD_DELFAMILY,
+ CTRL_CMD_GETFAMILY,
+ CTRL_CMD_NEWOPS,
+ CTRL_CMD_DELOPS,
+ CTRL_CMD_GETOPS,
+ CTRL_CMD_NEWMCAST_GRP,
+ CTRL_CMD_DELMCAST_GRP,
+ CTRL_CMD_GETMCAST_GRP, /* unused */
+ __CTRL_CMD_MAX,
+};
+
+
+ msg = nlmsg_alloc ();
+
+ struct genlmsghdr hdr = {
+ .cmd = cmd,
+ .version = version,
+ };
+
+ nlh = nlmsg_put (msg, port, seq, family, GENL_HDRLEN + hdrlen, flags);
+ if (nlh == NULL)
+ return NULL;
+
+
+ if (!genlmsg_put (msg, NL_AUTO_PORT, NL_AUTO_SEQ, GENL_ID_CTRL,
+ 0, 0, CTRL_CMD_GETFAMILY, 1))
+ goto out;
+
+
+
+ nle = nl_socket_add_memberships (priv->nlh,
+ RTNLGRP_LINK,
+ RTNLGRP_IPV4_IFADDR, RTNLGRP_IPV6_IFADDR,
+ RTNLGRP_IPV4_ROUTE, RTNLGRP_IPV6_ROUTE,
+ RTNLGRP_TC,
+ 0);
+#endif
+
+
+ info (sock, id);
+#if 0
+
+// NL802154_CMD_SET_PAN_ID,
+// pan_id = nla_get_le16(info->attrs[NL802154_ATTR_PAN_ID]);
+// [NL802154_ATTR_IFINDEX] = { .type = NLA_U32 },
+// msg = nl80211_alloc_msg (nl80211, NL80211_CMD_GET_WIPHY, 0);
+
+
+ msg = nlmsg_alloc ();
+ // genlmsg_put (struct nl_msg *msg, uint32_t port, uint32_t seq, int family, int hdrlen, int flags, uint8_t cmd, uint8_t version)
+// genlmsg_put (msg, 0, 0, id, 0, 0, NL802154_CMD_SET_PAN_ID, 0);
+// NLA_PUT_U32 (msg, NL802154_ATTR_IFINDEX, 7);
+// NLA_PUT_U16 (msg, NL802154_ATTR_PAN_ID, 123);
+
+ genlmsg_put (msg, 0, 0, id, 0, 0, NL802154_CMD_GET_INTERFACE, 0);
+
+ nl_send_auto (sock, msg);
+ nl_recvmsgs (sock, &cb);
+
+
+
+ g_printerr ("0x%x\n", id);
+
+
+
+
+ return 0;
+goto nla_put_failure;
+nla_put_failure:
+ g_return_val_if_reached (1);
+#endif
+
+
+
+
+
+
+
+}