Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

178 lines
6.9 KiB

  1. /*----
  2. // hdlc.h
  3. 6-18-97 change timing on timeouts to 1.0 sec base.
  4. ------*/
  5. #define HDLC_TRACE_outs(c)
  6. #define HDLC_DEB_outs(s,l)
  7. // define a circular queue for incoming packets.
  8. // queue uses an extra tail end head room of MAX_PKT_SIZE to avoid having to
  9. // perform to much sypherin concerning queue room.
  10. #define HDLC_TX_PKT_QUEUE_SIZE 9
  11. // control fields for hdlc header control field
  12. #define CONTROL_IFRAME 0
  13. #define CONTROL_UFRAME 1
  14. #define CONTROL_CONNECT_ASK 3
  15. #define CONTROL_CONNECT_REPLY 5
  16. /*--------------------------------------------
  17. Hdlc struct - main struct for HDLC support(layer 2)
  18. ----------------------------------------------*/
  19. typedef struct {
  20. //LanPort *lp; // our layer 1 handle.
  21. Nic *nic; // nic card we are bound to on lower end
  22. PVOID context; // upper layer can put handle here
  23. BYTE dest_addr[6]; // dest. address(needed for ack/seq. timeouts)
  24. WORD phys_outpkt_len[HDLC_TX_PKT_QUEUE_SIZE];
  25. //----- circular que of outgoing data packets
  26. Queue qout;
  27. // packet and buffer pool handles, basically points to the
  28. // tx-buffer space in qout.
  29. NDIS_HANDLE TxPacketPool;
  30. NDIS_HANDLE TxBufferPool;
  31. // queue of packets setup for use
  32. PNDIS_PACKET TxPackets[HDLC_TX_PKT_QUEUE_SIZE];
  33. // control packet and buffer pool handles, basically points to the
  34. // tx-buffer space in qout_ctl.
  35. NDIS_HANDLE TxCtlPacketPool;
  36. NDIS_HANDLE TxCtlBufferPool;
  37. // queue of packets setup for use
  38. PNDIS_PACKET TxCtlPackets[2];
  39. //----- circular que of outgoing control packets
  40. Queue qout_ctl;
  41. //----- timer statistics
  42. DWORD rec_ack_timeouts; // # of rec-ack-timeouts
  43. DWORD send_ack_timeouts; // # of send-ack-timeouts
  44. //----- outgoing statistics
  45. DWORD iframes_resent; // cout of all resent iframes
  46. DWORD iframes_sent; // count of every sent iframe
  47. DWORD ctlframes_sent; // count of every sent control frame
  48. DWORD rawframes_sent; // count of every sent raw frame
  49. DWORD iframes_outofseq; // statistics, error count
  50. //DWORD ErrBadHeader; // statistics, error count
  51. //----- incoming statistics
  52. DWORD frames_rcvd; //
  53. //------ packet driver handle
  54. WORD status;
  55. // sent out on each packet, increment by one each time a new packet
  56. // is sent out. The receiver uses this to check for packet sequence
  57. // order. This value is copied into the snd_index field when we are
  58. // ready to send a packet. A sync-message will set this to an
  59. // initial working value of 0.
  60. BYTE out_snd_index;
  61. // last good rx ack_index received. The receiver will send us a
  62. // acknowledge index(ack_index field) indicating the last good
  63. // received packet index it received. This allows us to remove
  64. // all packets up to this index number from our transmit buffer
  65. // since they have been acknowledged. Until this point we must
  66. // retain the packet for retransmition in case the receiver does
  67. // not acknowledge reception after a timeout period.
  68. BYTE in_ack_index;
  69. // last good rx snd_index on received packet. All packets received
  70. // should have a snd_index value equal to +1 of this value. So this
  71. // value is used to check for consequative incrementing index values
  72. // on the packets received. On sync-message this value is set to
  73. // 0xff.
  74. BYTE next_in_index;
  75. // used to measure how many incoming pkts received which are
  76. // unacknowledged so we can trip a acknowledgement at 80% full
  77. BYTE unacked_pkts;
  78. // tick counter used to timeout sent packets and the expected
  79. // acknowledgement.
  80. WORD sender_ack_timer;
  81. // tick counters used to check that connection is still active
  82. // periodically to recover from device power-cycle or hdlc
  83. // sequence level failure. If it ticks up past X many minutes
  84. // then a iframe packet is sent(and a iframe response is expected
  85. // back. If it ticks past (X*2) minutes, then failure is declared
  86. // and server re-initializes the box.
  87. WORD tx_alive_timer; // ticks up, reset every acked-reclaim of sent iframe.
  88. WORD rx_alive_timer; // ticks up, reset on every received iframe.
  89. WORD tick_timer; // used to generate 10Hz timer signal used for timeouts.
  90. // tick counter used to timeout rec. packets and our responsibility
  91. // to send and ack on them
  92. WORD rec_ack_timer;
  93. WORD pkt_window_size; // 1 to 8, num tx packets before ack
  94. WORD state; // state of hdlc level, see defines
  95. WORD old_state; // old state of hdlc level(used to reset timer)
  96. WORD sub_state; // sub_state of a particular state
  97. WORD state_timer; // state timer
  98. // following function ptrs is a general method for linking
  99. // layers together.
  100. ULONG (*upper_layer_proc) (PVOID context, int message_id, ULONG message_data);
  101. ULONG (*lower_layer_proc) (PVOID context, int message_id, ULONG message_data);
  102. } Hdlc;
  103. //--- layer 2 HDLC events used in _proc() calls
  104. // layer 2(hdlc) assigned range from 200-299
  105. #define EV_L2_RESYNC 200
  106. #define EV_L2_RX_PACKET 201
  107. #define EV_L2_TX_PACKET 202
  108. #define EV_L2_BOOT_REPLY 203
  109. #define EV_L2_ADMIN_REPLY 204
  110. #define EV_L2_RELOAD 205
  111. #define EV_L2_CHECK_LINK 206
  112. // packet sequence timeout values
  113. #define MIN_ACK_REC_TIME 10 // 10th seconds (1.0 sec)
  114. #define KEEP_ALIVE_TIMEOUT 300 // 10th seconds (30.0 sec)
  115. // state field defines
  116. //#define ST_HDLC_OFF 0 // HDLC is off, won't do anything.
  117. //#define ST_HDLC_DISCONNECTED 1 // HDLC is turned on, will allow connections
  118. //#define ST_HDLC_CONNECTED 2 // HDLC is connected up and active
  119. // status field bit values
  120. #define LST_RESYNC 0x0001 // set if we need to re-sync the packet index
  121. // #define LST_SEND_NAK 0x0002 // set if we need to update other side with index
  122. #define LST_RECLAIM 0x0004 // set if we should attempt to reclaim tx packets
  123. #define LST_SEND_ACK 0x0008 // set if we need to send immediate ACK
  124. //------------------ public functions
  125. int hdlc_open(Hdlc *hd, BYTE *box_mac_addr);
  126. int hdlc_close(Hdlc *hd);
  127. #define ERR_GET_EMPTY 1 // empty
  128. #define ERR_GET_BAD_INDEX 2 // error, packet out of sequence
  129. #define ERR_GET_BADHDR 3 // error, not our packet
  130. #define ERR_CONTROL_PACKET 4 // hdlc control packet only, no data
  131. int hdlc_validate_rx_pkt(Hdlc *hd, BYTE *buf);
  132. int hdlc_send_outpkt(Hdlc *hd, int data_len, BYTE *dest_addr);
  133. int hdlc_send_ctl_outpkt(Hdlc *hd, int data_len, BYTE *dest_addr);
  134. int hdlc_get_outpkt(Hdlc *hd, BYTE **buf);
  135. int hdlc_get_ctl_outpkt(Hdlc *hd, BYTE **buf);
  136. int hdlc_send_raw(Hdlc *hd, int data_len, BYTE *dest_addr);
  137. int hdlc_resend_outpkt(Hdlc *hd);
  138. void hdlc_resync(Hdlc *hd);
  139. void hdlc_poll(Hdlc *hd);
  140. int hdlc_close(Hdlc *hd);
  141. int hdlc_send_control(Hdlc *hd, BYTE *header_data, int header_len,
  142. BYTE *data, int data_len, BYTE *dest_addr);