tcp、ip协议栈移植
LWIP协议栈详解

LWIP协议栈详解LWIP(Lightweight IP)是一个轻量级的开源 TCP/IP 协议栈,旨在为嵌入式系统提供网络连接功能。
它非常适合资源受限的系统,如单片机和小型处理器,因为它非常小巧且具有很好的可移植性。
首先,让我们来看看LWIP的核心协议。
LWIP提供了IP协议、ARP协议、ICMP协议和UDP协议的实现。
IP协议层负责数据包的路由和分段,ARP协议层负责解析IP地址和MAC地址的映射,ICMP协议用于网络探测和错误报告,UDP协议提供简单的不可靠数据传输。
除了核心协议,LWIP还提供了一些可选的协议功能,如TCP协议和DHCP协议的实现。
TCP协议提供了可靠的数据传输,而DHCP协议用于自动获取IP地址。
LWIP的另一个重要特性是它的可移植性。
LWIP设计了一个适配层,将操作系统相关的功能与核心协议分离开来。
适配层提供了一组标准的API,操作系统只需要实现这些API就可以使用LWIP协议栈。
LWIP支持的平台非常广泛,包括常见的操作系统如Windows、Linux和FreeRTOS,以及嵌入式系统如ARM Cortex-M和Microchip PIC等。
最后,让我们来看看LWIP的应用协议扩展能力。
应用协议可以通过注册回调函数来扩展LWIP的功能。
例如,应用程序可以注册一个回调函数来处理HTTP请求,或者注册一个回调函数来处理自定义的应用层数据。
这种扩展机制使得LWIP非常灵活,可以满足各种应用需求。
总结起来,LWIP是一个轻量级的开源TCP/IP协议栈,适用于资源受限的嵌入式系统。
它将TCP/IP协议栈分为核心协议和应用协议两层,提供了IP、ARP、ICMP、UDP等核心协议的实现,并通过可移植的适配层支持各种平台。
此外,LWIP还提供了应用协议扩展的能力,通过注册回调函数来扩展功能。
无论是大型操作系统还是小型嵌入式系统,LWIP都是一个很好的选择。
FuIP协议栈详解,专为单片机联网TCP IP协议,移植教程

下载到源码之后
一、如果你的路由器默认网关是:192.168.1.1
子网掩码是:255.255.255.0
并且没有机器在用:192.168.1.150
那么恭喜你,直接下载进你的单片机,如果不是,那么自己改哈。
在“网络连接”的“详细信息”看到如图所示:
如果你是其他的相应改动即可。
保证单片机和电脑或者手机同在一个路由器的一个网段下面。
192.168.1.xxx都是在一个子网
一般子网掩码,MAC不用改,MAC同局域网不能有相同的,IP也是。
(我说的是STC12C5A60S2或者STC12LE5A60S2其他单片机只需要改改头文件即可,默认工程是用的替换文件换了Keil4)
二、下载进去之后,插上一般的网线,到路由器LAN口之一。
然后就ping单片机,看它通不通
怎么ping?明天XP就要过期了,好怀念啊。
说ping,
就是点“开始”——>"运行"——>“cmd”——>Enter-------出现黑色界面
输入:ping192.168.1.150按——>Enter(PS:如果你的IP改成别的,就写别的)
出现这个回应,那么一切都通了。
下一步就是看你想做什么了
三、如果是手机下载TCP/UDP调试APP如果是电脑用TCP/UDP调试助手发送命令
命令解析是在fu_app.c里面函数里面。
默认示例是点亮,关闭led等
接收UDP数据的,有效数据从DATA[42]开始
接收TCP数据的,有效数据从DATA[54]开始
收到什么数据,该做什么都是你自己的事情了。
若不明白?那看视屏教程更直观哈。
μCOS-II-下-LwIP-协议栈的移植和测试

