Micro Vibe

My Micro Hobby Projects

  • Increase font size
  • Default font size
  • Decrease font size
Home MIC80 Documents MIC80 Network Stack Overview

MIC80 Network Stack Overview


This article provides an overview of the MIC80 Ethernet IP stack. The current MIC80 Ethernet IP stack provides the following network protocols; ARP, ICMP Echo, IP,  UDP, DHCP and simple DNS domain name to IP address resolution. The IP support for MIC80 allows for fragmented IP packets. The MIC80 IP stack API is composed of a number of support functions that can be called from a user level program. This article is intended as an overview of the use of the MIC80 EBIOS network support functions. The EBIOS support functions are referenced in this article by there source code labels in the EZ80 source assembler file "eZ80-CPM-BIOS.inc". For a list of the EBIOS support functions, there jump table address and parameters see the article EBIOS Reference Guide. The MIC80 network stack support functions all use EZ80 ADL memory mode. This requires any user program to call into the API using an ADL call instruction. If the user program is not running in ADL mode such as a program running under the CPM2.2 monitor a EZ80 "CALL.LIL" instruction should be used to enter ADL mode. The disk image provided with the MIC80 project files contains a Turbo Pascal source code file, "IPSTACK.INC" that contains examples of using the network stack API from a non ADL mode program. Currently the network API is accessed via a jump table located in ADL memory in the EBIOS (extended BIOS). Each of the jump table entries in the EBIOS is five bytes in size. The jump table is located in the EZ80 source assembler file "eZ80-CPM-BIOS.inc". The base address for EBIOS jump table is 010800h.

ARP support:

The MIC80 EBIOS contains the support code for the ARP protocol. The ARP protocol is used to resolve the hardware MAC address of a network host from a network IP address. The ARP protocol requires that the resolved host IP address be on the same IP sub-net as the host resolving the address. The MAC address is required for Ethernet hardware to send a packet to another Ethernet hardware device. The MIC80 ARP support requires no intervention from a user level program once the network stack is initialized.

When a user program attempts to send an IP packet to a host on the same network sub-net the MIC80 will look in it's ARP cache to see if it already knows the MAC address for the given IP address. If there is no valid record in the ARP cache the MIC80 will send an ARP request to resolve the IP address and will fail the sending of the IP packet with a "resolving address" error code. After receiving this error code the user level program should wait a suitable amount of time to allow a response to the ARP request before attempting to send the IP packet again.

It is possible for a host's IP address to change over time and for an IP address to be reassigned to a new host. The MIC80 ARP protocol support uses a background timer to limit the life of an ARP cache entry to about three minutes. When the background timer expires an ARP cache entry it will send an ARP request  to the cache entry IP address. If a host responds the ARP cache will be updated and the time out period will reset to three minutes.

The MIC80 network stack will automatically respond to an ARP request from another network host. There is no requirement of the user level program to manage the ARP protocol and there are no EBIOS support functions.

ICMP support:

The MIC80 EBIOS contains the support code for the ICMP protocol. Currently only "ICMP Echo" packets are supported. In the future I would like to add support for ICMP error responses such as, invalid host, invalid protocol, and invalid port. The latter ICMP error packet is used by port scanning programs to find active ports on a networked host.

The MIC80 EBIOS will respond to ICMP Echo packets received from another host in the background. If the Echo packet data size is larger then the Ethernet maximum transmission size (MTU) the response will be sent as a fragmented IP packet. If the data size of a received ICMP Echo packet is larger then the configured maximum IP packet size no response will be sent by the MIC80. There is no requirement of the user level program to manage the response to an ICMP Echo and there are no EBIOS support functions.

User level programs can use the EBIOS to send an ICMP Echo request. The EBIOS contains two functions used to send ICMP Echo packets. The first function called "E_SndPing" in the EBIOS source code will send an ICMP Echo packet to another host. The EBIOS "E_SndPing" function requires two parameters; 1) the IP address of the host, 2) the size of the data section of the ICMP Echo packet. If the Echo packet can be sent the function returns an identifier. The second function provided by the EBIOS, "E_GetEchoId" is used to read the identifier of the last valid Echo packet response received by the MIC80. The allows a user level program to send an Echo packet then poll the last received identifier. This way the user level program does not have to block waiting for a response.

IP Support:

The MIC80 EBIOS contains IP support for a network based on Ethernet using four byte IP addresses also know as IPV4. The EBIOS allows for the use of fragmented IP packets and provides out of order packet assembly buffers. The IP protocol provides the mechanism used to transfer data packets between hosts using there IP addresses. Network protocols such as UDP and TCP ride on top of the IP protocol.

The MIC80 IP stack does not support a routing table as there is only one network interface and the IP stack currently allows for only one gateway device. There is currently no EBIOS user program support for raw IP packets. There is no requirement for a user level program to manage the IP protocol and there are no EBIOS support functions. There are a number of EBIOS user level support functions to set the basic IP stack parameters such as IP address, sub-net mask, gateway, and host name. As well the are EBIOS support functions for the initialization and shutdown of the IP stack. See the section "Configuration And Start-up" below for more information regarding EBIOS support functions.

DHCP Support:

The current DHCP support code has not been converted to EZ80 assembler code and is only available through utility programs written in Turbo Pascal. The utility programs "NETWORK.COM" and "DHCP.COM" can be used to connect to a DHCP server and populate the EBIOS IP settings with the values retrieved from the DHCP server. The utility programs and there source code can be found on the "A" disk ROM image included with the project source files. The EBIOS does provide two function used to set and read the current DHCP server address. When a DHCP acquire address request is made the 4 byte IP address of the DHCP server should be saved using the "IpSetDhcpAdr" EBIOS support function. When a DHCP renew or release request is to be sent the program should use the EBIOS "IpGetDhcpAdr" support function to read the 4 byte IP address of the DHCP server.

