TS-4900 yocto wifi: Difference between revisions

From embeddedTS Manuals
(Created page with "The Yocto distribution includes hostapd which is running by default, so it must first be disabled to use it as a client. <source lang=bash> update-rc.d -f hostapd remove reboo...")
 
No edit summary
 
(9 intermediate revisions by 2 users not shown)
Line 1: Line 1:
The Yocto distribution includes hostapd which is running by default, so it must first be disabled to use it as a client.
Yocto uses systemd to start wpa_supplicant, and systemd-networkd to set an IP address via a static setting or DHCP.
<source lang=bash>
update-rc.d -f hostapd remove
reboot
</source>
 
Once the system boots back up you will have a "wlan0" device in managed mode.


''' Scan for a network '''
''' Scan for a network '''
Line 12: Line 6:


# Scan for available networks
# Scan for available networks
iwlist wlan0 scan
iw wlan0 scan
</source>
</source>


In this case I'm connecting to "default" which is an open network:
An example of connecting to an open network with an SSID of "default":
<pre style="font-family:monospace,Courier New ;background:black; width:18cm; white-space: pre-wrap; white-space: -moz-pre-wrap; word-wrap: break-word; color:white; ">
<console>
          Cell 03 - Address: c0:ff:ee:c0:ff:ee
BSS c0:ff:ee:c0:ff:ee(on wlan0)
                    Mode:Managed
        TSF: 848750528860 usec (9d, 19:45:50)
                    ESSID:"default"
        freq: 2462
                    Channel:2
        beacon interval: 100 TUs
                    Encryption key:off
        capability: ESS Privacy ShortPreamble ShortSlotTime RadioMeasure (0x1431)
                    Bit Rates:9 Mb/s
        signal: -69.00 dBm
</pre>
        last seen: 3253 ms ago
        Information elements from Probe Response frame:
        SSID: default
        Supported rates: 1.0* 2.0* 5.5* 11.0* 6.0* 9.0 12.0* 18.0
        DS Parameter set: channel 11
        Country: US    Environment: Indoor/Outdoor
                Channels [1 - 11] @ 30 dBm
</console>


To connect to this open network:
To connect to this open network manually for just this boot:
<source lang=bash>
<source lang=bash>
iwconfig wlan0 essid "default"
iw wlan0 connect "default"
</source>
</source>


You can use the iwconfig command to determine if you have authenticated to an access point.  Before connecting it will show something similar to this:
If connecting using WEP, also specify a network key:
<pre style="font-family:monospace,Courier New ;background:black; width:18cm; white-space: pre-wrap; white-space: -moz-pre-wrap; word-wrap: break-word; color:white; ">
<source lang=bash>
# iwconfig wlan0
iw wlan0 connect "default" keys 0:abcde d:1:0011223344
wlan0    IEEE 802.11bgn  ESSID:"default"
</source>
          Mode:Managed  Frequency:2.417 GHz  Access Point: c0:ff:ee:c0:ff:ee 
          Bit Rate=1 Mb/s  Tx-Power=20 dBm 
          Retry  long limit:7  RTS thr:off  Fragment thr:off
          Encryption key:off
          Power Management:off
          Link Quality=70/70  Signal level=-34 dBm 
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:0  Invalid misc:0  Missed beacon:0
</pre>


If you are connecting using WEP, you will need to define a network key:
If connecting to a WPA network use <source lang=bash inline>wpa_passphrase</source> and <source lang=bash inline>wpa_supplicant</source>:
<source lang=bash>
<source lang=bash>
iwconfig wlan0 essid "default" key "yourpassword"
mkdir /etc/wpa_supplicant/
wpa_passphrase "ssid name" "full passphrase" >> /etc/wpa_supplicant/wpa_supplicant-wlan0.conf
</source>
</source>


If you are connecting to WPA you will need to use wpa_passphrase and wpa_supplicant:
After generating the configuration file the <source lang=bash inline>wpa_supplicant</source> daemon can be started.
<source lang=bash>
<source lang=bash>
wpa_passphrase the_essid the_password >> /etc/wpa_supplicant.conf
wpa_supplicant -iwlan0 -c/etc/wpa_supplicant/wpa_supplicant-wlan0.conf -B
</source>
</source>


Now that you have the configuration file, you will need to restart the wpa_supplicant daemon:
This will return output similar to:
  Successfully initialized wpa_supplicant
  root@ts-imx6-q:~# dmesg
  ...
  [  306.924691] wlan0: authenticate with c0:ff:ee:c0:ff:ee
  [  306.959415] wlan0: send auth to c0:ff:ee:c0:ff:ee (try 1/3)
  [  306.968137] wlan0: authenticated
  [  306.978477] wlan0: associate with c0:ff:ee:c0:ff:ee (try 1/3)
  [  306.988577] wlan0: RX AssocResp from c0:ff:ee:c0:ff:ee (capab=0x1431 status=0 aid=9)
  [  307.009751] wlan0: associated
  [  307.012768] IPv6: ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready
  [  307.047989] wlcore: Association completed.
 
Use <source lang=bash inline>iw wlan0 info</source> and <source lang=bash inline>iw wlan0 station dump</source> to verify the connection. This will also report the link quality to the AP.
 
