PPP protocol (Point-to-Point Protocol) provides a method for transmitting datagrams on serial point-to-point links, supporting asynchronous 8-bit data and bit-oriented synchronous connections (such as ISDN). It provides an effective method for managing conversations between two points and is replacing SLIP (Serial Line Interface Protocol) protocol to become the standard for point-to-point networks.
Embedded microcontroller PPP protocol is to embed PPP protocol in microcontroller to realize PPP data transmission between microcontroller and computer, so that it can be used as a client of PPP connection or as an independent PPP server. It has a very broad application prospect in home appliance control and small data transmission systems, and has the characteristics of low cost and stable transmission. It is one of the hot topics in current microcontroller research.
1 Working principle of PPP
PPP uses high-level data link control (HDLC) protocol as the basic method for subpackaging datagrams on point-to-point links. Use extensible link control protocol (LCP) to establish, configure and test data links. Use network control protocol cluster (NCP) to establish and configure different network layer protocols. PPP allows multiple network layer protocols to be used simultaneously.
In order to establish a communication connection on a point-to-point link, the sending PPP first sends an LCP frame to configure and test the data link. After the LCP establishes the data link and coordinates the selected devices, the sending PPP sends an NCP frame to select and configure one or more network layer protocols. When the selected network layer protocol is configured, the data packets of each network layer protocol can be sent to the data link. The configured link will remain in the communication state until the LCP frame or NCP frame explicitly prompts to close the link, or other external events occur. The PPP connection state diagram is shown in Figure 1.
|
1.1 Connection Death Phase
This phase is passed through at the beginning and end of a connection. When an external event indicates that the physical layer is ready and available, PPP enters the connection establishment phase. At this point, the LCP automaton is in the initial phase. When it transitions to the link establishment phase, an UP event signal is sent to the LCP automaton.
1.2 Connection Establishment Phase
LCP is used to exchange configuration packets and establish a connection. Once a successful configuration packet is sent and received, the exchange is completed and the LCP is in the open state. All configuration options are assumed to use default values unless they are changed during the configuration exchange. Only those options that are not related to a specific network layer protocol are configured by LCP. Receipt of an LCP configuration packet will cause the link to return from the network layer protocol phase or the authentication phase to the link establishment phase.
1.3 Authentication Phase
In some connection situations, it is desirable to authenticate the peers before allowing the network layer protocol to exchange data. By default, authentication is not required. Authentication requirements must be raised during the connection establishment phase, and then the authentication phase will be entered. If authentication fails, the connection termination phase will be entered. Only connection protocol, authentication protocol, and connection quality test packets are processed in this phase.
1.4 Network layer protocol phase
Once PPP completes the above phases, it enters the network protocol phase. Each network layer protocol (such as IP, IPX, AppleTalk, etc.) must have a corresponding network control protocol (NCP) configured separately, and each network control protocol can be turned on or off at any time. At this stage, the LCP protocol automatic state machine is in the open state, and any unsupported protocol data packet received will be returned with a protocol rejection packet, and all supported data packets received will be discarded. At this time, LCP data packets, NCP data packets, and network protocol data packets are circulating on the link.
1.5 Connection termination phase
The PPP connection can be terminated at any time. LCP terminates the connection by exchanging connection termination packets. When the connection is terminated, PPP will notify the physical layer to take corresponding actions. Only when the physical layer is disconnected will the connection be truly terminated. At this stage, all non-LCP data packets received will be discarded.
2 PPP data structure
The structure of the PPP data frame is shown in Table 1, and the PPP protocol flags are shown in Table 2.
|
|
Each PPP data packet begins and ends with a 0x7E data flag. After the start flag, there are two HDLC constants: address constant 0xFF and control constant 0x03. The protocol field length is usually 2 bytes, indicating which protocol is contained in the information field and its processing information. This is followed by the code, identifier (ID) and length field (Length). In fact, they are all part of the information field (Payload). The information field length is up to 1500 bytes. The code part is used to indicate a certain type in the LCP, PAP, IPCP or CHAP protocol data packet. Usually, the identifier used to indicate the IP self-addressing information data packet is 0x45. The ID is unique for each frame, and all negotiations and responses between protocols are linked together through the ID. The only exception is when the PPP protocol frame is compressed into an IP addressing information packet. At this time, the ID indicates a service type. The payload part is variable and can change accordingly with the changes in requests and responses. In the case of IP self-addressing, the size of the IP data packet is compatible with the size of the PPP protocol frame, and the payload contains the negotiation of the relevant protocol and the maintenance of the data packet. Then comes a 2-byte cyclic redundancy check code to detect errors in the data frame. Since the value of the flag character is 0x7E, PPP needs to escape it when it appears in the information field. The specific implementation process is as follows:
(1) When encountering the character 0x7E, it is necessary to transmit two characters in succession: 0x7D and 0x5E to escape the flag character.
(2) When encountering the escape character 0x7D, it is necessary to transmit two characters in succession: 0x7D and 0x5D to escape the escape character.
(3) By default, if the value of the character is less than 0x20 (such as ASCII control characters), it is generally escaped. For example, when encountering the character 0x01, it is necessary to transmit two characters 0x7D and 0x21 in succession (at this time, the sixth bit is complemented and becomes 1, while the previous two cases change it to 0). This is done to prevent them from appearing in the serial interface drivers or modems of both hosts, because they sometimes interpret these control characters as special meanings. Another possibility is to use the link control protocol to specify whether some of the 32 characters need to be escaped. By default, all 32 characters are escaped.
For a detailed description of the PPP protocol, please refer to the RFC1661 document.
3 MCU PPP Protocol
The MCU PPP protocol is the application of the PPP protocol in the MCU, and has its own characteristics. The storage space of the MCU is only 64KB, and the PPP protocol includes protocols such as LCP, PAP, IPCP and NCP, and after the connection is established, data transmission protocols (TCP/IP, UDP, etc.) and various compression protocols are also used. It is impossible to embed these protocols completely into the MCU, so only some of them can be selected according to actual needs.
For example, the UDP protocol is used instead of the TCP/IP protocol, which has relatively complete functions but too large protocol content, to transmit data. The data compression protocol is basically not used in the transmission, the password verification process when the MCU is used as the server is skipped, and the network layer protocols such as IPX and AppleTalk are omitted. In other words, the MCU PPP protocol in this article actually only includes the protocols necessary from the establishment of the PPP connection to the realization of simple data transmission, but does not include all the functions of the PPP protocol. The choice of this protocol is determined by the objective limitations of the hardware and the actual application needs.
4 MCU PPP protocol PPP connection establishment
The MCU PPP connection status after establishment is shown in Figure 2.
|
Among them, the C51 system is a 51 series single-chip microcomputer that has been implanted with the PPP protocol, and the telephone line part can also be part of a network, or even the Internet.
The single-chip microcomputer PPP protocol flow chart is shown in Figure 3.
|
The establishment of a PPP connection mainly goes through three stages, namely LCP negotiation, password authentication, and network layer protocol configuration.
4.1 LCP processing stage
First, after the first LCP data packet is sent by the server, a PPP rejection packet is returned from the server for all options except password authentication, and then the server forces the authentication protocol to negotiate (both PAP and CHAP from the previous negative frame are sent). The server then returns a rejection packet to CHAP, which is replaced by PAP in this article. Then the server agrees and returns a new request, and PAP is required at this time. Next, PAP is confirmed, and the system negotiates the discarding of character mapping. Finally, all control features are discarded by the server.
The microcontroller sends a PAP data packet to the PC after the PC sends a confirmation of the microcontroller LCP option and before the PC sends an IPCP request to the microcontroller.
4.3 IPCP processing stage
IPCP is used to set the network environment in the PPP connection, including IP address, IP compression protocol, DNS server address, etc., which are all negotiated through IPCP. First, the server sends a request for IPCP negotiation, and then the system returns a rejection packet for all operations except the IP address. Since the previous transmission was rejected, the server sends a reply containing only the IP address. At this point, the system is equivalent to the IP address authentication of the server, and then the three-way handshake protocol is completed by the request information and the IP address. Then the server returns a rejection packet containing the pre-assigned IP address. At this point, the connection is established and has a specified IP address. The format of the IPCP frame is similar to that of the LCP: a one-byte code, followed by a flag, length, and options. When the options of the IP protocol are configured, communication can begin. A detailed description of IPCP is in RFC1332.
After the connection is established, PPP will call network protocols such as UDP (User Datagram Protocol) and ICMP (Internet Control Messages Protocol) based on the original protocol. For detailed information on the user datagram protocol UDP, please refer to the RFC882 and RFC883 documents; for detailed information on the Internet information control protocol ICMP, please refer to the document RFC792.
Previous article:RISC CPU's Processing Method and Simulation of Transfer Instructions
Next article:Design of liquid dripping speed monitoring system based on 89C51
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Why are PCBs mostly green?
- Class AB amplifiers are replaced by Class D amplifiers
- What kind of operation circuit is U2?
- Those who want to learn ROS system should read this (video teaching materials are updated continuously...)
- A large number of books have been released after graduation, including C/C++, Linux, algorithms, and other books. They are on sale now. Only 3 days left
- IWR1642Boost people counting DEMO program operation process
- I would like to ask the experts to introduce the generation of 2HZ in detail. Now the buzzer circuit 2HZ does not work! ! ! ! ! !
- Why doesn't the CPU top cover use silver, which has better heat dissipation?
- Summary of low power consumption STM32L151+RTC wake-up application
- LLC design information collection (for learning only)