1

I'm facing an issue where nmcli stops working on a custom rockchip controller.

When running nmcli dev wifi, I get no results so I had to start using iwlist scan. Is there something similar for nmcli d wifi connect?

I keep getting back No network with SSID '2KLIC Guests' found with nmcli.

This is the script I want to replace:

if [ -n "$2" ];then
  nmcli d wifi connect "$1" password "$2"
else
  nmcli d wifi connect "$1"
fi

Or maybe there is a command I can run to fix nmcli (it did return results at one point, seems it had its configurations changed while using AP mode).


Results of iwconfig wlan3:

wlan3     unassociated  Nickname:"<WIFI@REALTEK>"
          Mode:Auto  Frequency=2.412 GHz  Access Point: Not-Associated   
          Sensitivity:0/0  
          Retry:off   RTS thr:off   Fragment thr:off
          Power Management:off
          Link Quality=0/100  Signal level=0 dBm  Noise level=0 dBm
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:0  Invalid misc:0   Missed beacon:0

3 Answers3

3

You can connect through wpa_supplicant command , create a wpa_supplicant.conf file through wpa_passphrase command then connect:

touch /etc/wpa_supplicant/wpa_supplicant.conf
echo ctrl_interface=/run/wpa_supplicant > /etc/wpa_supplicant/wpa_supplicant.conf
echo update_config=1 >> /etc/wpa_supplicant/wpa_supplicant.conf
wpa_passphrase "Your_SSID" Your_PASSWORD >> /etc/wpa_supplicant/wpa_supplicant.conf
i=$(iw dev | grep Interface | awk '{ print $2}')
killall wpa_supplicant
wpa_supplicant -i $i -c/etc/wpa_supplicant/wpa_supplicant.conf -B
dhclient $i

A sample script may contain the following lines:

i=$(iw dev | grep Interface | awk '{ print $2}')
killall wpa_supplicant
wpa_supplicant -i $i -c/etc/wpa_supplicant/wpa_supplicant.conf -B
dhclient $i

The killall wpa_supplicant is added because you are using network-manager , it will create a wpa_supplicant instance.

Also you can connect through wpa_supplicant using a WEP key.

Create a wpa_supplicant.conf manually (wpa_passphrase will not work to generate a conf file) , e,g:

ctrl_interface=/run/wpa_supplicant
update_config=1

network={
    ssid="YOUR-SSID"
    key_mgmt=NONE
    wep_key0="12345"
    wep_tx_keyidx=0
}

Or simply you can connect through :

iwconfig <interface> essid "Your_SSID" key WEP_KEY

or:

iw dev <interface> connect "Your_SSID" key 0:WEP_KEY

The wpa_cli command line tool (recommanded by @dirkt) is also an alternative to nmcli , you can use the interactive mode by typing wpa_cli or directly by:

wpa_cli -p/var/run/wpa_supplicant OPTION

The OPTION can be : scan ; scan_results , add_network 0 ..... see man wpa_cli and wpa_cli --help for more details.

GAD3R
  • 66,769
  • Thanks, I can't test right now but I will asap. I assume this solution will fail on WEP? – Philip Kirkbride Oct 27 '17 at 18:20
  • 2
    Wpa_supplicant support WEP ; WPA and WPA2 – GAD3R Oct 27 '17 at 18:21
  • I have update my answer, a WEP key is supposed weak and unsecured – GAD3R Oct 27 '17 at 18:48
  • 1
    In addition, it's also possible to use wpa_cli to add networks from the command line or in a script if this is more convenient than making a configuration file. wpa_cli help lists the commands (more than mentioned in the documentation). – dirkt Oct 27 '17 at 20:59
  • It's my first time getting a chance to test but I'm at Starbucks so I can only test with no password. Here is the result of the script https://pastebin.com/9Z2E5VTK I disconnect but never get running. Is it possible I need to add a line to stop any previous instances of wpa_supplicant before starting? – Philip Kirkbride Oct 28 '17 at 12:33
  • @PhilipKirkbride rm /run/wpa_supplicant/wlo1 then killall wpa_supplicant as the ouptut error say . What is the content of connect.sh script? – GAD3R Oct 28 '17 at 12:37
  • I will try that connect.sh is the first code block in your answer. – Philip Kirkbride Oct 28 '17 at 12:40
  • To use an open network , write the configuration manully and remove the tow lines wep_key0 and wep_tx_keyidx following the wpa_supplicant.conf on my answer – GAD3R Oct 28 '17 at 12:48
  • I'm having an issue with the step i=$(iw dev | grep Interface | awk '{ print $2}') because when I run sudo iw dev I get no output. – Philip Kirkbride Oct 30 '17 at 13:37
  • What is the expected output of iw dev maybe I can get it somewhere else. – Philip Kirkbride Oct 30 '17 at 13:54
  • @PhilipKirkbride How many wifi interfaces did you have? – GAD3R Oct 30 '17 at 14:29
  • 1
    @GAD3R just one, I found people on Pi having a similar issue using iw https://raspberrypi.stackexchange.com/questions/39601/make-iw-work-on-raspbian I can use iwlist but not iw for some reason. Opened another question related https://unix.stackexchange.com/questions/401413/iw-dev-interface-scan-not-working-on-embedded-device – Philip Kirkbride Oct 30 '17 at 14:31
  • @GAD3R what should the result of i=$(iw dev | grep Interface | awk '{ print $2}') be? I'm going to see if I can find another way around it. – Philip Kirkbride Oct 30 '17 at 15:34
  • it should return : wlan3 – GAD3R Oct 30 '17 at 15:38
  • @GAD3R I was able to replace it with this i=$(ifconfig -a | grep wl | cut -d' ' -f1) going to try again. – Philip Kirkbride Oct 30 '17 at 15:50
  • @GAD3R running sudo wpa_supplicant -i wlan3 -c/etc/wpa_supplicant/wpa_supplicant.conf -B returns Successfully initialized wpa_supplicant and wlan3: Failed to initialize driver interface – Philip Kirkbride Oct 30 '17 at 15:53
1

I ended up replacing my script with this. Seems to work on my system and keeps the original structure.

wifi=$(cat /proc/net/wireless | perl -ne '/(\w+):/ && print $1')

if [ -n "$2" ];then
  iwconfig $wifi essid "$1" key "s:$2"
else
  iwconfig $wifi essid "$1" key
fi

dhclient $wifi
  • 2
    This will not work for WPA, only for WEP. I strongly recommend against using WEP, it's broken. – dirkt Nov 15 '17 at 16:29
  • WEP is broken as in "people will break the password and look at your traffic or use your AP" – A.B Mar 17 '19 at 16:32
0

You can use Wicd, it has a command line and GUI interface for managing your wifi networking. I have used it for a while, as a lightweight alternative to NM. It will save you of having to deal with wpa_supplicant manually.

Rolf
  • 759
  • 2
  • 8
  • 16