Share this

Simplification and Implementation of TCP/IP Protocol in Embedded Systems

2026-04-06 06:02:07 · · #1
By analyzing the TCP/IP protocol and considering the characteristics of embedded systems, a concise and practical subset of TCP/IP protocols is selected, and the implementation process of each protocol layer is described in detail. This provides a relatively simple and feasible approach for the development of embedded network systems. 1. Introduction An embedded network system is a system that implements network interconnection functionality on embedded devices. Generally, embedded devices are required to support the TCP/IP protocol stack in software and implement relevant Ethernet communication protocols. How to implement the TCP/IP protocol is one of the key technologies of embedded network systems. The key to applying the TCP/IP protocol in embedded systems is how to design a concise and efficient subset of TCP/IP protocols to reduce the consumption of system resources. Currently, widely used TCP/IP protocol stacks include LWIP (Light Weight), uIP, and Linux IP. These stacks have a certain degree of universality, contain relatively complete protocol content, and are also relatively complex. When porting them to application systems, many issues need to be considered. Various library files and global variables cross-reference each other. If simplification is to be made for a specific system, it will affect the whole system. In particular, memory management and the interface between upper-layer protocols and lower-layer network drivers are the two biggest porting challenges. To gain a deeper understanding of the TCP/IP protocol and facilitate further in-depth research, we independently developed an embedded TCP/IP protocol system while implementing a specific Internet network alarm system. The TCP/IP protocol system described below is streamlined and easy to implement, requiring no memory management, making it suitable for embedded systems with small data transmission volumes. During implementation, simply complete the corresponding functions at each layer according to the appropriate data frame format. It is highly suitable for research and learning, providing a feasible and simple approach for the development of embedded network systems. 2. Protocol Analysis and Selection As is well known, TCP/IP is a protocol suite, a collection of hundreds of network protocols. General-purpose computer systems have sufficient resources to support communication protocols implemented in the kernel, but embedded systems are different because their CPU processing power and system storage capacity are limited by cost. Making full use of resources and improving system cost-effectiveness are fundamental characteristics of embedded application development. Therefore, the TCP/IP protocol needs to be streamlined to suit embedded systems. Below, we will use a practical Internet network alarm system as an example to design a relatively streamlined TCP/IP protocol subsystem. This system uses a 32-bit ARM-based Samsung S3C440BX processor, an SMSC LAN91C113 Ethernet controller chip, and other peripheral chips. The system requires transmitting field-collected alarm data to a remote site via the Internet, demanding good real-time performance and high transmission speed, but with a small amount of data transmitted each time, consisting only of simple alarm information. Based on these requirements, and after detailed analysis of the functions implemented by each TCP/IP protocol layer, a simplified protocol subset is shown in Figure 1: [align=center] Figure 1 Simplified TCP/IP Protocol Subset[/align] First, at the link layer, due to the use of Ethernet access, the system must implement the CDMA/CD protocol specified by IEEE 802.3. The CDMA/CD protocol does not require user implementation; it can be supported by a general-purpose Ethernet interface chip. Second, to ensure communication over Ethernet, the system also needs to implement the ARP reply protocol, which maps IP addresses to Ethernet MAC addresses. ARP execution relies on maintaining a table to complete the mapping between IP addresses and MAC addresses. At the network layer, since the system requires communication over the Internet, the system must implement the IP protocol. The IP layer code has two functions: verifying the correctness of the incoming IP packet header and performing packet splitting between TCP and ICMP packets. Because IP fragmentation and reassembly are not considered, the IP layer code is very concise. To test the system's connection to the network, the system needs to implement the Ping acknowledgment protocol in ICMP. The Ping acknowledgment protocol mainly checks network connectivity. At the transport layer, TCP provides connection-oriented, reliable, non-duplicated bidirectional data stream transmission services between two hosts. The TCP protocol has a strict three-way handshake for establishing a connection and a four-way handshake for closing a connection, which consumes significant system resources. UDP is simpler to implement and can be well-suited for certain embedded Internet applications. Considering system simplification and speed requirements, the UDP protocol is adopted. To ensure the arrival of UDP data, the application uses repeated sending and acknowledgment to guarantee data correctness. Since this embedded system does not have HTTP, FTP, or other applications, the application layer protocols do not need to be implemented. 3. Protocol Implementation Because the protocols in this system are relatively concise, only essential protocols are retained, making the implementation process relatively simple. A key objective in the implementation process is to minimize system overhead, ensure independence between each layer, and simplify memory operations. To achieve layer independence, transparent data transmission between layers is crucial. Data transfer between layers should be facilitated through a series of functions. Furthermore, to reduce system overhead caused by data copying, the system should use pointer operations, rather than data copying, to pass data from the buffer up the protocol stack. Since the various data formats of each layer of the TCP/IP protocol are detailed in various resources, they will not be described in detail here. Only the overall structure, the function of each layer, and the implementation process will be described in detail. For ease of debugging, the system will be implemented starting from the bottom layer and working upwards layer by layer. 1) First, the definition of common data structures: such as MAC address format, IP address format, system address configuration, buffer format and size. The MAC and IP address formats are fixed, and the system configuration determines the system's IP address, port, and MAC address value. Due to the limited amount of data to be transmitted in this system, only four buffers, each 150 bytes in length, are defined for transmitting and receiving data. 2) Network Driver Interface: Since the network driver was also developed by us, it integrates smoothly with the upper layer. It uses an interrupt mechanism for receiving data; when a network interrupt is received, data is read and, depending on the packet type, forwarded to either ARP or IP protocol, with each layer processing the data independently. For sending, a polling method is used; the application layer prepares the data, encapsulates it layer by layer, and passes it down, finally sending it via the network driver. 3) Implementation of the Link Layer ARP Protocol: First, the ARP data frame header structure and ARP cache table are defined. Data frames must conform to the standard definition, and the cache table must contain at least the IP address and its corresponding MAC address. Since the number of connected objects in the embedded system is relatively small and fixed, the periodic refresh procedure for the cache table is removed, significantly reducing system refresh overhead. The main tasks in this part are: a) Based on the IP address in the upper-layer data packet, look up the corresponding MAC address in the cache table and fill it into the corresponding position in the packet. If the table does not contain the corresponding MAC address, assemble an ARP request packet according to the format and send it to obtain the other party's MAC address. b) If an ARP reply packet is received, update the ARP cache table. The main functions are: `struct pbuf * arp_packet(struct arpdata *q)` // Packs the ARP data to be sent into a network format byte stream; `struct mac * arp_lookup(struct ip *p)` // Looks up the MAC address in the ARP cache table based on the IP address. If not found, it automatically broadcasts an ARP request to the network; `void arp_input(struct pbuf *p)` // Inputs ARP frame data from the driver. If it is an ARP request, it sends an ARP reply packet; if it is an ARP reply, it updates the ARP cache table; 4) Implementation of the network layer IP protocol and Ping reply: First, define the data structures IP and ICMP data frame formats, both of which must be defined according to the standard. The main tasks in this part are: a) Adding the IP header and IP checksum to the data packets sent down from the upper layer and sending them to the lower layer. And performing checksum checks on the data packets sent up from the lower layer. If correct, removing the IP header and sending them to the upper layer. b. To facilitate testing the PING program of the host, i.e., if an ICMP echo request packet is received, an ICMP echo reply packet is assembled according to the format and sent. The main functions are: int ip_input(struct pbuf * p); // Input the data packet of the next layer, remove the IP header and pass it to the previous layer; int ip_send_data(struct pbuf * p, int len, int type, struct ip dst_ip); // Add the IP header to the data of the previous layer and send it to the next layer; void ip_packet(struct pbuf * p, struct IP_data * q, int len); // Pack the IP header and data; U16 ip_chksum(U8 * p, int len); // IP checksum and calculation; void icmp_input(struct pbuf * p) If there is an ICMP echo request, send a reply packet; 5) Implementation of the transport layer UDP protocol: The UDP data frame format is defined according to the standard. The main tasks in this part are: adding a UDP header and UDP checksum to the data packets sent down from the application layer before sending them to the next layer; and performing checksum checks on the data packets sent up from the next layer, removing the UDP header if correct, and then sending the data to the application layer. It's important to note that a pseudo-header needs to be generated for UDP data verification and calculation. The main functions are: void udp_input(struct pbuf *p); // Input UDP data from the next layer void udp_output(U8 *str,struct ip dst_ip,U16 dst_port); // Send UDP data to the next layer void makeup_pheader(struct ip *p,U16 len,U8 *q); // Generate pseudo headers for UDP checksum calculation U16 udp_chksum(U8 *p,int len,U8 *p1,int len1); // Calculate UDP checksum 6) Execution process: When the local system has data to send, it first adds a UDP header to the data at the transport layer, then adds an IP header at the network layer, then queries the corresponding MAC address from the ARP table at the link layer, fills in the corresponding position, and sends it to the network driver for transmission to the Ethernet. Figure 2 is a screenshot taken by SPYNET software of the entire network protocol response process when the system sends a string of characters for the first time after startup. Since it is the first transmission, the ARP table is empty. Therefore, when sending UDP data, if the MAC address corresponding to the destination IP address cannot be found, the system first sends an ARP request, waits for the other party to return an ARP reply to obtain the other party's MAC address, and then sends the UDP data packet. [align=center]Figure 2 A complete process of sending an actual UDP data packet[/align] 4. Conclusion Due to the development of embedded systems and the popularization of the Internet, as well as the rise of remote control and information appliances, the combination of embedded systems and the Internet has gradually become a new direction of technological development. The selection and implementation of embedded TCP/IP protocols is a challenge that this technology must address. Often, when dealing with TCP/IP protocols, people are easily confused by their complex architecture and dare not start easily. The embedded TCP/IP protocol selection approach proposed in this paper, and the implementation process of a simplified subset of TCP/IP protocols, are of great reference value for research in this area. References 1. Li Runzhi, Yue Jian, Li Yangyang (2003). Web-based embedded network management system. Computer Applications. 23(6): 95-97. 2. Xu Haiyan, Fu Yan (eds.) (2002). Embedded System Technology and Application. Beijing: Machinery Industry Press. 3. W. Richard Stevens (author), Fan Jianhua et al. (translators) (2000). TCP/IP Illustrated, Volume 1: Protocols. Machinery Industry Press. 4. Li Ming, Kang Jingqiu, Jia Zhiping (2002). Research and development of embedded TCP/IP protocol stack. Computer Engineering and Applications. 2002(16): 118-121. 5. Hong Xijun, Wang Decai (2000). Internet-based multifunctional remote monitoring and alarm system. Journal of Shanghai Jiaotong University. 34(10): 1370-1371.
Read next

CATDOLL 101cm TPE Doll with Anime A-Type Head – Cute Petite Body

Height: 101cm Weight: 15.5kg Shoulder Width: 26cm Bust/Waist/Hip: 57/50/66cm Oral Depth: 3-5cm Vaginal Depth: 3-13cm An...

Articles 2026-02-22