1、引言为了实现嵌入式系统终端连入互联网,而有必要为其引入了网络功能。
μC/OS II 是一个源代码开放的实时操作系统,但是它只是一个实时的任务调度及通信内核,并没有集成TCP/IP 通信协议,为了实现网络功能,需要在μC/OS II 移植一个轻量级的TCP/IP 通信协议LwIP。
本文主要论述μC/OS II 下通信协议LwIP 的移植以及测试。
2、LwIP 简介LwIP ( light weight IP)是瑞士计算机科学院的Adam Dunkels 等开发的一套开放TCP/IP 协议栈源代码。
LwIP 既可以移植到操作系统上,又可以在无操作系统的情况下独立运行。
LwIP 实现的重点是在保持TCP/IP 协议主要功能的基础上减少对RAM 的占用,这使LwIP 适合在低端嵌入式系统中使用。
其主要特点如下:(1)支持多网络接口下IP 转发;(2)支持ICMP 协议;(3)包括试验性扩展的UDP;(4)包括简单的拥塞控制,RTT 估算和快速恢复和快速转发的TCP;(5)提供专门的内部回调接口(Raw API)用于提高应用程序性能;(6)可选择的Berkeley 接口API;3、LwIP 协议栈移植到μC/OS II 操作系统的具体实现3.1 嵌入式系统结构和LwIP 接口整个嵌入式系统的结构如图 1 所示,由ARM 微处理器、网卡、网络设备驱动、μC/OSII 操作系统、LwIP 协议栈和应用程序组成。
图 1 嵌入式系统结构图LwIP 在设计时为了适应不同的操作系统,并没有在代码中使用和某个特定的操作系统相关的系统调用和数据结构,而是在LwIP 和操作系统之间提供了一个接口层(sys_arch interface),该接口主要实现的功能包括数据类型的定义、存储模式的选择、任务间的同步、时间和内存的管理等。
因此,完成LwIP 在μC/OS II 移植,我们就是要通过修改这个接口层来实现。
同时,还要根据自己所要实现的具体目的,可以对LwIP 协议栈进行一定的裁减。
lwip移植说明及心得

lwip移植说明及心得lwIP(lightweight IP)是一个轻量级的TCP/IP协议栈,适用于嵌入式系统。
它提供了TCP/IP协议的核心功能,包括IP、TCP、UDP和ICMP等。
在移植lwIP协议栈时,需要完成以下几个步骤:1. 硬件适配:lwIP协议栈需要根据具体硬件平台进行适配。
首先需要根据硬件平台的网络接口驱动,实现lwIP的网络接口层接口函数,包括接收和发送数据包的函数。
其次,还需要完成其他硬件相关的初始化工作,例如中断初始化、时钟初始化等。
2. 内存管理:lwIP协议栈需要进行内存管理,包括分配、释放和管理数据包的内存。
移植lwIP时,可以根据实际需求选择适合的内存管理方式,例如使用静态内存池或者动态内存分配算法。
3. 系统接口:lwIP需要与操作系统进行交互,包括线程管理、时间管理和互斥锁等。
在移植lwIP时,需要实现与目标操作系统相关的系统接口函数,并将其注册给lwIP。
4. 配置参数:lwIP协议栈有许多配置选项,可以根据实际的应用需求进行设置。
移植lwIP时,需要根据实际需求修改lwipopts.h文件中的配置选项,例如内存池的大小、TCP和UDP的最大连接数等。
在移植lwIP协议栈的过程中,我总结了以下几点心得:1. 在移植过程中,应该尽量保持lwIP协议栈的轻量级特性,避免不必要的代码和功能。
这样可以降低存储和计算资源的消耗,提高系统的性能和效率。
2. 在进行硬件适配时,需要仔细阅读lwIP的文档和源代码,了解其网络接口层的要求和接口函数的使用方式。
同时,还要根据硬件平台的特点做相应的调整和优化,以确保网络数据的稳定和高效传输。
3. 内存管理是lwIP移植的一个关键问题。
根据实际需求选用适合的内存管理方式,并进行合理的内存优化。
例如,可以通过调整内存池的大小、采用更高效的内存分配算法等方式,减小内存的占用和碎片化。
4. 系统接口的实现需要与目标操作系统紧密结合。
在实现系统接口函数时,要充分考虑操作系统的特点和限制,例如线程管理方式、时间管理方式和互斥锁的实现等。
基于ARM的LwIP协议栈研究与移植

