1

I trigger the scan with following code

struct nl_msg *msg = nlmsg_alloc();
struct nlmsghdr *hdr;
struct genlmsghdr cmd = { .cmd = NL80211_CMD_TRIGGER_SCAN };

struct nl_sock *sock = nl_socket_alloc();

int dev = if_nametoindex("wlan0");
nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev);

hdr = nlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, NLMSG_NOOP, 0, 0);
memcpy(nlmsg_data(hdr), &cmd, sizeof(cmd));
nl_send_auto(sock, msg);

Now, how should i know when scan is finished, and how can i get it? In all places i have been searching so far, there is "You will receive NL80211_CMD_NEW_SCANS notification on "scan" multicast group", How should i subscribe to it? i registered my callback, tried

nl_socket_add_memberships(sock, RTN_MULTICAST);

and after that listen for messages in while with

while (1)
  nl_recvmsgs_default(sock);

but nothing happened, so: if you had enough patience to read up to this point, please help me with 2 questions

1) How do i know when scan is finished(how to subscribe on this notifications, or read them etc.)

2) How can i read messages after notifications received(method as i understand it below)

To read scanned data i need to send message similar to one that triggers scan, but with message NL80211_CMD_GET_SCAN, and after that data will be stored in nl_socket's payload, am i right?

Ikakok
  • 103
  • 1
  • 10

1 Answers1

1

send a NL80211_CMD_TRIGGER_SCAN to start a scan off. (one after another will fail) After sending, then listen out for the scan to complete when you get a NL80211_CMD_NEW_SCAN_RESULTS. a NL80211_CMD_GET_SCAN command to ask for the results. You will get one message back for every station found, so be ready to handle multiple messages.

  • NL80211_CMD_TRIGGER_SCAN to scan off
  • listen to NL80211_CMD_NEW_SCAN_RESULTS
  • NL80211_CMD_GET_SCAN command to ask for the results
  • should get one message back for every station found
Lango
  • 323
  • 5
  • 17