I'm new to OpenWrt. I am using iwinfo lib to scan wifi. It was working fine until I scan multiple time in my code. At first I think it is because of I am doing wrong using this library, so I tried to modified the cli program from iwinfo library and make it scan twice. Here is the main function of the cli code, which will work only once. The print_scanlist function implementation is same it in the cli program.
int main() {
const struct iwinfo_ops *iw = iwinfo_backend("wlan0");
print_scanlist(iw, "wlan0");
print_scanlist(iw, "wlan0");
iwinfo_finish();
return 0;
}
At first I think it was because the hardware does not allowed to scan in short amount of time. But if I run the program second time it still work for the first function. Now I have no idea why is this happenging, does anyone know why?
Since I am using nl80211 as backend, I dug into the source code of iwinfo. I found that it is using WPA supplicant. In the scan function, it called a function name nl80211_get_scanlist_wpactl
and it's purpose is to connect to the WPA supplicant and ask it to scan and get its result.
The steps in iwinfo are
send(sock, "ATTACH", 6, 0);
send(sock, "SCAN", 4, 0);
send(sock, "SCAN_RESULTS", 12, 0);
The problem is iwinfo forgot to call a DETACH therefore the next time you wont able to do anything. So after I add a send(sock, "DETACH", 6, 0)
, I got it to work. Thanks everybody