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.

2953 lines
86 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 $
  14. * $Date: 05 Mar 1997 14:30:26 $
  15. * $Author: SBELL1 $
  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. #include "precomp.h"
  35. #include "incommon.h"
  36. #include "ccerror.h"
  37. #include "isrg.h"
  38. #include "gkiexp.h"
  39. #include "callman2.h"
  40. #include "cclock.h"
  41. #include "iras.h"
  42. #include "bestintf.h"
  43. #pragma warning ( default : 4115 4201 4214)
  44. #ifdef FORCE_SERIALIZE_CALL_CONTROL
  45. #define EnterCallControlTop() {CCLOCK_AcquireLock();}
  46. #define LeaveCallControlTop(f) {HRESULT stat; \
  47. stat = f; \
  48. CCLOCK_RelinquishLock(); \
  49. return stat;}
  50. #else
  51. #define EnterCallControlTop()
  52. #define LeaveCallControlTop(f) {HRESULT stat; \
  53. stat = f; \
  54. return stat;}
  55. #endif
  56. #define GKIMAN_BASE WM_USER
  57. #define MIN_BANDWIDTH 1
  58. #define MAX_BANDWIDTH (0xFFFFFFFF / 100)
  59. #define GKI_ADMITTING_HANDLE ((HANDLE)-1)
  60. #define GKI_BYPASS_HANDLE ((HANDLE)-2)
  61. // GKI Manager state
  62. #define STATE_START 0
  63. #define STATE_CLASS_REGISTERED 1
  64. #define STATE_WINDOW_CREATED 2
  65. #define STATE_REGISTERING 3
  66. #define STATE_REGISTERING_REREG 4
  67. #define STATE_REGISTERING_UNREG 5
  68. #define STATE_REGISTERED 6
  69. #define STATE_ADMITTING 7
  70. #define STATE_ADMITTING_REREG 8
  71. #define STATE_ADMITTING_UNREG 9
  72. #define STATE_DISENGAGING 10
  73. #define STATE_DISENGAGING_REREG 11
  74. #define STATE_UNREGISTERING 12
  75. #define STATE_UNREGISTERING_REREG 13
  76. #define STATE_REG_BYPASS 14
  77. typedef HRESULT (*PGKI_RegistrationRequest)(long lVersion,
  78. SeqTransportAddr *pCallSignalAddr,
  79. EndpointType *pTerminalType,
  80. SeqAliasAddr *pAliasAddr,
  81. PCC_VENDORINFO pVendorInfo,
  82. HWND hWnd,
  83. WORD wBaseMessage,
  84. unsigned short usRegistrationTransport /* = ipAddress_chosen */);
  85. typedef HRESULT (*PGKI_UnregistrationRequest)(void);
  86. typedef HRESULT (*PGKI_LocationRequest)(SeqAliasAddr *pLocationInfo);
  87. typedef HRESULT (*PGKI_AdmissionRequest)(unsigned short usCallTypeChoice,
  88. SeqAliasAddr *pDestinationInfo,
  89. TransportAddress *pDestCallSignalAddress,
  90. SeqAliasAddr *pDextExtraCallInfo,
  91. LPGUID pCallIdentifier,
  92. BandWidth bandWidth,
  93. ConferenceIdentifier *pConferenceID,
  94. BOOL activeMC,
  95. BOOL answerCall,
  96. unsigned short usCallTransport /* = ipAddress_chosen */);
  97. typedef HRESULT (*PGKI_BandwidthRequest)(HANDLE hModCall,
  98. unsigned short usCallTypeChoice,
  99. BandWidth bandWidth);
  100. typedef HRESULT (*PGKI_DisengageRequest)(HANDLE hCall);
  101. typedef HRESULT (*PGKI_Initialize)(void);
  102. typedef HRESULT (*PGKI_CleanupRequest)(void);
  103. HRESULT Q931CopyAliasNames(PCC_ALIASNAMES *ppTarget, PCC_ALIASNAMES pSource);
  104. HRESULT Q931FreeAliasNames(PCC_ALIASNAMES pSource);
  105. #define CopyAliasNames Q931CopyAliasNames
  106. #define FreeAliasNames Q931FreeAliasNames
  107. HRESULT CopyVendorInfo( PCC_VENDORINFO *ppDest,
  108. PCC_VENDORINFO pSource);
  109. HRESULT FreeVendorInfo( PCC_VENDORINFO pVendorInfo);
  110. typedef struct _LISTEN
  111. {
  112. struct _LISTEN * pNext;
  113. PCC_ALIASNAMES pAliasNames;
  114. CC_HLISTEN hListen;
  115. DWORD dwAddr;
  116. WORD wPort;
  117. } LISTEN, *PLISTEN;
  118. //
  119. // GKI Manager Global Data
  120. //
  121. CRITICAL_SECTION GkiLock;
  122. const char szClassName[] = "GkiManWndClass";
  123. HWND hwndGki = 0;
  124. ATOM atomGki = 0;
  125. unsigned int uGkiState = STATE_START;
  126. PLISTEN pListenList = NULL;
  127. unsigned int uGkiCalls = 0;
  128. unsigned int uPendingDisengages = 0;
  129. BOOL fGKConfigured = FALSE;
  130. BOOL fGKEnabled = FALSE;
  131. PCC_ALIASNAMES gpLocalAliasNames = NULL;
  132. PCC_VENDORINFO gpVendorInfo = NULL;
  133. DWORD g_dwMultipointConfiguration = 0;
  134. RASNOTIFYPROC gpRasNotifyProc = NULL;
  135. // HINSTANCE hGkiDll = 0;
  136. PGKI_RegistrationRequest pGKI_RegistrationRequest = NULL;
  137. PGKI_UnregistrationRequest pGKI_UnregistrationRequest = NULL;
  138. PGKI_LocationRequest pGKI_LocationRequest = NULL;
  139. PGKI_AdmissionRequest pGKI_AdmissionRequest = NULL;
  140. PGKI_BandwidthRequest pGKI_BandwidthRequest = NULL;
  141. PGKI_DisengageRequest pGKI_DisengageRequest = NULL;
  142. PGKI_CleanupRequest pGKI_CleanupRequest = NULL;
  143. PGKI_Initialize pGKI_Initialize = NULL;
  144. HRESULT ValidateCall(CC_HCALL hCall);
  145. HRESULT LastGkiError = CC_GKI_STATE;
  146. //
  147. // Forward declarations
  148. //
  149. LRESULT APIENTRY GkiWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
  150. //
  151. // Helper subroutines
  152. //
  153. #ifdef _DEBUG
  154. typedef struct _GKIMAP
  155. {
  156. HRESULT hResult;
  157. char * pString;
  158. } GKIMAP;
  159. GKIMAP GkiErrorNames[] =
  160. {
  161. GKI_OK, "GKI_OK",
  162. GKI_EXIT_THREAD, "GKI_EXIT_THREAD",
  163. GKI_REDISCOVER, "GKI_REDISCOVER",
  164. GKI_DELETE_CALL, "GKI_DELETE_CALL",
  165. GKI_GCF_RCV, "GKI_GCF_RCV",
  166. GKI_NO_MEMORY, "GKI_NO_MEMORY",
  167. GKI_NO_THREAD, "GKI_NO_THREAD",
  168. GKI_HANDLE_ERROR, "GKI_HANDLE_ERROR",
  169. GKI_ALREADY_REG, "GKI_ALREADY_REG",
  170. GKI_VERSION_ERROR, "GKI_VERSION_ERROR",
  171. GKI_ENCODER_ERROR, "GKI_ENCODER_ERROR",
  172. GKI_NOT_REG, "GKI_NOT_REG",
  173. GKI_BUSY, "GKI_BUSY",
  174. GKI_NO_TA_ERROR, "GKI_NO_TA_ERROR",
  175. GKI_NO_RESPONSE, "GKI_NO_RESPONSE",
  176. GKI_DECODER_ERROR, "GKI_DECODER_ERROR",
  177. };
  178. char *StateNames[] =
  179. {
  180. "STATE_START",
  181. "STATE_CLASS_REGISTERED",
  182. "STATE_WINDOW_CREATED",
  183. "STATE_REGISTERING",
  184. "STATE_REGISTERING_REREG",
  185. "STATE_REGISTERING_UNREG",
  186. "STATE_REGISTERED",
  187. "STATE_ADMITTING",
  188. "STATE_ADMITTING_REREG",
  189. "STATE_ADMITTING_UNREG",
  190. "STATE_DISENGAGING",
  191. "STATE_DISENGAGING_REREG",
  192. "STATE_UNREGISTERING",
  193. "STATE_UNREGISTERING_REREG",
  194. "STATE_REG_BYPASS",
  195. };
  196. char *CallStateNames[] =
  197. {
  198. "GCS_START",
  199. "GCS_WAITING",
  200. "GCS_ADMITTING",
  201. "GCS_ADMITTING_CLOSE_PENDING",
  202. "GCS_ADMITTED",
  203. "GCS_CHANGING",
  204. "GCS_CHANGING_CLOSE_PENDING",
  205. "GCS_DISENGAGING",
  206. };
  207. char szBuffer[128];
  208. char * GkiErrorName(char *szFormat, HRESULT hResult)
  209. {
  210. register int nIndex = sizeof(GkiErrorNames) / sizeof(GkiErrorNames[0]);
  211. char szTemp[32];
  212. while (nIndex > 0)
  213. {
  214. if (GkiErrorNames[--nIndex].hResult == hResult)
  215. {
  216. wsprintf(szBuffer, szFormat, GkiErrorNames[nIndex].pString);
  217. return szBuffer;
  218. }
  219. }
  220. wsprintf(szTemp, "Unknown(0x%x)", hResult);
  221. wsprintf(szBuffer, szFormat, szTemp);
  222. return szBuffer;
  223. } // GkiErrorName()
  224. char * StateName(char *szFormat, unsigned uState)
  225. {
  226. char szTemp[32];
  227. if (uState < (sizeof(StateNames)/sizeof(StateNames[0])))
  228. {
  229. wsprintf(szBuffer, szFormat, StateNames[uState]);
  230. }
  231. else
  232. {
  233. wsprintf(szTemp, "Unknown(%d)", uState);
  234. wsprintf(szBuffer, szFormat, szTemp);
  235. }
  236. return szBuffer;
  237. } // StateName()
  238. char * CallStateName(char *szFormat, unsigned uCallState)
  239. {
  240. char szTemp[32];
  241. if (uCallState <= (sizeof(CallStateNames)/sizeof(CallStateNames[0])))
  242. {
  243. wsprintf(szBuffer, szFormat, CallStateNames[uCallState]);
  244. }
  245. else
  246. {
  247. wsprintf(szTemp, "Unknown(%d)", uCallState);
  248. wsprintf(szBuffer, szFormat, szTemp);
  249. }
  250. return szBuffer;
  251. } // CallStateName()
  252. #else
  253. #define GkiErrorName(x,y) ""
  254. #define StateName(x,y) ""
  255. #define CallStateName(x,y) ""
  256. #endif // _DEBUG
  257. HRESULT MapRegistrationRejectReason(UINT uReason)
  258. {
  259. #if(0) // this must have been coded by the department of redundancy department
  260. register HRESULT lReason;
  261. // TBD - Map reason code into CC_xxx HRESULT
  262. switch (uReason)
  263. {
  264. case discoveryRequired_chosen:
  265. lReason = CC_GATEKEEPER_REFUSED;
  266. break;
  267. case RgstrtnRjctRsn_invldRvsn_chosen:
  268. lReason = CC_GATEKEEPER_REFUSED;
  269. break;
  270. case invalidCallSignalAddress_chosen:
  271. lReason = CC_GATEKEEPER_REFUSED;
  272. break;
  273. case invalidRASAddress_chosen:
  274. lReason = CC_GATEKEEPER_REFUSED;
  275. break;
  276. case duplicateAlias_chosen:
  277. lReason = CC_GATEKEEPER_REFUSED;
  278. break;
  279. case invalidTerminalType_chosen:
  280. lReason = CC_GATEKEEPER_REFUSED;
  281. break;
  282. case RgstrtnRjctRsn_undfndRsn_chosen:
  283. lReason = CC_GATEKEEPER_REFUSED;
  284. break;
  285. case transportNotSupported_chosen:
  286. lReason = CC_GATEKEEPER_REFUSED;
  287. break;
  288. default:
  289. lReason = CC_GATEKEEPER_REFUSED;
  290. } // switch
  291. return lReason;
  292. #else
  293. return (MAKE_CUSTOM_HRESULT(SEVERITY_ERROR, TRUE, FACILITY_GKIREGISTRATION, (LOWORD(uReason))));
  294. #endif
  295. } // MapRegistrationRejectReason()
  296. HRESULT MapUnregistrationRequestReason(UINT uReason)
  297. {
  298. HRESULT lReason;
  299. lReason = MAKE_CUSTOM_HRESULT(SEVERITY_ERROR,1,FACILITY_GKIUNREGREQ, ERROR_LOCAL_BASE_ID + (LOWORD(uReason)));
  300. return lReason;
  301. }
  302. HRESULT MapAdmissionRejectReason(register UINT uReason)
  303. {
  304. register HRESULT lReason;
  305. #if(0)
  306. // TBD - Map reason code into CC_xxx HRESULT
  307. switch (uReason)
  308. {
  309. case AdmissionRejectReason_calledPartyNotRegistered_chosen:
  310. lReason = CC_GATEKEEPER_REFUSED;
  311. break;
  312. case ARRn_invldPrmssn_chosen:
  313. lReason = CC_GATEKEEPER_REFUSED;
  314. break;
  315. case AdmssnRjctRsn_rqstDnd_chosen:
  316. lReason = CC_GATEKEEPER_REFUSED;
  317. break;
  318. case AdmssnRjctRsn_undfndRsn_chosen:
  319. lReason = CC_GATEKEEPER_REFUSED;
  320. break;
  321. case AdmissionRejectReason_callerNotRegistered_chosen:
  322. lReason = CC_GATEKEEPER_REFUSED;
  323. break;
  324. case AdmissionRejectReason_routeCallToGatekeeper_chosen:
  325. lReason = CC_GATEKEEPER_REFUSED;
  326. break;
  327. case invldEndpntIdntfr_chosen:
  328. lReason = CC_GATEKEEPER_REFUSED;
  329. break;
  330. case AdmssnRjctRsn_rsrcUnvlbl_chosen:
  331. lReason = CC_GATEKEEPER_REFUSED;
  332. break;
  333. default:
  334. lReason = CC_GATEKEEPER_REFUSED;
  335. } // switch
  336. #else// last 8 bits are the reason code
  337. lReason = MAKE_CUSTOM_HRESULT(SEVERITY_ERROR,1,FACILITY_GKIADMISSION, ERROR_LOCAL_BASE_ID + (uReason & 0xff));
  338. #endif
  339. return lReason;
  340. } // MapAdmissionRejectReason()
  341. HRESULT MapBandwidthRejectReason(register UINT uReason)
  342. {
  343. register HRESULT lReason;
  344. // TBD - Map reason code into CC_xxx HRESULT
  345. switch (uReason)
  346. {
  347. case notBound_chosen:
  348. lReason = CC_GATEKEEPER_REFUSED;
  349. break;
  350. case invalidConferenceID_chosen:
  351. lReason = CC_GATEKEEPER_REFUSED;
  352. break;
  353. case BndRjctRsn_invldPrmssn_chosen:
  354. lReason = CC_GATEKEEPER_REFUSED;
  355. break;
  356. case insufficientResources_chosen:
  357. lReason = CC_GATEKEEPER_REFUSED;
  358. break;
  359. case BndRjctRsn_invldRvsn_chosen:
  360. lReason = CC_GATEKEEPER_REFUSED;
  361. break;
  362. case BndRjctRsn_undfndRsn_chosen:
  363. lReason = CC_GATEKEEPER_REFUSED;
  364. break;
  365. default:
  366. lReason = CC_GATEKEEPER_REFUSED;
  367. } // switch
  368. return lReason;
  369. } // MapBandwidthRejectReason()
  370. /*
  371. * NOTES
  372. * GkiLock must be locked before calling this routine!
  373. */
  374. static PLISTEN ListenEnqueue(register PLISTEN pListen)
  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(CC_HLISTEN 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 = MemAlloc((uPrefixLength + uDataLength) * sizeof(pAliasItem->pData[0]));
  482. if (pAlias->value.u.h323_ID.value == NULL)
  483. {
  484. ISRERROR(ghISRInst, "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. ISRERROR(ghISRInst, "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. ISRTRACE(ghISRInst, "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. CC_HCALL hCall;
  553. ASSERT(pGkiCall != NULL);
  554. pConference = pConference; // Disable compiler warning
  555. hCall = pGkiCall->hCall;
  556. ISRTRACE(ghISRInst, 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. ISRERROR(ghISRInst, "GkiCancelCall: Invalid call state %d", pGkiCall->uGkiCallState);
  586. } // switch
  587. if (ValidateCall(hCall) == NOERROR && pGkiCall->uGkiCallState != GCS_START)
  588. {
  589. GkiFreeCall(pGkiCall);
  590. }
  591. ISRTRACE(ghISRInst, 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. ISRTRACE(ghISRInst, 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. ISRTRACE(ghISRInst, 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. ISRTRACE(ghISRInst, 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. ISRERROR(ghISRInst, "GatekeeperNotFound: Invalid call state %d", pGkiCall->uGkiCallState);
  649. } // switch
  650. ISRTRACE(ghISRInst, 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. 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. ISRERROR(ghISRInst, "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. ISRERROR(ghISRInst, "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 = NULL;
  695. SeqAliasAddr *pRegistrationAliasAddrs = NULL;
  696. PCC_ALIASITEM pAliasItem;
  697. unsigned uIndex;
  698. unsigned uDigit;
  699. EndpointType TerminalType = {0};
  700. // Count Transport Addresses and Alias Names
  701. pListen = pListenList;
  702. while (pListen)
  703. {
  704. // Count the Transport Address
  705. ++uListens;
  706. if (pListen->pAliasNames)
  707. {
  708. // Count the Alias Names
  709. uAliasNames += pListen->pAliasNames->wCount;
  710. }
  711. pListen = pListen->pNext;
  712. }
  713. // if the separately configured alias names exist, override what was
  714. // in the listen list
  715. if(gpLocalAliasNames)
  716. {
  717. uAliasNames = gpLocalAliasNames->wCount;
  718. }
  719. pTransportAddrs = MemAlloc(uListens * sizeof(*pTransportAddrs));
  720. if (pTransportAddrs == NULL)
  721. {
  722. ISRERROR(ghISRInst, "GkiRegister: Could not allocate %d Transport Addresses", uListens);
  723. return CC_NO_MEMORY;
  724. }
  725. if (uAliasNames)
  726. {
  727. pAliasAddrs =
  728. MemAlloc(uAliasNames * sizeof(*pAliasAddrs));
  729. if (pAliasAddrs == NULL)
  730. {
  731. MemFree(pTransportAddrs);
  732. ISRERROR(ghISRInst, "GkiRegister: Could not allocate %d Alias Addresses", uAliasNames);
  733. return CC_NO_MEMORY;
  734. }
  735. }
  736. pListen = pListenList;
  737. uListens = 0;
  738. uAliasNames = 0;
  739. // if the separately configured alias names exist, override what was
  740. // in the listen list
  741. if(gpLocalAliasNames)
  742. {
  743. pAliasItem = gpLocalAliasNames->pItems;
  744. for (uIndex = 0; uIndex < gpLocalAliasNames->wCount; ++uIndex, ++pAliasItem)
  745. {
  746. pAliasAddrs[uAliasNames].next = &pAliasAddrs[uAliasNames + 1];
  747. switch (pAliasItem->wType)
  748. {
  749. case CC_ALIAS_H323_ID:
  750. pAliasAddrs[uAliasNames].value.choice = h323_ID_chosen;
  751. pAliasAddrs[uAliasNames].value.u.h323_ID.length = pAliasItem->wDataLength;
  752. pAliasAddrs[uAliasNames].value.u.h323_ID.value = pAliasItem->pData;
  753. break;
  754. case CC_ALIAS_H323_PHONE:
  755. pAliasAddrs[uAliasNames].value.choice = e164_chosen;
  756. memset(pAliasAddrs[uAliasNames].value.u.e164, 0, sizeof(pAliasAddrs[uAliasNames].value.u.e164));
  757. for (uDigit = 0; uDigit < pAliasItem->wDataLength; ++uDigit)
  758. {
  759. pAliasAddrs[uAliasNames].value.u.e164[uDigit] = (char)pAliasItem->pData[uDigit];
  760. }
  761. break;
  762. default:
  763. MemFree(pAliasAddrs);
  764. ISRERROR(ghISRInst, "GkiRegister: Bad alias name type %d",
  765. pAliasItem->wType);
  766. return CC_BAD_PARAM;
  767. } // switch
  768. ++uAliasNames;
  769. } // for
  770. }
  771. while (pListen)
  772. {
  773. // Initialize a transport address
  774. // TBD - throw out duplicates
  775. pTransportAddrs[uListens].next = &pTransportAddrs[uListens + 1];
  776. pTransportAddrs[uListens].value.choice = ipAddress_chosen;
  777. pTransportAddrs[uListens].value.u.ipAddress.ip.length = 4;
  778. *((DWORD *)pTransportAddrs[uListens].value.u.ipAddress.ip.value) = pListen->dwAddr;
  779. pTransportAddrs[uListens].value.u.ipAddress.port = pListen->wPort;
  780. // Add any alias names to list (unless separately configured alias names exist)
  781. // TBD - throw out duplicates
  782. if ((gpLocalAliasNames == NULL) && pAliasAddrs && pListen->pAliasNames)
  783. {
  784. pAliasItem = pListen->pAliasNames->pItems;
  785. for (uIndex = 0; uIndex < pListen->pAliasNames->wCount; ++uIndex, ++pAliasItem)
  786. {
  787. pAliasAddrs[uAliasNames].next = &pAliasAddrs[uAliasNames + 1];
  788. switch (pAliasItem->wType)
  789. {
  790. case CC_ALIAS_H323_ID:
  791. pAliasAddrs[uAliasNames].value.choice = h323_ID_chosen;
  792. pAliasAddrs[uAliasNames].value.u.h323_ID.length = pAliasItem->wDataLength;
  793. pAliasAddrs[uAliasNames].value.u.h323_ID.value = pAliasItem->pData;
  794. break;
  795. case CC_ALIAS_H323_PHONE:
  796. pAliasAddrs[uAliasNames].value.choice = e164_chosen;
  797. memset(pAliasAddrs[uAliasNames].value.u.e164, 0, sizeof(pAliasAddrs[uAliasNames].value.u.e164));
  798. for (uDigit = 0; uDigit < pAliasItem->wDataLength; ++uDigit)
  799. {
  800. pAliasAddrs[uAliasNames].value.u.e164[uDigit] = (char)pAliasItem->pData[uDigit];
  801. }
  802. break;
  803. default:
  804. MemFree(pAliasAddrs);
  805. MemFree(pTransportAddrs);
  806. ISRERROR(ghISRInst, "GkiRegister: Bad alias name type %d",
  807. pAliasItem->wType);
  808. return CC_BAD_PARAM;
  809. } // switch
  810. ++uAliasNames;
  811. } // for
  812. } // if
  813. ++uListens;
  814. pListen = pListen->pNext;
  815. } // while
  816. pTransportAddrs[uListens - 1].next = NULL;
  817. if (pAliasAddrs)
  818. {
  819. pAliasAddrs[uAliasNames - 1].next = NULL;
  820. }
  821. // Initialize TerminalType
  822. TerminalType.bit_mask = terminal_present;
  823. TerminalType.mc = (g_dwMultipointConfiguration)?TRUE:FALSE;
  824. uGkiState = STATE_REGISTERING;
  825. ISRTRACE(ghISRInst, "GKI_RegistrationRequest called...", 0);
  826. status =
  827. pGKI_RegistrationRequest(GKI_VERSION, // lVersion
  828. pTransportAddrs, // pCallSignalAddr
  829. &TerminalType, // pTerminalType
  830. pAliasAddrs, // pRgstrtnRgst_trmnlAls
  831. gpVendorInfo,
  832. hwndGki, // hWnd
  833. GKIMAN_BASE, // wBaseMessage
  834. ipAddress_chosen); // usRegistrationTransport
  835. if (status == NOERROR)
  836. {
  837. ISRTRACE(ghISRInst, GkiErrorName("GKI_RegistrationRequest returned %s", status), 0);
  838. }
  839. else
  840. {
  841. ISRERROR(ghISRInst, GkiErrorName("GKI_RegistrationRequest returned %s", status), 0);
  842. uGkiState = STATE_WINDOW_CREATED;
  843. }
  844. if (pAliasAddrs)
  845. MemFree(pAliasAddrs);
  846. if (pTransportAddrs)
  847. MemFree(pTransportAddrs);
  848. }
  849. break;
  850. case STATE_REGISTERING:
  851. case STATE_REGISTERING_REREG:
  852. case STATE_REGISTERING_UNREG:
  853. uGkiState = STATE_REGISTERING_REREG;
  854. break;
  855. case STATE_REGISTERED:
  856. uGkiState = STATE_UNREGISTERING_REREG;
  857. ISRTRACE(ghISRInst, "GKI_UnregistrationRequest called...", 0);
  858. status = pGKI_UnregistrationRequest();
  859. if (status == NOERROR)
  860. {
  861. ISRTRACE(ghISRInst, GkiErrorName("GKI_UnregistrationRequest returned %s", status), 0);
  862. }
  863. else
  864. {
  865. ISRERROR(ghISRInst, GkiErrorName("GKI_UnregistrationRequest returned %s", status), 0);
  866. uGkiState = STATE_REG_BYPASS;
  867. ApplyToAllCalls(GatekeeperNotFound);
  868. }
  869. break;
  870. case STATE_ADMITTING:
  871. case STATE_ADMITTING_REREG:
  872. case STATE_ADMITTING_UNREG:
  873. uGkiState = STATE_ADMITTING_REREG;
  874. break;
  875. case STATE_DISENGAGING:
  876. uGkiState = STATE_DISENGAGING_REREG;
  877. break;
  878. case STATE_DISENGAGING_REREG:
  879. break;
  880. case STATE_UNREGISTERING:
  881. uGkiState = STATE_UNREGISTERING_REREG;
  882. break;
  883. case STATE_UNREGISTERING_REREG:
  884. break;
  885. case STATE_REG_BYPASS:
  886. break;
  887. default:
  888. ISRERROR(ghISRInst, "GkiRegister: Invalid state %d", uGkiState);
  889. status = LastGkiError;
  890. } // switch
  891. return status;
  892. } // GkiRegister()
  893. /*
  894. * NOTES
  895. * GkiLock must be locked before calling this routine!
  896. */
  897. HRESULT GkiCloseCallNoError(PGKICALL pGkiCall, void *pConference)
  898. {
  899. ASSERT(GKIExists());
  900. ASSERT(pGkiCall != NULL);
  901. pConference = pConference; // Disable compiler warning
  902. if (pGkiCall->uGkiCallState != GCS_START)
  903. GkiCloseCall(pGkiCall);
  904. return NOERROR;
  905. } // GkiCloseCallNoError()
  906. HRESULT GkiUnregister(void)
  907. {
  908. register HRESULT status = NOERROR;
  909. switch (uGkiState)
  910. {
  911. case STATE_REG_BYPASS:
  912. ApplyToAllCalls(GkiCancelCall);
  913. uGkiState = STATE_WINDOW_CREATED;
  914. break;
  915. case STATE_UNREGISTERING_REREG:
  916. uGkiState = STATE_UNREGISTERING;
  917. break;
  918. case STATE_UNREGISTERING:
  919. break;
  920. case STATE_DISENGAGING_REREG:
  921. if (uGkiCalls != 0 || uPendingDisengages != 0)
  922. {
  923. uGkiState = STATE_DISENGAGING;
  924. }
  925. else
  926. {
  927. uGkiState = STATE_REGISTERED;
  928. return GkiUnregister();
  929. }
  930. break;
  931. case STATE_DISENGAGING:
  932. if (uGkiCalls == 0 && uPendingDisengages == 0)
  933. {
  934. uGkiState = STATE_REGISTERED;
  935. return GkiUnregister();
  936. }
  937. break;
  938. case STATE_ADMITTING_UNREG:
  939. case STATE_ADMITTING_REREG:
  940. case STATE_ADMITTING:
  941. uGkiState = STATE_ADMITTING_UNREG;
  942. break;
  943. case STATE_REGISTERING_UNREG:
  944. case STATE_REGISTERING_REREG:
  945. case STATE_REGISTERING:
  946. uGkiState = STATE_REGISTERING_UNREG;
  947. break;
  948. case STATE_REGISTERED:
  949. if (uGkiCalls)
  950. {
  951. // Issue Disengage Request for every call
  952. uGkiState = STATE_DISENGAGING;
  953. ApplyToAllCalls(GkiCloseCallNoError);
  954. break;
  955. }
  956. else
  957. {
  958. // Issue Unregistration Request
  959. uGkiState = STATE_UNREGISTERING;
  960. ISRTRACE(ghISRInst, "GKI_UnregistrationRequest called...", 0);
  961. status = pGKI_UnregistrationRequest();
  962. if (status == NOERROR)
  963. {
  964. ISRTRACE(ghISRInst, GkiErrorName("GKI_UnregistrationRequest returned %s", status), 0);
  965. }
  966. else
  967. {
  968. ISRERROR(ghISRInst, GkiErrorName("GKI_UnregistrationRequest returned %s", status), 0);
  969. uGkiState = STATE_WINDOW_CREATED;
  970. }
  971. }
  972. break;
  973. case STATE_WINDOW_CREATED:
  974. case STATE_CLASS_REGISTERED:
  975. case STATE_START:
  976. ISRWARNING(ghISRInst, StateName("GkiUnregister: Already in uninitialized state %s", uGkiState), 0);
  977. status = LastGkiError;
  978. break;
  979. default:
  980. ISRERROR(ghISRInst, "GkiUnregister: Invalid state %d", uGkiState);
  981. status = LastGkiError;
  982. } // switch
  983. return status;
  984. } // GkiUnregister()
  985. void DeInitGkiManager(void)
  986. {
  987. register PLISTEN pListen;
  988. if(!fGKConfigured)
  989. return;
  990. EnterCriticalSection(&GkiLock);
  991. #if 0
  992. // TBD - When called from DllMain PROCESS_DETACH, this does not work because
  993. // apparently the socket to the Gatekeeper has already been closed.
  994. if (uGkiState != STATE_START)
  995. {
  996. GkiUnregister();
  997. uGkiState = STATE_START;
  998. }
  999. #else
  1000. uGkiState = STATE_START;
  1001. #endif
  1002. while (pListenList)
  1003. {
  1004. pListen = pListenList;
  1005. pListenList = pListenList->pNext;
  1006. if (pListen->pAliasNames)
  1007. {
  1008. FreeAliasNames(pListen->pAliasNames);
  1009. }
  1010. MemFree(pListen);
  1011. }
  1012. pGKI_RegistrationRequest = NULL;
  1013. pGKI_UnregistrationRequest = NULL;
  1014. pGKI_LocationRequest = NULL;
  1015. pGKI_AdmissionRequest = NULL;
  1016. pGKI_BandwidthRequest = NULL;
  1017. pGKI_DisengageRequest = NULL;
  1018. pGKI_Initialize = NULL;
  1019. if (pGKI_CleanupRequest)
  1020. pGKI_CleanupRequest();
  1021. pGKI_CleanupRequest = NULL;
  1022. LeaveCriticalSection(&GkiLock);
  1023. DeleteCriticalSection(&GkiLock);
  1024. if (NULL != hwndGki)
  1025. {
  1026. DestroyWindow(hwndGki);
  1027. }
  1028. } // DeInitGkiManager()
  1029. HRESULT InitGkiManager(void)
  1030. {
  1031. HRESULT hr = CC_GKI_LOAD;
  1032. InitializeCriticalSection(&GkiLock);
  1033. pGKI_RegistrationRequest = (PGKI_RegistrationRequest) GKI_RegistrationRequest;
  1034. pGKI_UnregistrationRequest = (PGKI_UnregistrationRequest) GKI_UnregistrationRequest;
  1035. pGKI_LocationRequest = (PGKI_LocationRequest) GKI_LocationRequest;
  1036. pGKI_AdmissionRequest = (PGKI_AdmissionRequest) GKI_AdmissionRequest;
  1037. pGKI_BandwidthRequest = (PGKI_BandwidthRequest) GKI_BandwidthRequest;
  1038. pGKI_DisengageRequest = (PGKI_DisengageRequest) GKI_DisengageRequest;
  1039. pGKI_CleanupRequest = (PGKI_CleanupRequest) GKI_CleanupRequest;
  1040. pGKI_Initialize = (PGKI_Initialize) GKI_Initialize;
  1041. hr = pGKI_Initialize();
  1042. if(hr != GKI_OK)
  1043. {
  1044. DeleteCriticalSection(&GkiLock);
  1045. DeInitGkiManager();
  1046. }
  1047. else
  1048. {
  1049. fGKConfigured = TRUE;
  1050. }
  1051. return hr;
  1052. } // InitGkiManager()
  1053. //
  1054. // Entry Points
  1055. //
  1056. HRESULT GkiFreeCall(PGKICALL pGkiCall)
  1057. {
  1058. HRESULT status = NOERROR;
  1059. ASSERT(pGkiCall != NULL);
  1060. ASSERT(pGkiCall->uGkiCallState != GCS_START);
  1061. pGkiCall->hGkiCall = 0;
  1062. while (pGkiCall->pBwReqHead)
  1063. {
  1064. MemFree(BwReqDequeue(pGkiCall));
  1065. }
  1066. if (pGkiCall->pCalleeAliasNames)
  1067. {
  1068. Q931FreeAliasNames(pGkiCall->pCalleeAliasNames);
  1069. pGkiCall->pCalleeAliasNames = NULL;
  1070. }
  1071. if (pGkiCall->pCalleeExtraAliasNames != NULL)
  1072. {
  1073. Q931FreeAliasNames(pGkiCall->pCalleeExtraAliasNames);
  1074. pGkiCall->pCalleeExtraAliasNames = NULL;
  1075. }
  1076. switch (pGkiCall->uGkiCallState)
  1077. {
  1078. case GCS_START:
  1079. case GCS_WAITING:
  1080. break;
  1081. case GCS_ADMITTING:
  1082. ASSERT(uGkiState == STATE_ADMITTING);
  1083. switch (uGkiState)
  1084. {
  1085. case STATE_ADMITTING:
  1086. uGkiState = STATE_REGISTERED;
  1087. break;
  1088. } // switch
  1089. break;
  1090. case GCS_ADMITTING_CLOSE_PENDING:
  1091. ASSERT(uGkiState == STATE_ADMITTING || uGkiState == STATE_ADMITTING_UNREG || uGkiState == STATE_ADMITTING_REREG);
  1092. switch (uGkiState)
  1093. {
  1094. case STATE_ADMITTING:
  1095. uGkiState = STATE_REGISTERED;
  1096. break;
  1097. case STATE_ADMITTING_UNREG:
  1098. uGkiState = STATE_REGISTERED;
  1099. status = GkiUnregister();
  1100. break;
  1101. case STATE_ADMITTING_REREG:
  1102. uGkiState = STATE_REGISTERED;
  1103. status = GkiRegister();
  1104. break;
  1105. } // switch
  1106. break;
  1107. case GCS_ADMITTED:
  1108. case GCS_CHANGING:
  1109. case GCS_CHANGING_CLOSE_PENDING:
  1110. case GCS_DISENGAGING:
  1111. --uGkiCalls;
  1112. ISRTRACE(ghISRInst, "GkiFreeCall: uGkiCalls = %d", uGkiCalls);
  1113. break;
  1114. default:
  1115. ISRERROR(ghISRInst, "GkiFreeCall: Invalid call state %d", pGkiCall->uGkiCallState);
  1116. } // switch
  1117. pGkiCall->uGkiCallState = GCS_START;
  1118. if (uGkiCalls == 0 && uPendingDisengages == 0)
  1119. {
  1120. switch (uGkiState)
  1121. {
  1122. case STATE_DISENGAGING:
  1123. uGkiState = STATE_REGISTERED;
  1124. status = GkiUnregister();
  1125. break;
  1126. case STATE_DISENGAGING_REREG:
  1127. uGkiState = STATE_REGISTERED;
  1128. status = GkiRegister();
  1129. break;
  1130. } // switch
  1131. }
  1132. return status;
  1133. } // GkiFreeCall()
  1134. HRESULT GkiCloseListen (CC_HLISTEN hListen)
  1135. {
  1136. register PLISTEN pListen;
  1137. register HRESULT status;
  1138. ISRTRACE(ghISRInst, StateName("GkiCloseListen <- State = %s", uGkiState), 0);
  1139. EnterCriticalSection(&GkiLock);
  1140. pListen = ListenDequeue(hListen);
  1141. if (pListen == NULL)
  1142. {
  1143. status = CC_GKI_LISTEN_NOT_FOUND;
  1144. }
  1145. else
  1146. {
  1147. if (pListen->pAliasNames)
  1148. {
  1149. FreeAliasNames(pListen->pAliasNames);
  1150. }
  1151. MemFree(pListen);
  1152. if (pListenList)
  1153. {
  1154. status = GkiRegister();
  1155. }
  1156. else
  1157. {
  1158. status = GkiUnregister();
  1159. }
  1160. }
  1161. LeaveCriticalSection(&GkiLock);
  1162. ISRTRACE(ghISRInst, StateName("GkiCloseListen -> State = %s", uGkiState), 0);
  1163. return status;
  1164. } // GkiCloseListen()
  1165. HRESULT GkiSetVendorConfig( PCC_VENDORINFO pVendorInfo,
  1166. DWORD dwMultipointConfiguration)
  1167. {
  1168. HRESULT status = CC_OK;
  1169. EnterCriticalSection(&GkiLock);
  1170. if(gpVendorInfo)
  1171. {
  1172. FreeVendorInfo(gpVendorInfo);
  1173. gpVendorInfo = NULL;
  1174. }
  1175. if (!pVendorInfo)
  1176. {
  1177. // everything is cleaned up, so return
  1178. LeaveCriticalSection(&GkiLock);
  1179. return status;
  1180. }
  1181. status = CopyVendorInfo(&gpVendorInfo, pVendorInfo);
  1182. if (status != NOERROR)
  1183. {
  1184. ISRERROR(ghISRInst, "GkiSetRegistrationAliases: CopyVendorInfo returned 0x%x", status);
  1185. LeaveCriticalSection(&GkiLock);
  1186. return status;
  1187. }
  1188. g_dwMultipointConfiguration = dwMultipointConfiguration;
  1189. LeaveCriticalSection(&GkiLock);
  1190. return status;
  1191. }
  1192. HRESULT GkiSetRegistrationAliases(PCC_ALIASNAMES pLocalAliasNames)
  1193. {
  1194. HRESULT status = CC_OK;
  1195. EnterCriticalSection(&GkiLock);
  1196. if(gpLocalAliasNames)
  1197. {
  1198. FreeAliasNames(gpLocalAliasNames);
  1199. gpLocalAliasNames = NULL;
  1200. }
  1201. if (!pLocalAliasNames)
  1202. {
  1203. // everything is cleaned up, so return
  1204. LeaveCriticalSection(&GkiLock);
  1205. return status;
  1206. }
  1207. status = CopyAliasNames(&gpLocalAliasNames, pLocalAliasNames);
  1208. if (status != NOERROR)
  1209. {
  1210. ISRERROR(ghISRInst, "GkiSetRegistrationAliases: CopyAliasNames returned 0x%x", status);
  1211. LeaveCriticalSection(&GkiLock);
  1212. return status;
  1213. }
  1214. LeaveCriticalSection(&GkiLock);
  1215. return status;
  1216. }
  1217. HRESULT GkiOpenListen (CC_HLISTEN hListen, PCC_ALIASNAMES pAliasNames, DWORD dwAddr, WORD wPort)
  1218. {
  1219. register PLISTEN pListen;
  1220. register HRESULT status = NOERROR;
  1221. ISRTRACE(ghISRInst, StateName("GkiOpenListen <- State = %s", uGkiState), 0);
  1222. EnterCriticalSection(&GkiLock);
  1223. // dwAddr, wPort are in host byte order
  1224. // Check for invalid IP address
  1225. if (dwAddr == INADDR_ANY || dwAddr == INADDR_NONE)
  1226. {
  1227. // this doesn't neccessarily get the correct IP address on a multi-homed
  1228. // machine, but it at least tests to see if IP is configured on this
  1229. // box.
  1230. dwAddr = GetIpAddress();
  1231. if (dwAddr == INADDR_ANY)
  1232. {
  1233. LeaveCriticalSection(&GkiLock);
  1234. return CC_GKI_IP_ADDRESS;
  1235. }
  1236. }
  1237. // Check for invalid alias list
  1238. if (pAliasNames)
  1239. {
  1240. PCC_ALIASITEM pAliasItem;
  1241. unsigned int uIndex;
  1242. if (pAliasNames->wCount == 0)
  1243. {
  1244. ISRERROR(ghISRInst, "GkiOpenListen: Alias name wCount == 0", 0);
  1245. return CC_BAD_PARAM;
  1246. }
  1247. pAliasItem = pAliasNames->pItems;
  1248. for (uIndex = 0; uIndex < pAliasNames->wCount; ++uIndex, ++pAliasItem)
  1249. {
  1250. if (pAliasItem->wDataLength == 0 || pAliasItem->pData == NULL)
  1251. {
  1252. // Bad alias item
  1253. ISRERROR(ghISRInst, "GkiOpenListen: Bad alias item (wDataLength = %d)",
  1254. pAliasItem->wDataLength);
  1255. return CC_BAD_PARAM;
  1256. }
  1257. }
  1258. }
  1259. pListen = (PLISTEN)MemAlloc(sizeof(*pListen));
  1260. if (pListen)
  1261. {
  1262. if (pAliasNames)
  1263. {
  1264. status = CopyAliasNames(&pListen->pAliasNames, pAliasNames);
  1265. if (status != NOERROR)
  1266. {
  1267. ISRERROR(ghISRInst, "GkiOpenListen: CopyAliasNames returned 0x%x", status);
  1268. LeaveCriticalSection(&GkiLock);
  1269. MemFree(pListen);
  1270. return status;
  1271. }
  1272. }
  1273. else
  1274. {
  1275. pListen->pAliasNames = NULL;
  1276. }
  1277. pListen->hListen = hListen;
  1278. pListen->dwAddr = htonl(dwAddr);
  1279. pListen->wPort = wPort;
  1280. ListenEnqueue(pListen);
  1281. if(GKIExists())
  1282. {
  1283. status = GkiRegister();
  1284. }
  1285. } // if
  1286. else
  1287. {
  1288. ISRERROR(ghISRInst, "GkiOpenListen: Could not allocate listen structure", 0);
  1289. status = CC_NO_MEMORY;
  1290. } // else
  1291. LeaveCriticalSection(&GkiLock);
  1292. ISRTRACE(ghISRInst, StateName("GkiOpenListen -> State = %s", uGkiState), 0);
  1293. return status;
  1294. } // GkiOpenListen()
  1295. HRESULT GkiListenAddr (SOCKADDR_IN* psin)
  1296. {
  1297. PLISTEN pListen = pListenList;
  1298. HRESULT status = NOERROR;
  1299. SOCKADDR_IN srem;
  1300. SOCKADDR_IN sloc;
  1301. ASSERT(psin);
  1302. ASSERT(pListen != NULL);
  1303. // try and get the best interface given the dwAddr passed in to us
  1304. srem.sin_family = AF_INET;
  1305. srem.sin_port = htons(7); // give echo a try since most GKs are unix-based
  1306. srem.sin_addr.s_addr = psin->sin_addr.s_addr;
  1307. status = NMGetBestInterface(&srem, &sloc);
  1308. if (status == NOERROR)
  1309. {
  1310. EnterCriticalSection(&GkiLock);
  1311. while (pListen)
  1312. {
  1313. pListen->dwAddr = sloc.sin_addr.s_addr;
  1314. pListen = pListen->pNext;
  1315. }
  1316. LeaveCriticalSection(&GkiLock);
  1317. }
  1318. return status;
  1319. } // GkiListenAddr()
  1320. /*
  1321. * NOTES
  1322. * Must have Call locked before calling!
  1323. */
  1324. HRESULT GkiCloseCall(PGKICALL pGkiCall)
  1325. {
  1326. HRESULT status = NOERROR;
  1327. ASSERT(GKIExists());
  1328. ASSERT(pGkiCall != NULL);
  1329. ISRTRACE(ghISRInst, CallStateName("GkiCloseCall <- Call State = %s", pGkiCall->uGkiCallState), 0);
  1330. while (pGkiCall->pBwReqHead)
  1331. {
  1332. MemFree(BwReqDequeue(pGkiCall));
  1333. }
  1334. if (pGkiCall->uGkiCallState == GCS_START)
  1335. {
  1336. ISRWARNING(ghISRInst, CallStateName("GkiCloseCall: Call already in state %s", pGkiCall->uGkiCallState), 0);
  1337. status = CC_GKI_CALL_STATE;
  1338. }
  1339. else
  1340. {
  1341. switch (uGkiState)
  1342. {
  1343. case STATE_START:
  1344. break;
  1345. case STATE_REG_BYPASS:
  1346. status = GkiFreeCall(pGkiCall);
  1347. break;
  1348. default:
  1349. switch (pGkiCall->uGkiCallState)
  1350. {
  1351. case GCS_WAITING:
  1352. status = GkiFreeCall(pGkiCall);
  1353. break;
  1354. case GCS_ADMITTING:
  1355. pGkiCall->uGkiCallState = GCS_ADMITTING_CLOSE_PENDING;
  1356. break;
  1357. case GCS_ADMITTING_CLOSE_PENDING:
  1358. case GCS_CHANGING_CLOSE_PENDING:
  1359. case GCS_DISENGAGING:
  1360. ISRWARNING(ghISRInst, CallStateName("GkiCloseCall: Call already in closing state %s", pGkiCall->uGkiCallState), 0);
  1361. status = CC_GKI_CALL_STATE;
  1362. break;
  1363. case GCS_ADMITTED:
  1364. pGkiCall->uGkiCallState = GCS_DISENGAGING;
  1365. ISRTRACE(ghISRInst, "GKI_DisengageRequest called...", 0);
  1366. ++uPendingDisengages;
  1367. status = pGKI_DisengageRequest(pGkiCall->hGkiCall);
  1368. if (status == NOERROR)
  1369. {
  1370. ISRTRACE(ghISRInst, GkiErrorName("GKI_DisengageRequest returned %s", status), 0);
  1371. }
  1372. else
  1373. {
  1374. --uPendingDisengages;
  1375. ISRERROR(ghISRInst, GkiErrorName("GKI_DisengageRequest returned %s", status), 0);
  1376. GkiFreeCall(pGkiCall);
  1377. }
  1378. break;
  1379. case GCS_CHANGING:
  1380. pGkiCall->uGkiCallState = GCS_CHANGING_CLOSE_PENDING;
  1381. break;
  1382. default:
  1383. ISRERROR(ghISRInst, CallStateName("GkiCloseCall: Call in invalid state %s", pGkiCall->uGkiCallState), 0);
  1384. status = CC_GKI_CALL_STATE;
  1385. } // switch
  1386. } // switch
  1387. } // else
  1388. ISRTRACE(ghISRInst, StateName("GkiCloseCall -> State = %s", uGkiState), 0);
  1389. return status;
  1390. } // GkiCloseCall()
  1391. /*
  1392. * NOTES
  1393. * Must have Call locked before calling!
  1394. */
  1395. static HRESULT BandwidthRejected(PGKICALL pGkiCall, UINT Reason)
  1396. {
  1397. HRESULT status = NOERROR;
  1398. PBWREQ pBwReq;
  1399. CC_HCALL hCall;
  1400. ASSERT(pGkiCall != NULL);
  1401. pBwReq = BwReqDequeue(pGkiCall);
  1402. hCall = pGkiCall->hCall;
  1403. if (pBwReq)
  1404. {
  1405. if ((pGkiCall->uBandwidthUsed + pBwReq->uChannelBandwidth) <= pGkiCall->uBandwidthAllocated)
  1406. {
  1407. if (pBwReq->Type == TX)
  1408. {
  1409. OpenChannelConfirm (pBwReq->hChannel);
  1410. }
  1411. else
  1412. {
  1413. AcceptChannelConfirm(pBwReq->hChannel);
  1414. }
  1415. }
  1416. else
  1417. {
  1418. if (pBwReq->Type == TX)
  1419. {
  1420. OpenChannelReject (pBwReq->hChannel, MapBandwidthRejectReason(Reason));
  1421. }
  1422. else
  1423. {
  1424. AcceptChannelReject (pBwReq->hChannel, MapBandwidthRejectReason(Reason));
  1425. }
  1426. }
  1427. MemFree(pBwReq);
  1428. if (ValidateCall(hCall) == NOERROR)
  1429. {
  1430. CheckPendingBandwidth(pGkiCall);
  1431. }
  1432. }
  1433. return status;
  1434. } // BandwidthRejected()
  1435. /*
  1436. * NOTES
  1437. * Must have Call locked before calling!
  1438. */
  1439. static HRESULT CheckPendingBandwidth(PGKICALL pGkiCall)
  1440. {
  1441. HRESULT status = NOERROR;
  1442. PBWREQ pBwReq;
  1443. CC_HCALL hCall;
  1444. ASSERT(pGkiCall != NULL);
  1445. ASSERT(pGkiCall->uGkiCallState == GCS_ADMITTED);
  1446. hCall = pGkiCall->hCall;
  1447. while (pGkiCall->pBwReqHead != NULL &&
  1448. (pGkiCall->uBandwidthUsed + pGkiCall->pBwReqHead->uChannelBandwidth) <= pGkiCall->uBandwidthAllocated)
  1449. {
  1450. pBwReq = BwReqDequeue(pGkiCall);
  1451. ASSERT(pBwReq != NULL);
  1452. pGkiCall->uBandwidthUsed += pBwReq->uChannelBandwidth;
  1453. if (pBwReq->Type == TX)
  1454. {
  1455. OpenChannelConfirm(pBwReq->hChannel);
  1456. }
  1457. else
  1458. {
  1459. AcceptChannelConfirm(pBwReq->hChannel);
  1460. }
  1461. MemFree(pBwReq);
  1462. if (ValidateCall(hCall) != NOERROR)
  1463. {
  1464. return status;
  1465. }
  1466. }
  1467. if (pGkiCall->pBwReqHead != NULL)
  1468. {
  1469. pGkiCall->uGkiCallState = GCS_CHANGING;
  1470. ISRTRACE(ghISRInst, "GKI_BandwidthRequest called...", 0);
  1471. status = pGKI_BandwidthRequest(pGkiCall->hGkiCall,
  1472. pGkiCall->usCallTypeChoice,
  1473. pGkiCall->uBandwidthUsed + pGkiCall->pBwReqHead->uChannelBandwidth);
  1474. if (status == NOERROR)
  1475. {
  1476. ISRTRACE(ghISRInst, GkiErrorName("GKI_BandwidthRequest returned %s", status), 0);
  1477. }
  1478. else
  1479. {
  1480. ISRERROR(ghISRInst, GkiErrorName("GKI_BandwidthRequest returned %s", status), 0);
  1481. BandwidthRejected(pGkiCall, BndRjctRsn_undfndRsn_chosen);
  1482. }
  1483. }
  1484. return status;
  1485. } // CheckPendingBandwidth()
  1486. static void FreeAliasList(SeqAliasAddr *pAliasAddrs)
  1487. {
  1488. register SeqAliasAddr *pAlias = pAliasAddrs;
  1489. while (pAlias)
  1490. {
  1491. if (pAlias->value.choice == h323_ID_chosen && pAlias->value.u.h323_ID.value)
  1492. MemFree(pAlias->value.u.h323_ID.value);
  1493. pAlias = pAlias->next;
  1494. }
  1495. MemFree(pAlias);
  1496. } // FreeAliasList()
  1497. /*
  1498. * NOTES
  1499. * Must have Call locked before calling!
  1500. *
  1501. * The following fields in the GKICALL structure must be properly filled
  1502. * in before calling this function:
  1503. * pCall Pointer back to containing CALL structure.
  1504. * CallType Type of call.
  1505. * uBandwidthRequested Initial bandwidth for call.
  1506. * pConferenceId Pointer to conference ID buffer.
  1507. * bActiveMC TRUE if calling party has an active MC.
  1508. * bAnswerCall ???
  1509. * CallIdentifier the GUID identifying this call. This must be the same
  1510. * value as CallIdentifier of the Q.931 messages.
  1511. */
  1512. HRESULT GkiOpenCall (PGKICALL pGkiCall, void *pConference)
  1513. {
  1514. HRESULT status = NOERROR;
  1515. CC_HCALL hCall;
  1516. TransportAddress DestCallSignalAddress;
  1517. TransportAddress * pDestCallSignalAddress;
  1518. SeqAliasAddr * pAliasAddrs;
  1519. SeqAliasAddr * pExtraAliasAddrs;
  1520. SeqAliasAddr * pAlias;
  1521. PCC_ALIASITEM pAliasItem;
  1522. unsigned uCount;
  1523. unsigned uIndex;
  1524. ConferenceIdentifier ConferenceId;
  1525. ASSERT(GKIExists());
  1526. ASSERT(pGkiCall != NULL);
  1527. ASSERT(pConference != NULL);
  1528. ISRTRACE(ghISRInst, StateName("GkiOpenCall <- State = %s", uGkiState), 0);
  1529. EnterCriticalSection(&GkiLock);
  1530. switch (uGkiState)
  1531. {
  1532. case STATE_REG_BYPASS:
  1533. ASSERT(pGkiCall->uGkiCallState == GCS_START || pGkiCall->uGkiCallState == GCS_WAITING || pGkiCall->uGkiCallState == GCS_ADMITTING);
  1534. hCall = pGkiCall->hCall;
  1535. GkiAllocCall(pGkiCall, GKI_BYPASS_HANDLE);
  1536. pGkiCall->uBandwidthAllocated = MAX_BANDWIDTH;
  1537. if (pGkiCall->bAnswerCall)
  1538. {
  1539. status = AcceptCallConfirm(pGkiCall->pCall, pConference);
  1540. if (status == NOERROR && ValidateCall(hCall) == NOERROR)
  1541. {
  1542. CheckPendingBandwidth(pGkiCall);
  1543. }
  1544. }
  1545. else if (pGkiCall->dwIpAddress == 0)
  1546. {
  1547. status = PlaceCallReject (pGkiCall->pCall, pConference, CC_INVALID_WITHOUT_GATEKEEPER);
  1548. }
  1549. else
  1550. {
  1551. status = PlaceCallConfirm (pGkiCall->pCall, pConference);
  1552. if (status == NOERROR && ValidateCall(hCall) == NOERROR)
  1553. {
  1554. CheckPendingBandwidth(pGkiCall);
  1555. }
  1556. }
  1557. break;
  1558. case STATE_REGISTERING:
  1559. case STATE_REGISTERING_REREG:
  1560. case STATE_ADMITTING:
  1561. pGkiCall->uGkiCallState = GCS_WAITING;
  1562. break;
  1563. case STATE_REGISTERED:
  1564. switch (pGkiCall->CallType)
  1565. {
  1566. case POINT_TO_POINT:
  1567. pGkiCall->usCallTypeChoice = pointToPoint_chosen;
  1568. break;
  1569. case ONE_TO_MANY:
  1570. pGkiCall->usCallTypeChoice = oneToN_chosen;
  1571. break;
  1572. case MANY_TO_ONE:
  1573. pGkiCall->usCallTypeChoice = nToOne_chosen;
  1574. break;
  1575. case MANY_TO_MANY:
  1576. pGkiCall->usCallTypeChoice = nToN_chosen;
  1577. break;
  1578. default:
  1579. LeaveCriticalSection(&GkiLock);
  1580. ISRERROR(ghISRInst, "GkiOpenCall -> Invalid CallType %d", pGkiCall->CallType);
  1581. return CC_BAD_PARAM;
  1582. } // switch
  1583. pDestCallSignalAddress = NULL;
  1584. pAliasAddrs = NULL;
  1585. pExtraAliasAddrs = NULL;
  1586. if (pGkiCall->dwIpAddress != 0 && pGkiCall->wPort != 0)
  1587. {
  1588. DestCallSignalAddress.choice = ipAddress_chosen;
  1589. DestCallSignalAddress.u.ipAddress.ip.length = 4;
  1590. *((DWORD *)DestCallSignalAddress.u.ipAddress.ip.value) = pGkiCall->dwIpAddress;
  1591. DestCallSignalAddress.u.ipAddress.port = pGkiCall->wPort;
  1592. pDestCallSignalAddress = &DestCallSignalAddress;
  1593. }
  1594. if (pGkiCall->pCalleeAliasNames)
  1595. {
  1596. uCount = pGkiCall->pCalleeAliasNames->wCount;
  1597. pAliasAddrs = MemAlloc(uCount * sizeof(*pAliasAddrs));
  1598. if (pAliasAddrs == NULL)
  1599. {
  1600. LeaveCriticalSection(&GkiLock);
  1601. ISRERROR(ghISRInst, "GkiOpenCall: Could not allocate %d Alias Addresses", uCount);
  1602. return CC_NO_MEMORY;
  1603. }
  1604. memset(pAliasAddrs, 0, uCount * sizeof(*pAliasAddrs));
  1605. pAlias = pAliasAddrs;
  1606. pAliasItem = pGkiCall->pCalleeAliasNames->pItems;
  1607. for (uIndex = 0; uIndex < uCount; ++uIndex)
  1608. {
  1609. status = CopyAliasItem(pAlias, pAliasItem);
  1610. if (status != NOERROR)
  1611. {
  1612. LeaveCriticalSection(&GkiLock);
  1613. ISRERROR(ghISRInst, "GkiOpenCall: CopyAliasItem returned %d", status);
  1614. FreeAliasList(pAliasAddrs);
  1615. MemFree(pAliasAddrs);
  1616. return status;
  1617. }
  1618. pAlias->next = pAlias + 1;
  1619. ++pAlias;
  1620. ++pAliasItem;
  1621. } // for
  1622. --pAlias;
  1623. pAlias->next = NULL;
  1624. }
  1625. if (pGkiCall->pCalleeExtraAliasNames)
  1626. {
  1627. uCount = pGkiCall->pCalleeExtraAliasNames->wCount;
  1628. pExtraAliasAddrs = MemAlloc(uCount * sizeof(*pExtraAliasAddrs));
  1629. if (pExtraAliasAddrs == NULL)
  1630. {
  1631. LeaveCriticalSection(&GkiLock);
  1632. ISRERROR(ghISRInst, "GkiOpenCall: Could not allocate %d Alias Addresses", uCount);
  1633. if (pAliasAddrs)
  1634. {
  1635. FreeAliasList(pAliasAddrs);
  1636. MemFree(pAliasAddrs);
  1637. }
  1638. return CC_NO_MEMORY;
  1639. }
  1640. memset(pExtraAliasAddrs, 0, uCount * sizeof(*pExtraAliasAddrs));
  1641. pAlias = pExtraAliasAddrs;
  1642. pAliasItem = pGkiCall->pCalleeExtraAliasNames->pItems;
  1643. for (uIndex = 0; uIndex < uCount; ++uIndex)
  1644. {
  1645. status = CopyAliasItem(pAlias, pAliasItem);
  1646. if (status != NOERROR)
  1647. {
  1648. LeaveCriticalSection(&GkiLock);
  1649. ISRERROR(ghISRInst, "GkiOpenCall: CopyAliasItem returned %d", status);
  1650. if (pAliasAddrs)
  1651. {
  1652. FreeAliasList(pAliasAddrs);
  1653. MemFree(pAliasAddrs);
  1654. }
  1655. FreeAliasList(pExtraAliasAddrs);
  1656. MemFree(pExtraAliasAddrs);
  1657. return status;
  1658. }
  1659. pAlias->next = pAlias + 1;
  1660. ++pAlias;
  1661. ++pAliasItem;
  1662. } // for
  1663. --pAlias;
  1664. pAlias->next = NULL;
  1665. }
  1666. if (pGkiCall->uBandwidthRequested < MIN_BANDWIDTH)
  1667. {
  1668. pGkiCall->uBandwidthRequested = MIN_BANDWIDTH;
  1669. }
  1670. ASSERT(pGkiCall->uBandwidthAllocated == 0);
  1671. ASSERT(pGkiCall->uBandwidthUsed == 0);
  1672. memcpy(ConferenceId.value, pGkiCall->pConferenceId, 16);
  1673. if (((DWORD *)pGkiCall->pConferenceId)[0] != 0 ||
  1674. ((DWORD *)pGkiCall->pConferenceId)[1] != 0 ||
  1675. ((DWORD *)pGkiCall->pConferenceId)[2] != 0 ||
  1676. ((DWORD *)pGkiCall->pConferenceId)[3] != 0)
  1677. {
  1678. ConferenceId.length = 16;
  1679. }
  1680. else
  1681. {
  1682. ConferenceId.length = 0;
  1683. }
  1684. pGkiCall->hGkiCall = GKI_ADMITTING_HANDLE;
  1685. if (pDestCallSignalAddress != NULL || pAliasAddrs != NULL)
  1686. {
  1687. uGkiState = STATE_ADMITTING;
  1688. pGkiCall->uGkiCallState = GCS_ADMITTING;
  1689. ISRTRACE(ghISRInst, "GKI_AdmissionRequest called...", 0);
  1690. status = pGKI_AdmissionRequest(pGkiCall->usCallTypeChoice, // usCallTypeChoice.
  1691. pAliasAddrs, // pDestinationInfo,
  1692. pDestCallSignalAddress, // pDestCallSignalAddress
  1693. pExtraAliasAddrs, // pDestExtraCallInfo,
  1694. &pGkiCall->CallIdentifier, // H.225 call identifer
  1695. pGkiCall->uBandwidthRequested, // bandWidth,
  1696. &ConferenceId, // pConferenceID,
  1697. pGkiCall->bActiveMC, // activeMC,
  1698. pGkiCall->bAnswerCall, // answerCall,
  1699. ipAddress_chosen); // usCallTransport
  1700. if (status == NOERROR)
  1701. {
  1702. ISRTRACE(ghISRInst, GkiErrorName("GKI_AdmissionRequest returned %s", status), 0);
  1703. }
  1704. else
  1705. {
  1706. ISRERROR(ghISRInst, GkiErrorName("GKI_AdmissionRequest returned %s", status), 0);
  1707. }
  1708. }
  1709. else
  1710. {
  1711. pGkiCall->hGkiCall = 0;
  1712. status = CC_BAD_PARAM;
  1713. }
  1714. if (status != NOERROR)
  1715. {
  1716. uGkiState = STATE_REGISTERED;
  1717. GkiCancelCall(pGkiCall, pConference);
  1718. }
  1719. if (pAliasAddrs)
  1720. {
  1721. FreeAliasList(pAliasAddrs);
  1722. MemFree(pAliasAddrs);
  1723. }
  1724. if (pExtraAliasAddrs)
  1725. {
  1726. FreeAliasList(pExtraAliasAddrs);
  1727. MemFree(pExtraAliasAddrs);
  1728. }
  1729. break;
  1730. case STATE_START:
  1731. case STATE_CLASS_REGISTERED:
  1732. case STATE_WINDOW_CREATED:
  1733. pGkiCall->uGkiCallState = GCS_WAITING;
  1734. // not registered!!! attempt to register or reregister
  1735. status = GkiRegister();
  1736. break;
  1737. default:
  1738. ISRERROR(ghISRInst, StateName("GkiOpenCall: Invalid state %s", uGkiState), 0);
  1739. status = LastGkiError;
  1740. } // switch
  1741. LeaveCriticalSection(&GkiLock);
  1742. ISRTRACE(ghISRInst, CallStateName("GkiOpenCall -> Call State = %s", pGkiCall->uGkiCallState), 0);
  1743. return status;
  1744. } // GkiOpenCall()
  1745. /*
  1746. * NOTES
  1747. * Must have Call locked before calling!
  1748. */
  1749. HRESULT GkiOpenChannel(PGKICALL pGkiCall, unsigned uChannelBandwidth, CC_HCHANNEL hChannel, CHANNELTYPE Type)
  1750. {
  1751. HRESULT status = NOERROR;
  1752. PBWREQ pBwReq;
  1753. ASSERT(GKIExists());
  1754. ASSERT(pGkiCall != NULL);
  1755. ISRTRACE(ghISRInst, CallStateName("GkiOpenChannel <- Call State = %s", pGkiCall->uGkiCallState), 0);
  1756. pBwReq = (PBWREQ)MemAlloc(sizeof(*pBwReq));
  1757. if (pBwReq == NULL)
  1758. {
  1759. ISRERROR(ghISRInst, "GkiOpenChannel: Memory allocation failed", 0);
  1760. return CC_NO_MEMORY;
  1761. }
  1762. pBwReq->uChannelBandwidth = uChannelBandwidth / 100;
  1763. pBwReq->hChannel = hChannel;
  1764. pBwReq->Type = Type;
  1765. BwReqEnqueue(pGkiCall, pBwReq);
  1766. switch (pGkiCall->uGkiCallState)
  1767. {
  1768. case GCS_WAITING:
  1769. case GCS_ADMITTING:
  1770. case GCS_CHANGING:
  1771. // Must wait for current operation to complete
  1772. break;
  1773. case GCS_ADMITTED:
  1774. status = CheckPendingBandwidth(pGkiCall);
  1775. break;
  1776. default:
  1777. ISRERROR(ghISRInst, "GkiOpenChannel: Invalid call state %d", pGkiCall->uGkiCallState);
  1778. status = CC_GKI_CALL_STATE;
  1779. } // switch
  1780. ISRTRACE(ghISRInst, CallStateName("GkiOpenChannel -> Call State = %s", pGkiCall->uGkiCallState), 0);
  1781. return status;
  1782. } // GkiOpenChannel()
  1783. /*
  1784. * NOTES
  1785. * Must have Call locked before calling!
  1786. */
  1787. HRESULT GkiCloseChannel(PGKICALL pGkiCall, unsigned uChannelBandwidth, CC_HCHANNEL hChannel)
  1788. {
  1789. PBWREQ pBwReq;
  1790. PBWREQ pBwReq1;
  1791. ASSERT(GKIExists());
  1792. ASSERT(pGkiCall != NULL);
  1793. ISRTRACE(ghISRInst, CallStateName("GkiCloseChannel <- Call State = %s", pGkiCall->uGkiCallState), 0);
  1794. // If Bandwidth request is still in queue, bandwidth has not been allocated
  1795. pBwReq = pGkiCall->pBwReqHead;
  1796. if (pBwReq)
  1797. {
  1798. if (pBwReq->hChannel == hChannel)
  1799. {
  1800. MemFree(BwReqDequeue(pGkiCall));
  1801. ISRTRACE(ghISRInst, CallStateName("GkiCloseChannel -> Call State = %s", pGkiCall->uGkiCallState), 0);
  1802. return NOERROR;
  1803. }
  1804. while ((pBwReq1 = pBwReq->pNext) != NULL)
  1805. {
  1806. if (pBwReq1->hChannel == hChannel)
  1807. {
  1808. if (pGkiCall->pBwReqTail == pBwReq1)
  1809. {
  1810. pGkiCall->pBwReqTail = pBwReq;
  1811. }
  1812. pBwReq->pNext = pBwReq1->pNext;
  1813. MemFree(pBwReq1);
  1814. ISRTRACE(ghISRInst, CallStateName("GkiCloseChannel -> Call State = %s", pGkiCall->uGkiCallState), 0);
  1815. return NOERROR;
  1816. }
  1817. }
  1818. }
  1819. pGkiCall->uBandwidthUsed -= (uChannelBandwidth / 100);
  1820. ISRTRACE(ghISRInst, CallStateName("GkiCloseChannel -> Call State = %s", pGkiCall->uGkiCallState), 0);
  1821. return NOERROR;
  1822. } // GkiCloseChannel()
  1823. unsigned GkiGetBandwidth(PGKICALL pGkiCall)
  1824. {
  1825. ASSERT(pGkiCall != NULL);
  1826. return pGkiCall->uBandwidthAllocated * 100;
  1827. } // GkiGetBandwidth()
  1828. //
  1829. // GkiWndProc subroutines
  1830. //
  1831. /*
  1832. * NOTES
  1833. * Must have Call locked before calling!
  1834. */
  1835. static HRESULT CheckPendingOpen(PGKICALL pGkiCall, void *pConference)
  1836. {
  1837. HRESULT status = NOERROR;
  1838. ASSERT(pGkiCall != NULL);
  1839. ASSERT(pConference != NULL);
  1840. switch (uGkiState)
  1841. {
  1842. case STATE_REGISTERED:
  1843. case STATE_REG_BYPASS:
  1844. // TBD - Can only open 1!!!
  1845. ASSERT(pGkiCall->uGkiCallState != GCS_ADMITTING);
  1846. if (pGkiCall->uGkiCallState == GCS_WAITING)
  1847. {
  1848. status = GkiOpenCall(pGkiCall, pConference);
  1849. }
  1850. break;
  1851. default:
  1852. status = LastGkiError;
  1853. } // switch
  1854. return status;
  1855. } // CheckPendingOpen()
  1856. static void GkiNoResponse(HWND hWnd)
  1857. {
  1858. HRESULT status;
  1859. switch (uGkiState)
  1860. {
  1861. case STATE_START:
  1862. case STATE_CLASS_REGISTERED:
  1863. case STATE_WINDOW_CREATED:
  1864. case STATE_REG_BYPASS:
  1865. break;
  1866. case STATE_REGISTERING:
  1867. case STATE_REGISTERING_REREG:
  1868. case STATE_REGISTERING_UNREG:
  1869. #if(0)
  1870. why did Intel *DO* this?????
  1871. ISRTRACE(ghISRInst, "GkiWndProc: dummy GKI_REG_REJECT", 0);
  1872. PostMessage(hWnd, GKIMAN_BASE + GKI_REG_REJECT, 0, 0);
  1873. #else
  1874. // there was no response to registration request, assume the GK is not there or dead.
  1875. uGkiState = STATE_REG_BYPASS;
  1876. if(gpRasNotifyProc)
  1877. {
  1878. (gpRasNotifyProc)(RAS_REG_TIMEOUT, 0);
  1879. }
  1880. ApplyToAllCalls(CheckPendingOpen);
  1881. #endif
  1882. break;
  1883. case STATE_ADMITTING:
  1884. case STATE_ADMITTING_REREG:
  1885. ApplyToAllCalls(GkiCancelAdmitting);
  1886. uGkiState = STATE_REGISTERED;
  1887. // Fall-through to next case
  1888. case STATE_REGISTERED:
  1889. if (uGkiCalls == 0)
  1890. {
  1891. GkiRegister();
  1892. }
  1893. else
  1894. {
  1895. uGkiState = STATE_REG_BYPASS;
  1896. ApplyToAllCalls(GatekeeperNotFound);
  1897. ISRTRACE(ghISRInst, "GKI_UnregistrationRequest called...", 0);
  1898. status = pGKI_UnregistrationRequest();
  1899. if (status == NOERROR)
  1900. {
  1901. ISRTRACE(ghISRInst, GkiErrorName("GKI_UnregistrationRequest returned %s", status), 0);
  1902. }
  1903. else
  1904. {
  1905. ISRERROR(ghISRInst, GkiErrorName("GKI_UnregistrationRequest returned %s", status), 0);
  1906. }
  1907. }
  1908. break;
  1909. case STATE_ADMITTING_UNREG:
  1910. ApplyToAllCalls(GkiCancelAdmitting);
  1911. uGkiState = STATE_REGISTERED;
  1912. GkiUnregister();
  1913. break;
  1914. case STATE_DISENGAGING:
  1915. ApplyToAllCalls(GatekeeperNotFound);
  1916. ASSERT(uGkiCalls == 0);
  1917. uGkiState = STATE_REGISTERED;
  1918. GkiUnregister();
  1919. break;
  1920. case STATE_DISENGAGING_REREG:
  1921. ApplyToAllCalls(GatekeeperNotFound);
  1922. ASSERT(uGkiCalls == 0);
  1923. uGkiState = STATE_REGISTERED;
  1924. GkiRegister();
  1925. break;
  1926. case STATE_UNREGISTERING:
  1927. case STATE_UNREGISTERING_REREG:
  1928. ISRTRACE(ghISRInst, "GkiWndProc: dummy GKI_UNREG_CONFIRM", 0);
  1929. PostMessage(hWnd, GKIMAN_BASE + GKI_UNREG_CONFIRM, 0, 0);
  1930. break;
  1931. default:
  1932. ISRERROR(ghISRInst, "GkiWndProc: Bad uGkiState %d", uGkiState);
  1933. } // switch
  1934. } // GkiNoResponse()
  1935. LRESULT APIENTRY GkiWndProc(
  1936. HWND hWnd, /* window handle */
  1937. UINT message, /* type of message */
  1938. WPARAM wParam, /* additional information */
  1939. LPARAM lParam) /* additional information */
  1940. {
  1941. CallReturnInfo * pCallReturnInfo;
  1942. PGKICALL pGkiCall;
  1943. void * pConference;
  1944. CC_HCALL hCall;
  1945. CC_HCONFERENCE hConference;
  1946. HRESULT status;
  1947. if (message < GKIMAN_BASE)
  1948. {
  1949. return DefWindowProc(hWnd, message, wParam, lParam);
  1950. }
  1951. EnterCallControlTop();
  1952. ISRTRACE(ghISRInst, StateName("GkiWndProc <- State = %s", uGkiState), 0);
  1953. switch (message)
  1954. {
  1955. case GKIMAN_BASE + GKI_REG_CONFIRM:
  1956. ISRTRACE(ghISRInst, "GkiWndProc: GKI_REG_CONFIRM", 0);
  1957. ASSERT(gpRasNotifyProc); // we should never get messages if
  1958. // this is not configured
  1959. if(gpRasNotifyProc)
  1960. {
  1961. (gpRasNotifyProc)(RAS_REG_CONFIRM, 0);
  1962. }
  1963. switch (uGkiState)
  1964. {
  1965. case STATE_REGISTERING:
  1966. uGkiState = STATE_REGISTERED;
  1967. ApplyToAllCalls(CheckPendingOpen);
  1968. break;
  1969. case STATE_REGISTERING_REREG:
  1970. uGkiState = STATE_REGISTERED;
  1971. GkiRegister();
  1972. break;
  1973. case STATE_REGISTERING_UNREG:
  1974. uGkiState = STATE_REGISTERED;
  1975. GkiUnregister();
  1976. break;
  1977. default:
  1978. ISRERROR(ghISRInst, StateName("GkiWndProc: GKI_REG_CONFIRM in state %s", uGkiState), 0);
  1979. } // switch
  1980. break;
  1981. case GKIMAN_BASE + GKI_REG_DISCOVERY:
  1982. ISRTRACE(ghISRInst, "GkiWndProc: GKI_REG_DISCOVERY", 0);
  1983. ASSERT(uGkiState == STATE_REGISTERING || uGkiState == STATE_REGISTERING_REREG || uGkiState == STATE_REGISTERING_UNREG);
  1984. break;
  1985. case GKIMAN_BASE + GKI_UNREG_REQUEST:
  1986. // the GK kicked us out!
  1987. // pass the unregistration request upward
  1988. ASSERT(gpRasNotifyProc); // we should never get messages if
  1989. // this is not configured
  1990. if(gpRasNotifyProc)
  1991. {
  1992. (gpRasNotifyProc)(RAS_UNREG_REQ, MapUnregistrationRequestReason((UINT)wParam));
  1993. }
  1994. break;
  1995. case GKIMAN_BASE + GKI_REG_REJECT:
  1996. ISRERROR(ghISRInst, "GkiWndProc: GKI_REG_REJECT Reason = %d", (DWORD)wParam);
  1997. switch (uGkiState)
  1998. {
  1999. case STATE_REGISTERING:
  2000. ApplyToAllCalls(GkiCancelCall);
  2001. #if(0)
  2002. // leave the listen list intact so that subsequent registration attempts
  2003. // will work.
  2004. //
  2005. EnterCriticalSection(&GkiLock);
  2006. while (pListenList)
  2007. {
  2008. register PLISTEN pListen = pListenList;
  2009. pListenList = pListen->pNext;
  2010. LeaveCriticalSection(&GkiLock);
  2011. ListenReject(pListen->hListen, MapRegistrationRejectReason((UINT)wParam));
  2012. if (pListen->pAliasNames)
  2013. {
  2014. FreeAliasNames(pListen->pAliasNames);
  2015. }
  2016. MemFree(pListen);
  2017. EnterCriticalSection(&GkiLock);
  2018. }
  2019. LeaveCriticalSection(&GkiLock);
  2020. #endif
  2021. uGkiState = STATE_WINDOW_CREATED;
  2022. // pass the registration reject upward
  2023. ASSERT(gpRasNotifyProc); // we should never get messages if
  2024. // this is not configured
  2025. if(gpRasNotifyProc)
  2026. {
  2027. (gpRasNotifyProc)(RAS_REJECTED, MapRegistrationRejectReason((UINT)wParam));
  2028. }
  2029. break;
  2030. case STATE_REGISTERING_REREG:
  2031. uGkiState = STATE_WINDOW_CREATED;
  2032. GkiRegister();
  2033. break;
  2034. case STATE_REGISTERING_UNREG:
  2035. uGkiState = STATE_WINDOW_CREATED;
  2036. GkiUnregister();
  2037. break;
  2038. default:
  2039. ISRERROR(ghISRInst, StateName("GkiWndProc: GKI_REG_REJECT in state %s", uGkiState), 0);
  2040. } // switch
  2041. break;
  2042. case GKIMAN_BASE + GKI_REG_BYPASS:
  2043. ISRTRACE(ghISRInst, "GkiWndProc: GKI_REG_BYPASS", 0);
  2044. switch (uGkiState)
  2045. {
  2046. case STATE_REGISTERING:
  2047. case STATE_REGISTERING_REREG:
  2048. uGkiState = STATE_REG_BYPASS;
  2049. ApplyToAllCalls(CheckPendingOpen);
  2050. break;
  2051. case STATE_REGISTERING_UNREG:
  2052. uGkiState = STATE_WINDOW_CREATED;
  2053. GkiUnregister();
  2054. break;
  2055. default:
  2056. ISRERROR(ghISRInst, StateName("GkiWndProc: GKI_REG_BYPASS in state %s", uGkiState), 0);
  2057. } // switch
  2058. break;
  2059. case GKIMAN_BASE + GKI_UNREG_CONFIRM:
  2060. ISRTRACE(ghISRInst, "GkiWndProc: GKI_UNREG_CONFIRM", 0);
  2061. ASSERT(gpRasNotifyProc); // we should never get messages if
  2062. // this is not configured
  2063. if(gpRasNotifyProc)
  2064. {
  2065. (gpRasNotifyProc)(RAS_UNREG_CONFIRM, 0);
  2066. }
  2067. switch (uGkiState)
  2068. {
  2069. case STATE_REGISTERING:
  2070. case STATE_REGISTERING_REREG:
  2071. case STATE_REGISTERED:
  2072. case STATE_ADMITTING:
  2073. case STATE_ADMITTING_REREG:
  2074. case STATE_DISENGAGING_REREG:
  2075. case STATE_UNREGISTERING_REREG:
  2076. uGkiState = STATE_WINDOW_CREATED;
  2077. GkiRegister();
  2078. break;
  2079. default:
  2080. ISRERROR(ghISRInst, StateName("GkiWndProc: GKI_UNREG_CONFIRM in state %s", uGkiState), 0);
  2081. // Fall through to next case
  2082. case STATE_ADMITTING_UNREG:
  2083. case STATE_DISENGAGING:
  2084. ApplyToAllCalls(GkiCancelCall);
  2085. // Fall-through to next case
  2086. case STATE_REGISTERING_UNREG:
  2087. case STATE_UNREGISTERING:
  2088. uGkiState = STATE_WINDOW_CREATED;
  2089. // Fall-through to next case
  2090. case STATE_CLASS_REGISTERED:
  2091. case STATE_WINDOW_CREATED:
  2092. // Fall-through to next case
  2093. case STATE_START:
  2094. case STATE_REG_BYPASS:
  2095. break;
  2096. } // switch
  2097. break;
  2098. case GKIMAN_BASE + GKI_UNREG_REJECT:
  2099. ISRERROR(ghISRInst, "GkiWndProc: GKI_UNREG_REJECT Reason = %d", (DWORD)wParam);
  2100. switch (uGkiState)
  2101. {
  2102. case STATE_UNREGISTERING:
  2103. uGkiState = STATE_WINDOW_CREATED;
  2104. GkiUnregister();
  2105. break;
  2106. case STATE_UNREGISTERING_REREG:
  2107. uGkiState = STATE_WINDOW_CREATED;
  2108. GkiRegister();
  2109. break;
  2110. default:
  2111. ISRWARNING(ghISRInst, StateName("GkiWndProc: GKI_UNREG_REJECT in state %s", uGkiState), 0);
  2112. } // switch
  2113. break;
  2114. case GKIMAN_BASE + GKI_ADM_CONFIRM:
  2115. ISRTRACE(ghISRInst, "GkiWndProc: GKI_ADM_CONFIRM", 0);
  2116. switch (uGkiState)
  2117. {
  2118. case STATE_ADMITTING:
  2119. uGkiState = STATE_REGISTERED;
  2120. pCallReturnInfo = (CallReturnInfo *) lParam;
  2121. if (LockGkiCallAndConference(GKI_ADMITTING_HANDLE, &pGkiCall, &pConference, &hCall, &hConference) == NOERROR)
  2122. {
  2123. ISRTRACE(ghISRInst, CallStateName("GkiWndProc: Call State = %s", pGkiCall->uGkiCallState), 0);
  2124. pGkiCall->usCallModelChoice = pCallReturnInfo->callModel.choice;
  2125. pGkiCall->uBandwidthAllocated = pCallReturnInfo->bandWidth;
  2126. pGkiCall->usCRV = pCallReturnInfo->callReferenceValue;
  2127. memcpy(pGkiCall->pConferenceId, pCallReturnInfo->conferenceID.value, 16);
  2128. switch (pGkiCall->uGkiCallState)
  2129. {
  2130. case GCS_ADMITTING:
  2131. GkiAllocCall(pGkiCall, pCallReturnInfo->hCall);
  2132. if (pGkiCall->bAnswerCall)
  2133. {
  2134. status = AcceptCallConfirm(pGkiCall->pCall, pConference);
  2135. }
  2136. else
  2137. {
  2138. ASSERT(pCallReturnInfo->destCallSignalAddress.choice == ipAddress_chosen);
  2139. pGkiCall->dwIpAddress = *((DWORD *)pCallReturnInfo->destCallSignalAddress.u.ipAddress.ip.value);
  2140. pGkiCall->wPort = pCallReturnInfo->destCallSignalAddress.u.ipAddress.port;
  2141. status = PlaceCallConfirm(pGkiCall->pCall, pConference);
  2142. }
  2143. if (status == NOERROR && ValidateCall(hCall) == NOERROR)
  2144. CheckPendingBandwidth(pGkiCall);
  2145. break;
  2146. case GCS_ADMITTING_CLOSE_PENDING:
  2147. GkiAllocCall(pGkiCall, pCallReturnInfo->hCall);
  2148. GkiCloseCall(pGkiCall);
  2149. break;
  2150. default:
  2151. ISRWARNING(ghISRInst, CallStateName("GkiWndProc: GKI_ADM_CONFIRM in call state %s", pGkiCall->uGkiCallState), 0);
  2152. } // switch
  2153. UnlockGkiCallAndConference(pGkiCall, pConference, hCall, hConference);
  2154. } // if
  2155. else
  2156. {
  2157. ISRWARNING(ghISRInst, "GkiWndProc: GKI_ADM_CONFIRM handle not found", 0);
  2158. }
  2159. ApplyToAllCalls(CheckPendingOpen);
  2160. break;
  2161. case STATE_ADMITTING_UNREG:
  2162. uGkiState = STATE_REGISTERED;
  2163. GkiUnregister();
  2164. break;
  2165. default:
  2166. ISRWARNING(ghISRInst, StateName("GkiWndProc: GKI_ADM_CONFIRM in state %s", uGkiState), 0);
  2167. } // switch
  2168. break;
  2169. case GKIMAN_BASE + GKI_ADM_REJECT:
  2170. ISRERROR(ghISRInst, "GkiWndProc: GKI_ADM_REJECT Reason = %d", (DWORD)wParam);
  2171. switch (uGkiState)
  2172. {
  2173. case STATE_ADMITTING:
  2174. pCallReturnInfo = (CallReturnInfo *) lParam;
  2175. if (LockGkiCallAndConference(GKI_ADMITTING_HANDLE, &pGkiCall, &pConference, &hCall, &hConference) == NOERROR)
  2176. {
  2177. ASSERT(pGkiCall->uGkiCallState == GCS_ADMITTING);
  2178. switch (wParam)
  2179. {
  2180. case AdmissionRejectReason_calledPartyNotRegistered_chosen:
  2181. if (pGkiCall->bAnswerCall)
  2182. {
  2183. // The gateway has gone away and come back without our notice!
  2184. GkiCancelAdmitting(pGkiCall, pConference);
  2185. uGkiState = STATE_REGISTERED;
  2186. GkiRegister();
  2187. ISRTRACE(ghISRInst, StateName("GkiWndProc -> State = %s", uGkiState), 0);
  2188. LeaveCallControlTop(0);
  2189. }
  2190. break;
  2191. case AdmissionRejectReason_callerNotRegistered_chosen:
  2192. if (pGkiCall->bAnswerCall == FALSE)
  2193. {
  2194. // The gateway has gone away and come back without our notice!
  2195. GkiCancelAdmitting(pGkiCall, pConference);
  2196. uGkiState = STATE_REGISTERED;
  2197. GkiRegister();
  2198. ISRTRACE(ghISRInst, StateName("GkiWndProc -> State = %s", uGkiState), 0);
  2199. LeaveCallControlTop(0);
  2200. }
  2201. } // switch
  2202. GkiFreeCall(pGkiCall);
  2203. if (pGkiCall->bAnswerCall)
  2204. AcceptCallReject(pGkiCall->pCall, pConference, MapAdmissionRejectReason((UINT)wParam));
  2205. else
  2206. PlaceCallReject (pGkiCall->pCall, pConference, MapAdmissionRejectReason((UINT)wParam));
  2207. UnlockGkiCallAndConference(pGkiCall, pConference, hCall, hConference);
  2208. } // if
  2209. else
  2210. {
  2211. ISRWARNING(ghISRInst, "GkiWndProc: GKI_ADM_REJECT handle not found", 0);
  2212. }
  2213. uGkiState = STATE_REGISTERED;
  2214. ApplyToAllCalls(CheckPendingOpen);
  2215. break;
  2216. case STATE_ADMITTING_REREG:
  2217. pCallReturnInfo = (CallReturnInfo *) lParam;
  2218. if (LockGkiCallAndConference(GKI_ADMITTING_HANDLE, &pGkiCall, &pConference, &hCall, &hConference) == NOERROR)
  2219. {
  2220. ASSERT(pGkiCall->uGkiCallState == GCS_ADMITTING_CLOSE_PENDING);
  2221. GkiFreeCall(pGkiCall);
  2222. if (pGkiCall->bAnswerCall)
  2223. {
  2224. AcceptCallReject(pGkiCall->pCall, pConference, MapAdmissionRejectReason((UINT)wParam));
  2225. }
  2226. else
  2227. {
  2228. PlaceCallReject (pGkiCall->pCall, pConference, MapAdmissionRejectReason((UINT)wParam));
  2229. }
  2230. UnlockGkiCallAndConference(pGkiCall, pConference, hCall, hConference);
  2231. } // if
  2232. else
  2233. {
  2234. ISRWARNING(ghISRInst, "GkiWndProc: GKI_ADM_REJECT handle not found", 0);
  2235. }
  2236. uGkiState = STATE_REGISTERED;
  2237. GkiRegister();
  2238. break;
  2239. case STATE_ADMITTING_UNREG:
  2240. pCallReturnInfo = (CallReturnInfo *) lParam;
  2241. if (LockGkiCallAndConference(GKI_ADMITTING_HANDLE, &pGkiCall, &pConference, &hCall, &hConference) == NOERROR)
  2242. {
  2243. ASSERT(pGkiCall->uGkiCallState == GCS_ADMITTING_CLOSE_PENDING);
  2244. GkiFreeCall(pGkiCall);
  2245. if (pGkiCall->bAnswerCall)
  2246. {
  2247. AcceptCallReject(pGkiCall->pCall, pConference, MapAdmissionRejectReason((UINT)wParam));
  2248. }
  2249. else
  2250. {
  2251. PlaceCallReject (pGkiCall->pCall, pConference, MapAdmissionRejectReason((UINT)wParam));
  2252. }
  2253. UnlockGkiCallAndConference(pGkiCall, pConference, hCall, hConference);
  2254. } // if
  2255. else
  2256. {
  2257. ISRWARNING(ghISRInst, "GkiWndProc: GKI_ADM_REJECT handle not found", 0);
  2258. }
  2259. uGkiState = STATE_REGISTERED;
  2260. GkiUnregister();
  2261. break;
  2262. default:
  2263. ISRWARNING(ghISRInst, StateName("GkiWndProc: GKI_ADM_REJECT in state %s", uGkiState), 0);
  2264. } // switch
  2265. break;
  2266. case GKIMAN_BASE + GKI_BW_CONFIRM:
  2267. ISRTRACE(ghISRInst, "GkiWndProc: GKI_BW_CONFIRM", 0);
  2268. switch (uGkiState)
  2269. {
  2270. case STATE_REGISTERED:
  2271. pCallReturnInfo = (CallReturnInfo *) lParam;
  2272. if (LockGkiCallAndConference(pCallReturnInfo->hCall, &pGkiCall, &pConference, &hCall, &hConference) == NOERROR)
  2273. {
  2274. ISRTRACE(ghISRInst, CallStateName("GkiWndProc: Call State = %s", pGkiCall->uGkiCallState), 0);
  2275. pGkiCall->uBandwidthAllocated = pCallReturnInfo->bandWidth;
  2276. switch (pGkiCall->uGkiCallState)
  2277. {
  2278. case GCS_ADMITTED:
  2279. if (pGkiCall->uBandwidthUsed < pGkiCall->uBandwidthAllocated)
  2280. {
  2281. BandwidthShrunk(pGkiCall->pCall,
  2282. pConference,
  2283. pGkiCall->uBandwidthAllocated,
  2284. ((long)pGkiCall->uBandwidthAllocated) - ((long)pGkiCall->uBandwidthUsed));
  2285. }
  2286. break;
  2287. case GCS_CHANGING:
  2288. pGkiCall->uGkiCallState = GCS_ADMITTED;
  2289. CheckPendingBandwidth(pGkiCall);
  2290. break;
  2291. case GCS_CHANGING_CLOSE_PENDING:
  2292. pGkiCall->uGkiCallState = GCS_ADMITTED;
  2293. GkiCloseCall(pGkiCall);
  2294. break;
  2295. default:
  2296. ISRWARNING(ghISRInst, CallStateName("GkiWndProc: GKI_BW_CONFIRM in call state %s", pGkiCall->uGkiCallState), 0);
  2297. } // switch
  2298. UnlockGkiCallAndConference(pGkiCall, pConference, hCall, hConference);
  2299. } // if
  2300. else
  2301. {
  2302. ISRWARNING(ghISRInst, "GkiWndProc: GKI_BW_CONFIRM handle not found", 0);
  2303. } // else
  2304. break;
  2305. default:
  2306. ISRERROR(ghISRInst, StateName("GkiWndProc: GKI_BW_CONFIRM in GKI state %s", uGkiState), 0);
  2307. } // switch
  2308. break;
  2309. case GKIMAN_BASE + GKI_BW_REJECT:
  2310. ISRERROR(ghISRInst, "GkiWndProc: GKI_BW_REJECT Reason = %d", (DWORD)wParam);
  2311. switch (uGkiState)
  2312. {
  2313. case STATE_REGISTERED:
  2314. pCallReturnInfo = (CallReturnInfo *) lParam;
  2315. if (LockGkiCallAndConference(pCallReturnInfo->hCall, &pGkiCall, &pConference, &hCall, &hConference) == NOERROR)
  2316. {
  2317. ISRTRACE(ghISRInst, CallStateName("GkiWndProc: Call State = %s", pGkiCall->uGkiCallState), 0);
  2318. pGkiCall->uBandwidthAllocated = pCallReturnInfo->bandWidth;
  2319. switch (pGkiCall->uGkiCallState)
  2320. {
  2321. case GCS_CHANGING:
  2322. pGkiCall->uGkiCallState = GCS_ADMITTED;
  2323. BandwidthRejected(pGkiCall, (UINT)wParam);
  2324. if (ValidateCall(hCall) == NOERROR)
  2325. {
  2326. CheckPendingBandwidth(pGkiCall);
  2327. }
  2328. break;
  2329. case GCS_CHANGING_CLOSE_PENDING:
  2330. pGkiCall->uGkiCallState = GCS_ADMITTED;
  2331. GkiCloseCall(pGkiCall);
  2332. break;
  2333. default:
  2334. ISRERROR(ghISRInst, CallStateName("GkiWndProc: GKI_BW_REJECT in state %s", pGkiCall->uGkiCallState), 0);
  2335. } // switch
  2336. UnlockGkiCallAndConference(pGkiCall, pConference, hCall, hConference);
  2337. } // if
  2338. else
  2339. {
  2340. ISRWARNING(ghISRInst, "GkiWndProc: GKI_BW_REJECT handle not found", 0);
  2341. }
  2342. break;
  2343. default:
  2344. ISRERROR(ghISRInst, StateName("GkiWndProc: GKI_BW_REJECT in state %s", uGkiState), 0);
  2345. } // switch
  2346. break;
  2347. case GKIMAN_BASE + GKI_DISENG_CONFIRM:
  2348. ISRTRACE(ghISRInst, "GkiWndProc: GKI_DISENG_CONFIRM", 0);
  2349. if (LockGkiCall((HANDLE)lParam, &pGkiCall) == NOERROR)
  2350. {
  2351. ISRTRACE(ghISRInst, CallStateName("GkiWndProc: Call State = %s", pGkiCall->uGkiCallState), 0);
  2352. switch (pGkiCall->uGkiCallState)
  2353. {
  2354. case GCS_DISENGAGING:
  2355. --uPendingDisengages;
  2356. break;
  2357. default:
  2358. ISRWARNING(ghISRInst, CallStateName("GkiWndProc: GKI_DISENG_CONFIRM in call state %s", pGkiCall->uGkiCallState), 0);
  2359. } // switch
  2360. GkiFreeCall(pGkiCall);
  2361. Disengage(pGkiCall->pCall);
  2362. } // if
  2363. else if (uPendingDisengages != 0)
  2364. {
  2365. --uPendingDisengages;
  2366. if (uPendingDisengages == 0)
  2367. {
  2368. switch (uGkiState)
  2369. {
  2370. case STATE_DISENGAGING:
  2371. uGkiState = STATE_REGISTERED;
  2372. GkiUnregister();
  2373. break;
  2374. case STATE_DISENGAGING_REREG:
  2375. uGkiState = STATE_REGISTERED;
  2376. GkiRegister();
  2377. break;
  2378. } // switch
  2379. } // if
  2380. } // else if
  2381. else
  2382. {
  2383. ISRWARNING(ghISRInst, "GkiWndProc: GKI_DISENG_CONFIRM handle not found", 0);
  2384. }
  2385. break;
  2386. case GKIMAN_BASE + GKI_DISENG_REJECT:
  2387. ISRERROR(ghISRInst, "GkiWndProc: GKI_DISENG_REJECT Reason = %d", (DWORD)wParam);
  2388. if (LockGkiCall((HANDLE)lParam, &pGkiCall) == NOERROR)
  2389. {
  2390. ISRTRACE(ghISRInst, CallStateName("GkiWndProc: Call State = %s", pGkiCall->uGkiCallState), 0);
  2391. switch (pGkiCall->uGkiCallState)
  2392. {
  2393. case GCS_DISENGAGING:
  2394. // Pretend we received a Disengage Confirm
  2395. --uPendingDisengages;
  2396. break;
  2397. default:
  2398. ISRERROR(ghISRInst, CallStateName("GkiWndProc: GKI_DISENG_REJECT in call state %s", pGkiCall->uGkiCallState), 0);
  2399. } // switch
  2400. GkiFreeCall(pGkiCall);
  2401. Disengage(pGkiCall->pCall);
  2402. } // if
  2403. else if (uPendingDisengages != 0)
  2404. {
  2405. // Pretend we received a Disengage Confirm
  2406. --uPendingDisengages;
  2407. if (uPendingDisengages == 0)
  2408. {
  2409. switch (uGkiState)
  2410. {
  2411. case STATE_DISENGAGING:
  2412. uGkiState = STATE_REGISTERED;
  2413. GkiUnregister();
  2414. break;
  2415. case STATE_DISENGAGING_REREG:
  2416. uGkiState = STATE_REGISTERED;
  2417. GkiRegister();
  2418. break;
  2419. } // switch
  2420. } // if
  2421. } // else if
  2422. else
  2423. {
  2424. ISRWARNING(ghISRInst, "GkiWndProc: GKI_DISENG_REJECT handle not found", 0);
  2425. }
  2426. break;
  2427. case GKIMAN_BASE + GKI_LOCATION_CONFIRM:
  2428. ISRTRACE(ghISRInst, "GkiWndProc: GKI_LOCATION_CONFIRM", 0);
  2429. break;
  2430. case GKIMAN_BASE + GKI_LOCATION_REJECT:
  2431. ISRERROR(ghISRInst, "GkiWndProc: GKI_LOCATION_REJECT Reason = %d", (DWORD)wParam);
  2432. break;
  2433. case GKIMAN_BASE + GKI_ERROR:
  2434. ISRERROR(ghISRInst, GkiErrorName("GkiWndProc: GKI_ERROR %s %%d", (HRESULT)lParam), (DWORD)wParam);
  2435. switch (lParam)
  2436. {
  2437. case GKI_NO_RESPONSE:
  2438. LastGkiError = (HRESULT)lParam;
  2439. GkiNoResponse(hWnd);
  2440. break;
  2441. #if 1
  2442. // TEMPORARY KLUDGE FOR WINSOCK 2 BETA 1.6 OPERATION
  2443. case MAKE_CUSTOM_HRESULT(SEVERITY_ERROR,1,FACILITY_WINSOCK,0xffff):
  2444. uGkiState = STATE_REG_BYPASS;
  2445. ApplyToAllCalls(CheckPendingOpen);
  2446. break;
  2447. #endif
  2448. default:
  2449. LastGkiError = (HRESULT)lParam;
  2450. GkiUnregister();
  2451. } // switch
  2452. break;
  2453. default:
  2454. ISRERROR(ghISRInst, "Unknown message %d", message);
  2455. } // switch
  2456. ISRTRACE(ghISRInst, StateName("GkiWndProc -> State = %s", uGkiState), 0);
  2457. LeaveCallControlTop(0);
  2458. } // GkiWndProc()
  2459. // because the ASN.1 header files are not exposed and there is a redefinition of
  2460. // RAS reason codes, make sure that the mapping is correct. The functions herien
  2461. // assume equality and don't actually do any remapping.
  2462. // break the build if the definitions don't match !!!
  2463. #if (discoveryRequired_chosen != RRJ_DISCOVERY_REQ)
  2464. #error "Registration reject reason code definitions mismatch!! GO back and FIX IT!!"
  2465. #endif
  2466. #if (RegistrationRejectReason_invalidRevision_chosen != RRJ_INVALID_REVISION)
  2467. #error "Registration reject reason code definitions mismatch!! GO back and FIX IT!!"
  2468. #endif
  2469. #if (invalidCallSignalAddress_chosen != RRJ_INVALID_CALL_ADDR)
  2470. #error "Registration reject reason code definitions mismatch!! GO back and FIX IT!!"
  2471. #endif
  2472. #if (invalidRASAddress_chosen != RRJ_INVALID_RAS_ADDR)
  2473. #error "Registration reject reason code definitions mismatch!! GO back and FIX IT!!"
  2474. #endif
  2475. #if (duplicateAlias_chosen != RRJ_DUPLICATE_ALIAS)
  2476. #error "Registration reject reason code definitions mismatch!! GO back and FIX IT!!"
  2477. #endif
  2478. #if (invalidTerminalType_chosen != RRJ_INVALID_TERMINAL_TYPE)
  2479. #error "Registration reject reason code definitions mismatch!! GO back and FIX IT!!"
  2480. #endif
  2481. #if (RegistrationRejectReason_undefinedReason_chosen != RRJ_UNDEFINED)
  2482. #error "Registration reject reason code definitions mismatch!! GO back and FIX IT!!"
  2483. #endif
  2484. #if (transportNotSupported_chosen != RRJ_TRANSPORT_NOT_SUPPORTED)
  2485. #error "Registration reject reason code definitions mismatch!! GO back and FIX IT!!"
  2486. #endif
  2487. #if (transportQOSNotSupported_chosen != RRJ_TRANSPORT_QOS_NOT_SUPPORTED)
  2488. #error "Registration reject reason code definitions mismatch!! GO back and FIX IT!!"
  2489. #endif
  2490. #if (RegistrationRejectReason_resourceUnavailable_chosen != RRJ_RESOURCE_UNAVAILABLE)
  2491. #error "Registration reject reason code definitions mismatch!! GO back and FIX IT!!"
  2492. #endif
  2493. #if (invalidAlias_chosen != RRJ_INVALID_ALIAS)
  2494. #error "Registration reject reason code definitions mismatch!! GO back and FIX IT!!"
  2495. #endif
  2496. #if (RegistrationRejectReason_securityDenial_chosen != RRJ_SECURITY_DENIAL)
  2497. #error "Registration reject reason code definitions mismatch!! GO back and FIX IT!!"
  2498. #endif
  2499. // reason codes for GK initiated URQ
  2500. #if(reregistrationRequired_chosen != URQ_REREG_REQUIRED)
  2501. #error "UnregRequestReason code definitions mismatch!! GO back and FIX IT!!"
  2502. #endif
  2503. #if(ttlExpired_chosen != URQ_TTL_EXPIRED)
  2504. #error "UnregRequestReason code definitions mismatch!! GO back and FIX IT!!"
  2505. #endif
  2506. #if(UnregRequestReason_securityDenial_chosen != URQ_SECURITY_DENIAL)
  2507. #error "UnregRequestReason code definitions mismatch!! GO back and FIX IT!!"
  2508. #endif
  2509. #if(UnregRequestReason_undefinedReason_chosen != URQ_UNDEFINED)
  2510. #error "UnregRequestReason code definitions mismatch!! GO back and FIX IT!!"
  2511. #endif
  2512. #if(AdmissionRejectReason_calledPartyNotRegistered_chosen != ARJ_CALLEE_NOT_REGISTERED)
  2513. #error "AdmissionRejectReason code definitions mismatch!! GO back and FIX IT!!"
  2514. #endif
  2515. #if(AdmissionRejectReason_invalidPermission_chosen != ARJ_INVALID_PERMISSION)
  2516. #error "AdmissionRejectReason code definitions mismatch!! GO back and FIX IT!!"
  2517. #endif
  2518. #if(AdmissionRejectReason_requestDenied_chosen != ARJ_REQUEST_DENIED)
  2519. #error "AdmissionRejectReason code definitions mismatch!! GO back and FIX IT!!"
  2520. #endif
  2521. #if(AdmissionRejectReason_undefinedReason_chosen != ARJ_UNDEFINED)
  2522. #error "AdmissionRejectReason code definitions mismatch!! GO back and FIX IT!!"
  2523. #endif
  2524. #if(AdmissionRejectReason_callerNotRegistered_chosen != ARJ_CALLER_NOT_REGISTERED)
  2525. #error "AdmissionRejectReason code definitions mismatch!! GO back and FIX IT!!"
  2526. #endif
  2527. #if(AdmissionRejectReason_routeCallToGatekeeper_chosen != ARJ_ROUTE_TO_GK)
  2528. #error "AdmissionRejectReason code definitions mismatch!! GO back and FIX IT!!"
  2529. #endif
  2530. #if(invalidEndpointIdentifier_chosen != ARJ_INVALID_ENDPOINT_ID)
  2531. #error "AdmissionRejectReason code definitions mismatch!! GO back and FIX IT!!"
  2532. #endif
  2533. #if(AdmissionRejectReason_resourceUnavailable_chosen != ARJ_RESOURCE_UNAVAILABLE)
  2534. #error "AdmissionRejectReason code definitions mismatch!! GO back and FIX IT!!"
  2535. #endif
  2536. #if(AdmissionRejectReason_securityDenial_chosen != ARJ_SECURTY_DENIAL)
  2537. #error "AdmissionRejectReason code definitions mismatch!! GO back and FIX IT!!"
  2538. #endif
  2539. #if(qosControlNotSupported_chosen != ARJ_QOS_CONTROL_NOT_SUPPORTED)
  2540. #error "AdmissionRejectReason code definitions mismatch!! GO back and FIX IT!!"
  2541. #endif
  2542. #if(incompleteAddress_chosen != ARJ_INCOMPLETE_ADDRESS)
  2543. #error "AdmissionRejectReason code definitions mismatch!! GO back and FIX IT!!"
  2544. #endif
  2545. #if(reregistrationRequired_chosen != URQ_REREG_REQUIRED)
  2546. #error "UnregistrationRequest code definitions mismatch!! GO back and FIX IT!!"
  2547. #endif
  2548. #if(ttlExpired_chosen != URQ_TTL_EXPIRED)
  2549. #error "UnregistrationRequest code definitions mismatch!! GO back and FIX IT!!"
  2550. #endif
  2551. #if(UnregRequestReason_securityDenial_chosen != URQ_SECURITY_DENIAL)
  2552. #error "UnregistrationRequest code definitions mismatch!! GO back and FIX IT!!"
  2553. #endif
  2554. #if(UnregRequestReason_undefinedReason_chosen != URQ_UNDEFINED)
  2555. #error "UnregistrationRequest code definitions mismatch!! GO back and FIX IT!!"
  2556. #endif
  2557. #else // GATEKEEPER
  2558. static char ch; // Kludge around warning C4206: nonstandard extension used : translation unit is empty
  2559. #endif // GATEKEEPER