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.

1531 lines
46 KiB

  1. /*++
  2. Copyright (c) 1989-1993 Microsoft Corporation
  3. Module Name:
  4. nbitypes.h
  5. Abstract:
  6. This module contains definitions specific to the
  7. Netbios module of the ISN transport.
  8. Author:
  9. Adam Barr (adamba) 16-November-1993
  10. Environment:
  11. Kernel mode
  12. Revision History:
  13. --*/
  14. #define MAJOR_TDI_VERSION 2
  15. #define MINOR_TDI_VERSION 0
  16. #define BIND_FIX 1
  17. extern ULONG NbiBindState;
  18. #define NBI_BOUND_TO_IPX 0x01
  19. #define IPX_HAS_DEVICES 0x02
  20. #define TDI_HAS_NOTIFIED 0x04
  21. enum eTDI_ACTION
  22. {
  23. NBI_IPX_REGISTER,
  24. NBI_IPX_DEREGISTER,
  25. NBI_TDI_REGISTER, // Register the Device and Net Address
  26. NBI_TDI_DEREGISTER // DeRegister the Net Address and Device respectively
  27. };
  28. //
  29. // For find name requests, defines the current status (SR_FN.Status).
  30. //
  31. typedef enum {
  32. FNStatusNoResponse, // no response has been received
  33. FNStatusResponseUnique, // response received, is a unique name
  34. FNStatusResponseGroup // response received, is a group name
  35. };
  36. //
  37. // Defines the results we can get from sending a series of find
  38. // names to locate a netbios name.
  39. //
  40. typedef enum _NETBIOS_NAME_RESULT {
  41. NetbiosNameFound, // name was located
  42. NetbiosNameNotFoundNormal, // name not found, no response received
  43. NetbiosNameNotFoundWanDown // name not found, all lines were down
  44. } NETBIOS_NAME_RESULT, *PNETBIOS_NAME_RESULT;
  45. //
  46. // Definition of the protocol reserved field of a send packet.
  47. //
  48. typedef struct _NB_SEND_RESERVED {
  49. UCHAR Identifier; // 0 for NB packets
  50. BOOLEAN SendInProgress; // used in an NdisSend
  51. UCHAR Type; // what to do on completion
  52. BOOLEAN OwnedByConnection; // if this is a connection's one packet
  53. #if defined(_PNP_POWER)
  54. PVOID Reserved[SEND_RESERVED_COMMON_SIZE]; // used by ipx for even-padding and local target etc.
  55. #else
  56. PVOID Reserved[2]; // used by ipx for even-padding
  57. #endif _PNP_POWER
  58. LIST_ENTRY GlobalLinkage; // all packets are on this
  59. SLIST_ENTRY PoolLinkage; // when on free queue
  60. LIST_ENTRY WaitLinkage; // when waiting on other queues
  61. #ifdef NB_TRACK_POOL
  62. PVOID Pool; // send pool it was allocated from
  63. #endif
  64. union {
  65. struct {
  66. UCHAR NetbiosName[16]; // name being searched for
  67. UCHAR StatusAndSentOnUpLine; // low nibble: look at FNStatusXXX enum
  68. // high nibble: TRUE if while sending, found lan or up wan line
  69. UCHAR RetryCount; // number of times sent
  70. USHORT SendTime; // based on Device->FindNameTime
  71. #if !defined(_PNP_POWER)
  72. USHORT CurrentNicId; // current nic id it is being sent on
  73. USHORT MaximumNicId; // highest one it will be sent on
  74. #endif !_PNP_POWER
  75. struct _NETBIOS_CACHE * NewCache; // new cache entry for group names
  76. } SR_FN;
  77. struct {
  78. struct _ADDRESS * Address; // that owns this packet, if one does
  79. PREQUEST Request; // send datagram request
  80. struct _ADDRESS_FILE * AddressFile; // that this send is on
  81. #if !defined(_PNP_POWER)
  82. USHORT CurrentNicId; // non-zero for frames that go to all
  83. #endif !_PNP_POWER
  84. UCHAR NameTypeFlag; // save these two values for frames
  85. UCHAR DataStreamType; // that need to be sent to all nic id's
  86. } SR_NF;
  87. struct {
  88. PREQUEST DatagramRequest; // holds the passed-in request
  89. TDI_ADDRESS_NETBIOS * RemoteName; // will be -1 for broadcast
  90. struct _ADDRESS_FILE * AddressFile; // that the datagram was sent on
  91. struct _NETBIOS_CACHE * Cache; // how to route to the netbios address
  92. ULONG CurrentNetwork; // within the cache entry
  93. } SR_DG;
  94. struct {
  95. struct _CONNECTION * Connection; // that this frame was sent on.
  96. PREQUEST Request; // that this frame was sent for.
  97. ULONG PacketLength; // total packet length.
  98. BOOLEAN NoNdisBuffer; // none allocate for send
  99. } SR_CO;
  100. struct {
  101. ULONG ActualBufferLength; // real length of allocated buffer.
  102. } SR_AS;
  103. } u;
  104. PUCHAR Header; // points to the MAC/IPX/NB header
  105. PNDIS_BUFFER HeaderBuffer; // the NDIS_BUFFER describing Header
  106. ULONG CurrentSendIteration; // Iteration # for Send Completions so that we can avoid stack overflow
  107. } NB_SEND_RESERVED, *PNB_SEND_RESERVED;
  108. //
  109. // Values for Type.
  110. //
  111. #define SEND_TYPE_NAME_FRAME 1
  112. #define SEND_TYPE_SESSION_INIT 2
  113. #define SEND_TYPE_FIND_NAME 3
  114. #define SEND_TYPE_DATAGRAM 4
  115. #define SEND_TYPE_SESSION_NO_DATA 5
  116. #define SEND_TYPE_SESSION_DATA 6
  117. #define SEND_TYPE_STATUS_QUERY 7
  118. #define SEND_TYPE_STATUS_RESPONSE 8
  119. #ifdef RSRC_TIMEOUT_DBG
  120. #define SEND_TYPE_DEATH_PACKET 9
  121. #endif //RSRC_TIMEOUT_DBG
  122. //
  123. // Macros to access StatusAndSentOnUpLine.
  124. //
  125. #define NB_GET_SR_FN_STATUS(_Reserved) \
  126. ((_Reserved)->u.SR_FN.StatusAndSentOnUpLine & 0x0f)
  127. #define NB_SET_SR_FN_STATUS(_Reserved,_Value) \
  128. (_Reserved)->u.SR_FN.StatusAndSentOnUpLine = \
  129. (((_Reserved)->u.SR_FN.StatusAndSentOnUpLine & 0xf0) | (_Value));
  130. #define NB_GET_SR_FN_SENT_ON_UP_LINE(_Reserved) \
  131. (((_Reserved)->u.SR_FN.StatusAndSentOnUpLine & 0xf0) != 0)
  132. #define NB_SET_SR_FN_SENT_ON_UP_LINE(_Reserved,_Value) \
  133. (_Reserved)->u.SR_FN.StatusAndSentOnUpLine = (UCHAR) \
  134. (((_Reserved)->u.SR_FN.StatusAndSentOnUpLine & 0x0f) | ((_Value) << 4));
  135. //
  136. // Definition of the protocol reserved field of a receive packet.
  137. //
  138. typedef struct _NB_RECEIVE_RESERVED {
  139. UCHAR Identifier; // 0 for NB packets
  140. BOOLEAN TransferInProgress; // used in an NdisTransferData
  141. UCHAR Type; // what to do on completion
  142. #if defined(_PNP_POWER)
  143. PVOID Pool; // send pool it was allocated from
  144. #else
  145. #ifdef IPX_TRACK_POOL
  146. PVOID Pool; // send pool it was allocated from
  147. #endif
  148. #endif _PNP_POWER
  149. union {
  150. struct {
  151. struct _CONNECTION * Connection; // that the transfer is for
  152. BOOLEAN EndOfMessage; // this was the last part of a message
  153. BOOLEAN CompleteReceive; // receive should be completed
  154. BOOLEAN NoNdisBuffer; // user's mdl chain was used
  155. BOOLEAN PartialReceive; // (new nb) don't ack this packet
  156. } RR_CO;
  157. struct {
  158. struct _NB_RECEIVE_BUFFER * ReceiveBuffer; // datagram receive buffer
  159. } RR_DG;
  160. struct {
  161. PREQUEST Request; // for this request
  162. } RR_AS;
  163. } u;
  164. LIST_ENTRY GlobalLinkage; // all packets are on this
  165. SLIST_ENTRY PoolLinkage; // when on free queue
  166. } NB_RECEIVE_RESERVED, *PNB_RECEIVE_RESERVED;
  167. //
  168. // Values for Type.
  169. //
  170. #define RECEIVE_TYPE_DATAGRAM 1
  171. #define RECEIVE_TYPE_DATA 2
  172. #define RECEIVE_TYPE_ADAPTER_STATUS 3
  173. typedef struct _NB_RECEIVE_BUFFER {
  174. LIST_ENTRY GlobalLinkage; // all buffers are on this
  175. #if defined(_PNP_POWER)
  176. PVOID Pool; // receive buffer pool was allocated from
  177. #else
  178. #ifdef NB_TRACK_POOL
  179. PVOID Pool; // receive buffer pool was allocated from
  180. #endif
  181. #endif _PNP_POWER
  182. struct _ADDRESS * Address; // that the datagram is for
  183. SINGLE_LIST_ENTRY PoolLinkage; // when in free pool
  184. LIST_ENTRY WaitLinkage; // when in ReceiveDatagrams queue
  185. PNDIS_BUFFER NdisBuffer; // describes the data
  186. UCHAR RemoteName[16]; // datagram was received from
  187. ULONG DataLength; // length for current one, not allocated
  188. PUCHAR Data; // points to data to hold packet
  189. } NB_RECEIVE_BUFFER, *PNB_RECEIVE_BUFFER;
  190. #define MAX_SEND_ITERATIONS 3
  191. //
  192. // Types to abstract NDIS packets. This is to allow us to
  193. // switch from using our own memory for packets to using
  194. // authentically allocated NDIS packets.
  195. //
  196. //#define NB_OWN_PACKETS 1
  197. #ifdef NB_OWN_PACKETS
  198. #define NDIS_PACKET_SIZE 48
  199. // #define NDIS_PACKET_SIZE FIELD_OFFSET(NDIS_PACKET,ProtocolReserved[0])
  200. typedef struct _NB_SEND_PACKET {
  201. UCHAR Data[NDIS_PACKET_SIZE+sizeof(NB_SEND_RESERVED)];
  202. } NB_SEND_PACKET, *PNB_SEND_PACKET;
  203. typedef struct _NB_RECEIVE_PACKET {
  204. UCHAR Data[NDIS_PACKET_SIZE+sizeof(NB_RECEIVE_RESERVED)];
  205. } NB_RECEIVE_PACKET, *PNB_RECEIVE_PACKET;
  206. typedef struct _NB_SEND_POOL {
  207. LIST_ENTRY Linkage;
  208. UINT PacketCount;
  209. UINT PacketFree;
  210. NB_SEND_PACKET Packets[1];
  211. // after the packets the header buffers are allocated also.
  212. } NB_SEND_POOL, *PNB_SEND_POOL;
  213. typedef struct _NB_RECEIVE_POOL {
  214. LIST_ENTRY Linkage;
  215. UINT PacketCount;
  216. UINT PacketFree;
  217. NB_RECEIVE_PACKET Packets[1];
  218. } NB_RECEIVE_POOL, *PNB_RECEIVE_POOL;
  219. #define PACKET(_Packet) ((PNDIS_PACKET)((_Packet)->Data))
  220. #define NbiAllocateSendPacket(_Device,_PoolHandle, _SendPacket,_Status) { \
  221. NdisReinitializePacket((PNDIS_PACKET)((_SendPacket)->Data)); \
  222. *(_Status) = STATUS_SUCCESS; \
  223. }
  224. #define NbiAllocateReceivePacket(_Device,_PoolHandle, _ReceivePacket,_Status) { \
  225. NdisReinitializePacket((PNDIS_PACKET)((_ReceivePacket)->Data)); \
  226. *(_Status) = STATUS_SUCCESS; \
  227. }
  228. #define NbiFreeSendPacket(_Device,_Packet)
  229. #define NbiFreeReceivePacket(_Device,_Packet)
  230. #else // NB_OWN_PACKETS
  231. typedef struct _NB_SEND_PACKET {
  232. PNDIS_PACKET Packet;
  233. } NB_SEND_PACKET, *PNB_SEND_PACKET;
  234. typedef struct _NB_RECEIVE_PACKET {
  235. PNDIS_PACKET Packet;
  236. } NB_RECEIVE_PACKET, *PNB_RECEIVE_PACKET;
  237. typedef struct _NB_PACKET_POOL {
  238. LIST_ENTRY Linkage;
  239. UINT PacketCount;
  240. UINT PacketFree;
  241. NDIS_HANDLE PoolHandle;
  242. NB_SEND_PACKET Packets[1];
  243. // after the packets the header buffers are allocated also.
  244. } NB_SEND_POOL, *PNB_SEND_POOL;
  245. typedef struct _NB_RECEIVE_POOL {
  246. LIST_ENTRY Linkage;
  247. UINT PacketCount;
  248. UINT PacketFree;
  249. NDIS_HANDLE PoolHandle;
  250. NB_RECEIVE_PACKET Packets[1];
  251. } NB_RECEIVE_POOL, *PNB_RECEIVE_POOL;
  252. #define PACKET(_Packet) ((_Packet)->Packet)
  253. #define NbiAllocateSendPacket(_Device,_PoolHandle, _SendPacket,_Status) { \
  254. NdisAllocatePacket(_Status, &(_SendPacket)->Packet, _PoolHandle); \
  255. }
  256. #define NbiAllocateReceivePacket(_Device, _PoolHandle, _ReceivePacket,_Status) { \
  257. NdisAllocatePacket(_Status, &(_ReceivePacket)->Packet, _PoolHandle); \
  258. }
  259. #define NbiFreeSendPacket(_Device,_Packet) { \
  260. NdisFreePacket(PACKET(_Packet)); \
  261. }
  262. #define NbiFreeReceivePacket(_Device,_Packet) { \
  263. NdisFreePacket(PACKET(_Packet)); \
  264. }
  265. #endif // NB_OWN_PACKETS
  266. #define SEND_RESERVED(_Packet) ((PNB_SEND_RESERVED)((PACKET(_Packet))->ProtocolReserved))
  267. #define RECEIVE_RESERVED(_Packet) ((PNB_RECEIVE_RESERVED)((PACKET(_Packet))->ProtocolReserved))
  268. typedef struct _NB_RECEIVE_BUFFER_POOL {
  269. LIST_ENTRY Linkage;
  270. UINT BufferCount;
  271. UINT BufferFree;
  272. #if defined(_PNP_POWER)
  273. UINT BufferDataSize; // allocation size of each buffer data
  274. #endif _PNP_POWER
  275. NB_RECEIVE_BUFFER Buffers[1];
  276. // after the packets the data buffers are allocated also.
  277. } NB_RECEIVE_BUFFER_POOL, *PNB_RECEIVE_BUFFER_POOL;
  278. //
  279. // Tags for memory allocation.
  280. //
  281. #define MEMORY_CONFIG 0
  282. #define MEMORY_ADAPTER 1
  283. #define MEMORY_ADDRESS 2
  284. #define MEMORY_PACKET 3
  285. #define MEMORY_CACHE 4
  286. #define MEMORY_CONNECTION 5
  287. #define MEMORY_STATUS 6
  288. #define MEMORY_QUERY 7
  289. #if defined(_PNP_POWER)
  290. #define MEMORY_WORK_ITEM 8
  291. #define MEMORY_ADAPTER_ADDRESS 9
  292. #endif _PNP_POWER
  293. #if defined(_PNP_POWER)
  294. #define MEMORY_MAX 10
  295. #else
  296. #define MEMORY_MAX 8
  297. #endif _PNP_POWER
  298. #if DBG
  299. //
  300. // Holds the allocations for a specific memory type.
  301. //
  302. typedef struct _MEMORY_TAG {
  303. ULONG Tag;
  304. ULONG BytesAllocated;
  305. } MEMORY_TAG, *PMEMORY_TAG;
  306. EXTERNAL_LOCK(NbiMemoryInterlock);
  307. extern MEMORY_TAG NbiMemoryTag[MEMORY_MAX];
  308. #endif
  309. //
  310. // This structure holds a single remote network which a
  311. // Netbios name exists on.
  312. //
  313. typedef struct _NETBIOS_NETWORK {
  314. ULONG Network;
  315. IPX_LOCAL_TARGET LocalTarget;
  316. } NETBIOS_NETWORK, *PNETBIOS_NETWORK;
  317. //
  318. // This defines a netbios cache entry for a given name.
  319. //
  320. typedef struct _NETBIOS_CACHE {
  321. UCHAR NetbiosName[16];
  322. BOOLEAN Unique;
  323. BOOLEAN FailedOnDownWan; // if NetworksUsed == 0, was it due to down wan lines?
  324. USHORT TimeStamp; // in seconds - CacheTimeStamp when inserted
  325. ULONG ReferenceCount;
  326. LIST_ENTRY Linkage;
  327. TDI_ADDRESS_IPX FirstResponse;
  328. USHORT NetworksAllocated;
  329. USHORT NetworksUsed;
  330. NETBIOS_NETWORK Networks[1]; // may be more than one of these
  331. } NETBIOS_CACHE, *PNETBIOS_CACHE;
  332. typedef struct _NETBIOS_CACHE_TABLE {
  333. USHORT MaxHashIndex;
  334. USHORT CurrentEntries;
  335. LIST_ENTRY Bucket[1];
  336. } NETBIOS_CACHE_TABLE, *PNETBIOS_CACHE_TABLE;
  337. #define NB_NETBIOS_CACHE_TABLE_LARGE 26 // for server
  338. #define NB_NETBIOS_CACHE_TABLE_SMALL 8 // for workstation
  339. #define NB_MAX_AVG_CACHE_ENTRIES_PER_BUCKET 8
  340. //
  341. // This defines the different kind of requests that can be made
  342. // to CacheFindName().
  343. //
  344. typedef enum _FIND_NAME_TYPE {
  345. FindNameConnect,
  346. FindNameNetbiosFindName,
  347. FindNameOther
  348. } FIND_NAME_TYPE, *PFIND_NAME_TYPE;
  349. //
  350. // The number of hash entries in the non-inactive connection
  351. // database.
  352. //
  353. #define CONNECTION_HASH_COUNT 8
  354. //
  355. // Mask and shift to retrieve the hash number from a connection
  356. // ID.
  357. //
  358. #define CONNECTION_HASH_MASK 0xe000
  359. #define CONNECTION_HASH_SHIFT 13
  360. //
  361. // The maximum connection ID we can assign, not counting the
  362. // shifted-over hash id (which occupies the top 3 bits of the
  363. // real id we use on the wire). We can use all the bits except
  364. // the top one, to prevent an ID of 0xffff being used.
  365. //
  366. #define CONNECTION_MAXIMUM_ID (USHORT)(~CONNECTION_HASH_MASK & ~1)
  367. //
  368. // A single connection hash bucket.
  369. //
  370. typedef struct _CONNECTION_HASH {
  371. struct _CONNECTION * Connections;
  372. USHORT ConnectionCount;
  373. USHORT NextConnectionId;
  374. } CONNECTION_HASH, *PCONNECTION_HASH;
  375. //
  376. // These are queued in the ConnectIndicationInProgress
  377. // queue to track indications to TDI clients.
  378. //
  379. typedef struct _CONNECT_INDICATION {
  380. LIST_ENTRY Linkage;
  381. UCHAR NetbiosName[16];
  382. TDI_ADDRESS_IPX RemoteAddress;
  383. USHORT ConnectionId;
  384. } CONNECT_INDICATION, *PCONNECT_INDICATION;
  385. //
  386. // This structure defines the per-device structure for NB
  387. // (one of these is allocated globally).
  388. //
  389. #define DREF_CREATE 0
  390. #define DREF_LOADED 1
  391. #define DREF_ADAPTER 2
  392. #define DREF_ADDRESS 3
  393. #define DREF_CONNECTION 4
  394. #define DREF_FN_TIMER 5
  395. #define DREF_FIND_NAME 6
  396. #define DREF_SESSION_INIT 7
  397. #define DREF_NAME_FRAME 8
  398. #define DREF_FRAME 9
  399. #define DREF_SHORT_TIMER 10
  400. #define DREF_LONG_TIMER 11
  401. #define DREF_STATUS_QUERY 12
  402. #define DREF_STATUS_RESPONSE 13
  403. #define DREF_STATUS_FRAME 14
  404. #define DREF_NB_FIND_NAME 15
  405. #define DREF_TOTAL 16
  406. typedef struct _DEVICE {
  407. DEVICE_OBJECT DeviceObject; // the I/O system's device object.
  408. #if DBG
  409. ULONG RefTypes[DREF_TOTAL];
  410. #endif
  411. CSHORT Type; // type of this structure
  412. USHORT Size; // size of this structure
  413. #if DBG
  414. UCHAR Signature1[4]; // contains "IDC1"
  415. #endif
  416. NB_LOCK Interlock; // GLOBAL lock for reference count.
  417. // (used in ExInterlockedXxx calls)
  418. NB_LOCK Lock;
  419. LONG ReferenceCount; // activity count/this provider.
  420. //
  421. // These are kept around for error logging, and stored right
  422. // after this structure.
  423. //
  424. UNICODE_STRING DeviceString;
  425. LIST_ENTRY GlobalSendPacketList;
  426. LIST_ENTRY GlobalReceivePacketList;
  427. LIST_ENTRY GlobalReceiveBufferList;
  428. //
  429. // All send packet pools are chained on this list.
  430. //
  431. LIST_ENTRY SendPoolList;
  432. LIST_ENTRY ReceivePoolList;
  433. LIST_ENTRY ReceiveBufferPoolList;
  434. SLIST_HEADER SendPacketList;
  435. SLIST_HEADER ReceivePacketList;
  436. SINGLE_LIST_ENTRY ReceiveBufferList;
  437. //
  438. // Receive requests waiting to be completed.
  439. //
  440. LIST_ENTRY ReceiveCompletionQueue;
  441. //
  442. // Connections waiting for send packets.
  443. //
  444. LIST_ENTRY WaitPacketConnections;
  445. //
  446. // Connections waiting to packetize.
  447. //
  448. LIST_ENTRY PacketizeConnections;
  449. //
  450. // Connections waiting to send a data ack.
  451. //
  452. LIST_ENTRY DataAckConnections;
  453. //
  454. // The list changed while we were processing it.
  455. //
  456. BOOLEAN DataAckQueueChanged;
  457. //
  458. // Information to manage the Netbios name cache.
  459. //
  460. LIST_ENTRY WaitingConnects; // connect requests waiting for a name
  461. LIST_ENTRY WaitingDatagrams; // datagram requests waiting for a name
  462. LIST_ENTRY WaitingAdapterStatus; // adapter status requests waiting for a name
  463. LIST_ENTRY WaitingNetbiosFindName; // netbios find name requests waiting for a name
  464. //
  465. // Holds adapter status request which have a name and
  466. // are waiting for a response. The long timeout aborts
  467. // these after a couple of expirations (currently we
  468. // do not do resends).
  469. //
  470. LIST_ENTRY ActiveAdapterStatus;
  471. //
  472. // Receive datagrams waiting to be indicated.
  473. //
  474. LIST_ENTRY ReceiveDatagrams;
  475. //
  476. // In-progress connect indications (used to make
  477. // sure we don't indicate the same packet twice).
  478. //
  479. LIST_ENTRY ConnectIndicationInProgress;
  480. //
  481. // Listens that have been posted to connections.
  482. //
  483. LIST_ENTRY ListenQueue;
  484. UCHAR State;
  485. //
  486. // The following fields control the timer system.
  487. // The short timer is used for retransmission and
  488. // delayed acks, and the long timer is used for
  489. // watchdog timeouts.
  490. //
  491. BOOLEAN ShortListActive; // ShortList is not empty.
  492. BOOLEAN DataAckActive; // DataAckConnections is not empty.
  493. BOOLEAN TimersInitialized; // has the timer system been initialized.
  494. BOOLEAN ProcessingShortTimer; // TRUE if we are in ScanShortTimer.
  495. #if defined(_PNP_POWER)
  496. BOOLEAN LongTimerRunning; // True if the long timer is running.
  497. #endif _PNP_POWER
  498. LARGE_INTEGER ShortTimerStart; // tick count when the short timer was set.
  499. CTETimer ShortTimer; // controls the short timer.
  500. ULONG ShortAbsoluteTime; // up-count timer ticks, short timer.
  501. CTETimer LongTimer; // kernel DPC object, long timer.
  502. ULONG LongAbsoluteTime; // up-count timer ticks, long timer.
  503. NB_LOCK TimerLock; // lock for following timer queues
  504. LIST_ENTRY ShortList; // list of waiting connections
  505. LIST_ENTRY LongList; // list of waiting connections
  506. //
  507. // Hash table of non-inactive connections.
  508. //
  509. CONNECTION_HASH ConnectionHash[CONNECTION_HASH_COUNT];
  510. //
  511. // Control the queue of waiting find names.
  512. //
  513. USHORT FindNameTime; // incremented each time the timer runs
  514. BOOLEAN FindNameTimerActive; // TRUE if the timer is queued
  515. CTETimer FindNameTimer; // runs every FIND_NAME_GRANULARITY
  516. ULONG FindNameTimeout; // the retry count in timer ticks
  517. ULONG FindNamePacketCount; // Count of packets on the queue
  518. LIST_ENTRY WaitingFindNames; // FIND_NAME frames waiting to go out
  519. //
  520. // The cache of NETBIOS_CACHE entries.
  521. //
  522. PNETBIOS_CACHE_TABLE NameCache;
  523. //
  524. // The current time stamp, incremented every second.
  525. //
  526. USHORT CacheTimeStamp;
  527. //
  528. // Maximum valid NIC ID we can use.
  529. //
  530. USHORT MaximumNicId;
  531. //
  532. // Handle for our binding to the IPX driver.
  533. //
  534. HANDLE BindHandle;
  535. //
  536. // Holds the output from binding to IPX.
  537. //
  538. IPX_INTERNAL_BIND_OUTPUT Bind;
  539. IPX_INTERNAL_BIND_INPUT BindInput;
  540. //
  541. // Holds our reserved netbios name, which is 10 bytes
  542. // of zeros followed by our node address.
  543. //
  544. #if !defined(_PNP_POWER)
  545. UCHAR ReservedNetbiosName[16];
  546. #endif !_PNP_POWER
  547. //
  548. // This holds the total memory allocated for the above structures.
  549. //
  550. LONG MemoryUsage;
  551. LONG MemoryLimit;
  552. //
  553. // How many packets have been allocated.
  554. //
  555. ULONG AllocatedSendPackets;
  556. ULONG AllocatedReceivePackets;
  557. ULONG AllocatedReceiveBuffers;
  558. #if defined(_PNP_POWER)
  559. //
  560. // This is the size of each buffer in the receive buffer pool.
  561. // We reallocate buffer pool when the LineInfo.MaxPacketSize changes(increases)
  562. // from IPX because of a new adapter. The LineInfo.MaxPacketSize could
  563. // also change(decrease) when a adapter disappears but our buffer pool size
  564. // will stay at this value.
  565. //
  566. ULONG CurMaxReceiveBufferSize;
  567. #endif _PNP_POWER
  568. //
  569. // Other configuration parameters.
  570. //
  571. ULONG AckDelayTime; // converted to short timeouts, rounded up
  572. ULONG AckWindow;
  573. ULONG AckWindowThreshold;
  574. ULONG EnablePiggyBackAck;
  575. ULONG Extensions;
  576. ULONG RcvWindowMax;
  577. ULONG BroadcastCount;
  578. ULONG BroadcastTimeout;
  579. ULONG ConnectionCount;
  580. ULONG ConnectionTimeout;
  581. ULONG InitPackets;
  582. ULONG MaxPackets;
  583. ULONG InitialRetransmissionTime;
  584. ULONG Internet;
  585. ULONG KeepAliveCount;
  586. ULONG KeepAliveTimeout;
  587. ULONG RetransmitMax;
  588. ULONG RouterMtu;
  589. ULONG MaxReceiveBuffers;
  590. //
  591. // Where we tell upper drivers to put their headers.
  592. //
  593. ULONG IncludedHeaderOffset;
  594. //
  595. // The following field is a head of a list of ADDRESS objects that
  596. // are defined for this transport provider. To edit the list, you must
  597. // hold the spinlock of the device context object.
  598. //
  599. LIST_ENTRY AddressDatabase; // list of defined transport addresses.
  600. #if defined(_PNP_POWER)
  601. LIST_ENTRY AdapterAddressDatabase; // list of netbios names made from adapter addresses.
  602. #endif _PNP_POWER
  603. ULONG AddressCount; // number of addresses in the database.
  604. NDIS_HANDLE NdisBufferPoolHandle;
  605. #if DBG
  606. UCHAR Signature2[4]; // contains "IDC2"
  607. #endif
  608. //
  609. // This structure holds a pre-built IPX header which is used
  610. // to quickly fill in common fields of outgoing connectionless
  611. // frames.
  612. //
  613. IPX_HEADER ConnectionlessHeader;
  614. //
  615. // This event is used when unloading to signal that
  616. // the reference count is now 0.
  617. //
  618. KEVENT UnloadEvent;
  619. BOOLEAN UnloadWaiting;
  620. #if defined(_PNP_POWER)
  621. HANDLE TdiRegistrationHandle;
  622. #endif _PNP_POWER
  623. //
  624. // Counters for most of the statistics that NB maintains;
  625. // some of these are kept elsewhere. Including the structure
  626. // itself wastes a little space but ensures that the alignment
  627. // inside the structure is correct.
  628. //
  629. TDI_PROVIDER_STATISTICS Statistics;
  630. //
  631. // These are "temporary" versions of the other counters.
  632. // During normal operations we update these, then during
  633. // the short timer expiration we update the real ones.
  634. //
  635. ULONG TempFrameBytesSent;
  636. ULONG TempFramesSent;
  637. ULONG TempFrameBytesReceived;
  638. ULONG TempFramesReceived;
  639. //
  640. // This contains the next unique indentified to use as
  641. // the FsContext in the file object associated with an
  642. // open of the control channel.
  643. //
  644. USHORT ControlChannelIdentifier;
  645. //
  646. // Counters for "active" time.
  647. //
  648. LARGE_INTEGER NbiStartTime;
  649. //
  650. // This array is used to quickly dismiss connectionless frames
  651. // that are not destined for us. The count is the number
  652. // of addresses with that first letter that are registered
  653. // on this device.
  654. //
  655. UCHAR AddressCounts[256];
  656. //
  657. // This resource guards access to the ShareAccess
  658. // and SecurityDescriptor fields in addresses.
  659. //
  660. ERESOURCE AddressResource;
  661. //
  662. // The following structure contains statistics counters for use
  663. // by TdiQueryInformation and TdiSetInformation. They should not
  664. // be used for maintenance of internal data structures.
  665. //
  666. TDI_PROVIDER_INFO Information; // information about this provider.
  667. #ifdef _PNP_POWER_
  668. HANDLE NetAddressRegistrationHandle; // Handle returned from TdiRegisterNetAddress.
  669. #endif // _PNP_POWER_
  670. #ifdef BIND_FIX
  671. KEVENT BindReadyEvent;
  672. #endif // BIND_FIX
  673. } DEVICE, * PDEVICE;
  674. extern PDEVICE NbiDevice;
  675. EXTERNAL_LOCK(NbiGlobalPoolInterlock);
  676. //
  677. // This is used only for CHK build. For
  678. // tracking the refcount problem on connection, this
  679. // is moved here for now.
  680. //
  681. EXTERNAL_LOCK(NbiGlobalInterlock);
  682. //
  683. // device state definitions
  684. //
  685. #if defined(_PNP_POWER)
  686. #define DEVICE_STATE_CLOSED 0x00 // Initial state
  687. #define DEVICE_STATE_LOADED 0x01 // Loaded and bound to IPX but no adapters
  688. #define DEVICE_STATE_OPEN 0x02 // Fully operational
  689. #define DEVICE_STATE_STOPPING 0x03 // Unload has been initiated, The I/O system
  690. // will not call us until nobody above has Netbios open.
  691. #else
  692. #define DEVICE_STATE_CLOSED 0x00
  693. #define DEVICE_STATE_OPEN 0x01
  694. #define DEVICE_STATE_STOPPING 0x02
  695. #endif _PNP_POWER
  696. #define NB_TDI_RESOURCES 9
  697. //
  698. // This structure is pointed to by the FsContext field in the FILE_OBJECT
  699. // for this Address. This structure is the base for all activities on
  700. // the open file object within the transport provider. All active connections
  701. // on the address point to this structure, although no queues exist here to do
  702. // work from. This structure also maintains a reference to an ADDRESS
  703. // structure, which describes the address that it is bound to.
  704. //
  705. #define AFREF_CREATE 0
  706. #define AFREF_RCV_DGRAM 1
  707. #define AFREF_SEND_DGRAM 2
  708. #define AFREF_VERIFY 3
  709. #define AFREF_INDICATION 4
  710. #define AFREF_TIMEOUT 5
  711. #define AFREF_CONNECTION 6
  712. #define AFREF_TOTAL 8
  713. typedef struct _ADDRESS_FILE {
  714. #if DBG
  715. ULONG RefTypes[AFREF_TOTAL];
  716. #endif
  717. CSHORT Type;
  718. CSHORT Size;
  719. LIST_ENTRY Linkage; // next address file on this address.
  720. // also used for linkage in the
  721. // look-aside list
  722. ULONG ReferenceCount; // number of references to this object.
  723. //
  724. // the current state of the address file structure; this is either open or
  725. // closing
  726. //
  727. UCHAR State;
  728. PNB_LOCK AddressLock;
  729. //
  730. // The following fields are kept for housekeeping purposes.
  731. //
  732. PREQUEST OpenRequest; // the request used for open
  733. struct _ADDRESS *Address; // address to which we are bound.
  734. #ifdef ISN_NT
  735. PFILE_OBJECT FileObject; // easy backlink to file object.
  736. #endif
  737. struct _DEVICE *Device; // device to which we are attached.
  738. LIST_ENTRY ConnectionDatabase; // associated with this address.
  739. LIST_ENTRY ReceiveDatagramQueue; // posted by the client.
  740. //
  741. // This holds the request used to close this address file,
  742. // for pended completion.
  743. //
  744. PREQUEST CloseRequest;
  745. //
  746. // Handler for kernel event actions. First we have a set of booleans that
  747. // indicate whether or not this address has an event handler of the given
  748. // type registered.
  749. //
  750. BOOLEAN RegisteredHandler[6];
  751. //
  752. // This is a list of handlers for a given event. They can be
  753. // accessed using the explicit names for type-checking, or the
  754. // array (indexed by the event type) for speed.
  755. //
  756. union {
  757. struct {
  758. PTDI_IND_CONNECT ConnectionHandler;
  759. PTDI_IND_DISCONNECT DisconnectHandler;
  760. PTDI_IND_ERROR ErrorHandler;
  761. PTDI_IND_RECEIVE ReceiveHandler;
  762. PTDI_IND_RECEIVE_DATAGRAM ReceiveDatagramHandler;
  763. PTDI_IND_RECEIVE_EXPEDITED ExpeditedDataHandler;
  764. };
  765. PVOID Handlers[6];
  766. };
  767. PVOID HandlerContexts[6];
  768. } ADDRESS_FILE, *PADDRESS_FILE;
  769. #define ADDRESSFILE_STATE_OPENING 0x00 // not yet open for business
  770. #define ADDRESSFILE_STATE_OPEN 0x01 // open for business
  771. #define ADDRESSFILE_STATE_CLOSING 0x02 // closing
  772. //
  773. // This structure defines a NETBIOS name as a character array for use when
  774. // passing preformatted NETBIOS names between internal routines. It is
  775. // not a part of the external interface to the transport provider.
  776. //
  777. typedef struct _NBI_NETBIOS_ADDRESS {
  778. UCHAR NetbiosName[16];
  779. USHORT NetbiosNameType;
  780. BOOLEAN Broadcast;
  781. } NBI_NETBIOS_ADDRESS, *PNBI_NETBIOS_ADDRESS;
  782. //
  783. // This structure defines an ADDRESS, or active transport address,
  784. // maintained by the transport provider. It contains all the visible
  785. // components of the address (such as the TSAP and network name components),
  786. // and it also contains other maintenance parts, such as a reference count,
  787. // ACL, and so on. All outstanding connection-oriented and connectionless
  788. // data transfer requests are queued here.
  789. //
  790. #define AREF_ADDRESS_FILE 0
  791. #define AREF_LOOKUP 1
  792. #define AREF_RECEIVE 2
  793. #define AREF_NAME_FRAME 3
  794. #define AREF_TIMER 4
  795. #define AREF_FIND 5
  796. #define AREF_TOTAL 8
  797. typedef struct _ADDRESS {
  798. #if DBG
  799. ULONG RefTypes[AREF_TOTAL];
  800. #endif
  801. USHORT Size;
  802. CSHORT Type;
  803. LIST_ENTRY Linkage; // next address/this device object.
  804. ULONG ReferenceCount; // number of references to this object.
  805. NB_LOCK Lock;
  806. //
  807. // The following fields comprise the actual address itself.
  808. //
  809. PREQUEST Request; // pointer to address creation request.
  810. UCHAR NameTypeFlag; // NB_NAME_UNIQUE or NB_NAME_GROUP
  811. NBI_NETBIOS_ADDRESS NetbiosAddress; // our netbios name.
  812. //
  813. // The following fields are used to maintain state about this address.
  814. //
  815. ULONG Flags; // attributes of the address.
  816. ULONG State; // current state of the address.
  817. struct _DEVICE *Device; // device context to which we are attached.
  818. PNB_LOCK DeviceLock;
  819. //
  820. // The following queues is used to hold send datagrams for this
  821. // address. Receive datagrams are queued to the address file. Requests are
  822. // processed in a first-in, first-out manner, so that the very next request
  823. // to be serviced is always at the head of its respective queue. These
  824. // queues are managed by the EXECUTIVE interlocked list management routines.
  825. // The actual objects which get queued to this structure are request control
  826. // blocks (RCBs).
  827. //
  828. LIST_ENTRY AddressFileDatabase; // list of defined address file objects
  829. UCHAR SendPacketHeader[NB_MAXIMUM_MAC + sizeof(IPX_HEADER)];
  830. //
  831. // This timer is used for registering the name.
  832. //
  833. CTETimer RegistrationTimer;
  834. //
  835. // Number of times an add name frame has been sent.
  836. //
  837. ULONG RegistrationCount;
  838. #ifdef ISN_NT
  839. //
  840. // These two can be a union because they are not used
  841. // concurrently.
  842. //
  843. union {
  844. //
  845. // This structure is used for checking share access.
  846. //
  847. SHARE_ACCESS ShareAccess;
  848. //
  849. // Used for delaying NbiDestroyAddress to a thread so
  850. // we can access the security descriptor.
  851. //
  852. WORK_QUEUE_ITEM DestroyAddressQueueItem;
  853. } u;
  854. //
  855. // This structure is used to hold ACLs on the address.
  856. PSECURITY_DESCRIPTOR SecurityDescriptor;
  857. #endif
  858. } ADDRESS, *PADDRESS;
  859. //
  860. // Values for Flags
  861. //
  862. #define ADDRESS_FLAGS_DUPLICATE_NAME 0x00000002
  863. #if defined(_PNP_POWER)
  864. #define ADDRESS_FLAGS_CONFLICT 0x00000010
  865. #endif _PNP_POWER
  866. #if defined(_PNP_POWER)
  867. //
  868. // this booleans are passed to nbiverifyaddressfile calls.
  869. //
  870. #define CONFLICT_IS_OK TRUE
  871. #define CONFLICT_IS_NOT_OK FALSE
  872. #endif _PNP_POWER
  873. //
  874. // Values for State
  875. //
  876. #define ADDRESS_STATE_REGISTERING 1
  877. #define ADDRESS_STATE_OPEN 2
  878. #define ADDRESS_STATE_STOPPING 3
  879. #if defined(_PNP_POWER)
  880. //
  881. // This holds the adapters names i.e netbios names which are
  882. // created from adater node address to support adapter status
  883. // queries using adapter node addresses.
  884. //
  885. typedef struct _ADAPTER_ADDRESS {
  886. USHORT Size;
  887. CSHORT Type;
  888. LIST_ENTRY Linkage; // next address/this device object.
  889. NIC_HANDLE NicHandle; // NicHandle corresponding to this address.
  890. UCHAR NetbiosName[16];
  891. } ADAPTER_ADDRESS, *PADAPTER_ADDRESS;
  892. #endif _PNP_POWER
  893. //
  894. // This defines the types of probe packets we can send.
  895. //
  896. typedef enum _NB_ACK_TYPE {
  897. NbiAckQuery,
  898. NbiAckResponse,
  899. NbiAckResend
  900. } NB_ACK_TYPE, *PNB_ACK_TYPE;
  901. //
  902. // This defines the a packetizing location in a
  903. // send.
  904. //
  905. typedef struct _SEND_POINTER {
  906. ULONG MessageOffset; // up count, bytes sent this message.
  907. PREQUEST Request; // current send request in chain.
  908. PNDIS_BUFFER Buffer; // current buffer in send chain.
  909. ULONG BufferOffset; // current byte offset in current buffer.
  910. USHORT SendSequence;
  911. } SEND_POINTER, *PSEND_POINTER;
  912. //
  913. // This defines the current location in a receive.
  914. //
  915. typedef struct _RECEIVE_POINTER {
  916. ULONG MessageOffset; // up count, bytes received this message.
  917. ULONG Offset; // up count, bytes received this request.
  918. PNDIS_BUFFER Buffer; // current buffer in receive request.
  919. ULONG BufferOffset; // current byte offset in current buffer.
  920. } RECEIVE_POINTER, *PRECEIVE_POINTER;
  921. //
  922. // This structure defines a connection, which controls a
  923. // session with a remote.
  924. //
  925. #define CREF_VERIFY 0
  926. #define CREF_LISTEN 1
  927. #define CREF_CONNECT 2
  928. #define CREF_WAIT_CACHE 3
  929. #define CREF_TIMER 4
  930. #define CREF_INDICATE 5
  931. #define CREF_ACTIVE 6
  932. #define CREF_FRAME 7
  933. #define CREF_BY_CONTEXT 8
  934. #define CREF_W_ACCEPT 9
  935. #define CREF_SEND 10
  936. #define CREF_RECEIVE 11
  937. #define CREF_PACKETIZE 12
  938. #define CREF_DISASSOC 13
  939. #define CREF_W_PACKET 14
  940. #define CREF_CANCEL 15
  941. #define CREF_NDIS_SEND 16
  942. #define CREF_SHORT_D_ACK 17
  943. #define CREF_LONG_D_ACK 18
  944. #define CREF_FIND_ROUTE 19
  945. #define CREF_ACCEPT 20
  946. #define CREF_TOTAL 24
  947. typedef struct _CONNECTION {
  948. #if DBG
  949. ULONG RefTypes[CREF_TOTAL];
  950. #endif
  951. CSHORT Type;
  952. USHORT Size;
  953. NB_LOCK Lock;
  954. PNB_LOCK DeviceLock;
  955. ULONG ReferenceCount; // number of references to this object.
  956. CONNECTION_CONTEXT Context; // client-specified value.
  957. ULONG State;
  958. ULONG SubState;
  959. ULONG ReceiveState; // SubState tracks sends when active.
  960. ULONG NewNetbios; // 1 if we negotiated this.
  961. REQUEST_LIST_HEAD SendQueue;
  962. REQUEST_LIST_HEAD ReceiveQueue;
  963. USHORT ReceiveSequence;
  964. USHORT LocalRcvSequenceMax; // we advertise to him (will be near SendSequence)
  965. USHORT RemoteRcvSequenceMax; // he advertises to us (will be near ReceiveSequence)
  966. USHORT SendWindowSequenceLimit; // when this send window ends (may send past it however)
  967. //
  968. // RemoteRcvSequenceMax is the largest frame number that he expects to
  969. // receive, while SendWindowSequenceLimit is one more than the max
  970. // we can send. I.e. if he is advertising a window of 4 and we think
  971. // the window should be 2, and the current send sequence is 7,
  972. // RemoteRcvSequenceMax is 10 and SendWindowSequenceLimit is 9.
  973. //
  974. USHORT ReceiveWindowSize; // when it is open, how big to make it
  975. USHORT SendWindowSize; // what we'll send, may be less than what he advertises
  976. USHORT MaxSendWindowSize; // maximum we allow it to grow to
  977. USHORT IncreaseWindowFailures; // how many windows after increase have had retransmits
  978. BOOLEAN RetransmitThisWindow; // we had to retransmit in this send window
  979. BOOLEAN SendWindowIncrease; // send window was just increased.
  980. BOOLEAN ResponseTimeout; // we hit timeout in SEND_W or REMOTE_W
  981. BOOLEAN SendBufferInUse; // current send's already queued on packet
  982. ULONG Retries;
  983. //
  984. // Tracks the current send.
  985. //
  986. SEND_POINTER CurrentSend;
  987. //
  988. // Tracks the unacked point in the send.
  989. //
  990. SEND_POINTER UnAckedSend;
  991. PREQUEST FirstMessageRequest; // first one in the message.
  992. PREQUEST LastMessageRequest; // last one in the message.
  993. ULONG CurrentMessageLength; // total length of current message.
  994. //
  995. // Tracks the current receive.
  996. //
  997. RECEIVE_POINTER CurrentReceive; // where to receive next data
  998. RECEIVE_POINTER PreviousReceive; // stores it while transfer in progress
  999. PREQUEST ReceiveRequest; // current one; not in ReceiveQueue
  1000. ULONG ReceiveLength; // length of ReceiveRequest
  1001. ULONG ReceiveUnaccepted; // by client...only indicate when == 0
  1002. ULONG CurrentIndicateOffset; // if previous frame was partially accepted.
  1003. IPX_LINE_INFO LineInfo; // for the adapter this connect is on.
  1004. ULONG MaximumPacketSize; // as negotiated during session init/ack
  1005. //
  1006. // Links us in the non-inactive connection hash bucket.
  1007. //
  1008. struct _CONNECTION * NextConnection;
  1009. //
  1010. // These are used to determine when to piggyback and when not to.
  1011. //
  1012. BOOLEAN NoPiggybackHeuristic; // we have reason to assume it would be bad.
  1013. BOOLEAN PiggybackAckTimeout; // we got a timeout last time we tried.
  1014. ULONG ReceivesWithoutAck; // used to do an auto ack.
  1015. //
  1016. // The following field is used as linkage in the device's
  1017. // PacketizeConnections queue.
  1018. //
  1019. LIST_ENTRY PacketizeLinkage;
  1020. //
  1021. // The following field is used as linkage in the device's
  1022. // WaitPacketConnections queue.
  1023. //
  1024. LIST_ENTRY WaitPacketLinkage;
  1025. //
  1026. // The following field is used as linkage in the device's
  1027. // DataAckConnections queue.
  1028. //
  1029. LIST_ENTRY DataAckLinkage;
  1030. //
  1031. // TRUE if we are on these queues.
  1032. //
  1033. BOOLEAN OnPacketizeQueue;
  1034. BOOLEAN OnWaitPacketQueue;
  1035. BOOLEAN OnDataAckQueue;
  1036. //
  1037. // TRUE if we have a piggyback ack pending.
  1038. //
  1039. BOOLEAN DataAckPending;
  1040. //
  1041. // TRUE if the current receive does not allow piggyback acks.
  1042. //
  1043. BOOLEAN CurrentReceiveNoPiggyback;
  1044. //
  1045. // Number of short timer expirations with the data ack queued.
  1046. //
  1047. ULONG DataAckTimeouts;
  1048. //
  1049. // Used to queue sends so that no two are outstanding at once.
  1050. //
  1051. ULONG NdisSendsInProgress;
  1052. LIST_ENTRY NdisSendQueue;
  1053. //
  1054. // This pointer is valid when NdisSendsInProgress is non-zero;
  1055. // it holds a pointer to a location on the stack of the thread
  1056. // which is inside NbiAssignSequenceAndSend. If this location
  1057. // is set to TRUE, it means the connection was stopped by another
  1058. // thread and a reference was added to keep the connection around.
  1059. //
  1060. PBOOLEAN NdisSendReference;
  1061. //
  1062. // These are used for timeouts.
  1063. //
  1064. ULONG BaseRetransmitTimeout; // config # of short timeouts we wait.
  1065. ULONG CurrentRetransmitTimeout; // possibly backed-off number
  1066. ULONG WatchdogTimeout; // how many long timeouts we wait.
  1067. ULONG Retransmit; // timer; based on Device->ShortAbsoluteTime
  1068. ULONG Watchdog; // timer; based on Device->LongAbsoluteTime
  1069. USHORT TickCount; // 18.21/second, # for 576-byte packet.
  1070. USHORT HopCount; // As returned by ipx on find route.
  1071. BOOLEAN OnShortList; // are we inserted in the list
  1072. BOOLEAN OnLongList; // are we inserted in the list
  1073. LIST_ENTRY ShortList; // queues us on Device->ShortList
  1074. LIST_ENTRY LongList; // queues us on Device->LongList
  1075. //
  1076. // These are valid when we have a connection established;
  1077. //
  1078. USHORT LocalConnectionId;
  1079. USHORT RemoteConnectionId;
  1080. PREQUEST DisassociatePending; // guarded by device lock.
  1081. PREQUEST ClosePending;
  1082. PREQUEST ConnectRequest;
  1083. PREQUEST ListenRequest;
  1084. PREQUEST AcceptRequest;
  1085. PREQUEST DisconnectRequest;
  1086. PREQUEST DisconnectWaitRequest;
  1087. ULONG CanBeDestroyed; // FALSE if reference is non-zero
  1088. ULONG ThreadsInHandleConnectionZero; // # of threads in HandleConnectionZero
  1089. //
  1090. // These are used to hold extra data that was sent on a session
  1091. // init, for use in sending the ack. Generally will be NULL and 0.
  1092. //
  1093. PUCHAR SessionInitAckData;
  1094. ULONG SessionInitAckDataLength;
  1095. IPX_LOCAL_TARGET LocalTarget; // for the remote when active.
  1096. IPX_HEADER RemoteHeader;
  1097. CTETimer Timer;
  1098. PADDRESS_FILE AddressFile; // guarded by device lock if associated.
  1099. LIST_ENTRY AddressFileLinkage; // guarded by device lock
  1100. ULONG AddressFileLinked; // TRUE if queued using AddressFileLinkage
  1101. PDEVICE Device;
  1102. #ifdef ISN_NT
  1103. PFILE_OBJECT FileObject; // easy backlink to file object.
  1104. #endif
  1105. CHAR RemoteName[16]; // for an active connection.
  1106. IPX_FIND_ROUTE_REQUEST FindRouteRequest; // use this to verify route.
  1107. TDI_CONNECTION_INFO ConnectionInfo; // can be queried from above.
  1108. BOOLEAN FindRouteInProgress; // we have a request pending.
  1109. BOOLEAN SendPacketInUse; // put this here to align packet/header.
  1110. BOOLEAN IgnoreNextDosProbe;
  1111. NTSTATUS Status; // status code for connection rundown.
  1112. #ifdef RSRC_TIMEOUT_DBG
  1113. LARGE_INTEGER FirstMessageRequestTime;
  1114. #endif //RSRC_TIMEOUT_DBG
  1115. NDIS_HANDLE SendPacketPoolHandle; // poolhandle for sendpacket below when
  1116. // the packet is allocated from ndis pool.
  1117. NB_SEND_PACKET SendPacket; // try to use this first for sends
  1118. ULONG Flags; // miscellaneous connection flags
  1119. UCHAR SendPacketHeader[1]; // connection is extended to include this
  1120. //
  1121. // NOTE: This is variable length structure!
  1122. // Do not add fields below this comment.
  1123. //
  1124. } CONNECTION, *PCONNECTION;
  1125. #define CONNECTION_STATE_INACTIVE 1
  1126. #define CONNECTION_STATE_CONNECTING 2
  1127. #define CONNECTION_STATE_LISTENING 3
  1128. #define CONNECTION_STATE_ACTIVE 4
  1129. #define CONNECTION_STATE_DISCONNECT 5
  1130. #define CONNECTION_STATE_CLOSING 6
  1131. #define CONNECTION_SUBSTATE_L_WAITING 1 // queued by a listen
  1132. #define CONNECTION_SUBSTATE_L_W_ACCEPT 2 // waiting for user to accept
  1133. #define CONNECTION_SUBSTATE_L_W_ROUTE 3 // waiting for rip response
  1134. #define CONNECTION_SUBSTATE_C_FIND_NAME 1 // waiting for cache response
  1135. #define CONNECTION_SUBSTATE_C_W_ACK 2 // waiting for session init ack
  1136. #define CONNECTION_SUBSTATE_C_W_ROUTE 3 // waiting for rip response
  1137. #define CONNECTION_SUBSTATE_C_DISCONN 4 // disconnect was issued
  1138. #define CONNECTION_SUBSTATE_A_IDLE 1 // no sends in progress
  1139. #define CONNECTION_SUBSTATE_A_PACKETIZE 2 // packetizing a send
  1140. #define CONNECTION_SUBSTATE_A_W_ACK 3 // waiting for an ack
  1141. #define CONNECTION_SUBSTATE_A_W_PACKET 4 // waiting for a packet
  1142. #define CONNECTION_SUBSTATE_A_W_EOR 5 // waiting for eor to start packetizing
  1143. #define CONNECTION_SUBSTATE_A_W_PROBE 6 // waiting for a keep-alive response
  1144. #define CONNECTION_SUBSTATE_A_REMOTE_W 7 // remote shut down our window
  1145. #define CONNECTION_RECEIVE_IDLE 1 // no receives queued
  1146. #define CONNECTION_RECEIVE_ACTIVE 2 // receive is queued
  1147. #define CONNECTION_RECEIVE_W_RCV 3 // waiting for receive to be posted
  1148. #define CONNECTION_RECEIVE_INDICATE 4 // indication in progress
  1149. #define CONNECTION_RECEIVE_TRANSFER 5 // transfer is in progress
  1150. #define CONNECTION_RECEIVE_PENDING 6 // last request is queued for completion
  1151. #define CONNECTION_SUBSTATE_D_W_ACK 1
  1152. #define CONNECTION_SUBSTATE_D_GOT_ACK 2
  1153. //
  1154. // Bit values for Flags field in
  1155. // the CONNECTION structure.
  1156. //
  1157. #define CONNECTION_FLAGS_AUTOCONNECTING 0x00000001 // RAS autodial in progress
  1158. #define CONNECTION_FLAGS_AUTOCONNECTED 0x00000002 // RAS autodial connected
  1159. #ifdef RSRC_TIMEOUT_DBG
  1160. extern ULONG NbiGlobalDebugResTimeout;
  1161. extern LARGE_INTEGER NbiGlobalMaxResTimeout;
  1162. extern NB_SEND_PACKET NbiGlobalDeathPacket; // try to use this first for sends
  1163. #endif //RSRC_TIMEOUT_DBG