User avatar
realies
Posts: 43
Joined: Fri Jul 18, 2014 9:27 am

wpa_cli set_network as argument failure

Mon Dec 29, 2014 3:12 am

Hello people,

I'm working on a project where I need to be able to control the wireless network connections on a Pi via a web interface and I've found that wpa_supplicant is taking care of that on the Rapsbian distro. I've researched a bit on some blogs and in wpa_cli's manual and found out that adding a basic network configuration should be executed as follows:

Code: Select all

wpa_cli add_network
wpa_cli set_network 0 ssid "MyNetwork"
wpa_cli set_network 0 psk "MyPassword"
The thing is that no matter what I try I can't execute the set_network command as an argument on wpa_cli without having FAIL as a return.
When I try and do it in wpa_cli's interactive mode it returns OK, but whenever I try to config on the command line it returns me a FAIL.

Would there be someone having an idea why is this happening?

User avatar
DougieLawson
Posts: 37742
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: wpa_cli set_network as argument failure

Fri Jan 02, 2015 12:08 pm

It appears to be a bug in the wpa_cli program.

The developer's website says
Any comments, reports on success/failure, ideas for further improvement, feature requests, etc. are welcome at j @ w1.fi. Please note, that I often receive more email than I have time to answer. Unfortunately, some messages may not get a reply, but I'll try to go through my mail whenever time permits.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

User avatar
realies
Posts: 43
Joined: Fri Jul 18, 2014 9:27 am

Re: wpa_cli set_network as argument failure

Fri Jan 02, 2015 2:41 pm

Thanks for the response. I've already written an email to the developer, but I do not expect an answer. I'll probably try to do a workaround with the interactive mode provided.

User avatar
realies
Posts: 43
Joined: Fri Jul 18, 2014 9:27 am

Re: wpa_cli set_network as argument failure

Sun Jan 04, 2015 3:36 pm

Update: using php's proc_open with input/output pointers seems to do the trick with running wpa_cli in interactive mode while setting up the network.

User avatar
realies
Posts: 43
Joined: Fri Jul 18, 2014 9:27 am

Re: wpa_cli set_network as argument failure

Thu Aug 27, 2015 5:03 am

Update: I thought there wasn't a workaround with a single command execution trough the terminal, but apparently I didn't look good enough. Someone from superuser.com has posted how to avoid the FAIL response from wpa_cli with adding additional single quotes around the ones that are expected.

As posted:

Code: Select all

# wpa_cli add_network
4                                          <--- note the network ID!
# wpa_cli set_network 4 ssid '"Your SSID"'
OK
# wpa_cli set_network 4 scan_ssid 1
OK
# wpa_cli set_network 4 key_mgmt WPA-PSK
OK
# wpa_cli set_network 4 psk '"1234567890"' <--- note the single quotes around
OK
# wpa_cli enable_network 4
OK

elenalizina
Posts: 2
Joined: Wed Oct 18, 2017 3:03 pm

Re: wpa_cli set_network as argument failure

Wed Oct 18, 2017 3:15 pm

Hello,
I faced with similar issue and I stuck with it...

I'm developing own NetworkManager for RPi on Qt.
I'm using QProcess for execution wpa_cli commands.
All commands except wpa_cli set_network psk exutes good.
But wpa_cli set_network psk returns FAIL.
I call it like this: wpacliProcess.execute("wpa_cli set_network 0 psk '"12345678"'");
When I paste this command right in console, it returns OK.
Only using QProcess it returns FAIL.
I also tried to use password without quotes or with single quotes or with only double quotes but always get FAIL.

I don't understand what can be wrong here.....

Can anybody explain what happened when I try to execute "wpa_cli set_network 0 psk '"12345678"'" using QProcess.
Why it differs from using console?

My output (executing by QProcess):
wpa_cli remove_network all
OK
Selected interface 'wlan0'

wpa_cli add_network
0
Selected interface 'wlan0'

wpa_cli set_network 0 ssid 4e617461
OK
Selected interface 'wlan0'

wpa_cli set_network 0 key_mgmt WPA-PSK
OK
Selected interface 'wlan0'

wpa_cli set_network 0 psk '"12345678"'
FAIL
Selected interface 'wlan0'

wpa_cli enable_network 0
OK
Selected interface 'wlan0'

wpa_cli select_network 0
OK
Selected interface 'wlan0'

wpa_cli save_config
OK
Selected interface 'wlan0'

wpa_cli reconfigure
OK
Selected interface 'wlan0'

User avatar
realies
Posts: 43
Joined: Fri Jul 18, 2014 9:27 am

Re: wpa_cli set_network as argument failure

Wed Oct 18, 2017 3:26 pm

elenalizina wrote:
Wed Oct 18, 2017 3:15 pm
I call it like this: wpacliProcess.execute("wpa_cli set_network 0 psk '"12345678"'");
It seems that you would need to some escaping of the double quotes within the QProcess statement.

Code: Select all

wpacliProcess.execute("wpa_cli set_network 0 psk '\"12345678\"'");
What about this?

elenalizina
Posts: 2
Joined: Wed Oct 18, 2017 3:03 pm

Re: wpa_cli set_network as argument failure

Fri Oct 20, 2017 8:13 am

Actually I used the next syntax:

Code: Select all

QString cmd = "set_network 0 psk '\"";
cmd.append(pwd + "\"'");
wpacli.execute(cmd);

Return to “Networking and servers”