IP Address Resolution:

The MIC80 EBIOS contains a number of support functions to convert a string of text to an IP 4 byte address. There are two main EBIOS support functions "RES_ResFirst" and "RES_ResNext" which are used to convert a user supplied string of characters representing an IP address into a 4 byte network address. The EBIOS support function "RES_ResFirst" is called first with the address of the string to be converted. If the supplied string is in dotted decimal format it is converted to an IP4 address. If the string is not a dotted decimal string it is assumed to contains a  domain name. A DNS request is made for the "A" records for the supplied domain name. If more then one DNS "A" record is returned the "RES_ResFirst" support function returns the first IP 4 byte address found in the DNS response. The EBIOS support function "RES_ResNext " is then used to read any additional addresses returned. The DNS server IP address must be set in the MIC80 EBIOS IP settings before a domain name can be resolved. The EBIOS IP settings allow for two DNS servers to be configured. The primary DNS is always used first and the secondary DNS is only used if no DNS response is received from the primary DNS server.

The MIC80 EBIOS contains support functions to convert a string in dotted decimal format to a 4 byte IP address. The EBIOS function "RES_StrToIp4" converts a dotted decimal format string into a 4 byte IP address. A second support function "RES_ExStrToIp4" converts a partial IP dotted notation string to an IP 4 byte address. The missing higher octets are filled in using the current EBIOS IP address. At a minumum one octet must be provided. The first character of the partial IP4 dotten notation string may be a '.' if so it is ignored.

The EBIOS also contains the support function "RES_Ip4ToStr" to convert a 4 byte IP 4 byte address to a dotted decimal IP address string.

UDP Support:

The MIC80 EBIOS contains a number of functions to support UDP packet transfer. UDP rides on top of the IP protocol and adds the ability to use a "port" number to identify the source and destination channels for a data packet.

To use UDP the EBIOS must be used to start the IP stack using the support function "IpInit". To check if the IP stack is already running use the EBIOS support function "IpIsInit". Once the IP stack is running a user level program must acquire a socket handle using the EBIOS support function "E_UdpOpenSkt". The support function takes one parameter which indicates the local port number for the UDP socket and a second parameter to control the reception of broadcast UDP packets. If a port number of zero is provided by a user program the next unused port number will be assigned to the UDP socket. The EBIOS "E_UdpCloseSkt" support function should be used to close and free a previously open UDP socket. The default EBIOS allows up to 4 UPD sockets to be open at once.

There are a number of EBIOS support functions to read data packets sent by a remote host to an open UDP socket. The "E_UdpRead" support function is used to read the next UDP packet from an open socket. The support function "E_UdpPeer" can be used to retrieve the IP address and UDP port of the remote host that send the last UDP packet read. The EBISO support function "E_UdpReadFrm" combines a "E_UdpRead" and "E_UdpPeer" in a single function returning the UDP packet and the sending host IP address and UDP port.

The EBIOS provides two support functions to send a UDP packet. The first support function "E_UDPSend" is used to send a UDP packet to the remote host IP address and UDP port of the last UDP packet read from the open socket. The "E_UdpSend" function can not be used until at least one UDP packet is read by the user program from an open UDP socket. The EBIOS support function "E_UdpSendTo" allows a UDP packet to be sent to any host IP address and port. The "E_UdpSendTo" function requires an open UDP socket, the data to transfer and the IP address and UDP port of the host to send the UDP packet to.

Each UDP socket contains a receive FIFO capable of holding 4 maximum size UDP packets or a larger number of smaller UDP packets. This allows a user level program to receive UDP packets in the background. 

For the sending of UDP packets the EBIOS maintains a single UDP transmit FIFO. All open UDP sockets share this single UDP transmit FIFO. If a socket is closed before all of its UDP packets have been sent all the packets in the transmit FIFO will be send. Once a UDP socket is closed all unread UDP packets are lost.

Configuration And Start-up:

There are a number of EBIOS support functions used to set the IP stack parameters. The "IPConfig" support function is used to set basic IP stack parameters; IP address, sub-net mask, gateway address, DNS primary and secondary servers, and the 6 byte MAC address. The parameters are packed into a 26 byte structure and the address of the structure is passed as a parameter to the support function. The "IPGetConfig" support function is used to copy the current IP stack parameters to user program supplied buffer. The support function "IpSetHostName" is used to set a host name to be sent with a DHCP acquire request. The host name is stored in a character string where the first byte is the length of the string. The "IpGetHostName" support function can be used to copy the current host name to a user program supplied buffer. The buffer will need to be one byte longer then the length of the host name to accommodate the one byte length field at the start of the string.

Before the IP stack will run you must call the support function "IpInit" to initialize all IP stack variables and start the EMAC and PHY hardware. The IP stack is driven by hardware interrupts from the EMAC and TIMER0 EZ80 on-board devices. The support function "IpInit" requires two parameters, one specifies if the PHY should use 100Mbs or 10Mbs, anda second parameter to select between full and half duplex. Once the IP stack is running a call to the EBIOS support function "IpDone" is used to stop the IP stack and disable the hardware. Once the IP stack is running a CPM monitor warm boot will not alter the state of the IP stack. The IP stack is only reset on a MIC80 system reset. A user program can test to see if the IP stack is running by calling the "IsIpInit" EBIOS support function and should never call the "IpInit" support function if the IP stack is already running.


Last Updated on Saturday, 07 November 2009 10:27