LwIP(Lightweight IP)是一种专为嵌入式系统设计的轻量级TCP/IP协议。 它实现了TCP/IP协议栈的主要功能,包括IP、ICMP、IGMP、UDP、TCP等协议, 适用于内存受限的环境。LwIP具有可移植性、可扩展性、易用性等特点,因此 在嵌入式系统中得到了广泛应用。
三、基于FreeRTOS的LwIP移植
5、调试与测试:完成移植后,需要对系统进行调试和测试,确保网络连接的 稳定性和可靠性。这包括对网络接口的物理连接、软件配置、数据传输等进行 测试。
四、优化策略
为了提高基于ARM的LwIP协议栈的性能和效率,以下优化策略可以参考:
1、内存管理:由于嵌入式系统的内存资源有限,因此需要合理地管理内存。 可以采用内存池技术,预先分配一定数量的内存块,以减少内存碎片和内存分 配的时间开销。
一、实时操作系统FreeRTOS
FreeRTOS是一个开源的、可扩展的、适用于各种不同平台(包括ARM CortexM系列、AVR、PIC32等)的实时操作系统。FreeRTOS内核提供多任务调度、任 务优先级管理、中断处理等功能,使得嵌入式系统可以更加高效、可靠地进行 任务管理和资源分配。
二、LwIP协议
4、减少系统资源占用
在嵌入式系统中,资源通常是有限的。因此,为了优化系统的性能和可靠性, 可以减少系统资源占用的比例。例如,在使用任务堆栈时,可以使用较小的堆 栈大小来避免过多的内存占用;在使用中断处理函数时,可以尽量减少中断处 理函数的执行时间,避免长时间占用CPU资源。
五、结论
本次演示介绍了基于实时操作系统FreeRTOS的LwIP协议的移植和优化方法。 通过使用内存池技术、异步通信技术、优化协议栈处理函数以及减少系统资源 占用等优化方法,可以提高系统的性能和可靠性。在嵌入式系统中,基于 FreeRTOS的LwIP协议的移植和优化具有重要的意义和应用价值。
一步步移植uCOS-IIandLwIP(一)

一步步移植uCOS-IIandLwIP(一)STM32F103ZE下移植uCOS-II and LwIP 汇总本文主要记录嵌入式实时操作系统uCOS-II(Ver 2.85)和轻量型TCP/IP协议栈LwIP(Ver 1.4.1)在32bit单片机STM32F103ZE上的移植过程,并列举几个simple examples说明两者工作原理。
本文的叙述原则是“用到什么知识点,就查阅相关资料”,对于其它延伸知识点不再概述。
所需物资:- 硬件开发平台,本平台网卡为DM9000A- uCOS-II(Ver 2.85)源码,可直接从Micrium官网下载uCOS 在cortex-M3上的移植例程uCOSII-ST-STM32F103ZE-SK - LwIP(Ver 1.4.1)源码,下载链接LwIP1.4.1一、Lwip移植TCP/IP协议分为网络链路层、网络层、传输层和应用层四个部分,网络链路层主要涉及底层硬件驱动的编写,另外三个上次协议一般采用协议栈的方式软件实现。
要实现与其它网络设备通信,首当其冲的是要移植好底层网卡驱动。
LwIP协议栈已经为我们提供了网络链路底层接口,我们要做到主要工作涉及到以下几个方面:- 单片机与网卡DM9000芯片的通信;- 完善LwIP协议栈文件ethernetif.c接口函数,该部分的难点在于实现LwIP规定的struct pbuf类型的数据包与网卡数据之间相互转换;- 上层软件协议的simple explain;1、网卡DM9000底层驱动的编写首先查阅DM9000的Datasheet(建议直接从芯片官网上查找,一般会有该芯片的Application note or Demo)本文主要是运用DM9000的16-bit mode,其总线形式类似与intel 8080总线,涉及读写指令和数据的控制引脚为CS#、IOW#、IOR#、CMD,数据总线引脚SD0~SD15,中断引脚INT。
【RL-TCPnet网络教程】第10章 RL-TCPnet网络协议栈移植(FreeRTOS)

