Android WiFi development summary

1 WLAN physical layer
composed of the physical layer is 1.1
PLCP: Physical Layer Convergence Procedure, a physical layer convergence sublayer
PMD: Physical Medium Dependent, Physical Medium Dependent layer; this layer modem is

1.2 signal the RSSI
the WPS Key: Key Press. 3 seconds The WITHIN .
router valid signal range: -20dB ~ -90dB
a room, it is about -40dB; separated by a wall, will be about -50dB.
-20dB rarely, only to rely on very close.
. The Smaller ABS (RSSI), The Better

1.3 provided a WiFi signal path most suitable number
- 6, 11 or 13 to select these suggestions do not conflict with each channel.
- When more than two AP within the wireless signal coverage of the wireless AP needs to be set for each AP different frequency bands, in order to avoid conflict shared channel. And the default settings of the wireless device used by many users are Channel 1, when two or more such devices with wireless AP "case" conflict is inevitable.
- both IEEE802.11b or IEEE802.11g standard which supports only 3 non-overlapping channels to transport channels, only channels 6, 11 or 13 are not in conflict, but can interfere with equipment using channels 1 and 3 6, use of the device may interfere with a channel 6 and 9 13.

MIMO 1.4
Figure 1-1 the WiFi MIMO

1.5 MRMC Concurrency
1)MRMC是multi-role multi-channel operation的缩写。
2)The WiLink8.0 supports the multi-channel operation as time division multiplexing (TDM)-based concurrency. Each role gets a portion of the air time. The core of the multi-role operation is the scheduler that decides on each given time what role should be activated, and protects the role that should be suspended before moving to a new role.
3)TI AP+SoftAP是单信道TDM并发。
4)Cypress WLAN+P2P采用不同的信道实现TDM并发。
5)Linux中每一个role叫做vif。
Figure 1
-2 Concurrency Setup STA with Group Client

The WiFi Android 2
2.1 automatically generates Android Selinux policy based on log AVC
2.1.1 generated text file policy
1) extract all log AVC
adb shell "CAT / proc / kmsg | grep AVC"> avc_log.txt

or

adb shell
dmesg | grep AVC> /dev/avc_log.txt
the adb pull /dev/avc_log.txt.

2) used to directly generate audit2allow Policy
the sudo APT-GET the install the policycoreutils
audit2allow avc_log.txt -i -o output_pol.te

VI output_pol.te

2.1.2 inserted directly into sepolicy file
adb shell
dmesg> /dev/kern_msg.txt
adb pull /dev/kern_msg.txt.

CAT kern_msg.log | audit2allow -p OUT / target / Product / <Device> / root / sepolicy

2.2 kernel module signature issue
CONFIG_MODULE_SIG = y
- indicate on the signature mechanism, but this time the module signature or no signature can be used.

= The y-CONFIG_MODULE_SIG_FORCE
- If the above configuration item is enabled, the module must have the correct signature to normal use.

= The y-CONFIG_MODULE_SIG_ALL
- kernel at compile time, and will not take the initiative to go to the module signature, unless you open the above configuration items.

@ Kernel / kernel / Makefile
wherein, x509.genkey CI generated when the key pair, signing_key.priv, signing_key.x509 respectively private key and a digital certificate. Digital certificates will be packaged into the kernel, which has a public key, etc., used to decrypt. Each compile time, although the configuration file every time the same, but the generated key pair is different.

2.3 Linux kernel module compiled script
2.3.1 Method chip manufacturers
@ Device / <VVV> /common/dlkm/AndroidKernelModule.mk

2.3.2 the OEM customization methods
@ hello.c

@ the Makefile
# PIC-NO: work of the Independent the Position Code, location independent code
obj-m: = hello.o

the PREFIX = the Android source path -linux / Android
KERNELDIR: = $ (the PREFIX) / OUT / target / Product / <PPP> / obj / KERNEL_OBJ /
the pWD: = $ (the shell pwd)
the ARCH = arm
= $ The CROSS_COMPILE (the PREFIX) /prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.8/bin/arm-linux-androideabi-

the CC = $ (the CROSS_COMPILE) GCC
the LD $ = (the CROSS_COMPILE) LD
CFLAGS_MODULE = - PIC-Fno

modules:
    the make -C $ (KERNELDIR) the ARCH = $ (the ARCH) the CROSS_COMPILE = $ (the CROSS_COMPILE) M = $ (the PWD) modules
Clean:
    RM * .o * .ko .order * * * .mod.c. symvers

2.4 nl80211
nl80211: netlink configuration using WiFi, top to bottom are the code hierarchy nl80211-cfg80211-mac80211 (comprising ieee80211_ops), abbreviated as the NCM; ioctl arranged on the wext a WiFi

@ NET / Wireless / nl80211.c
the mac80211 of add_virtual_intf () - adding to net_device under / sys / class / net directory (for example p2p0 - for hostapd, wlan0 - for STA); netd calls NL80211_CMD_NEW_INTERFACE create a virtual interface
mac80211 of del_virtual_intf () - The net_device deleted from sys / class / net directory (for example p2p0 - for hostapd, wlan0 - for STA); netd calls NL80211_CMD_DEL_INTERFACE delete a virtual interface

@ NET / mac80211 / iface.c
ieee80211_open () - call ieee80211_ops of add_interface (), generally refers to ifconfig wlan0 up
ieee80211_stop () - remove_interface call ieee80211_ops of (), generally refers to ifconfig wlan0 Down

hw_scan () - start a single scan
cancel_hw_scan () - stop a single scan
sched_scan_start () - start cycle scan
sched_scan_stop () - periodic scanning stop