Wireless may be associated, but this does not get an IP on the network.  To connect to the internet or talk to the internal network first configure the interface.  See [[#Configuring the Network|configuring the network]], but on many networks only a DHCP client is needed:
<source lang=bash>
<source lang=bash>
ifdown wlan0 && ifup wlan0
udhcpc -i wlan0
</source>
</source>
The wpa_supplicant is started on ifup and /etc/network/interfaces includes the configuration to automatically use dhcp. It must be changed to automatically bring up the interface on startup:
 
Systemd can also be configured to start wpa_supplicant on boot up.
<source lang=bash>
<source lang=bash>
# Wireless interfaces
# Assuming the same path for the wpa conf file as shown above
auto wlan0 # this needs to be added to automatically ifup the interface
systemctl enable wpa_supplicant@wlan0
iface wlan0 inet dhcp
systemctl start wpa_supplicant@wlan0
        wireless_mode managed
</source>
        wireless_essid any
 
        wpa-driver wext
Once this service is started it will bring up the wlan0 link and associate it to the SSID that is noted in the <source lang=bash inline>wpa_supplicant.conf</source> file.  Configure the IP settings the same way as a wired network.
        wpa-conf /etc/wpa_supplicant.conf
 
In <source lang=bash inline>/etc/systemd/network/wlan0.network</source>
<source lang=ini>
[Match]
Name=wlan0


## If you are using a static ip instead:
[Network]
#iface wlan0 inet static
DHCP=yes
#        wireless_mode managed
#        wireless_essid any
#        wpa-driver wext
#        wpa-conf /etc/wpa_supplicant.conf
#        address 192.168.0.50
#        netmask 255.255.255.0
#        gateway 192.168.0.1
</source>
</source>
For a static configuration of IP, the following format may be used:
<source lang=ini>
[Match]
Name=wlan0
[Network]
Address=192.168.0.50/24
Gateway=192.168.0.1
DNS=192.168.0.1
</source>
For more information on what options are available to configure the network, see the [http://www.freedesktop.org/software/systemd/man/systemd.network.html systemd network documentation].

Latest revision as of 16:37, 7 January 2021

Yocto uses systemd to start wpa_supplicant, and systemd-networkd to set an IP address via a static setting or DHCP.

Scan for a network

ifconfig wlan0 up

# Scan for available networks
iw wlan0 scan

An example of connecting to an open network with an SSID of "default":

BSS c0:ff:ee:c0:ff:ee(on wlan0)
        TSF: 848750528860 usec (9d, 19:45:50)
        freq: 2462
        beacon interval: 100 TUs
        capability: ESS Privacy ShortPreamble ShortSlotTime RadioMeasure (0x1431)
        signal: -69.00 dBm
        last seen: 3253 ms ago
        Information elements from Probe Response frame:
        SSID: default
        Supported rates: 1.0* 2.0* 5.5* 11.0* 6.0* 9.0 12.0* 18.0 
        DS Parameter set: channel 11
        Country: US     Environment: Indoor/Outdoor
                Channels [1 - 11] @ 30 dBm

To connect to this open network manually for just this boot:

iw wlan0 connect "default"

If connecting using WEP, also specify a network key:

iw wlan0 connect "default" keys 0:abcde d:1:0011223344

If connecting to a WPA network use wpa_passphrase and wpa_supplicant:

mkdir /etc/wpa_supplicant/
wpa_passphrase "ssid name" "full passphrase" >> /etc/wpa_supplicant/wpa_supplicant-wlan0.conf

After generating the configuration file the wpa_supplicant daemon can be started.

wpa_supplicant -iwlan0 -c/etc/wpa_supplicant/wpa_supplicant-wlan0.conf -B

This will return output similar to:

 Successfully initialized wpa_supplicant
 root@ts-imx6-q:~# dmesg
 ...
 [  306.924691] wlan0: authenticate with c0:ff:ee:c0:ff:ee
 [  306.959415] wlan0: send auth to c0:ff:ee:c0:ff:ee (try 1/3)
 [  306.968137] wlan0: authenticated
 [  306.978477] wlan0: associate with c0:ff:ee:c0:ff:ee (try 1/3)
 [  306.988577] wlan0: RX AssocResp from c0:ff:ee:c0:ff:ee (capab=0x1431 status=0 aid=9)
 [  307.009751] wlan0: associated
 [  307.012768] IPv6: ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready
 [  307.047989] wlcore: Association completed.

Use iw wlan0 info and iw wlan0 station dump to verify the connection. This will also report the link quality to the AP.

Wireless may be associated, but this does not get an IP on the network. To connect to the internet or talk to the internal network first configure the interface. See configuring the network, but on many networks only a DHCP client is needed:

udhcpc -i wlan0

Systemd can also be configured to start wpa_supplicant on boot up.

# Assuming the same path for the wpa conf file as shown above
systemctl enable wpa_supplicant@wlan0
systemctl start wpa_supplicant@wlan0

Once this service is started it will bring up the wlan0 link and associate it to the SSID that is noted in the wpa_supplicant.conf file. Configure the IP settings the same way as a wired network.

In /etc/systemd/network/wlan0.network

[Match]
Name=wlan0

[Network]
DHCP=yes

For a static configuration of IP, the following format may be used:

[Match]
Name=wlan0

[Network]
Address=192.168.0.50/24
Gateway=192.168.0.1
DNS=192.168.0.1

For more information on what options are available to configure the network, see the systemd network documentation.