dhcpcCommonLib.h
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:7k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* dhcpcCommonLib.h - common include file for run-time and boot-time client */
  2. /* Copyright 1984 - 2001 Wind River Systems, Inc. */
  3. #include "copyright_wrs.h"
  4. /*
  5. modification history
  6. --------------------
  7. 01m,08jan02,wap  fix duplicate error codes (SPR #72103)
  8. 01l,09oct01,rae  merge from truestack (SPR 69850)
  9. 01k,07sep00,spm  moved client-specific transmit routine from shared module
  10. 01j,05apr00,spm  added entries for boot-time client shared code
  11. 01i,24nov99,spm  upgraded to RFC 2131 and removed direct link-level access
  12. 01h,17mar99,spm  enabled dhcpcRelease() routine (SPR #25482)
  13. 01g,06oct97,spm  added relative paths to #include statements; removed warnings
  14. 01f,06aug97,spm  removed parameters linked list to reduce memory required;
  15.                  added definitions for C++ compilation
  16. 01e,10jun97,spm  isolated incoming messages in state machine from input hooks
  17. 01d,06may97,spm  added DHCPC_OFF to align IP header on four byte boundary
  18. 01c,07apr97,spm  added shutdown return code
  19. 01b,29jan97,spm  added little-endian support and modified for coding standards
  20. 01a,03oct96,spm  created by modifying WIDE project DHCP implementation
  21. */
  22. #ifndef __INCdhcpClientCommonh
  23. #define __INCdhcpClientCommonh
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. #include "dhcp/dhcpc.h"
  28. #include "rngLib.h"
  29. #define S_dhcpcLib_NOT_INITIALIZED           (M_dhcpcLib | 1)
  30. #define S_dhcpcLib_BAD_DEVICE                (M_dhcpcLib | 2)
  31. #define S_dhcpcLib_MAX_LEASES_REACHED        (M_dhcpcLib | 3)
  32. #define S_dhcpcLib_MEM_ERROR                 (M_dhcpcLib | 4)
  33. #define S_dhcpcLib_BAD_COOKIE                (M_dhcpcLib | 5)
  34. #define S_dhcpcLib_NOT_BOUND                 (M_dhcpcLib | 6)
  35. #define S_dhcpcLib_BAD_OPTION                (M_dhcpcLib | 7)
  36. #define S_dhcpcLib_OPTION_NOT_PRESENT        (M_dhcpcLib | 8)
  37. #define S_dhcpcLib_TIMER_ERROR               (M_dhcpcLib | 9)
  38. #define S_dhcpcLib_OPTION_NOT_STORED         (M_dhcpcLib | 10)
  39. /* Define sources for events. */
  40. #define DHCP_AUTO_EVENT 0
  41. #define DHCP_USER_EVENT 1
  42. /*  Define types of events. */
  43. #define DHCP_MSG_ARRIVED 0
  44. #define DHCP_TIMEOUT 1
  45. #define DHCP_USER_BIND 2
  46. #define DHCP_USER_VERIFY 3
  47. #define DHCP_USER_RELEASE 4
  48. #define DHCP_USER_SHUTDOWN 5
  49. #define DHCP_USER_INFORM 6
  50. /* State transition definitions (besides OK or ERROR). */
  51. #define DHCPC_DONE 2            /* Lease relinquished or expired - exit. */
  52. #define DHCPC_MORE 3            /* Call a second routine when processing. */
  53. #define DHCPC_STATE_BEGIN 6     /* Initial processing after DHCPC_MORE. */
  54. /* Return codes indicate special situations related to state machine. */
  55. #define  DHCPC_SHUTDOWN 11
  56. #define  DHCPC_ERROR 12
  57. /* Classification of DHCP client leases. */
  58. #define DHCP_MANUAL 0      /* Lease established after system boot. */
  59. #define DHCP_BOOTP 1       /* Lease established using BOOTP reply. */
  60. #define DHCP_NATIVE 2      /* Lease established using DHCP reply. */
  61. #define DHCP_AUTOMATIC 3   /* Bound at boot time - lease still valid. */
  62. /* Internal settings for state machine */
  63. #define FIRSTTIMER          4
  64. #define MAXTIMER           64
  65. #define INIT_WAITING       10
  66. #define DISCOVER_RETRANS    4
  67. #if CPU_FAMILY==I960
  68. #pragma align 1                 /* tell gcc960 not to optimize alignments */
  69. #endif  /* CPU_FAMILY==I960 */
  70. typedef struct leaseData        /* Lease-specific variables. */
  71.     {
  72.     BOOL        initFlag;       /* Lease initialized? */
  73.     BOOL        waitFlag;       /* Synchronous or asynchronous bind attempt? */
  74.     BOOL        autoConfig;     /* Apply parameters to network interface? */
  75.     BOOL  oldFlag;  /* Use old (padded) DHCP message formats? */
  76.     SEM_ID      leaseSem;       /* Blocking semaphore for synchronous bind. */
  77.     BOOL        leaseGood;      /* Bind attempt successful? */
  78.     char *  msgBuffer;
  79.     int         leaseType;      /* Static or dynamic parameters, or BOOTP. */
  80.     int         prevState;      /* Preceding state in state machine. */
  81.     int         currState;      /* Current/next state in state machine. */
  82.     WDOG_ID     timer;          /* Timeout interval for DHCP events */
  83.     time_t      initEpoch;      /* Timestamp of last request. */
  84.     int         timeout;        /* Current timeout interval. */
  85.     int         numRetry;       /* Number of retransmission timeouts. */
  86.     FUNCPTR     eventHookRtn;   /* Event notification hook */
  87.     FUNCPTR     cacheHookRtn;   /* Data storage hook */
  88.     struct dhcp_reqspec leaseReqSpec;   /* Options request list */
  89.     struct if_info ifData;      /* Transmit/receive interface */
  90.     unsigned long       xid;    /* Current transaction ID. */
  91.     struct dhcp_param *dhcpcParam;      /* Current configuration parameters */
  92.     }
  93. LEASE_DATA;
  94. typedef struct messageData  /* Storage for incoming DHCP messages */
  95.     {
  96.     BOOL writeFlag;  /* Buffer available? */
  97.     char *msgBuffer;            /* Data buffer contents (copied from BPF) */
  98.     }
  99. MESSAGE_DATA;
  100. typedef struct dhcpcEvent       /* External event descriptor. */
  101.     {
  102.     unsigned char source;       /* Automatic event or manual event? */
  103.     unsigned char type;         /* Manual event - defines user request.
  104.                                  * Automatic - message arrival or timeout.
  105.                                  */
  106.     void * leaseId;             /* Cookie assigned by dhcpcInit (). */
  107.     int slot;  /* Offset of message buffer in list. */
  108.     char * pMsg;  /* Start of DHCP message */
  109.     BOOL lastFlag;  /* Release buffer when finished processing? */
  110.     }
  111. EVENT_DATA;
  112. /* Values for lease established during system boot. */
  113. typedef struct dhcpLeaseData
  114.     {
  115.     struct in_addr yiaddr;          /* assigned IP address */
  116.     unsigned long lease_origin;     /* start time of lease */
  117.     unsigned long lease_duration;   /* length of lease */
  118.     }
  119. DHCP_LEASE_DATA;
  120. struct buffer           /* transmission buffer for DHCP messages */
  121.     {
  122.     char *      buf;
  123.     int         size;
  124.     };
  125. #if CPU_FAMILY==I960
  126. #pragma align 0                 /* turn off alignment requirement */
  127. #endif  /* CPU_FAMILY==I960 */
  128. #define EVENT_RING_SIZE (10 * sizeof (EVENT_DATA))
  129. IMPORT RING_ID  dhcpcEventRing;    /* Ring buffer of DHCP events */
  130. IMPORT SEM_ID   dhcpcEventSem;     /* DHCP event notification */
  131. IMPORT BOOL dhcpcInitialized;
  132. IMPORT DHCP_LEASE_DATA dhcpcBootLease;  /* Settings from boot-time lease. */
  133. IMPORT LEASE_DATA **   dhcpcLeaseList;      /* List of available cookies. */
  134. IMPORT MESSAGE_DATA *  dhcpcMessageList;    /* Incoming DHCP messages. */
  135. IMPORT int     dhcpcMaxLeases;         /* Max. number of simultaneous leases. */
  136. IMPORT void  dhcpcOptFieldCreate (struct dhcpcOpts *, UCHAR *);
  137. IMPORT void  dhcpcDefaultsSet (struct dhcp_param *);
  138. IMPORT void  dhcpcParamsCopy (LEASE_DATA *, struct dhcp_param *);
  139. IMPORT STATUS  dhcpcArpSend (struct ifnet *, char *, int);
  140. IMPORT STATUS  dhcpSend (struct ifnet *, struct sockaddr_in *,
  141.                           char *, int, BOOL);
  142. IMPORT STATUS  dhcpcEventAdd (int, int, void *, BOOL);
  143. IMPORT void  dhcpcLeaseCleanup (LEASE_DATA *);
  144. #ifdef __cplusplus
  145. }
  146. #endif
  147. #endif