2.5 nl80211 how to find the net_device specific struct
@ NET / NetLink / genetlink.c
static int genl_family_rcv_msg (struct genl_family Family *,
                   struct the sk_buff SKB *,
                   struct nlmsghdr NLH *)
{
    [...]
    // ieee80211_alloc_hw () -> wiphy_new ( ) is created in cfg80211_registered_device struct
    // & nl80211_fam-> pre_doit ()
    IF (Family-> pre_doit) {
        ERR = Family-> pre_doit (OPS, SKB, & info);
        IF (ERR)
            GOTO OUT;
    }

    // nl80211_ops [I] .doit (), Call cfg80211_ops-> XXX ()
    ERR = OPS-> doIt (SKB, & info);

    // & nl80211_fam-> post_doit ()
    IF (Family-> post_doit)
        Family- > post_doit (OPS, SKB, & info);

    [...]
}

2.6 state and a WiFi the StateMachine
State.java - state and the other class inheritance class, generating a multi-state N
StateMachine.java - state management, other class inheritance class, generating management State

2.7 STA and AP coexist
must be 2 at nodes / sys / class / net: such p2p0 (or wds0) and wlan0.

NET @ / Wireless / nl80211.c
mac80211 of add_virtual_intf () - Adding to net_device under / sys / class / net directory (for example p2p0 - for hostapd, wlan0 - for STA); netd calls NL80211_CMD_NEW_INTERFACE create a virtual interface
del_virtual_intf mac80211 of () - the net_device deleted from sys / class / net directory (for example p2p0 - for hostapd, wlan0 - for STA); netd calls NL80211_CMD_DEL_INTERFACE delete a virtual interface

@ /etc/wifi/wifi_concurrency_cfg.txt an under WifiServiceImpl.java
WifiController. java - or decide to use SoftApStateMachine.java WifiStateMachine.java
SoftApStateMachine.java - concurrent state machines AP and STA, the AP open code in the class; open STA code WifiStateMachine.java the
WifiStateMachine.java - AP and STA not concurrent state machines, the opening AP and the STA code in the class, the AP and the STA can choose one

Figure 2-1 Android state machine mechanism the StateMachine

2.8 Tethering
- NETD monitor network interface (/ sys / class / net) additions and deletions, and sent Tethering.java
@ Tethering.java
interfaceAdded()
interfaceRemoved()

- UI启动USB Tethering功能
@ Tethering.java
setUsbTethering()

- 使能路由和转发功能
@ TetherInterfaceStateMachine.java
class TetheredState extends State {
    [...]
    public boolean processMessage(Message message) {
        switch (message.what) {
            case CMD_TETHER_CONNECTION_CHANGED:
                [...]
                mNMService.enableNat(mIfaceName, newUpstreamIfaceName);
                mNMService.startInterfaceForwarding(mIfaceName,
                                    newUpstreamIfaceName);
                [...]
        }
    }
    [...]
}

Captive Detection Android 2.9
@ NetworkMonitor.java

# View all the configuration
Settings, Ltd. Free Join List

# using HTTPS
Settings PUT, Ltd. Free Join captive_portal_use_https 1
Settings PUT, Ltd. Free Join captive_portal_https_url https://www.qualcomm.cn/generate_204

# using HTTP
Settings PUT, Ltd. Free Join captive_portal_use_https 0
Settings PUT, Ltd. Free Join captive_portal_http_url http://connect.rom.miui.com/generate_204

# use the default, that is, delete the configuration
Settings, Ltd. Free Join captive_portal_http_url the delete
Settings, Ltd. Free Join captive_portal_https_url the delete

# disable captive probe
Settings PUT, Ltd. Free Join captive_portal_mode 0

3 common network debugging tools
- SocketTool (MCU and PC Socket testing communication is very convenient)
- WireShark

. 4 eCos the Write the MAC
MAC ra0 0x0004,0x0006 and 0x0008 is read three registers.
Suppose MAC address: 00: 0C: 43: 76 : 20: 58
into the command line, using eCos USB2UART line.
CD NET
the iwpriv RA0 E2P 04 = 0C00
the iwpriv RA0 E2P 06 = 7643
the iwpriv RA0 E2P 08 = 5820

. 5 Abbreviations
the CentOS yum: [jʌm], Yellowdog Updater, Modified
the Ubuntu APT-GET: Advanced Packaging Tool
BLA: the bind (), the listen () , the Accept ()
BSS: Basic service the Set, the AP or IBSS or the STA
CNN: ConnectivityService, NetworkPolicyManagerService, NetworkStatsService (statistics), NetworkManagementService (the lowest level, the physical network interface management service, netd communicate with)
config_tether_upstream_types: Android phone configuration is ApCli (AP-Client) time, as one of the Client
config_tether_usb_regexs: regular expressions, the regular expression
genl: Generic Netlink
IBSS: Independent Basic Service Set, generally refers to ADHOC
MLME: Mac Layer the Entity Management
NCM: nl80211-cfg80211-mac80211 (containing ieee80211_ops); another means that Network Control Model (iPhone CarPlay use)
nl80211: netlink configuration using WiFi, the code hierarchy top to bottom are nl80211-cfg80211-mac80211 (comprising ieee80211_ops), abbreviated as the NCM; WiFi configuration based on the wext ioctl embodiment
RTS / CTS: Request to send ( STA to a router), Clear to send (sent by the STA to a router )
the STA: Station
the TAP / TUN: Tunnel
VIF: the Virtual Interface

Published 121 original articles · won praise 49 · views 320 000 +

Guess you like

Origin blog.csdn.net/zoosenpin/article/details/74738229