offchannel: introduce new offchannel module
James Prestwood
PATCH v2 1/1 offchannel: introduce new offchannel module
This module provides a convenient wrapper around both CMD_[CANCEL_]_REMAIN_ON_CHANNEL APIs.
Certain protocols require going offchannel to send frames, and/or wait for a response. The frame-xchg module somewhat does this but has some limitations. For example you cannot just go offchannel; an initial frame must be sent out to start the procedure. In addition frame-xchg does not work for broadcasts since it expects an ACK.
This module is much simpler and only handles going offchannel for a duration. During this time frames may be sent or received. After the duration the caller will get a callback and any included error if there was one. Any offchannel request can be cancelled prior to the duration expriring if the offchannel work has finished early.
--- Makefile.am | 1 + src/offchannel.c | 302 +++++++++++++++++++++++++++++++++++++++++++++++ src/offchannel.h | 29 +++++ 3 files changed, 332 insertions(+) create mode 100644 src/offchannel.c create mode 100644 src/offchannel.h
v2:
* Removed internal timer and intead rely on the kernel to keep track
* Specially handle the cancel case where the command had been sent to the kernel already. For this we need to wait until the genl callback to cancel (since we then have the cookie).
Makefile.am +1 -0
@@ -247,6 +247,7 @@ src_iwd_SOURCES = src/main.c linux/nl80211.h src/iwd.h src/missing.h \ src/ip-pool.h src/ip-pool.c \ src/band.h src/band.c \ src/sysfs.h src/sysfs.c \ + src/offchannel.h src/offchannel.c \ $(eap_sources) \ $(builtin_sources)
src/offchannel.c new file +302 -0
302 lines not on this page · raw message
src/offchannel.h new file +29 -0
@@ -0,0 +1,29 @@ +/* +* +* Wireless daemon for Linux +* +* Copyright (C) 2021 Intel Corporation. All rights reserved. +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +* +*/ + +typedef void (*offchannel_started_cb_t )(void *user_data); +typedef void (*offchannel_destroy_cb_t )(int error,void *user_data); + +uint32_t offchannel_start (uint64_t wdev_id,uint32_t freq,uint32_t duration, +offchannel_started_cb_t started,void *user_data, +offchannel_destroy_cb_t destroy); +void offchannel_cancel (uint64_t wdev_id,uint32_t id);
Signature · 1 line
2.31.1
Paul Menzel
Dear James,
Thank you for writing this great commit message, helping me understand, what the module does.
Kind regards,
Paul
Denis Kenzior
Hi James,
Quoted 28 lines · James Prestwood
This module provides a convenient wrapper around both CMD_[CANCEL_]_REMAIN_ON_CHANNEL APIs.
Certain protocols require going offchannel to send frames, and/or wait for a response. The frame-xchg module somewhat does this but has some limitations. For example you cannot just go offchannel; an initial frame must be sent out to start the procedure. In addition frame-xchg does not work for broadcasts since it expects an ACK.
This module is much simpler and only handles going offchannel for a duration. During this time frames may be sent or received. After the duration the caller will get a callback and any included error if there was one. Any offchannel request can be cancelled prior to the duration expriring if the offchannel work has finished early.
--- Makefile.am | 1 + src/offchannel.c | 302 +++++++++++++++++++++++++++++++++++++++++++++++ src/offchannel.h | 29 +++++ 3 files changed, 332 insertions(+)create mode 100644
src/offchannel.c
create mode 100644src/offchannel.hv2:
* Removed internal timer and intead rely on the kernel to keep track
* Specially handle the cancel case where the command had been sent to the kernel already. For this we need to wait until the genl callback to cancel (since we then have the cookie).
<snip>
src/offchannel.c line 78
Quoted 11 lines
src/offchannel.c new file +11
-0+static void offchannel_cancel_roc (struct offchannel_info *info) +{ +struct l_genl_msg *msg; + + msg =l_genl_msg_new (NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL ); + +l_genl_msg_append_attr (msg,NL80211_ATTR_WDEV ,8 , &info->wdev_id); +l_genl_msg_append_attr (msg,NL80211_ATTR_COOKIE ,8 , &info->roc_cookie); + +/* Nothing much can be done if this fails */ +if (!l_genl_family_send (nl80211, msg,NULL ,NULL ,NULL ))
Would it not be better to wait until the cancel is at least acked and only end the wiphy work then? Might be even better if we waited around until the kernel sends the cancel event as well.
Quoted 34 lines
src/offchannel.c new file +34
-0+l_genl_msg_unref (msg); +} + +static void offchannel_roc_cb (struct l_genl_msg *msg,void *user_data) +{ +struct offchannel_info *info = user_data; + + info->error =l_genl_msg_get_error (msg); + info->roc_cmd_id =0 ; + +if (info->error <0 ) { +l_debug ("Error from CMD_REMAIN_ON_CHANNEL (%d)" , info->error); + goto work_done; + } + + info->error =nl80211_parse_attrs (msg,NL80211_ATTR_COOKIE , + &info->roc_cookie,NL80211_ATTR_UNSPEC ); +if (info->error <0 ) { +l_error ("Could not parse ROC cookie" ); + goto work_done; + } + +/* This request was cancelled, and ROC needs to be cancelled */ +if (info->needs_cancel) { +offchannel_cancel_roc (info); + goto work_done; + } + +return ; + +work_done: +wiphy_radio_work_done (wiphy_find_by_wdev (info->wdev_id), info->work.id); +} +
<snip>
src/offchannel.c line 181
Quoted 6 lines
src/offchannel.c new file +6
-0+ +void offchannel_cancel (uint64_t wdev_id,uint32_t id) +{ +struct wiphy *wiphy =wiphy_find_by_wdev (wdev_id); +struct offchannel_info *info; +
Maybe be paranoid and check wiphy isn't NULL?
Also, shouldn't we check that the work id exists?
src/offchannel.c line 184
Quoted 3 lines
src/offchannel.c new file +3
-0+/* Hasn't even started yet */ +if (!wiphy_radio_work_is_running (wiphy, id)) + goto work_done;
Guess we could modify wiphy_radio_work_is_running to return an int and use 0/1 for true/false and -ENOENT if the work doesn't exist.
src/offchannel.c line 197
Quoted 13 lines
src/offchannel.c new file +13
-0+ + info =l_queue_find (offchannel_list, match_wdev, &wdev_id); +if (!info) +return ; + +if (info->roc_cmd_id) { +/* +* The command has been sent to the kernel. This means we must +* wait till ROC starts and cancel at that time. Cancelling just +* the ROC command now will have no effect. +*/ +if (l_genl_family_request_sent (nl80211, info->roc_cmd_id)) + info->needs_cancel = true;
Hmm, is a patch missing for ell?
So you set needs_cancel and invoke l_genl_family_cancel, which means that offchannel_roc_cb() is never called. Yet that seems to be the only place you check needs_cancel?
src/offchannel.c line 203
Quoted 6 lines
src/offchannel.c new file +6
-0+ +l_genl_family_cancel (nl80211, info->roc_cmd_id); + info->roc_cmd_id =0 ; + +if (!info->needs_cancel) + goto work_done;
If the request hasn't started, then indeed invoking l_genl_family_cancel and destroying the work right away should be fine. If the request has already been sent, then we are stuck waiting for the ack. You could also assume that if roc_cmd_id is set, then the command is in flight and setting needs_cancel/waiting for the ack is needed.
In either case, we should invoke the destroy callback here and clear out the user data/callbacks.
src/offchannel.c line 213
Quoted 10 lines
src/offchannel.c new file +10
-0+ +return ; + } + +/* +* Something must have happened in the genl callback. Any errors there +* will be handled already +*/ +if (!info->roc_cookie) +return ;
I'm guessing this should be an L_WARN_ON.
src/offchannel.c line 224
Quoted 11 lines
src/offchannel.c new file +11
-0+ +/* +* At this point we know ROC has at least been queued (potentially not +* started) and can be cancelled. +*/ +offchannel_cancel_roc (info); + +work_done: +wiphy_radio_work_done (wiphy, id); +} +
Regards,
-Denis
James Prestwood
Quoted 53 lines · Denis Kenzior
Hi James,
Quoted 33 lines · James Prestwood
This module provides a convenient wrapper around both CMD_[CANCEL_]_REMAIN_ON_CHANNEL APIs.
Certain protocols require going offchannel to send frames, and/or wait for a response. The frame-xchg module somewhat does this but has some limitations. For example you cannot just go offchannel; an initial frame must be sent out to start the procedure. In addition
frame-xchg does not work for broadcasts since it expects an ACK.This module is much simpler and only handles going offchannel for a duration. During this time frames may be sent or received. After the duration the caller will get a callback and any included error if there was one. Any offchannel request can be cancelled prior to the duration expriring if the offchannel work has finished early.
---
Makefile.am | 1 +
src/offchannel.c| 302
+++++++++++++++++++++++++++++++++++++++++++++++
src/offchannel.h| 29 +++++3 files changed, 332 insertions(+)create mode 100644
src/offchannel.c
create mode 100644src/offchannel.hv2:
* Removed internal timer and intead rely on the kernel to keep track
* Specially handle the cancel case where the command had been sent to
the kernel already. For this we need to wait until the genl callback
to cancel (since we then have the cookie).<snip>
Quoted 8 lines
src/offchannel.c new file +7
-0+static void offchannel_cancel_roc (struct offchannel_info *info) +{ + struct l_genl_msg *msg; + + msg = l_genl_msg_new(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL); + + l_genl_msg_append_attr(msg, NL80211_ATTR_WDEV, 8, &info-Quoted 1 line
wdev_id);Quoted 5 lines
+ l_genl_msg_append_attr(msg,
NL80211_ATTR_COOKIE, 8, &info-Quoted 1 line
roc_cookie);+
+ /* Nothing much can be done if this fails */
+ if (!l_genl_family_send(nl80211, msg, NULL, NULL, NULL))
Quoted 5 lines
Would it not be better to wait until the cancel is at least acked and only end
the wiphy work then? Might be even better if we waited around until the kernel
sends the cancel event as well.
Sure I think waiting till the kernel sends cancel ROC is best, that moves most of the 'done' paths into one spot anyways. I'll change the 'needs_cancel' check to just return below.
Even with this though I don't see a point of waiting for the ACK since the kernel will send cancel ROC. The ACK callback for this would have no purpose AFAIK.
Quoted 23 lines
Quoted 23 lines
+ l_genl_msg_unref(msg);
src/offchannel.c new file +3
-0+} + +static void offchannel_roc_cb(struct l_genl_msg *msg, void
*user_data)src/offchannel.c new file +8
-0+{ + struct offchannel_info *info = user_data; + + info->error = l_genl_msg_get_error(msg); + info->roc_cmd_id = 0; + + if (info->error < 0) { + l_debug("Error from CMD_REMAIN_ON_CHANNEL (%d)",
info->error);
+ gotowork_done;
+ }
+
+ info->error = nl80211_parse_attrs(msg,NL80211_ATTR_COOKIE, + &info->roc_cookie,NL80211_ATTR_UNSPEC);
+ if (info->error< 0) {
+ l_error("Could not parse ROC cookie");
Quoted 8 lines
Quoted 8 lines
+ goto
work_done;
+ }
+
+ /* This request was cancelled, and ROC needs to be cancelled */
+ if (info->needs_cancel) {
+ offchannel_cancel_roc(info);
+ gotowork_done;
This can just return, and be 'done' in the ROC cancel event.
Quoted 23 lines
Quoted 9 lines
+ }
src/offchannel.c new file +5
-0+ + return; + +work_done: + wiphy_radio_work_done(wiphy_find_by_wdev(info->wdev_id),
info->work.id);(quoted diff) +2
-0+} +<snip>
src/offchannel.c line 181
Quoted 6 lines
src/offchannel.c new file +6
-0+ +void offchannel_cancel (uint64_t wdev_id,uint32_t id) +{ + struct wiphy *wiphy = wiphy_find_by_wdev(wdev_id); + struct offchannel_info *info; +Maybe be paranoid and check wiphy isn't NULL?
Also, shouldn't we check that the work id exists?
Quoted 7 lines
Quoted 3 lines
+ /* Hasn't even started yet */
+ if (!wiphy_radio_work_is_running(wiphy, id)) + gotowork_done;Guess we could modify
wiphy_radio_work_is_runningto return an int and use 0/1
for true/false and-ENOENTif the work doesn't exist.
Sure, sounds good.
Quoted 15 lines
Quoted 15 lines
src/offchannel.c new file +8
-0+ + info = l_queue_find(offchannel_list, match_wdev, &wdev_id); + if (!info) + return; + + if (info->roc_cmd_id) { + /* +* The command has been sent to the kernel. This means we must
+ * wait till ROC starts and cancel at that time. Cancelling just
+ * the ROC command now will have no effect. + */
+ if (l_genl_family_request_sent(nl80211, info-
Quoted 4 lines
Quoted 2 lines
Quoted 1 line
roc_cmd_id))+ info->needs_cancel = true;
Hmm, is a patch missing for ell?
Yeah, I'll send this out.
Quoted 23 lines
So you set
needs_canceland invokel_genl_family_cancel, which means thatoffchannel_roc_cb()is never called. Yet that seems to be the only place you
checkneeds_cancel?src/offchannel.c line 203
Quoted 6 lines
src/offchannel.c new file +6
-0+ + l_genl_family_cancel(nl80211, info->roc_cmd_id); + info->roc_cmd_id = 0; + + if (!info->needs_cancel) + goto work_done;If the request hasn't started, then indeed invoking
l_genl_family_canceland
destroying the work right away should be fine. If the request has already been
sent, then we are stuck waiting for the ack. You could also assume that ifroc_cmd_idis set, then the command is in flight and setting needs_cancel/waiting for the ack is needed.
Quoted 3 lines
In either case, we should invoke the destroy callback here and clear out the
user data/callbacks.
Yes, I need to only cancel conditionally. I don't see why we need to invoke destroy here though? I would rather keep destroy() in one location, in the work done callback.
Quoted 30 lines
Quoted 7 lines
src/offchannel.c new file +6
-0+ + return; + } + + /* +* Something must have happened in the genl callback. Any Quoted 5 lines
errors there
+ * will be handled already
+ */
+ if (!info->roc_cookie)
+ return;I'm guessing this should be an
L_WARN_ON.src/offchannel.c line 224
Quoted 12 lines
+
+ /*
+ * At this point we know ROC has at least been queued (potentially not
+ * started) and can be cancelled.
+ */
+ offchannel_cancel_roc(info);src/offchannel.c new file +5
-0+ +work_done: + wiphy_radio_work_done(wiphy, id); +} +Regards,
-Denis
Denis Kenzior
Hi James,
Quoted 4 lines
Even with this though I don't see a point of waiting for the ACK since the kernel will send cancel ROC. The ACK callback for this would have no purpose AFAIK.
If you always want to wait for the cancel event, then I would concur. Question is whether the kernel would always guarantee that this is sent. I guess we'll find out :)
Quoted 4 lines
Yes, I need to only cancel conditionally. I don't see why we need to invoke destroy here though? I would rather keep
destroy()in one location, in the work done callback.
Mostly to be nice to the consumer of these methods. They may want to assume that cancel succeeds synchronously and that the destroy method is invoked right away. For example, this may be useful if the destroy method manipulates some data hanging off the main object and the main object is about to be destroyed (hence the cancel call on the ongoing request).
Regards,
-Denis
James Prestwood
Quoted 21 lines · Denis Kenzior
Hi James,
Quoted 6 lines
Even with this though I don't see a point of waiting for the ACK since
the kernel will send cancel ROC. The ACK callback for this would have
no purpose AFAIK.If you always want to wait for the cancel event, then I would concur. Question
is whether the kernel would always guarantee that this is sent. I guess we'll
find out :)Quoted 5 lines
Yes, I need to only cancel conditionally. I don't see why we need to
invoke destroy here though? I would rather keepdestroy()in one location, in the work done callback.
Quoted 9 lines
Mostly to be nice to the consumer of these methods. They may want to assume
that cancel succeeds synchronously and that the destroy method is invoked right
away. For example, this may be useful if the destroy method manipulates some
data hanging off the main object and the main object is about to be destroyed
(hence the cancel call on the ongoing request).
Ok makes sense. I guess in this case we can just call then NULL destroy and all other cases it will still happen in the work done callback. I've already sent v3 but I'll update this in the next round.
Quoted 3 lines
Regards,
-Denis