OpenWrt Forum Archive

Topic: Command line connect to the external AP (my router is in "sta") ?

The content of this topic has been archived on 23 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

I use custom build of Openwrt AA with NO gui on TP-Link wr-743ND.
In order to connect to an external AP, I usually edit /etc/config/wireless to add/comment new ssid, encryption, and password lines.

Instead, I'd like to write a script, to connect preconfigured AP, WITHOUT rewriting the config. So I need to connect to the external AP using command line.

Since I do not have experience on Linux, I can't figure how to accomplish this.
So far, I can only try to

1. create a file for specific external AP,like
network={
        ssid="ESSID_AP_NAME"
        psk="WPA_PASS"
}


2. invoke wpa_suppicant, like
wpa_supplicant -B -iwlan0 -c/tmp/ap_specific_file -Dnl80211
the above will effectively make my router to connect(authenticate, authorize) to external AP, but without actual IP connectivity:
ping 8.8.8.8
FAILS


3. the only clue, i have,is to invoke netifd , which can actually resolve connectivity issue, but this command hangs...
--
SO PLEASE give me further instructions.

AlekXL wrote:

WITHOUT rewriting the config.

Rewrite the config WITHOUT issuing a "uci commit".
The new config will take effect immediately issuing some restart/reload of the involved services.

Nilfred wrote:
AlekXL wrote:

WITHOUT rewriting the config.

Rewrite the config WITHOUT issuing a "uci commit".
The new config will take effect immediately issuing some restart/reload of the involved services.

such config still uses FLASH memory write resource, I presume. So this is not an option.

currently, I've managed to do make the system to the WPA/WPA2 AP like this:
killall  -2 wpa_supplicant; wpa_supplicant -B -iwlan0 -Dnl80211 -c/root/AP_CONFIG_FILE; killall -2  udhcpc; udhcpc  -t 0 -i wlan0 -b

But I still have no idea how to connect OPEN (no-encrytion) OR WEP-encrypted AP

AlekXL wrote:
Nilfred wrote:
AlekXL wrote:

WITHOUT rewriting the config.

Rewrite the config WITHOUT issuing a "uci commit".
The new config will take effect immediately issuing some restart/reload of the involved services.

such config still uses FLASH memory write resource, I presume. So this is not an option.

The configuration is only saved in RAM, it does not write anything to flash.

snk wrote:

The configuration is only saved in RAM, it does not write anything to flash.

so what command exactly should I write to connect an ap with NO flash write?

because when I edit
vi /etc/config/wireless
it is almost certainly scratch the flash.


added:
if I am currently connected to the ap 'A',  issuing
uci set wireless.ssid=B
uci set wireless.encryption=none

DOES NOT force to connect ap 'B'. issuing

wifi down;wifi

DOES NOT do this the as well

(Last edited by AlekXL on 7 Apr 2014, 20:34)

uci show wireless

should give you some hints on how to use uci..

also this:

http://wiki.openwrt.org/doc/uci

(Last edited by nebbia88 on 7 Apr 2014, 20:58)

This is what I use without writing to flash to connect to AP.


#!/bin/sh

### assuming your wlan is wlan1

file="/var/run/wpa_supplicant-wlan1.conf"
    printf "ssid "
    read sid
    printf "bssid Mac "
    read bsid
    printf "Key "
    read key
    if [ "$key" != "" ]; then
        printf "Type wp(a) / w(e)p "
        read ty
    fi
    printf "Mac "
    read mac
           
    echo "ctrl_interface=/var/run/wpa_supplicant-wlan1" > $file
    echo "network={" >> $file
    echo "scan_ssid=1" >> $file
    echo "ssid=\"$sid\"" >> $file
    if [ "$bsid" != "" ]; then
        echo "bssid=$bsid" >> $file
    fi
    if [ "$key" = "" ]; then
        echo "key_mgmt=NONE" >> $file
    elif [ "$ty" = "a" ]; then
        echo "key_mgmt=WPA-PSK" >> $file
        echo "proto=RSN" >> $file
        echo "psk=\"$key\"" >> $file
    elif [ "$ty" = "e" ]; then
        echo "key_mgmt=NONE" >> $file
        echo "wep_key0=$key" >> $file
        echo "wep_tx_keyidx=0" >> $file
    fi
    echo "}" >> $file
                                       
    kill $(cat /var/run/wifi-wlan1.pid)
   
    wpa_supplicant -B -P /var/run/wifi-wlan1.pid -D nl80211 -i wlan1 -c /var/run/wpa_supplicant-wlan1.conf
    sleep 1
    kill $(cat /var/run/udhcpc-wlan1.pid)
    cat $file

AlekXL wrote:
snk wrote:

The configuration is only saved in RAM, it does not write anything to flash.

so what command exactly should I write to connect an ap with NO flash write?

because when I edit
vi /etc/config/wireless
it is almost certainly scratch the flash.

LOL lol

AlekXL wrote:

if I am currently connected to the ap 'A',  issuing
uci set wireless.ssid=B
uci set wireless.encryption=none

DOES NOT force to connect ap 'B'. issuing

wifi down;wifi

DOES NOT do this the as well

Your UCI commands to edit the config looks good, but try this to reload:

ubus call network reload   # tells netifd to reload just the network config
/etc/init.d/network reload # restarts wifi as well

The discussion might have continued from here.