Application of PPP protocol in embedded single chip microcomputer

Publisher:oplkjjjLatest update time:2011-02-16 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.

Reference address:Application of PPP protocol in embedded single chip microcomputer

Previous article:RISC CPU's Processing Method and Simulation of Transfer Instructions
Next article:Design of liquid dripping speed monitoring system based on 89C51

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号