net/ip.h File Reference

IP Module for Modtronix TCP/IP Stack. More...

#include "net\mac.h"

Data Structures

union  _IP_ADDR
struct  _IP_HEADER
struct  _NODE_INFO

Defines

#define IP_PROT_ICMP   (1ul)
#define IP_PROT_TCP   (6ul)
#define IP_PROT_UDP   (17ul)
#define IPDiscard()   MACDiscard()
#define IPGetArray(a, b)   MACGetArray(a, b)
#define IPIsTxReady(HighPriority)   MACIsTxReady(HighPriority)
#define IPPutArray(a, b)   MACPutArray(a, b)
#define IPSetTxBuffer(buffer, offset)   MACSetTxBuffer(buffer, offset+sizeof(IP_HEADER))
#define MY_IP_TTL   (100ul)

Typedefs

typedef union _IP_ADDR IP_ADDR
typedef struct _IP_HEADER IP_HEADER
typedef struct _NODE_INFO NODE_INFO

Functions

BOOL IPGetHeader (IP_ADDR *localIP, NODE_INFO *remote, BYTE *protocol, WORD *len)
WORD IPPutHeader (NODE_INFO *remote, BYTE protocol, WORD len)
void IPSetRxBuffer (WORD offset)


Detailed Description

IP Module for Modtronix TCP/IP Stack.

Author:
Modtronix Engineering
Dependencies:
stacktsk.h, mac.h
Compiler:
MPLAB C18 v2.10 or higher
HITECH PICC-18 V8.35PL3 or higher

Description

This module contains the IP code.
For a detailed description, see the IP section of this document - in [Modules] [TCP/IP Stack] [TCP/IP Base Protocols].

Configuration

The following defines are used to configure this module, and should be placed in the projdefs.h (or similar) file. For details, see Project Configuration. To configure the module, the required defines should be uncommended, and the rest commented out.
 //*********************************************************************
 //-------------------- IP Configuration --------------------
 //*********************************************************************
 //Time-To-Live in Seconds
 #define MY_IP_TTL   (100ul)
 //When defined, the code will be compiled for optimal speed. If not defined, code is defined
 //for smallest size.
 #define IP_SPEED_OPTIMIZE

Define Documentation

#define IP_PROT_ICMP   (1ul)

#define IP_PROT_TCP   (6ul)

#define IP_PROT_UDP   (17ul)

 
#define IPDiscard (  )     MACDiscard()

Pre-Condition:
MACGetHeader() == TRUE
Returns:
Current packet is discarded and buffer is freed up

#define IPGetArray ( a,
 )     MACGetArray(a, b)

Data is copied from IP data to given buffer

Pre-Condition:
MACGetHeader() == TRUE
Parameters:
a Data buffer
b Buffer length

#define IPIsTxReady ( HighPriority   )     MACIsTxReady(HighPriority)

Check if ready for next transmission.

Parameters:
HighPriority High priority messages are those that don't need to be acknowledged before being discarded (TCP control packets, all ICMP packets, all UDP packets, etc.)
Returns:
TRUE if transmit buffer is empty
FALSE if transmit buffer is not empty

#define IPPutArray ( a,
 )     MACPutArray(a, b)

Data is copied to IP data area.

Pre-Condition:
IPIsTxReady() == TRUE
Parameters:
a Data buffer
b Buffer length

#define IPSetTxBuffer ( buffer,
offset   )     MACSetTxBuffer(buffer, offset+sizeof(IP_HEADER))

This function makes the given transmit buffer active, and sets it's access pointer to be:

  • At the given offset after the IP header
  • In the given TX Buffer
    So, if we pass 0 in as the offset, we will set the pointer to the first byte of after the IP header. All future read and writes to the TX Buffer will be to the set location.

Parameters:
buffer Buffer identifier
offset Offset

#define MY_IP_TTL   (100ul)


Typedef Documentation

typedef union _IP_ADDR IP_ADDR

Structure to store an IP address. For example, if IP address is "192.168.1.0", then:

typedef struct _IP_HEADER IP_HEADER

IP packet header definition

typedef struct _NODE_INFO NODE_INFO

Structure to store a nodes info


Function Documentation

BOOL IPGetHeader ( IP_ADDR localIP,
NODE_INFO remote,
BYTE protocol,
WORD len 
)

Only one IP message can be received. Caller may not transmit and receive a message at the same time. If this function returns false, the caller must call MACDiscardRx() to discard and release the current receive buffer!

Pre-Condition:
MACGetHeader() == TRUE
Parameters:
localIP Local node IP Address (Destination IP Address) as received in current IP header. If this information is not required caller may pass NULL value.
remote Remote node info
protocol Current packet protocol
len Length of IP data. For example, if TCP is contained in this IP packet, this will be = TCP Header length + TCP Data Length
Returns:
TRUE, if valid packet was received
FALSE otherwise - call MACDiscardRx() to discard message if FALSE is returned !!

WORD IPPutHeader ( NODE_INFO remote,
BYTE  protocol,
WORD  len 
)

Write the Ethernet Header (MAC Header) and IP Header to the current TX buffer. The last parameter (len) is the length of the data to follow. This function will do the following:

  • Reset the NIC Remote DMA write pointer to the first byte of the current TX Buffer
  • Write the given header
  • Set the NIC Remote DMA byte count to the given len. This configures the Remote DMA to receive the given number of bytes. Only one IP message can be transmitted at any time. Caller may not transmit and receive a message at the same time.

Pre-Condition:
IPIsTxReady() == TRUE
Parameters:
remote Destination node address
protocol Protocol of data to follow, for example IP_PROT_ICMP, IP_PROT_TCP....
len Total length of IP data bytes to follow, excluding IP header. This is the length of the bytes to follow.
Returns:
Handle to current packet - For use by IPSendByte() function.

void IPSetRxBuffer ( WORD  offset  ) 

Sets the receive buffer access pointer to given offset in IP Data. For example, if IP data is a TCP packet, an offset of 0 will set access to first byte of TCP header. Layers that use IP services (TCP, UDP...) should call this macro to set the access pointer for the current buffer.

Parameters:
offset Offset, An offset with respect to IP Data


Generated on Wed Feb 3 12:45:35 2010 for SBC65EC Web Server by  doxygen 1.5.8