WiFi Command Line Tool

This topic provides details on using the wifi command line tool to control the Wifi Service.

The wifi command line tool supports both client and access point options.

Also see the wifi command line help:

# wifi help
wifi command line usage
==========

To run Wifi Client:
    wifi client help
To run Wifi Access Point:
    wifi ap help

WiFi Client

The wifi client command line has these options:

The wifi client command line has the following options:

# wifi client help
wifi command line usage
==========

To start using the Wifi Client:
    wifi client start
To stop  using the Wifi Client:
    wifi client stop
To start a scan:
    wifi client scan
To create to a access point and get [REF]:
    wifi client create [SSID]
To connect to a access point set in 'create':
    wifi client connect [REF]
To set security protocol
    wifi client setsecurityproto [REF] [SecuProto]
Values for SecuProto;
    0: No security
    1: Using WEP
    2: Using WPA
    3: Using WPA2
    4: Using WPA Enterprise
    5 :Using WPA2 Enterprise
To disconnect from an access point:
    wifi client disconnect
To delete the access point set in 'create':
    wifi client delete
To set WPA/WPA2 passphrase that generates PSK :
    wifi client setpassphrase [REF] [passphrase]
To set WPA/WPA2 PSK directly:
    wifi client setpsk [REF] [psk]
To set WPA/WPA2 Enterprise user credentials:
    wifi client setusercred [REF] [userName] [password]
To set WEP Key:
    wifi client setwepkey [REF] [WEPKEY]

Client Example

This example shows how a client connects to an open access point with no security

Start the wifi client

>wifi client start

Scan for available access points. Note the references in the response.

>wifi client scan
starting scan
Found:  SSID:   "GustavNet" Strength:-49    Ref:0x10000003
Found:  SSID:   "hotspot"   Strength:-54    Ref:0x10000001
Found:  SSID:   "NEUF_B698" Strength:-71    Ref:0x10000009
Found:  SSID:   "SFR WiFi FON"  Strength:-71    Ref:0x10000007
Found:  SSID:   "SFR WiFi Mobile"   Strength:-71    Ref:0x10000005

Set security preference for accesspoint "hotspot"

>  wifi client setsecurityproto 10000001 0

Connect to hotspot with reference 10000001

>  wifi client connect 10000001

note that IP handling is not handled by the wifi command line tool but here is how it can be done

> /sbin/udhcpc -R -b -i wlan0
udhcpc (v1.22.1) started
Sending discover...
Sending select for 192.168.43.25...
Lease of 192.168.43.25 obtained, lease time 3600
/etc/udhcpc.d/50default: Adding DNS 192.168.43.1

now try your IP connection towards the internet by pinging Googles DNS

> ping 8.8.8.8

WiFi Access Point

The wifi access point command line has the following options:

# wifi ap help
wifi command line Access Point usage
==========

To start the  Wifi Access Point:
    wifi ap start
To stop the  Wifi Access Point:
    wifi ap stop
To set the SSID of the Wifi Access Point:
    wifi ap setssid [SSID]
To set the channel of the Wifi Access Point:
    wifi ap setchannel [ChannelNo]
To set the security protocol used :
    wifi ap setsecurityproto [SecuProto]
Values for SecuProto;
    0: No security
    1: Using WPA2
To set WPA2 passphrase that generates PSK :
    wifi ap setpassphrase  [passphrase]
To set WPA2 PSK directly:
    wifi ap setpsk [PSK]
To setdiscoverablity for the Wifi Access Point:
    wifi ap setdiscoverable
To maximum nbr of clients for the Wifi Access Point:
    wifi ap setmaxclients [MAXNBR]

Access Point Example

This example shows how to setup a open access point WPA2 security.

set the security to none.

> wifi ap setsecurityproto 1

set the pass phrase

> wifi ap setpassphrase  secret123

set the name of the access point

> wifi ap setssid EXAMPLESSID

start the AP

> wifi ap start

DHCP IP handling the wifi service does not handle the DHCP IP handling. To bridge the DHCP server and the modem the following can be done.

> /sbin/ifconfig wlan0 192.168.10.1 up


// Configure the interfaces
// interface du point of access wifi
> export INT_WIFI="wlan0"
// interface wlan or eth0 with internet (or "eth0"
> export INT_NET="rmnet0"

//IP & mask for subnet
> export SUBNET="192.168.10.0/24"
> export IP="192.168.10.1"
> export IP_RANGE_START="192.168.10.10"
> export IP_RANGE_END="192.168.10.20"

// Start rmnet0 with pin 3699
> /mnt/legato/system/bin/cm sim enterpin 3699
> /mnt/legato/system/bin/cm data connect &

// bring up the interface
>/sbin/ifconfig wlan0 $IP up

// DNSMASQ Startup
> /usr/bin/dnsmasq --interface=$INT_WIFI --dhcp-range=$IP_RANGE_START,$IP_RANGE_END,12h -d --bogus-priv&

// Turn on IP forwarding
> echo 1 > /proc/sys/net/ipv4/ip_forward
// load masquerade module
> /proc/sys/kernel/modprobe ipt_MASQUERADE
> /usr/sbin/iptables -A POSTROUTING -t nat -o $INT_NET -j MASQUERADE
> /usr/sbin/iptables -A FORWARD --match state --state RELATED,ESTABLISHED --jump ACCEPT
> /usr/sbin/iptables -A FORWARD -i $INT_WIFI --destination $SUBNET --match state --state NEW --jump ACCEPT
> /usr/sbin/iptables -A INPUT -s $SUBNET --jump ACCEPT