2010-08-20 23:42:56

by Christopher Piggott

[permalink] [raw]
Subject: Fwd: nl80211 scanning from userspace

I'm sorry ... I hit REPLY again to Johannes personally rather than to
the list. I don't know what it is about this list server that makes
me do it ... maybe there's no Reply-To.

Here was my followup question:


---------- Forwarded message ----------



I have another question about netlink scanning. ?Here is what I am
doing. ?First, trigger a request to starts canning:

? ?type = genl_family_get_id(nl80211);
? ?cmd = NL80211_CMD_TRIGGER_SCAN;
? ?flags = 0;
? ?pid = 0;
? ?(void) genlmsg_put(msg, pid, seqSent, type, 0, flags, cmd, 0);
? ?int dev = if_nametoindex("wlan0");
? ?nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev);
? ?rc = nl_send_auto_complete(sock, msg);


Wait a little while, and I get back a valid message that indicates the
scan is complete. ?I handle that here:

bool try_parse_scan_status(struct nl_msg *msg) {
? ?struct genlmsghdr *genMsgHeader = (struct genlmsghdr *) nlmsg_data(header);

? ?/* check to make sure it's the right interface. ?That works so
I'll leave that code out */
? ?switch (genMsgHeader->cmd) {
? ? ? ?case NL80211_CMD_NEW_SCAN_RESULTS:
? ? ? ? ? ?if (debug) {
? ? ? ? ? ? ? ?cerr << "New scan results available" << endl;
? ? ? ? ? ?}
? ? ? ? ? ?nl_msg_dump(msg, stdout);
? ? ? ? ? ?trigger_fetch_scan_results();
? ? ? ? ? ?break;
? ? ? ?/* other stuff deleted */
}

OK so here's what happens. ?I get the message back indicating the scan
is complete, yay! ?Then I try to call my trigger_fetch_scan_results().
?What that method does is sends command NL80211_CMD_GET_SCAN on that
interface, with the flag NLM_F_DUMP. ?Great!

The problem is, I get a message back whose genMsgHeader->cmd STILL
says "NL80211_CMD_NEW_SCAN_RESULTS." ?The resulting packet has good
stuff in it (the ssid, etc. info I am looking for). ?UNFORTUNATELY,
because of the way I wrote my code it triggers another scan, which
causes it to say "Device or resource busy" and it just loops.


So here's the question: in my NL_CB_VALID listener, how do I
distinguish the response to the NL80211_CMD_TRIGGER_SCAN (the one that
indicates scan complete) from the response to the CMD_GET_SCAN (fetch
the results) message?

--Chris


2010-08-21 09:21:51

by Johannes Berg

[permalink] [raw]
Subject: Re: Fwd: nl80211 scanning from userspace

On Fri, 2010-08-20 at 19:42 -0400, Christopher Piggott wrote:

> So here's the question: in my NL_CB_VALID listener, how do I
> distinguish the response to the NL80211_CMD_TRIGGER_SCAN (the one that
> indicates scan complete) from the response to the CMD_GET_SCAN (fetch
> the results) message?

One will be unicast to you, and the event is multicast to everybody. You
should be able to tell the difference.

johannes


2010-08-22 19:49:10

by Christopher Piggott

[permalink] [raw]
Subject: Re: Fwd: nl80211 scanning from userspace

> One will be unicast to you, and the event is multicast to everybody. You
> should be able to tell the difference.

Oh, right ... or, is there some kind of "message source address" that
I can get to? The only thing I have been able to figure out so far is
that the messages coming from the second message (multicast) seem to
have a PID of 0... maybe if I make sure mine is set to something else
I can tell that way.