This is my eleventh week of being an intern at Aeste Works. My main focus this week was to ensure that two way communication between the USB stack and lwIP’s TCP/IP stack was working as intended. The simplest way to achieve this was pinging the USB CDC ECM device and observing the packets through Wireshark. Ping is a tool that sends an ICMP (Internet Control Message Protocol) echo request and expects an echo reply if the Network layer (Layer 3 of the OSI Model) has been set up correctly with the lwIP TCP/IP stack.
Before I wrote code for the output function of my network driver, I had to test and confirm whether my network driver input function correctly sends the ICMP echo request packets to the lwIP stack. The ICMP echo request starts with an ethernet header containing information such as packet type, source and destination MAC addresses. The ethernet header is first processed in lwIP’s ethernet_input function which is a callback function within the network driver input function I had written. Once information from the ethernet header is obtained, the lwIP stack strips it off and sends the rest of the payload to another function called etharp_input. Here, the Internet Protocol address is mapped to a MAC address that is recognized in the local network and once this is successful, the lwIP stack would call the etharp_raw function and then the ethernet_output functions which places the necessary ethernet header information and the payload in the ICMP response packet. Finally, the lwIP stack would call the output function of the network driver that sends the packet from the lwIP stack to the USB stack. Since I hadn’t written the output function at that time, the movement of packets as seen on Wireshark would halt at this point. Still, I was relieved to know that ICMP echo request packet was sent and processed by the lwIP stack correctly.
The next step was to write my output function. After the ICMP echo request packet has been processed by the lwIP stack, a pbuf structure which contains the response payload would be taken in by my output function. The contents of the pbuf structure would be then copied over to the USB stack’s buffer and then sent to the USB stack by calling the USB_DEVICE_CDC_Write function. A simple ping request on the terminal and by observing the packets on Wireshark showed that the host was indeed receiving an ICMP echo response through USB! This meant that the Network layer (Layer 3 of the OSI Model) has been successfully built on top of the Data link layer (Layer 2 of the OSI Model established by virtual ethernet interface of USB CDC ECM) . Finally, my second main project has come to an end and next week will be my last week here. Next week, I would try to test the network performance of the device using iPerf which is a network bandwidth measurement tool as well as trying to check whether IPv6 can be used with the device.