wifi

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.

Usage

# 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 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 set whether the access point is hidden or not:
    wifi client hiddenap [REF] [state]
Values for state;
    0: SSID of AP is discoverable
    1: SSID of AP is hidden
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
IP handling is not handled by the wifi command line tool but can be done using the following commands:
# /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 Google's 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 set the discoverablity of the WiFi access point:
    wifi ap setdiscoverable

To maximum nbr of clients for the WiFi access point:
    wifi ap setmaxclients [MAXNBR]

To define the address of the AP and the IP addresses range as well:
WARNING: Only IPv4 addresses are supported.
    wifi ap setiprange [IP AP] [IP START] [IP STOP]

Access Point Example

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

Bring up the access point

Set the security to WPA2:

# wifi ap setsecurityproto 1

Set the passphrase:

# wifi ap setpassphrase secret123

Set the name of the access point:

# wifi ap setssid EXAMPLESSID

Start the access point:

# wifi ap start
Warning
The WiFi service does not take care of the IP management, so the WiFi network interface would not have any IP at this point.
To associate an IP, you can do the following:
# /sbin/ifconfig wlan0 192.168.10.1

Provide a DHCP server

Configure the interfaces:

  • interface of the WiFi access point (LAN - Local Area Network)
  • interface WAN: "rmnet0" or "eth0" (WAN - Wide Area Network)
    # export ITF_LAN="wlan0"
    # export ITF_WAN="rmnet0"
    
Note
On wp76xx, the ITF_WAN variable should be set to "rmnet_data0".

Select 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"

Unlock the SIM and start the data connection:

# /mnt/legato/system/bin/cm sim enterpin 3699
# /mnt/legato/system/bin/cm data connect &

Bring up the WiFi interface:

# /sbin/ifconfig $ITF_LAN $IP up

Start dnsmasq as a DHCP server:

# /usr/bin/dnsmasq --interface=${ITF_LAN} --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 the iptables masquerade module that will take care of the network address translation (NAT):

# /sbin/modprobe ipt_MASQUERADE

Configure the iptables to let your LAN (WiFi) access your WAN (cellular):

# /usr/sbin/iptables -I POSTROUTING -t nat -o ${ITF_WAN} -j MASQUERADE
# /usr/sbin/iptables -I FORWARD --match state --state RELATED,ESTABLISHED --jump ACCEPT
# /usr/sbin/iptables -I FORWARD -i ${ITF_LAN} --destination ${SUBNET} --match state --state NEW --jump ACCEPT
# /usr/sbin/iptables -I INPUT -s ${SUBNET} --jump ACCEPT
# /usr/sbin/iptables -I FORWARD -i ${ITF_WAN} --jump ACCEPT
# /usr/sbin/iptables -I FORWARD -o ${ITF_WAN} --jump ACCEPT
Note
If a DROP policy is set on FORWARD chain, it is mandatory to use the option -I to insert the rules at the beginning of the table.