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.

2952 lines
84 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. return status;
  1270. }
  1271. }
  1272. else
  1273. {
  1274. pListen->pAliasNames = NULL;
  1275. }
  1276. pListen->hListen = hListen;
  1277. pListen->dwAddr = htonl(dwAddr);
  1278. pListen->wPort = wPort;
  1279. ListenEnqueue(pListen);
  1280. if(GKIExists())
  1281. {
  1282. status = GkiRegister();
  1283. }
  1284. } // if
  1285. else
  1286. {
  1287. ISRERROR(ghISRInst, "GkiOpenListen: Could not allocate listen structure", 0);
  1288. status = CC_NO_MEMORY;
  1289. } // else
  1290. LeaveCriticalSection(&GkiLock);
  1291. ISRTRACE(ghISRInst, StateName("GkiOpenListen -> State = %s", uGkiState), 0);
  1292. return status;
  1293. } // GkiOpenListen()
  1294. HRESULT GkiListenAddr (SOCKADDR_IN* psin)
  1295. {
  1296. PLISTEN pListen = pListenList;
  1297. HRESULT status = NOERROR;
  1298. SOCKADDR_IN srem;
  1299. SOCKADDR_IN sloc;
  1300. ASSERT(psin);
  1301. ASSERT(pListen != NULL);
  1302. // try and get the best interface given the dwAddr passed in to us
  1303. srem.sin_family = AF_INET;
  1304. srem.sin_port = htons(7); // give echo a try since most GKs are unix-based
  1305. srem.sin_addr.s_addr = psin->sin_addr.s_addr;
  1306. status = NMGetBestInterface(&srem, &sloc);
  1307. if (status == NOERROR)
  1308. {
  1309. EnterCriticalSection(&GkiLock);
  1310. while (pListen)
  1311. {
  1312. pListen->dwAddr = sloc.sin_addr.s_addr;
  1313. pListen = pListen->pNext;
  1314. }
  1315. LeaveCriticalSection(&GkiLock);
  1316. }
  1317. return status;
  1318. } // GkiListenAddr()
  1319. /*
  1320. * NOTES
  1321. * Must have Call locked before calling!
  1322. */
  1323. HRESULT GkiCloseCall(PGKICALL pGkiCall)
  1324. {
  1325. HRESULT status = NOERROR;
  1326. ASSERT(GKIExists());
  1327. ASSERT(pGkiCall != NULL);
  1328. ISRTRACE(ghISRInst, CallStateName("GkiCloseCall <- Call State = %s", pGkiCall->uGkiCallState), 0);
  1329. while (pGkiCall->pBwReqHead)
  1330. {
  1331. MemFree(BwReqDequeue(pGkiCall));
  1332. }
  1333. if (pGkiCall->uGkiCallState == GCS_START)
  1334. {
  1335. ISRWARNING(ghISRInst, CallStateName("GkiCloseCall: Call already in state %s", pGkiCall->uGkiCallState), 0);
  1336. status = CC_GKI_CALL_STATE;
  1337. }
  1338. else
  1339. {
  1340. switch (uGkiState)
  1341. {
  1342. case STATE_START:
  1343. break;
  1344. case STATE_REG_BYPASS:
  1345. status = GkiFreeCall(pGkiCall);
  1346. break;
  1347. default:
  1348. switch (pGkiCall->uGkiCallState)
  1349. {
  1350. case GCS_WAITING:
  1351. status = GkiFreeCall(pGkiCall);
  1352. break;
  1353. case GCS_ADMITTING:
  1354. pGkiCall->uGkiCallState = GCS_ADMITTING_CLOSE_PENDING;
  1355. break;
  1356. case GCS_ADMITTING_CLOSE_PENDING:
  1357. case GCS_CHANGING_CLOSE_PENDING:
  1358. case GCS_DISENGAGING:
  1359. ISRWARNING(ghISRInst, CallStateName("GkiCloseCall: Call already in closing state %s", pGkiCall->uGkiCallState), 0);
  1360. status = CC_GKI_CALL_STATE;
  1361. break;
  1362. case GCS_ADMITTED:
  1363. pGkiCall->uGkiCallState = GCS_DISENGAGING;
  1364. ISRTRACE(ghISRInst, "GKI_DisengageRequest called...", 0);
  1365. ++uPendingDisengages;
  1366. status = pGKI_DisengageRequest(pGkiCall->hGkiCall);
  1367. if (status == NOERROR)
  1368. {
  1369. ISRTRACE(ghISRInst, GkiErrorName("GKI_DisengageRequest returned %s", status), 0);
  1370. }
  1371. else
  1372. {
  1373. --uPendingDisengages;
  1374. ISRERROR(ghISRInst, GkiErrorName("GKI_DisengageRequest returned %s", status), 0);
  1375. GkiFreeCall(pGkiCall);
  1376. }
  1377. break;
  1378. case GCS_CHANGING:
  1379. pGkiCall->uGkiCallState = GCS_CHANGING_CLOSE_PENDING;
  1380. break;
  1381. default:
  1382. ISRERROR(ghISRInst, CallStateName("GkiCloseCall: Call in invalid state %s", pGkiCall->uGkiCallState), 0);
  1383. status = CC_GKI_CALL_STATE;
  1384. } // switch
  1385. } // switch
  1386. } // else
  1387. ISRTRACE(ghISRInst, StateName("GkiCloseCall -> State = %s", uGkiState), 0);
  1388. return status;
  1389. } // GkiCloseCall()
  1390. /*
  1391. * NOTES
  1392. * Must have Call locked before calling!
  1393. */
  1394. static HRESULT BandwidthRejected(PGKICALL pGkiCall, UINT Reason)
  1395. {
  1396. HRESULT status = NOERROR;
  1397. PBWREQ pBwReq;
  1398. CC_HCALL hCall;
  1399. ASSERT(pGkiCall != NULL);
  1400. pBwReq = BwReqDequeue(pGkiCall);
  1401. hCall = pGkiCall->hCall;
  1402. if (pBwReq)
  1403. {
  1404. if ((pGkiCall->uBandwidthUsed + pBwReq->uChannelBandwidth) <= pGkiCall->uBandwidthAllocated)
  1405. {
  1406. if (pBwReq->Type == TX)
  1407. {
  1408. OpenChannelConfirm (pBwReq->hChannel);
  1409. }
  1410. else
  1411. {
  1412. AcceptChannelConfirm(pBwReq->hChannel);
  1413. }
  1414. }
  1415. else
  1416. {
  1417. if (pBwReq->Type == TX)
  1418. {
  1419. OpenChannelReject (pBwReq->hChannel, MapBandwidthRejectReason(Reason));
  1420. }
  1421. else
  1422. {
  1423. AcceptChannelReject (pBwReq->hChannel, MapBandwidthRejectReason(Reason));
  1424. }
  1425. }
  1426. MemFree(pBwReq);
  1427. if (ValidateCall(hCall) == NOERROR)
  1428. {
  1429. CheckPendingBandwidth(pGkiCall);
  1430. }
  1431. }
  1432. return status;
  1433. } // BandwidthRejected()
  1434. /*
  1435. * NOTES
  1436. * Must have Call locked before calling!
  1437. */
  1438. static HRESULT CheckPendingBandwidth(PGKICALL pGkiCall)
  1439. {
  1440. HRESULT status = NOERROR;
  1441. PBWREQ pBwReq;
  1442. CC_HCALL hCall;
  1443. ASSERT(pGkiCall != NULL);
  1444. ASSERT(pGkiCall->uGkiCallState == GCS_ADMITTED);
  1445. hCall = pGkiCall->hCall;
  1446. while (pGkiCall->pBwReqHead != NULL &&
  1447. (pGkiCall->uBandwidthUsed + pGkiCall->pBwReqHead->uChannelBandwidth) <= pGkiCall->uBandwidthAllocated)
  1448. {
  1449. pBwReq = BwReqDequeue(pGkiCall);
  1450. ASSERT(pBwReq != NULL);
  1451. pGkiCall->uBandwidthUsed += pBwReq->uChannelBandwidth;
  1452. if (pBwReq->Type == TX)
  1453. {
  1454. OpenChannelConfirm(pBwReq->hChannel);
  1455. }
  1456. else
  1457. {
  1458. AcceptChannelConfirm(pBwReq->hChannel);
  1459. }
  1460. MemFree(pBwReq);
  1461. if (ValidateCall(hCall) != NOERROR)
  1462. {
  1463. return status;
  1464. }
  1465. }
  1466. if (pGkiCall->pBwReqHead != NULL)
  1467. {
  1468. pGkiCall->uGkiCallState = GCS_CHANGING;
  1469. ISRTRACE(ghISRInst, "GKI_BandwidthRequest called...", 0);
  1470. status = pGKI_BandwidthRequest(pGkiCall->hGkiCall,
  1471. pGkiCall->usCallTypeChoice,
  1472. pGkiCall->uBandwidthUsed + pGkiCall->pBwReqHead->uChannelBandwidth);
  1473. if (status == NOERROR)
  1474. {
  1475. ISRTRACE(ghISRInst, GkiErrorName("GKI_BandwidthRequest returned %s", status), 0);
  1476. }
  1477. else
  1478. {
  1479. ISRERROR(ghISRInst, GkiErrorName("GKI_BandwidthRequest returned %s", status), 0);
  1480. BandwidthRejected(pGkiCall, BndRjctRsn_undfndRsn_chosen);
  1481. }
  1482. }
  1483. return status;
  1484. } // CheckPendingBandwidth()
  1485. static void FreeAliasList(SeqAliasAddr *pAliasAddrs)
  1486. {
  1487. register SeqAliasAddr *pAlias = pAliasAddrs;
  1488. while (pAlias)
  1489. {
  1490. if (pAlias->value.choice == h323_ID_chosen && pAlias->value.u.h323_ID.value)
  1491. MemFree(pAlias->value.u.h323_ID.value);
  1492. pAlias = pAlias->next;
  1493. }
  1494. MemFree(pAlias);
  1495. } // FreeAliasList()
  1496. /*
  1497. * NOTES
  1498. * Must have Call locked before calling!
  1499. *
  1500. * The following fields in the GKICALL structure must be properly filled
  1501. * in before calling this function:
  1502. * pCall Pointer back to containing CALL structure.
  1503. * CallType Type of call.
  1504. * uBandwidthRequested Initial bandwidth for call.
  1505. * pConferenceId Pointer to conference ID buffer.
  1506. * bActiveMC TRUE if calling party has an active MC.
  1507. * bAnswerCall ???
  1508. * CallIdentifier the GUID identifying this call. This must be the same
  1509. * value as CallIdentifier of the Q.931 messages.
  1510. */
  1511. HRESULT GkiOpenCall (PGKICALL pGkiCall, void *pConference)
  1512. {
  1513. HRESULT status = NOERROR;
  1514. CC_HCALL hCall;
  1515. TransportAddress DestCallSignalAddress;
  1516. TransportAddress * pDestCallSignalAddress;
  1517. SeqAliasAddr * pAliasAddrs;
  1518. SeqAliasAddr * pExtraAliasAddrs;
  1519. SeqAliasAddr * pAlias;
  1520. PCC_ALIASITEM pAliasItem;
  1521. unsigned uCount;
  1522. unsigned uIndex;
  1523. ConferenceIdentifier ConferenceId;
  1524. ASSERT(GKIExists());
  1525. ASSERT(pGkiCall != NULL);
  1526. ASSERT(pConference != NULL);
  1527. ISRTRACE(ghISRInst, StateName("GkiOpenCall <- State = %s", uGkiState), 0);
  1528. EnterCriticalSection(&GkiLock);
  1529. switch (uGkiState)
  1530. {
  1531. case STATE_REG_BYPASS:
  1532. ASSERT(pGkiCall->uGkiCallState == GCS_START || pGkiCall->uGkiCallState == GCS_WAITING || pGkiCall->uGkiCallState == GCS_ADMITTING);
  1533. hCall = pGkiCall->hCall;
  1534. GkiAllocCall(pGkiCall, GKI_BYPASS_HANDLE);
  1535. pGkiCall->uBandwidthAllocated = MAX_BANDWIDTH;
  1536. if (pGkiCall->bAnswerCall)
  1537. {
  1538. status = AcceptCallConfirm(pGkiCall->pCall, pConference);
  1539. if (status == NOERROR && ValidateCall(hCall) == NOERROR)
  1540. {
  1541. CheckPendingBandwidth(pGkiCall);
  1542. }
  1543. }
  1544. else if (pGkiCall->dwIpAddress == 0)
  1545. {
  1546. status = PlaceCallReject (pGkiCall->pCall, pConference, CC_INVALID_WITHOUT_GATEKEEPER);
  1547. }
  1548. else
  1549. {
  1550. status = PlaceCallConfirm (pGkiCall->pCall, pConference);
  1551. if (status == NOERROR && ValidateCall(hCall) == NOERROR)
  1552. {
  1553. CheckPendingBandwidth(pGkiCall);
  1554. }
  1555. }
  1556. break;
  1557. case STATE_REGISTERING:
  1558. case STATE_REGISTERING_REREG:
  1559. case STATE_ADMITTING:
  1560. pGkiCall->uGkiCallState = GCS_WAITING;
  1561. break;
  1562. case STATE_REGISTERED:
  1563. switch (pGkiCall->CallType)
  1564. {
  1565. case POINT_TO_POINT:
  1566. pGkiCall->usCallTypeChoice = pointToPoint_chosen;
  1567. break;
  1568. case ONE_TO_MANY:
  1569. pGkiCall->usCallTypeChoice = oneToN_chosen;
  1570. break;
  1571. case MANY_TO_ONE:
  1572. pGkiCall->usCallTypeChoice = nToOne_chosen;
  1573. break;
  1574. case MANY_TO_MANY:
  1575. pGkiCall->usCallTypeChoice = nToN_chosen;
  1576. break;
  1577. default:
  1578. LeaveCriticalSection(&GkiLock);
  1579. ISRERROR(ghISRInst, "GkiOpenCall -> Invalid CallType %d", pGkiCall->CallType);
  1580. return CC_BAD_PARAM;
  1581. } // switch
  1582. pDestCallSignalAddress = NULL;
  1583. pAliasAddrs = NULL;
  1584. pExtraAliasAddrs = NULL;
  1585. if (pGkiCall->dwIpAddress != 0 && pGkiCall->wPort != 0)
  1586. {
  1587. DestCallSignalAddress.choice = ipAddress_chosen;
  1588. DestCallSignalAddress.u.ipAddress.ip.length = 4;
  1589. *((DWORD *)DestCallSignalAddress.u.ipAddress.ip.value) = pGkiCall->dwIpAddress;
  1590. DestCallSignalAddress.u.ipAddress.port = pGkiCall->wPort;
  1591. pDestCallSignalAddress = &DestCallSignalAddress;
  1592. }
  1593. if (pGkiCall->pCalleeAliasNames)
  1594. {
  1595. uCount = pGkiCall->pCalleeAliasNames->wCount;
  1596. pAliasAddrs = MemAlloc(uCount * sizeof(*pAliasAddrs));
  1597. if (pAliasAddrs == NULL)
  1598. {
  1599. LeaveCriticalSection(&GkiLock);
  1600. ISRERROR(ghISRInst, "GkiOpenCall: Could not allocate %d Alias Addresses", uCount);
  1601. return CC_NO_MEMORY;
  1602. }
  1603. memset(pAliasAddrs, 0, uCount * sizeof(*pAliasAddrs));
  1604. pAlias = pAliasAddrs;
  1605. pAliasItem = pGkiCall->pCalleeAliasNames->pItems;
  1606. for (uIndex = 0; uIndex < uCount; ++uIndex)
  1607. {
  1608. status = CopyAliasItem(pAlias, pAliasItem);
  1609. if (status != NOERROR)
  1610. {
  1611. LeaveCriticalSection(&GkiLock);
  1612. ISRERROR(ghISRInst, "GkiOpenCall: CopyAliasItem returned %d", status);
  1613. FreeAliasList(pAliasAddrs);
  1614. MemFree(pAliasAddrs);
  1615. return status;
  1616. }
  1617. pAlias->next = pAlias + 1;
  1618. ++pAlias;
  1619. ++pAliasItem;
  1620. } // for
  1621. --pAlias;
  1622. pAlias->next = NULL;
  1623. }
  1624. if (pGkiCall->pCalleeExtraAliasNames)
  1625. {
  1626. uCount = pGkiCall->pCalleeExtraAliasNames->wCount;
  1627. pExtraAliasAddrs = MemAlloc(uCount * sizeof(*pExtraAliasAddrs));
  1628. if (pExtraAliasAddrs == NULL)
  1629. {
  1630. LeaveCriticalSection(&GkiLock);
  1631. ISRERROR(ghISRInst, "GkiOpenCall: Could not allocate %d Alias Addresses", uCount);
  1632. if (pAliasAddrs)
  1633. {
  1634. FreeAliasList(pAliasAddrs);
  1635. MemFree(pAliasAddrs);
  1636. }
  1637. return CC_NO_MEMORY;
  1638. }
  1639. memset(pExtraAliasAddrs, 0, uCount * sizeof(*pExtraAliasAddrs));
  1640. pAlias = pExtraAliasAddrs;
  1641. pAliasItem = pGkiCall->pCalleeExtraAliasNames->pItems;
  1642. for (uIndex = 0; uIndex < uCount; ++uIndex)
  1643. {
  1644. status = CopyAliasItem(pAlias, pAliasItem);
  1645. if (status != NOERROR)
  1646. {
  1647. LeaveCriticalSection(&GkiLock);
  1648. ISRERROR(ghISRInst, "GkiOpenCall: CopyAliasItem returned %d", status);
  1649. if (pAliasAddrs)
  1650. {
  1651. FreeAliasList(pAliasAddrs);
  1652. MemFree(pAliasAddrs);
  1653. }
  1654. FreeAliasList(pExtraAliasAddrs);
  1655. MemFree(pExtraAliasAddrs);
  1656. return status;
  1657. }
  1658. pAlias->next = pAlias + 1;
  1659. ++pAlias;
  1660. ++pAliasItem;
  1661. } // for
  1662. --pAlias;
  1663. pAlias->next = NULL;
  1664. }
  1665. if (pGkiCall->uBandwidthRequested < MIN_BANDWIDTH)
  1666. {
  1667. pGkiCall->uBandwidthRequested = MIN_BANDWIDTH;
  1668. }
  1669. ASSERT(pGkiCall->uBandwidthAllocated == 0);
  1670. ASSERT(pGkiCall->uBandwidthUsed == 0);
  1671. memcpy(ConferenceId.value, pGkiCall->pConferenceId, 16);
  1672. if (((DWORD *)pGkiCall->pConferenceId)[0] != 0 ||
  1673. ((DWORD *)pGkiCall->pConferenceId)[1] != 0 ||
  1674. ((DWORD *)pGkiCall->pConferenceId)[2] != 0 ||
  1675. ((DWORD *)pGkiCall->pConferenceId)[3] != 0)
  1676. {
  1677. ConferenceId.length = 16;
  1678. }
  1679. else
  1680. {
  1681. ConferenceId.length = 0;
  1682. }
  1683. pGkiCall->hGkiCall = GKI_ADMITTING_HANDLE;
  1684. if (pDestCallSignalAddress != NULL || pAliasAddrs != NULL)
  1685. {
  1686. uGkiState = STATE_ADMITTING;
  1687. pGkiCall->uGkiCallState = GCS_ADMITTING;
  1688. ISRTRACE(ghISRInst, "GKI_AdmissionRequest called...", 0);
  1689. status = pGKI_AdmissionRequest(pGkiCall->usCallTypeChoice, // usCallTypeChoice.
  1690. pAliasAddrs, // pDestinationInfo,
  1691. pDestCallSignalAddress, // pDestCallSignalAddress
  1692. pExtraAliasAddrs, // pDestExtraCallInfo,
  1693. &pGkiCall->CallIdentifier, // H.225 call identifer
  1694. pGkiCall->uBandwidthRequested, // bandWidth,
  1695. &ConferenceId, // pConferenceID,
  1696. pGkiCall->bActiveMC, // activeMC,
  1697. pGkiCall->bAnswerCall, // answerCall,
  1698. ipAddress_chosen); // usCallTransport
  1699. if (status == NOERROR)
  1700. {
  1701. ISRTRACE(ghISRInst, GkiErrorName("GKI_AdmissionRequest returned %s", status), 0);
  1702. }
  1703. else
  1704. {
  1705. ISRERROR(ghISRInst, GkiErrorName("GKI_AdmissionRequest returned %s", status), 0);
  1706. }
  1707. }
  1708. else
  1709. {
  1710. pGkiCall->hGkiCall = 0;
  1711. status = CC_BAD_PARAM;
  1712. }
  1713. if (status != NOERROR)
  1714. {
  1715. uGkiState = STATE_REGISTERED;
  1716. GkiCancelCall(pGkiCall, pConference);
  1717. }
  1718. if (pAliasAddrs)
  1719. {
  1720. FreeAliasList(pAliasAddrs);
  1721. MemFree(pAliasAddrs);
  1722. }
  1723. if (pExtraAliasAddrs)
  1724. {
  1725. FreeAliasList(pExtraAliasAddrs);
  1726. MemFree(pExtraAliasAddrs);
  1727. }
  1728. break;
  1729. case STATE_START:
  1730. case STATE_CLASS_REGISTERED:
  1731. case STATE_WINDOW_CREATED:
  1732. pGkiCall->uGkiCallState = GCS_WAITING;
  1733. // not registered!!! attempt to register or reregister
  1734. status = GkiRegister();
  1735. break;
  1736. default:
  1737. ISRERROR(ghISRInst, StateName("GkiOpenCall: Invalid state %s", uGkiState), 0);
  1738. status = LastGkiError;
  1739. } // switch
  1740. LeaveCriticalSection(&GkiLock);
  1741. ISRTRACE(ghISRInst, CallStateName("GkiOpenCall -> Call State = %s", pGkiCall->uGkiCallState), 0);
  1742. return status;
  1743. } // GkiOpenCall()
  1744. /*
  1745. * NOTES
  1746. * Must have Call locked before calling!
  1747. */
  1748. HRESULT GkiOpenChannel(PGKICALL pGkiCall, unsigned uChannelBandwidth, CC_HCHANNEL hChannel, CHANNELTYPE Type)
  1749. {
  1750. HRESULT status = NOERROR;
  1751. PBWREQ pBwReq;
  1752. ASSERT(GKIExists());
  1753. ASSERT(pGkiCall != NULL);
  1754. ISRTRACE(ghISRInst, CallStateName("GkiOpenChannel <- Call State = %s", pGkiCall->uGkiCallState), 0);
  1755. pBwReq = (PBWREQ)MemAlloc(sizeof(*pBwReq));
  1756. if (pBwReq == NULL)
  1757. {
  1758. ISRERROR(ghISRInst, "GkiOpenChannel: Memory allocation failed", 0);
  1759. return CC_NO_MEMORY;
  1760. }
  1761. pBwReq->uChannelBandwidth = uChannelBandwidth / 100;
  1762. pBwReq->hChannel = hChannel;
  1763. pBwReq->Type = Type;
  1764. BwReqEnqueue(pGkiCall, pBwReq);
  1765. switch (pGkiCall->uGkiCallState)
  1766. {
  1767. case GCS_WAITING:
  1768. case GCS_ADMITTING:
  1769. case GCS_CHANGING:
  1770. // Must wait for current operation to complete
  1771. break;
  1772. case GCS_ADMITTED:
  1773. status = CheckPendingBandwidth(pGkiCall);
  1774. break;
  1775. default:
  1776. ISRERROR(ghISRInst, "GkiOpenChannel: Invalid call state %d", pGkiCall->uGkiCallState);
  1777. status = CC_GKI_CALL_STATE;
  1778. } // switch
  1779. ISRTRACE(ghISRInst, CallStateName("GkiOpenChannel -> Call State = %s", pGkiCall->uGkiCallState), 0);
  1780. return status;
  1781. } // GkiOpenChannel()
  1782. /*
  1783. * NOTES
  1784. * Must have Call locked before calling!
  1785. */
  1786. HRESULT GkiCloseChannel(PGKICALL pGkiCall, unsigned uChannelBandwidth, CC_HCHANNEL hChannel)
  1787. {
  1788. PBWREQ pBwReq;
  1789. PBWREQ pBwReq1;
  1790. ASSERT(GKIExists());
  1791. ASSERT(pGkiCall != NULL);
  1792. ISRTRACE(ghISRInst, CallStateName("GkiCloseChannel <- Call State = %s", pGkiCall->uGkiCallState), 0);
  1793. // If Bandwidth request is still in queue, bandwidth has not been allocated
  1794. pBwReq = pGkiCall->pBwReqHead;
  1795. if (pBwReq)
  1796. {
  1797. if (pBwReq->hChannel == hChannel)
  1798. {
  1799. MemFree(BwReqDequeue(pGkiCall));
  1800. ISRTRACE(ghISRInst, CallStateName("GkiCloseChannel -> Call State = %s", pGkiCall->uGkiCallState), 0);
  1801. return NOERROR;
  1802. }
  1803. while ((pBwReq1 = pBwReq->pNext) != NULL)
  1804. {
  1805. if (pBwReq1->hChannel == hChannel)
  1806. {
  1807. if (pGkiCall->pBwReqTail == pBwReq1)
  1808. {
  1809. pGkiCall->pBwReqTail = pBwReq;
  1810. }
  1811. pBwReq->pNext = pBwReq1->pNext;
  1812. MemFree(pBwReq1);
  1813. ISRTRACE(ghISRInst, CallStateName("GkiCloseChannel -> Call State = %s", pGkiCall->uGkiCallState), 0);
  1814. return NOERROR;
  1815. }
  1816. }
  1817. }
  1818. pGkiCall->uBandwidthUsed -= (uChannelBandwidth / 100);
  1819. ISRTRACE(ghISRInst, CallStateName("GkiCloseChannel -> Call State = %s", pGkiCall->uGkiCallState), 0);
  1820. return NOERROR;
  1821. } // GkiCloseChannel()
  1822. unsigned GkiGetBandwidth(PGKICALL pGkiCall)
  1823. {
  1824. ASSERT(pGkiCall != NULL);
  1825. return pGkiCall->uBandwidthAllocated * 100;
  1826. } // GkiGetBandwidth()
  1827. //
  1828. // GkiWndProc subroutines
  1829. //
  1830. /*
  1831. * NOTES
  1832. * Must have Call locked before calling!
  1833. */
  1834. static HRESULT CheckPendingOpen(PGKICALL pGkiCall, void *pConference)
  1835. {
  1836. HRESULT status = NOERROR;
  1837. ASSERT(pGkiCall != NULL);
  1838. ASSERT(pConference != NULL);
  1839. switch (uGkiState)
  1840. {
  1841. case STATE_REGISTERED:
  1842. case STATE_REG_BYPASS:
  1843. // TBD - Can only open 1!!!
  1844. ASSERT(pGkiCall->uGkiCallState != GCS_ADMITTING);
  1845. if (pGkiCall->uGkiCallState == GCS_WAITING)
  1846. {
  1847. status = GkiOpenCall(pGkiCall, pConference);
  1848. }
  1849. break;
  1850. default:
  1851. status = LastGkiError;
  1852. } // switch
  1853. return status;
  1854. } // CheckPendingOpen()
  1855. static void GkiNoResponse(HWND hWnd)
  1856. {
  1857. HRESULT status;
  1858. switch (uGkiState)
  1859. {
  1860. case STATE_START:
  1861. case STATE_CLASS_REGISTERED:
  1862. case STATE_WINDOW_CREATED:
  1863. case STATE_REG_BYPASS:
  1864. break;
  1865. case STATE_REGISTERING:
  1866. case STATE_REGISTERING_REREG:
  1867. case STATE_REGISTERING_UNREG:
  1868. #if(0)
  1869. why did Intel *DO* this?????
  1870. ISRTRACE(ghISRInst, "GkiWndProc: dummy GKI_REG_REJECT", 0);
  1871. PostMessage(hWnd, GKIMAN_BASE + GKI_REG_REJECT, 0, 0);
  1872. #else
  1873. // there was no response to registration request, assume the GK is not there or dead.
  1874. uGkiState = STATE_REG_BYPASS;
  1875. if(gpRasNotifyProc)
  1876. {
  1877. (gpRasNotifyProc)(RAS_REG_TIMEOUT, 0);
  1878. }
  1879. ApplyToAllCalls(CheckPendingOpen);
  1880. #endif
  1881. break;
  1882. case STATE_ADMITTING:
  1883. case STATE_ADMITTING_REREG:
  1884. ApplyToAllCalls(GkiCancelAdmitting);
  1885. uGkiState = STATE_REGISTERED;
  1886. // Fall-through to next case
  1887. case STATE_REGISTERED:
  1888. if (uGkiCalls == 0)
  1889. {
  1890. GkiRegister();
  1891. }
  1892. else
  1893. {
  1894. uGkiState = STATE_REG_BYPASS;
  1895. ApplyToAllCalls(GatekeeperNotFound);
  1896. ISRTRACE(ghISRInst, "GKI_UnregistrationRequest called...", 0);
  1897. status = pGKI_UnregistrationRequest();
  1898. if (status == NOERROR)
  1899. {
  1900. ISRTRACE(ghISRInst, GkiErrorName("GKI_UnregistrationRequest returned %s", status), 0);
  1901. }
  1902. else
  1903. {
  1904. ISRERROR(ghISRInst, GkiErrorName("GKI_UnregistrationRequest returned %s", status), 0);
  1905. }
  1906. }
  1907. break;
  1908. case STATE_ADMITTING_UNREG:
  1909. ApplyToAllCalls(GkiCancelAdmitting);
  1910. uGkiState = STATE_REGISTERED;
  1911. GkiUnregister();
  1912. break;
  1913. case STATE_DISENGAGING:
  1914. ApplyToAllCalls(GatekeeperNotFound);
  1915. ASSERT(uGkiCalls == 0);
  1916. uGkiState = STATE_REGISTERED;
  1917. GkiUnregister();
  1918. break;
  1919. case STATE_DISENGAGING_REREG:
  1920. ApplyToAllCalls(GatekeeperNotFound);
  1921. ASSERT(uGkiCalls == 0);
  1922. uGkiState = STATE_REGISTERED;
  1923. GkiRegister();
  1924. break;
  1925. case STATE_UNREGISTERING:
  1926. case STATE_UNREGISTERING_REREG:
  1927. ISRTRACE(ghISRInst, "GkiWndProc: dummy GKI_UNREG_CONFIRM", 0);
  1928. PostMessage(hWnd, GKIMAN_BASE + GKI_UNREG_CONFIRM, 0, 0);
  1929. break;
  1930. default:
  1931. ISRERROR(ghISRInst, "GkiWndProc: Bad uGkiState %d", uGkiState);
  1932. } // switch
  1933. } // GkiNoResponse()
  1934. LRESULT APIENTRY GkiWndProc(
  1935. HWND hWnd, /* window handle */
  1936. UINT message, /* type of message */
  1937. WPARAM wParam, /* additional information */
  1938. LPARAM lParam) /* additional information */
  1939. {
  1940. CallReturnInfo * pCallReturnInfo;
  1941. PGKICALL pGkiCall;
  1942. void * pConference;
  1943. CC_HCALL hCall;
  1944. CC_HCONFERENCE hConference;
  1945. HRESULT status;
  1946. if (message < GKIMAN_BASE)
  1947. {
  1948. return DefWindowProc(hWnd, message, wParam, lParam);
  1949. }
  1950. EnterCallControlTop();
  1951. ISRTRACE(ghISRInst, StateName("GkiWndProc <- State = %s", uGkiState), 0);
  1952. switch (message)
  1953. {
  1954. case GKIMAN_BASE + GKI_REG_CONFIRM:
  1955. ISRTRACE(ghISRInst, "GkiWndProc: GKI_REG_CONFIRM", 0);
  1956. ASSERT(gpRasNotifyProc); // we should never get messages if
  1957. // this is not configured
  1958. if(gpRasNotifyProc)
  1959. {
  1960. (gpRasNotifyProc)(RAS_REG_CONFIRM, 0);
  1961. }
  1962. switch (uGkiState)
  1963. {
  1964. case STATE_REGISTERING:
  1965. uGkiState = STATE_REGISTERED;
  1966. ApplyToAllCalls(CheckPendingOpen);
  1967. break;
  1968. case STATE_REGISTERING_REREG:
  1969. uGkiState = STATE_REGISTERED;
  1970. GkiRegister();
  1971. break;
  1972. case STATE_REGISTERING_UNREG:
  1973. uGkiState = STATE_REGISTERED;
  1974. GkiUnregister();
  1975. break;
  1976. default:
  1977. ISRERROR(ghISRInst, StateName("GkiWndProc: GKI_REG_CONFIRM in state %s", uGkiState), 0);
  1978. } // switch
  1979. break;
  1980. case GKIMAN_BASE + GKI_REG_DISCOVERY:
  1981. ISRTRACE(ghISRInst, "GkiWndProc: GKI_REG_DISCOVERY", 0);
  1982. ASSERT(uGkiState == STATE_REGISTERING || uGkiState == STATE_REGISTERING_REREG || uGkiState == STATE_REGISTERING_UNREG);
  1983. break;
  1984. case GKIMAN_BASE + GKI_UNREG_REQUEST:
  1985. // the GK kicked us out!
  1986. // pass the unregistration request upward
  1987. ASSERT(gpRasNotifyProc); // we should never get messages if
  1988. // this is not configured
  1989. if(gpRasNotifyProc)
  1990. {
  1991. (gpRasNotifyProc)(RAS_UNREG_REQ, MapUnregistrationRequestReason((UINT)wParam));
  1992. }
  1993. break;
  1994. case GKIMAN_BASE + GKI_REG_REJECT:
  1995. ISRERROR(ghISRInst, "GkiWndProc: GKI_REG_REJECT Reason = %d", (DWORD)wParam);
  1996. switch (uGkiState)
  1997. {
  1998. case STATE_REGISTERING:
  1999. ApplyToAllCalls(GkiCancelCall);
  2000. #if(0)
  2001. // leave the listen list intact so that subsequent registration attempts
  2002. // will work.
  2003. //
  2004. EnterCriticalSection(&GkiLock);
  2005. while (pListenList)
  2006. {
  2007. register PLISTEN pListen = pListenList;
  2008. pListenList = pListen->pNext;
  2009. LeaveCriticalSection(&GkiLock);
  2010. ListenReject(pListen->hListen, MapRegistrationRejectReason((UINT)wParam));
  2011. if (pListen->pAliasNames)
  2012. {
  2013. FreeAliasNames(pListen->pAliasNames);
  2014. }
  2015. MemFree(pListen);
  2016. EnterCriticalSection(&GkiLock);
  2017. }
  2018. LeaveCriticalSection(&GkiLock);
  2019. #endif
  2020. uGkiState = STATE_WINDOW_CREATED;
  2021. // pass the registration reject upward
  2022. ASSERT(gpRasNotifyProc); // we should never get messages if
  2023. // this is not configured
  2024. if(gpRasNotifyProc)
  2025. {
  2026. (gpRasNotifyProc)(RAS_REJECTED, MapRegistrationRejectReason((UINT)wParam));
  2027. }
  2028. break;
  2029. case STATE_REGISTERING_REREG:
  2030. uGkiState = STATE_WINDOW_CREATED;
  2031. GkiRegister();
  2032. break;
  2033. case STATE_REGISTERING_UNREG:
  2034. uGkiState = STATE_WINDOW_CREATED;
  2035. GkiUnregister();
  2036. break;
  2037. default:
  2038. ISRERROR(ghISRInst, StateName("GkiWndProc: GKI_REG_REJECT in state %s", uGkiState), 0);
  2039. } // switch
  2040. break;
  2041. case GKIMAN_BASE + GKI_REG_BYPASS:
  2042. ISRTRACE(ghISRInst, "GkiWndProc: GKI_REG_BYPASS", 0);
  2043. switch (uGkiState)
  2044. {
  2045. case STATE_REGISTERING:
  2046. case STATE_REGISTERING_REREG:
  2047. uGkiState = STATE_REG_BYPASS;
  2048. ApplyToAllCalls(CheckPendingOpen);
  2049. break;
  2050. case STATE_REGISTERING_UNREG:
  2051. uGkiState = STATE_WINDOW_CREATED;
  2052. GkiUnregister();
  2053. break;
  2054. default:
  2055. ISRERROR(ghISRInst, StateName("GkiWndProc: GKI_REG_BYPASS in state %s", uGkiState), 0);
  2056. } // switch
  2057. break;
  2058. case GKIMAN_BASE + GKI_UNREG_CONFIRM:
  2059. ISRTRACE(ghISRInst, "GkiWndProc: GKI_UNREG_CONFIRM", 0);
  2060. ASSERT(gpRasNotifyProc); // we should never get messages if
  2061. // this is not configured
  2062. if(gpRasNotifyProc)
  2063. {
  2064. (gpRasNotifyProc)(RAS_UNREG_CONFIRM, 0);
  2065. }
  2066. switch (uGkiState)
  2067. {
  2068. case STATE_REGISTERING:
  2069. case STATE_REGISTERING_REREG:
  2070. case STATE_REGISTERED:
  2071. case STATE_ADMITTING:
  2072. case STATE_ADMITTING_REREG:
  2073. case STATE_DISENGAGING_REREG:
  2074. case STATE_UNREGISTERING_REREG:
  2075. uGkiState = STATE_WINDOW_CREATED;
  2076. GkiRegister();
  2077. break;
  2078. default:
  2079. ISRERROR(ghISRInst, StateName("GkiWndProc: GKI_UNREG_CONFIRM in state %s", uGkiState), 0);
  2080. // Fall through to next case
  2081. case STATE_ADMITTING_UNREG:
  2082. case STATE_DISENGAGING:
  2083. ApplyToAllCalls(GkiCancelCall);
  2084. // Fall-through to next case
  2085. case STATE_REGISTERING_UNREG:
  2086. case STATE_UNREGISTERING:
  2087. uGkiState = STATE_WINDOW_CREATED;
  2088. // Fall-through to next case
  2089. case STATE_CLASS_REGISTERED:
  2090. case STATE_WINDOW_CREATED:
  2091. // Fall-through to next case
  2092. case STATE_START:
  2093. case STATE_REG_BYPASS:
  2094. break;
  2095. } // switch
  2096. break;
  2097. case GKIMAN_BASE + GKI_UNREG_REJECT:
  2098. ISRERROR(ghISRInst, "GkiWndProc: GKI_UNREG_REJECT Reason = %d", (DWORD)wParam);
  2099. switch (uGkiState)
  2100. {
  2101. case STATE_UNREGISTERING:
  2102. uGkiState = STATE_WINDOW_CREATED;
  2103. GkiUnregister();
  2104. break;
  2105. case STATE_UNREGISTERING_REREG:
  2106. uGkiState = STATE_WINDOW_CREATED;
  2107. GkiRegister();
  2108. break;
  2109. default:
  2110. ISRWARNING(ghISRInst, StateName("GkiWndProc: GKI_UNREG_REJECT in state %s", uGkiState), 0);
  2111. } // switch
  2112. break;
  2113. case GKIMAN_BASE + GKI_ADM_CONFIRM:
  2114. ISRTRACE(ghISRInst, "GkiWndProc: GKI_ADM_CONFIRM", 0);
  2115. switch (uGkiState)
  2116. {
  2117. case STATE_ADMITTING:
  2118. uGkiState = STATE_REGISTERED;
  2119. pCallReturnInfo = (CallReturnInfo *) lParam;
  2120. if (LockGkiCallAndConference(GKI_ADMITTING_HANDLE, &pGkiCall, &pConference, &hCall, &hConference) == NOERROR)
  2121. {
  2122. ISRTRACE(ghISRInst, CallStateName("GkiWndProc: Call State = %s", pGkiCall->uGkiCallState), 0);
  2123. pGkiCall->usCallModelChoice = pCallReturnInfo->callModel.choice;
  2124. pGkiCall->uBandwidthAllocated = pCallReturnInfo->bandWidth;
  2125. pGkiCall->usCRV = pCallReturnInfo->callReferenceValue;
  2126. memcpy(pGkiCall->pConferenceId, pCallReturnInfo->conferenceID.value, 16);
  2127. switch (pGkiCall->uGkiCallState)
  2128. {
  2129. case GCS_ADMITTING:
  2130. GkiAllocCall(pGkiCall, pCallReturnInfo->hCall);
  2131. if (pGkiCall->bAnswerCall)
  2132. {
  2133. status = AcceptCallConfirm(pGkiCall->pCall, pConference);
  2134. }
  2135. else
  2136. {
  2137. ASSERT(pCallReturnInfo->destCallSignalAddress.choice == ipAddress_chosen);
  2138. pGkiCall->dwIpAddress = *((DWORD *)pCallReturnInfo->destCallSignalAddress.u.ipAddress.ip.value);
  2139. pGkiCall->wPort = pCallReturnInfo->destCallSignalAddress.u.ipAddress.port;
  2140. status = PlaceCallConfirm(pGkiCall->pCall, pConference);
  2141. }
  2142. if (status == NOERROR && ValidateCall(hCall) == NOERROR)
  2143. CheckPendingBandwidth(pGkiCall);
  2144. break;
  2145. case GCS_ADMITTING_CLOSE_PENDING:
  2146. GkiAllocCall(pGkiCall, pCallReturnInfo->hCall);
  2147. GkiCloseCall(pGkiCall);
  2148. break;
  2149. default:
  2150. ISRWARNING(ghISRInst, CallStateName("GkiWndProc: GKI_ADM_CONFIRM in call state %s", pGkiCall->uGkiCallState), 0);
  2151. } // switch
  2152. UnlockGkiCallAndConference(pGkiCall, pConference, hCall, hConference);
  2153. } // if
  2154. else
  2155. {
  2156. ISRWARNING(ghISRInst, "GkiWndProc: GKI_ADM_CONFIRM handle not found", 0);
  2157. }
  2158. ApplyToAllCalls(CheckPendingOpen);
  2159. break;
  2160. case STATE_ADMITTING_UNREG:
  2161. uGkiState = STATE_REGISTERED;
  2162. GkiUnregister();
  2163. break;
  2164. default:
  2165. ISRWARNING(ghISRInst, StateName("GkiWndProc: GKI_ADM_CONFIRM in state %s", uGkiState), 0);
  2166. } // switch
  2167. break;
  2168. case GKIMAN_BASE + GKI_ADM_REJECT:
  2169. ISRERROR(ghISRInst, "GkiWndProc: GKI_ADM_REJECT Reason = %d", (DWORD)wParam);
  2170. switch (uGkiState)
  2171. {
  2172. case STATE_ADMITTING:
  2173. pCallReturnInfo = (CallReturnInfo *) lParam;
  2174. if (LockGkiCallAndConference(GKI_ADMITTING_HANDLE, &pGkiCall, &pConference, &hCall, &hConference) == NOERROR)
  2175. {
  2176. ASSERT(pGkiCall->uGkiCallState == GCS_ADMITTING);
  2177. switch (wParam)
  2178. {
  2179. case AdmissionRejectReason_calledPartyNotRegistered_chosen:
  2180. if (pGkiCall->bAnswerCall)
  2181. {
  2182. // The gateway has gone away and come back without our notice!
  2183. GkiCancelAdmitting(pGkiCall, pConference);
  2184. uGkiState = STATE_REGISTERED;
  2185. GkiRegister();
  2186. ISRTRACE(ghISRInst, StateName("GkiWndProc -> State = %s", uGkiState), 0);
  2187. LeaveCallControlTop(0);
  2188. }
  2189. break;
  2190. case AdmissionRejectReason_callerNotRegistered_chosen:
  2191. if (pGkiCall->bAnswerCall == FALSE)
  2192. {
  2193. // The gateway has gone away and come back without our notice!
  2194. GkiCancelAdmitting(pGkiCall, pConference);
  2195. uGkiState = STATE_REGISTERED;
  2196. GkiRegister();
  2197. ISRTRACE(ghISRInst, StateName("GkiWndProc -> State = %s", uGkiState), 0);
  2198. LeaveCallControlTop(0);
  2199. }
  2200. } // switch
  2201. GkiFreeCall(pGkiCall);
  2202. if (pGkiCall->bAnswerCall)
  2203. AcceptCallReject(pGkiCall->pCall, pConference, MapAdmissionRejectReason((UINT)wParam));
  2204. else
  2205. PlaceCallReject (pGkiCall->pCall, pConference, MapAdmissionRejectReason((UINT)wParam));
  2206. UnlockGkiCallAndConference(pGkiCall, pConference, hCall, hConference);
  2207. } // if
  2208. else
  2209. {
  2210. ISRWARNING(ghISRInst, "GkiWndProc: GKI_ADM_REJECT handle not found", 0);
  2211. }
  2212. uGkiState = STATE_REGISTERED;
  2213. ApplyToAllCalls(CheckPendingOpen);
  2214. break;
  2215. case STATE_ADMITTING_REREG:
  2216. pCallReturnInfo = (CallReturnInfo *) lParam;
  2217. if (LockGkiCallAndConference(GKI_ADMITTING_HANDLE, &pGkiCall, &pConference, &hCall, &hConference) == NOERROR)
  2218. {
  2219. ASSERT(pGkiCall->uGkiCallState == GCS_ADMITTING_CLOSE_PENDING);
  2220. GkiFreeCall(pGkiCall);
  2221. if (pGkiCall->bAnswerCall)
  2222. {
  2223. AcceptCallReject(pGkiCall->pCall, pConference, MapAdmissionRejectReason((UINT)wParam));
  2224. }
  2225. else
  2226. {
  2227. PlaceCallReject (pGkiCall->pCall, pConference, MapAdmissionRejectReason((UINT)wParam));
  2228. }
  2229. UnlockGkiCallAndConference(pGkiCall, pConference, hCall, hConference);
  2230. } // if
  2231. else
  2232. {
  2233. ISRWARNING(ghISRInst, "GkiWndProc: GKI_ADM_REJECT handle not found", 0);
  2234. }
  2235. uGkiState = STATE_REGISTERED;
  2236. GkiRegister();
  2237. break;
  2238. case STATE_ADMITTING_UNREG:
  2239. pCallReturnInfo = (CallReturnInfo *) lParam;
  2240. if (LockGkiCallAndConference(GKI_ADMITTING_HANDLE, &pGkiCall, &pConference, &hCall, &hConference) == NOERROR)
  2241. {
  2242. ASSERT(pGkiCall->uGkiCallState == GCS_ADMITTING_CLOSE_PENDING);
  2243. GkiFreeCall(pGkiCall);
  2244. if (pGkiCall->bAnswerCall)
  2245. {
  2246. AcceptCallReject(pGkiCall->pCall, pConference, MapAdmissionRejectReason((UINT)wParam));
  2247. }
  2248. else
  2249. {
  2250. PlaceCallReject (pGkiCall->pCall, pConference, MapAdmissionRejectReason((UINT)wParam));
  2251. }
  2252. UnlockGkiCallAndConference(pGkiCall, pConference, hCall, hConference);
  2253. } // if
  2254. else
  2255. {
  2256. ISRWARNING(ghISRInst, "GkiWndProc: GKI_ADM_REJECT handle not found", 0);
  2257. }
  2258. uGkiState = STATE_REGISTERED;
  2259. GkiUnregister();
  2260. break;
  2261. default:
  2262. ISRWARNING(ghISRInst, StateName("GkiWndProc: GKI_ADM_REJECT in state %s", uGkiState), 0);
  2263. } // switch
  2264. break;
  2265. case GKIMAN_BASE + GKI_BW_CONFIRM:
  2266. ISRTRACE(ghISRInst, "GkiWndProc: GKI_BW_CONFIRM", 0);
  2267. switch (uGkiState)
  2268. {
  2269. case STATE_REGISTERED:
  2270. pCallReturnInfo = (CallReturnInfo *) lParam;
  2271. if (LockGkiCallAndConference(pCallReturnInfo->hCall, &pGkiCall, &pConference, &hCall, &hConference) == NOERROR)
  2272. {
  2273. ISRTRACE(ghISRInst, CallStateName("GkiWndProc: Call State = %s", pGkiCall->uGkiCallState), 0);
  2274. pGkiCall->uBandwidthAllocated = pCallReturnInfo->bandWidth;
  2275. switch (pGkiCall->uGkiCallState)
  2276. {
  2277. case GCS_ADMITTED:
  2278. if (pGkiCall->uBandwidthUsed < pGkiCall->uBandwidthAllocated)
  2279. {
  2280. BandwidthShrunk(pGkiCall->pCall,
  2281. pConference,
  2282. pGkiCall->uBandwidthAllocated,
  2283. ((long)pGkiCall->uBandwidthAllocated) - ((long)pGkiCall->uBandwidthUsed));
  2284. }
  2285. break;
  2286. case GCS_CHANGING:
  2287. pGkiCall->uGkiCallState = GCS_ADMITTED;
  2288. CheckPendingBandwidth(pGkiCall);
  2289. break;
  2290. case GCS_CHANGING_CLOSE_PENDING:
  2291. pGkiCall->uGkiCallState = GCS_ADMITTED;
  2292. GkiCloseCall(pGkiCall);
  2293. break;
  2294. default:
  2295. ISRWARNING(ghISRInst, CallStateName("GkiWndProc: GKI_BW_CONFIRM in call state %s", pGkiCall->uGkiCallState), 0);
  2296. } // switch
  2297. UnlockGkiCallAndConference(pGkiCall, pConference, hCall, hConference);
  2298. } // if
  2299. else
  2300. {
  2301. ISRWARNING(ghISRInst, "GkiWndProc: GKI_BW_CONFIRM handle not found", 0);
  2302. } // else
  2303. break;
  2304. default:
  2305. ISRERROR(ghISRInst, StateName("GkiWndProc: GKI_BW_CONFIRM in GKI state %s", uGkiState), 0);
  2306. } // switch
  2307. break;
  2308. case GKIMAN_BASE + GKI_BW_REJECT:
  2309. ISRERROR(ghISRInst, "GkiWndProc: GKI_BW_REJECT Reason = %d", (DWORD)wParam);
  2310. switch (uGkiState)
  2311. {
  2312. case STATE_REGISTERED:
  2313. pCallReturnInfo = (CallReturnInfo *) lParam;
  2314. if (LockGkiCallAndConference(pCallReturnInfo->hCall, &pGkiCall, &pConference, &hCall, &hConference) == NOERROR)
  2315. {
  2316. ISRTRACE(ghISRInst, CallStateName("GkiWndProc: Call State = %s", pGkiCall->uGkiCallState), 0);
  2317. pGkiCall->uBandwidthAllocated = pCallReturnInfo->bandWidth;
  2318. switch (pGkiCall->uGkiCallState)
  2319. {
  2320. case GCS_CHANGING:
  2321. pGkiCall->uGkiCallState = GCS_ADMITTED;
  2322. BandwidthRejected(pGkiCall, (UINT)wParam);
  2323. if (ValidateCall(hCall) == NOERROR)
  2324. {
  2325. CheckPendingBandwidth(pGkiCall);
  2326. }
  2327. break;
  2328. case GCS_CHANGING_CLOSE_PENDING:
  2329. pGkiCall->uGkiCallState = GCS_ADMITTED;
  2330. GkiCloseCall(pGkiCall);
  2331. break;
  2332. default:
  2333. ISRERROR(ghISRInst, CallStateName("GkiWndProc: GKI_BW_REJECT in state %s", pGkiCall->uGkiCallState), 0);
  2334. } // switch
  2335. UnlockGkiCallAndConference(pGkiCall, pConference, hCall, hConference);
  2336. } // if
  2337. else
  2338. {
  2339. ISRWARNING(ghISRInst, "GkiWndProc: GKI_BW_REJECT handle not found", 0);
  2340. }
  2341. break;
  2342. default:
  2343. ISRERROR(ghISRInst, StateName("GkiWndProc: GKI_BW_REJECT in state %s", uGkiState), 0);
  2344. } // switch
  2345. break;
  2346. case GKIMAN_BASE + GKI_DISENG_CONFIRM:
  2347. ISRTRACE(ghISRInst, "GkiWndProc: GKI_DISENG_CONFIRM", 0);
  2348. if (LockGkiCall((HANDLE)lParam, &pGkiCall) == NOERROR)
  2349. {
  2350. ISRTRACE(ghISRInst, CallStateName("GkiWndProc: Call State = %s", pGkiCall->uGkiCallState), 0);
  2351. switch (pGkiCall->uGkiCallState)
  2352. {
  2353. case GCS_DISENGAGING:
  2354. --uPendingDisengages;
  2355. break;
  2356. default:
  2357. ISRWARNING(ghISRInst, CallStateName("GkiWndProc: GKI_DISENG_CONFIRM in call state %s", pGkiCall->uGkiCallState), 0);
  2358. } // switch
  2359. GkiFreeCall(pGkiCall);
  2360. Disengage(pGkiCall->pCall);
  2361. } // if
  2362. else if (uPendingDisengages != 0)
  2363. {
  2364. --uPendingDisengages;
  2365. if (uPendingDisengages == 0)
  2366. {
  2367. switch (uGkiState)
  2368. {
  2369. case STATE_DISENGAGING:
  2370. uGkiState = STATE_REGISTERED;
  2371. GkiUnregister();
  2372. break;
  2373. case STATE_DISENGAGING_REREG:
  2374. uGkiState = STATE_REGISTERED;
  2375. GkiRegister();
  2376. break;
  2377. } // switch
  2378. } // if
  2379. } // else if
  2380. else
  2381. {
  2382. ISRWARNING(ghISRInst, "GkiWndProc: GKI_DISENG_CONFIRM handle not found", 0);
  2383. }
  2384. break;
  2385. case GKIMAN_BASE + GKI_DISENG_REJECT:
  2386. ISRERROR(ghISRInst, "GkiWndProc: GKI_DISENG_REJECT Reason = %d", (DWORD)wParam);
  2387. if (LockGkiCall((HANDLE)lParam, &pGkiCall) == NOERROR)
  2388. {
  2389. ISRTRACE(ghISRInst, CallStateName("GkiWndProc: Call State = %s", pGkiCall->uGkiCallState), 0);
  2390. switch (pGkiCall->uGkiCallState)
  2391. {
  2392. case GCS_DISENGAGING:
  2393. // Pretend we received a Disengage Confirm
  2394. --uPendingDisengages;
  2395. break;
  2396. default:
  2397. ISRERROR(ghISRInst, CallStateName("GkiWndProc: GKI_DISENG_REJECT in call state %s", pGkiCall->uGkiCallState), 0);
  2398. } // switch
  2399. GkiFreeCall(pGkiCall);
  2400. Disengage(pGkiCall->pCall);
  2401. } // if
  2402. else if (uPendingDisengages != 0)
  2403. {
  2404. // Pretend we received a Disengage Confirm
  2405. --uPendingDisengages;
  2406. if (uPendingDisengages == 0)
  2407. {
  2408. switch (uGkiState)
  2409. {
  2410. case STATE_DISENGAGING:
  2411. uGkiState = STATE_REGISTERED;
  2412. GkiUnregister();
  2413. break;
  2414. case STATE_DISENGAGING_REREG:
  2415. uGkiState = STATE_REGISTERED;
  2416. GkiRegister();
  2417. break;
  2418. } // switch
  2419. } // if
  2420. } // else if
  2421. else
  2422. {
  2423. ISRWARNING(ghISRInst, "GkiWndProc: GKI_DISENG_REJECT handle not found", 0);
  2424. }
  2425. break;
  2426. case GKIMAN_BASE + GKI_LOCATION_CONFIRM:
  2427. ISRTRACE(ghISRInst, "GkiWndProc: GKI_LOCATION_CONFIRM", 0);
  2428. break;
  2429. case GKIMAN_BASE + GKI_LOCATION_REJECT:
  2430. ISRERROR(ghISRInst, "GkiWndProc: GKI_LOCATION_REJECT Reason = %d", (DWORD)wParam);
  2431. break;
  2432. case GKIMAN_BASE + GKI_ERROR:
  2433. ISRERROR(ghISRInst, GkiErrorName("GkiWndProc: GKI_ERROR %s %%d", (HRESULT)lParam), (DWORD)wParam);
  2434. switch (lParam)
  2435. {
  2436. case GKI_NO_RESPONSE:
  2437. LastGkiError = (HRESULT)lParam;
  2438. GkiNoResponse(hWnd);
  2439. break;
  2440. #if 1
  2441. // TEMPORARY KLUDGE FOR WINSOCK 2 BETA 1.6 OPERATION
  2442. case MAKE_CUSTOM_HRESULT(SEVERITY_ERROR,1,FACILITY_WINSOCK,0xffff):
  2443. uGkiState = STATE_REG_BYPASS;
  2444. ApplyToAllCalls(CheckPendingOpen);
  2445. break;
  2446. #endif
  2447. default:
  2448. LastGkiError = (HRESULT)lParam;
  2449. GkiUnregister();
  2450. } // switch
  2451. break;
  2452. default:
  2453. ISRERROR(ghISRInst, "Unknown message %d", message);
  2454. } // switch
  2455. ISRTRACE(ghISRInst, StateName("GkiWndProc -> State = %s", uGkiState), 0);
  2456. LeaveCallControlTop(0);
  2457. } // GkiWndProc()
  2458. // because the ASN.1 header files are not exposed and there is a redefinition of
  2459. // RAS reason codes, make sure that the mapping is correct. The functions herien
  2460. // assume equality and don't actually do any remapping.
  2461. // break the build if the definitions don't match !!!
  2462. #if (discoveryRequired_chosen != RRJ_DISCOVERY_REQ)
  2463. #error "Registration reject reason code definitions mismatch!! GO back and FIX IT!!"
  2464. #endif
  2465. #if (RegistrationRejectReason_invalidRevision_chosen != RRJ_INVALID_REVISION)
  2466. #error "Registration reject reason code definitions mismatch!! GO back and FIX IT!!"
  2467. #endif
  2468. #if (invalidCallSignalAddress_chosen != RRJ_INVALID_CALL_ADDR)
  2469. #error "Registration reject reason code definitions mismatch!! GO back and FIX IT!!"
  2470. #endif
  2471. #if (invalidRASAddress_chosen != RRJ_INVALID_RAS_ADDR)
  2472. #error "Registration reject reason code definitions mismatch!! GO back and FIX IT!!"
  2473. #endif
  2474. #if (duplicateAlias_chosen != RRJ_DUPLICATE_ALIAS)
  2475. #error "Registration reject reason code definitions mismatch!! GO back and FIX IT!!"
  2476. #endif
  2477. #if (invalidTerminalType_chosen != RRJ_INVALID_TERMINAL_TYPE)
  2478. #error "Registration reject reason code definitions mismatch!! GO back and FIX IT!!"
  2479. #endif
  2480. #if (RegistrationRejectReason_undefinedReason_chosen != RRJ_UNDEFINED)
  2481. #error "Registration reject reason code definitions mismatch!! GO back and FIX IT!!"
  2482. #endif
  2483. #if (transportNotSupported_chosen != RRJ_TRANSPORT_NOT_SUPPORTED)
  2484. #error "Registration reject reason code definitions mismatch!! GO back and FIX IT!!"
  2485. #endif
  2486. #if (transportQOSNotSupported_chosen != RRJ_TRANSPORT_QOS_NOT_SUPPORTED)
  2487. #error "Registration reject reason code definitions mismatch!! GO back and FIX IT!!"
  2488. #endif
  2489. #if (RegistrationRejectReason_resourceUnavailable_chosen != RRJ_RESOURCE_UNAVAILABLE)
  2490. #error "Registration reject reason code definitions mismatch!! GO back and FIX IT!!"
  2491. #endif
  2492. #if (invalidAlias_chosen != RRJ_INVALID_ALIAS)
  2493. #error "Registration reject reason code definitions mismatch!! GO back and FIX IT!!"
  2494. #endif
  2495. #if (RegistrationRejectReason_securityDenial_chosen != RRJ_SECURITY_DENIAL)
  2496. #error "Registration reject reason code definitions mismatch!! GO back and FIX IT!!"
  2497. #endif
  2498. // reason codes for GK initiated URQ
  2499. #if(reregistrationRequired_chosen != URQ_REREG_REQUIRED)
  2500. #error "UnregRequestReason code definitions mismatch!! GO back and FIX IT!!"
  2501. #endif
  2502. #if(ttlExpired_chosen != URQ_TTL_EXPIRED)
  2503. #error "UnregRequestReason code definitions mismatch!! GO back and FIX IT!!"
  2504. #endif
  2505. #if(UnregRequestReason_securityDenial_chosen != URQ_SECURITY_DENIAL)
  2506. #error "UnregRequestReason code definitions mismatch!! GO back and FIX IT!!"
  2507. #endif
  2508. #if(UnregRequestReason_undefinedReason_chosen != URQ_UNDEFINED)
  2509. #error "UnregRequestReason code definitions mismatch!! GO back and FIX IT!!"
  2510. #endif
  2511. #if(AdmissionRejectReason_calledPartyNotRegistered_chosen != ARJ_CALLEE_NOT_REGISTERED)
  2512. #error "AdmissionRejectReason code definitions mismatch!! GO back and FIX IT!!"
  2513. #endif
  2514. #if(AdmissionRejectReason_invalidPermission_chosen != ARJ_INVALID_PERMISSION)
  2515. #error "AdmissionRejectReason code definitions mismatch!! GO back and FIX IT!!"
  2516. #endif
  2517. #if(AdmissionRejectReason_requestDenied_chosen != ARJ_REQUEST_DENIED)
  2518. #error "AdmissionRejectReason code definitions mismatch!! GO back and FIX IT!!"
  2519. #endif
  2520. #if(AdmissionRejectReason_undefinedReason_chosen != ARJ_UNDEFINED)
  2521. #error "AdmissionRejectReason code definitions mismatch!! GO back and FIX IT!!"
  2522. #endif
  2523. #if(AdmissionRejectReason_callerNotRegistered_chosen != ARJ_CALLER_NOT_REGISTERED)
  2524. #error "AdmissionRejectReason code definitions mismatch!! GO back and FIX IT!!"
  2525. #endif
  2526. #if(AdmissionRejectReason_routeCallToGatekeeper_chosen != ARJ_ROUTE_TO_GK)
  2527. #error "AdmissionRejectReason code definitions mismatch!! GO back and FIX IT!!"
  2528. #endif
  2529. #if(invalidEndpointIdentifier_chosen != ARJ_INVALID_ENDPOINT_ID)
  2530. #error "AdmissionRejectReason code definitions mismatch!! GO back and FIX IT!!"
  2531. #endif
  2532. #if(AdmissionRejectReason_resourceUnavailable_chosen != ARJ_RESOURCE_UNAVAILABLE)
  2533. #error "AdmissionRejectReason code definitions mismatch!! GO back and FIX IT!!"
  2534. #endif
  2535. #if(AdmissionRejectReason_securityDenial_chosen != ARJ_SECURTY_DENIAL)
  2536. #error "AdmissionRejectReason code definitions mismatch!! GO back and FIX IT!!"
  2537. #endif
  2538. #if(qosControlNotSupported_chosen != ARJ_QOS_CONTROL_NOT_SUPPORTED)
  2539. #error "AdmissionRejectReason code definitions mismatch!! GO back and FIX IT!!"
  2540. #endif
  2541. #if(incompleteAddress_chosen != ARJ_INCOMPLETE_ADDRESS)
  2542. #error "AdmissionRejectReason code definitions mismatch!! GO back and FIX IT!!"
  2543. #endif
  2544. #if(reregistrationRequired_chosen != URQ_REREG_REQUIRED)
  2545. #error "UnregistrationRequest code definitions mismatch!! GO back and FIX IT!!"
  2546. #endif
  2547. #if(ttlExpired_chosen != URQ_TTL_EXPIRED)
  2548. #error "UnregistrationRequest code definitions mismatch!! GO back and FIX IT!!"
  2549. #endif
  2550. #if(UnregRequestReason_securityDenial_chosen != URQ_SECURITY_DENIAL)
  2551. #error "UnregistrationRequest code definitions mismatch!! GO back and FIX IT!!"
  2552. #endif
  2553. #if(UnregRequestReason_undefinedReason_chosen != URQ_UNDEFINED)
  2554. #error "UnregistrationRequest code definitions mismatch!! GO back and FIX IT!!"
  2555. #endif
  2556. #else // GATEKEEPER
  2557. static char ch; // Kludge around warning C4206: nonstandard extension used : translation unit is empty
  2558. #endif // GATEKEEPER
  2559.