Subversion Repositories HomeAutomation

Rev

Rev 363 | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. /*********************************************************************
  2.  *
  3.  *                  IP Defs for Microchip TCP/IP Stack
  4.  *
  5.  *********************************************************************
  6.  * FileName:        IP.h
  7.  * Dependencies:    StackTsk.h
  8.  *                  MAC.h
  9.  * Processor:       PIC18, PIC24F, PIC24H, dsPIC30F, dsPIC33F
  10.  * Complier:        Microchip C18 v3.02 or higher
  11.  *                  Microchip C30 v2.01 or higher
  12.  * Company:         Microchip Technology, Inc.
  13.  *
  14.  * Software License Agreement
  15.  *
  16.  * This software is owned by Microchip Technology Inc. ("Microchip")
  17.  * and is supplied to you for use exclusively as described in the
  18.  * associated software agreement.  This software is protected by
  19.  * software and other intellectual property laws.  Any use in
  20.  * violation of the software license may subject the user to criminal
  21.  * sanctions as well as civil liability.  Copyright 2006 Microchip
  22.  * Technology Inc.  All rights reserved.
  23.  *
  24.  * This software is provided "AS IS."  MICROCHIP DISCLAIMS ALL
  25.  * WARRANTIES, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, NOT LIMITED
  26.  * TO MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
  27.  * INFRINGEMENT.  Microchip shall in no event be liable for special,
  28.  * incidental, or consequential damages.
  29.  *
  30.  *
  31.  * Author               Date    Comment
  32.  *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  33.  * Nilesh Rajbharti     4/27/01 Original        (Rev 1.0)
  34.  * Nilesh Rajbharti     2/9/02  Cleanup
  35.  * Nilesh Rajbharti     5/22/02 Rev 2.0 (See version.log for detail)
  36.  ********************************************************************/
  37.  
  38. #ifndef IP_H
  39. #define IP_H
  40.  
  41. #include "..\Include\StackTsk.h"
  42. #include "..\Include\MAC.h"
  43.  
  44.  
  45. #define IP_PROT_ICMP    (1)
  46. #define IP_PROT_TCP     (6)
  47. #define IP_PROT_UDP     (17)
  48.  
  49.  
  50. /*
  51.  * IP packet header definition
  52.  */
  53. typedef struct _IP_HEADER
  54. {
  55.     BYTE    VersionIHL;
  56.     BYTE    TypeOfService;
  57.     WORD    TotalLength;
  58.     WORD    Identification;
  59.     WORD    FragmentInfo;
  60.     BYTE    TimeToLive;
  61.     BYTE    Protocol;
  62.     WORD    HeaderChecksum;
  63.     IP_ADDR SourceAddress;
  64.     IP_ADDR DestAddress;
  65.  
  66. } IP_HEADER;
  67.  
  68.  
  69. /*********************************************************************
  70.  * Function:        BOOL IPIsTxReady(BOOL HighPriority)
  71.  *
  72.  * PreCondition:    None
  73.  *
  74.  * Input:           None
  75.  *
  76.  * Output:          TRUE if transmit buffer is empty
  77.  *                  FALSE if transmit buffer is not empty
  78.  *
  79.  * Side Effects:    None
  80.  *
  81.  * Note:            None
  82.  *
  83.  ********************************************************************/
  84. #define IPIsTxReady(HighPriority)       MACIsTxReady(HighPriority)
  85.  
  86.  
  87. /*********************************************************************
  88.  * Macro:           IPSetTxBuffer(a, b)
  89.  *
  90.  * PreCondition:    None
  91.  *
  92.  * Input:           a       - Buffer identifier
  93.  *                  b       - Offset
  94.  *
  95.  * Output:          Next Read/Write access to transmit buffer 'a'
  96.  *                  set to offset 'b'
  97.  *
  98.  * Side Effects:    None
  99.  *
  100.  * Note:            None
  101.  *
  102.  ********************************************************************/
  103. #define IPSetTxBuffer(a, b) MACSetTxBuffer(a, b+sizeof(IP_HEADER))
  104.  
  105.  
  106.  
  107. /*********************************************************************
  108.  * Function:        WORD IPPutHeader(   IP_ADDR *Dest,
  109.  *                                      BYTE    Protocol,
  110.  *                                      WORD    Identifier,
  111.  *                                      WORD    DataLen)
  112.  *
  113.  * PreCondition:    IPIsTxReady() == TRUE
  114.  *
  115.  * Input:           Src         - Destination node address
  116.  *                  Protocol    - Current packet protocol
  117.  *                  Identifier  - Current packet identifier
  118.  *                  DataLen     - Current packet data length
  119.  *
  120.  * Output:          Handle to current packet - For use by
  121.  *                  IPSendByte() function.
  122.  *
  123.  * Side Effects:    None
  124.  *
  125.  * Note:            Only one IP message can be transmitted at any
  126.  *                  time.
  127.  *                  Caller may not transmit and receive a message
  128.  *                  at the same time.
  129.  *
  130.  ********************************************************************/
  131. WORD    IPPutHeader(NODE_INFO *remote,
  132.                     BYTE protocol,
  133.                     WORD len);
  134.  
  135.  
  136. /*********************************************************************
  137.  * Macro:           IPPutArray(a, b)
  138.  *
  139.  * PreCondition:    IPIsTxReady() == TRUE
  140.  *
  141.  * Input:           a       - Data buffer
  142.  *                  b       - Buffer length
  143.  *
  144.  * Output:          None
  145.  *
  146.  * Side Effects:    None
  147.  *
  148.  * Note:            Data is copied to IP data area.
  149.  *
  150.  ********************************************************************/
  151. #define IPPutArray(a, b)    MACPutArray(a, b)
  152.  
  153.  
  154.  
  155.  
  156. /*********************************************************************
  157.  * Function:        BOOL IPGetHeader( IP_ADDR    *localIP,
  158.  *                                    NODE_INFO  *remote,
  159.  *                                    BYTE        *Protocol,
  160.  *                                    WORD        *len)
  161.  *
  162.  * PreCondition:    MACGetHeader() == TRUE
  163.  *
  164.  * Input:           localIP     - Local node IP Address as received
  165.  *                                in current IP header.
  166.  *                                If this information is not required
  167.  *                                caller may pass NULL value.
  168.  *                  remote      - Remote node info
  169.  *                  Protocol    - Current packet protocol
  170.  *                  len         - Current packet data length
  171.  *
  172.  * Output:          TRUE, if valid packet was received
  173.  *                  FALSE otherwise
  174.  *
  175.  * Side Effects:    None
  176.  *
  177.  * Note:            Only one IP message can be received.
  178.  *                  Caller may not transmit and receive a message
  179.  *                  at the same time.
  180.  *
  181.  ********************************************************************/
  182. BOOL IPGetHeader(IP_ADDR *localIP,
  183.                  NODE_INFO *remote,
  184.                  BYTE *protocol,
  185.                  WORD *len);
  186.  
  187.  
  188. /*********************************************************************
  189.  * Macro:           IPDiscard()
  190.  *
  191.  * PreCondition:    MACGetHeader() == TRUE
  192.  *
  193.  * Input:           None
  194.  *
  195.  * Output:          Current packet is discarded and buffer is
  196.  *                  freed-up
  197.  *
  198.  * Side Effects:    None
  199.  *
  200.  * Note:            None
  201.  *
  202.  ********************************************************************/
  203. #define IPDiscard()         MACDiscard()
  204.  
  205.  
  206.  
  207. /*********************************************************************
  208.  * Macro:           IPGetArray(a, b)
  209.  *
  210.  * PreCondition:    MACGetHeader() == TRUE
  211.  *
  212.  * Input:           a       - Data buffer
  213.  *                  b       - Buffer length
  214.  *
  215.  * Output:          None
  216.  *
  217.  * Side Effects:    None
  218.  *
  219.  * Note:            Data is copied from IP data to given buffer
  220.  *
  221.  ********************************************************************/
  222. #define IPGetArray(a, b)    MACGetArray(a, b)
  223.  
  224.  
  225.  
  226.  
  227. /*********************************************************************
  228.  * Function:        IPSetRxBuffer(WORD Offset)
  229.  *
  230.  * PreCondition:    IPHeaderLen must have been intialized by
  231.  *                  IPGetHeader() or IPPutHeader()
  232.  *
  233.  * Input:           Offset from beginning of IP data field
  234.  *
  235.  * Output:          Next Read/Write access to receive buffer is
  236.  *                  set to Offset
  237.  *
  238.  * Side Effects:    None
  239.  *
  240.  * Note:            None
  241.  *
  242.  ********************************************************************/
  243. void IPSetRxBuffer(WORD Offset);
  244.  
  245.  
  246.  
  247.  
  248.  
  249. #endif
  250.  
  251.  
  252.  
  253.