Windows NT 4.0 source code leak
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.

1141 lines
20 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1993 Microsoft Corporation
  3. Module Name:
  4. dgpkt.hxx
  5. Abstract:
  6. This file contains the definitions for a dg packet.
  7. Author:
  8. Dave Steckler (davidst) 3-Mar-1992
  9. Revision History:
  10. --*/
  11. #ifndef __DGPKT_HXX__
  12. #define __DGPKT_HXX__
  13. #include <rpctran.h>
  14. #include <limits.h>
  15. #if defined(NTENV) || defined(WIN96)
  16. #define MULTITHREADED
  17. #include <threads.hxx>
  18. #include <delaytab.hxx>
  19. extern DELAYED_ACTION_NODE * GlobalScavengerTimer;
  20. extern DELAYED_ACTION_TABLE * DelayedActions;
  21. extern void
  22. GlobalScavengerProc(
  23. void * Unused
  24. );
  25. #endif // 32-bit platform
  26. #define DG_RPC_PROTOCOL_VERSION 4
  27. #define MAX_WINDOW_SIZE (CHAR_BIT * sizeof(unsigned))
  28. //
  29. // delay times
  30. //
  31. #define TWO_SECS_IN_MSEC (2 * 1000)
  32. #define THREE_SECS_IN_MSEC (3 * 1000)
  33. #define TEN_SECS_IN_MSEC (10 * 1000)
  34. #define FIFTEEN_SECS_IN_MSEC (15 * 1000)
  35. #define ONE_MINUTE_IN_MSEC (60 * 1000)
  36. #define FIVE_MINUTES_IN_MSEC (5 * 60 * 1000)
  37. inline unsigned long
  38. CurrentTimeInMsec(
  39. void
  40. )
  41. {
  42. #ifdef MULTITHREADED
  43. return GetTickCount();
  44. #else
  45. return 0;
  46. #endif
  47. }
  48. // PacketType values:
  49. #define DG_REQUEST 0
  50. #define DG_PING 1
  51. #define DG_RESPONSE 2
  52. #define DG_FAULT 3
  53. #define DG_WORKING 4
  54. #define DG_NOCALL 5
  55. #define DG_REJECT 6
  56. #define DG_ACK 7
  57. #define DG_QUIT 8
  58. #define DG_FACK 9
  59. #define DG_QUACK 10
  60. // PacketFlags values:
  61. #define DG_PF_INIT 0x0000
  62. #define DG_PF_FORWARDED 0x0001
  63. #define DG_PF_LAST_FRAG 0x0002
  64. #define DG_PF_FRAG 0x0004
  65. #define DG_PF_NO_FACK 0x0008
  66. #define DG_PF_MAYBE 0x0010
  67. #define DG_PF_IDEMPOTENT 0x0020
  68. #define DG_PF_BROADCAST 0x0040
  69. // In the AES this bit is "reserved for implementations"
  70. //
  71. #define DG_PF_OVERSIZE_PACKET 0x0080
  72. // for PacketFlags2:
  73. #define DG_PF_FORWARDED_2 0x0001
  74. #define DG_PF_CANCEL_PENDING 0x0002
  75. // for DREP[0]:
  76. #define DG_DREP_CHAR_ASCII 0
  77. #define DG_DREP_CHAR_EBCDIC 1
  78. #define DG_DREP_INT_BIG 0
  79. #define DG_DREP_INT_LITTLE 16
  80. // for DREP[1]
  81. #define DG_DREP_FP_IEEE 0
  82. #define DG_DREP_FP_VAX 1
  83. #define DG_DREP_FP_CRAY 2
  84. #define DG_DREP_FP_IBM 3
  85. #define DG_MSG_DREP_INITIALIZE 0x11111100
  86. #define NDR_DREP_ENDIAN_MASK 0xF0
  87. #define RPC_NCA_PACKET_FLAGS (RPC_NCA_FLAGS_IDEMPOTENT | RPC_NCA_FLAGS_BROADCAST | RPC_NCA_FLAGS_MAYBE)
  88. //
  89. // The RPC packet header and security verifier must each be 8-aligned.
  90. //
  91. #define PACKET_HEADER_ALIGNMENT (8)
  92. #define SECURITY_HEADER_ALIGNMENT (8)
  93. extern const unsigned RpcToPacketFlagsArray[];
  94. extern const unsigned PacketToRpcFlagsArray[];
  95. extern unsigned DefaultSocketBufferLength;
  96. extern unsigned DefaultMaxDatagramSize;
  97. //
  98. // Controls on the number of packets in the packet cache.
  99. // Note that these values are for each packet size, not the
  100. // cache as a whole.
  101. //
  102. #ifndef NO_PACKET_CACHE
  103. #define MIN_FREE_PACKETS 3
  104. #if defined(__RPC_DOS__)
  105. #define MAX_FREE_PACKETS 8
  106. #elif defined(__RPC_WIN16__)
  107. #define MAX_FREE_PACKETS 20
  108. #else
  109. #define MAX_FREE_PACKETS 1000
  110. #endif
  111. #else
  112. #define MIN_FREE_PACKETS 0
  113. #define MAX_FREE_PACKETS 0
  114. #endif
  115. #if defined(DOS) && !defined(WIN)
  116. typedef long LONG;
  117. typedef long PAPI * PLONG;
  118. #endif // Windows
  119. #if defined(MAC)
  120. typedef long LONG;
  121. typedef long PAPI * PLONG;
  122. #endif // Windows
  123. #ifndef min
  124. #define min(a,b) (((a) < (b)) ? (a) : (b))
  125. #endif
  126. typedef unsigned char boolean;
  127. //-------------------------------------------------------------------
  128. char __RPC_FAR *
  129. AllocateLargeBuffer(
  130. unsigned Size
  131. );
  132. void
  133. FreeLargeBuffer(
  134. void __RPC_FAR * Ptr
  135. );
  136. extern unsigned long __RPC_FAR
  137. MapToNcaStatusCode (
  138. IN RPC_STATUS RpcStatus
  139. );
  140. extern RPC_STATUS __RPC_FAR
  141. MapFromNcaStatusCode (
  142. IN unsigned long NcaStatus
  143. );
  144. inline unsigned
  145. PacketToRpcFlags(
  146. unsigned PacketFlags
  147. )
  148. {
  149. return PacketToRpcFlagsArray[(PacketFlags >> 4) & 7];
  150. }
  151. #ifndef WIN32
  152. inline LONG
  153. InterlockedExchange(
  154. LONG * pDest,
  155. LONG New
  156. )
  157. {
  158. LONG Old = *pDest;
  159. *pDest = New;
  160. return Old;
  161. }
  162. inline LONG
  163. InterlockedIncrement(
  164. LONG * pDest
  165. )
  166. {
  167. LONG Old = *pDest;
  168. *pDest = 1+Old;
  169. return Old;
  170. }
  171. inline LONG
  172. InterlockedDecrement(
  173. LONG * pDest
  174. )
  175. {
  176. LONG Old = *pDest;
  177. *pDest = -1+Old;
  178. return Old;
  179. }
  180. #endif // !NTENV
  181. //-------------------------------------------------------------------
  182. struct DG_SECURITY_TRAILER
  183. {
  184. unsigned char protection_level;
  185. unsigned char key_vers_num;
  186. };
  187. typedef DG_SECURITY_TRAILER __RPC_FAR * PDG_SECURITY_TRAILER;
  188. struct FACK_BODY_VER_0
  189. {
  190. // FACK body version; we understand only zero.
  191. //
  192. unsigned char Version;
  193. // pad byte
  194. //
  195. unsigned char Pad1;
  196. // Window size, in kilobytes.
  197. // BUGBUG AES/DC contradicts itself on page 12-18; is it kilobytes or packets?
  198. //
  199. unsigned short WindowSize;
  200. // Largest datagram the sender can handle, in bytes.
  201. //
  202. unsigned long MaxDatagramSize;
  203. // Largest datagram that won't be fragmented over the wire, in bytes.
  204. //
  205. unsigned long MaxPacketSize;
  206. // Serial number of packet that caused this FACK.
  207. //
  208. unsigned short SerialNumber;
  209. // Number of unsigned longs in the Acks[] array.
  210. //
  211. unsigned short AckWordCount;
  212. #pragma warning(disable:4200)
  213. // Array of bit masks.
  214. //
  215. unsigned long Acks[0];
  216. #pragma warning(default:4200)
  217. };
  218. void
  219. ByteSwapFackBody0(
  220. FACK_BODY_VER_0 __RPC_FAR * pBody
  221. );
  222. typedef unsigned char DREP[4];
  223. //
  224. // The following structure is the NCA Datagram RPC packet header.
  225. //
  226. struct _NCA_PACKET_HEADER
  227. {
  228. unsigned char RpcVersion;
  229. unsigned char PacketType;
  230. unsigned char PacketFlags;
  231. unsigned char PacketFlags2;
  232. DREP DataRep;
  233. RPC_UUID ObjectId;
  234. RPC_UUID InterfaceId;
  235. RPC_UUID ActivityId;
  236. unsigned long ServerBootTime;
  237. RPC_VERSION InterfaceVersion;
  238. unsigned long SequenceNumber;
  239. unsigned short OperationNumber;
  240. unsigned short InterfaceHint;
  241. unsigned short ActivityHint;
  242. unsigned short PacketBodyLen;
  243. unsigned short FragmentNumber;
  244. unsigned char AuthProto;
  245. unsigned char SerialLo;
  246. #pragma warning(disable:4200)
  247. unsigned char Data[0];
  248. #pragma warning(default:4200)
  249. };
  250. typedef struct _NCA_PACKET_HEADER NCA_PACKET_HEADER, PAPI * PNCA_PACKET_HEADER;
  251. struct QUIT_BODY_0
  252. {
  253. unsigned long Version;
  254. unsigned long EventId;
  255. };
  256. struct QUACK_BODY_0
  257. {
  258. unsigned long Version;
  259. unsigned long EventId;
  260. unsigned char Accepted;
  261. };
  262. class DG_PACKET;
  263. typedef DG_PACKET PAPI * PDG_PACKET;
  264. class __RPC_FAR DG_PACKET
  265. /*++
  266. Class Description:
  267. This class represents a packet that will be sent or received on the
  268. network.
  269. Fields:
  270. pTransAddress - A pointer to either a DG_CLIENT_TRANS_ADDRESS or
  271. a DG_SERVER_TRANS_ADDRESS that this packet will be sent or
  272. received through.
  273. pNcaPacketHeader - Where the packet information goes. Marshalled data
  274. follows immediately after this header.
  275. DataLength - Length of the marshalled data.
  276. TimeReceive - Time in seconds that this packet was
  277. received. This is filled in by the transport.
  278. pNext, pPrevious - Used to keep these packets in a list.
  279. --*/
  280. {
  281. public:
  282. unsigned MaxDataLength;
  283. unsigned DataLength;
  284. DG_PACKET * pNext;
  285. DG_PACKET * pPrevious;
  286. unsigned Flags;
  287. // Tick count when the packet was added to the free list.
  288. //
  289. unsigned TimeReceived;
  290. // WARNING: Header must be 8-byte-aligned.
  291. //
  292. NCA_PACKET_HEADER Header;
  293. //--------------------------------------------------------------------
  294. DG_PACKET(
  295. unsigned PacketLength
  296. );
  297. ~DG_PACKET();
  298. void PAPI *
  299. operator new(
  300. size_t ObjectSize,
  301. unsigned BufferLength
  302. );
  303. void
  304. operator delete(
  305. void PAPI * UserBuffer,
  306. size_t ObjectSize
  307. );
  308. static PDG_PACKET
  309. AllocatePacket(
  310. unsigned BufferLength
  311. );
  312. static void
  313. FreePacket(
  314. PDG_PACKET pPacket
  315. );
  316. static unsigned
  317. ScavengePackets(
  318. unsigned Age
  319. );
  320. static void
  321. FlushPacketLists(
  322. );
  323. static RPC_STATUS
  324. Initialize(
  325. );
  326. inline static PDG_PACKET
  327. ContainingRecord(
  328. void __RPC_FAR * Buffer
  329. )
  330. {
  331. return CONTAINING_RECORD (Buffer, DG_PACKET, Header.Data);
  332. }
  333. private:
  334. enum { NUMBER_OF_PACKET_LISTS = 6 };
  335. struct PACKET_LIST
  336. {
  337. unsigned PacketLength;
  338. unsigned Count;
  339. PDG_PACKET Head;
  340. };
  341. static MUTEX * PacketListMutex;
  342. static PACKET_LIST PacketLists[NUMBER_OF_PACKET_LISTS];
  343. };
  344. inline
  345. DG_PACKET::DG_PACKET(
  346. unsigned PacketLength
  347. )
  348. {
  349. MaxDataLength = PacketLength;
  350. }
  351. inline
  352. DG_PACKET::~DG_PACKET()
  353. {
  354. }
  355. inline void PAPI *
  356. DG_PACKET::operator new(
  357. size_t ObjectSize,
  358. unsigned BufferLength
  359. )
  360. /*++
  361. Routine Description:
  362. Allocates a DG_PACKET with the specified buffer size.
  363. Arguments:
  364. ObjectSize - generated by compiler; same as sizeof(DG_PACKET)
  365. BufferLength - PDU size, including NCA header
  366. Return Value:
  367. an 8-byte-aligned pointer to an obect of the requested size
  368. --*/
  369. {
  370. unsigned Size = ObjectSize + BufferLength - sizeof(NCA_PACKET_HEADER);
  371. return AllocateLargeBuffer(Size);
  372. }
  373. inline void
  374. DG_PACKET::operator delete(
  375. void PAPI * UserBuffer,
  376. size_t ObjectSize
  377. )
  378. {
  379. FreeLargeBuffer(UserBuffer);
  380. }
  381. void
  382. ByteSwapPacketHeader(
  383. PDG_PACKET pPacket
  384. );
  385. inline BOOL
  386. NeedsByteSwap(
  387. PNCA_PACKET_HEADER pHeader
  388. )
  389. {
  390. #ifdef __RPC_MAC__
  391. if (pHeader->DataRep[0] & DG_DREP_INT_LITTLE)
  392. {
  393. return TRUE;
  394. }
  395. else
  396. {
  397. return FALSE;
  398. }
  399. #else
  400. if (pHeader->DataRep[0] & DG_DREP_INT_LITTLE)
  401. {
  402. return FALSE;
  403. }
  404. else
  405. {
  406. return TRUE;
  407. }
  408. #endif
  409. }
  410. inline void
  411. ByteSwapPacketHeaderIfNecessary(
  412. PDG_PACKET pPacket
  413. )
  414. {
  415. if (NeedsByteSwap(&pPacket->Header))
  416. {
  417. ByteSwapPacketHeader(pPacket);
  418. }
  419. }
  420. #define ByteSwapLong(Value) \
  421. Value = ( (((Value) & 0xFF000000) >> 24) \
  422. | (((Value) & 0x00FF0000) >> 8) \
  423. | (((Value) & 0x0000FF00) << 8) \
  424. | (((Value) & 0x000000FF) << 24))
  425. #define ByteSwapShort(Value) \
  426. Value = ( (((Value) & 0x00FF) << 8) \
  427. | (((Value) & 0xFF00) >> 8))
  428. inline unsigned short
  429. ReadSerialNumber(
  430. PNCA_PACKET_HEADER pHeader
  431. )
  432. {
  433. unsigned short SerialNum = 0;
  434. SerialNum = pHeader->SerialLo;
  435. SerialNum |= (pHeader->DataRep[3] << 8);
  436. return SerialNum;
  437. }
  438. inline void
  439. SetMyDataRep(
  440. PNCA_PACKET_HEADER pHeader
  441. )
  442. {
  443. #ifdef __RPC_MAC__
  444. pHeader->DataRep[0] = DG_DREP_CHAR_ASCII | DG_DREP_INT_BIG;
  445. pHeader->DataRep[1] = DG_DREP_FP_IEEE;
  446. pHeader->DataRep[2] = 0;
  447. #else
  448. pHeader->DataRep[0] = DG_DREP_CHAR_ASCII | DG_DREP_INT_LITTLE;
  449. pHeader->DataRep[1] = DG_DREP_FP_IEEE;
  450. pHeader->DataRep[2] = 0;
  451. #endif
  452. }
  453. inline char __RPC_FAR *
  454. AllocateLargeBuffer(
  455. unsigned Size
  456. )
  457. /*++
  458. Routine Description:
  459. Rpc Stubs expect buffers to be 8 [ALIGN_REQUIRED] aligned
  460. NT allocator does this by default
  461. DOS/WIN allocators are 2 bytes aligned and we need to allign
  462. here appropriately
  463. This routine exists only for DOS and WINDOWS
  464. Arguments:
  465. Size - size of memoryblock reqd.
  466. Return Value:
  467. Buffer that is allocated or 0
  468. --*/
  469. {
  470. #ifdef NTENV
  471. return new char[Size];
  472. #else
  473. void PAPI * RealBuffer;
  474. char pad;
  475. RealBuffer = RpcpFarAllocate(Size + PACKET_HEADER_ALIGNMENT);
  476. if (RealBuffer == 0)
  477. {
  478. return 0;
  479. }
  480. ASSERT(PACKET_HEADER_ALIGNMENT == 8);
  481. pad = Pad((char __RPC_FAR *)RealBuffer + 1, PACKET_HEADER_ALIGNMENT) + 1;
  482. ASSERT(pad > 0 && pad <= PACKET_HEADER_ALIGNMENT);
  483. char PAPI * UserBuffer = (char PAPI *) RealBuffer;
  484. UserBuffer += pad;
  485. UserBuffer[-1] = pad;
  486. ASSERT(Align8(UserBuffer) == UserBuffer);
  487. return UserBuffer;
  488. #endif
  489. }
  490. inline void
  491. FreeLargeBuffer(
  492. void __RPC_FAR * Ptr
  493. )
  494. {
  495. #ifdef NTENV
  496. delete Ptr;
  497. #else
  498. char PAPI * RealPointer = (char PAPI *) Ptr;
  499. ASSERT(RealPointer[-1] <= PACKET_HEADER_ALIGNMENT);
  500. RealPointer -= RealPointer[-1];
  501. RpcpFarFree(RealPointer);
  502. #endif
  503. }
  504. inline void
  505. DeleteSpuriousAuthProto(
  506. PDG_PACKET pPacket
  507. )
  508. /*++
  509. Routine Description:
  510. Some versions of OSF DCE generate packets that specify an auth proto,
  511. but do not actually have an auth trailer. They should be interpreted
  512. as unsecure packets.
  513. Arguments:
  514. the packet to clean up
  515. Return Value:
  516. none
  517. --*/
  518. {
  519. if (pPacket->Header.AuthProto != 0 &&
  520. pPacket->Header.PacketBodyLen == pPacket->DataLength)
  521. {
  522. pPacket->Header.AuthProto = 0;
  523. }
  524. }
  525. class DG_ASSOCIATION
  526. {
  527. public:
  528. unsigned short CurrentPduSize;
  529. unsigned short RemoteWindowSize;
  530. DG_ASSOCIATION(
  531. unsigned a_InitialPduSize,
  532. RPC_STATUS __RPC_FAR * pStatus
  533. )
  534. : ReferenceCount (1),
  535. RemoteWindowSize (1),
  536. CurrentPduSize (a_InitialPduSize),
  537. Mutex (pStatus)
  538. {
  539. }
  540. void
  541. IncrementRefCount(
  542. )
  543. {
  544. ReferenceCount.Increment();
  545. }
  546. long
  547. DecrementRefCount(
  548. )
  549. {
  550. return ReferenceCount.Decrement();
  551. }
  552. void
  553. RequestMutex(
  554. )
  555. {
  556. Mutex.Request();
  557. }
  558. void
  559. ClearMutex(
  560. )
  561. {
  562. Mutex.Clear();
  563. }
  564. void
  565. SetMaxPduSize(
  566. unsigned PduSize
  567. )
  568. {
  569. CurrentPduSize = PduSize;
  570. }
  571. unsigned
  572. InqMaxPduSize(
  573. )
  574. {
  575. return CurrentPduSize;
  576. }
  577. protected:
  578. INTERLOCKED_INTEGER ReferenceCount;
  579. MUTEX Mutex;
  580. };
  581. typedef DG_ASSOCIATION * PDG_ASSOCIATION;
  582. class DG_PACKET_ENGINE
  583. {
  584. public:
  585. unsigned short ActivityHint;
  586. unsigned short InterfaceHint;
  587. unsigned long SequenceNumber;
  588. PDG_PACKET pSavedPacket;
  589. //--------------------------------------------------------------------
  590. DG_PACKET_ENGINE::DG_PACKET_ENGINE(
  591. unsigned short a_CurrentPduSize,
  592. unsigned short a_MaxPduSize,
  593. unsigned short a_MaxPacketSize,
  594. unsigned short a_SendWindowSize,
  595. unsigned a_TransportBufferLength,
  596. RPC_STATUS __RPC_FAR * pStatus
  597. );
  598. ~DG_PACKET_ENGINE(
  599. );
  600. void
  601. NewCall(
  602. );
  603. RPC_STATUS
  604. SetupSendWindow(
  605. PRPC_MESSAGE Message
  606. );
  607. void
  608. CleanupReceiveWindow(
  609. );
  610. RPC_STATUS
  611. SendSomeFragments(
  612. unsigned char PacketType
  613. );
  614. RPC_STATUS
  615. SendFragment(
  616. unsigned FragNum,
  617. unsigned char PacketType,
  618. BOOL fFack
  619. );
  620. virtual RPC_STATUS
  621. SealAndSendPacket(
  622. PNCA_PACKET_HEADER pHeader
  623. ) = 0;
  624. RPC_STATUS
  625. SendFack(
  626. PDG_PACKET pPacket
  627. );
  628. void
  629. UpdateSendWindow(
  630. PDG_PACKET pPacket,
  631. PSECURITY_CONTEXT pSecurityContext,
  632. PDG_ASSOCIATION Association
  633. );
  634. BOOL
  635. UpdateReceiveWindow(
  636. PDG_PACKET pPacket
  637. );
  638. RPC_STATUS
  639. AssembleBufferFromPackets(
  640. IN OUT PRPC_MESSAGE pMessage,
  641. CONNECTION * pConn
  642. );
  643. void
  644. SetFragmentLengths(
  645. SECURITY_CONTEXT * SecurityContext
  646. );
  647. inline void
  648. RecalcFragmentSize(
  649. );
  650. void
  651. RecalcPduSize(
  652. );
  653. BOOL
  654. ReceivedAllFrags(
  655. );
  656. unsigned short
  657. LastConsecutiveFragment(
  658. )
  659. {
  660. if (0 == pLastConsecutivePacket)
  661. {
  662. return 0xffff;
  663. }
  664. else
  665. {
  666. return pLastConsecutivePacket->Header.FragmentNumber;
  667. }
  668. }
  669. void
  670. MarkAllPacketsReceived(
  671. )
  672. {
  673. SendWindowBase = FinalSendFrag+1;
  674. }
  675. BOOL
  676. IsBufferAcknowledged(
  677. )
  678. {
  679. if (SendWindowBase > FinalSendFrag)
  680. {
  681. return TRUE;
  682. }
  683. return FALSE;
  684. }
  685. BOOL
  686. IsBufferSent(
  687. )
  688. {
  689. if (FirstUnsentFragment > FinalSendFrag)
  690. {
  691. return TRUE;
  692. }
  693. return FALSE;
  694. }
  695. inline void
  696. AddSerialNumber(
  697. PNCA_PACKET_HEADER pHeader
  698. );
  699. protected:
  700. PDG_PACKET
  701. AllocatePacket(
  702. )
  703. {
  704. return DG_PACKET::AllocatePacket(MaxPduSize);
  705. }
  706. void
  707. FreePacket(
  708. PDG_PACKET Packet
  709. )
  710. {
  711. DG_PACKET::FreePacket(Packet);
  712. }
  713. //
  714. //--------------data common to send and receive buffers-------------------
  715. //
  716. //
  717. // Biggest datagram the transport can send or receive, possibly
  718. // with fragmentation and reassembly.
  719. //
  720. unsigned short MaxPduSize;
  721. //
  722. // Biggest packet that transport won't fragment.
  723. //
  724. unsigned short MaxPacketSize;
  725. //
  726. // Largest PDU that this object will send.
  727. //
  728. unsigned short CurrentPduSize;
  729. //
  730. // Value of CurrentPduSize for the next RPC call.
  731. //
  732. unsigned short NextCallPduSize;
  733. //
  734. // Number of bytes of stub data in a datagram.
  735. //
  736. unsigned short MaxFragmentSize;
  737. //
  738. // Number of bytes of security trailer in a datagram.
  739. //
  740. unsigned short SecurityTrailerSize;
  741. //
  742. // number of consecutive unacknowledged packets, including retransmissions
  743. //
  744. unsigned TimeoutCount;
  745. unsigned short SendSerialNumber;
  746. unsigned short ReceiveSerialNumber;
  747. unsigned long CancelEventId;
  748. LONG Cancelled;
  749. #ifdef MULTITHREADED
  750. BOOL CancelPending;
  751. #endif
  752. //
  753. // -------------------data concerning send buffer-------------------------
  754. //
  755. void PAPI * Buffer;
  756. unsigned BufferLength;
  757. unsigned long BufferFlags;
  758. //
  759. // maximum number of packets in send window
  760. //
  761. unsigned short SendWindowSize;
  762. //
  763. // number of packets to transmit in one shot
  764. //
  765. unsigned short SendBurstLength;
  766. //
  767. // lowest unacknowledged fragment
  768. //
  769. unsigned short SendWindowBase;
  770. //
  771. // first fragment that has never been sent
  772. //
  773. unsigned short FirstUnsentFragment;
  774. //
  775. // Buffer offset of FirstUnsentFragment.
  776. //
  777. unsigned FirstUnsentOffset;
  778. //
  779. // bit mask showing which fragments to send
  780. // (same format as in FACK packet with body)
  781. //
  782. unsigned SendWindowBits;
  783. //
  784. // For each unacknowledged fragment, we need to know the serial number
  785. // of the last retransmission. When a FACK arrives, we will retransmit
  786. // only those packets with a serial number less than that of the FACK.
  787. //
  788. struct
  789. {
  790. unsigned short SerialNumber;
  791. unsigned short Length;
  792. unsigned Offset;
  793. }
  794. FragmentRingBuffer[MAX_WINDOW_SIZE];
  795. unsigned RingBufferBase;
  796. //
  797. // last fragment of buffer
  798. //
  799. unsigned short FinalSendFrag;
  800. // serial number of last packet FACKed by other end
  801. //
  802. unsigned short FackSerialNumber;
  803. //
  804. // ----------------data concerning receive buffer-------------------------
  805. //
  806. //
  807. // all received packets
  808. //
  809. PDG_PACKET pReceivedPackets;
  810. //
  811. // last packet before a gap
  812. //
  813. PDG_PACKET pLastConsecutivePacket;
  814. //
  815. // maximum number of packets in receive window
  816. //
  817. unsigned short ReceiveWindowSize;
  818. //
  819. // First fragment we should keep. Elder fragments belong to a previous
  820. // pipe buffer.
  821. //
  822. unsigned short ReceiveFragmentBase;
  823. //
  824. // Length of the underlying transport's socket buffer.
  825. //
  826. unsigned TransportBufferLength;
  827. //
  828. // Number of bytes in consecutive fragments.
  829. //
  830. unsigned ConsecutiveDataBytes;
  831. //
  832. // The last-allocated pipe receive buffer, and its length.
  833. //
  834. void __RPC_FAR *LastReceiveBuffer;
  835. unsigned LastReceiveBufferLength;
  836. boolean fReceivedAllFragments;
  837. boolean fRetransmitted;
  838. };
  839. inline void
  840. SetSerialNumber(
  841. PNCA_PACKET_HEADER pHeader,
  842. unsigned short SerialNumber
  843. )
  844. {
  845. pHeader->SerialLo = SerialNumber & 0x00ffU;
  846. pHeader->DataRep[3] = (unsigned char) (SerialNumber >> 8);
  847. }
  848. inline void
  849. DG_PACKET_ENGINE::AddSerialNumber(
  850. PNCA_PACKET_HEADER pHeader
  851. )
  852. {
  853. SetSerialNumber(pHeader, SendSerialNumber);
  854. }
  855. //------------------------------------------------------------------------
  856. RPC_STATUS
  857. VerifySecurePacket(
  858. PDG_PACKET pPacket,
  859. SECURITY_CONTEXT * pSecurityContext
  860. );
  861. #endif // __DGPKT_HXX__