Source code of Windows XP (NT5)
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.

2860 lines
76 KiB

  1. /****************************************************************************
  2. *
  3. * $Archive: S:\sturgeon\src\callcont\vcs\gkiman.c_v $
  4. *
  5. * INTEL Corporation Prorietary Information
  6. *
  7. * This listing is supplied under the terms of a license agreement
  8. * with INTEL Corporation and may not be copied nor disclosed except
  9. * in accordance with the terms of that agreement.
  10. *
  11. * Copyright (c) 1996 Intel Corporation.
  12. *
  13. * $Revision: 1.77.1.6 $
  14. * $Date: 21 Aug 1997 16:56:32 $
  15. * $Author: Helgebal $
  16. *
  17. * Deliverable:
  18. *
  19. * Abstract:
  20. *
  21. * Notes:
  22. *
  23. * Much effort has gone into working around the following constraints of
  24. * the GKI interface:
  25. * 1) Only one admission request can be pending at a time. This is because
  26. * the hCall is unknown until it completes.
  27. * 2) Only one bandwidth request per call can be pending at a time.
  28. * 3) Any pending bandwidth request must complete before issuing a
  29. * disengage request.
  30. * 4) Any calls must be disengaged before issuing a deregistration request.
  31. *
  32. ***************************************************************************/
  33. #ifdef GATEKEEPER
  34. #pragma warning ( disable : 4115 4201 4214 4514)
  35. #include <nt.h>
  36. #include <ntrtl.h>
  37. #include <nturtl.h>
  38. #include <windows.h>
  39. #include "incommon.h"
  40. #include "ccerror.h"
  41. #include "isrg.h"
  42. #include "gkiexp.h"
  43. #include "callman2.h"
  44. #ifdef FORCE_SERIALIZE_CALL_CONTROL
  45. #include "cclock.h"
  46. #endif // FORCE_SERIALIZE_CALL_CONTROL
  47. #pragma warning ( default : 4115 4201 4214)
  48. #if defined(DBG)
  49. void GKDbgPrint(DWORD dwLevel,
  50. #ifdef UNICODE_TRACE
  51. LPTSTR pszFormat,
  52. #else
  53. LPSTR pszFormat,
  54. #endif
  55. ...);
  56. #define GKDBG(_x_) GKDbgPrint _x_
  57. #else
  58. #define GKDBG(_x_)
  59. #endif
  60. extern HINSTANCE ghCallControlInstance;
  61. #define Malloc(size) GlobalAlloc(GMEM_FIXED, size)
  62. #define ReAlloc(p, size) GlobalReAlloc(p, GMEM_FIXED, size)
  63. #define Free(p) GlobalFree(p)
  64. #ifdef FORCE_SERIALIZE_CALL_CONTROL
  65. #define EnterCallControlTop() {CCLOCK_AcquireLock();}
  66. #define LeaveCallControlTop(f) {HRESULT stat; \
  67. stat = f; \
  68. CCLOCK_RelinquishLock(); \
  69. return stat;}
  70. #else
  71. #define EnterCallControlTop()
  72. #define LeaveCallControlTop(f) {HRESULT stat; \
  73. stat = f; \
  74. return stat;}
  75. #endif
  76. #define DEFAULT_LISTEN_HANDLE 0xFFFFFFFF
  77. #define GKIMAN_BASE WM_USER
  78. #define MIN_BANDWIDTH 1
  79. #define MAX_BANDWIDTH (0xFFFFFFFF / 100)
  80. #define GKI_ADMITTING_HANDLE ((HANDLE)-1)
  81. #define GKI_BYPASS_HANDLE ((HANDLE)-2)
  82. // GKI Manager state
  83. #define STATE_START 0
  84. #define STATE_CLASS_REGISTERED 1
  85. #define STATE_WINDOW_CREATED 2
  86. #define STATE_REGISTERING 3
  87. #define STATE_REGISTERING_REREG 4
  88. #define STATE_REGISTERING_UNREG 5
  89. #define STATE_REGISTERED 6
  90. #define STATE_ADMITTING 7
  91. #define STATE_ADMITTING_REREG 8
  92. #define STATE_ADMITTING_UNREG 9
  93. #define STATE_DISENGAGING 10
  94. #define STATE_DISENGAGING_REREG 11
  95. #define STATE_UNREGISTERING 12
  96. #define STATE_UNREGISTERING_REREG 13
  97. #define STATE_REG_BYPASS 14
  98. typedef HRESULT (*PGKI_RegistrationRequest)(long lVersion,
  99. SeqTransportAddr *pCallSignalAddr,
  100. EndpointType *pTerminalType,
  101. SeqAliasAddr *pAliasAddr,
  102. HWND hWnd,
  103. WORD wBaseMessage,
  104. unsigned short usRegistrationTransport /* = ipAddress_chosen */);
  105. typedef HRESULT (*PGKI_UnregistrationRequest)(void);
  106. typedef HRESULT (*PGKI_LocationRequest)(SeqAliasAddr *pLocationInfo);
  107. typedef HRESULT (*PGKI_AdmissionRequest)(unsigned short usCallTypeChoice,
  108. SeqAliasAddr *pDestinationInfo,
  109. TransportAddress *pDestCallSignalAddress,
  110. SeqAliasAddr *pDextExtraCallInfo,
  111. BandWidth bandWidth,
  112. ConferenceIdentifier *pConferenceID,
  113. BOOL activeMC,
  114. BOOL answerCall,
  115. unsigned short usCallTransport /* = ipAddress_chosen */);
  116. typedef HRESULT (*PGKI_BandwidthRequest)(HANDLE hModCall,
  117. unsigned short usCallTypeChoice,
  118. BandWidth bandWidth);
  119. typedef HRESULT (*PGKI_DisengageRequest)(HANDLE hCall);
  120. typedef HRESULT (*PGKI_CleanupRequest)(void);
  121. HRESULT Q931CopyAliasNames(PCC_ALIASNAMES *ppTarget, PCC_ALIASNAMES pSource);
  122. HRESULT Q931FreeAliasNames(PCC_ALIASNAMES pSource);
  123. #define CopyAliasNames Q931CopyAliasNames
  124. #define FreeAliasNames Q931FreeAliasNames
  125. typedef struct _LISTEN
  126. {
  127. struct _LISTEN * pNext;
  128. PCC_ALIASNAMES pAliasNames;
  129. DWORD hListen;
  130. DWORD dwAddr;
  131. WORD wPort;
  132. } LISTEN, *PLISTEN;
  133. //
  134. // GKI Manager Global Data
  135. //
  136. CRITICAL_SECTION GkiLock;
  137. const char szClassName[] = "GkiManWndClass";
  138. HWND hwndGki = 0;
  139. ATOM atomGki = 0;
  140. unsigned int uGkiState = STATE_START;
  141. PLISTEN pListenList = NULL;
  142. unsigned int uGkiCalls = 0;
  143. unsigned int uPendingDisengages = 0;
  144. HINSTANCE hGkiDll = 0;
  145. PGKI_RegistrationRequest pGKI_RegistrationRequest = NULL;
  146. PGKI_UnregistrationRequest pGKI_UnregistrationRequest = NULL;
  147. PGKI_LocationRequest pGKI_LocationRequest = NULL;
  148. PGKI_AdmissionRequest pGKI_AdmissionRequest = NULL;
  149. PGKI_BandwidthRequest pGKI_BandwidthRequest = NULL;
  150. PGKI_DisengageRequest pGKI_DisengageRequest = NULL;
  151. PGKI_CleanupRequest pGKI_CleanupRequest = NULL;
  152. HRESULT ValidateCall(DWORD hCall);
  153. HRESULT LastGkiError = CC_GKI_STATE;
  154. //
  155. // Forward declarations
  156. //
  157. LONG APIENTRY GkiWndProc(HWND hWnd, UINT message, UINT wParam, LONG lParam);
  158. //
  159. // Helper subroutines
  160. //
  161. #ifdef DBG
  162. typedef struct _GKIMAP
  163. {
  164. HRESULT hResult;
  165. char * pString;
  166. } GKIMAP;
  167. GKIMAP GkiErrorNames[] =
  168. {
  169. GKI_OK, "GKI_OK",
  170. GKI_EXIT_THREAD, "GKI_EXIT_THREAD",
  171. GKI_REDISCOVER, "GKI_REDISCOVER",
  172. GKI_DELETE_CALL, "GKI_DELETE_CALL",
  173. GKI_GCF_RCV, "GKI_GCF_RCV",
  174. GKI_NO_MEMORY, "GKI_NO_MEMORY",
  175. GKI_NO_THREAD, "GKI_NO_THREAD",
  176. GKI_HANDLE_ERROR, "GKI_HANDLE_ERROR",
  177. GKI_ALREADY_REG, "GKI_ALREADY_REG",
  178. GKI_VERSION_ERROR, "GKI_VERSION_ERROR",
  179. GKI_ENCODER_ERROR, "GKI_ENCODER_ERROR",
  180. GKI_NOT_REG, "GKI_NOT_REG",
  181. GKI_BUSY, "GKI_BUSY",
  182. GKI_NO_TA_ERROR, "GKI_NO_TA_ERROR",
  183. GKI_NO_RESPONSE, "GKI_NO_RESPONSE",
  184. GKI_DECODER_ERROR, "GKI_DECODER_ERROR",
  185. };
  186. char *StateNames[] =
  187. {
  188. "STATE_START",
  189. "STATE_CLASS_REGISTERED",
  190. "STATE_WINDOW_CREATED",
  191. "STATE_REGISTERING",
  192. "STATE_REGISTERING_REREG",
  193. "STATE_REGISTERING_UNREG",
  194. "STATE_REGISTERED",
  195. "STATE_ADMITTING",
  196. "STATE_ADMITTING_REREG",
  197. "STATE_ADMITTING_UNREG",
  198. "STATE_DISENGAGING",
  199. "STATE_DISENGAGING_REREG",
  200. "STATE_UNREGISTERING",
  201. "STATE_UNREGISTERING_REREG",
  202. "STATE_REG_BYPASS",
  203. };
  204. char *CallStateNames[] =
  205. {
  206. "GCS_START",
  207. "GCS_WAITING",
  208. "GCS_ADMITTING",
  209. "GCS_ADMITTING_CLOSE_PENDING",
  210. "GCS_ADMITTED",
  211. "GCS_CHANGING",
  212. "GCS_CHANGING_CLOSE_PENDING",
  213. "GCS_DISENGAGING",
  214. };
  215. char szBuffer[128];
  216. char * GkiErrorName(char *szFormat, HRESULT hResult)
  217. {
  218. register int nIndex = sizeof(GkiErrorNames) / sizeof(GkiErrorNames[0]);
  219. char szTemp[32];
  220. while (nIndex > 0)
  221. {
  222. if (GkiErrorNames[--nIndex].hResult == hResult)
  223. {
  224. wsprintf(szBuffer, szFormat, GkiErrorNames[nIndex].pString);
  225. return szBuffer;
  226. }
  227. }
  228. wsprintf(szTemp, "Unknown(0x%x)", hResult);
  229. wsprintf(szBuffer, szFormat, szTemp);
  230. return szBuffer;
  231. } // GkiErrorName()
  232. char * StateName(char *szFormat, unsigned uState)
  233. {
  234. char szTemp[32];
  235. if (uState < (sizeof(StateNames)/sizeof(StateNames[0])))
  236. {
  237. wsprintf(szBuffer, szFormat, StateNames[uState]);
  238. }
  239. else
  240. {
  241. wsprintf(szTemp, "Unknown(%d)", uState);
  242. wsprintf(szBuffer, szFormat, szTemp);
  243. }
  244. return szBuffer;
  245. } // StateName()
  246. char * CallStateName(char *szFormat, unsigned uCallState)
  247. {
  248. char szTemp[32];
  249. if (uCallState <= (sizeof(CallStateNames)/sizeof(CallStateNames[0])))
  250. {
  251. wsprintf(szBuffer, szFormat, CallStateNames[uCallState]);
  252. }
  253. else
  254. {
  255. wsprintf(szTemp, "Unknown(%d)", uCallState);
  256. wsprintf(szBuffer, szFormat, szTemp);
  257. }
  258. return szBuffer;
  259. } // CallStateName()
  260. #else
  261. #define GkiErrorName(x,y) ""
  262. #define StateName(x,y) ""
  263. #define CallStateName(x,y) ""
  264. #endif // DBG
  265. HRESULT MapRegistrationRejectReason(register UINT uReason)
  266. {
  267. register HRESULT lReason;
  268. // TBD - Map reason code into CC_xxx HRESULT
  269. switch (uReason)
  270. {
  271. case discoveryRequired_chosen:
  272. lReason = CC_GATEKEEPER_REFUSED;
  273. break;
  274. case RgstrtnRjctRsn_invldRvsn_chosen:
  275. lReason = CC_GATEKEEPER_REFUSED;
  276. break;
  277. case invalidCallSignalAddress_chosen:
  278. lReason = CC_GATEKEEPER_REFUSED;
  279. break;
  280. case invalidRASAddress_chosen:
  281. lReason = CC_GATEKEEPER_REFUSED;
  282. break;
  283. case duplicateAlias_chosen:
  284. lReason = CC_GATEKEEPER_REFUSED;
  285. break;
  286. case invalidTerminalType_chosen:
  287. lReason = CC_GATEKEEPER_REFUSED;
  288. break;
  289. case RgstrtnRjctRsn_undfndRsn_chosen:
  290. lReason = CC_GATEKEEPER_REFUSED;
  291. break;
  292. case transportNotSupported_chosen:
  293. lReason = CC_GATEKEEPER_REFUSED;
  294. break;
  295. default:
  296. lReason = CC_GATEKEEPER_REFUSED;
  297. } // switch
  298. return lReason;
  299. } // MapRegistrationRejectReason()
  300. HRESULT MapAdmissionRejectReason(register UINT uReason)
  301. {
  302. register HRESULT lReason;
  303. // TBD - Map reason code into CC_xxx HRESULT
  304. switch (uReason)
  305. {
  306. case calledPartyNotRegistered_chosen:
  307. lReason = CC_GATEKEEPER_REFUSED;
  308. break;
  309. case ARRn_invldPrmssn_chosen:
  310. lReason = CC_GATEKEEPER_REFUSED;
  311. break;
  312. case AdmssnRjctRsn_rqstDnd_chosen:
  313. lReason = CC_GATEKEEPER_REFUSED;
  314. break;
  315. case AdmssnRjctRsn_undfndRsn_chosen:
  316. lReason = CC_GATEKEEPER_REFUSED;
  317. break;
  318. case callerNotRegistered_chosen:
  319. lReason = CC_GATEKEEPER_REFUSED;
  320. break;
  321. case routeCallToGatekeeper_chosen:
  322. lReason = CC_GATEKEEPER_REFUSED;
  323. break;
  324. case invldEndpntIdntfr_chosen:
  325. lReason = CC_GATEKEEPER_REFUSED;
  326. break;
  327. case AdmssnRjctRsn_rsrcUnvlbl_chosen:
  328. lReason = CC_GATEKEEPER_REFUSED;
  329. break;
  330. default:
  331. lReason = CC_GATEKEEPER_REFUSED;
  332. } // switch
  333. return lReason;
  334. } // MapAdmissionRejectReason()
  335. HRESULT MapBandwidthRejectReason(register UINT uReason)
  336. {
  337. register HRESULT lReason;
  338. // TBD - Map reason code into CC_xxx HRESULT
  339. switch (uReason)
  340. {
  341. case notBound_chosen:
  342. lReason = CC_GATEKEEPER_REFUSED;
  343. break;
  344. case invalidConferenceID_chosen:
  345. lReason = CC_GATEKEEPER_REFUSED;
  346. break;
  347. case BndRjctRsn_invldPrmssn_chosen:
  348. lReason = CC_GATEKEEPER_REFUSED;
  349. break;
  350. case insufficientResources_chosen:
  351. lReason = CC_GATEKEEPER_REFUSED;
  352. break;
  353. case BndRjctRsn_invldRvsn_chosen:
  354. lReason = CC_GATEKEEPER_REFUSED;
  355. break;
  356. case BndRjctRsn_undfndRsn_chosen:
  357. lReason = CC_GATEKEEPER_REFUSED;
  358. break;
  359. default:
  360. lReason = CC_GATEKEEPER_REFUSED;
  361. } // switch
  362. return lReason;
  363. } // MapBandwidthRejectReason()
  364. /*
  365. * NOTES
  366. * GkiLock must be locked before calling this routine!
  367. */
  368. static PLISTEN ListenEnqueue(register PLISTEN pListen)
  369. {
  370. if (pListenList && pListenList->hListen == DEFAULT_LISTEN_HANDLE)
  371. {
  372. PLISTEN pDefaultListen = pListenList;
  373. pListenList = pListenList->pNext;
  374. Free(pDefaultListen);
  375. }
  376. pListen->pNext = pListenList;
  377. return pListenList = pListen;
  378. } // ListenEnqueue()
  379. /*
  380. * NOTES
  381. * GkiLock must be locked before calling this routine!
  382. */
  383. static PLISTEN ListenDequeue(register DWORD hListen)
  384. {
  385. register PLISTEN pListen = pListenList;
  386. register PLISTEN pListenPrev;
  387. if (pListen)
  388. {
  389. if (pListen->hListen == hListen)
  390. {
  391. pListenList = pListen->pNext;
  392. }
  393. else
  394. {
  395. do
  396. {
  397. pListenPrev = pListen;
  398. pListen = pListen->pNext;
  399. } while (pListen && pListen->hListen != hListen);
  400. if (pListen)
  401. {
  402. pListenPrev->pNext = pListen->pNext;
  403. }
  404. }
  405. }
  406. return pListen;
  407. } // ListenDequeue()
  408. /*
  409. * NOTES
  410. * Since the pGkiCall is locked, we don't need a critical section
  411. * around the queue manipulation code.
  412. */
  413. static PBWREQ BwReqEnqueue(register PGKICALL pGkiCall, register PBWREQ pBwReq)
  414. {
  415. pBwReq->pNext = NULL;
  416. if (pGkiCall->pBwReqHead)
  417. {
  418. pGkiCall->pBwReqTail->pNext = pBwReq;
  419. }
  420. else
  421. {
  422. pGkiCall->pBwReqHead = pBwReq;
  423. }
  424. return pGkiCall->pBwReqTail = pBwReq;
  425. } // BwReqEnqueue()
  426. /*
  427. * NOTES
  428. * Since the pGkiCall is locked, we don't need a critical section
  429. * around the queue manipulation code.
  430. */
  431. static PBWREQ BwReqDequeue(register PGKICALL pGkiCall)
  432. {
  433. register PBWREQ pBwReq = pGkiCall->pBwReqHead;
  434. if (pBwReq)
  435. {
  436. pGkiCall->pBwReqHead = pBwReq->pNext;
  437. }
  438. return pBwReq;
  439. } // BwReqDequeue()
  440. DWORD GetIpAddress(void)
  441. {
  442. DWORD dwAddr;
  443. char szHostName[128];
  444. if (gethostname(szHostName, sizeof(szHostName)) == 0)
  445. {
  446. struct hostent *pHostent;
  447. pHostent = gethostbyname(szHostName);
  448. if (pHostent != NULL)
  449. {
  450. ASSERT(pHostent->h_addrtype == AF_INET);
  451. dwAddr = *((DWORD *)pHostent->h_addr_list[0]);
  452. return ntohl(dwAddr);
  453. }
  454. }
  455. return INADDR_ANY;
  456. } // GetIpAddress()
  457. // Caveat: *pAlias should be initialized to all 0 before calling!
  458. static HRESULT CopyAliasItem(SeqAliasAddr *pAlias, PCC_ALIASITEM pAliasItem)
  459. {
  460. unsigned int uDigit;
  461. unsigned int uPrefixLength;
  462. unsigned int uDataLength;
  463. if (pAliasItem->pData == NULL || pAliasItem->wDataLength == 0)
  464. return CC_BAD_PARAM;
  465. if (pAliasItem->pPrefix)
  466. {
  467. // Strip off terminating NULs if included in prefix length
  468. uPrefixLength = pAliasItem->wPrefixLength;
  469. while (uPrefixLength && pAliasItem->pPrefix[uPrefixLength - 1] == 0)
  470. --uPrefixLength;
  471. }
  472. else
  473. {
  474. uPrefixLength = 0;
  475. }
  476. uDataLength = pAliasItem->wDataLength;
  477. switch (pAliasItem->wType)
  478. {
  479. case CC_ALIAS_H323_ID:
  480. pAlias->value.choice = h323_ID_chosen;
  481. pAlias->value.u.h323_ID.value = Malloc((uPrefixLength + uDataLength) * sizeof(pAliasItem->pData[0]));
  482. if (pAlias->value.u.h323_ID.value == NULL)
  483. {
  484. GKDBG((1, "CopyAliasItem: Could not allocate %d bytes memory",
  485. (uPrefixLength + uDataLength) * sizeof(pAliasItem->pData[0])));
  486. return CC_NO_MEMORY;
  487. }
  488. if (uPrefixLength)
  489. {
  490. memcpy(&pAlias->value.u.h323_ID.value[0],
  491. pAliasItem->pPrefix,
  492. uPrefixLength * sizeof(pAliasItem->pPrefix[0]));
  493. memcpy(&pAlias->value.u.h323_ID.value[uPrefixLength],
  494. pAliasItem->pData,
  495. uDataLength * sizeof(pAliasItem->pData[0]));
  496. }
  497. else
  498. {
  499. memcpy(&pAlias->value.u.h323_ID.value[0],
  500. pAliasItem->pData,
  501. uDataLength * sizeof(pAliasItem->pData[0]));
  502. }
  503. pAlias->value.u.h323_ID.length = (unsigned short)(uPrefixLength + uDataLength);
  504. break;
  505. case CC_ALIAS_H323_PHONE:
  506. pAlias->value.choice = e164_chosen;
  507. if (uPrefixLength)
  508. {
  509. for (uDigit = 0; uDigit < uPrefixLength; ++uDigit)
  510. {
  511. pAlias->value.u.e164[uDigit] = (char)pAliasItem->pPrefix[uDigit];
  512. }
  513. for (uDigit = 0; uDigit < uDataLength; ++uDigit)
  514. {
  515. pAlias->value.u.e164[uDigit + uPrefixLength] = (char)pAliasItem->pData[uDigit];
  516. }
  517. }
  518. else
  519. {
  520. for (uDigit = 0; uDigit < uDataLength; ++uDigit)
  521. {
  522. pAlias->value.u.e164[uDigit] = (char)pAliasItem->pData[uDigit];
  523. }
  524. }
  525. break;
  526. default:
  527. GKDBG((1, "CopyAliasItem: Bad alias name type %d", pAliasItem->wType));
  528. return CC_BAD_PARAM;
  529. } // switch
  530. return NOERROR;
  531. } // CopyAliasItem()
  532. /*
  533. * NOTES
  534. * Must have Call locked before calling!
  535. */
  536. static void GkiAllocCall(PGKICALL pGkiCall, HANDLE hGkiCall)
  537. {
  538. ASSERT(pGkiCall != NULL);
  539. ASSERT(hGkiCall != 0);
  540. ASSERT(hGkiCall != GKI_ADMITTING_HANDLE);
  541. pGkiCall->hGkiCall = hGkiCall;
  542. pGkiCall->uGkiCallState = GCS_ADMITTED;
  543. ++uGkiCalls;
  544. GKDBG((1, "GkiAllocCall: uGkiCalls = %d", uGkiCalls));
  545. } // GkiAllocCall()
  546. /*
  547. * NOTES
  548. * Must have Call locked before calling!
  549. */
  550. static HRESULT GkiCancelCall(PGKICALL pGkiCall, void *pConference)
  551. {
  552. DWORD hCall;
  553. ASSERT(pGkiCall != NULL);
  554. pConference = pConference; // Disable compiler warning
  555. hCall = pGkiCall->hCall;
  556. GKDBG((1, CallStateName("GkiCancelCall <- Call State = %s", pGkiCall->uGkiCallState), 0));
  557. switch (pGkiCall->uGkiCallState)
  558. {
  559. case GCS_START:
  560. break;
  561. case GCS_WAITING:
  562. ASSERT(pGkiCall->hGkiCall == 0);
  563. if (pGkiCall->bAnswerCall)
  564. AcceptCallReject(pGkiCall->pCall, pConference, CC_GATEKEEPER_REFUSED);
  565. else
  566. PlaceCallReject (pGkiCall->pCall, pConference, CC_GATEKEEPER_REFUSED);
  567. break;
  568. case GCS_ADMITTING:
  569. case GCS_ADMITTING_CLOSE_PENDING:
  570. ASSERT(pGkiCall->hGkiCall == GKI_ADMITTING_HANDLE);
  571. if (pGkiCall->bAnswerCall)
  572. AcceptCallReject(pGkiCall->pCall, pConference, CC_GATEKEEPER_REFUSED);
  573. else
  574. PlaceCallReject (pGkiCall->pCall, pConference, CC_GATEKEEPER_REFUSED);
  575. break;
  576. case GCS_ADMITTED:
  577. case GCS_CHANGING:
  578. case GCS_CHANGING_CLOSE_PENDING:
  579. case GCS_DISENGAGING:
  580. ASSERT(pGkiCall->hGkiCall != 0);
  581. ASSERT(pGkiCall->hGkiCall != GKI_ADMITTING_HANDLE);
  582. Disengage(pGkiCall->pCall);
  583. return NOERROR;
  584. default:
  585. GKDBG((1, "GkiCancelCall: Invalid call state %d", pGkiCall->uGkiCallState));
  586. } // switch
  587. if (ValidateCall(hCall) == NOERROR && pGkiCall->uGkiCallState != GCS_START)
  588. {
  589. GkiFreeCall(pGkiCall);
  590. }
  591. GKDBG((1, CallStateName("GkiCancelCall -> Call State = %s", pGkiCall->uGkiCallState), 0));
  592. return NOERROR;
  593. } // GkiCancelCall()
  594. /*
  595. * NOTES
  596. * Must have Call locked before calling!
  597. */
  598. static HRESULT GkiCancelAdmitting(PGKICALL pGkiCall, void *pConference)
  599. {
  600. ASSERT(pGkiCall != NULL);
  601. pConference = pConference; // Disable compiler warning
  602. GKDBG((1, CallStateName("GkiCancelAdmitting <- Call State = %s", pGkiCall->uGkiCallState), 0));
  603. switch (pGkiCall->uGkiCallState)
  604. {
  605. case GCS_ADMITTING:
  606. ASSERT(pGkiCall->hGkiCall == GKI_ADMITTING_HANDLE);
  607. pGkiCall->hGkiCall = 0;
  608. pGkiCall->uGkiCallState = GCS_WAITING;
  609. break;
  610. case GCS_ADMITTING_CLOSE_PENDING:
  611. ASSERT(pGkiCall->hGkiCall == GKI_ADMITTING_HANDLE);
  612. GkiFreeCall(pGkiCall);
  613. break;
  614. } // switch
  615. GKDBG((1, CallStateName("GkiCancelAdmitting -> Call State = %s", pGkiCall->uGkiCallState), 0));
  616. return NOERROR;
  617. } // GkiCancelAdmitting()
  618. /*
  619. * NOTES
  620. * Must have Call locked before calling!
  621. */
  622. static HRESULT CheckPendingBandwidth(PGKICALL pGkiCall);
  623. static HRESULT GatekeeperNotFound(PGKICALL pGkiCall, void *pConference)
  624. {
  625. ASSERT(pGkiCall != NULL);
  626. ASSERT(pConference != NULL);
  627. GKDBG((1, CallStateName("GatekeeperNotFound <- Call State = %s", pGkiCall->uGkiCallState), 0));
  628. switch (pGkiCall->uGkiCallState)
  629. {
  630. case GCS_START:
  631. case GCS_ADMITTED:
  632. break;
  633. case GCS_WAITING:
  634. case GCS_ADMITTING:
  635. GkiOpenCall(pGkiCall, pConference);
  636. break;
  637. case GCS_ADMITTING_CLOSE_PENDING:
  638. case GCS_CHANGING_CLOSE_PENDING:
  639. case GCS_DISENGAGING:
  640. GkiCloseCall(pGkiCall);
  641. break;
  642. case GCS_CHANGING:
  643. pGkiCall->uGkiCallState = GCS_ADMITTED;
  644. pGkiCall->uBandwidthAllocated = MAX_BANDWIDTH;
  645. CheckPendingBandwidth(pGkiCall);
  646. break;
  647. default:
  648. GKDBG((1, "GatekeeperNotFound: Invalid call state %d", pGkiCall->uGkiCallState));
  649. } // switch
  650. GKDBG((1, CallStateName("GatekeeperNotFound -> Call State = %s", pGkiCall->uGkiCallState), 0));
  651. return NOERROR;
  652. } // GatekeeperNotFound()
  653. /*
  654. * NOTES
  655. * GkiLock must be locked before calling this routine!
  656. */
  657. static HRESULT GkiRegister(void)
  658. {
  659. register HRESULT status = NOERROR;
  660. ASSERT(pListenList != NULL);
  661. switch (uGkiState)
  662. {
  663. case STATE_START:
  664. // Register window class
  665. {
  666. WNDCLASS wndclass = { 0, GkiWndProc, 0, 0, 0, 0, 0, 0, NULL, szClassName };
  667. atomGki = RegisterClass(&wndclass);
  668. if (atomGki == 0)
  669. {
  670. status = HRESULT_FROM_WIN32(GetLastError());
  671. GKDBG((1, "GkiRegister: Error 0x%x registering class", status));
  672. break;
  673. }
  674. }
  675. uGkiState = STATE_CLASS_REGISTERED;
  676. // Fall-through to next case
  677. case STATE_CLASS_REGISTERED:
  678. // Create window to receive GKI messages
  679. hwndGki = CreateWindow(szClassName, "", WS_OVERLAPPED, 0, 0, 0, 0, 0, 0, 0, NULL);
  680. if (hwndGki == 0)
  681. {
  682. status = HRESULT_FROM_WIN32(GetLastError());
  683. GKDBG((1, "GkiRegister: Error 0x%x creating window", status));
  684. break;
  685. }
  686. uGkiState = STATE_WINDOW_CREATED;
  687. // Fall-through to next case
  688. case STATE_WINDOW_CREATED:
  689. {
  690. PLISTEN pListen;
  691. unsigned uListens = 0;
  692. unsigned uAliasNames = 0;
  693. SeqTransportAddr *pTransportAddrs;
  694. SeqAliasAddr *pAliasAddrs;
  695. PCC_ALIASITEM pAliasItem;
  696. unsigned uIndex;
  697. unsigned uDigit;
  698. EndpointType TerminalType = {0};
  699. // Count Transport Addresses and Alias Names
  700. pListen = pListenList;
  701. while (pListen)
  702. {
  703. // Count the Transport Address
  704. ++uListens;
  705. if (pListen->pAliasNames)
  706. {
  707. // Count the Alias Names
  708. uAliasNames += pListen->pAliasNames->wCount;
  709. }
  710. pListen = pListen->pNext;
  711. }
  712. pTransportAddrs = Malloc(uListens * sizeof(*pTransportAddrs));
  713. if (pTransportAddrs == NULL)
  714. {
  715. GKDBG((1, "GkiRegister: Could not allocate %d Transport Addresses", uListens));
  716. return CC_NO_MEMORY;
  717. }
  718. if (uAliasNames)
  719. {
  720. pAliasAddrs = Malloc(uAliasNames * sizeof(*pAliasAddrs));
  721. if (pAliasAddrs == NULL)
  722. {
  723. Free(pTransportAddrs);
  724. GKDBG((1, "GkiRegister: Could not allocate %d Alias Addresses", uAliasNames));
  725. return CC_NO_MEMORY;
  726. }
  727. }
  728. else
  729. {
  730. pAliasAddrs = NULL;
  731. }
  732. pListen = pListenList;
  733. uListens = 0;
  734. uAliasNames = 0;
  735. while (pListen)
  736. {
  737. // Initialize a transport address
  738. // TBD - throw out duplicates
  739. pTransportAddrs[uListens].next = &pTransportAddrs[uListens + 1];
  740. pTransportAddrs[uListens].value.choice = ipAddress_chosen;
  741. pTransportAddrs[uListens].value.u.ipAddress.ip.length = 4;
  742. *((DWORD *)pTransportAddrs[uListens].value.u.ipAddress.ip.value) = pListen->dwAddr;
  743. pTransportAddrs[uListens].value.u.ipAddress.port = pListen->wPort;
  744. // Add any alias names to list
  745. // TBD - throw out duplicates
  746. if (pListen->pAliasNames)
  747. {
  748. pAliasItem = pListen->pAliasNames->pItems;
  749. for (uIndex = 0; uIndex < pListen->pAliasNames->wCount; ++uIndex, ++pAliasItem)
  750. {
  751. pAliasAddrs[uAliasNames].next = &pAliasAddrs[uAliasNames + 1];
  752. switch (pAliasItem->wType)
  753. {
  754. case CC_ALIAS_H323_ID:
  755. pAliasAddrs[uAliasNames].value.choice = h323_ID_chosen;
  756. pAliasAddrs[uAliasNames].value.u.h323_ID.length = pAliasItem->wDataLength;
  757. pAliasAddrs[uAliasNames].value.u.h323_ID.value = pAliasItem->pData;
  758. break;
  759. case CC_ALIAS_H323_PHONE:
  760. pAliasAddrs[uAliasNames].value.choice = e164_chosen;
  761. memset(pAliasAddrs[uAliasNames].value.u.e164, 0, sizeof(pAliasAddrs[uAliasNames].value.u.e164));
  762. for (uDigit = 0; uDigit < pAliasItem->wDataLength; ++uDigit)
  763. {
  764. pAliasAddrs[uAliasNames].value.u.e164[uDigit] = (char)pAliasItem->pData[uDigit];
  765. }
  766. break;
  767. default:
  768. Free(pAliasAddrs);
  769. Free(pTransportAddrs);
  770. GKDBG((1, "GkiRegister: Bad alias name type %d",
  771. pAliasItem->wType));
  772. return CC_BAD_PARAM;
  773. } // switch
  774. ++uAliasNames;
  775. } // for
  776. } // if
  777. ++uListens;
  778. pListen = pListen->pNext;
  779. } // while
  780. pTransportAddrs[uListens - 1].next = NULL;
  781. if (pAliasAddrs)
  782. {
  783. pAliasAddrs[uAliasNames - 1].next = NULL;
  784. }
  785. // Initialize TerminalType
  786. TerminalType.bit_mask = terminal_present;
  787. TerminalType.mc = TRUE;
  788. uGkiState = STATE_REGISTERING;
  789. GKDBG((1, "GKI_RegistrationRequest called...", 0));
  790. status =
  791. pGKI_RegistrationRequest(GKI_VERSION, // lVersion
  792. pTransportAddrs, // pCallSignalAddr
  793. &TerminalType, // pTerminalType
  794. pAliasAddrs, // pRgstrtnRgst_trmnlAls
  795. hwndGki, // hWnd
  796. GKIMAN_BASE, // wBaseMessage
  797. ipAddress_chosen); // usRegistrationTransport
  798. if (status == NOERROR)
  799. {
  800. GKDBG((1, GkiErrorName("GKI_RegistrationRequest returned %s", status), 0));
  801. }
  802. else
  803. {
  804. GKDBG((1, GkiErrorName("GKI_RegistrationRequest returned %s", status), 0));
  805. uGkiState = STATE_WINDOW_CREATED;
  806. }
  807. if (pAliasAddrs)
  808. Free(pAliasAddrs);
  809. if (pTransportAddrs)
  810. Free(pTransportAddrs);
  811. }
  812. break;
  813. case STATE_REGISTERING:
  814. case STATE_REGISTERING_REREG:
  815. case STATE_REGISTERING_UNREG:
  816. uGkiState = STATE_REGISTERING_REREG;
  817. break;
  818. case STATE_REGISTERED:
  819. uGkiState = STATE_UNREGISTERING_REREG;
  820. GKDBG((1, "GKI_UnregistrationRequest called...", 0));
  821. status = pGKI_UnregistrationRequest();
  822. if (status == NOERROR)
  823. {
  824. GKDBG((1, GkiErrorName("GKI_UnregistrationRequest returned %s", status), 0));
  825. }
  826. else
  827. {
  828. GKDBG((1, GkiErrorName("GKI_UnregistrationRequest returned %s", status), 0));
  829. uGkiState = STATE_REG_BYPASS;
  830. ApplyToAllCalls(GatekeeperNotFound);
  831. }
  832. break;
  833. case STATE_ADMITTING:
  834. case STATE_ADMITTING_REREG:
  835. case STATE_ADMITTING_UNREG:
  836. uGkiState = STATE_ADMITTING_REREG;
  837. break;
  838. case STATE_DISENGAGING:
  839. uGkiState = STATE_DISENGAGING_REREG;
  840. break;
  841. case STATE_DISENGAGING_REREG:
  842. break;
  843. case STATE_UNREGISTERING:
  844. uGkiState = STATE_UNREGISTERING_REREG;
  845. break;
  846. case STATE_UNREGISTERING_REREG:
  847. break;
  848. case STATE_REG_BYPASS:
  849. break;
  850. default:
  851. GKDBG((1, "GkiRegister: Invalid state %d", uGkiState));
  852. status = LastGkiError;
  853. } // switch
  854. return status;
  855. } // GkiRegister()
  856. /*
  857. * NOTES
  858. * GkiLock must be locked before calling this routine!
  859. */
  860. HRESULT GkiCloseCallNoError(PGKICALL pGkiCall, void *pConference)
  861. {
  862. ASSERT(pGkiCall != NULL);
  863. pConference = pConference; // Disable compiler warning
  864. if (pGkiCall->uGkiCallState != GCS_START)
  865. GkiCloseCall(pGkiCall);
  866. return NOERROR;
  867. } // GkiCloseCallNoError()
  868. HRESULT GkiUnregister(void)
  869. {
  870. register HRESULT status = NOERROR;
  871. switch (uGkiState)
  872. {
  873. case STATE_REG_BYPASS:
  874. ApplyToAllCalls(GkiCancelCall);
  875. uGkiState = STATE_WINDOW_CREATED;
  876. break;
  877. case STATE_UNREGISTERING_REREG:
  878. uGkiState = STATE_UNREGISTERING;
  879. break;
  880. case STATE_UNREGISTERING:
  881. break;
  882. case STATE_DISENGAGING_REREG:
  883. if (uGkiCalls != 0 || uPendingDisengages != 0)
  884. {
  885. uGkiState = STATE_DISENGAGING;
  886. }
  887. else
  888. {
  889. uGkiState = STATE_REGISTERED;
  890. return GkiUnregister();
  891. }
  892. break;
  893. case STATE_DISENGAGING:
  894. if (uGkiCalls == 0 && uPendingDisengages == 0)
  895. {
  896. uGkiState = STATE_REGISTERED;
  897. return GkiUnregister();
  898. }
  899. break;
  900. case STATE_ADMITTING_UNREG:
  901. case STATE_ADMITTING_REREG:
  902. case STATE_ADMITTING:
  903. uGkiState = STATE_ADMITTING_UNREG;
  904. break;
  905. case STATE_REGISTERING_UNREG:
  906. case STATE_REGISTERING_REREG:
  907. case STATE_REGISTERING:
  908. uGkiState = STATE_REGISTERING_UNREG;
  909. break;
  910. case STATE_REGISTERED:
  911. if (uGkiCalls)
  912. {
  913. // Issue Disengage Request for every call
  914. uGkiState = STATE_DISENGAGING;
  915. ApplyToAllCalls(GkiCloseCallNoError);
  916. break;
  917. }
  918. else
  919. {
  920. // Issue Unregistration Request
  921. uGkiState = STATE_UNREGISTERING;
  922. GKDBG((1, "GKI_UnregistrationRequest called...", 0));
  923. status = pGKI_UnregistrationRequest();
  924. if (status == NOERROR)
  925. {
  926. GKDBG((1, GkiErrorName("GKI_UnregistrationRequest returned %s", status), 0));
  927. }
  928. else
  929. {
  930. GKDBG((1, GkiErrorName("GKI_UnregistrationRequest returned %s", status), 0));
  931. uGkiState = STATE_WINDOW_CREATED;
  932. }
  933. }
  934. break;
  935. case STATE_WINDOW_CREATED:
  936. case STATE_CLASS_REGISTERED:
  937. case STATE_START:
  938. GKDBG((1, StateName("GkiUnregister: Already in uninitialized state %s", uGkiState), 0));
  939. status = LastGkiError;
  940. break;
  941. default:
  942. GKDBG((1, "GkiUnregister: Invalid state %d", uGkiState));
  943. status = LastGkiError;
  944. } // switch
  945. return status;
  946. } // GkiUnregister()
  947. void DeInitGkiManager(void)
  948. {
  949. register PLISTEN pListen;
  950. EnterCriticalSection(&GkiLock);
  951. #if 0
  952. // TBD - When called from DllMain PROCESS_DETACH, this does not work because
  953. // apparently the socket to the Gatekeeper has already been closed.
  954. if (uGkiState != STATE_START)
  955. {
  956. GkiUnregister();
  957. uGkiState = STATE_START;
  958. }
  959. #else
  960. uGkiState = STATE_START;
  961. #endif
  962. while (pListenList)
  963. {
  964. pListen = pListenList;
  965. pListenList = pListenList->pNext;
  966. if (pListen->pAliasNames)
  967. {
  968. FreeAliasNames(pListen->pAliasNames);
  969. }
  970. Free(pListen);
  971. }
  972. pGKI_RegistrationRequest = NULL;
  973. pGKI_UnregistrationRequest = NULL;
  974. pGKI_LocationRequest = NULL;
  975. pGKI_AdmissionRequest = NULL;
  976. pGKI_BandwidthRequest = NULL;
  977. pGKI_DisengageRequest = NULL;
  978. if (hGkiDll)
  979. {
  980. if (pGKI_CleanupRequest)
  981. pGKI_CleanupRequest();
  982. #if defined(REMOVE_FROM_TSP)
  983. FreeLibrary(hGkiDll);
  984. #endif // REMOVE_FROM_TSP
  985. }
  986. pGKI_CleanupRequest = NULL;
  987. LeaveCriticalSection(&GkiLock);
  988. DeleteCriticalSection(&GkiLock);
  989. DestroyWindow(hwndGki);
  990. UnregisterClass(szClassName, 0);
  991. } // DeInitGkiManager()
  992. HRESULT InitGkiManager(void)
  993. {
  994. InitializeCriticalSection(&GkiLock);
  995. #if defined(REMOVE_FROM_TSP)
  996. hGkiDll = LoadLibrary("GKI.DLL");
  997. if (hGkiDll == NULL)
  998. {
  999. DeInitGkiManager();
  1000. return CC_GKI_LOAD;
  1001. }
  1002. pGKI_RegistrationRequest = (PGKI_RegistrationRequest) GetProcAddress(hGkiDll, "GKI_RegistrationRequest");
  1003. pGKI_UnregistrationRequest = (PGKI_UnregistrationRequest)GetProcAddress(hGkiDll, "GKI_UnregistrationRequest");
  1004. pGKI_LocationRequest = (PGKI_LocationRequest) GetProcAddress(hGkiDll, "GKI_LocationRequest");
  1005. pGKI_AdmissionRequest = (PGKI_AdmissionRequest) GetProcAddress(hGkiDll, "GKI_AdmissionRequest");
  1006. pGKI_BandwidthRequest = (PGKI_BandwidthRequest) GetProcAddress(hGkiDll, "GKI_BandwidthRequest");
  1007. pGKI_DisengageRequest = (PGKI_DisengageRequest) GetProcAddress(hGkiDll, "GKI_DisengageRequest");
  1008. pGKI_CleanupRequest = (PGKI_CleanupRequest) GetProcAddress(hGkiDll, "GKI_CleanupRequest");
  1009. if (pGKI_RegistrationRequest == NULL ||
  1010. pGKI_UnregistrationRequest == NULL ||
  1011. pGKI_LocationRequest == NULL ||
  1012. pGKI_AdmissionRequest == NULL ||
  1013. pGKI_BandwidthRequest == NULL ||
  1014. pGKI_DisengageRequest == NULL ||
  1015. pGKI_CleanupRequest == NULL)
  1016. {
  1017. DeInitGkiManager();
  1018. return CC_GKI_LOAD;
  1019. }
  1020. #else // REMOVE_FROM_TSP
  1021. pGKI_RegistrationRequest = GKI_RegistrationRequest;
  1022. pGKI_UnregistrationRequest = GKI_UnregistrationRequest;
  1023. pGKI_LocationRequest = GKI_LocationRequest;
  1024. pGKI_AdmissionRequest = GKI_AdmissionRequest;
  1025. pGKI_BandwidthRequest = GKI_BandwidthRequest;
  1026. pGKI_DisengageRequest = GKI_DisengageRequest;
  1027. pGKI_CleanupRequest = GKI_CleanupRequest;
  1028. #endif // REMOVE_FROM_TSP
  1029. return NOERROR;
  1030. } // InitGkiManager()
  1031. //
  1032. // Entry Points
  1033. //
  1034. HRESULT GkiFreeCall(PGKICALL pGkiCall)
  1035. {
  1036. HRESULT status = NOERROR;
  1037. ASSERT(pGkiCall != NULL);
  1038. ASSERT(pGkiCall->uGkiCallState != GCS_START);
  1039. pGkiCall->hGkiCall = 0;
  1040. while (pGkiCall->pBwReqHead)
  1041. {
  1042. Free(BwReqDequeue(pGkiCall));
  1043. }
  1044. if (pGkiCall->pCalleeAliasNames)
  1045. {
  1046. Q931FreeAliasNames(pGkiCall->pCalleeAliasNames);
  1047. pGkiCall->pCalleeAliasNames = NULL;
  1048. }
  1049. if (pGkiCall->pCalleeExtraAliasNames != NULL)
  1050. {
  1051. Q931FreeAliasNames(pGkiCall->pCalleeExtraAliasNames);
  1052. pGkiCall->pCalleeExtraAliasNames = NULL;
  1053. }
  1054. switch (pGkiCall->uGkiCallState)
  1055. {
  1056. case GCS_START:
  1057. case GCS_WAITING:
  1058. break;
  1059. case GCS_ADMITTING:
  1060. ASSERT(uGkiState == STATE_ADMITTING);
  1061. switch (uGkiState)
  1062. {
  1063. case STATE_ADMITTING:
  1064. uGkiState = STATE_REGISTERED;
  1065. break;
  1066. } // switch
  1067. break;
  1068. case GCS_ADMITTING_CLOSE_PENDING:
  1069. ASSERT(uGkiState == STATE_ADMITTING || uGkiState == STATE_ADMITTING_UNREG || uGkiState == STATE_ADMITTING_REREG);
  1070. switch (uGkiState)
  1071. {
  1072. case STATE_ADMITTING:
  1073. uGkiState = STATE_REGISTERED;
  1074. break;
  1075. case STATE_ADMITTING_UNREG:
  1076. uGkiState = STATE_REGISTERED;
  1077. status = GkiUnregister();
  1078. break;
  1079. case STATE_ADMITTING_REREG:
  1080. uGkiState = STATE_REGISTERED;
  1081. status = GkiRegister();
  1082. break;
  1083. } // switch
  1084. break;
  1085. case GCS_ADMITTED:
  1086. case GCS_CHANGING:
  1087. case GCS_CHANGING_CLOSE_PENDING:
  1088. case GCS_DISENGAGING:
  1089. --uGkiCalls;
  1090. GKDBG((1, "GkiFreeCall: uGkiCalls = %d", uGkiCalls));
  1091. break;
  1092. default:
  1093. GKDBG((1, "GkiFreeCall: Invalid call state %d", pGkiCall->uGkiCallState));
  1094. } // switch
  1095. pGkiCall->uGkiCallState = GCS_START;
  1096. if (uGkiCalls == 0 && uPendingDisengages == 0)
  1097. {
  1098. switch (uGkiState)
  1099. {
  1100. case STATE_DISENGAGING:
  1101. uGkiState = STATE_REGISTERED;
  1102. status = GkiUnregister();
  1103. break;
  1104. case STATE_DISENGAGING_REREG:
  1105. uGkiState = STATE_REGISTERED;
  1106. status = GkiRegister();
  1107. break;
  1108. } // switch
  1109. if (pListenList && pListenList->hListen == DEFAULT_LISTEN_HANDLE)
  1110. {
  1111. GkiCloseListen(DEFAULT_LISTEN_HANDLE);
  1112. }
  1113. }
  1114. return status;
  1115. } // GkiFreeCall()
  1116. HRESULT GkiCloseListen (DWORD hListen)
  1117. {
  1118. register PLISTEN pListen;
  1119. register HRESULT status;
  1120. GKDBG((1, StateName("GkiCloseListen <- State = %s", uGkiState), 0));
  1121. EnterCriticalSection(&GkiLock);
  1122. pListen = ListenDequeue(hListen);
  1123. if (pListen == NULL)
  1124. {
  1125. status = CC_GKI_LISTEN_NOT_FOUND;
  1126. }
  1127. else
  1128. {
  1129. if (pListen->pAliasNames)
  1130. {
  1131. FreeAliasNames(pListen->pAliasNames);
  1132. }
  1133. Free(pListen);
  1134. if (pListenList)
  1135. {
  1136. status = GkiRegister();
  1137. }
  1138. else
  1139. {
  1140. status = GkiUnregister();
  1141. }
  1142. }
  1143. LeaveCriticalSection(&GkiLock);
  1144. GKDBG((1, StateName("GkiCloseListen -> State = %s", uGkiState), 0));
  1145. return status;
  1146. } // GkiCloseListen()
  1147. HRESULT GkiOpenListen (DWORD hListen, PCC_ALIASNAMES pAliasNames, DWORD dwAddr, WORD wPort)
  1148. {
  1149. register PLISTEN pListen;
  1150. register HRESULT status = NOERROR;
  1151. GKDBG((1, StateName("GkiOpenListen <- State = %s", uGkiState), 0));
  1152. EnterCriticalSection(&GkiLock);
  1153. // Check for invalid IP address
  1154. if (dwAddr == INADDR_ANY || dwAddr == INADDR_NONE)
  1155. {
  1156. dwAddr = GetIpAddress();
  1157. if (dwAddr == INADDR_ANY)
  1158. return CC_GKI_IP_ADDRESS;
  1159. }
  1160. // Check for invalid alias list
  1161. if (pAliasNames)
  1162. {
  1163. PCC_ALIASITEM pAliasItem;
  1164. unsigned int uIndex;
  1165. if (pAliasNames->wCount == 0)
  1166. {
  1167. GKDBG((1, "GkiOpenListen: Alias name wCount == 0", 0));
  1168. return CC_BAD_PARAM;
  1169. }
  1170. pAliasItem = pAliasNames->pItems;
  1171. for (uIndex = 0; uIndex < pAliasNames->wCount; ++uIndex, ++pAliasItem)
  1172. {
  1173. if (pAliasItem->wDataLength == 0 || pAliasItem->pData == NULL)
  1174. {
  1175. // Bad alias item
  1176. GKDBG((1, "GkiOpenListen: Bad alias item (wDataLength = %d)",
  1177. pAliasItem->wDataLength));
  1178. return CC_BAD_PARAM;
  1179. }
  1180. }
  1181. }
  1182. pListen = (PLISTEN)Malloc(sizeof(*pListen));
  1183. if (pListen)
  1184. {
  1185. if (pAliasNames)
  1186. {
  1187. status = CopyAliasNames(&pListen->pAliasNames, pAliasNames);
  1188. if (status != NOERROR)
  1189. {
  1190. GKDBG((1, "GkiOpenListen: CopyAliasNames returned 0x%x", status));
  1191. LeaveCriticalSection(&GkiLock);
  1192. return status;
  1193. }
  1194. }
  1195. else
  1196. {
  1197. pListen->pAliasNames = NULL;
  1198. }
  1199. pListen->hListen = hListen;
  1200. pListen->dwAddr = ntohl(dwAddr);
  1201. pListen->wPort = wPort;
  1202. ListenEnqueue(pListen);
  1203. status = GkiRegister();
  1204. } // if
  1205. else
  1206. {
  1207. GKDBG((1, "GkiOpenListen: Could not allocate listen structure", 0));
  1208. status = CC_NO_MEMORY;
  1209. } // else
  1210. LeaveCriticalSection(&GkiLock);
  1211. GKDBG((1, StateName("GkiOpenListen -> State = %s", uGkiState), 0));
  1212. return status;
  1213. } // GkiOpenListen()
  1214. /*
  1215. * NOTES
  1216. * Must have Call locked before calling!
  1217. */
  1218. HRESULT GkiCloseCall(PGKICALL pGkiCall)
  1219. {
  1220. HRESULT status = NOERROR;
  1221. ASSERT(pGkiCall != NULL);
  1222. GKDBG((1, CallStateName("GkiCloseCall <- Call State = %s", pGkiCall->uGkiCallState), 0));
  1223. while (pGkiCall->pBwReqHead)
  1224. {
  1225. Free(BwReqDequeue(pGkiCall));
  1226. }
  1227. if (pGkiCall->uGkiCallState == GCS_START)
  1228. {
  1229. GKDBG((1, CallStateName("GkiCloseCall: Call already in state %s", pGkiCall->uGkiCallState), 0));
  1230. status = CC_GKI_CALL_STATE;
  1231. }
  1232. else
  1233. {
  1234. switch (uGkiState)
  1235. {
  1236. case STATE_START:
  1237. break;
  1238. case STATE_REG_BYPASS:
  1239. status = GkiFreeCall(pGkiCall);
  1240. break;
  1241. default:
  1242. switch (pGkiCall->uGkiCallState)
  1243. {
  1244. case GCS_WAITING:
  1245. status = GkiFreeCall(pGkiCall);
  1246. break;
  1247. case GCS_ADMITTING:
  1248. pGkiCall->uGkiCallState = GCS_ADMITTING_CLOSE_PENDING;
  1249. break;
  1250. case GCS_ADMITTING_CLOSE_PENDING:
  1251. case GCS_CHANGING_CLOSE_PENDING:
  1252. case GCS_DISENGAGING:
  1253. GKDBG((1, CallStateName("GkiCloseCall: Call already in closing state %s", pGkiCall->uGkiCallState), 0));
  1254. status = CC_GKI_CALL_STATE;
  1255. break;
  1256. case GCS_ADMITTED:
  1257. pGkiCall->uGkiCallState = GCS_DISENGAGING;
  1258. GKDBG((1, "GKI_DisengageRequest called...", 0));
  1259. ++uPendingDisengages;
  1260. status = pGKI_DisengageRequest(pGkiCall->hGkiCall);
  1261. if (status == NOERROR)
  1262. {
  1263. GKDBG((1, GkiErrorName("GKI_DisengageRequest returned %s", status), 0));
  1264. }
  1265. else
  1266. {
  1267. --uPendingDisengages;
  1268. GKDBG((1, GkiErrorName("GKI_DisengageRequest returned %s", status), 0));
  1269. GkiFreeCall(pGkiCall);
  1270. }
  1271. break;
  1272. case GCS_CHANGING:
  1273. pGkiCall->uGkiCallState = GCS_CHANGING_CLOSE_PENDING;
  1274. break;
  1275. default:
  1276. GKDBG((1, CallStateName("GkiCloseCall: Call in invalid state %s", pGkiCall->uGkiCallState), 0));
  1277. status = CC_GKI_CALL_STATE;
  1278. } // switch
  1279. } // switch
  1280. } // else
  1281. GKDBG((1, StateName("GkiCloseCall -> State = %s", uGkiState), 0));
  1282. return status;
  1283. } // GkiCloseCall()
  1284. /*
  1285. * NOTES
  1286. * Must have Call locked before calling!
  1287. */
  1288. static HRESULT BandwidthRejected(PGKICALL pGkiCall, UINT Reason)
  1289. {
  1290. HRESULT status = NOERROR;
  1291. PBWREQ pBwReq;
  1292. DWORD hCall;
  1293. ASSERT(pGkiCall != NULL);
  1294. pBwReq = BwReqDequeue(pGkiCall);
  1295. hCall = pGkiCall->hCall;
  1296. if (pBwReq)
  1297. {
  1298. if ((pGkiCall->uBandwidthUsed + pBwReq->uChannelBandwidth) <= pGkiCall->uBandwidthAllocated)
  1299. {
  1300. if (pBwReq->Type == TX)
  1301. {
  1302. OpenChannelConfirm (pBwReq->hChannel);
  1303. }
  1304. else
  1305. {
  1306. AcceptChannelConfirm(pBwReq->hChannel);
  1307. }
  1308. }
  1309. else
  1310. {
  1311. if (pBwReq->Type == TX)
  1312. {
  1313. OpenChannelReject (pBwReq->hChannel, MapBandwidthRejectReason(Reason));
  1314. }
  1315. else
  1316. {
  1317. AcceptChannelReject (pBwReq->hChannel, MapBandwidthRejectReason(Reason));
  1318. }
  1319. }
  1320. Free(pBwReq);
  1321. if (ValidateCall(hCall) == NOERROR)
  1322. {
  1323. CheckPendingBandwidth(pGkiCall);
  1324. }
  1325. }
  1326. return status;
  1327. } // BandwidthRejected()
  1328. /*
  1329. * NOTES
  1330. * Must have Call locked before calling!
  1331. */
  1332. static HRESULT CheckPendingBandwidth(PGKICALL pGkiCall)
  1333. {
  1334. HRESULT status = NOERROR;
  1335. PBWREQ pBwReq;
  1336. DWORD hCall;
  1337. ASSERT(pGkiCall != NULL);
  1338. ASSERT(pGkiCall->uGkiCallState == GCS_ADMITTED);
  1339. hCall = pGkiCall->hCall;
  1340. while (pGkiCall->pBwReqHead != NULL &&
  1341. (pGkiCall->uBandwidthUsed + pGkiCall->pBwReqHead->uChannelBandwidth) <= pGkiCall->uBandwidthAllocated)
  1342. {
  1343. pBwReq = BwReqDequeue(pGkiCall);
  1344. ASSERT(pBwReq != NULL);
  1345. pGkiCall->uBandwidthUsed += pBwReq->uChannelBandwidth;
  1346. if (pBwReq->Type == TX)
  1347. {
  1348. OpenChannelConfirm(pBwReq->hChannel);
  1349. }
  1350. else
  1351. {
  1352. AcceptChannelConfirm(pBwReq->hChannel);
  1353. }
  1354. Free(pBwReq);
  1355. if (ValidateCall(hCall) != NOERROR)
  1356. {
  1357. return status;
  1358. }
  1359. }
  1360. if (pGkiCall->pBwReqHead != NULL)
  1361. {
  1362. pGkiCall->uGkiCallState = GCS_CHANGING;
  1363. GKDBG((1, "GKI_BandwidthRequest called...", 0);
  1364. status = pGKI_BandwidthRequest(pGkiCall->hGkiCall,
  1365. pGkiCall->usCallTypeChoice,
  1366. pGkiCall->uBandwidthUsed + pGkiCall->pBwReqHead->uChannelBandwidth));
  1367. if (status == NOERROR)
  1368. {
  1369. GKDBG((1, GkiErrorName("GKI_BandwidthRequest returned %s", status), 0));
  1370. }
  1371. else
  1372. {
  1373. GKDBG((1, GkiErrorName("GKI_BandwidthRequest returned %s", status), 0));
  1374. BandwidthRejected(pGkiCall, BndRjctRsn_undfndRsn_chosen);
  1375. }
  1376. }
  1377. return status;
  1378. } // CheckPendingBandwidth()
  1379. static void FreeAliasList(SeqAliasAddr *pAliasAddrs)
  1380. {
  1381. register SeqAliasAddr *pAlias = pAliasAddrs;
  1382. while (pAlias)
  1383. {
  1384. if (pAlias->value.choice == h323_ID_chosen && pAlias->value.u.h323_ID.value)
  1385. Free(pAlias->value.u.h323_ID.value);
  1386. pAlias = pAlias->next;
  1387. }
  1388. Free(pAlias);
  1389. } // FreeAliasList()
  1390. /*
  1391. * NOTES
  1392. * Must have Call locked before calling!
  1393. *
  1394. * The following fields in the GKICALL structure must be properly filled
  1395. * in before calling this function:
  1396. * pCall Pointer back to containing CALL structure.
  1397. * CallType Type of call.
  1398. * uBandwidthRequested Initial bandwidth for call.
  1399. * pConferenceId Pointer to conference ID buffer.
  1400. * bActiveMC TRUE if calling party has an active MC.
  1401. * bAnswerCall ???
  1402. */
  1403. HRESULT GkiOpenCall (PGKICALL pGkiCall, void *pConference)
  1404. {
  1405. HRESULT status = NOERROR;
  1406. DWORD hCall;
  1407. TransportAddress SrcCallSignalAddress;
  1408. TransportAddress * pSrcCallSignalAddress;
  1409. TransportAddress DestCallSignalAddress;
  1410. TransportAddress * pDestCallSignalAddress;
  1411. SeqAliasAddr * pAliasAddrs;
  1412. SeqAliasAddr * pExtraAliasAddrs;
  1413. SeqAliasAddr * pAlias;
  1414. PCC_ALIASITEM pAliasItem;
  1415. unsigned uCount;
  1416. unsigned uIndex;
  1417. ConferenceIdentifier ConferenceId;
  1418. ASSERT(pGkiCall != NULL);
  1419. ASSERT(pConference != NULL);
  1420. GKDBG((1, StateName("GkiOpenCall <- State = %s", uGkiState), 0));
  1421. EnterCriticalSection(&GkiLock);
  1422. switch (uGkiState)
  1423. {
  1424. case STATE_REG_BYPASS:
  1425. ASSERT(pGkiCall->uGkiCallState == GCS_START || pGkiCall->uGkiCallState == GCS_WAITING || pGkiCall->uGkiCallState == GCS_ADMITTING);
  1426. hCall = pGkiCall->hCall;
  1427. GkiAllocCall(pGkiCall, GKI_BYPASS_HANDLE);
  1428. pGkiCall->uBandwidthAllocated = MAX_BANDWIDTH;
  1429. if (pGkiCall->bAnswerCall)
  1430. {
  1431. status = AcceptCallConfirm(pGkiCall->pCall, pConference);
  1432. if (status == NOERROR && ValidateCall(hCall) == NOERROR)
  1433. {
  1434. CheckPendingBandwidth(pGkiCall);
  1435. }
  1436. }
  1437. else if (pGkiCall->dwIpAddress == 0)
  1438. {
  1439. status = PlaceCallReject (pGkiCall->pCall, pConference, CC_INVALID_WITHOUT_GATEKEEPER);
  1440. }
  1441. else
  1442. {
  1443. status = PlaceCallConfirm (pGkiCall->pCall, pConference);
  1444. if (status == NOERROR && ValidateCall(hCall) == NOERROR)
  1445. {
  1446. CheckPendingBandwidth(pGkiCall);
  1447. }
  1448. }
  1449. break;
  1450. case STATE_REGISTERING:
  1451. case STATE_REGISTERING_REREG:
  1452. case STATE_ADMITTING:
  1453. pGkiCall->uGkiCallState = GCS_WAITING;
  1454. break;
  1455. case STATE_REGISTERED:
  1456. switch (pGkiCall->CallType)
  1457. {
  1458. case POINT_TO_POINT:
  1459. pGkiCall->usCallTypeChoice = pointToPoint_chosen;
  1460. break;
  1461. case ONE_TO_MANY:
  1462. pGkiCall->usCallTypeChoice = oneToN_chosen;
  1463. break;
  1464. case MANY_TO_ONE:
  1465. pGkiCall->usCallTypeChoice = nToOne_chosen;
  1466. break;
  1467. case MANY_TO_MANY:
  1468. pGkiCall->usCallTypeChoice = nToN_chosen;
  1469. break;
  1470. default:
  1471. LeaveCriticalSection(&GkiLock);
  1472. GKDBG((1, "GkiOpenCall -> Invalid CallType %d", pGkiCall->CallType));
  1473. return CC_BAD_PARAM;
  1474. } // switch
  1475. pSrcCallSignalAddress = NULL;
  1476. pDestCallSignalAddress = NULL;
  1477. pAliasAddrs = NULL;
  1478. pExtraAliasAddrs = NULL;
  1479. if (pGkiCall->dwSrcCallSignalIpAddress != 0 && pGkiCall->wSrcCallSignalPort != 0)
  1480. {
  1481. SrcCallSignalAddress.choice = ipAddress_chosen;
  1482. SrcCallSignalAddress.u.ipAddress.ip.length = 4;
  1483. *((DWORD *)SrcCallSignalAddress.u.ipAddress.ip.value) = pGkiCall->dwSrcCallSignalIpAddress;
  1484. SrcCallSignalAddress.u.ipAddress.port = pGkiCall->wSrcCallSignalPort;
  1485. pSrcCallSignalAddress = &SrcCallSignalAddress;
  1486. }
  1487. if (pGkiCall->dwIpAddress != 0 && pGkiCall->wPort != 0)
  1488. {
  1489. DestCallSignalAddress.choice = ipAddress_chosen;
  1490. DestCallSignalAddress.u.ipAddress.ip.length = 4;
  1491. *((DWORD *)DestCallSignalAddress.u.ipAddress.ip.value) = pGkiCall->dwIpAddress;
  1492. DestCallSignalAddress.u.ipAddress.port = pGkiCall->wPort;
  1493. pDestCallSignalAddress = &DestCallSignalAddress;
  1494. }
  1495. if (pGkiCall->pCalleeAliasNames)
  1496. {
  1497. // pDestCallSignalAddress = NULL;
  1498. uCount = pGkiCall->pCalleeAliasNames->wCount;
  1499. pAliasAddrs = Malloc(uCount * sizeof(*pAliasAddrs));
  1500. if (pAliasAddrs == NULL)
  1501. {
  1502. LeaveCriticalSection(&GkiLock);
  1503. GKDBG((1, "GkiOpenCall: Could not allocate %d Alias Addresses", uCount));
  1504. return CC_NO_MEMORY;
  1505. }
  1506. memset(pAliasAddrs, 0, uCount * sizeof(*pAliasAddrs));
  1507. pAlias = pAliasAddrs;
  1508. pAliasItem = pGkiCall->pCalleeAliasNames->pItems;
  1509. for (uIndex = 0; uIndex < uCount; ++uIndex)
  1510. {
  1511. status = CopyAliasItem(pAlias, pAliasItem);
  1512. if (status != NOERROR)
  1513. {
  1514. LeaveCriticalSection(&GkiLock);
  1515. GKDBG((1, "GkiOpenCall: CopyAliasItem returned %d", status));
  1516. FreeAliasList(pAliasAddrs);
  1517. return status;
  1518. }
  1519. pAlias->next = pAlias + 1;
  1520. ++pAlias;
  1521. ++pAliasItem;
  1522. } // for
  1523. --pAlias;
  1524. pAlias->next = NULL;
  1525. }
  1526. if (pGkiCall->pCalleeExtraAliasNames)
  1527. {
  1528. uCount = pGkiCall->pCalleeExtraAliasNames->wCount;
  1529. pExtraAliasAddrs = Malloc(uCount * sizeof(*pExtraAliasAddrs));
  1530. if (pExtraAliasAddrs == NULL)
  1531. {
  1532. LeaveCriticalSection(&GkiLock);
  1533. GKDBG((1, "GkiOpenCall: Could not allocate %d Alias Addresses", uCount));
  1534. if (pAliasAddrs)
  1535. FreeAliasList(pAliasAddrs);
  1536. return CC_NO_MEMORY;
  1537. }
  1538. memset(pExtraAliasAddrs, 0, uCount * sizeof(*pExtraAliasAddrs));
  1539. pAlias = pExtraAliasAddrs;
  1540. pAliasItem = pGkiCall->pCalleeExtraAliasNames->pItems;
  1541. for (uIndex = 0; uIndex < uCount; ++uIndex)
  1542. {
  1543. status = CopyAliasItem(pAlias, pAliasItem);
  1544. if (status != NOERROR)
  1545. {
  1546. LeaveCriticalSection(&GkiLock);
  1547. GKDBG((1, "GkiOpenCall: CopyAliasItem returned %d", status));
  1548. if (pAliasAddrs)
  1549. FreeAliasList(pAliasAddrs);
  1550. FreeAliasList(pExtraAliasAddrs);
  1551. return status;
  1552. }
  1553. pAlias->next = pAlias + 1;
  1554. ++pAlias;
  1555. ++pAliasItem;
  1556. } // for
  1557. --pAlias;
  1558. pAlias->next = NULL;
  1559. }
  1560. if (pGkiCall->uBandwidthRequested < MIN_BANDWIDTH)
  1561. {
  1562. pGkiCall->uBandwidthRequested = MIN_BANDWIDTH;
  1563. }
  1564. ASSERT(pGkiCall->uBandwidthAllocated == 0);
  1565. ASSERT(pGkiCall->uBandwidthUsed == 0);
  1566. memcpy(ConferenceId.value, pGkiCall->pConferenceId, 16);
  1567. if (((DWORD *)pGkiCall->pConferenceId)[0] != 0 ||
  1568. ((DWORD *)pGkiCall->pConferenceId)[1] != 0 ||
  1569. ((DWORD *)pGkiCall->pConferenceId)[2] != 0 ||
  1570. ((DWORD *)pGkiCall->pConferenceId)[3] != 0)
  1571. {
  1572. ConferenceId.length = 16;
  1573. }
  1574. else
  1575. {
  1576. ConferenceId.length = 0;
  1577. }
  1578. pGkiCall->hGkiCall = GKI_ADMITTING_HANDLE;
  1579. if (pDestCallSignalAddress != NULL || pAliasAddrs != NULL)
  1580. {
  1581. uGkiState = STATE_ADMITTING;
  1582. pGkiCall->uGkiCallState = GCS_ADMITTING;
  1583. GKDBG((1, "GKI_AdmissionRequest called...", 0);
  1584. status = pGKI_AdmissionRequest(pGkiCall->usCallTypeChoice, // usCallTypeChoice.
  1585. pAliasAddrs, // pDestinationInfo
  1586. pGkiCall->bAnswerCall ? pSrcCallSignalAddress : pDestCallSignalAddress,
  1587. pExtraAliasAddrs, // pDestExtraCallInfo,
  1588. pGkiCall->uBandwidthRequested, // bandWidth,
  1589. &ConferenceId, // pConferenceID,
  1590. pGkiCall->bActiveMC, // activeMC,
  1591. pGkiCall->bAnswerCall, // answerCall,
  1592. ipAddress_chosen)); // usCallTransport
  1593. if (status == NOERROR)
  1594. {
  1595. GKDBG((1, GkiErrorName("GKI_AdmissionRequest returned %s", status), 0));
  1596. }
  1597. else
  1598. {
  1599. GKDBG((1, GkiErrorName("GKI_AdmissionRequest returned %s", status), 0));
  1600. }
  1601. }
  1602. else
  1603. {
  1604. pGkiCall->hGkiCall = 0;
  1605. status = CC_BAD_PARAM;
  1606. }
  1607. if (status != NOERROR)
  1608. {
  1609. uGkiState = STATE_REGISTERED;
  1610. GkiCancelCall(pGkiCall, pConference);
  1611. }
  1612. if (pAliasAddrs)
  1613. FreeAliasList(pAliasAddrs);
  1614. if (pExtraAliasAddrs)
  1615. FreeAliasList(pExtraAliasAddrs);
  1616. break;
  1617. case STATE_START:
  1618. case STATE_CLASS_REGISTERED:
  1619. case STATE_WINDOW_CREATED:
  1620. pGkiCall->uGkiCallState = GCS_WAITING;
  1621. status = GkiOpenListen(DEFAULT_LISTEN_HANDLE, NULL, 0, 1720);
  1622. break;
  1623. default:
  1624. GKDBG((1, StateName("GkiOpenCall: Invalid state %s", uGkiState), 0));
  1625. status = LastGkiError;
  1626. } // switch
  1627. LeaveCriticalSection(&GkiLock);
  1628. GKDBG((1, CallStateName("GkiOpenCall -> Call State = %s", pGkiCall->uGkiCallState), 0));
  1629. return status;
  1630. } // GkiOpenCall()
  1631. /*
  1632. * NOTES
  1633. * Must have Call locked before calling!
  1634. */
  1635. HRESULT GkiOpenChannel(PGKICALL pGkiCall, unsigned uChannelBandwidth, DWORD hChannel, CHANNELTYPE Type)
  1636. {
  1637. HRESULT status = NOERROR;
  1638. PBWREQ pBwReq;
  1639. ASSERT(pGkiCall != NULL);
  1640. GKDBG((1, CallStateName("GkiOpenChannel <- Call State = %s", pGkiCall->uGkiCallState), 0));
  1641. pBwReq = (PBWREQ)Malloc(sizeof(*pBwReq));
  1642. if (pBwReq == NULL)
  1643. {
  1644. GKDBG((1, "GkiOpenChannel: Memory allocation failed", 0));
  1645. return CC_NO_MEMORY;
  1646. }
  1647. pBwReq->uChannelBandwidth = uChannelBandwidth / 100;
  1648. pBwReq->hChannel = hChannel;
  1649. pBwReq->Type = Type;
  1650. BwReqEnqueue(pGkiCall, pBwReq);
  1651. switch (pGkiCall->uGkiCallState)
  1652. {
  1653. case GCS_WAITING:
  1654. case GCS_ADMITTING:
  1655. case GCS_CHANGING:
  1656. // Must wait for current operation to complete
  1657. break;
  1658. case GCS_ADMITTED:
  1659. status = CheckPendingBandwidth(pGkiCall);
  1660. break;
  1661. default:
  1662. GKDBG((1, "GkiOpenChannel: Invalid call state %d", pGkiCall->uGkiCallState));
  1663. status = CC_GKI_CALL_STATE;
  1664. } // switch
  1665. GKDBG((1, CallStateName("GkiOpenChannel -> Call State = %s", pGkiCall->uGkiCallState), 0));
  1666. return status;
  1667. } // GkiOpenChannel()
  1668. /*
  1669. * NOTES
  1670. * Must have Call locked before calling!
  1671. */
  1672. HRESULT GkiCloseChannel(PGKICALL pGkiCall, unsigned uChannelBandwidth, DWORD hChannel)
  1673. {
  1674. PBWREQ pBwReq;
  1675. PBWREQ pBwReq1;
  1676. ASSERT(pGkiCall != NULL);
  1677. GKDBG((1, CallStateName("GkiCloseChannel <- Call State = %s", pGkiCall->uGkiCallState), 0));
  1678. // If Bandwidth request is still in queue, bandwidth has not been allocated
  1679. pBwReq = pGkiCall->pBwReqHead;
  1680. if (pBwReq)
  1681. {
  1682. if (pBwReq->hChannel == hChannel)
  1683. {
  1684. Free(BwReqDequeue(pGkiCall));
  1685. GKDBG((1, CallStateName("GkiCloseChannel -> Call State = %s", pGkiCall->uGkiCallState), 0));
  1686. return NOERROR;
  1687. }
  1688. while ((pBwReq1 = pBwReq->pNext) != NULL)
  1689. {
  1690. if (pBwReq1->hChannel == hChannel)
  1691. {
  1692. if (pGkiCall->pBwReqTail == pBwReq1)
  1693. {
  1694. pGkiCall->pBwReqTail = pBwReq;
  1695. }
  1696. pBwReq->pNext = pBwReq1->pNext;
  1697. Free(pBwReq1);
  1698. GKDBG((1, CallStateName("GkiCloseChannel -> Call State = %s", pGkiCall->uGkiCallState), 0));
  1699. return NOERROR;
  1700. }
  1701. }
  1702. }
  1703. pGkiCall->uBandwidthUsed -= (uChannelBandwidth / 100);
  1704. GKDBG((1, CallStateName("GkiCloseChannel -> Call State = %s", pGkiCall->uGkiCallState), 0));
  1705. return NOERROR;
  1706. } // GkiCloseChannel()
  1707. unsigned GkiGetBandwidth(PGKICALL pGkiCall)
  1708. {
  1709. ASSERT(pGkiCall != NULL);
  1710. return pGkiCall->uBandwidthAllocated * 100;
  1711. } // GkiGetBandwidth()
  1712. //
  1713. // GkiWndProc subroutines
  1714. //
  1715. /*
  1716. * NOTES
  1717. * Must have Call locked before calling!
  1718. */
  1719. static HRESULT CheckPendingOpen(PGKICALL pGkiCall, void *pConference)
  1720. {
  1721. HRESULT status = NOERROR;
  1722. ASSERT(pGkiCall != NULL);
  1723. ASSERT(pConference != NULL);
  1724. switch (uGkiState)
  1725. {
  1726. case STATE_REGISTERED:
  1727. case STATE_REG_BYPASS:
  1728. // TBD - Can only open 1!!!
  1729. ASSERT(pGkiCall->uGkiCallState != GCS_ADMITTING);
  1730. if (pGkiCall->uGkiCallState == GCS_WAITING)
  1731. {
  1732. status = GkiOpenCall(pGkiCall, pConference);
  1733. }
  1734. break;
  1735. default:
  1736. status = LastGkiError;
  1737. } // switch
  1738. return status;
  1739. } // CheckPendingOpen()
  1740. static void GkiNoResponse(HWND hWnd)
  1741. {
  1742. HRESULT status;
  1743. switch (uGkiState)
  1744. {
  1745. case STATE_START:
  1746. case STATE_CLASS_REGISTERED:
  1747. case STATE_WINDOW_CREATED:
  1748. case STATE_REG_BYPASS:
  1749. break;
  1750. case STATE_REGISTERING:
  1751. case STATE_REGISTERING_REREG:
  1752. case STATE_REGISTERING_UNREG:
  1753. GKDBG((1, "GkiWndProc: dummy GKI_REG_REJECT", 0));
  1754. PostMessage(hWnd, GKIMAN_BASE + GKI_REG_REJECT, 0, 0);
  1755. break;
  1756. case STATE_ADMITTING:
  1757. case STATE_ADMITTING_REREG:
  1758. ApplyToAllCalls(GkiCancelAdmitting);
  1759. uGkiState = STATE_REGISTERED;
  1760. // Fall-through to next case
  1761. case STATE_REGISTERED:
  1762. if (uGkiCalls == 0)
  1763. {
  1764. GkiRegister();
  1765. }
  1766. else
  1767. {
  1768. uGkiState = STATE_REG_BYPASS;
  1769. ApplyToAllCalls(GatekeeperNotFound);
  1770. GKDBG((1, "GKI_UnregistrationRequest called...", 0));
  1771. status = pGKI_UnregistrationRequest();
  1772. if (status == NOERROR)
  1773. {
  1774. GKDBG((1, GkiErrorName("GKI_UnregistrationRequest returned %s", status), 0));
  1775. }
  1776. else
  1777. {
  1778. GKDBG((1, GkiErrorName("GKI_UnregistrationRequest returned %s", status), 0));
  1779. }
  1780. }
  1781. break;
  1782. case STATE_ADMITTING_UNREG:
  1783. ApplyToAllCalls(GkiCancelAdmitting);
  1784. uGkiState = STATE_REGISTERED;
  1785. GkiUnregister();
  1786. break;
  1787. case STATE_DISENGAGING:
  1788. ApplyToAllCalls(GatekeeperNotFound);
  1789. ASSERT(uGkiCalls == 0);
  1790. uGkiState = STATE_REGISTERED;
  1791. GkiUnregister();
  1792. break;
  1793. case STATE_DISENGAGING_REREG:
  1794. ApplyToAllCalls(GatekeeperNotFound);
  1795. ASSERT(uGkiCalls == 0);
  1796. uGkiState = STATE_REGISTERED;
  1797. GkiRegister();
  1798. break;
  1799. case STATE_UNREGISTERING:
  1800. case STATE_UNREGISTERING_REREG:
  1801. GKDBG((1, "GkiWndProc: dummy GKI_UNREG_CONFIRM", 0));
  1802. PostMessage(hWnd, GKIMAN_BASE + GKI_UNREG_CONFIRM, 0, 0);
  1803. break;
  1804. default:
  1805. GKDBG((1, "GkiWndProc: Bad uGkiState %d", uGkiState));
  1806. } // switch
  1807. } // GkiNoResponse()
  1808. LONG APIENTRY GkiWndProc(
  1809. HWND hWnd, /* window handle */
  1810. UINT message, /* type of message */
  1811. UINT wParam, /* additional information */
  1812. LONG lParam) /* additional information */
  1813. {
  1814. CallReturnInfo * pCallReturnInfo;
  1815. PGKICALL pGkiCall;
  1816. void * pConference;
  1817. DWORD hCall;
  1818. DWORD hConference;
  1819. HRESULT status;
  1820. if (message < GKIMAN_BASE)
  1821. {
  1822. return DefWindowProc(hWnd, message, wParam, lParam);
  1823. }
  1824. EnterCallControlTop();
  1825. GKDBG((1, StateName("GkiWndProc <- State = %s", uGkiState), 0));
  1826. switch (message)
  1827. {
  1828. case GKIMAN_BASE + GKI_REG_CONFIRM:
  1829. GKDBG((1, "GkiWndProc: GKI_REG_CONFIRM", 0));
  1830. switch (uGkiState)
  1831. {
  1832. case STATE_REGISTERING:
  1833. uGkiState = STATE_REGISTERED;
  1834. ApplyToAllCalls(CheckPendingOpen);
  1835. break;
  1836. case STATE_REGISTERING_REREG:
  1837. uGkiState = STATE_REGISTERED;
  1838. GkiRegister();
  1839. break;
  1840. case STATE_REGISTERING_UNREG:
  1841. uGkiState = STATE_REGISTERED;
  1842. GkiUnregister();
  1843. break;
  1844. default:
  1845. GKDBG((1, StateName("GkiWndProc: GKI_REG_CONFIRM in state %s", uGkiState), 0));
  1846. } // switch
  1847. break;
  1848. case GKIMAN_BASE + GKI_REG_DISCOVERY:
  1849. GKDBG((1, "GkiWndProc: GKI_REG_DISCOVERY", 0));
  1850. ASSERT(uGkiState == STATE_REGISTERING || uGkiState == STATE_REGISTERING_REREG || uGkiState == STATE_REGISTERING_UNREG);
  1851. break;
  1852. case GKIMAN_BASE + GKI_REG_REJECT:
  1853. GKDBG((1, "GkiWndProc: GKI_REG_REJECT Reason = %d", wParam));
  1854. switch (uGkiState)
  1855. {
  1856. case STATE_REGISTERING:
  1857. ApplyToAllCalls(GkiCancelCall);
  1858. EnterCriticalSection(&GkiLock);
  1859. while (pListenList)
  1860. {
  1861. register PLISTEN pListen = pListenList;
  1862. pListenList = pListen->pNext;
  1863. LeaveCriticalSection(&GkiLock);
  1864. ListenReject(pListen->hListen, MapRegistrationRejectReason(wParam));
  1865. if (pListen->pAliasNames)
  1866. {
  1867. FreeAliasNames(pListen->pAliasNames);
  1868. }
  1869. Free(pListen);
  1870. EnterCriticalSection(&GkiLock);
  1871. }
  1872. LeaveCriticalSection(&GkiLock);
  1873. uGkiState = STATE_WINDOW_CREATED;
  1874. break;
  1875. case STATE_REGISTERING_REREG:
  1876. uGkiState = STATE_WINDOW_CREATED;
  1877. GkiRegister();
  1878. break;
  1879. case STATE_REGISTERING_UNREG:
  1880. uGkiState = STATE_WINDOW_CREATED;
  1881. GkiUnregister();
  1882. break;
  1883. default:
  1884. GKDBG((1, StateName("GkiWndProc: GKI_REG_REJECT in state %s", uGkiState), 0));
  1885. } // switch
  1886. break;
  1887. case GKIMAN_BASE + GKI_REG_BYPASS:
  1888. GKDBG((1, "GkiWndProc: GKI_REG_BYPASS", 0));
  1889. switch (uGkiState)
  1890. {
  1891. case STATE_REGISTERING:
  1892. case STATE_REGISTERING_REREG:
  1893. uGkiState = STATE_REG_BYPASS;
  1894. ApplyToAllCalls(CheckPendingOpen);
  1895. break;
  1896. case STATE_REGISTERING_UNREG:
  1897. uGkiState = STATE_WINDOW_CREATED;
  1898. GkiUnregister();
  1899. break;
  1900. default:
  1901. GKDBG((1, StateName("GkiWndProc: GKI_REG_BYPASS in state %s", uGkiState), 0));
  1902. } // switch
  1903. break;
  1904. case GKIMAN_BASE + GKI_UNREG_CONFIRM:
  1905. GKDBG((1, "GkiWndProc: GKI_UNREG_CONFIRM", 0));
  1906. switch (uGkiState)
  1907. {
  1908. case STATE_REGISTERING:
  1909. case STATE_REGISTERING_REREG:
  1910. case STATE_REGISTERED:
  1911. case STATE_ADMITTING:
  1912. case STATE_ADMITTING_REREG:
  1913. case STATE_DISENGAGING_REREG:
  1914. case STATE_UNREGISTERING_REREG:
  1915. uGkiState = STATE_WINDOW_CREATED;
  1916. GkiRegister();
  1917. break;
  1918. default:
  1919. GKDBG((1, StateName("GkiWndProc: GKI_UNREG_CONFIRM in state %s", uGkiState), 0));
  1920. // Fall through to next case
  1921. case STATE_ADMITTING_UNREG:
  1922. case STATE_DISENGAGING:
  1923. ApplyToAllCalls(GkiCancelCall);
  1924. // Fall-through to next case
  1925. case STATE_REGISTERING_UNREG:
  1926. case STATE_UNREGISTERING:
  1927. uGkiState = STATE_WINDOW_CREATED;
  1928. // Fall-through to next case
  1929. case STATE_CLASS_REGISTERED:
  1930. case STATE_WINDOW_CREATED:
  1931. // Fall-through to next case
  1932. case STATE_START:
  1933. case STATE_REG_BYPASS:
  1934. break;
  1935. } // switch
  1936. break;
  1937. case GKIMAN_BASE + GKI_UNREG_REJECT:
  1938. GKDBG((1, "GkiWndProc: GKI_UNREG_REJECT Reason = %d", wParam));
  1939. switch (uGkiState)
  1940. {
  1941. case STATE_UNREGISTERING:
  1942. uGkiState = STATE_WINDOW_CREATED;
  1943. GkiUnregister();
  1944. break;
  1945. case STATE_UNREGISTERING_REREG:
  1946. uGkiState = STATE_WINDOW_CREATED;
  1947. GkiRegister();
  1948. break;
  1949. default:
  1950. GKDBG((1, StateName("GkiWndProc: GKI_UNREG_REJECT in state %s", uGkiState), 0));
  1951. } // switch
  1952. break;
  1953. case GKIMAN_BASE + GKI_ADM_CONFIRM:
  1954. GKDBG((1, "GkiWndProc: GKI_ADM_CONFIRM", 0));
  1955. switch (uGkiState)
  1956. {
  1957. case STATE_ADMITTING:
  1958. uGkiState = STATE_REGISTERED;
  1959. pCallReturnInfo = (CallReturnInfo *) lParam;
  1960. if (LockGkiCallAndConference(GKI_ADMITTING_HANDLE, &pGkiCall, &pConference, &hCall, &hConference) == NOERROR)
  1961. {
  1962. GKDBG((1, CallStateName("GkiWndProc: Call State = %s", pGkiCall->uGkiCallState), 0));
  1963. pGkiCall->usCallModelChoice = pCallReturnInfo->callModel.choice;
  1964. pGkiCall->uBandwidthAllocated = pCallReturnInfo->bandWidth;
  1965. pGkiCall->usCRV = pCallReturnInfo->callReferenceValue;
  1966. memcpy(pGkiCall->pConferenceId, pCallReturnInfo->conferenceID.value, 16);
  1967. switch (pGkiCall->uGkiCallState)
  1968. {
  1969. case GCS_ADMITTING:
  1970. GkiAllocCall(pGkiCall, pCallReturnInfo->hCall);
  1971. if (pGkiCall->bAnswerCall)
  1972. {
  1973. status = AcceptCallConfirm(pGkiCall->pCall, pConference);
  1974. }
  1975. else
  1976. {
  1977. ASSERT(pCallReturnInfo->destCallSignalAddress.choice == ipAddress_chosen);
  1978. pGkiCall->dwIpAddress = *((DWORD *)pCallReturnInfo->destCallSignalAddress.u.ipAddress.ip.value);
  1979. pGkiCall->dwIpAddress = pGkiCall->dwIpAddress;
  1980. pGkiCall->wPort = pCallReturnInfo->destCallSignalAddress.u.ipAddress.port;
  1981. status = PlaceCallConfirm(pGkiCall->pCall, pConference);
  1982. }
  1983. if (status == NOERROR && ValidateCall(hCall) == NOERROR)
  1984. CheckPendingBandwidth(pGkiCall);
  1985. break;
  1986. case GCS_ADMITTING_CLOSE_PENDING:
  1987. GkiAllocCall(pGkiCall, pCallReturnInfo->hCall);
  1988. GkiCloseCall(pGkiCall);
  1989. break;
  1990. default:
  1991. GKDBG((1, CallStateName("GkiWndProc: GKI_ADM_CONFIRM in call state %s", pGkiCall->uGkiCallState), 0));
  1992. } // switch
  1993. UnlockGkiCallAndConference(pGkiCall, pConference, hCall, hConference);
  1994. } // if
  1995. else
  1996. {
  1997. GKDBG((1, "GkiWndProc: GKI_ADM_CONFIRM handle not found", 0));
  1998. }
  1999. ApplyToAllCalls(CheckPendingOpen);
  2000. break;
  2001. case STATE_ADMITTING_UNREG:
  2002. uGkiState = STATE_REGISTERED;
  2003. GkiUnregister();
  2004. break;
  2005. default:
  2006. GKDBG((1, StateName("GkiWndProc: GKI_ADM_CONFIRM in state %s", uGkiState), 0));
  2007. } // switch
  2008. break;
  2009. case GKIMAN_BASE + GKI_ADM_REJECT:
  2010. GKDBG((1, "GkiWndProc: GKI_ADM_REJECT Reason = %d", wParam));
  2011. switch (uGkiState)
  2012. {
  2013. case STATE_ADMITTING:
  2014. pCallReturnInfo = (CallReturnInfo *) lParam;
  2015. if (LockGkiCallAndConference(GKI_ADMITTING_HANDLE, &pGkiCall, &pConference, &hCall, &hConference) == NOERROR)
  2016. {
  2017. ASSERT(pGkiCall->uGkiCallState == GCS_ADMITTING);
  2018. switch (wParam)
  2019. {
  2020. case calledPartyNotRegistered_chosen:
  2021. if (pGkiCall->bAnswerCall)
  2022. {
  2023. // The gateway has gone away and come back without our notice!
  2024. GkiCancelAdmitting(pGkiCall, pConference);
  2025. uGkiState = STATE_REGISTERED;
  2026. GkiRegister();
  2027. GKDBG((1, StateName("GkiWndProc -> State = %s", uGkiState), 0));
  2028. LeaveCallControlTop(0);
  2029. }
  2030. break;
  2031. case callerNotRegistered_chosen:
  2032. if (pGkiCall->bAnswerCall == FALSE)
  2033. {
  2034. // The gateway has gone away and come back without our notice!
  2035. GkiCancelAdmitting(pGkiCall, pConference);
  2036. uGkiState = STATE_REGISTERED;
  2037. GkiRegister();
  2038. GKDBG((1, StateName("GkiWndProc -> State = %s", uGkiState), 0));
  2039. LeaveCallControlTop(0);
  2040. }
  2041. } // switch
  2042. GkiFreeCall(pGkiCall);
  2043. if (pGkiCall->bAnswerCall)
  2044. AcceptCallReject(pGkiCall->pCall, pConference, MapAdmissionRejectReason(wParam));
  2045. else
  2046. PlaceCallReject (pGkiCall->pCall, pConference, MapAdmissionRejectReason(wParam));
  2047. UnlockGkiCallAndConference(pGkiCall, pConference, hCall, hConference);
  2048. } // if
  2049. else
  2050. {
  2051. GKDBG((1, "GkiWndProc: GKI_ADM_REJECT handle not found", 0));
  2052. }
  2053. uGkiState = STATE_REGISTERED;
  2054. ApplyToAllCalls(CheckPendingOpen);
  2055. break;
  2056. case STATE_ADMITTING_REREG:
  2057. pCallReturnInfo = (CallReturnInfo *) lParam;
  2058. if (LockGkiCallAndConference(GKI_ADMITTING_HANDLE, &pGkiCall, &pConference, &hCall, &hConference) == NOERROR)
  2059. {
  2060. ASSERT(pGkiCall->uGkiCallState == GCS_ADMITTING_CLOSE_PENDING);
  2061. GkiFreeCall(pGkiCall);
  2062. if (pGkiCall->bAnswerCall)
  2063. {
  2064. AcceptCallReject(pGkiCall->pCall, pConference, MapAdmissionRejectReason(wParam));
  2065. }
  2066. else
  2067. {
  2068. PlaceCallReject (pGkiCall->pCall, pConference, MapAdmissionRejectReason(wParam));
  2069. }
  2070. UnlockGkiCallAndConference(pGkiCall, pConference, hCall, hConference);
  2071. } // if
  2072. else
  2073. {
  2074. GKDBG((1, "GkiWndProc: GKI_ADM_REJECT handle not found", 0));
  2075. }
  2076. uGkiState = STATE_REGISTERED;
  2077. GkiRegister();
  2078. break;
  2079. case STATE_ADMITTING_UNREG:
  2080. pCallReturnInfo = (CallReturnInfo *) lParam;
  2081. if (LockGkiCallAndConference(GKI_ADMITTING_HANDLE, &pGkiCall, &pConference, &hCall, &hConference) == NOERROR)
  2082. {
  2083. ASSERT(pGkiCall->uGkiCallState == GCS_ADMITTING_CLOSE_PENDING);
  2084. GkiFreeCall(pGkiCall);
  2085. if (pGkiCall->bAnswerCall)
  2086. {
  2087. AcceptCallReject(pGkiCall->pCall, pConference, MapAdmissionRejectReason(wParam));
  2088. }
  2089. else
  2090. {
  2091. PlaceCallReject (pGkiCall->pCall, pConference, MapAdmissionRejectReason(wParam));
  2092. }
  2093. UnlockGkiCallAndConference(pGkiCall, pConference, hCall, hConference);
  2094. } // if
  2095. else
  2096. {
  2097. GKDBG((1, "GkiWndProc: GKI_ADM_REJECT handle not found", 0));
  2098. }
  2099. uGkiState = STATE_REGISTERED;
  2100. GkiUnregister();
  2101. break;
  2102. default:
  2103. GKDBG((1, StateName("GkiWndProc: GKI_ADM_REJECT in state %s", uGkiState), 0));
  2104. } // switch
  2105. break;
  2106. case GKIMAN_BASE + GKI_BW_CONFIRM:
  2107. GKDBG((1, "GkiWndProc: GKI_BW_CONFIRM", 0));
  2108. switch (uGkiState)
  2109. {
  2110. case STATE_REGISTERED:
  2111. pCallReturnInfo = (CallReturnInfo *) lParam;
  2112. if (LockGkiCallAndConference(pCallReturnInfo->hCall, &pGkiCall, &pConference, &hCall, &hConference) == NOERROR)
  2113. {
  2114. GKDBG((1, CallStateName("GkiWndProc: Call State = %s", pGkiCall->uGkiCallState), 0));
  2115. pGkiCall->uBandwidthAllocated = pCallReturnInfo->bandWidth;
  2116. switch (pGkiCall->uGkiCallState)
  2117. {
  2118. case GCS_ADMITTED:
  2119. if (pGkiCall->uBandwidthUsed < pGkiCall->uBandwidthAllocated)
  2120. {
  2121. BandwidthShrunk(pGkiCall->pCall,
  2122. pConference,
  2123. pGkiCall->uBandwidthAllocated,
  2124. ((long)pGkiCall->uBandwidthAllocated) - ((long)pGkiCall->uBandwidthUsed));
  2125. }
  2126. break;
  2127. case GCS_CHANGING:
  2128. pGkiCall->uGkiCallState = GCS_ADMITTED;
  2129. CheckPendingBandwidth(pGkiCall);
  2130. break;
  2131. case GCS_CHANGING_CLOSE_PENDING:
  2132. pGkiCall->uGkiCallState = GCS_ADMITTED;
  2133. GkiCloseCall(pGkiCall);
  2134. break;
  2135. default:
  2136. GKDBG((1, CallStateName("GkiWndProc: GKI_BW_CONFIRM in call state %s", pGkiCall->uGkiCallState), 0));
  2137. } // switch
  2138. UnlockGkiCallAndConference(pGkiCall, pConference, hCall, hConference);
  2139. } // if
  2140. else
  2141. {
  2142. GKDBG((1, "GkiWndProc: GKI_BW_CONFIRM handle not found", 0));
  2143. } // else
  2144. break;
  2145. default:
  2146. GKDBG((1, StateName("GkiWndProc: GKI_BW_CONFIRM in GKI state %s", uGkiState), 0));
  2147. } // switch
  2148. break;
  2149. case GKIMAN_BASE + GKI_BW_REJECT:
  2150. GKDBG((1, "GkiWndProc: GKI_BW_REJECT Reason = %d", wParam));
  2151. switch (uGkiState)
  2152. {
  2153. case STATE_REGISTERED:
  2154. pCallReturnInfo = (CallReturnInfo *) lParam;
  2155. if (LockGkiCallAndConference(pCallReturnInfo->hCall, &pGkiCall, &pConference, &hCall, &hConference) == NOERROR)
  2156. {
  2157. GKDBG((1, CallStateName("GkiWndProc: Call State = %s", pGkiCall->uGkiCallState), 0));
  2158. pGkiCall->uBandwidthAllocated = pCallReturnInfo->bandWidth;
  2159. switch (pGkiCall->uGkiCallState)
  2160. {
  2161. case GCS_CHANGING:
  2162. pGkiCall->uGkiCallState = GCS_ADMITTED;
  2163. BandwidthRejected(pGkiCall, wParam);
  2164. if (ValidateCall(hCall) == NOERROR)
  2165. {
  2166. CheckPendingBandwidth(pGkiCall);
  2167. }
  2168. break;
  2169. case GCS_CHANGING_CLOSE_PENDING:
  2170. pGkiCall->uGkiCallState = GCS_ADMITTED;
  2171. GkiCloseCall(pGkiCall);
  2172. break;
  2173. default:
  2174. GKDBG((1, CallStateName("GkiWndProc: GKI_BW_REJECT in state %s", pGkiCall->uGkiCallState), 0));
  2175. } // switch
  2176. UnlockGkiCallAndConference(pGkiCall, pConference, hCall, hConference);
  2177. } // if
  2178. else
  2179. {
  2180. GKDBG((1, "GkiWndProc: GKI_BW_REJECT handle not found", 0));
  2181. }
  2182. break;
  2183. default:
  2184. GKDBG((1, StateName("GkiWndProc: GKI_BW_REJECT in state %s", uGkiState), 0));
  2185. } // switch
  2186. break;
  2187. case GKIMAN_BASE + GKI_DISENG_CONFIRM:
  2188. GKDBG((1, "GkiWndProc: GKI_DISENG_CONFIRM", 0));
  2189. if (LockGkiCall((HANDLE)lParam, &pGkiCall) == NOERROR)
  2190. {
  2191. GKDBG((1, CallStateName("GkiWndProc: Call State = %s", pGkiCall->uGkiCallState), 0));
  2192. switch (pGkiCall->uGkiCallState)
  2193. {
  2194. case GCS_DISENGAGING:
  2195. --uPendingDisengages;
  2196. break;
  2197. default:
  2198. GKDBG((1, CallStateName("GkiWndProc: GKI_DISENG_CONFIRM in call state %s", pGkiCall->uGkiCallState), 0));
  2199. } // switch
  2200. GkiFreeCall(pGkiCall);
  2201. Disengage(pGkiCall->pCall);
  2202. } // if
  2203. else if (uPendingDisengages != 0)
  2204. {
  2205. --uPendingDisengages;
  2206. if (uPendingDisengages == 0)
  2207. {
  2208. switch (uGkiState)
  2209. {
  2210. case STATE_DISENGAGING:
  2211. uGkiState = STATE_REGISTERED;
  2212. GkiUnregister();
  2213. break;
  2214. case STATE_DISENGAGING_REREG:
  2215. uGkiState = STATE_REGISTERED;
  2216. GkiRegister();
  2217. break;
  2218. } // switch
  2219. if (pListenList && pListenList->hListen == DEFAULT_LISTEN_HANDLE)
  2220. {
  2221. GkiCloseListen(DEFAULT_LISTEN_HANDLE);
  2222. }
  2223. } // if
  2224. } // else if
  2225. else
  2226. {
  2227. GKDBG((1, "GkiWndProc: GKI_DISENG_CONFIRM handle not found", 0));
  2228. }
  2229. break;
  2230. case GKIMAN_BASE + GKI_DISENG_REJECT:
  2231. GKDBG((1, "GkiWndProc: GKI_DISENG_REJECT Reason = %d", wParam));
  2232. if (LockGkiCall((HANDLE)lParam, &pGkiCall) == NOERROR)
  2233. {
  2234. GKDBG((1, CallStateName("GkiWndProc: Call State = %s", pGkiCall->uGkiCallState), 0));
  2235. switch (pGkiCall->uGkiCallState)
  2236. {
  2237. case GCS_DISENGAGING:
  2238. // Pretend we received a Disengage Confirm
  2239. --uPendingDisengages;
  2240. break;
  2241. default:
  2242. GKDBG((1, CallStateName("GkiWndProc: GKI_DISENG_REJECT in call state %s", pGkiCall->uGkiCallState), 0));
  2243. } // switch
  2244. GkiFreeCall(pGkiCall);
  2245. Disengage(pGkiCall->pCall);
  2246. } // if
  2247. else if (uPendingDisengages != 0)
  2248. {
  2249. // Pretend we received a Disengage Confirm
  2250. --uPendingDisengages;
  2251. if (uPendingDisengages == 0)
  2252. {
  2253. switch (uGkiState)
  2254. {
  2255. case STATE_DISENGAGING:
  2256. uGkiState = STATE_REGISTERED;
  2257. GkiUnregister();
  2258. break;
  2259. case STATE_DISENGAGING_REREG:
  2260. uGkiState = STATE_REGISTERED;
  2261. GkiRegister();
  2262. break;
  2263. } // switch
  2264. if (pListenList && pListenList->hListen == DEFAULT_LISTEN_HANDLE)
  2265. {
  2266. GkiCloseListen(DEFAULT_LISTEN_HANDLE);
  2267. }
  2268. } // if
  2269. } // else if
  2270. else
  2271. {
  2272. GKDBG((1, "GkiWndProc: GKI_DISENG_REJECT handle not found", 0));
  2273. }
  2274. break;
  2275. case GKIMAN_BASE + GKI_LOCATION_CONFIRM:
  2276. GKDBG((1, "GkiWndProc: GKI_LOCATION_CONFIRM", 0));
  2277. break;
  2278. case GKIMAN_BASE + GKI_LOCATION_REJECT:
  2279. GKDBG((1, "GkiWndProc: GKI_LOCATION_REJECT Reason = %d", wParam));
  2280. break;
  2281. case GKIMAN_BASE + GKI_ERROR:
  2282. GKDBG((1, GkiErrorName("GkiWndProc: GKI_ERROR %s %%d", lParam), wParam));
  2283. switch (lParam)
  2284. {
  2285. case GKI_NO_RESPONSE:
  2286. LastGkiError = lParam;
  2287. GkiNoResponse(hWnd);
  2288. break;
  2289. #if 1
  2290. // TEMPORARY KLUDGE FOR WINSOCK 2 BETA 1.6 OPERATION
  2291. case MAKE_CUSTOM_HRESULT(SEVERITY_ERROR,1,FACILITY_WINSOCK,0xffff):
  2292. uGkiState = STATE_REG_BYPASS;
  2293. ApplyToAllCalls(CheckPendingOpen);
  2294. break;
  2295. #endif
  2296. default:
  2297. LastGkiError = lParam;
  2298. GkiUnregister();
  2299. } // switch
  2300. break;
  2301. default:
  2302. GKDBG((1, "Unknown message %d", message));
  2303. } // switch
  2304. GKDBG((1, StateName("GkiWndProc -> State = %s", uGkiState), 0));
  2305. LeaveCallControlTop(0);
  2306. } // GkiWndProc()
  2307. #if defined(DBG)
  2308. DWORD g_dwH225DbgLevel = 0;
  2309. BOOL g_fInitialized = FALSE;
  2310. void GKDbgInit() {
  2311. #define H323_REGKEY_ROOT \
  2312. TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\H323TSP")
  2313. #define H323_REGVAL_DEBUGLEVEL \
  2314. TEXT("DebugLevel")
  2315. #define H323_REGVAL_H225DEBUGLEVEL \
  2316. TEXT("H225DebugLevel")
  2317. HKEY hKey;
  2318. LONG lStatus;
  2319. DWORD dwValue;
  2320. DWORD dwValueSize;
  2321. DWORD dwValueType;
  2322. LPSTR pszValue;
  2323. LPSTR pszKey = H323_REGKEY_ROOT;
  2324. // only call this once
  2325. g_fInitialized = TRUE;
  2326. // open registry subkey
  2327. lStatus = RegOpenKeyEx(
  2328. HKEY_LOCAL_MACHINE,
  2329. pszKey,
  2330. 0,
  2331. KEY_READ,
  2332. &hKey
  2333. );
  2334. // validate return code
  2335. if (lStatus != ERROR_SUCCESS) {
  2336. return; // bail...
  2337. }
  2338. // initialize values
  2339. dwValueType = REG_DWORD;
  2340. dwValueSize = sizeof(DWORD);
  2341. // retrieve ras debug level
  2342. pszValue = H323_REGVAL_H225DEBUGLEVEL;
  2343. // query for registry value
  2344. lStatus = RegQueryValueEx(
  2345. hKey,
  2346. pszValue,
  2347. NULL,
  2348. &dwValueType,
  2349. (LPBYTE)&dwValue,
  2350. &dwValueSize
  2351. );
  2352. // validate return code
  2353. if (lStatus != ERROR_SUCCESS) {
  2354. // initialize values
  2355. dwValueType = REG_DWORD;
  2356. dwValueSize = sizeof(DWORD);
  2357. // retrieve tsp debug level
  2358. pszValue = H323_REGVAL_DEBUGLEVEL;
  2359. // query for registry value
  2360. lStatus = RegQueryValueEx(
  2361. hKey,
  2362. pszValue,
  2363. NULL,
  2364. &dwValueType,
  2365. (LPBYTE)&dwValue,
  2366. &dwValueSize
  2367. );
  2368. }
  2369. // validate return code
  2370. if (lStatus == ERROR_SUCCESS) {
  2371. // update debug level
  2372. g_dwH225DbgLevel = dwValue;
  2373. }
  2374. // close key
  2375. RegCloseKey(hKey);
  2376. }
  2377. void GKDbgPrint(DWORD dwLevel,
  2378. #ifdef UNICODE_TRACE
  2379. LPTSTR pszFormat,
  2380. #else
  2381. LPSTR pszFormat,
  2382. #endif
  2383. ...)
  2384. {
  2385. #define DEBUG_FORMAT_HEADER "H225 "
  2386. #define DEBUG_FORMAT_TIMESTAMP "[%02u:%02u:%02u.%03u"
  2387. #define DEBUG_FORMAT_THREADID ",tid=%x] "
  2388. #define MAXDBG_STRLEN 512
  2389. va_list Args;
  2390. SYSTEMTIME SystemTime;
  2391. char szDebugMessage[MAXDBG_STRLEN+1];
  2392. int nLengthRemaining;
  2393. int nLength = 0;
  2394. // make sure initialized
  2395. if (g_fInitialized == FALSE) {
  2396. GKDbgInit();
  2397. }
  2398. // validate debug log level
  2399. if (dwLevel > g_dwH225DbgLevel) {
  2400. return; // bail...
  2401. }
  2402. // retrieve local time
  2403. GetLocalTime(&SystemTime);
  2404. // add component header to the debug message
  2405. nLength += sprintf(&szDebugMessage[nLength],
  2406. DEBUG_FORMAT_HEADER
  2407. );
  2408. // add timestamp to the debug message
  2409. nLength += sprintf(&szDebugMessage[nLength],
  2410. DEBUG_FORMAT_TIMESTAMP,
  2411. SystemTime.wHour,
  2412. SystemTime.wMinute,
  2413. SystemTime.wSecond,
  2414. SystemTime.wMilliseconds
  2415. );
  2416. // add thread id to the debug message
  2417. nLength += sprintf(&szDebugMessage[nLength],
  2418. DEBUG_FORMAT_THREADID,
  2419. GetCurrentThreadId()
  2420. );
  2421. // point at first argument
  2422. va_start(Args, pszFormat);
  2423. // determine number of bytes left in buffer
  2424. nLengthRemaining = sizeof(szDebugMessage) - nLength;
  2425. // add user specified debug message
  2426. _vsnprintf(&szDebugMessage[nLength],
  2427. nLengthRemaining,
  2428. pszFormat,
  2429. Args
  2430. );
  2431. // release pointer
  2432. va_end(Args);
  2433. // output message to specified sink
  2434. OutputDebugString(szDebugMessage);
  2435. OutputDebugString("\n");
  2436. }
  2437. #endif
  2438. #else // GATEKEEPER
  2439. static char ch; // Kludge around warning C4206: nonstandard extension used : translation unit is empty
  2440. #endif // GATEKEEPER