至此,RL-TCPnet 的移植工作就完成了,剩下就是系统配置和应用了。
2017年09月26日
版本:1.0
第 4 页 共 57 页
武汉安富莱电子有限公司
安富莱 STM32-V5 开发板 RL-TCPnet 教程
10.2.2 RL-TCPnet 配置说明(Net_Config.c)
10.2 STM32F407 移植 RL-TCPnet 协议栈 10.2.1 RL-TCPnet 网络协议栈移植
首先准备好一个简单的 FreeRTOS 工程模板,工程模板的制作就不做讲解了,这里的重点是教大家移 植 RL-TCPnet 协议栈。准备好的工程模板如下图所示(大家也可以制作其它任意的工程模板,不限制):
武汉安富莱电子有限公司
安富莱 STM32-V5 开发板 RL-TCPnet 教程
准备好工程模板后,就可以开始移植了。首先要做的就是将所有需要的文件放到工程模板里面。下面 分 4 步跟大家进行说明,当然,不限制必须使用下面的方法添加源码到工程,只要将需要的文件添加到工 程模板即可。 第 1 步:将我们 FreeRTOS 模板中制作好的 RL-ARM 文件夹复制粘贴到大家准备好的工程模板中。
10.1 移植前准备工作说明
学习本章节前,务必要优先学习第 6 章的底层驱动讲解。 RL-TCPnet 只有库,没有源码。库分为两个版本,一个用于调试的版本 TCPD_CM3.lib 和一个正式 版本 TCP_CM3.lib,当前的例子统一使用调试版本。另外注意,虽然是 CM3 版本的,但可同时用于 CM3 和 CM4 内核的 MCU,因为官方没有专门的 CM4 内核库。 测试时,请将网线接到路由器或者交换机上面测试,因为已经使能了 DHCP, 可以自动获取 IP 地址。 而且使能了 NetBIOS 局域网域名,用户只需在电脑端 ping armfly,就可以获得板子的 IP 地址。 如果要使用固定 IP 进行测试,请看附件 C。 网口使用的是 DM9161/9162(挨着 9 帧串口座的网口),而不是 DM9000。 找一个简单的工程,最好是跑马灯之类的,越简单越好,我们就在这个简单的工程上面移植即可。
tcpip协议栈

