『循名責實』談何容易?比方說
root@LEDE:~# cat /etc/config/wireless
config wifi-device ‘radio0‘
option type ‘mac80211’
option channel ’11’
option hwmode ’11g’
option path ‘platform/soc/3f300000.mmc/mmc_host/mmc1/mmc1:0001/mmc1:0001:1’
option htmode ‘HT20’
option disabled ‘0’
config wifi-iface ‘default_radio0’
option device ‘radio0‘
option network ‘lan’
option mode ‘ap’
option ssid ‘LEDE-RPI-3B’
option encryption ‘psk2+ccmp’
option key ‘12345678’
分明沒有定義 wlan0 !那麼它打哪來的呢??
root@LEDE:~# ifconfig br-lan Link encap:Ethernet HWaddr B8:27:EB:97:E5:3B inet addr:5.168.166.88 Bcast:5.168.166.255 Mask:255.255.255.0 inet6 addr: fe80::ba27:ebff:fe97:e53b/64 Scope:Link inet6 addr: fd42:80c5:b618::1/60 Scope:Global UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:50 errors:0 dropped:0 overruns:0 frame:0 TX packets:29 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:7070 (6.9 KiB) TX bytes:4688 (4.5 KiB) br-wan Link encap:Ethernet HWaddr B8:27:EB:C2:B0:6E inet addr:5.168.168.9 Bcast:5.168.168.255 Mask:255.255.255.0 inet6 addr: fe80::ba27:ebff:fec2:b06e/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:5531 errors:0 dropped:2067 overruns:0 frame:0 TX packets:2641 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:898901 (877.8 KiB) TX bytes:598999 (584.9 KiB) eth0 Link encap:Ethernet HWaddr B8:27:EB:C2:B0:6E UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:5531 errors:0 dropped:0 overruns:0 frame:0 TX packets:2641 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:898901 (877.8 KiB) TX bytes:630039 (615.2 KiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:76 errors:0 dropped:0 overruns:0 frame:0 TX packets:76 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1 RX bytes:7379 (7.2 KiB) TX bytes:7379 (7.2 KiB) wlan0 Link encap:Ethernet HWaddr B8:27:EB:97:E5:3B inet6 addr: fe80::ba27:ebff:fe97:e53b/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:50 errors:0 dropped:0 overruns:0 frame:0 TX packets:83 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:7070 (6.9 KiB) TX bytes:15160 (14.8 KiB)
處於科技快速變化之時代,文獻新舊駁雜,傳統與現在正交替︰
Linux Network Interfaces
Types of network interfaces
The Linux kernel universally distinguishes between two types of software network interfaces:
Physical Network Interfaces
eth0
, eth8
, radio0
, wlan19
, .. always represent an actual network hardware device such as a NIC, WNIC or some other kind of Modem. As soon as the device driver is loaded into the Kernel a corresponding physical network interface becomes present and available.
Any physical network interface is a named software representation by the operating system to the user to enable him to configure the hardware network device and also to integrate it into programs and scripts.
Virtual Network Interfaces
lo
, eth0:1
, eth0.1
, vlan2
, br0
, pppoe-dsl
, gre0
, sit0
tun0
, imq0
, teql0
, .. are virtual network interfaces that do NOT represent an existent hardware device but are linked to one (otherwise they would be useless). Virtual network interfaces were invented to give the system administrator maximum flexibility when configuring a Linux-based operating system. A virtual network interface is generally associated with a physical network interface (eth6) or another virtual interface (eth6.9) or be stand alone such as the loopback interface lo
.
Types of Virtual Network Interfaces
-
aliases:
eth4:5
,eth4:6
, ..
IP-aliases are an obsolete way to manage multiple IP-addresses/masks per interface. Newer tools such as iproute2 support multiple address/prefixes per interface, but aliases are still supported for backwards compatibility. Documentation/networking/alias.txt -
VLANs:
eth4.0
,eth4.1
,eth4.3
,vlan0
, ..
are created to partition a single layer 2 network into multiple virtual ones. The drivers all participating network cards must support IEEE 802.1Q and be configured accordingly. This standard allows for up to 4096 VLANs (12Bits). -
Stacked VLANs: IEEE 802.1ad-support was mainlined in 2013-04-19: net: vlan: add 802.1ad support Configuration is done using
ip link
:
ip link add link eth0 eth0.1000 type vlan proto 802.1ad id 1000 ip link add link eth0.1000 eth0.1000.1000 type vlan proto 802.1q id 1000
-
bridgeds:
br0
,br-lan
are used to make multiple virtual or physical network interfaces act as if they were just one network interface (quasi the opposite of VLANs). Can also be used for VPN and bridged interfaces. The Linux Ethernet bridge can be used for connecting multiple Ethernet devices together. The connecting is fully transparent: hosts connected to one Ethernet device see hosts connected to the other Ethernet devices directly. understanding how bridge-interfaces work -
tunnel interfaces:
pppoe-dsl
,pppoa-dsl
,tun0
,vpn1
,
used to send packets over a tunneling protocol such as GRE, IPsec PPPoE, etc. -
wireless operating mode virtual interfaces:
wlan0
,wlan0_1
,ath3
,ath_monitor
, ..
Linux wireless subsystem: There is always one physical network interface for each WNIC called the master interface. The master interface is invisible. Then, depending on the wireless operating mode the master interface is configured to, ad-hoc (IBSS), managed , AP , WDS, mesh point, monitor, wireless virtual network interfaces with different properties are created. This is done automatically by default. When the WNIC driver is loaded, there always will be the master interface and (at least) one virtual interface!
Two network interfaces can also be bonded together (please see Link aggregation and Channel bonding and Ubuntu Wiki), Documentation/networking/bonding.txt
UCI is a small C utility designed to centralize configuration in OpenWrt./etc/config/network is the network configuration file./etc/config/wireless is the wireless configuration file.UCI creates an abstraction layer for configuring network interfaces: In /etc/config/network you allocate a name like lan or internet_wire or whatever to each ifname -variable for every device and then this name is consistently used through the entire UCI configuration. But this can only be used in conjunction with UCI! |
OpenWrt default configuration
The OpenWrt default configuration is explained in …
叫人苦惱也!!
誰能先知 option path 出自何方?☻
Wireless configuration
The wireless UCI configuration is located in /etc/config/wireless
. Learn about the entire IEEE 802.11 “wireless” subsystem.
Note1: By default the wireless is OFF. You can turn it on in the /etc/config/wireless by changing disabled 1 to disabled 0 In UCI CLI you do this with: uci set wireless.@wifi-device[0].disabled=0; uci commit wireless; wifi
uci show wireless | grep disabled
|
Sections
A typical wireless config file contains at least one wifi device specifying general radio properties like channel, driver type and txpower and one wifi interface defining a wireless network on top of the radio device.
Wifi Devices
The wifi-device
refer to physical radio devices present on the system. The options present in this section describe properties common across all wireless networks on this radio interface, such as channel or antenna selection.
In most cases there is only one radio adapter present on the device, so only one such section is defined, however on multi-radio hardware there may be multiple wifi-device
sections – each referring to a different adapter.
A minimal wifi-device
declaration may look like the example below. Note that identifiers and options may vary for different chipset types or drivers.
config 'wifi-device' 'wl0' option 'type' 'broadcom' option 'channel' '6'
-
wl0
is the internal identifier for the wireless adapter -
broadcom
specifies the chipset/driver type -
6
is the wireless channel the device operates on
The possible options for device sections are listed in the table below. Note that not all options are used for all chipset/driver types, refer to the comments for further details.
Common Device Options
Name | Type | Required | Default | Description |
---|---|---|---|---|
type |
string | yes | (autodetected) | The type is determined on firstboot during the initial radio device detection – it is usually not required to change it. Used values are broadcom on brcm47xx, or mac80211 for b43, ath5k and ath9k |
phy |
string | no/yes | (autodetected) | Specifies the radio phy associated to this section. If present, it is usually autodetected and should not be changed. |
macaddr |
MAC address | yes/no | (autodetected) | Specifies the radio adapter associated to this section, it is not used to change the device mac but to identify the underlying interface. |
ifname |
string | no | (driver default) | Specifies a custom name for the wifi interface, which is otherwise automatically named. |
disabled |
boolean | no | 0 |
Disables the radio adapter if set to 1 . Removing this option or setting it to 0 will enable the adapter |
channel |
integer or “auto” | yes | auto |
Specifies the wireless channel to use. “auto” defaults to the minimum channel available |
……
MAC80211 Device Options
The options below are only used by the mac80211 driver (type mac80211
).
Name | Type | Required | Default | Description |
---|---|---|---|---|
path |
string | no | (none) | Alternative to phy used to identify the device based paths in /sys/devices |
htmode |
string | no | (driver default) | Specifies the channel width in 802.11n and 802.11ac mode, possible values are:HT20 (single 20MHz channel),HT40- (2x 20MHz channels, primary/control channel is upper, secondary channel is below)HT40+ (2x 20MHz channels, primary/control channel is lower, secondary channel is above).HT40 (2x 20Mz channels, auto selection of upper or lower secondary channel on versions 14.07 and above).NONE (disables 802.11n rates and enforce the usage of legacy 802.11 b/g/a rates)VHT20 / VHT40 / VHT80 / VHT160 (channel width in 802.11ac, extra channels are picked according to the specification)Cf. why.can.t.i.use.ht40.with.channel.11 and http://hostap.epitest.fi/cgit/hostap/tree/hostapd/hostapd.conf(search for HT40) in the web page. |
※ 註︰
sysfs
sysfs is a pseudo file system provided by the Linux kernel that exports information about various kernel subsystems, hardware devices, and associated device drivers from the kernel’s device model to user space through virtual files.[1] In addition to providing information about various devices and kernel subsystems, exported virtual files are also used for their configuration.
sysfs provides functionality similar to the sysctl mechanism found in BSD operating systems, with the difference that sysfs is implemented as a virtual file system instead of being a purpose-built kernel mechanism, and that, in Linux, sysctl configuration parameters are made available at /proc/sys/ as part of procfs, not sysfs which is mounted at /sys/.[2]
History
During the 2.5 development cycle, the Linux driver model was introduced to fix several shortcomings of version 2.4:
- No unified method of representing driver-device relationships existed.
- There was no generic hotplug mechanism.
- procfs was cluttered with non-process information.
Sysfs was designed to export the information present in the device tree which would then no longer clutter up procfs. It was written by Patrick Mochel.[3][4] Maneesh Soni later wrote the sysfs backing store patch to reduce memory usage on large systems.
During the next year of 2.5 development the infrastructural capabilities of the driver model and driverfs, formerly called ddfs, began to prove useful to other subsystems.[5][6] kobjects were developed to provide a central object management mechanism and driverfs was renamed to sysfs to represent its subsystem agnosticism.
Sysfs is mounted under the /sys mount point. If it is not mounted during initialization, you can always mount it using the command: “mount -t sysfs sysfs /sys”
Supported buses
- PCI
- Exports information about PCI devices.
- USB
- Contains both USB devices and USB hosts.
- S/390 buses
- As the S/390 architecture contains devices not found elsewhere, special buses have been created:
- css: Contains subchannels (currently the only driver provided is for I/O subchannels).
- ccw: Contains channel attached devices (driven by CCWs).
- ccwgroup: Artificial devices, created by the user and consisting of ccw devices. Replaces some of the 2.4 chandev functionality.
- iucv: Artificial devices like netiucv devices which use VM’s IUCV interface.
Sysfs and userspace
Sysfs is used by several utilities to access information about hardware and its driver (kernel modules) such as udev or HAL. Scripts have been written to access information previously obtained via procfs, and some scripts configure device drivers and devices via their attributes.
假使安裝『老工具』︰
opkg update
opkg install wireless-tools
或可一窺堂奧乎?☆
root@LEDE:~# iwconfig
wlan0 IEEE 802.11 Mode:Master Tx-Power=31 dBm
RTS thr:off Fragment thr:off
Power Management:on
br-wan no wireless extensions.
lo no wireless extensions.
eth0 no wireless extensions.
br-lan no wireless extensions.
然而『多功能』 IC 晶片越來越多︰
root@LEDE:~# dmesg | grep brcmfmac [ 6.052003] brcmfmac: brcmf_fw_map_chip_to_name: using brcm/brcmfmac43430-sdio.bin for chip 0x00a9a6(43430) rev 0x000001 [ 6.187644] brcmfmac: brcmf_c_preinit_dcmds: Firmware version = wl0: Aug 29 2016 20:48:16 version 7.45.41.26 (r640327) FWID 01-4527cfab [ 6.236390] usbcore: registered new interface driver brcmfmac root@LEDE:/sys/bus/sdio/drivers/brcmfmac# ls -l --w------- 1 root root 4096 Oct 6 15:33 bind lrwxrwxrwx 1 root root 0 Oct 6 15:33 mmc1:0001:1 -> ../../../../devices/platform/soc/3f300000.mmc/mmc_host/mmc1/mmc1:0001/mmc1:0001:1 lrwxrwxrwx 1 root root 0 Oct 6 15:33 mmc1:0001:2 -> ../../../../devices/platform/soc/3f300000.mmc/mmc_host/mmc1/mmc1:0001/mmc1:0001:2 lrwxrwxrwx 1 root root 0 Oct 6 15:33 module -> ../../../../module/brcmfmac --w------- 1 root root 4096 Oct 6 15:33 uevent --w------- 1 root root 4096 Oct 6 15:33 unbind root@LEDE:/sys/bus/sdio/drivers/brcmfmac# cd mmc1\:0001\:1/ root@LEDE:/sys/devices/platform/soc/3f300000.mmc/mmc_host/mmc1/mmc1:0001/mmc1:0001:1# ls class driver modalias power uevent device ieee80211 net subsystem vendor root@LEDE:/sys/devices/platform/soc/3f300000.mmc/mmc_host/mmc1/mmc1:0001/mmc1:0001:1# cd .. root@LEDE:/sys/bus/sdio/drivers/brcmfmac# cd mmc1\:0001\:2 root@LEDE:/sys/devices/platform/soc/3f300000.mmc/mmc_host/mmc1/mmc1:0001/mmc1:0001:2# ls class driver power uevent device modalias subsystem vendor
這個『mmc1\:0001\:2』到底是什麼東東耶?★