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.

1380 lines
36 KiB

  1. //
  2. // AppSharing T.120 Layer
  3. // * GCC (conference management)
  4. // * MCS (data)
  5. // * FLOW (data queuing, flow control)
  6. //
  7. // This is also used by ObMan for old Whiteboard, but old Whiteboard will
  8. // disappear in the next version of NM.
  9. //
  10. // Copyright (c) Microsoft 1998-
  11. //
  12. #ifndef _H_AST120
  13. #define _H_AST120
  14. #include <confreg.h>
  15. // REAL T.120 headers
  16. #include <t120.h>
  17. #include <igccapp.h>
  18. #include <imcsapp.h>
  19. #include <iappldr.h>
  20. #include <mtgset.h>
  21. //
  22. // GCC PART
  23. //
  24. //
  25. // Call Manager Secondaries
  26. //
  27. #define CMTASK_FIRST 0
  28. typedef enum
  29. {
  30. CMTASK_OM = CMTASK_FIRST,
  31. CMTASK_AL,
  32. CMTASK_DCS,
  33. CMTASK_WB,
  34. CMTASK_MAX
  35. }
  36. CMTASK;
  37. //
  38. // The GCC Application Registry Key. This is used for enrolling Groupware
  39. // with GCC and for assigning tokens: for all tokens the registration key
  40. // is the Groupware application key followed by the specific tokenKey for
  41. // this secondary.
  42. //
  43. // The MFGCODE portion of this key has been assigned by the ITU.
  44. //
  45. // USACode1 0xb5
  46. // USACode2 0x00
  47. // MFGCode1 0x53
  48. // MFGCode2 0x4c
  49. // "Groupware" 0x02
  50. //
  51. // The length of the key in bytes including the NULLTERM.
  52. //
  53. //
  54. #define GROUPWARE_GCC_APPLICATION_KEY "\xb5\x00\x53\x4c\x02"
  55. //
  56. // Call Manager Events
  57. //
  58. enum
  59. {
  60. CMS_NEW_CALL = CM_BASE_EVENT,
  61. CMS_END_CALL,
  62. CMS_PERSON_JOINED,
  63. CMS_PERSON_LEFT,
  64. CMS_CHANNEL_REGISTER_CONFIRM,
  65. CMS_TOKEN_ASSIGN_CONFIRM
  66. };
  67. //
  68. // CM_STATUS
  69. //
  70. typedef struct tagCM_STATUS
  71. {
  72. UINT_PTR callID;
  73. UINT peopleCount;
  74. BOOL fTopProvider;
  75. UINT topProviderID;
  76. NM30_MTG_PERMISSIONS attendeePermissions;
  77. TSHR_PERSONID localHandle;
  78. char localName[TSHR_MAX_PERSON_NAME_LEN];
  79. }
  80. CM_STATUS;
  81. typedef CM_STATUS * PCM_STATUS;
  82. //
  83. // Secondary instance data
  84. //
  85. typedef struct tagCM_CLIENT
  86. {
  87. STRUCTURE_STAMP
  88. PUT_CLIENT putTask;
  89. CMTASK taskType;
  90. UINT useCount;
  91. // Registering Channel
  92. UINT channelKey;
  93. // Assigning Token
  94. UINT tokenKey;
  95. BOOL exitProcRegistered:1;
  96. }
  97. CM_CLIENT;
  98. typedef CM_CLIENT * PCM_CLIENT;
  99. //
  100. // Person element in linked list of people currently in conference
  101. //
  102. typedef struct tagCM_PERSON
  103. {
  104. BASEDLIST chain;
  105. TSHR_PERSONID netID;
  106. }
  107. CM_PERSON;
  108. typedef CM_PERSON * PCM_PERSON;
  109. //
  110. // Primary data
  111. //
  112. typedef struct tagCM_PRIMARY
  113. {
  114. STRUCTURE_STAMP
  115. PUT_CLIENT putTask;
  116. BOOL exitProcRegistered;
  117. //
  118. // Secondary tasks
  119. //
  120. PCM_CLIENT tasks[CMTASK_MAX];
  121. //
  122. // T.120/call state stuff
  123. //
  124. UINT_PTR callID;
  125. BOOL currentCall;
  126. BOOL fTopProvider;
  127. BOOL bGCCEnrolled;
  128. IGCCAppSap * pIAppSap;
  129. UserID gccUserID;
  130. UserID gccTopProviderID;
  131. //
  132. // People conference stuff
  133. //
  134. char localName[TSHR_MAX_PERSON_NAME_LEN];
  135. UINT peopleCount;
  136. BASEDLIST people;
  137. }
  138. CM_PRIMARY;
  139. typedef CM_PRIMARY * PCM_PRIMARY;
  140. __inline void ValidateCMP(PCM_PRIMARY pcmPrimary)
  141. {
  142. ASSERT(!IsBadWritePtr(pcmPrimary, sizeof(CM_PRIMARY)));
  143. ASSERT(pcmPrimary->putTask);
  144. }
  145. __inline void ValidateCMS(PCM_CLIENT pcm)
  146. {
  147. extern PCM_PRIMARY g_pcmPrimary;
  148. ValidateCMP(g_pcmPrimary);
  149. ASSERT(!IsBadWritePtr(pcm, sizeof(CM_CLIENT)));
  150. ASSERT(pcm->putTask);
  151. ASSERT(pcm->taskType >= CMTASK_FIRST);
  152. ASSERT(pcm->taskType < CMTASK_MAX);
  153. ASSERT(g_pcmPrimary->tasks[pcm->taskType] == pcm);
  154. }
  155. //
  156. // CM Primary Functions
  157. //
  158. BOOL CMP_Init(BOOL * pfCleanup);
  159. void CMP_Term(void);
  160. void CMPCallEnded(PCM_PRIMARY pcmPrimary);
  161. void CMPBroadcast(PCM_PRIMARY pcmPrimary, UINT event, UINT param1, UINT_PTR param2);
  162. void CALLBACK CMPExitProc(LPVOID pcmPrimary);
  163. BOOL CMPGCCEnroll(PCM_PRIMARY pcmPrimary,
  164. GCCConferenceID conferenceID,
  165. BOOL fEnroll);
  166. void CMPProcessPermitToEnroll(PCM_PRIMARY pcmPrimary,
  167. GCCAppPermissionToEnrollInd FAR * pMsg);
  168. void CMPProcessEnrollConfirm(PCM_PRIMARY pcmPrimary,
  169. GCCAppEnrollConfirm FAR * pMsg);
  170. void CMPProcessRegistryConfirm(PCM_PRIMARY pcmPrimary,
  171. GCCMessageType messageType,
  172. GCCRegistryConfirm FAR * pMsg);
  173. void CMPProcessAppRoster(PCM_PRIMARY pcmPrimary,
  174. GCCConferenceID confID,
  175. GCCApplicationRoster FAR * pAppRoster);
  176. //
  177. // Process GCC callbacks
  178. //
  179. void CALLBACK CMPGCCCallback(GCCAppSapMsg FAR * pMsg);
  180. void CMPBuildGCCRegistryKey(UINT dcgKeyNum, GCCRegistryKey FAR * pGCCKey, LPSTR dcgKeyStr);
  181. //
  182. // CM Secondary
  183. //
  184. BOOL CMS_Register(PUT_CLIENT putTask, CMTASK taskType, PCM_CLIENT * pCmHandle);
  185. void CMS_Deregister(PCM_CLIENT * pCmHandle);
  186. #ifdef __cplusplus
  187. extern "C"
  188. {
  189. #endif
  190. BOOL WINAPI CMS_GetStatus(PCM_STATUS pCmStats);
  191. #ifdef __cplusplus
  192. }
  193. #endif
  194. BOOL CMS_ChannelRegister(PCM_CLIENT pcmClient, UINT channelKey, UINT channelID);
  195. BOOL CMS_AssignTokenId(PCM_CLIENT pcmClient, UINT tokenKey);
  196. void CALLBACK CMSExitProc(LPVOID pcmClient);
  197. //
  198. // MCS PART
  199. //
  200. //
  201. // Errors
  202. //
  203. enum
  204. {
  205. // Generic errors
  206. NET_RC_NO_MEMORY = NET_BASE_RC,
  207. NET_RC_INVALID_STATE,
  208. // S20 errors
  209. NET_RC_S20_FAIL,
  210. // MGC errors
  211. NET_RC_MGC_ALREADY_INITIALIZED,
  212. NET_RC_MGC_INVALID_USER_HANDLE,
  213. NET_RC_MGC_INVALID_LENGTH,
  214. NET_RC_MGC_INVALID_DOMAIN,
  215. NET_RC_MGC_TOO_MUCH_IN_USE,
  216. NET_RC_MGC_NOT_YOUR_BUFFER,
  217. NET_RC_MGC_LIST_FAIL,
  218. NET_RC_MGC_NOT_CONNECTED,
  219. NET_RC_MGC_NOT_SUPPORTED,
  220. NET_RC_MGC_NOT_INITIALIZED,
  221. NET_RC_MGC_INIT_FAIL,
  222. NET_RC_MGC_DOMAIN_IN_USE,
  223. NET_RC_MGC_NOT_ATTACHED,
  224. NET_RC_MGC_INVALID_CONN_HANDLE,
  225. NET_RC_MGC_INVALID_UP_DOWN_PARM,
  226. NET_RC_MGC_INVALID_REMOTE_ADDRESS,
  227. NET_RC_MGC_CALL_FAILED
  228. };
  229. //
  230. // Results
  231. //
  232. typedef TSHR_UINT16 NET_RESULT;
  233. enum
  234. {
  235. NET_RESULT_OK = 0,
  236. NET_RESULT_NOK,
  237. NET_RESULT_CHANNEL_UNAVAILABLE,
  238. NET_RESULT_DOMAIN_UNAVAILABLE,
  239. NET_RESULT_REJECTED,
  240. NET_RESULT_TOKEN_ALREADY_GRABBED,
  241. NET_RESULT_TOKEN_NOT_OWNED,
  242. NET_RESULT_NOT_SPECIFIED,
  243. NET_RESULT_UNKNOWN,
  244. NET_RESULT_USER_REJECTED
  245. };
  246. //
  247. // Reaons
  248. //
  249. typedef enum
  250. {
  251. NET_REASON_DOMAIN_DISCONNECTED = 1,
  252. NET_REASON_DOMAIN_UNAVAILABLE,
  253. NET_REASON_TOKEN_NONEXISTENT,
  254. NET_REASON_USER_REQUESTED,
  255. NET_REASON_CHANNEL_UNAVAILABLE,
  256. NET_REASON_UNKNOWN
  257. }
  258. NET_REASON;
  259. //
  260. // Events
  261. //
  262. enum
  263. {
  264. NET_EVENT_USER_ATTACH = NET_BASE_EVENT,
  265. NET_EVENT_USER_DETACH,
  266. NET_EVENT_CHANNEL_JOIN,
  267. NET_EVENT_CHANNEL_LEAVE,
  268. NET_EVENT_TOKEN_GRAB,
  269. NET_EVENT_TOKEN_INHIBIT,
  270. NET_EVENT_DATA_RECEIVED,
  271. NET_FEEDBACK,
  272. NET_FLOW,
  273. NET_MG_SCHEDULE,
  274. NET_MG_WATCHDOG
  275. };
  276. //
  277. // FOR MCS USERS (ALL APPS, INCLUDING CALL MANAGER)
  278. //
  279. // state->| 0 | 1 | 2 | 3 | 4 | 5
  280. // |CTRLR |CTRLR |CTLR |CTLR |CTLR |CTLR
  281. // |state |state 2,|state2, |state2, |state 3, |state 3
  282. // | 0/1 |user not|user |user |user |user
  283. // verb/event | |attached|pending |attached |attached |pending
  284. // | |......|........|........|..........|.........|.........
  285. // V | | | | | |
  286. // _get_buffer | X | X | X | - | ** | X
  287. // _free_buffer | X | X | X | - | - | -
  288. // _realloc_bfr | X | X | X | - | - | -
  289. // _attach_user | X | ->2 | X | X | X | X
  290. // _detach_user | X | X | X | ->1 | ->0 | X
  291. // _channel_join | X | X | X | - | X | X
  292. // _channel_leave | X | X | X | - | - | X
  293. // _send_data | X | X | X | - | X | X
  294. // | | | | | |
  295. // _STOP_CONTRLR* | | ->0 | ->5 | ->4 | |
  296. // | | | | | |
  297. // _ATTACH_CNF OK | | | ->3 | | | ->4
  298. // _ATTACH_CNF FAIL| | | ->1 | | | ->0
  299. // _DETACH_IND-SELF| | | ->1 | ->1 | ->0 |
  300. // _DETACH_IND-othr| | | | - | - |
  301. // _JOIN_CONFIRM | | | | - | - |
  302. // _LEAVE_INDICAT | | | | - | - |
  303. // _SEND_INDICAT | | | | - | - |
  304. // =======================================================================
  305. //
  306. // NOTES ** when the controller is STOPPING the NET_GetBuffer
  307. // verb is valid but always returns a NULL buffer (no memory)
  308. //
  309. // * the STOP_CONTROLLER event is internally generated, and is
  310. // not seen across the API. It is generated when the controller
  311. // issues the NET_StopController verb and causes the state change
  312. // (to state 0, 4 or 5) such that the NET_AttachUser,
  313. // ChannelJoin and NET_SendData verbs are rejected.
  314. //
  315. //
  316. //
  317. //
  318. // Priorities
  319. //
  320. #define NET_INVALID_PRIORITY ((NET_PRIORITY)-1)
  321. enum
  322. {
  323. NET_TOP_PRIORITY = 0,
  324. NET_HIGH_PRIORITY,
  325. NET_MEDIUM_PRIORITY,
  326. NET_LOW_PRIORITY,
  327. NET_NUM_PRIORITIES
  328. };
  329. //
  330. // SFR6025: This flag is or-ed with the priority bit to indicate to the MCS
  331. // glue that it should send data on all channels.
  332. //
  333. //
  334. // FOR OBMAN ONLY -- REMOVE IN NM 4.0
  335. //
  336. #define NET_SEND_ALL_PRIORITIES 0x8000
  337. #define NET_ALL_REMOTES ((NET_UID)1)
  338. #define NET_INVALID_DOMAIN_ID (0xFFFFFFFF)
  339. #define NET_UNUSED_IDMCS 1
  340. typedef TSHR_UINT16 NET_UID; // MCS user IDs
  341. typedef TSHR_UINT16 NET_CHANNEL_ID; // MCS channel IDs
  342. typedef TSHR_UINT16 NET_TOKEN_ID; // MCS token IDs
  343. typedef TSHR_UINT16 NET_PRIORITY; // MCS priorities
  344. //
  345. // Forward decls of MGC structures
  346. //
  347. typedef struct tagMG_BUFFER * PMG_BUFFER;
  348. typedef struct tagMG_CLIENT * PMG_CLIENT;
  349. //
  350. // Flow control structure - This contains the target latency (in mS) and
  351. // stream size (in bytes) for each User Attachment
  352. // lonchanc: used by S20, MG, and OM.
  353. //
  354. typedef struct tag_NET_FLOW_CONTROL
  355. {
  356. UINT latency[NET_NUM_PRIORITIES];
  357. UINT streamSize[NET_NUM_PRIORITIES];
  358. }
  359. NET_FLOW_CONTROL, * PNET_FLOW_CONTROL;
  360. //
  361. // NET_EV_JOIN_CONFIRM and NET_EV_JOIN_CONFIRM_BY_KEY
  362. // join_channel confirm:
  363. // lonchanc: used by S20, MG, and OM.
  364. //
  365. typedef struct tagNET_JOIN_CNF_EVENT
  366. {
  367. UINT_PTR callID;
  368. NET_RESULT result; // NET_RESULT_USER_ACCEPTED/REJECTED
  369. TSHR_UINT16 pad1;
  370. NET_CHANNEL_ID correlator;
  371. NET_CHANNEL_ID channel;
  372. }
  373. NET_JOIN_CNF_EVENT;
  374. typedef NET_JOIN_CNF_EVENT * PNET_JOIN_CNF_EVENT;
  375. //
  376. // NET_EV_SEND_INDICATION
  377. // send data indication: see MG_SendData()
  378. // Despite its name, this event indicates that data has been RECEIVED!
  379. // lonchanc: used by MG and S20
  380. //
  381. typedef struct tag_NET_SEND_IND_EVENT
  382. {
  383. UINT_PTR callID;
  384. NET_PRIORITY priority;
  385. NET_CHANNEL_ID channel;
  386. UINT lengthOfData;
  387. LPBYTE data_ptr; // Pointer to the real data.
  388. }
  389. NET_SEND_IND_EVENT;
  390. typedef NET_SEND_IND_EVENT * PNET_SEND_IND_EVENT;
  391. //
  392. // MGC, FLOW CONTROL
  393. //
  394. //
  395. // MG tasks
  396. //
  397. #define MGTASK_FIRST 0
  398. typedef enum
  399. {
  400. MGTASK_OM = MGTASK_FIRST,
  401. MGTASK_DCS,
  402. MGTASK_MAX
  403. }
  404. MGTASK;
  405. //
  406. // Buffer types
  407. //
  408. enum
  409. {
  410. MG_TX_BUFFER = 1,
  411. MG_RX_BUFFER,
  412. MG_EV_BUFFER,
  413. MG_TX_PING,
  414. MG_TX_PONG,
  415. MG_TX_PANG,
  416. MG_RQ_CHANNEL_JOIN,
  417. MG_RQ_CHANNEL_JOIN_BY_KEY,
  418. MG_RQ_CHANNEL_LEAVE,
  419. MG_RQ_TOKEN_GRAB,
  420. MG_RQ_TOKEN_INHIBIT,
  421. MG_RQ_TOKEN_RELEASE
  422. };
  423. //
  424. // Period of watchdog timer to detect lost connections
  425. //
  426. #define MG_TIMER_PERIOD 1000
  427. //
  428. // MG priorities:
  429. //
  430. #define MG_HIGH_PRIORITY NET_HIGH_PRIORITY
  431. #define MG_MEDIUM_PRIORITY NET_MEDIUM_PRIORITY
  432. #define MG_LOW_PRIORITY NET_LOW_PRIORITY
  433. #define MG_PRIORITY_HIGHEST MG_HIGH_PRIORITY
  434. #define MG_PRIORITY_LOWEST MG_LOW_PRIORITY
  435. #define MG_NUM_PRIORITIES (MG_PRIORITY_LOWEST - MG_PRIORITY_HIGHEST + 1)
  436. //
  437. // MCS priority validation.
  438. // Priorities are contiguous numbers in the range NET_PRIORITY_HIGHEST..
  439. // NETPRIORITY_LOWEST. Priorities supplied to MG may also have the
  440. // NET_SEND_ALL_PRIORITIES flag set. So, to validate a priority:
  441. // - knock off the NET_SEND_ALL_PRIORITIES flag to give the raw priority
  442. // - set the valid raw prioririty to
  443. // NET_PRIORITY_HIGHEST if the raw priority is less than ...ITY_HIGHEST
  444. // NET_PRIORITY_LOWEST if the raw priority is more than ...ITY_LOWEST
  445. // the raw priority if it is in the valid range
  446. // - add the original ...ALL_PRIORITIES flag to the valid raw priority
  447. //
  448. #define MG_VALID_PRIORITY(p) \
  449. ((((p)&~NET_SEND_ALL_PRIORITIES)<MG_HIGH_PRIORITY)? \
  450. (MG_HIGH_PRIORITY|((p)&NET_SEND_ALL_PRIORITIES)): \
  451. (((p)&~NET_SEND_ALL_PRIORITIES)>MG_LOW_PRIORITY)? \
  452. (MG_LOW_PRIORITY|((p)&NET_SEND_ALL_PRIORITIES)): \
  453. (p))
  454. //
  455. //
  456. // The initial stream size setting may appear high, but it is set so that
  457. // in a LAN scenario we do not require the app to place a lot of forward
  458. // pressure on the pipe before it opens up. In a non-LAN scenario we may
  459. // not do enough spoiling to start with, but in actual fact DCS tends
  460. // to send less data than this limit anyway, so we should reduce it
  461. // quite quickly without flooding the buffers.
  462. //
  463. #define FLO_INIT_STREAMSIZE 8000
  464. #define FLO_MIN_STREAMSIZE 500
  465. #define FLO_MAX_STREAMSIZE 256000
  466. #define FLO_MIN_PINGTIME 100
  467. #define FLO_INIT_PINGTIME 1000
  468. //
  469. // This is the max number of bytes that can be allocated per stream if a
  470. // pong has not been received (i.e. FC is not operational).
  471. //
  472. #define FLO_MAX_PRE_FC_ALLOC 16000
  473. //
  474. // This is the max number of pkts outstanding before we apply back
  475. // pressure:
  476. //
  477. #define FLO_MAX_RCV_PACKETS 5
  478. //
  479. // This is the max number of pkts outstanding before we get worried about
  480. // creep:
  481. //
  482. #define FLO_MAX_RCV_PKTS_CREEP 250
  483. //
  484. // The maximum number of flow controlled streams.
  485. //
  486. #define FLO_MAX_STREAMS 128
  487. #define FLO_NOT_CONTROLLED FLO_MAX_STREAMS
  488. //
  489. // STRUCTURE : FLO_STREAM_DATA
  490. //
  491. // DESCRIPTION:
  492. //
  493. // This structure holds all the static data for a flow control stream
  494. //
  495. // FIELDS:
  496. //
  497. // channel
  498. // priority
  499. // pingValue - Next ping value to be sent on the pipe
  500. // eventNeeded - We need to wake up the app because we have rejected
  501. // a buffer allocation request
  502. // backlog - the allowable backlog in mS bejond which we apply
  503. // back pressure
  504. // pingNeeded - Send a ping at the next opportunity
  505. // pingTime - Minimum time, in mS, between each ping
  506. // gotPong - Indicates we have received a pong from some remote
  507. // party and so flow control can commence
  508. // lastPingTime - Time for last ping, in timer ticks
  509. // nextPingTime - Time for next ping, in timer ticks
  510. // lastDenialTime - Previous time (in ticks) that we started denying
  511. // buffer requests
  512. // curDenialTime - Time in ticks that we most recently started denying
  513. // buffer requests
  514. // DC_ABSMaxBytesInPipe
  515. // - Absolute maximum buffer allocation for this stream
  516. // maxBytesInPipe - Current buffer allocation limit
  517. // bytesInPipe - Current amount of data outstanding on this stream.
  518. // This includes data currently waiting to be sent.
  519. // users - Base for queue of User correlators
  520. // bytesAllocated - The current amount of data in the glue for this
  521. // stream which has not been sent. This is different
  522. // to bytesInPipe which is the amount of unacknowledged
  523. // data in this stream.
  524. //
  525. //
  526. typedef struct tagFLO_STREAM_DATA
  527. {
  528. STRUCTURE_STAMP
  529. NET_CHANNEL_ID channel;
  530. WORD gotPong:1;
  531. WORD eventNeeded:1;
  532. WORD pingNeeded:1;
  533. UINT priority;
  534. UINT pingValue;
  535. UINT backlog;
  536. UINT pingTime;
  537. UINT lastPingTime;
  538. UINT nextPingTime;
  539. UINT lastDenialTime;
  540. UINT curDenialTime;
  541. UINT DC_ABSMaxBytesInPipe;
  542. UINT maxBytesInPipe;
  543. UINT bytesInPipe;
  544. UINT bytesAllocated;
  545. BASEDLIST users;
  546. }
  547. FLO_STREAM_DATA;
  548. typedef FLO_STREAM_DATA * PFLO_STREAM_DATA;
  549. void __inline ValidateFLOStr(PFLO_STREAM_DATA pStr)
  550. {
  551. if (pStr != NULL)
  552. {
  553. ASSERT(!IsBadWritePtr(pStr, sizeof(FLO_STREAM_DATA)));
  554. }
  555. }
  556. //
  557. // The FLO callback function
  558. //
  559. // A wakeup type callback indicates that a back pressure situation has
  560. // been relieved.
  561. //
  562. // A buffermod callback indicates this as well, but also indicates that
  563. // the buffer size for controlling flow on the designated channel/priority
  564. // has changed.
  565. //
  566. #define FLO_WAKEUP 1
  567. #define FLO_BUFFERMOD 2
  568. typedef void (* PFLOCALLBACK)(PMG_CLIENT pmgClient,
  569. UINT callbackType,
  570. UINT priority,
  571. UINT newBufferSize);
  572. //
  573. // STRUCTURE : FLO_STATIC_DATA
  574. //
  575. // DESCRIPTION:
  576. //
  577. // This structure holds all the instance specific static data for the
  578. // Flow Control DLL
  579. //
  580. // FIELDS:
  581. //
  582. // numStreams - ID of the highest allocated stream
  583. // rsvd - reserved
  584. // callback - pointer to a callback function
  585. // pStrData - an array of FLO_STREAM_DATA pointers.
  586. //
  587. //
  588. typedef struct FLO_STATIC_DATA
  589. {
  590. UINT numStreams;
  591. PFLOCALLBACK callBack;
  592. PFLO_STREAM_DATA pStrData[FLO_MAX_STREAMS];
  593. }
  594. FLO_STATIC_DATA;
  595. typedef FLO_STATIC_DATA * PFLO_STATIC_DATA;
  596. typedef struct FLO_USER
  597. {
  598. BASEDLIST list;
  599. STRUCTURE_STAMP
  600. WORD userID;
  601. WORD lastPongRcvd;
  602. WORD pongNeeded;
  603. BYTE sendPongID;
  604. BYTE pad1;
  605. UINT sentPongTime; // Time we actually sent the pong
  606. WORD rxPackets; // Count of packets outstanding
  607. WORD gotPong; // Indicates this user has ponged
  608. // and they are permitted to apply
  609. // back pressure to our sends
  610. UINT numPongs; // total number of pongs from user
  611. UINT pongDelay; // total latency across pongs
  612. }
  613. FLO_USER;
  614. typedef FLO_USER * PFLO_USER;
  615. void __inline ValidateFLOUser(PFLO_USER pFloUser)
  616. {
  617. ASSERT(!IsBadWritePtr(pFloUser, sizeof(FLO_USER)));
  618. }
  619. //
  620. // Maximum wait time before assuming a user is offline
  621. // We need to keep this high until the apps become "well behaved" and
  622. // respond to the flow control buffer size recommendations.
  623. //
  624. #define FLO_MAX_WAIT_TIME 20000
  625. //
  626. //
  627. // Client Control Block
  628. //
  629. //
  630. typedef struct tagMG_CLIENT
  631. {
  632. PUT_CLIENT putTask;
  633. PCM_CLIENT pcmClient;
  634. BASEDLIST buffers; // list of children buffers
  635. BASEDLIST pendChain; // Chain of pending request from client
  636. BASEDLIST joinChain; // Chain of pending join-by-key requests
  637. //
  638. // MCS user attachment info
  639. //
  640. PIMCSSap m_piMCSSap; // user interface ptr returned by MCS
  641. UserID userIDMCS; // user ID returned by MCS
  642. FLO_STATIC_DATA flo; // flow control structure
  643. WORD eventProcReg:1;
  644. WORD lowEventProcReg:1;
  645. WORD exitProcReg:1;
  646. WORD joinPending:1; // Is there a channel join outstanding ?
  647. WORD userAttached:1;
  648. WORD joinNextCorr;
  649. NET_FLOW_CONTROL flowControl; // flow control latency/backlog params
  650. }
  651. MG_CLIENT;
  652. void __inline ValidateMGClient(PMG_CLIENT pmgc)
  653. {
  654. ASSERT(!IsBadWritePtr(pmgc, sizeof(MG_CLIENT)));
  655. ValidateUTClient(pmgc->putTask);
  656. }
  657. typedef struct tagMG_INT_PKT_HEADER
  658. {
  659. TSHR_UINT16 useCount; // The use count of this packet. This
  660. // is required for sending the same
  661. // data on multiple channels.
  662. TSHR_NET_PKT_HEADER header;
  663. }
  664. MG_INT_PKT_HEADER;
  665. typedef MG_INT_PKT_HEADER * PMG_INT_PKT_HEADER;
  666. //
  667. //
  668. // Buffer Control Block
  669. //
  670. //
  671. typedef struct tagMG_BUFFER
  672. {
  673. STRUCTURE_STAMP
  674. UINT type;
  675. BASEDLIST pendChain; // Used when the buffer is added to the
  676. BASEDLIST clientChain;
  677. PMG_INT_PKT_HEADER pPktHeader; // Pointer to MCS control info
  678. void * pDataBuffer; // Pointer passed to apps
  679. UINT length; // length of the associated packet
  680. ChannelID channelId; // Send destination, or token grab req
  681. ChannelID channelKey;
  682. UserID senderId;
  683. NET_PRIORITY priority;
  684. BOOL eventPosted;
  685. UINT work; // work field for misc use
  686. PFLO_STREAM_DATA pStr; // Pointer to the FC stream
  687. }
  688. MG_BUFFER;
  689. void __inline ValidateMGBuffer(PMG_BUFFER pmgb)
  690. {
  691. ASSERT(!IsBadWritePtr(pmgb, sizeof(MG_BUFFER)));
  692. }
  693. //
  694. //
  695. //
  696. // MACROS
  697. //
  698. //
  699. //
  700. //
  701. // MCS priority validation.
  702. // Priorities are contiguous numbers in the range NET_PRIORITY_HIGHEST..
  703. // NET_PRIORITY_LOWEST. Priorities supplied to MG may also have the
  704. // NET_SEND_ALL_PRIORITIES flag set. So, to validate a priority:
  705. // - knock off the NET_SEND_ALL_PRIORITIES flag to give the raw priority
  706. // - set the valid raw priority to
  707. // - NET_PRIORITY_HIGHEST if the raw priority is less than ...ITY_HIGHEST
  708. // - NET_PRIORITY_LOWEST if the raw priority is more than ...ITY_LOWEST
  709. // - the raw priority if it is in the valid range
  710. // - add the original ...ALL_PRIORITIES flag to the valid raw priority.
  711. //
  712. //
  713. //
  714. //
  715. // FUNCTION PROTOTYPES
  716. //
  717. //
  718. //
  719. //
  720. //
  721. // MGLongStopHandler(...)
  722. //
  723. // This function is registered as a low priority event handler for each
  724. // client. It catches any unprocessed network events and frees any
  725. // associated memory.
  726. //
  727. //
  728. BOOL CALLBACK MGLongStopHandler(LPVOID pmgClient, UINT event, UINT_PTR param1, UINT_PTR param2);
  729. //
  730. //
  731. // MGEventHandler(...)
  732. //
  733. // This function is registered as a high priority event handler for the
  734. // processing of MG_ChannelJoinByKey, MCS request handling and scheduling.
  735. // It catches NET channel join confirm and CMS register channel confirm
  736. // events, and massages them into the correct return events for the app.
  737. // It queues requests coming from the app context into the glue context
  738. // and schedules queued requests.
  739. //
  740. //
  741. BOOL CALLBACK MGEventHandler(LPVOID pmgClient, UINT event, UINT_PTR param1, UINT_PTR param2);
  742. //
  743. UINT MGHandleSendInd(PMG_CLIENT pmgClient, PSendData pSendInfo);
  744. //
  745. //
  746. // MGNewBuffer(...)
  747. // NewTxBuffer(...)
  748. // NewRxBuffer(...)
  749. // FreeBuffer(...)
  750. //
  751. // The New function allocates and initialises a buffer , allocates buffer
  752. // memory of the specified size and type and adds the to the client's
  753. // list of buffer s.
  754. //
  755. // The Tx version performs flow control on the buffer allocation request
  756. // The Rx version just allocates a receive buffer
  757. //
  758. // The Free function discards a buffer , discards the associated buffer
  759. // memory, decrements the client's count of memory in use and removes the
  760. // from the client's list of buffer s.
  761. //
  762. //
  763. void MGNewCorrelator(PMG_CLIENT ppmgClient, WORD * pCorrelator);
  764. UINT MGNewBuffer(PMG_CLIENT pmgClient, UINT typeOfBuffer,
  765. PMG_BUFFER * ppBuffer);
  766. UINT MGNewDataBuffer(PMG_CLIENT pmgClient,
  767. UINT typeOfBuffer,
  768. UINT sizeOfBuffer,
  769. PMG_BUFFER * ppBuffer);
  770. UINT MGNewTxBuffer(PMG_CLIENT pmgClient,
  771. NET_PRIORITY priority,
  772. NET_CHANNEL_ID channel,
  773. UINT sizeOfBuffer,
  774. PMG_BUFFER * ppBuffer);
  775. UINT MGNewRxBuffer(PMG_CLIENT pmgClient,
  776. NET_PRIORITY priority,
  777. NET_CHANNEL_ID channel,
  778. NET_CHANNEL_ID senderID,
  779. PMG_BUFFER * ppBuffer);
  780. void MGFreeBuffer(PMG_CLIENT pmgClient, PMG_BUFFER * ppBuffer);
  781. //
  782. //
  783. // MGProcessDomainWatchdog(...)
  784. //
  785. // Handle domain watchdog timer ticks.
  786. //
  787. //
  788. void MGProcessDomainWatchdog(PMG_CLIENT pmgClient);
  789. void MGProcessEndFlow(PMG_CLIENT pmgClient, ChannelID channel);
  790. UINT MGPostJoinConfirm(PMG_CLIENT pmgClient,
  791. NET_RESULT result,
  792. NET_CHANNEL_ID channel,
  793. NET_CHANNEL_ID correlator);
  794. NET_RESULT TranslateResult(WORD Result);
  795. //
  796. //
  797. // MGFLOCallBack(...)
  798. //
  799. // Callback poked by flow control to trigger the app to retry buffer
  800. // requests thet were previously rejected
  801. //
  802. //
  803. void MGFLOCallBack(PMG_CLIENT pmgClient,
  804. UINT callbackType,
  805. UINT priority,
  806. UINT newBufferSize);
  807. //
  808. //
  809. // MGProcessPendingQueue(...)
  810. //
  811. // Called whenever MG wants to try and execute pending requests. Requests
  812. // are queued because they may fail for a transient reason, such as MCS
  813. // buffer shortage.
  814. //
  815. //
  816. UINT MGProcessPendingQueue(PMG_CLIENT pmgClient);
  817. BOOL MG_Register(MGTASK task, PMG_CLIENT * pmgClient, PUT_CLIENT putTask);
  818. void MG_Deregister(PMG_CLIENT * ppmgClient);
  819. void CALLBACK MGExitProc(LPVOID uData);
  820. UINT MG_Attach(PMG_CLIENT pmgClient, UINT_PTR callID, PNET_FLOW_CONTROL pFlowControl);
  821. void MG_Detach(PMG_CLIENT pmgClient);
  822. void MGDetach(PMG_CLIENT pmgClient);
  823. UINT MG_ChannelJoin(PMG_CLIENT pmgClient, NET_CHANNEL_ID * pCorrelator,
  824. NET_CHANNEL_ID channel);
  825. UINT MG_ChannelJoinByKey(PMG_CLIENT pmgClient,
  826. NET_CHANNEL_ID * pCorrelator,
  827. WORD channelKey);
  828. void MG_ChannelLeave(PMG_CLIENT pmgClient, NET_CHANNEL_ID channel);
  829. UINT MG_GetBuffer(PMG_CLIENT pmgClient, UINT length,
  830. NET_PRIORITY priority,
  831. NET_CHANNEL_ID channel,
  832. void ** buffer);
  833. void MG_FreeBuffer(PMG_CLIENT pmgClient,
  834. void ** buffer);
  835. UINT MG_SendData(PMG_CLIENT pmgClient,
  836. NET_PRIORITY priority,
  837. NET_CHANNEL_ID channel,
  838. UINT length,
  839. void ** data);
  840. UINT MG_TokenGrab(PMG_CLIENT pmgClient, NET_TOKEN_ID token);
  841. UINT MG_TokenInhibit(PMG_CLIENT pmgClient, NET_TOKEN_ID token);
  842. void MG_FlowControlStart(PMG_CLIENT pmgClient,
  843. NET_CHANNEL_ID channel,
  844. NET_PRIORITY priority,
  845. UINT backlog,
  846. UINT maxBytesOutstanding);
  847. //
  848. // API FUNCTION: FLO_UserTerm
  849. //
  850. // DESCRIPTION:
  851. //
  852. // Called by an application to end flow control on all the channels
  853. // associated with a particular user.
  854. //
  855. // PARAMETERS:
  856. //
  857. // pUser - MCS Glue User attachment
  858. //
  859. // RETURNS: Nothing.
  860. //
  861. //
  862. void FLO_UserTerm(PMG_CLIENT pmgClient);
  863. //
  864. // API FUNCTION: FLO_StartControl
  865. //
  866. // DESCRIPTION:
  867. //
  868. // The application calls this function whenever it wants a data stream to
  869. // be flow controlled
  870. //
  871. // PARAMETERS:
  872. //
  873. // pUser - MCS Glue User attachment
  874. // channel - channel id of channel to be flow controlled
  875. // priority - priority of the stream to be controlled
  876. // backlog - the maximum backlog (in mS) allowed for this stream
  877. // maxBytesOutstanding - the maximum number of bytes allowed in the stream
  878. // irrespective of the backlog. 0 = use default of
  879. // 64 KBytes
  880. //
  881. // RETURNS:
  882. // None
  883. //
  884. //
  885. void FLO_StartControl(PMG_CLIENT pmgClient,
  886. NET_CHANNEL_ID channel,
  887. UINT priority,
  888. UINT backlog,
  889. UINT maxBytesOutstanding);
  890. void FLO_EndControl
  891. (
  892. PMG_CLIENT pmgClient,
  893. NET_CHANNEL_ID channel,
  894. UINT priority
  895. );
  896. //
  897. // API FUNCTION: FLO_AllocSend
  898. //
  899. // DESCRIPTION:
  900. //
  901. // The application is requesting a buffer in order to send a packet. This
  902. // may trigger a flow control packet in advance of the application packet.
  903. // Flow control may choose to reject the packet with NET_OUT_OF_RESOURCE in
  904. // which case the application must reschedule the allocation at a ater
  905. // date. To assist the rescheduling, if ever a send is rejected then flow
  906. // control will call the application callback to trigger the reschedule.
  907. //
  908. // PARAMETERS:
  909. //
  910. // pUser - MCS Glue User attachment
  911. // priority - The priority for this buffer
  912. // channel - The channnel on which to send the packet
  913. // size - The size of the packet
  914. // ppStr - Pointer to the pointer to the FC stream. This is a
  915. // return value.
  916. //
  917. //
  918. UINT FLO_AllocSend(PMG_CLIENT pmgClient,
  919. UINT priority,
  920. NET_CHANNEL_ID channel,
  921. UINT size,
  922. PFLO_STREAM_DATA * ppStr);
  923. //
  924. // API FUNCTION: FLO_ReallocSend
  925. //
  926. // DESCRIPTION:
  927. //
  928. // The application has requested that the glue send a packet, but the
  929. // packet contains less data than originally requested.
  930. // Flow control heuristics get thrown out unless we logically free the
  931. // unused portion of the packet for reuse for other allocations.
  932. // If we didn't do this then we might see a 8K packet, for example,
  933. // complete in 1 second because the app only put 1K of data in it.
  934. //
  935. // PARAMETERS:
  936. //
  937. // pUser - MCS Glue User attachment
  938. // pStr - The flow control stream to be corrected
  939. // size - The size of the packet that has been unused
  940. //
  941. // RETURNS:
  942. //
  943. // None
  944. //
  945. //
  946. void FLO_ReallocSend(PMG_CLIENT pmgClient,
  947. PFLO_STREAM_DATA pStr,
  948. UINT size);
  949. //
  950. // API FUNCTION: FLO_DecrementAlloc
  951. //
  952. // DESCRIPTION:
  953. //
  954. // This function decrements the bytesAllocated count for a given stream.
  955. // It is called whenever a packet is sent or removed from the send chain.
  956. //
  957. // PARAMETERS:
  958. //
  959. // pStr - The flow control stream to be decremented
  960. // size - The size to decrement
  961. //
  962. // RETURNS:
  963. //
  964. // None
  965. //
  966. //
  967. void FLO_DecrementAlloc( PFLO_STREAM_DATA pStr,
  968. UINT size);
  969. //
  970. // API FUNCTION: FLO_ReceivedPacket
  971. //
  972. // DESCRIPTION:
  973. //
  974. // Upon receipt of a flow control packet the MCS glue calls this function
  975. // and then ignores the packet.
  976. //
  977. // PARAMETERS:
  978. //
  979. // pUser - MCS Glue User attachment
  980. // pPkt - pointer to the packet, for FLO to process
  981. //
  982. // RETURNS:
  983. //
  984. // None
  985. //
  986. //
  987. void FLO_ReceivedPacket(PMG_CLIENT pmgClient, PTSHR_FLO_CONTROL pPkt);
  988. //
  989. // API FUNCTION: FLO_AllocReceive
  990. //
  991. // DESCRIPTION:
  992. //
  993. // Called to indicate that a receive buffer is now in use by the application
  994. //
  995. // PARAMETERS:
  996. //
  997. // pmg - pointer to the glue user attacgment cb
  998. // priority
  999. // channel
  1000. // size - size of the buffer just been allocated
  1001. //
  1002. // RETURNS:
  1003. //
  1004. // None
  1005. //
  1006. //
  1007. void FLO_AllocReceive(PMG_CLIENT pmgClient,
  1008. UINT priority,
  1009. NET_CHANNEL_ID channel,
  1010. UINT senderID);
  1011. //
  1012. // API FUNCTION: FLO_FreeReceive
  1013. //
  1014. // DESCRIPTION:
  1015. //
  1016. // Called to indicate that a receive buffer has ben handed back by the
  1017. // application.
  1018. //
  1019. // PARAMETERS:
  1020. //
  1021. // pmg - pointer to the glue user attachment cb
  1022. // priority
  1023. // channel
  1024. // size - size of the buffer just been freed
  1025. //
  1026. // RETURNS:
  1027. //
  1028. // None
  1029. //
  1030. //
  1031. void FLO_FreeReceive(PMG_CLIENT pmgClient,
  1032. NET_PRIORITY priority,
  1033. NET_CHANNEL_ID channel,
  1034. UINT senderID);
  1035. //
  1036. // API FUNCTION: FLO_CheckUsers
  1037. //
  1038. // DESCRIPTION:
  1039. //
  1040. // Called periodically by each client to allow flow control to determine if
  1041. // remote users have left the channel
  1042. //
  1043. // PARAMETERS:
  1044. //
  1045. // pmg - pointer to the user
  1046. //
  1047. // RETURNS:
  1048. //
  1049. // None
  1050. //
  1051. //
  1052. void FLO_CheckUsers(PMG_CLIENT pmgClient);
  1053. //
  1054. // FLOGetStream()
  1055. //
  1056. UINT FLOGetStream(PMG_CLIENT pmgClient, NET_CHANNEL_ID channel, UINT priority,
  1057. PFLO_STREAM_DATA * ppStr);
  1058. void FLOStreamEndControl(PMG_CLIENT pmgClient, UINT stream);
  1059. void FLOPing(PMG_CLIENT pmgClient, UINT stream, UINT curtime);
  1060. void FLOPang(PMG_CLIENT pmgClient, UINT stream, UINT userID);
  1061. void FLOPong(PMG_CLIENT pmgClient, UINT stream, UINT userID, UINT pongID);
  1062. //
  1063. // API FUNCTION: FLOAddUser
  1064. //
  1065. // DESCRIPTION:
  1066. //
  1067. // Add a user to a flow controlled stream
  1068. //
  1069. // PARAMETERS:
  1070. //
  1071. // userID - ID of the new user (single member channel ID)
  1072. // pStr - pointer to the stream to receive the new user
  1073. //
  1074. // RETURNS:
  1075. //
  1076. // None
  1077. //
  1078. //
  1079. PFLO_USER FLOAddUser(UINT userID,
  1080. PFLO_STREAM_DATA pStr);
  1081. //
  1082. // API FUNCTION: FLO_RemoveUser
  1083. //
  1084. // DESCRIPTION:
  1085. //
  1086. // Remove a user from a flow controlled stream
  1087. //
  1088. // PARAMETERS:
  1089. //
  1090. // pmg - pointer to the MCS glue user
  1091. // userID - ID of the bad user (single member channel ID)
  1092. //
  1093. // RETURNS:
  1094. //
  1095. // None
  1096. //
  1097. //
  1098. void FLO_RemoveUser(PMG_CLIENT pmgClient, UINT userID);
  1099. //
  1100. // FUNCTION: MGCallback
  1101. //
  1102. // DESCRIPTION:
  1103. //
  1104. // This function is the callback passed to MCS. The glue layer receives
  1105. // all communication from MCS via this function. It converts MCS messages
  1106. // into DC-Groupware events and posts them to the relevant client(s).
  1107. //
  1108. //
  1109. void CALLBACK MGCallback( unsigned int mcsMessageType,
  1110. UINT_PTR eventData,
  1111. UINT_PTR pUser );
  1112. #endif // _H_AST120
  1113.