tcpip协议栈TCP/IP协议栈是当前网络通信中最基础和最重要的协议栈之一,它由四层组成,分别是网络接口层、网络层、传输层和应用层。
首先是网络接口层,它负责将数据从传输层传送到物理网络。
在这一层,数据被封装成数据帧,然后通过物理层的网卡发送出去。
常见的协议有以太网、Wi-Fi等。
接下来是网络层,主要负责寻址和路由功能。
数据在这一层被封装成数据包,其中包含源地址和目的地址。
在网络层,数据包通过IP协议进行传输,并依靠路由器等设备进行转发和寻址。
传输层负责数据的可靠传输。
常见的传输层协议有TCP和UDP。
TCP协议提供可靠的连接和流式传输,通过数据的分段、排序和检验,确保数据的可靠性。
而UDP协议则是一种无连接的传输协议,它不保证数据的可靠性,但传输效率较高。
最后是应用层,它是网络应用程序和用户之间的接口。
应用层协议有很多,例如HTTP、FTP、SMTP等。
HTTP协议是Web浏览器和服务器之间传输超文本的协议,FTP协议是用于文件传输的协议,SMTP协议是用于发送电子邮件的协议,它们都是基于TCP协议的。
TCP/IP协议栈的设计使得不同的网络设备和应用程序可以互相交互和通信。
它的优点是灵活性高,可扩展性强,同时在各个层次上实现了分层的模块化设计。
当然,它也存在一些缺点,如复杂性较高,协议过程中的开销较大。
总的来说,TCP/IP协议栈是现代网络通信的基石,它通过网络接口层、网络层、传输层和应用层的协同工作,实现了数据的封装、路由和传输,提供了可靠和高效的网络通信服务。
随着互联网的发展,TCP/IP协议栈也在不断演进和完善,为网络通信提供了更好的基础支撑。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
This article was downloaded by: [University of Jiangnan]On: 27 March 2015, At: 06:51Publisher: Taylor & FrancisInforma Ltd Registered in England and Wales Registered Number: 1072954 Registered office: Mortimer House, 37-41 Mortimer Street, London W1T 3JH, UKJournal of Discrete Mathematical Sciences andCryptographyPublication details, including instructions for authors and subscription information:/loi/tdmc20An abridged protocol stack for micro controller inplace of TCP/IPR. Seshadri aa Computer Centre, S.V. University , Tirupati , 517 502 , IndiaPublished online: 03 Jun 2013.PLEASE SCROLL DOWN FOR ARTICLEAn abridged protocol stack for micro controller in place of TCP/IP R.Seshadri ∗Computer CentreS.V .UniversityTirupati 517502IndiaAbstractThe existing TCP/IP protocol stack running in hosts takes lot of overhead while the node in network is for a specific purpose.For example transferring simple messages across network.If the node in the network is not a PC but,some thing like a micro controller,which measures some values and stores in its local memory,then it becomes lavishness in using the micro controller’s memory.As it is a node in a network,working with TCP/IP ,it should be able to transfer those values in the form of messages to other hosts which are in either local network or global network.But in micro controller terms the memory is expensive and compact.The existing TCP/IP stack consumes a few mega bytes of memory.Therefore it can’t be accommodated in the memory of micro controller.Hence one needs to reduce the memory consumption.In this regard,an abridged protocol which replaces the existing TCP/IP has been designed to suit the above needs.For this purpose,the TCP/IP have been combined with KEIL C51features for 8051micro controller to make it work in transferring messages in local area network as well as global network.The above scheme was implemented and tested and the system was working satisfac-torily.The results are found to be more effective in communicating information/message from the micro controller to a PC.Keywords :Ethernet,stack,Transmission Control Protocol (TCP ),Internet Protocol (IP ).Introduction to TCP/IPThe name TCP/IP refers to a suite of communication protocols.The name is misleading because TCP and IP are the only two of the dozens of protocols that compose the suite.Its name comes from two of the most ∗E-mail :ravalaseshadri@yahoo.co.in—————————————————–Journal of Discrete Mathematical Sciences &CryptographyVol.9(2006),No.3,pp.523–536c Taru Publications D o w n l o ade d b y [U n i v e r s i t y of J i a ng n a n ] a t 06:51 27 M a r ch 2015524R.SESHADRI important protocols in the suite,the Transmission Control Protocol (TCP)and the Internet Protocol (IP).TCP/IP originated out of the investigative research into networking protocols that the Department of Defense (DOD)initiated in 1969.In 1968,the DOD Advanced Research Projects Agency (APRA)began researching the network technology that is now called packet switching.The original focus of this research was to facilitate communication among the DOD community.However,the network that was initially constructed as a result of this research,then called ARPANET,gradually became known as the internet.In the early 1980’s,the TCP/IP protocols were developed.In 1983,they became standard protocols for ARPANET.It is often referred to as DOD protocol suite or the internet protocol suite.When two computers wish to exchange information over a network,there are several components that must be in place before the data can actually be sent and received.Ofcourse,the physical hardware must exist,which is typically either a Network Interface Card (NIC)or a serial communications port for dial-up network connections.Beyond this phys-ical connection,however computers also need to use a protocol,which defines the parameters of the communication between them.In short,a protocol defines “rules of the road”that each computer must follow so that all the systems in the network can exchange data.One of the most popular protocols is use today is TCP/IP ,which stands for transmission control/internet protocol.KEIL C51compiler basicsThe KEIL C51compiler has been written to allow C programmers to get code running quickly on 8051systems with little or no learning curve.However,to get the best from it,some appreciation of the under-lying hardware is desirable.The most basic decision to be made is which memory model to use.Implementation of abridged TCP/IP in C51[1]The conceptual overview and infrastructure of TCP/IP will be very immensive and fuzzy.Each protocol in the stack has its own functional ually Programmers choose a powerful high level language for implementation.High level language like ‘C’provides dynamic mem-ory allocation,buffer maintenance strong type checking etc.,which are useful in implementing protocols in an optimized way.D o w n l o a d e d b y [U n i v e r s i t y o f J i a n g n a n ] a t 06:51 27 M a r c h 2015MICRO CONTROLLER IN PLACE OF TCP/IP 525Existing paradigmThe native TCP/IP in the Linux system implements several features:Internet ProtocolIn the TCP ,UDP ,ICMP ,IGMP data gets transmitted as IP datagrams,so it is called as workhorse protocol.Currently,IP is implemented with the following features:IP routing:This provides the basic mechanism for routers to interconnectdifferent physical networks.IP routing is done by hop-by-hop basis.It uses a data structure called routing table which maintains source and destination addresses and the next hop router to which the datagram is to be sent.IP multicasting:This feature enables the IP to send the datagrams to theselective destination addresses.IP tunneling:This feature lets the other protocols to use the IP .Forexample IPX protocol can make use if IP tunneling to send its data.IP masquerading:If a Linux host is connected to the internet with IPmasquerade enabled,then computers connecting to it either on the same LAN or connected with modems can reach the internet as well,even though they have no officially assigned IP addresses.IP accounting:This keeps track of IP network traffic,performs packetlogging and produces some statistics.IP aliasing:This provides the possibility of setting multiple networkaddresses on the same low-level network device driver.It is typically used for services that act differently based on the address they listen on.Address Resolution ProtocolCurrently ARP implements two featuresGratuitous ARP:It occurs when a host sends an ARP request looking for its own IP address.This is done when the interface is configured at bootstrap time.Transmission Control Protocol:Currently TCP is implemented with the following features [2]:•Handle multiple simultaneous connections D o w n l o a d e d b y [U n i v e r s i t y o f J i a n g n a n ] a t 06:51 27 M a r c h 2015526R.SESHADRI•Hold sent segments until ack is received•Resend segments if no ack is received•Handle TCP options•Handle passive open (act as a server)•Handle active open (act as a client)•Assemble multiple segments•Assemble out-of-order segments•Discard duplicate received segments•Nagle algorithm•Van Jacobsen’s algorithm•Respect other end’s max segment size•Slow start on new connection•Estimate round trip time•Kam’s algorithm•Congestion avoidance algorithm•Handle urgent mode Code Description Code Description0Echo reply 3Destination unreachable 4Source quench 5Redirect8Echo 9Router advertisement10Router solicitation 11Time exceeded12Parameter problem 13Timestamp request14Timestamp reply 15Information request16Information reply 17Address mask request 18Address mask reply 30Traceroute31Datagram conversion errorProblems in existing paradigmThe above mentioned protocols and its feature are efficient in terms of functionality when the PC to PC communication is concerned.It took few Mbytes of memory in a x86system.As in case of micro controller the memory model is very compact when compared with the PC.Now our existing system can not be suited for porting in to micro controller,because it’s a spacious one.D o w n l o a d e d b y [U n i v e r s i t y o f J i a n g n a n ] a t 06:51 27 M a r c h 2015MICRO CONTROLLER IN PLACE OF TCP/IP 527Proposed paradigm [3]Not all the features mentioned above are required in terms of micro-controller.So we abridged them and implemented the following protocols and its features.The model for the proposed system is shown in Figure1.Figure 1Layers of the proposed systemInternet ProtocolIP routing:This provides the basic mechanism for routers to interconnect different physical networks.IP routing is done by hop-by-hop basis.It uses a datastructure called routing table which maintains source and destination addresses and the next hop router to which the datagram is to be sent.Address Resolution ProtocolARP will translate the IP address to the physical address of the destination host.It uses a lookup table (some times referred to as the ARP cache)to perform this translation.D o w n l o a d e d b y [U n i v e r s i t y o f J i a n g n a n ] a t 06:51 27 M a r c h 2015528R.SESHADRI Transmission Control ProtocolCurrently TCP is implemented with the following features:Handle multiple simultaneous connectionsHold sent segments until ack is receivedHandle TCP optionsHandle passive openInternet Control Message ProtocolIt is an interactive error reporting protocol.Currently it handles the following message types:Code Description0Echo reply3Destination unreachableImplementationSequence ofsteps followed toimplement an abridgedprotocol stack inplace of TCP/IP isshown in Figure2.Figure 2Sequence of steps D o w n l o a d e d b y [U n i v e r s i t y o f J i a n g n a n ] a t 06:51 27 M a r c h 2015MICRO CONTROLLER IN PLACE OF TCP/IP 529The following are the protocols,which has been implemented so as to reach the desired goal.ARP (Address Resolution Protocol )ICMP (Internet Control Message Protocol )IP (Internet Protocol )TCP (Transmission Control Protocol )HTTP (Hyper Text Transmission Protocol )ETH (Ethernet Protocol )Now let us see on by one protocol.Implementation of ARP [4]The data structures used in this protocol are as follows:typedef struct{ULONG ipaddr;UCHAR hwaddr[6];UCHAR timer;}ARP CACHE;This cache maintains the recent mappings from internet addresses to hardware addresses.The normal expiration time of entry in a cache is 0.5seconds from the time the entry was created.This time value is represented using the timer template member in the structure.typedef struct{UINT hardware type;UINT protocol type;UCHAR hwaddr len;UCHAR ipaddr len;UINT message type;UCHAR source hwaddr[6];ULONG source ipaddr;UCHAR dest hwaddr[6];ULONG dest ipaddr;}ARP HEADER;D o w n l o a d e d b y [U n i v e r s i t y o f J i a n g n a n ] a t 06:51 27 M a r c h 2015530R.SESHADRI This represents the ARP header.The methods which I used in this are as follows:UCHAR*arp resolve(ULONG)This method finds the ethernet hardware address for the given IP address,if destination IP is on the subnet then we want the eth address of destination,otherwise we want eth address of gateway.This will look in ARP cache first.If not found there,this will send ARP request.This will return pointer to the hardware address or NULL if not found.void arp rcve(UCHAR*)This handles incoming ARP messages.void arp send(UINT8*,UINT32,UINT8)This allocates memory for the entire outgoing message,including Ethernet and ip headers,then builds an outgoing ARP response message.void age arp cache(void)This is called every 60seconds to age the ARP cache.If an entry times out then it is deleted from the cache.void arp retransmit(void)This resends an ARP request if there was no response to the first one.It is called every 0.5seconds.If there is no response after 2retries,the datagram that IP was trying to send is deleted.Implementation of ICMPThe data structure used in this protocol is as follows:typedef struct{UCHAR msg type;UCHAR msg code;UINT checksum;ULONG msg data;UCHAR echo data;}ICMP ERR HEADER;typedef struct{UCHAR ver len;D o w n l o a d e d b y [U n i v e r s i t y o f J i a n g n a n ] a t 06:51 27 M a r c h 2015MICRO CONTROLLER IN PLACE OF TCP/IP 531UCHAR type of service;UINT total length;UINT identifier;UINT fragment info;UCHAR time to live;UCHAR protocol id;UINT header cksum;ULONG source ipaddr;ULONG dest ipaddr;}IP HEADER;typedef struct{UCHAR msg type;UCHAR msg code;UINT checksum;UINT identifier;UINT sequence;UCHAR echo data;}PING HEADER;ICMP messages are usually acted on by the IP layer,when an ICMP error message is sent,the message always contains the IP header and the first eight bytes of IP datagram that caused the ICMP error to be generated.So used the above two data structures.The methods which were used in this are as follows:void ping send(UCHAR*,ULONG,UINT)This builds a ping response message.It allocates memory for the entire outgoing message,including Eth and IP headers.void dest unreach send(UCHAR*,ULONG)This builds an outgoing ICMP destination port unreachable response message.void icmp rcve(UCHAR*,UINT)This handles incoming ICMP messages.And displays what type of error it is.D o w n l o a d e d b y [U n i v e r s i t y o f J i a n g n a n ] a t 06:51 27 M a r c h 2015Implementation of IPThe data structure used in this protocol is as follows:typedef struct{UCHAR ver len;UCHAR type of service;UINT total length;UINT identifier;UINT fragment info;UCHAR time to live;UCHAR protocol id;UINT header cksum;ULONG source ipaddr;ULONG dest ipaddr;}IP HEADER;This represents the IP header.The methods followed are as follows:void ip send(UCHAR*,ULONG,UCHAR,UINT)This builds outgoing IP datagrams.It adds the 20byte IP header and checksum then forwards the IP datagram to the Ethernet layer for sending.void ip rcve(UCHAR*)This handles incoming IP datagrams from the Ethernet layer.Implementation of TCP [5]The data structure used in this protocol is as follows:typedef struct{UINT source yort;UINT dest yort;ULONG sequence;ULONG ack number;UINT flags;UINT window;UINT checksum;D o w n l o a d e d b y [U n i v e r s i t y o f J i a n g n a n ] a t 06:51 27 M a r c h 2015UINT urgent ytr;UCHAR options;}TCP HEADER;This represents the TCP header.typedef struct{UCHAR ver len;UCHAR type of service;UINT total length;UINT identifier;UINT fragment info;UCHAR time to live;,UCHAR protocol id;UINT header cksum;ULONG source ipaddr;ULONG dest ipaddr;}IF HEADER;The methods which I used in this are as follows:void TCP send(UINT,UNIT,UCHAR)This sends a TCP segments that do not include any data.void TCP rcve(UCHAR*,UINT)This handles incoming TCP messages and manages the TCP state ma-chine.void TCP retransmit(void)This runs every 0.5seconds.If the other end has not acknowledged everything we have sent,resends it.To save RAM space,we regenerate a segment rather than keeping a bunch segments hanging around eating up RAM.A connection should not be in an opening or closing state when this timer expires,so we simply send a reset.If a connection is in the ESTABLISHED state when the timer expires then we have just sent a web page so resend the page.void TCP inactivity(void)This runs every 0.5seconds.If the connection has had no activity it initiates closing the connection.D o w n l o a d e d b y [U n i v e r s i t y o f J i a n g n a n ] a t 06:51 27 M a r c h 2015Implementation of HTTPThe data structure used in this protocol is as follows:typedef struct{UCHAR ver len;UCHAR type of service;UINT total length;UINT identifier;UINT fragment info;UCHAR time to live;UCHAR protocol id;UINT header cksum;ULONG source ipaddr;ULONG dest ipaddr;}IP HEADER;typedef struct{UINT source-port;UINT dest-port;ULONG sequence;ULONG ack number;UINT flags;UINT window;UINT checksum;UINT urgent-ptr;UCHAR options;}TCP HEADER;The methods which I used in this are as follows:void init http(void)UINT http server(UCHAR*,UINT,UCHAR,UCHAR)This serves up either a HTML page,a JPEG image,or controls an LED,depending what it gets from the browser.The received header must contain the word “GET”or “POST”)to be considered a valid request.Implementation of ethernet protocolThe data structure used in this protocol is as follows:D o w n l o a d e d b y [U n i v e r s i t y o f J i a n g n a n ] a t 06:51 27 M a r c h 2015typedef struct{UCHAR dest hwaddr[6];UCHAR source hwaddr[6];UINT frame type;}ETH HEADER;The methods which I used in this are as follows:void eth rcve(UCHAR*)This is the handler for incoming Ethernet frames.This is designed to handle standard Ethernet frames.void eth send(UCHAR*,UCHAR*,UINT,UIN1)This adds the ethernet header and sends completed Ethernet frame to micro controller.Testing•Here the test case is the acquisition of power measurement in the micro controller in the form of HTTP reply.•For this we initialized the microcontroller with the IP address 192.168.0.15and passed the HTTP request.•The HTTP request is passed from another host in the network through the internet explorer.•HTTP reply from the micro controller is as given below.D o w n l o a d e d b y [U n i v e r s i t y o f J i a n g n a n ] a t 06:51 27 M a r c h 2015Conclusion•This paper clearly shown that it is possible to implement “An Abridged Protocol Stack for Micro Controller in place of TCP/IP”using KEIL C51in Windows operating system.•The Micro Controller is made itself to work in a Network instead of PC’s.Now some of the cost based measures like space,complexity,effort are reduced.Micro Controller is highly economical when com-pared with PC’s.Future enhancements•This can be enhanced to support Wireless communication over Eth-ernet by implementing the 802.11standards.This can be done easily because this abridged stack can adapt a new protocol easily.•Right now there is no any security for the data in the micro controller,i.e any body can have access to it.In future this can be avoided by implementing authentication methods like LDAP etc.•We can enhance this abridged protocol stack by adding some extra features to current protocols,so that it can be more efficient in communicating data,while the configuration of the system also upgraded.•In future this can be enhanced and implement for Linux and other operating systems also.References[1]M.Beach,C51Primer .[2][3]W.Richard Stevens,TCP/IP Illustrated ,Vol.1.[4] C.Hunt,TCP/IP Network Administration .[5]W.R.Stevens,TCP/IP Illustrated ,Vol.1.Received April,2006D o w n l o a d e d b y [U n i v e r s i t y o f J i a n g n a n ] a t 06:51 27 M a r c h 2015。