diff mbox series

iw: add command to inject a frame via direct mesh link to mesh peer

Message ID 1554766163-12649-1-git-send-email-pradeepc@codeaurora.org (mailing list archive)
State Accepted
Delegated to: Johannes Berg
Headers show
Series iw: add command to inject a frame via direct mesh link to mesh peer | expand

Commit Message

Pradeep Kumar Chitrapu April 8, 2019, 11:29 p.m. UTC
Add mpath command to inject ethernet frame over direct mesh link to
given peer, bypassing the mpath table lookup. This helps to send data
frames over unexcersized direct mesh path, which is not selected as
next_hop node. This can be helpful in measuring link metrics.

Format:
$ iw dev <devname> mpath probe <Peer MAC> frame <pattern>

Example:
$ iw wlan0 mpath probe aa:bb:cc:dd:ee:ff frame aa:bb:cc:dd:ee:ff:kk:ll:mm:nn:oo:pp:yy:zz

Frame pattern is supplied as hex pattern of the form aa:bb:cc without
leading 0x. Frame type and length are expected to be of ethernet frame
type.

Signed-off-by: Pradeep Kumar Chitrapu <pradeepc@codeaurora.org>
---

 mpath.c | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
diff mbox series

Patch

diff --git a/mpath.c b/mpath.c
index ff0b7419fd2b..e39c24ba4403 100644
--- a/mpath.c
+++ b/mpath.c
@@ -90,6 +90,45 @@  static int print_mpath_handler(struct nl_msg *msg, void *arg)
 	return NL_SKIP;
 }
 
+static int handle_mpath_probe(struct nl80211_state *state,
+			      struct nl_msg *msg,
+			      int argc, char **argv,
+			      enum id_input id)
+{
+	unsigned char dst[ETH_ALEN];
+	unsigned char *frame;
+	size_t frame_len;
+
+	if (argc < 3)
+		return 1;
+
+	if (mac_addr_a2n(dst, argv[0])) {
+		fprintf(stderr, "invalid mac address\n");
+		return 2;
+	}
+
+	if (strcmp("frame", argv[1]) != 0)
+		return 1;
+
+	frame = parse_hex(argv[2], &frame_len);
+	if (!frame) {
+		fprintf(stderr, "invalid frame pattern: %p\n", frame);
+		return 2;
+	}
+
+	NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst);
+	NLA_PUT(msg, NL80211_ATTR_FRAME, frame_len, frame);
+
+	return 0;
+ nla_put_failure:
+	return -ENOBUFS;
+}
+COMMAND(mpath, probe, "<destination MAC address> frame <frame>",
+	NL80211_CMD_PROBE_MESH_LINK, 0, CIB_NETDEV, handle_mpath_probe,
+	"Inject ethernet frame to given peer overriding the next hop\n"
+	"lookup from mpath table.\n."
+	"Example: iw dev wlan0 mpath probe xx:xx:xx:xx:xx:xx frame 01:xx:xx:00\n");
+
 static int handle_mpath_get(struct nl80211_state *state,
 			    struct nl_msg *msg,
 			    int argc, char **argv,