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。