Mobile phones generally provide two types of Internet access: Wifi or 3G/4G Internet access. Wifi Internet access is actually the use of network cards through Ethernet Internet access. 3G/4G is through the baseband, the use of cellular network for Internet access, previously has simply described the difference between Wifi and 3G Internet access **, this paper mainly describes the process and principle of Android 3G/4G Internet access.

  • Wireless Internet hardware model
  • 3G/4G Internet protocol PPP
  • 3G/4G Internet access process – how to establish PPP
  • How does a socket send and receive data through the baseband module

Overview of Android Traffic Data Online (Hardware platform and Environment)

Mobile phones generally have two network cards, just not used at the same time, the Wifi Ethernet card, and 3G/4G wireless Modem type network card (baseband module), 3G/4G Internet use is cellular network, signal in the form of electromagnetic waves in the air to spread, sent to the nearest base station, The base station forwards to the base station covering the target device through the switch, notifies the target device, and sends back the result. In this Internet access mode, PPP (Point-to-point Protocol) is generally used at the link layer, and the Internet access medium is the wireless baseband communication module dedicated for wireless communication:

Point-to-point Protocol (PPP) for Android Traffic data Internet Access

Different from Ethernet, the mobile terminal accesses the Internet through cellular network. The biggest difference between the two is at the link layer. The network protocol model of Android 3G/4G wireless Internet is as follows:

At the data link layer, point-to-point Protocol (PPP) provides a standard point-to-point transmission mode for communication between hosts, Bridges, and routers. PPP consists of the following three parts:

  • Make Data frame encapsulation format: Based on HDLC(High Level Data Control, High Level Data Control link) standard, define encapsulation format for Data packets transmitted on serial Data link.
  • Link Control Protocol (LCP) : used to automatically negotiate format options, establish and terminate links, and detect Link errors and configuration errors.
  • The most common Authentication protocols include Password Authentication Protocol (PAP) and Challenge-Handshake Authentication Protocol (CHAP).
  • Network Control Protocol (NCP) : PPP provides Network Control protocols for each network-layer Protocol and uses them to configure network-layer parameters for point-to-point communication, such as dynamic negotiation of IP addresses and DNS.

Most of the above are used in the establishment of data link. After the establishment of data link, the main concern is to make data frame encapsulation. The format of making data frame encapsulation under PPP protocol is shown as follows:

Since PPP is point-to-point and does not require much information, there is no concept of a 48-bit MAC address. Therefore, PPP does not have ARP (Address resolution Protocol) and RARP (Reverse Address resolution Protocol), which are special protocols used by certain network interfaces, such as Ethernet and token ring networks.

Android traffic data Internet access

In the Android system, when an application accesses the network, it first checks whether the data network link is established. If the data network link is established, the application communicates directly with the established network interface. If the data network link is not established, it needs to establish a data path first. PPP dial-up Internet configuration is very complex, which requires a series of negotiation and verification. To facilitate development, Linux abstracted the establishment process of PPP data links and implemented the PPPD dial-up application, which is specially used to manage the establishment and closure of PPP data links. However, IN fact, PPPD is only responsible for the establishment of data links. After the establishment, data access will not depend on PPPD service. For example, PPPD is only responsible for road repair, not cargo transportation.

PPPD is a daemon that implements all authentication, compression/decompression, encryption/decryption and other extended functions. It transfers the packets to the PPP processing module, sets PPP parameters, and establishes/closes connections.

PPP data link establishment process

If the Android system wants to use PPP protocol for data communication, it must first establish a data communication link according to PPP protocol. After the baseband module is loaded correctly, multiple ttyUSB device files will be mapped. Some ttyUSB is used for AT command sending, and some is used for data communication. AT the bottom, USB serial port multiplexing is realized through serial port multiplexing mechanism. When using ttyUSB to establish the data link, first through sending AT command, open the wireless Internet module, then use PPPD dialer to establish the data link. The dialing link process follows THE PPP communication protocol. The mobile phone and the cellular base station negotiate dynamically to configure link parameters and IP addresses. After the dialing is successful, the Android system will map a virtual network interface named PPP0 or RMNETxxx for the baseband module. The Android system can use this interface for network communication. The interface is similar to wLAN0, and the IP layer is completely unaware of the link layer.

To establish a PPP data link, you need to complete three steps, including link layer configuration, link authentication, and network layer configuration. During this process, communication parties must negotiate to determine link parameters, such as packet format and IP address, before establishing a PPP data link. In practice, the establishment of PPP data links can be divided into the following stages:

  • (1) Link Dead Phase: A PPP Link starts and ends in this Phase. In this Phase, the whole Link is unavailable. When the communication parties detect that the physical Link is active, they enter the Link establishment Phase.
  • (2) Link Establishment Phase: In this Phase, PPP links will negotiate through LCP to determine the working mode, authentication mode, Link compression, etc. If the LCP negotiation succeeds, the LCP is in the Opened state, indicating that an underlying link is established. If the link negotiation fails, the LCP is returned to Phase 1. After the link is successfully established, if PPP authentication is configured, the link enters the authentication phase. If PPP authentication is not configured, the link directly enters the network layer protocol phase.
  • (3) Authentication Phase: In this Phase, PPP authenticates users through PAP or CHAP Authentication. If the Authentication fails, the PPP link enters the link termination Phase and is removed. If the Authentication succeeds, the PPP link enters the network layer protocol Phase.
  • (4) Network-Layer Protocol Phase; At this stage, each network layer protocol is configured through the corresponding network control protocol. In this project, IP addresses and DNS of both parties are negotiated through IPCP. After successful negotiation, PPP links can send or receive packets based on TCP/IP.
  • (5) Link Termination Phase: PPP terminates the Link at any time, such as authentication failure or carrier loss. PPP closes the Link by exchanging LCP packets, notifies the network layer and physical layer to forcibly close the Link, and returns to the Link unavailable Phase. Link establishment process is shown in Figure 3.19:

After the communication link is established, PPPD creates a network interface (such as PPP0), and the PPP protocol module in the kernel registers this network interface. For upper-layer applications, this virtual network interface ppP0 or RMNETxxx is the interface to be invoked for wireless Internet access. And the interface has been dynamically assigned IP address from 3G network at the beginning of creation, for the upper application can be regarded as a real, and has been activated network device, can be used as Ethernet card, TCP/IP network communication, PPPD service link establishment flow chart:

Data sending process

When the application sends TCP/IP packets through the socket, the kernel finds the corresponding network interface (PPP0 or RMNETXXX) through the IP address and routing table, calls the corresponding implementation function of PPP, encapsulates PPP, sends the data, and finally sends the data to the baseband module through the serial port. And the radio frequency module will transmit the information to the nearby base station.

Data receiving process

The data receiving process can be regarded as the reverse of sending, but there is a slight difference here, that is, the receiver. When the data link is established, the receiver is the PPPD dial-up process. After the establishment, the receiver of ordinary Internet access data is the general user process:

conclusion

  • Mobile Internet access is PPP protocol
  • PPP does not have the concept of MAC addresses
  • PPPD is mainly used for paving roads (establishing links) and is not responsible for shipping
  • After the link is established, the data communication flow at the IP layer is no different from that of Ethernet

Android 3G/4G traffic Internet access principle analysis

For reference only, welcome correction