How to configure hostapd.conf for wps push button?
Solution 1
Funny coincidence. I was looking for this, too, today for Debian. Currently I'm following:
http://ftp.netbsd.org/pub/NetBSD/NetBSD-current/src/external/bsd/wpa/dist/hostapd/README-WPS and a bit of https://w1.fi/cgit/hostap/plain/hostapd/hostapd.conf
I just needed to copy these lines:
wpa_psk_file=/home/<username>/etc/hostapd/hostapd.psk
ctrl_interface=/var/run/hostapd
eap_server=1
wps_state=2
ap_setup_locked=1
wps_pin_requests=/var/run/hostapd.pin-req
device_name=USB2.0 WLAN
manufacturer=ATHEROS
model_name=WAP
model_number=123
serial_number=12345
device_type=6-0050F204-1
os_version=01020300
config_methods=label display push_button keypad
into my hostapd.conf
file. I created a custom one for myself in ~/etc/hostapd.conf
, but normally there is one in /etc/hostapd/hostapd.conf
.
In your case you might have to change device_type
. I tried to mostly verify the information like manufacturer, ... but I don't think they are that important. I was able to find manufacturer
and serial number
using lsusb
and then sudo lsusb -v -s 5:7
(the numbers after -s
are the bus and device numbers shown by lsusb
)
After that I restarted hostapd
with the new configuration file:
sudo pkill hostapd
sudo bash -c "nohup hostapd '$HOME/etc/hostapd/hostapd.conf' > '$HOME/nohupHostapd.out'" &
and did a quick sudo hostapd_cli wps_pbc
and then was able to connect the printer using WPS.
Solution 2
Needs to add the string (wps_state, eap_server) in the following files,
system/netd/server/SoftapController.cpp
int SoftapController::setSoftap(int argc, char *argv[]) {
int hidden = 0;
int channel = AP_CHANNEL_DEFAULT;
int wps_state = 2;
if (argc < 5) {
ALOGE("Softap set is missing arguments. Please use:");
ALOGE("softap <wlan iface> <SSID> <hidden/broadcast> <channel> <wpa2?-psk|open> <passphrase>");
return ResponseCode: : CommandSyntaxError;
}
if (!strcasecmp(argv[4], "hidden"))
hidden = 1;
if (argc >= 5) {
channel = atoi(argv[5]);
if (channel <= 0)
channel = AP_CHANNEL_DEFAULT;
}
std::string wbuf(StringPrintf("interface=%s\n"
"driver=nl80211\n"
"ctrl_interface=/data/misc/wifi/hostapd\n"
"ssid=%s\n"
"channel=%d\n"
"ieee80211n=1\n"
"hw_mode=%c\n"
"ignore_broadcast_ssid=%d, eap_server = 1, wps_state = %d\n",
argv[2], argv[3], channel, (channel <= 14) ? 'g' : 'a', hidden,wps_state));
std::string fbuf;
if (argc > 7) {
char psk_str[2*SHA256_DIGEST_LENGTH+1];
if (!strcmp(argv[6], "wpa-psk")) {
if (!generatePsk(argv[3], argv[7], psk_str)) {
return ResponseCode: : OperationFailed;
}
fbuf = StringPrintf("%swpa=3\nwpa_pairwise=TKIP CCMP\nwpa_psk=%s\n", wbuf.c_str(), psk_str);
} else if (!strcmp(argv[6], "wpa2-psk")) {
if (!generatePsk(argv[3], argv[7], psk_str)) {
return ResponseCode: : OperationFailed;
}
fbuf = StringPrintf("%swpa=2\nrsn_pairwise=CCMP\nwpa_psk=%s\n", wbuf.c_str(), psk_str);
} else if (!strcmp(argv[6], "open")) {
fbuf = wbuf;
}
} else if (argc > 6) {
if (!strcmp(argv[6], "open")) {
fbuf = wbuf;
}
} else {
fbuf = wbuf;
}
if (!WriteStringToFile(fbuf, HOSTAPD_CONF_FILE, 0660, AID_SYSTEM, AID_WIFI)) {
ALOGE("Cannot write to \"%s\": %s", HOSTAPD_CONF_FILE, strerror(errno));
return ResponseCode::OperationFailed;
} else {
return ResponseCode::SoftapStatusResult;
}
Testing,
hostapd_cli wps_pbc
Related videos on Youtube
VINOTHKUMAR S
Updated on September 18, 2022Comments
-
VINOTHKUMAR S over 1 year
I have android6.0.1 I want to enable the wps when hotspot on.
Can anyone give some ideas and give whatever changes i want to do in someother files.?
Can anyone provide any application for wps server.?
Thanks, VinothS,
-
VINOTHKUMAR S almost 7 yearsHi Thank you for your reply. I have the doubt now. I can not find "var/run" this one default or created automatically. And which wifi module are used? I am using wl1831. Thanks, VinothS,
-
VINOTHKUMAR S almost 7 yearsWhen i try i got error like that root@sabresd_6dq:/ # hostapd_cli wps_pbc Failed to connect to hostapd - wpa_ctrl_open: No such file or directory Can you provide some ideas.? Thanks, VinothS,
-
mxmlnkn almost 7 years
/var/run/hostapd
is created automatically. The error messageFailed to connect to hostapd
should only happen if you forgot the linectrl_interface=/var/run/hostapd
or if you apply the changes by restarting hostapd, see also here Note that I didn't need to addctrl_interface_group=0
like the answers writes. If/var/run/
itself is missing, then I can't really help.Must be an android problem then. Try creating it with mkdir... -
VINOTHKUMAR S almost 7 yearsHi thank you for your reply, I try everything.But, i got error root@sabresd_6dq:/system/etc/wifi # start hostapd init: Starting service 'hostapd'... root@sabresd_6dq:/system/etc/wifi # init: Service 'hostapd' (pid 2276) exited with status 1 hostapd_cli wps_pbc Failed to connect to hostapd - wpa_ctrl_open: No such file or directory Help me and give some more suggestion. Thanks, VinothS,
-
alex almost 7 yearsHaving the same issue, actually. I'm on Ubuntu 16.04, will try to mkdir it, maybe that'll take care of the issue.
-
mxmlnkn almost 7 yearsIt is very hard to debug over the internet. My guess is, that both of you aren't doing this on your router. I have a WLAN-stick for my PC which I use to make a hotspot with which my printer then connects. I.e. it is directly connected to my PC where I configure hostapd. "failed to connect" means most likely hostapd isn't running or was configured wrong or even with the wrong config-file. E.g. check with
ps aux | grep hostapd
. I don't know how you start hostapd, but I do withsudo pkill hostapd
andsudo bash -c "nohup hostapd '$HOME/etc/hostapd/hostapd.conf' > '$HOME/nohupHostapd.out'" &
-
VINOTHKUMAR S almost 7 yearsHi, are you try in Linux.? or Android.? Why because i was tried in Android.? May be it's work or possible in Linux. But, not sure at Android.
-
mxmlnkn almost 7 yearsI'm using Linux. Android uses the Linux kernel and many Linux programs like hostapd, but there still might be differences, yes. I can't really test it on mine, because I haven't rooted my smartphone.
-
VINOTHKUMAR S almost 7 yearsHi mxmlnkn. I already have rooted phone. Do you know any possible to work in android?. And what are the important things when i try this one. I want some configuration file related to this like android.conf and hostapd.conf. and are you configured dhcpcd.conf file. and which wifi-chip you are used?
-
mxmlnkn almost 7 yearsI'm sorry, I can't help anymore. My android skills are basically none. Stackoverflow also isn't suited for many follow-up questions. You might be better off asking in an Android forum or wait for another answer to your question if my answer isn't working for you.
-
VINOTHKUMAR S almost 7 yearsHi thank you for your reply. i want to what are the configuration you enabled or added with hostapd.conf and android.conf. and which wifi chip are you used.? Thanks,