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.

160 lines
4.2 KiB

  1. //----- nic.h
  2. #if DBG
  3. //#define BREAK_NIC_STUFF
  4. #endif
  5. #define MAX_RX_PACKETS 1
  6. #define MAX_PKT_SIZE 1550
  7. #ifndef BYTE
  8. #define BYTE UCHAR
  9. #endif
  10. #ifndef WORD
  11. #define WORD USHORT
  12. #endif
  13. #ifndef DWORD
  14. #define DWORD ULONG
  15. #endif
  16. #ifndef PBYTE
  17. #define PBYTE PUCHAR
  18. #endif
  19. #ifndef PWORD
  20. #define PWORD PUSHORT
  21. #endif
  22. #ifndef LWORD
  23. #define LWORD ULONG
  24. #endif
  25. #ifndef PLWORD
  26. #define PLWORD PULONG
  27. #endif
  28. // header space we leave before ndis packet data, since ndis
  29. // wants to split the 14 byte header anyway
  30. #define HDR_SIZE 20
  31. #define HDR_SRC_ADDR(_buf) (_buf)
  32. #define HDR_DEST_ADDR(_buf) (&_buf[6])
  33. #define HDR_PKTLEN(_buf) *((WORD *)&_buf[12])
  34. typedef struct _Nic Nic;
  35. typedef struct _Nic {
  36. // This is the name of the NIC card which we got from the Registry.
  37. // Used to specify the nic card when wee do an OpenAdapter call.
  38. //PUNICODE_STRING NicName;
  39. char NicName[160];
  40. int Open; // flag, set when open for operation (use handle)
  41. // This is the handle for the NIC card returned from NdisOpenAdapter
  42. NDIS_HANDLE NICHandle;
  43. // This event will be set when a compeltion routine finishes so
  44. // if someone is waiting on it it can continue
  45. KEVENT CompletionEvent;
  46. // our local NIC address(6-bytes, two just padding)
  47. BYTE address[8];
  48. // following is for temporary output packet(convient but lots of overhead)
  49. // packet and buffer pool handles
  50. NDIS_HANDLE TxPacketPoolTemp;
  51. NDIS_HANDLE TxBufferPoolTemp;
  52. PNDIS_PACKET TxPacketsTemp; // []
  53. // queue data buffer space for all packets
  54. UCHAR *TxBufTemp;
  55. // packet and buffer pool handles
  56. NDIS_HANDLE RxPacketPool;
  57. NDIS_HANDLE RxBufferPool;
  58. // queue of packets setup for use
  59. PNDIS_PACKET RxPackets[MAX_RX_PACKETS];
  60. // queue data buffer space for all packets
  61. UCHAR *RxBuf;
  62. LIST_ENTRY RxPacketList;
  63. NDIS_STATUS PendingStatus;
  64. //----- statistics
  65. DWORD RxPendingMoves;
  66. DWORD RxNonPendingMoves;
  67. //----- incoming statistics
  68. WORD pkt_overflows; // statistics: receiver queue overflow count
  69. //DWORD RxPacketOurs;
  70. DWORD pkt_rcvd_ours;
  71. DWORD rec_bytes; // statistics: running tally of bytes received.
  72. DWORD pkt_rcvd_not_ours;
  73. //----- outgoing statistics
  74. DWORD pkt_sent; // statistics: running tally of packets sent.
  75. DWORD send_bytes; // statistics: running tally of bytes sent.
  76. //Nic *next_nic; // next nic struct in linked list or null if end of chain
  77. int RefIndex;
  78. } Nic;
  79. #define FLAG_APPL_RUNNING 0x01
  80. #define FLAG_NOT_OWNER 0x02
  81. #define FLAG_OWNER_TIMEOUT 0x04
  82. typedef struct {
  83. unsigned char mac[6];
  84. unsigned char flags;
  85. unsigned char nic_index;
  86. } DRIVER_MAC_STATUS;
  87. //--- layer 1 ethernet events used in _proc() calls
  88. // layer 1(ethernet) assigned range from 100-199
  89. #define EV_L1_RX_PACKET 100
  90. #define EV_L1_TX_PACKET 101
  91. // comtrol_type defines(byte [14] of ethernet packet):
  92. #define ASYNC_PRODUCT_HEADER_ID 0x55
  93. #define ISDN_PRODUCT_HEADER_ID 0x15
  94. #define ANY_PRODUCT_HEADER_ID 0xFF
  95. // comtrol_type defines(byte [14] of ethernet packet):
  96. #define ASYNC_PRODUCT_HEADER_ID 0x55
  97. #define ISDN_PRODUCT_HEADER_ID 0x15
  98. #define ANY_PRODUCT_HEADER_ID 0xFF
  99. //---- macro to see if mac-addresses match
  100. #define mac_match(_addr1, _addr2) \
  101. ( (*((DWORD *)_addr1) == *((DWORD *)_addr2) ) && \
  102. (*((WORD *)(_addr1+4)) == *((WORD *)(_addr2+4)) ) )
  103. //-- packet type
  104. #define ADMIN_FRAME 1
  105. #define ASYNC_FRAME 0x55
  106. #define ADMIN_ID_BOOT 0
  107. #define ADMIN_BOOT_PACKET 1
  108. #define ADMIN_ID_QUERY 2
  109. #define ADMIN_ID_REPLY 3
  110. #define ADMIN_ID_LOOP 4
  111. #define ADMIN_ID_RESET 5
  112. int ProtocolOpen(void);
  113. int NicMakeList(IN PUNICODE_STRING RegistryPath,
  114. int style); // 0=nt3.51,4.0 1=nt5.0
  115. int NicOpen(Nic *nic, IN PUNICODE_STRING NicName);
  116. int NicClose(Nic *nic);
  117. int NicProtocolClose(void);
  118. // int NicSend(Nic *nic, UCHAR *data, int length);
  119. NDIS_STATUS NicSetNICInfo(Nic *nic, NDIS_OID Oid, PVOID Data, ULONG Size);
  120. NDIS_STATUS NicGetNICInfo(Nic *nic, NDIS_OID Oid, PVOID Data, ULONG Size);
  121. int nic_send_pkt(Nic *nic, BYTE *buf, int len);
  122. extern BYTE broadcast_addr[6];
  123. extern BYTE mac_zero_addr[6];
  124. extern BYTE mac_bogus_addr[6];