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.

11828 lines
311 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. call.cpp
  5. Abstract:
  6. TAPI Service Provider functions related to manipulating calls.
  7. TSPI_lineAnswer
  8. TSPI_lineCloseCall
  9. TSPI_lineDrop
  10. TSPI_lineGetCallAddressID
  11. TSPI_lineGetCallInfo
  12. TSPI_lineGetCallStatus
  13. TSPI_lineMakeCall
  14. TSPI_lineMonitorDigits
  15. TSPI_lineSendUserUserInfo
  16. TSPI_lineReleaseUserUserInfo
  17. Author:
  18. Nikhil Bobde (NikhilB)
  19. Revision History:
  20. --*/
  21. //
  22. // Include files
  23. //
  24. #include "globals.h"
  25. #include "line.h"
  26. #include "q931pdu.h"
  27. #include "q931obj.h"
  28. #include "ras.h"
  29. #include "config.h"
  30. #define SETUP_SENT_TIMEOUT 8000
  31. #define H450_ENCODED_ARG_LEN 0x4000
  32. #define MAX_DIVERSION_COUNTER 14
  33. static LONG g_H323CallID;
  34. static LONG g_lNumberOfcalls;
  35. LONG g_lCallReference;
  36. //
  37. // Public functions
  38. //
  39. //
  40. //The function that handles a network event(CONNECT|CLOSE) on any of the
  41. //Q931 calls. This function needs to find out the exact event
  42. // that took place and the socket on which it took place
  43. //
  44. void NTAPI Q931TransportEventHandler (
  45. IN PVOID Parameter,
  46. IN BOOLEAN TimerFired)
  47. {
  48. PH323_CALL pCall;
  49. H323DBG(( DEBUG_LEVEL_TRACE, "Q931 transport event recvd." ));
  50. pCall = g_pH323Line -> FindH323CallAndLock ((HDRVCALL) Parameter);
  51. if( pCall != NULL )
  52. {
  53. pCall -> HandleTransportEvent();
  54. pCall -> Unlock();
  55. }
  56. }
  57. //
  58. // returns S_OK if socket was consumed
  59. // returns E_FAIL if socket should be destroyed by caller
  60. //
  61. static HRESULT CallCreateIncomingCall (
  62. IN SOCKET Socket,
  63. IN SOCKADDR_IN * LocalAddress,
  64. IN SOCKADDR_IN * RemoteAddress)
  65. {
  66. PH323_CALL pCall;
  67. HANDLE SelectEvent;
  68. HANDLE SelectWaitHandle;
  69. BOOL fSuccess = TRUE;
  70. BOOL DeleteCall = FALSE;
  71. TCHAR ptstrEventName[100];
  72. BOOL retVal;
  73. pCall = new CH323Call;
  74. if( pCall == NULL )
  75. {
  76. H323DBG(( DEBUG_LEVEL_ERROR,
  77. "failed to allocate memory for CH323Call." ));
  78. return E_OUTOFMEMORY;
  79. }
  80. _stprintf( ptstrEventName, _T("%s-%p"),
  81. _T( "H323TSP_Incoming_TransportHandlerEvent" ), pCall );
  82. // create the wait event
  83. SelectEvent = H323CreateEvent (NULL, FALSE,
  84. FALSE, ptstrEventName );
  85. if( SelectEvent == NULL )
  86. {
  87. H323DBG(( DEBUG_LEVEL_ERROR, "CALL: failed to create select event." ));
  88. delete pCall;
  89. return GetLastResult();
  90. }
  91. retVal = pCall -> Initialize( NULL,
  92. LINECALLORIGIN_INBOUND,
  93. CALLTYPE_NORMAL );
  94. if( retVal == FALSE )
  95. {
  96. H323DBG ((DEBUG_LEVEL_ERROR, "failed to initialize CH323Call."));
  97. CloseHandle (SelectEvent);
  98. delete pCall;
  99. return E_FAIL;
  100. }
  101. //add it to the call context array
  102. if (!pCall -> InitializeQ931 (Socket))
  103. {
  104. H323DBG(( DEBUG_LEVEL_ERROR,
  105. "Failed to initialize incoming call Q.931 state." ));
  106. DeleteCall = FALSE;
  107. pCall -> Shutdown (&DeleteCall);
  108. delete pCall;
  109. if (SelectEvent)
  110. {
  111. CloseHandle (SelectEvent);
  112. }
  113. return E_FAIL;
  114. }
  115. pCall -> SetQ931CallState (Q931_CALL_CONNECTED);
  116. pCall -> Lock();
  117. if (!RegisterWaitForSingleObject(
  118. &SelectWaitHandle, // pointer to the returned handle.
  119. SelectEvent, // the event handle to wait for.
  120. Q931TransportEventHandler, // the callback function.
  121. (PVOID)pCall -> GetCallHandle(),// the context for the callback.
  122. INFINITE, // wait forever.
  123. WT_EXECUTEDEFAULT)) // use the wait thread to call the callback.
  124. {
  125. goto cleanup;
  126. }
  127. _ASSERTE( SelectWaitHandle );
  128. if( SelectWaitHandle == NULL )
  129. {
  130. goto cleanup;
  131. }
  132. //store this in the call context
  133. pCall -> SetNewCallInfo (SelectWaitHandle, SelectEvent,
  134. Q931_CALL_CONNECTED);
  135. SelectEvent = NULL;
  136. pCall -> InitializeRecvBuf();
  137. //post a buffer to winsock to accept messages from the peer
  138. if(!pCall -> PostReadBuffer())
  139. {
  140. H323DBG(( DEBUG_LEVEL_ERROR, "failed to post read buffer on call." ));
  141. goto cleanup;
  142. }
  143. pCall -> Unlock();
  144. H323DBG(( DEBUG_LEVEL_TRACE, "successfully created incoming Q.931 call." ));
  145. //success
  146. return S_OK;
  147. cleanup:
  148. if (pCall)
  149. {
  150. pCall -> Unlock();
  151. pCall -> Shutdown (&DeleteCall);
  152. delete pCall;
  153. }
  154. if (SelectEvent)
  155. {
  156. CloseHandle (SelectEvent);
  157. }
  158. return E_OUTOFMEMORY;
  159. }
  160. void CallProcessIncomingCall (
  161. IN SOCKET Socket,
  162. IN SOCKADDR_IN * LocalAddress,
  163. IN SOCKADDR_IN * RemoteAddress)
  164. {
  165. HRESULT hr;
  166. hr = CallCreateIncomingCall (Socket, LocalAddress, RemoteAddress);
  167. if (hr != S_OK)
  168. {
  169. closesocket (Socket);
  170. }
  171. }
  172. #if DBG
  173. DWORD
  174. ProcessTAPICallRequest(
  175. IN PVOID ContextParameter
  176. )
  177. {
  178. __try
  179. {
  180. return ProcessTAPICallRequestFre( ContextParameter );
  181. }
  182. __except( 1 )
  183. {
  184. TAPI_CALLREQUEST_DATA* pRequestData =
  185. (TAPI_CALLREQUEST_DATA*)ContextParameter;
  186. H323DBG(( DEBUG_LEVEL_TRACE, "TSPI %s event threw exception: %p, %p.",
  187. EventIDToString(pRequestData -> EventID),
  188. pRequestData -> pCall,
  189. pRequestData -> pCallforwardParams ));
  190. _ASSERTE( FALSE );
  191. return 0;
  192. }
  193. }
  194. #endif
  195. DWORD
  196. ProcessTAPICallRequestFre(
  197. IN PVOID ContextParameter)
  198. {
  199. _ASSERTE( ContextParameter );
  200. TAPI_CALLREQUEST_DATA* pCallRequestData = (TAPI_CALLREQUEST_DATA*)ContextParameter;
  201. PH323_CALL pCall = pCallRequestData->pCall;
  202. BOOL fDelete = FALSE;
  203. H323DBG(( DEBUG_LEVEL_TRACE, "TSPI %s event recvd.",
  204. EventIDToString(pCallRequestData -> EventID) ));
  205. pCall -> Lock();
  206. if( pCallRequestData -> EventID == TSPI_DELETE_CALL )
  207. {
  208. pCall -> Unlock();
  209. delete pCallRequestData;
  210. delete pCall;
  211. return EXIT_SUCCESS;
  212. }
  213. if( pCall -> IsCallShutdown() == FALSE )
  214. {
  215. switch( pCallRequestData -> EventID )
  216. {
  217. case TSPI_MAKE_CALL:
  218. pCall -> MakeCall();
  219. break;
  220. case TSPI_ANSWER_CALL:
  221. pCall -> AcceptCall();
  222. break;
  223. case TSPI_DROP_CALL:
  224. pCall -> DropUserInitiated( 0 );
  225. //pCall -> DropCall(0);
  226. break;
  227. case TSPI_RELEASE_U2U:
  228. pCall -> ReleaseU2U();
  229. break;
  230. case TSPI_CALL_HOLD:
  231. pCall -> Hold();
  232. break;
  233. case TSPI_CALL_UNHOLD:
  234. pCall -> UnHold();
  235. break;
  236. case TSPI_CALL_DIVERT:
  237. pCall -> CallDivertOnNoAnswer();
  238. break;
  239. case TSPI_LINEFORWARD_NOSPECIFIC:
  240. case TSPI_LINEFORWARD_SPECIFIC:
  241. pCall -> Forward( pCallRequestData -> EventID,
  242. pCallRequestData -> pCallforwardParams );
  243. break;
  244. case TSPI_SEND_U2U:
  245. pCall -> SendU2U( pCallRequestData -> pBuf->pbBuffer,
  246. pCallRequestData->pBuf->dwLength );
  247. delete pCallRequestData -> pBuf;
  248. break;
  249. default:
  250. _ASSERTE(0);
  251. break;
  252. }
  253. }
  254. pCall -> DecrementIoRefCount( &fDelete );
  255. pCall -> Unlock();
  256. delete pCallRequestData;
  257. if( fDelete == TRUE )
  258. {
  259. H323DBG((DEBUG_LEVEL_TRACE, "call delete:%p.", pCall ));
  260. delete pCall;
  261. }
  262. return EXIT_SUCCESS;
  263. }
  264. //
  265. // CH323Call Methods
  266. //
  267. CH323Call::CH323Call(void)
  268. {
  269. ZeroMemory( (PVOID)this, sizeof(CH323Call) );
  270. /*m_dwFlags = 0;
  271. m_pwszDisplay = NULL;
  272. m_fMonitoringDigits = FALSE;
  273. m_hdCall = NULL;
  274. m_htCall = NULL;
  275. m_dwCallState = NULL;
  276. m_dwOrigin = NULL;
  277. m_dwAddressType = NULL;
  278. m_dwIncomingModes = NULL;
  279. m_dwOutgoingModes = NULL;
  280. m_dwRequestedModes = NULL; // requested media modes
  281. m_hdMSPLine = NULL;
  282. m_htMSPLine = NULL;
  283. //m_fGateKeeperPresent = FALSE;
  284. m_fReadyToAnswer = FALSE;
  285. m_fCallAccepted = FALSE;
  286. // reset addresses
  287. memset((PVOID)&m_CalleeAddr,0,sizeof(H323_ADDR));
  288. memset((PVOID)&m_CallerAddr,0,sizeof(H323_ADDR));
  289. // reset addresses
  290. m_pCalleeAliasNames = NULL;
  291. m_pCallerAliasNames = NULL;
  292. //reset non standard data
  293. memset( (PVOID)&m_NonStandardData, 0, sizeof(H323NonStandardData ) );
  294. //reset the conference ID
  295. ZeroMemory (&m_ConferenceID, sizeof m_ConferenceID);
  296. pFastStart = NULL;
  297. //redet the peer information
  298. memset( (PVOID)&m_peerH245Addr, 0, sizeof(H323_ADDR) );
  299. memset( (PVOID)&m_selfH245Addr, 0, sizeof(H323_ADDR) );
  300. memset( (PVOID)&m_peerNonStandardData, 0, sizeof(H323NonStandardData ) );
  301. memset( (PVOID)&m_peerVendorInfo, 0, sizeof(H323_VENDORINFO) );
  302. memset( (PVOID)&m_peerEndPointType, 0, sizeof(H323_ENDPOINTTYPE) );
  303. m_pPeerFastStart = NULL;
  304. m_pPeerExtraAliasNames = NULL;
  305. m_pPeerDisplay = NULL;
  306. m_hCallEstablishmentTimer = NULL;
  307. m_hCallDivertOnNATimer = NULL;
  308. //Q931call data
  309. m_hTransport = NULL;
  310. m_hTransportWait = NULL;
  311. pRecvBuf = NULL;
  312. m_hSetupSentTimer = NULL;
  313. m_dwStateMachine = 0;
  314. m_dwQ931Flags = 0;
  315. //
  316. fActiveMC = FALSE;
  317. memset( (PVOID)&m_ASNCoderInfo, 0, sizeof(m_ASNCoderInfo));
  318. m_wCallReference = NULL;
  319. m_wQ931CallRef = NULL;
  320. m_IoRefCount = 0;
  321. //RAS call data
  322. wARQSeqNum = 0;
  323. m_wDRQSeqNum = 0;
  324. m_pARQExpireContext = NULL;
  325. m_pDRQExpireContext= NULL;
  326. m_hARQTimer = NULL;
  327. m_hDRQTimer = NULL;
  328. m_dwDRQRetryCount = 0;
  329. m_dwARQRetryCount = 0;
  330. m_fCallInTrnasition = FALSE
  331. m_dwAppSpecific = 0;*/
  332. m_dwFastStart = FAST_START_UNDECIDED;
  333. m_callSocket = INVALID_SOCKET;
  334. m_bStartOfPDU = TRUE;
  335. H323DBG(( DEBUG_LEVEL_TRACE,
  336. "Initialize:m_IoRefCount:%d:%p.", m_IoRefCount, this ));
  337. m_dwRASCallState = RASCALL_STATE_IDLE;
  338. if( InterlockedIncrement( &g_lNumberOfcalls ) == 1 )
  339. {
  340. H323DBG(( DEBUG_LEVEL_TRACE,
  341. "pCall no goes from 0 to 1:g_hCanUnloadDll set.", this ));
  342. ResetEvent( g_hCanUnloadDll );
  343. }
  344. H323DBG(( DEBUG_LEVEL_TRACE, "New pCall object created:%p.", this ));
  345. }
  346. CH323Call::~CH323Call()
  347. {
  348. CALL_SEND_CONTEXT* pSendBuf;
  349. PLIST_ENTRY pLE;
  350. H323DBG(( DEBUG_LEVEL_ERROR, "pCall object deleted:%p.", this ));
  351. if( m_dwFlags & CALLOBJECT_INITIALIZED )
  352. {
  353. while( IsListEmpty( &m_sendBufList ) == FALSE )
  354. {
  355. pLE = RemoveHeadList( &m_sendBufList );
  356. pSendBuf = CONTAINING_RECORD( pLE, CALL_SEND_CONTEXT, ListEntry);
  357. delete pSendBuf->WSABuf.buf;
  358. delete pSendBuf;
  359. }
  360. if( m_hTransportWait != NULL )
  361. {
  362. if( UnregisterWaitEx( m_hTransportWait, NULL ) == FALSE )
  363. {
  364. GetLastError();
  365. }
  366. m_hTransportWait = NULL;
  367. }
  368. if( m_hTransport != NULL )
  369. {
  370. if(!CloseHandle(m_hTransport))
  371. {
  372. WSAGetLastError();
  373. }
  374. m_hTransport = NULL;
  375. }
  376. if( m_callSocket != INVALID_SOCKET )
  377. {
  378. closesocket( m_callSocket );
  379. m_callSocket = INVALID_SOCKET;
  380. }
  381. TermASNCoder();
  382. DeleteCriticalSection( &m_CriticalSection );
  383. }
  384. if( InterlockedDecrement( &g_lNumberOfcalls ) == 0 )
  385. {
  386. H323DBG(( DEBUG_LEVEL_ERROR, "Unload dll event set.%p.", this ));
  387. SetEvent( g_hCanUnloadDll );
  388. }
  389. }
  390. //!!no need to lock
  391. BOOL
  392. CH323Call::Initialize(
  393. IN HTAPICALL htCall,
  394. IN DWORD dwOrigin,
  395. IN DWORD dwCallType
  396. )
  397. {
  398. int index;
  399. int rc;
  400. H323DBG(( DEBUG_LEVEL_ERROR, "call init entered:%p.",this ));
  401. m_pCallerAliasNames = new H323_ALIASNAMES;
  402. if( m_pCallerAliasNames == NULL )
  403. {
  404. H323DBG(( DEBUG_LEVEL_ERROR, "could not allocate caller name." ));
  405. return FALSE;
  406. }
  407. memset( (PVOID)m_pCallerAliasNames, 0, sizeof(H323_ALIASNAMES) );
  408. //H323DBG(( DEBUG_LEVEL_ERROR, "Caller alias count:%d : %p", m_pCallerAliasNames->wCount, this ));
  409. m_pCalleeAliasNames = new H323_ALIASNAMES;
  410. if( m_pCalleeAliasNames == NULL )
  411. {
  412. H323DBG(( DEBUG_LEVEL_ERROR, "could not allocate callee name." ));
  413. goto error1;
  414. }
  415. memset( (PVOID)m_pCalleeAliasNames, 0, sizeof(H323_ALIASNAMES) );
  416. __try
  417. {
  418. if( !InitializeCriticalSectionAndSpinCount( &m_CriticalSection,
  419. 0x80000000 ) )
  420. {
  421. H323DBG(( DEBUG_LEVEL_ERROR, "couldn't alloc critsec for call." ));
  422. goto error2;
  423. }
  424. }
  425. __except( 1 )
  426. {
  427. goto error2;
  428. }
  429. if( dwOrigin == LINECALLORIGIN_OUTBOUND )
  430. {
  431. int iresult = UuidCreate( &m_callIdentifier );
  432. if( (iresult != RPC_S_OK) && (iresult !=RPC_S_UUID_LOCAL_ONLY) )
  433. {
  434. goto error3;
  435. }
  436. }
  437. rc = InitASNCoder();
  438. if( rc != ASN1_SUCCESS )
  439. {
  440. H323DBG((DEBUG_LEVEL_ERROR, "Q931_InitCoder() returned: %d ", rc));
  441. goto error3;
  442. }
  443. rc = InitH450ASNCoder();
  444. if( rc != ASN1_SUCCESS )
  445. {
  446. H323DBG((DEBUG_LEVEL_ERROR, "Q931_InitCoder() returned: %d ", rc));
  447. goto error4;
  448. }
  449. //Create the CRV for this call.
  450. do
  451. {
  452. m_wCallReference = ((WORD)InterlockedIncrement( &g_lCallReference ))
  453. & 0x7fff;
  454. } while( (m_wCallReference == 0) ||
  455. g_pH323Line->CallReferenceDuped( m_wCallReference ) );
  456. //add the call to the call table
  457. index = g_pH323Line -> AddCallToTable((PH323_CALL)this);
  458. if( index == -1 )
  459. {
  460. H323DBG(( DEBUG_LEVEL_ERROR,
  461. "could not add call to call table." ));
  462. goto error5;
  463. }
  464. //By incrementing the g_H323CallID and taking lower 16 bits we get 65536
  465. //unique values and then same values are repeated. Thus we can have only
  466. //65535 simultaneous calls. By using the call table index we make sure that
  467. //no two existing calls have same call handle.
  468. do
  469. {
  470. m_hdCall = (HDRVCALL)( ((BYTE*)NULL) +
  471. MAKELONG( LOWORD((DWORD)index),
  472. (WORD)InterlockedIncrement(&g_H323CallID) ));
  473. } while ( m_hdCall == NULL );
  474. ZeroMemory( (PVOID)&m_prepareToAnswerMsgData, sizeof(BUFFERDESCR) );
  475. m_dwFlags |= CALLOBJECT_INITIALIZED;
  476. m_htCall = htCall;
  477. m_dwCallState = LINECALLSTATE_IDLE;
  478. m_dwOrigin = dwOrigin;
  479. m_hdConf = NULL;
  480. m_wQ931CallRef = m_wCallReference;
  481. m_dwCallType = dwCallType;
  482. // initialize user user information
  483. InitializeListHead( &m_IncomingU2U );
  484. InitializeListHead( &m_OutgoingU2U );
  485. InitializeListHead( &m_sendBufList );
  486. H323DBG(( DEBUG_LEVEL_TRACE,
  487. "m_hdCall:%lx m_htCall:%lx m_wCallReference:%lx : %p .",
  488. m_hdCall, m_htCall, m_wCallReference, this ));
  489. H323DBG(( DEBUG_LEVEL_TRACE, "call init exited:%p.",this ));
  490. return TRUE;
  491. error5:
  492. TermH450ASNCoder();
  493. error4:
  494. TermASNCoder();
  495. error3:
  496. DeleteCriticalSection( &m_CriticalSection );
  497. error2:
  498. delete m_pCalleeAliasNames;
  499. m_pCalleeAliasNames = NULL;
  500. error1:
  501. delete m_pCallerAliasNames;
  502. m_pCallerAliasNames = NULL;
  503. return FALSE;
  504. }
  505. //
  506. //!!must be always called in a lock
  507. //Queues a request made by TAPI to the thread pool
  508. //
  509. BOOL
  510. CH323Call::QueueTAPICallRequest(
  511. IN DWORD EventID,
  512. IN PVOID pBuf
  513. )
  514. {
  515. TAPI_CALLREQUEST_DATA * pCallRequestData = new TAPI_CALLREQUEST_DATA;
  516. BOOL fResult = TRUE;
  517. if( pCallRequestData != NULL )
  518. {
  519. pCallRequestData -> EventID = EventID;
  520. pCallRequestData -> pCall = this;
  521. pCallRequestData -> pBuf = (PBUFFERDESCR)pBuf;
  522. if( !QueueUserWorkItem( ProcessTAPICallRequest, pCallRequestData,
  523. WT_EXECUTEDEFAULT ) )
  524. {
  525. delete pCallRequestData;
  526. fResult = FALSE;
  527. }
  528. m_IoRefCount++;
  529. H323DBG(( DEBUG_LEVEL_TRACE, "TAPICallRequest:m_IoRefCount:%d:%p.",
  530. m_IoRefCount, this ));
  531. }
  532. else
  533. {
  534. fResult = FALSE;
  535. }
  536. return fResult;
  537. }
  538. //always called in lock
  539. void
  540. CH323Call::CopyCallStatus(
  541. IN LPLINECALLSTATUS pCallStatus
  542. )
  543. {
  544. H323DBG(( DEBUG_LEVEL_ERROR, "CopyCallStatus entered:%p.",this ));
  545. // transer call state information
  546. pCallStatus->dwCallState = m_dwCallState;
  547. pCallStatus->dwCallStateMode = m_dwCallStateMode;
  548. // determine call feature based on state
  549. pCallStatus->dwCallFeatures = ( m_dwCallState != LINECALLSTATE_IDLE)?
  550. (H323_CALL_FEATURES) : 0;
  551. H323DBG(( DEBUG_LEVEL_ERROR, "CopyCallStatus exited:%p.",this ));
  552. }
  553. //always called in lock
  554. LONG
  555. CH323Call::CopyCallInfo(
  556. IN LPLINECALLINFO pCallInfo
  557. )
  558. {
  559. DWORD dwCalleeNameSize = 0;
  560. DWORD dwCallerNameSize = 0;
  561. DWORD dwCallerAddressSize = 0;
  562. WCHAR wszIPAddress[20];
  563. DWORD dwNextOffset = sizeof(LINECALLINFO);
  564. DWORD dwU2USize = 0;
  565. PBYTE pU2U = NULL;
  566. LONG retVal = NOERROR;
  567. DWORD dwDivertingNameSize = 0;
  568. DWORD dwDiversionNameSize = 0;
  569. DWORD dwDivertedToNameSize = 0;
  570. DWORD dwCallDataSize = 0;
  571. H323DBG(( DEBUG_LEVEL_ERROR, "CopyCallInfo entered:%p.",this ));
  572. // see if user user info available
  573. if( IsListEmpty( &m_IncomingU2U) == FALSE )
  574. {
  575. PLIST_ENTRY pLE;
  576. PUserToUserLE pU2ULE;
  577. // get first list entry
  578. pLE = m_IncomingU2U.Flink;
  579. // convert to user user structure
  580. pU2ULE = CONTAINING_RECORD(pLE, UserToUserLE, Link);
  581. // transfer info
  582. dwU2USize = pU2ULE->dwU2USize;
  583. pU2U = pU2ULE->pU2U;
  584. }
  585. // initialize caller and callee id flags now
  586. pCallInfo->dwCalledIDFlags = LINECALLPARTYID_UNAVAIL;
  587. pCallInfo->dwCallerIDFlags = LINECALLPARTYID_UNAVAIL;
  588. pCallInfo->dwRedirectingIDFlags = LINECALLPARTYID_UNAVAIL;
  589. pCallInfo->dwRedirectionIDFlags = LINECALLPARTYID_UNAVAIL;
  590. // calculate memory necessary for strings
  591. if( m_pCalleeAliasNames && m_pCalleeAliasNames -> wCount !=0 )
  592. {
  593. dwCalleeNameSize =
  594. H323SizeOfWSZ( m_pCalleeAliasNames -> pItems[0].pData );
  595. }
  596. if( m_pCallerAliasNames && (m_pCallerAliasNames->wCount) )
  597. {
  598. //H323DBG(( DEBUG_LEVEL_ERROR, "Caller alias count:%d : %p", m_pCallerAliasNames->wCount, this ));
  599. dwCallerNameSize =
  600. sizeof(WCHAR) * (m_pCallerAliasNames->pItems[0].wDataLength + 1);
  601. }
  602. if( m_CallerAddr.Addr.IP_Binary.dwAddr != 0 )
  603. {
  604. wsprintfW(wszIPAddress, L"%d.%d.%d.%d",
  605. (m_CallerAddr.Addr.IP_Binary.dwAddr >> 24) & 0xff,
  606. (m_CallerAddr.Addr.IP_Binary.dwAddr >> 16) & 0xff,
  607. (m_CallerAddr.Addr.IP_Binary.dwAddr >> 8) & 0xff,
  608. (m_CallerAddr.Addr.IP_Binary.dwAddr) & 0xff
  609. );
  610. dwCallerAddressSize = (wcslen(wszIPAddress) + 1) * sizeof(WCHAR);
  611. }
  612. if( m_dwCallType & CALLTYPE_DIVERTEDDEST )
  613. {
  614. if( m_pCallReroutingInfo->divertingNrAlias &&
  615. (m_pCallReroutingInfo->divertingNrAlias->wCount !=0) )
  616. {
  617. dwDivertingNameSize = H323SizeOfWSZ(
  618. m_pCallReroutingInfo->divertingNrAlias-> pItems[0].pData );
  619. }
  620. if( m_pCallReroutingInfo->divertedToNrAlias &&
  621. (m_pCallReroutingInfo->divertedToNrAlias->wCount != 0) )
  622. {
  623. dwDivertedToNameSize = sizeof(WCHAR) *
  624. m_pCallReroutingInfo->divertedToNrAlias->pItems[0].wDataLength;
  625. }
  626. }
  627. if( m_dwCallType & CALLTYPE_DIVERTEDSRC_NOROUTING )
  628. {
  629. if( m_pCallReroutingInfo->divertedToNrAlias &&
  630. (m_pCallReroutingInfo->divertedToNrAlias->wCount != 0) )
  631. {
  632. dwDivertedToNameSize = sizeof(WCHAR) *
  633. m_pCallReroutingInfo->divertedToNrAlias->pItems[0].wDataLength;
  634. }
  635. }
  636. if( m_dwCallType & CALLTYPE_DIVERTEDSRC)
  637. {
  638. if( m_pCallReroutingInfo->divertedToNrAlias &&
  639. (m_pCallReroutingInfo->divertedToNrAlias->wCount != 0) )
  640. {
  641. dwDivertedToNameSize = sizeof(WCHAR) *
  642. m_pCallReroutingInfo->divertedToNrAlias->pItems[0].wDataLength;
  643. }
  644. if( m_pCallReroutingInfo->divertingNrAlias &&
  645. (m_pCallReroutingInfo->divertingNrAlias->wCount !=0) )
  646. {
  647. dwDivertingNameSize = H323SizeOfWSZ(
  648. m_pCallReroutingInfo->divertingNrAlias-> pItems[0].pData );
  649. }
  650. }
  651. if( m_CallData.wOctetStringLength != 0 )
  652. {
  653. dwCallDataSize = m_CallData.wOctetStringLength;
  654. }
  655. // determine number of bytes needed
  656. pCallInfo->dwNeededSize = sizeof(LINECALLINFO) +
  657. dwCalleeNameSize +
  658. dwCallerNameSize +
  659. dwCallerAddressSize +
  660. dwDivertingNameSize +
  661. dwDiversionNameSize +
  662. dwDivertedToNameSize +
  663. dwU2USize +
  664. dwCallDataSize
  665. ;
  666. // see if structure size is large enough
  667. if (pCallInfo->dwTotalSize >= pCallInfo->dwNeededSize)
  668. {
  669. // record number of bytes used
  670. pCallInfo->dwUsedSize = pCallInfo->dwNeededSize;
  671. // validate string size
  672. if (dwCalleeNameSize > 0)
  673. {
  674. if( m_pCalleeAliasNames -> pItems[0].wType == e164_chosen )
  675. {
  676. // callee number was specified
  677. pCallInfo->dwCalledIDFlags = LINECALLPARTYID_ADDRESS;
  678. // determine size and offset for callee number
  679. pCallInfo->dwCalledIDSize = dwCalleeNameSize;
  680. pCallInfo->dwCalledIDOffset = dwNextOffset;
  681. // copy call info after fixed portion
  682. CopyMemory(
  683. (PVOID)((LPBYTE)pCallInfo + pCallInfo->dwCalledIDOffset),
  684. (LPBYTE)m_pCalleeAliasNames -> pItems[0].pData,
  685. pCallInfo->dwCalledIDSize );
  686. }
  687. else
  688. {
  689. // callee name was specified
  690. pCallInfo->dwCalledIDFlags = LINECALLPARTYID_NAME;
  691. // determine size and offset for callee name
  692. pCallInfo->dwCalledIDNameSize = dwCalleeNameSize;
  693. pCallInfo->dwCalledIDNameOffset = dwNextOffset;
  694. // copy call info after fixed portion
  695. CopyMemory(
  696. (PVOID)((LPBYTE)pCallInfo + pCallInfo->dwCalledIDNameOffset),
  697. (LPBYTE)m_pCalleeAliasNames -> pItems[0].pData,
  698. pCallInfo->dwCalledIDNameSize );
  699. }
  700. // adjust offset to include string
  701. dwNextOffset += dwCalleeNameSize;
  702. H323DBG(( DEBUG_LEVEL_TRACE,
  703. "callee name: %S.", m_pCalleeAliasNames -> pItems[0].pData ));
  704. }
  705. // validate string size
  706. if (dwCallerNameSize > 0)
  707. {
  708. // caller name was specified
  709. pCallInfo->dwCallerIDFlags = LINECALLPARTYID_NAME;
  710. // determine size and offset for caller name
  711. pCallInfo->dwCallerIDNameSize = dwCallerNameSize;
  712. pCallInfo->dwCallerIDNameOffset = dwNextOffset;
  713. // copy call info after fixed portion
  714. CopyMemory(
  715. (PVOID)((LPBYTE)pCallInfo + pCallInfo->dwCallerIDNameOffset),
  716. (LPBYTE)m_pCallerAliasNames -> pItems[0].pData,
  717. pCallInfo->dwCallerIDNameSize );
  718. //H323DBG(( DEBUG_LEVEL_ERROR, "Caller alias count:%d : %p", m_pCallerAliasNames->wCount, this ));
  719. // adjust offset to include string
  720. dwNextOffset += dwCallerNameSize;
  721. H323DBG(( DEBUG_LEVEL_TRACE,
  722. "caller name: %S.", m_pCallerAliasNames -> pItems[0].pData ));
  723. }
  724. if( dwCallerAddressSize > 0 )
  725. {
  726. // caller number was specified
  727. pCallInfo->dwCallerIDFlags |= LINECALLPARTYID_ADDRESS;
  728. // determine size and offset for caller number
  729. pCallInfo->dwCallerIDSize = dwCallerAddressSize;
  730. pCallInfo->dwCallerIDOffset = dwNextOffset;
  731. // copy call info after fixed portion
  732. CopyMemory(
  733. (PVOID)((LPBYTE)pCallInfo + pCallInfo->dwCallerIDOffset),
  734. (LPBYTE)wszIPAddress,
  735. pCallInfo->dwCallerIDSize );
  736. // adjust offset to include string
  737. dwNextOffset += dwCallerAddressSize;
  738. }
  739. // validate buffer
  740. if (dwU2USize > 0)
  741. {
  742. // determine size and offset of info
  743. pCallInfo->dwUserUserInfoSize = dwU2USize;
  744. pCallInfo->dwUserUserInfoOffset = dwNextOffset;
  745. // copy user user info after fixed portion
  746. CopyMemory(
  747. (PVOID)((LPBYTE)pCallInfo + pCallInfo->dwUserUserInfoOffset),
  748. (LPBYTE)pU2U,
  749. pCallInfo->dwUserUserInfoSize );
  750. // adjust offset to include string
  751. dwNextOffset += pCallInfo->dwUserUserInfoSize;
  752. }
  753. if( dwDivertingNameSize > 0 )
  754. {
  755. // caller name was specified
  756. pCallInfo->dwRedirectingIDFlags = LINECALLPARTYID_NAME;
  757. // determine size and offset for caller name
  758. pCallInfo->dwRedirectingIDNameSize = dwDivertingNameSize;
  759. pCallInfo->dwRedirectingIDNameOffset = dwNextOffset;
  760. // copy call info after fixed portion
  761. CopyMemory(
  762. (PVOID)((LPBYTE)pCallInfo + pCallInfo->dwRedirectingIDNameOffset),
  763. (LPBYTE)(m_pCallReroutingInfo->divertingNrAlias->pItems[0].pData),
  764. pCallInfo->dwRedirectingIDNameSize );
  765. // adjust offset to include string
  766. dwNextOffset += dwDivertingNameSize;
  767. H323DBG(( DEBUG_LEVEL_TRACE, "diverting name: %S.",
  768. m_pCallReroutingInfo->divertingNrAlias->pItems[0].pData ));
  769. }
  770. if( dwDiversionNameSize > 0 )
  771. {
  772. // caller name was specified
  773. pCallInfo->dwRedirectionIDFlags = LINECALLPARTYID_NAME;
  774. // determine size and offset for caller name
  775. pCallInfo->dwRedirectionIDNameSize = dwDiversionNameSize;
  776. pCallInfo->dwRedirectionIDNameOffset = dwNextOffset;
  777. // copy call info after fixed portion
  778. CopyMemory(
  779. (PVOID)((LPBYTE)pCallInfo + pCallInfo->dwRedirectionIDNameOffset),
  780. (LPBYTE)(m_pCallReroutingInfo->diversionNrAlias->pItems[0].pData),
  781. pCallInfo->dwRedirectionIDNameSize );
  782. // adjust offset to include string
  783. dwNextOffset += dwDiversionNameSize;
  784. H323DBG(( DEBUG_LEVEL_TRACE, "redirection name: %S.",
  785. m_pCallReroutingInfo->diversionNrAlias->pItems[0].pData ));
  786. }
  787. if( dwDivertedToNameSize > 0 )
  788. {
  789. pCallInfo->dwRedirectionIDFlags = LINECALLPARTYID_NAME;
  790. // determine size and offset for caller name
  791. pCallInfo->dwRedirectionIDNameSize = dwDivertedToNameSize;
  792. pCallInfo->dwRedirectionIDNameOffset = dwNextOffset;
  793. // copy call info after fixed portion
  794. CopyMemory(
  795. (PVOID)((LPBYTE)pCallInfo + pCallInfo->dwRedirectionIDNameOffset),
  796. (LPBYTE)(m_pCallReroutingInfo->divertedToNrAlias->pItems[0].pData),
  797. pCallInfo->dwRedirectionIDNameSize );
  798. // adjust offset to include string
  799. dwNextOffset += pCallInfo->dwRedirectionIDNameSize;
  800. // adjust offset to include string
  801. dwNextOffset += dwDivertedToNameSize;
  802. H323DBG(( DEBUG_LEVEL_TRACE, "redirection name: %S.",
  803. m_pCallReroutingInfo->divertedToNrAlias->pItems[0].pData ));
  804. }
  805. //pass on the call data
  806. if( dwCallDataSize > 0 )
  807. {
  808. pCallInfo -> dwCallDataSize = dwCallDataSize;
  809. pCallInfo -> dwCallDataOffset = dwNextOffset;
  810. CopyMemory(
  811. (PVOID)((LPBYTE)pCallInfo + pCallInfo -> dwCallDataOffset),
  812. (LPBYTE)m_CallData.pOctetString,
  813. pCallInfo -> dwCallDataSize );
  814. dwNextOffset += dwCallDataSize;
  815. }
  816. }
  817. else if (pCallInfo->dwTotalSize >= sizeof(LINECALLINFO))
  818. {
  819. H323DBG(( DEBUG_LEVEL_WARNING,
  820. "linecallinfo structure too small for strings." ));
  821. // structure only contains fixed portion
  822. pCallInfo->dwUsedSize = sizeof(LINECALLINFO);
  823. }
  824. else
  825. {
  826. H323DBG(( DEBUG_LEVEL_ERROR, "linecallinfo structure too small." ));
  827. // structure is too small
  828. return LINEERR_STRUCTURETOOSMALL;
  829. }
  830. // initialize call line device and address info
  831. pCallInfo->dwLineDeviceID = g_pH323Line->GetDeviceID();
  832. pCallInfo->dwAddressID = 0;
  833. // initialize variable call parameters
  834. pCallInfo->dwOrigin = m_dwOrigin;
  835. pCallInfo->dwMediaMode = m_dwIncomingModes | m_dwOutgoingModes;
  836. if( m_dwCallType & CALLTYPE_DIVERTEDDEST )
  837. {
  838. if(m_pCallReroutingInfo->diversionReason==DiversionReason_cfu)
  839. {
  840. pCallInfo->dwReason = LINECALLREASON_FWDUNCOND;
  841. }
  842. else if(m_pCallReroutingInfo->diversionReason==DiversionReason_cfnr)
  843. {
  844. pCallInfo->dwReason = LINECALLREASON_FWDNOANSWER;
  845. }
  846. else
  847. {
  848. pCallInfo->dwReason = LINECALLREASON_FWDBUSY;
  849. }
  850. }
  851. if( m_dwCallType & CALLTYPE_TRANSFEREDDEST )
  852. {
  853. pCallInfo->dwReason = LINECALLREASON_TRANSFER;
  854. }
  855. else
  856. {
  857. pCallInfo->dwReason = LINECALLREASON_DIRECT;
  858. }
  859. pCallInfo->dwCallStates = (m_dwOrigin==LINECALLORIGIN_INBOUND)
  860. ? H323_CALL_INBOUNDSTATES
  861. : H323_CALL_OUTBOUNDSTATES
  862. ;
  863. // initialize constant call parameters
  864. pCallInfo->dwBearerMode = H323_LINE_BEARERMODES;
  865. pCallInfo->dwRate = H323_LINE_MAXRATE;
  866. // initialize unsupported call capabilities
  867. pCallInfo->dwConnectedIDFlags = LINECALLPARTYID_UNAVAIL;
  868. //pass on the dwAppSpecific info
  869. pCallInfo -> dwAppSpecific = m_dwAppSpecific;
  870. H323DBG(( DEBUG_LEVEL_ERROR, "CopyCallInfo exited:%p.",this ));
  871. return retVal;
  872. }
  873. //!!always called in lock
  874. BOOL
  875. CH323Call::HandleReadyToInitiate(
  876. IN PTspMspMessage pMessage
  877. )
  878. {
  879. Q931_SETUP_ASN setupASN;
  880. WORD wCount;
  881. DWORD dwAPDUType = 0;
  882. H323DBG(( DEBUG_LEVEL_ERROR, "HandleReadyToInitiate entered:%p.", this ));
  883. //set the additional callee addresses and callee aliases
  884. //see if there is a fast-connect proposal
  885. if( pMessage->dwEncodedASNSize != 0 )
  886. {
  887. if( !ParseSetupASN( pMessage ->pEncodedASNBuf,
  888. pMessage->dwEncodedASNSize,
  889. &setupASN,
  890. &dwAPDUType ))
  891. {
  892. goto cleanup;
  893. }
  894. if( setupASN.fFastStartPresent )
  895. {
  896. _ASSERTE( !m_pFastStart );
  897. m_pFastStart = setupASN.pFastStart;
  898. setupASN.pFastStart = NULL;
  899. m_dwFastStart = FAST_START_SELF_AVAIL;
  900. }
  901. else
  902. {
  903. m_dwFastStart = FAST_START_NOTAVAIL;
  904. }
  905. if( setupASN.pCallerAliasList && !RasIsRegistered() )
  906. {
  907. //_ASSERTE(0);
  908. if( m_pCallerAliasNames == NULL )
  909. {
  910. m_pCallerAliasNames = setupASN.pCallerAliasList;
  911. //dont release this alias list
  912. setupASN.pCallerAliasList = NULL;
  913. }
  914. else
  915. {
  916. wCount = m_pCallerAliasNames->wCount +
  917. setupASN.pCallerAliasList->wCount;
  918. PH323_ALIASITEM tempPtr = setupASN.pCallerAliasList->pItems;
  919. setupASN.pCallerAliasList->pItems = (PH323_ALIASITEM)realloc(
  920. (PVOID)setupASN.pCallerAliasList->pItems,
  921. wCount * sizeof(H323_ALIASITEM) );
  922. if( setupASN.pCallerAliasList->pItems == NULL )
  923. {
  924. //restore the old pointer in case enough memory was not
  925. //available to expand the memory block
  926. setupASN.pCallerAliasList->pItems = tempPtr;
  927. }
  928. else
  929. {
  930. CopyMemory(
  931. (PVOID)&(setupASN.pCallerAliasList->pItems[setupASN.pCallerAliasList->wCount]),
  932. (PVOID)m_pCallerAliasNames->pItems,
  933. m_pCallerAliasNames->wCount * sizeof(H323_ALIASITEM) );
  934. setupASN.pCallerAliasList->wCount = wCount;
  935. delete m_pCallerAliasNames->pItems;
  936. delete m_pCallerAliasNames;
  937. m_pCallerAliasNames = setupASN.pCallerAliasList;
  938. setupASN.pCallerAliasList = NULL;
  939. }
  940. }
  941. }
  942. //add the callee aliases sent by the MSP
  943. if( setupASN.pCalleeAliasList != NULL )
  944. {
  945. //_ASSERTE(0);
  946. if( m_pCalleeAliasNames == NULL )
  947. {
  948. m_pCalleeAliasNames = setupASN.pCalleeAliasList;
  949. //dont release this alias list
  950. setupASN.pCalleeAliasList = NULL;
  951. }
  952. else
  953. {
  954. wCount = m_pCalleeAliasNames->wCount +
  955. setupASN.pCalleeAliasList->wCount;
  956. PH323_ALIASITEM tempPtr = m_pCalleeAliasNames->pItems;
  957. m_pCalleeAliasNames->pItems = (PH323_ALIASITEM)realloc(
  958. (PVOID)m_pCalleeAliasNames->pItems,
  959. wCount * sizeof(H323_ALIASITEM) );
  960. if( m_pCalleeAliasNames->pItems == NULL )
  961. {
  962. //restore the old pointer in case enough memory was not
  963. //available to expand the memory block
  964. m_pCalleeAliasNames->pItems = tempPtr;
  965. goto cleanup;
  966. }
  967. CopyMemory(
  968. (PVOID)&(m_pCalleeAliasNames->pItems[m_pCalleeAliasNames->wCount]),
  969. (PVOID)setupASN.pCalleeAliasList->pItems,
  970. setupASN.pCalleeAliasList->wCount * sizeof(H323_ALIASITEM) );
  971. m_pCalleeAliasNames->wCount = wCount;
  972. delete setupASN.pCalleeAliasList->pItems;
  973. delete setupASN.pCalleeAliasList;
  974. setupASN.pCalleeAliasList = NULL;
  975. }
  976. }
  977. FreeSetupASN( &setupASN );
  978. }
  979. else
  980. {
  981. m_dwFastStart = FAST_START_NOTAVAIL;
  982. }
  983. //send the setup message
  984. if( !SendSetupMessage() )
  985. {
  986. DropCall( 0 );
  987. }
  988. H323DBG(( DEBUG_LEVEL_ERROR, "HandleReadyToInitiate exited:%p.", this ));
  989. return TRUE;
  990. cleanup:
  991. CloseCall( 0 );
  992. FreeSetupASN( &setupASN );
  993. return FALSE;
  994. }
  995. //!!always called in lock
  996. BOOL
  997. CH323Call::HandleProceedWithAnswer(
  998. IN PTspMspMessage pMessage
  999. )
  1000. {
  1001. Q931_CALL_PROCEEDING_ASN proceedingASN;
  1002. DWORD dwAPDUType = 0;
  1003. PH323_ALIASITEM pwszDivertedToAlias = NULL;
  1004. WCHAR *pwszAliasName = NULL;
  1005. WORD wAliasLength = 0;
  1006. H323DBG(( DEBUG_LEVEL_TRACE, "HandleProceedWithAnswer entered:%p.", this ));
  1007. if( m_dwCallType & CALLTYPE_DIVERTED_SERVED )
  1008. {
  1009. H323DBG(( DEBUG_LEVEL_TRACE,
  1010. "Call already diverted. ignore the message:%p.", this ));
  1011. return TRUE;
  1012. }
  1013. //see if there is a fast-connect proposal
  1014. if( pMessage->dwEncodedASNSize != 0 )
  1015. {
  1016. if( !ParseProceedingASN(pMessage ->pEncodedASNBuf,
  1017. pMessage->dwEncodedASNSize,
  1018. &proceedingASN,
  1019. &dwAPDUType ) )
  1020. {
  1021. goto cleanup;
  1022. }
  1023. if( proceedingASN.fH245AddrPresent )
  1024. {
  1025. m_selfH245Addr = proceedingASN.h245Addr;
  1026. }
  1027. if( proceedingASN.fFastStartPresent &&
  1028. (m_dwFastStart!=FAST_START_NOTAVAIL) )
  1029. {
  1030. _ASSERTE( m_pFastStart == NULL );
  1031. m_pFastStart = proceedingASN.pFastStart;
  1032. m_dwFastStart = FAST_START_AVAIL;
  1033. //we keep a reference to the fast start list so don't release it
  1034. proceedingASN.pFastStart = NULL;
  1035. proceedingASN.fFastStartPresent = FALSE;
  1036. }
  1037. /*else
  1038. {
  1039. m_dwFastStart = FAST_START_NOTAVAIL;
  1040. }*/
  1041. FreeProceedingASN( &proceedingASN );
  1042. }
  1043. /*else
  1044. {
  1045. m_dwFastStart = FAST_START_NOTAVAIL;
  1046. }*/
  1047. //send proceeding message to the peer
  1048. if(!SendProceeding() )
  1049. {
  1050. goto cleanup;
  1051. }
  1052. //send alerting message to the peer
  1053. if( !SendQ931Message(NO_INVOKEID, 0, 0, ALERTINGMESSAGETYPE, NO_H450_APDU) )
  1054. {
  1055. goto cleanup;
  1056. }
  1057. m_dwStateMachine = Q931_ALERT_SENT;
  1058. //for TRANSFEREDDEST call directly accept the call wihtout the user
  1059. //answering the call
  1060. if( (m_dwCallType & CALLTYPE_TRANSFEREDDEST) && m_hdRelatedCall )
  1061. {
  1062. AcceptCall();
  1063. }
  1064. if( m_pCallerAliasNames && (m_pCallerAliasNames -> wCount > 0) )
  1065. {
  1066. pwszAliasName = m_pCallerAliasNames->pItems[0].pData;
  1067. wAliasLength = (m_pCallerAliasNames->pItems[0].wDataLength+1)
  1068. * sizeof(WCHAR);
  1069. //H323DBG(( DEBUG_LEVEL_ERROR, "Caller alias count:%d : %p", m_pCallerAliasNames->wCount, this ));
  1070. }
  1071. pwszDivertedToAlias = g_pH323Line->CallToBeDiverted(
  1072. pwszAliasName,
  1073. wAliasLength,
  1074. LINEFORWARDMODE_NOANSW | LINEFORWARDMODE_NOANSWSPECIFIC |
  1075. LINEFORWARDMODE_BUSYNA | LINEFORWARDMODE_BUSYNASPECIFIC );
  1076. //if call is to be diverted for no answer, start the timer
  1077. if( pwszDivertedToAlias != NULL )
  1078. {
  1079. if( !StartTimerForCallDiversionOnNA( pwszDivertedToAlias ) )
  1080. {
  1081. goto cleanup;
  1082. }
  1083. }
  1084. H323DBG(( DEBUG_LEVEL_TRACE, "HandleProceedWithAnswer exited:%p.",this ));
  1085. return TRUE;
  1086. cleanup:
  1087. CloseCall( 0 );
  1088. return FALSE;
  1089. }
  1090. //!!always called in lock
  1091. BOOL
  1092. CH323Call::HandleReadyToAnswer(
  1093. IN PTspMspMessage pMessage
  1094. )
  1095. {
  1096. Q931_CALL_PROCEEDING_ASN proceedingASN;
  1097. DWORD dwAPDUType = 0;
  1098. PH323_CALL pConsultCall = NULL;
  1099. H323DBG(( DEBUG_LEVEL_ERROR, "HandleReadyToAnswer entered:%p.",this ));
  1100. m_fReadyToAnswer = TRUE;
  1101. //see if there is a fast-connect proposal
  1102. if( pMessage->dwEncodedASNSize != 0 )
  1103. {
  1104. if( !ParseProceedingASN(pMessage ->pEncodedASNBuf,
  1105. pMessage->dwEncodedASNSize,
  1106. &proceedingASN,
  1107. &dwAPDUType) )
  1108. {
  1109. goto cleanup;
  1110. }
  1111. if( proceedingASN.fH245AddrPresent )
  1112. {
  1113. m_selfH245Addr = proceedingASN.h245Addr;
  1114. }
  1115. if( proceedingASN.fFastStartPresent &&
  1116. (m_dwFastStart!=FAST_START_NOTAVAIL) )
  1117. {
  1118. _ASSERTE( m_pFastStart == NULL );
  1119. m_pFastStart = proceedingASN.pFastStart;
  1120. m_dwFastStart = FAST_START_AVAIL;
  1121. //we keep a reference to the fast start list so don't release it
  1122. proceedingASN.pFastStart = NULL;
  1123. proceedingASN.fFastStartPresent = FALSE;
  1124. }
  1125. else
  1126. {
  1127. m_dwFastStart = FAST_START_NOTAVAIL;
  1128. }
  1129. FreeProceedingASN( &proceedingASN );
  1130. }
  1131. else
  1132. {
  1133. m_dwFastStart = FAST_START_NOTAVAIL;
  1134. }
  1135. if( m_fCallAccepted )
  1136. {
  1137. // validate status
  1138. if( !AcceptH323Call() )
  1139. {
  1140. H323DBG(( DEBUG_LEVEL_ERROR,
  1141. "error answering call 0x%08lx.", this ));
  1142. // failure
  1143. goto cleanup;
  1144. }
  1145. //lock the primary call after replacement call to avoid deadlock
  1146. if( (m_dwCallType & CALLTYPE_TRANSFEREDDEST) && m_hdRelatedCall )
  1147. {
  1148. QueueSuppServiceWorkItem( SWAP_REPLACEMENT_CALL,
  1149. m_hdCall, (ULONG_PTR)m_hdRelatedCall );
  1150. }
  1151. else
  1152. {
  1153. //send MSP start H245
  1154. SendMSPStartH245( NULL, NULL );
  1155. //tell MSP about connect state
  1156. SendMSPMessage( SP_MSG_ConnectComplete, 0, 0, NULL );
  1157. }
  1158. //change call state to accepted from offering
  1159. ChangeCallState( LINECALLSTATE_CONNECTED, 0 );
  1160. }
  1161. H323DBG(( DEBUG_LEVEL_ERROR, "HandleReadyToAnswer exited:%p.",this ));
  1162. return TRUE;
  1163. cleanup:
  1164. CloseCall( 0 );
  1165. return FALSE;
  1166. }
  1167. //!!This function must be always called in a lock. The calling function should
  1168. //not unlock the call object as this function itself unlocks the call object
  1169. BOOL
  1170. CH323Call::HandleMSPMessage(
  1171. IN PTspMspMessage pMessage,
  1172. IN HDRVMSPLINE hdMSPLine,
  1173. IN HTAPIMSPLINE htMSPLine
  1174. )
  1175. {
  1176. BOOL fResult = TRUE;
  1177. PH323_CALL pCall = NULL;
  1178. ASN1octetstring_t pH245PDU;
  1179. H323DBG(( DEBUG_LEVEL_TRACE, "HandleMSPMessage entered:%p.",this ));
  1180. H323DBG(( DEBUG_LEVEL_TRACE, "MSP message:%s recvd.",
  1181. H323TSPMessageToString(pMessage->MessageType) ));
  1182. switch( pMessage -> MessageType )
  1183. {
  1184. case SP_MSG_ReadyToInitiate:
  1185. // The Q.931 connection should be in the connected state by now
  1186. if( pMessage -> MsgBody.ReadyToInitiateMessage.hMSPReplacementCall != NULL )
  1187. {
  1188. //unlock the primary call before locking the related call
  1189. Unlock();
  1190. pCall=g_pH323Line -> FindH323CallAndLock(m_hdRelatedCall);
  1191. if( pCall == NULL )
  1192. {
  1193. //transfered call is not around so close the primary call
  1194. CloseCall( 0 );
  1195. return TRUE;
  1196. }
  1197. fResult = pCall -> HandleReadyToInitiate( pMessage );
  1198. pCall -> Unlock();
  1199. }
  1200. else
  1201. {
  1202. m_hdMSPLine = hdMSPLine;
  1203. m_htMSPLine = htMSPLine;
  1204. fResult = HandleReadyToInitiate( pMessage );
  1205. Unlock();
  1206. }
  1207. break;
  1208. case SP_MSG_ProceedWithAnswer:
  1209. if( pMessage -> MsgBody.ProceedWithAnswerMessage.hMSPReplacementCall != NULL )
  1210. {
  1211. //unlock the primary call before locking the related call
  1212. Unlock();
  1213. pCall=g_pH323Line -> FindH323CallAndLock(m_hdRelatedCall);
  1214. if( pCall == NULL )
  1215. {
  1216. //transfered call is not around so close the primary call
  1217. CloseCall( 0 );
  1218. return FALSE;
  1219. }
  1220. fResult = pCall -> HandleProceedWithAnswer( pMessage );
  1221. pCall -> Unlock();
  1222. }
  1223. else
  1224. {
  1225. m_hdMSPLine = hdMSPLine;
  1226. m_htMSPLine = htMSPLine;
  1227. fResult = HandleProceedWithAnswer( pMessage );
  1228. Unlock();
  1229. }
  1230. break;
  1231. case SP_MSG_ReadyToAnswer:
  1232. if( pMessage -> MsgBody.ReadyToAnswerMessage.hMSPReplacementCall != NULL )
  1233. {
  1234. //unlock the primary call before locking the related call
  1235. Unlock();
  1236. pCall=g_pH323Line -> FindH323CallAndLock(m_hdRelatedCall);
  1237. if( pCall== NULL )
  1238. {
  1239. //transfered call is not around so close the primary call
  1240. CloseCall( 0 );
  1241. return FALSE;
  1242. }
  1243. fResult = pCall -> HandleReadyToAnswer( pMessage );
  1244. pCall -> Unlock();
  1245. }
  1246. else
  1247. {
  1248. //decode call_proceding message and extract local fast
  1249. //start inforamtion and local H245 address
  1250. fResult = HandleReadyToAnswer( pMessage );
  1251. Unlock();
  1252. }
  1253. break;
  1254. case SP_MSG_ReleaseCall:
  1255. //shutdown the H323 call
  1256. CloseCall( LINEDISCONNECTMODE_CANCELLED );
  1257. Unlock();
  1258. break;
  1259. case SP_MSG_H245Terminated:
  1260. //shutdown the H323 call
  1261. CloseCall( LINEDISCONNECTMODE_NORMAL );
  1262. Unlock();
  1263. break;
  1264. case SP_MSG_SendDTMFDigits:
  1265. if( m_fMonitoringDigits == TRUE )
  1266. {
  1267. WCHAR * pwch = pMessage->pWideChars;
  1268. H323DBG(( DEBUG_LEVEL_VERBOSE, "dtmf digits recvd:%S.", pwch));
  1269. // process each digit
  1270. WORD indexI=0;
  1271. while( indexI < pMessage->MsgBody.SendDTMFDigitsMessage.wNumDigits )
  1272. {
  1273. // signal incoming
  1274. PostLineEvent(
  1275. LINE_MONITORDIGITS,
  1276. (DWORD_PTR)*pwch,
  1277. LINEDIGITMODE_DTMF,
  1278. GetTickCount()
  1279. );
  1280. ++pwch;
  1281. indexI++;
  1282. }
  1283. }
  1284. Unlock();
  1285. break;
  1286. case SP_MSG_LegacyDefaultAlias:
  1287. if( pMessage -> MsgBody.LegacyDefaultAliasMessage.wNumChars > 0 )
  1288. {
  1289. if( !RasIsRegistered() )
  1290. {
  1291. _ASSERTE( m_pwszDisplay == NULL );
  1292. m_pwszDisplay = new WCHAR[
  1293. pMessage -> MsgBody.LegacyDefaultAliasMessage.wNumChars ];
  1294. if( m_pwszDisplay != NULL )
  1295. {
  1296. CopyMemory(
  1297. (PVOID)m_pwszDisplay,
  1298. pMessage->pWideChars,
  1299. sizeof(WCHAR) * pMessage -> MsgBody.LegacyDefaultAliasMessage.wNumChars
  1300. );
  1301. }
  1302. }
  1303. }
  1304. Unlock();
  1305. break;
  1306. case SP_MSG_H245PDU:
  1307. if( (pMessage ->pEncodedASNBuf) && (pMessage->dwEncodedASNSize != 0) )
  1308. {
  1309. pH245PDU.value = pMessage ->pEncodedASNBuf;
  1310. pH245PDU.length = pMessage->dwEncodedASNSize;
  1311. fResult = SendQ931Message( NO_INVOKEID, 0, (ULONG_PTR)&pH245PDU,
  1312. FACILITYMESSAGETYPE, NO_H450_APDU );
  1313. }
  1314. Unlock();
  1315. break;
  1316. case SP_MSG_RASRegistrationEvent:
  1317. default:
  1318. _ASSERTE(0);
  1319. Unlock();
  1320. break;
  1321. }
  1322. H323DBG(( DEBUG_LEVEL_ERROR, "HandleMSPMessage exited:%p.",this ));
  1323. return fResult;
  1324. }
  1325. //!!always called in a lock
  1326. void
  1327. CH323Call::SendMSPMessage(
  1328. IN TspMspMessageType messageType,
  1329. IN BYTE* pbEncodedBuf,
  1330. IN DWORD dwLength,
  1331. IN HDRVCALL hReplacementCall
  1332. )
  1333. {
  1334. TspMspMessageEx messageEx;
  1335. HTAPIMSPLINE hMSP = MSP_HANDLE_UNKNOWN;
  1336. int iError = 0;
  1337. int iLen = sizeof(SOCKADDR_IN);
  1338. SOCKADDR_IN* psaLocalQ931Addr = NULL;
  1339. H323DBG(( DEBUG_LEVEL_ERROR, "SendMSPMessage:%s entered:%p.",
  1340. H323TSPMessageToString(messageType), this ));
  1341. messageEx.message.MessageType = messageType;
  1342. switch( messageType )
  1343. {
  1344. case SP_MSG_InitiateCall:
  1345. messageEx.message.MsgBody.InitiateCallMessage.hTSPReplacementCall =
  1346. (HANDLE)hReplacementCall;
  1347. messageEx.message.MsgBody.InitiateCallMessage.hTSPConferenceCall =
  1348. m_hdConf;
  1349. psaLocalQ931Addr =
  1350. &messageEx.message.MsgBody.InitiateCallMessage.saLocalQ931Addr;
  1351. ZeroMemory( (PVOID)psaLocalQ931Addr, sizeof(SOCKADDR_IN) );
  1352. *psaLocalQ931Addr = m_LocalAddr;
  1353. psaLocalQ931Addr->sin_family = AF_INET;
  1354. break;
  1355. case SP_MSG_PrepareToAnswer:
  1356. if( (dwLength<=0) || (dwLength > sizeof(messageEx.pEncodedASN)) ||
  1357. (!pbEncodedBuf) )
  1358. {
  1359. CloseCall( 0 );
  1360. return;
  1361. }
  1362. messageEx.message.MsgBody.PrepareToAnswerMessage.hReplacementCall =
  1363. (HANDLE)hReplacementCall;
  1364. psaLocalQ931Addr =
  1365. &messageEx.message.MsgBody.PrepareToAnswerMessage.saLocalQ931Addr;
  1366. ZeroMemory( (PVOID)psaLocalQ931Addr, sizeof(SOCKADDR_IN) );
  1367. *psaLocalQ931Addr = m_LocalAddr;
  1368. psaLocalQ931Addr->sin_family = AF_INET;
  1369. //send the received Setup message. This should have the information
  1370. //about m_pPeerFastStart param as wel
  1371. CopyMemory( (PVOID)messageEx.message.pEncodedASNBuf,
  1372. (PVOID)pbEncodedBuf, dwLength );
  1373. break;
  1374. case SP_MSG_SendDTMFDigits:
  1375. if( (dwLength<=0) || (dwLength > sizeof(messageEx.pEncodedASN)) ||
  1376. (!pbEncodedBuf) )
  1377. {
  1378. CloseCall( 0 );
  1379. return;
  1380. }
  1381. hMSP = m_htMSPLine;
  1382. messageEx.message.MsgBody.SendDTMFDigitsMessage.wNumDigits =
  1383. (WORD)dwLength;
  1384. dwLength = (dwLength+1) * sizeof(WCHAR);
  1385. CopyMemory( (PVOID)messageEx.message.pEncodedASNBuf,
  1386. (PVOID)pbEncodedBuf, dwLength );
  1387. break;
  1388. case SP_MSG_ConnectComplete:
  1389. case SP_MSG_CallShutdown:
  1390. //dont set anything
  1391. hMSP = m_htMSPLine;
  1392. break;
  1393. case SP_MSG_H245PDU:
  1394. case SP_MSG_AnswerCall:
  1395. hMSP = m_htMSPLine;
  1396. break;
  1397. case SP_MSG_Hold:
  1398. hMSP = m_htMSPLine;
  1399. messageEx.message.MsgBody.HoldMessage.fHold = (BOOL)dwLength;
  1400. dwLength = 0;
  1401. break;
  1402. }
  1403. messageEx.message.dwMessageSize = sizeof(TspMspMessage) + dwLength
  1404. - ((dwLength)?sizeof(WORD):0);
  1405. if( messageType == SP_MSG_SendDTMFDigits )
  1406. {
  1407. messageEx.message.dwEncodedASNSize = 0;
  1408. }
  1409. else
  1410. {
  1411. messageEx.message.dwEncodedASNSize = dwLength;
  1412. }
  1413. //send msp message
  1414. PostLineEvent (
  1415. LINE_SENDMSPDATA,
  1416. (DWORD_PTR)hMSP, //This handle should be NULL when htCall param is a valid value
  1417. (DWORD_PTR)&(messageEx.message),
  1418. messageEx.message.dwMessageSize);
  1419. H323DBG(( DEBUG_LEVEL_ERROR, "SendMSPMessage exited:%p.",this ));
  1420. return;
  1421. }
  1422. //always called in lock
  1423. void
  1424. CH323Call::SendMSPStartH245(
  1425. PH323_ADDR pPeerH245Addr,
  1426. PH323_FASTSTART pPeerFastStart
  1427. )
  1428. {
  1429. TspMspMessageEx messageEx;
  1430. WORD wEncodedLength;
  1431. BYTE* pEncodedASNBuffer;
  1432. H323DBG(( DEBUG_LEVEL_ERROR, "SendMSPStartH245 entered:%p.", this ));
  1433. wEncodedLength = 0;
  1434. messageEx.message.MessageType = SP_MSG_StartH245;
  1435. messageEx.message.MsgBody.StartH245Message.hMSPReplaceCall = NULL;
  1436. messageEx.message.MsgBody.StartH245Message.hTSPReplacementCall =
  1437. (HANDLE)pPeerH245Addr;
  1438. ZeroMemory( messageEx.message.MsgBody.StartH245Message.ConferenceID,
  1439. sizeof(GUID) );
  1440. messageEx.message.MsgBody.StartH245Message.fH245TunnelCapability = FALSE;
  1441. messageEx.message.MsgBody.StartH245Message.fH245AddressPresent = FALSE;
  1442. memset( (PVOID)&messageEx.message.MsgBody.StartH245Message.saH245Addr,
  1443. 0, sizeof(SOCKADDR_IN) );
  1444. //for outgoing call send the fast start proposal.
  1445. if( (m_dwOrigin==LINECALLORIGIN_OUTBOUND) || pPeerH245Addr )
  1446. {
  1447. if( pPeerH245Addr == NULL )
  1448. {
  1449. pPeerFastStart = m_pPeerFastStart;
  1450. }
  1451. if( pPeerFastStart != NULL )
  1452. {
  1453. if( !EncodeFastStartProposal( pPeerFastStart, &pEncodedASNBuffer,
  1454. &wEncodedLength ) )
  1455. {
  1456. CloseCall( 0 );
  1457. return;
  1458. }
  1459. CopyMemory( (PVOID)messageEx.message.pEncodedASNBuf,
  1460. (PVOID)pEncodedASNBuffer, wEncodedLength );
  1461. ASN1_FreeEncoded(m_ASNCoderInfo.pEncInfo, pEncodedASNBuffer );
  1462. }
  1463. }
  1464. //If outgoing call send peer's H245 address
  1465. if( (m_dwOrigin == LINECALLORIGIN_OUTBOUND) || pPeerH245Addr )
  1466. {
  1467. if( pPeerH245Addr == NULL )
  1468. {
  1469. pPeerH245Addr = &m_peerH245Addr;
  1470. }
  1471. messageEx.message.MsgBody.StartH245Message.fH245AddressPresent = FALSE;
  1472. if( pPeerH245Addr->Addr.IP_Binary.dwAddr != 0 )
  1473. {
  1474. messageEx.message.MsgBody.StartH245Message.saH245Addr.sin_family = AF_INET;
  1475. messageEx.message.MsgBody.StartH245Message.saH245Addr.sin_port =
  1476. htons(pPeerH245Addr->Addr.IP_Binary.wPort);
  1477. messageEx.message.MsgBody.StartH245Message.saH245Addr.sin_addr.s_addr =
  1478. htonl(pPeerH245Addr->Addr.IP_Binary.dwAddr);
  1479. messageEx.message.MsgBody.StartH245Message.fH245AddressPresent = TRUE;
  1480. }
  1481. }
  1482. //set the Q931 address
  1483. ZeroMemory( (PVOID)&messageEx.message.MsgBody.StartH245Message.saQ931Addr,
  1484. sizeof(SOCKADDR_IN) );
  1485. messageEx.message.MsgBody.StartH245Message.saQ931Addr.sin_family = AF_INET;
  1486. messageEx.message.MsgBody.StartH245Message.saQ931Addr.sin_port =
  1487. htons( m_CalleeAddr.Addr.IP_Binary.wPort );
  1488. messageEx.message.MsgBody.StartH245Message.saQ931Addr.sin_addr.s_addr =
  1489. htonl( m_CalleeAddr.Addr.IP_Binary.dwAddr );
  1490. messageEx.message.MsgBody.StartH245Message.fH245TunnelCapability =
  1491. (m_fh245Tunneling & REMOTE_H245_TUNNELING) &&
  1492. (m_fh245Tunneling & LOCAL_H245_TUNNELING);
  1493. messageEx.message.dwMessageSize = sizeof(messageEx.message) +
  1494. wEncodedLength - ((wEncodedLength)?1:0);
  1495. messageEx.message.dwEncodedASNSize = wEncodedLength;
  1496. // send msp message
  1497. PostLineEvent (
  1498. LINE_SENDMSPDATA,
  1499. //this handle should be NULL when htCall is a valid handle.
  1500. (DWORD_PTR)NULL,
  1501. (DWORD_PTR)&(messageEx.message),
  1502. messageEx.message.dwMessageSize);
  1503. m_dwFlags |= H245_START_MSG_SENT;
  1504. H323DBG(( DEBUG_LEVEL_ERROR, "SendMSPStartH245 exited:%p.",this ));
  1505. return;
  1506. }
  1507. //always called in lock
  1508. BOOL
  1509. CH323Call::AddU2U(
  1510. IN DWORD dwDirection,
  1511. IN DWORD dwDataSize,
  1512. IN PBYTE pData
  1513. )
  1514. /*++
  1515. Routine Description:
  1516. Create user user structure and adds to list.
  1517. Arguments:
  1518. pLftHead - Pointer to list in which to add user user info.
  1519. dwDataSize - Size of buffer pointed to by pData.
  1520. pData - Pointer to user user info.
  1521. Return Values:
  1522. Returns true if successful.
  1523. --*/
  1524. {
  1525. PLIST_ENTRY pListHead = NULL;
  1526. PUserToUserLE pU2ULE;
  1527. H323DBG(( DEBUG_LEVEL_ERROR, "AddU2U entered:%p.",this ));
  1528. if( dwDirection == U2U_OUTBOUND )
  1529. {
  1530. pListHead = &m_OutgoingU2U;
  1531. }
  1532. else
  1533. {
  1534. pListHead = &m_IncomingU2U;
  1535. }
  1536. // validate data buffer pointer and size
  1537. if( (pData != NULL) && (dwDataSize > 0) )
  1538. {
  1539. // allocate memory for user user info
  1540. pU2ULE = (PUserToUserLE)new char[ dwDataSize + sizeof(UserToUserLE) ];
  1541. // validate pointer
  1542. if (pU2ULE == NULL)
  1543. {
  1544. H323DBG(( DEBUG_LEVEL_ERROR,
  1545. "could not allocate user user info." ));
  1546. // failure
  1547. return FALSE;
  1548. }
  1549. // aim pointer at the end of the buffer by default
  1550. pU2ULE->pU2U = (LPBYTE)pU2ULE + sizeof(UserToUserLE);
  1551. pU2ULE->dwU2USize = dwDataSize;
  1552. // transfer user user info into list entry
  1553. CopyMemory( (PVOID)pU2ULE->pU2U, (PVOID)pData, pU2ULE->dwU2USize);
  1554. // add list entry to back of list
  1555. InsertTailList(pListHead, &pU2ULE->Link);
  1556. H323DBG(( DEBUG_LEVEL_VERBOSE,
  1557. "added user user info 0x%08lx (%d bytes).",
  1558. pU2ULE->pU2U,
  1559. pU2ULE->dwU2USize
  1560. ));
  1561. }
  1562. H323DBG(( DEBUG_LEVEL_ERROR, "AddU2U exited:%p.",this ));
  1563. // success
  1564. return TRUE;
  1565. }
  1566. /*++
  1567. Routine Description:
  1568. Create user user structure and adds to list.
  1569. !!always called in lock.
  1570. Arguments:
  1571. pLftHead - Pointer to list in which to add user user info.
  1572. dwDataSize - Size of buffer pointed to by pData.
  1573. pData - Pointer to user user info.
  1574. Return Values:
  1575. Returns true if successful.
  1576. --*/
  1577. BOOL
  1578. CH323Call::AddU2UNoAlloc(
  1579. IN DWORD dwDirection,
  1580. IN DWORD dwDataSize,
  1581. IN PBYTE pData
  1582. )
  1583. {
  1584. PLIST_ENTRY pListHead = NULL;
  1585. PUserToUserLE pU2ULE;
  1586. H323DBG(( DEBUG_LEVEL_ERROR, "AddU2U entered:%p.",this ));
  1587. if( dwDirection == U2U_OUTBOUND )
  1588. {
  1589. pListHead = &m_OutgoingU2U;
  1590. }
  1591. else
  1592. {
  1593. pListHead = &m_IncomingU2U;
  1594. }
  1595. // validate data buffer pointer and size
  1596. if( (pData != NULL) && (dwDataSize > 0) )
  1597. {
  1598. // allocate memory for user user info
  1599. pU2ULE = new UserToUserLE;
  1600. // validate pointer
  1601. if (pU2ULE == NULL)
  1602. {
  1603. H323DBG(( DEBUG_LEVEL_ERROR,
  1604. "could not allocate user user info." ));
  1605. // failure
  1606. return FALSE;
  1607. }
  1608. // aim pointer at the end of the buffer by default
  1609. pU2ULE->pU2U = pData;
  1610. pU2ULE->dwU2USize = dwDataSize;
  1611. // add list entry to back of list
  1612. InsertTailList(pListHead, &pU2ULE->Link);
  1613. H323DBG(( DEBUG_LEVEL_VERBOSE,
  1614. "added user user info 0x%08lx (%d bytes).",
  1615. pU2ULE->pU2U,
  1616. pU2ULE->dwU2USize
  1617. ));
  1618. }
  1619. H323DBG(( DEBUG_LEVEL_ERROR, "AddU2U exited:%p.",this ));
  1620. // success
  1621. return TRUE;
  1622. }
  1623. //!!must be always called in a lock.
  1624. BOOL
  1625. CH323Call::RemoveU2U(
  1626. IN DWORD dwDirection,
  1627. IN PUserToUserLE * ppU2ULE
  1628. )
  1629. /*++
  1630. Routine Description:
  1631. Removes user user info structure from list.
  1632. Arguments:
  1633. pListHead - Pointer to list in which to remove user user info.
  1634. ppU2ULE - Pointer to pointer to list entry.
  1635. Return Values:
  1636. Returns true if successful.
  1637. --*/
  1638. {
  1639. PLIST_ENTRY pListHead = NULL;
  1640. PLIST_ENTRY pLE;
  1641. H323DBG(( DEBUG_LEVEL_ERROR, "RemoveU2U entered:%p.",this ));
  1642. if( dwDirection == U2U_OUTBOUND )
  1643. {
  1644. pListHead = &m_OutgoingU2U;
  1645. }
  1646. else
  1647. {
  1648. pListHead = &m_IncomingU2U;
  1649. }
  1650. // process list until empty
  1651. if( IsListEmpty(pListHead) == FALSE )
  1652. {
  1653. // retrieve first entry
  1654. pLE = RemoveHeadList(pListHead);
  1655. // convert list entry to structure pointer
  1656. *ppU2ULE = CONTAINING_RECORD(pLE, UserToUserLE, Link);
  1657. H323DBG(( DEBUG_LEVEL_VERBOSE,
  1658. "removed user user info 0x%08lx (%d bytes).",
  1659. (*ppU2ULE)->pU2U, (*ppU2ULE)->dwU2USize ));
  1660. H323DBG(( DEBUG_LEVEL_ERROR, "RemoveU2U exited:%p.",this ));
  1661. // success
  1662. return TRUE;
  1663. }
  1664. // failure
  1665. return FALSE;
  1666. }
  1667. BOOL
  1668. CH323Call::FreeU2U(
  1669. IN DWORD dwDirection
  1670. )
  1671. /*++
  1672. Routine Description:
  1673. Releases memory for user user list.
  1674. !!must be always called in a lock.
  1675. Arguments
  1676. pListHead - Pointer to list in which to free user user info.
  1677. Return Values:
  1678. Returns true if successful.
  1679. --*/
  1680. {
  1681. PLIST_ENTRY pLE;
  1682. PUserToUserLE pU2ULE;
  1683. PLIST_ENTRY pListHead = NULL;
  1684. H323DBG(( DEBUG_LEVEL_ERROR, "FreeU2U entered:%p.",this ));
  1685. if( dwDirection == U2U_OUTBOUND )
  1686. {
  1687. pListHead = &m_OutgoingU2U;
  1688. }
  1689. else
  1690. {
  1691. pListHead = &m_IncomingU2U;
  1692. }
  1693. // process list until empty
  1694. while( IsListEmpty(pListHead) == FALSE )
  1695. {
  1696. // retrieve first entry
  1697. pLE = RemoveHeadList(pListHead);
  1698. // convert list entry to structure pointer
  1699. pU2ULE = CONTAINING_RECORD(pLE, UserToUserLE, Link);
  1700. // release memory
  1701. if( pU2ULE )
  1702. {
  1703. delete pU2ULE;
  1704. pU2ULE = NULL;
  1705. }
  1706. }
  1707. H323DBG(( DEBUG_LEVEL_ERROR, "FreeU2U exited:%p.",this ));
  1708. // success
  1709. return TRUE;
  1710. }
  1711. /*++
  1712. Routine Description:
  1713. Resets call object to original state for re-use.
  1714. Arguments:
  1715. Return Values:
  1716. Returns true if successful.
  1717. --*/
  1718. void
  1719. CH323Call::Shutdown(
  1720. OUT BOOL * fDelete
  1721. )
  1722. {
  1723. H323DBG(( DEBUG_LEVEL_ERROR, "Shutdown entered:%p.",this ));
  1724. if( !(m_dwFlags & CALLOBJECT_INITIALIZED) )
  1725. {
  1726. return;
  1727. }
  1728. //acquire the lock on call table before acquiring the lock on call object
  1729. g_pH323Line -> LockCallTable();
  1730. Lock();
  1731. if( m_dwFlags & CALLOBJECT_SHUTDOWN )
  1732. {
  1733. Unlock();
  1734. g_pH323Line -> UnlockCallTable();
  1735. return;
  1736. }
  1737. // reset tapi info
  1738. m_dwCallState = LINECALLSTATE_UNKNOWN;
  1739. m_dwCallStateMode = 0;
  1740. m_dwOrigin = LINECALLORIGIN_UNKNOWN;
  1741. m_dwAddressType = 0;
  1742. m_dwIncomingModes = 0;
  1743. m_dwOutgoingModes = 0;
  1744. m_dwRequestedModes = 0;
  1745. m_fMonitoringDigits = FALSE;
  1746. // reset tapi handles
  1747. m_htCall = (HTAPICALL)NULL;
  1748. // reset addresses
  1749. memset( (PVOID)&m_CalleeAddr,0,sizeof(H323_ADDR));
  1750. memset( (PVOID)&m_CallerAddr,0,sizeof(H323_ADDR));
  1751. H323DBG(( DEBUG_LEVEL_ERROR, "deleting calleealias:%p.",this ));
  1752. FreeAliasNames( m_pCalleeAliasNames );
  1753. m_pCalleeAliasNames = NULL;
  1754. if( m_pCallerAliasNames != NULL )
  1755. {
  1756. //H323DBG(( DEBUG_LEVEL_ERROR, "Caller alias count:%d : %p", m_pCallerAliasNames->wCount, this ));
  1757. FreeAliasNames( m_pCallerAliasNames );
  1758. m_pCallerAliasNames = NULL;
  1759. }
  1760. //reset non standard data
  1761. memset( (PVOID)&m_NonStandardData, 0, sizeof(H323NonStandardData) );
  1762. // release user user information
  1763. FreeU2U( U2U_OUTBOUND );
  1764. FreeU2U( U2U_INBOUND );
  1765. //shutdown the Q931 call if not shutdown yet
  1766. if( m_hSetupSentTimer != NULL )
  1767. {
  1768. DeleteTimerQueueTimer( H323TimerQueue, m_hSetupSentTimer, NULL );
  1769. m_hSetupSentTimer = NULL;
  1770. }
  1771. if( m_hCallEstablishmentTimer )
  1772. {
  1773. DeleteTimerQueueTimer(H323TimerQueue, m_hCallEstablishmentTimer, NULL);
  1774. m_hCallEstablishmentTimer = NULL;
  1775. }
  1776. if( m_hCallDivertOnNATimer )
  1777. {
  1778. DeleteTimerQueueTimer(H323TimerQueue, m_hCallDivertOnNATimer, NULL);
  1779. m_hCallDivertOnNATimer = NULL;
  1780. }
  1781. *fDelete = FALSE;
  1782. if( m_IoRefCount == 0 )
  1783. {
  1784. *fDelete = TRUE;
  1785. }
  1786. m_dwStateMachine = Q931_CALL_STATE_NONE;
  1787. if( m_callSocket != INVALID_SOCKET )
  1788. {
  1789. if(shutdown( m_callSocket, SD_BOTH ) == SOCKET_ERROR)
  1790. {
  1791. H323DBG((DEBUG_LEVEL_TRACE, "couldn't shutdown the socket:%d, %p.",
  1792. WSAGetLastError(), this ));
  1793. }
  1794. closesocket( m_callSocket );
  1795. m_callSocket = INVALID_SOCKET;
  1796. }
  1797. m_pwszDisplay = NULL;
  1798. FreeVendorInfo( &m_peerVendorInfo );
  1799. if( m_peerNonStandardData.sData.pOctetString )
  1800. {
  1801. H323DBG(( DEBUG_LEVEL_ERROR, "deleting nonstd:%p.",this ));
  1802. delete m_peerNonStandardData.sData.pOctetString;
  1803. m_peerNonStandardData.sData.pOctetString = NULL;
  1804. }
  1805. H323DBG(( DEBUG_LEVEL_ERROR, "deleting xtraalias:%p.",this ));
  1806. FreeAliasNames( m_pPeerExtraAliasNames );
  1807. m_pPeerExtraAliasNames = NULL;
  1808. H323DBG(( DEBUG_LEVEL_ERROR, "deleting display:%p.",this ));
  1809. if( m_pPeerDisplay )
  1810. {
  1811. delete m_pPeerDisplay;
  1812. m_pPeerDisplay = NULL;
  1813. }
  1814. if( m_CallData.pOctetString != NULL )
  1815. {
  1816. delete m_CallData.pOctetString;
  1817. }
  1818. H323DBG(( DEBUG_LEVEL_ERROR, "deleting hdconf:%p.",this ));
  1819. // delete conference
  1820. if( m_hdConf != NULL )
  1821. {
  1822. g_pH323Line -> GetH323ConfTable() -> Remove( m_hdConf );
  1823. delete m_hdConf;
  1824. m_hdConf = NULL;
  1825. }
  1826. H323DBG(( DEBUG_LEVEL_ERROR, "deleting preparetoans:%p.",this ));
  1827. if( m_prepareToAnswerMsgData.pbBuffer )
  1828. {
  1829. delete m_prepareToAnswerMsgData.pbBuffer;
  1830. }
  1831. ZeroMemory( (PVOID)&m_prepareToAnswerMsgData, sizeof(BUFFERDESCR) );
  1832. H323DBG(( DEBUG_LEVEL_ERROR, "deleting drq timer:%p.",this ));
  1833. //ras related data structures
  1834. if( m_hDRQTimer != NULL )
  1835. {
  1836. DeleteTimerQueueTimer( H323TimerQueue, m_hDRQTimer, NULL );
  1837. m_hDRQTimer = NULL;
  1838. }
  1839. H323DBG(( DEBUG_LEVEL_ERROR, "deleting arq timer:%p.",this ));
  1840. if( m_hARQTimer != NULL )
  1841. {
  1842. DeleteTimerQueueTimer( H323TimerQueue, m_hARQTimer, NULL );
  1843. m_hARQTimer = NULL;
  1844. }
  1845. if( m_pPeerFastStart != NULL )
  1846. {
  1847. FreeFastStart( m_pPeerFastStart );
  1848. m_pPeerFastStart = NULL;
  1849. }
  1850. if( m_pFastStart != NULL )
  1851. {
  1852. FreeFastStart( m_pFastStart );
  1853. m_pFastStart = NULL;
  1854. }
  1855. if( m_pARQExpireContext != NULL )
  1856. {
  1857. delete m_pARQExpireContext;
  1858. m_pARQExpireContext = NULL;
  1859. }
  1860. if( m_pDRQExpireContext != NULL )
  1861. {
  1862. delete m_pDRQExpireContext;
  1863. m_pDRQExpireContext = NULL;
  1864. }
  1865. FreeCallForwardData();
  1866. g_pH323Line -> RemoveCallFromTable (m_hdCall);
  1867. m_dwFlags |= CALLOBJECT_SHUTDOWN;
  1868. Unlock();
  1869. g_pH323Line -> UnlockCallTable();
  1870. H323DBG(( DEBUG_LEVEL_ERROR, "Shutdown exited:%p.",this ));
  1871. return;
  1872. }
  1873. void
  1874. CH323Call::FreeCallForwardData()
  1875. {
  1876. if( m_pCallReroutingInfo )
  1877. {
  1878. FreeCallReroutingInfo();
  1879. }
  1880. if( m_hCheckRestrictionTimer )
  1881. {
  1882. DeleteTimerQueueTimer( H323TimerQueue, m_hCheckRestrictionTimer,
  1883. NULL );
  1884. m_hCheckRestrictionTimer = NULL;
  1885. }
  1886. if( m_hCallReroutingTimer )
  1887. {
  1888. DeleteTimerQueueTimer( H323TimerQueue, m_hCallReroutingTimer, NULL );
  1889. m_hCallReroutingTimer = NULL;
  1890. }
  1891. if( m_hCTIdentifyTimer )
  1892. {
  1893. DeleteTimerQueueTimer( H323TimerQueue, m_hCTIdentifyTimer, NULL );
  1894. m_hCTIdentifyTimer = NULL;
  1895. }
  1896. if( m_hCTIdentifyRRTimer )
  1897. {
  1898. DeleteTimerQueueTimer( H323TimerQueue, m_hCTIdentifyRRTimer, NULL );
  1899. m_hCTIdentifyRRTimer = NULL;
  1900. }
  1901. if( m_hCTInitiateTimer )
  1902. {
  1903. DeleteTimerQueueTimer( H323TimerQueue, m_hCTInitiateTimer, NULL );
  1904. m_hCTInitiateTimer = NULL;
  1905. }
  1906. if( m_pTransferedToAlias )
  1907. {
  1908. FreeAliasNames( m_pTransferedToAlias );
  1909. m_pTransferedToAlias = NULL;
  1910. }
  1911. if( m_dwCallType & CALLTYPE_TRANSFERED2_CONSULT )
  1912. {
  1913. g_pH323Line -> RemoveFromCTCallIdentityTable( m_hdCall );
  1914. }
  1915. if( m_H450ASNCoderInfo.pEncInfo )
  1916. {
  1917. TermH450ASNCoder();
  1918. }
  1919. if( m_pCallForwardParams )
  1920. {
  1921. FreeCallForwardParams( m_pCallForwardParams );
  1922. m_pCallForwardParams = NULL;
  1923. }
  1924. if( m_pForwardAddress )
  1925. {
  1926. FreeForwardAddress( m_pForwardAddress );
  1927. m_pForwardAddress = NULL;
  1928. }
  1929. }
  1930. BOOL
  1931. CH323Call::ResolveCallerAddress(void)
  1932. /*++
  1933. Routine Description:
  1934. Resolves caller address from callee address.
  1935. !!must be always called in a lock.
  1936. Arguments:
  1937. Return Values:
  1938. Returns true if successful.
  1939. --*/
  1940. {
  1941. INT nStatus;
  1942. SOCKET hCtrlSocket = INVALID_SOCKET;
  1943. SOCKADDR CalleeSockAddr;
  1944. SOCKADDR CallerSockAddr;
  1945. DWORD dwNumBytesReturned = 0;
  1946. H323DBG(( DEBUG_LEVEL_ERROR, "ResolveCallerAddress entered:%p.",this ));
  1947. // allocate control socket
  1948. hCtrlSocket = WSASocket(
  1949. AF_INET, // af
  1950. SOCK_DGRAM, // type
  1951. IPPROTO_IP, // protocol
  1952. NULL, // lpProtocolInfo
  1953. 0, // g
  1954. WSA_FLAG_OVERLAPPED // dwFlags
  1955. );
  1956. // validate control socket
  1957. if (hCtrlSocket == INVALID_SOCKET)
  1958. {
  1959. H323DBG(( DEBUG_LEVEL_ERROR,
  1960. "error %d creating control socket.", WSAGetLastError() ));
  1961. // failure
  1962. return FALSE;
  1963. }
  1964. // initialize ioctl parameters
  1965. memset( (PVOID)&CalleeSockAddr,0,sizeof(SOCKADDR));
  1966. memset( (PVOID)&CallerSockAddr,0,sizeof(SOCKADDR));
  1967. // initialize address family
  1968. CalleeSockAddr.sa_family = AF_INET;
  1969. // transfer callee information
  1970. ((SOCKADDR_IN*)&CalleeSockAddr)->sin_addr.s_addr =
  1971. htonl(m_CalleeAddr.Addr.IP_Binary.dwAddr);
  1972. // query stack
  1973. nStatus = WSAIoctl(
  1974. hCtrlSocket,
  1975. SIO_ROUTING_INTERFACE_QUERY,
  1976. &CalleeSockAddr,
  1977. sizeof(SOCKADDR),
  1978. &CallerSockAddr,
  1979. sizeof(SOCKADDR),
  1980. &dwNumBytesReturned,
  1981. NULL,
  1982. NULL
  1983. );
  1984. // release handle
  1985. closesocket(hCtrlSocket);
  1986. // validate return code
  1987. if (nStatus == SOCKET_ERROR)
  1988. {
  1989. H323DBG(( DEBUG_LEVEL_ERROR,
  1990. "error 0x%08lx calling SIO_ROUTING_INTERFACE_QUERY.",
  1991. WSAGetLastError() ));
  1992. // failure
  1993. return FALSE;
  1994. }
  1995. // save interface address of best route
  1996. m_CallerAddr.nAddrType = H323_IP_BINARY;
  1997. m_CallerAddr.Addr.IP_Binary.dwAddr =
  1998. ntohl(((SOCKADDR_IN*)&CallerSockAddr)->sin_addr.s_addr);
  1999. m_CallerAddr.Addr.IP_Binary.wPort =
  2000. LOWORD(g_RegistrySettings.dwQ931ListenPort);
  2001. m_CallerAddr.bMulticast =
  2002. IN_MULTICAST(m_CallerAddr.Addr.IP_Binary.dwAddr);
  2003. H323DBG(( DEBUG_LEVEL_TRACE,
  2004. "caller address resolved to %s.",
  2005. H323AddrToString(((SOCKADDR_IN*)&CallerSockAddr)->sin_addr.s_addr) ));
  2006. H323DBG(( DEBUG_LEVEL_ERROR, "ResolveCallerAddress exited:%p.",this ));
  2007. // success
  2008. return TRUE;
  2009. }
  2010. BOOL
  2011. CH323Call::ResolveE164Address(
  2012. IN LPCWSTR pwszDialableAddr
  2013. )
  2014. /*++
  2015. Routine Description:
  2016. Resolves E.164 address ("4259367111").
  2017. !!must be always called in a lock.
  2018. Arguments:
  2019. pwszDialableAddr - Specifies a pointer to the dialable address specified
  2020. by the TAPI application.
  2021. Return Values:
  2022. Returns true if successful.
  2023. --*/
  2024. {
  2025. WCHAR wszAddr[H323_MAXDESTNAMELEN+1];
  2026. DWORD dwE164AddrSize;
  2027. H323DBG(( DEBUG_LEVEL_ERROR, "ResolveE164Address entered:%p.",this ));
  2028. // make sure pstn gateway has been specified
  2029. if ((g_RegistrySettings.fIsGatewayEnabled == FALSE) ||
  2030. (g_RegistrySettings.gatewayAddr.nAddrType == 0))
  2031. {
  2032. H323DBG(( DEBUG_LEVEL_ERROR,
  2033. "pstn gateway not specified."
  2034. ));
  2035. // failure
  2036. return FALSE;
  2037. }
  2038. // save gateway address as callee address
  2039. m_CalleeAddr = g_RegistrySettings.gatewayAddr;
  2040. dwE164AddrSize = ValidateE164Address( pwszDialableAddr, wszAddr );
  2041. if( dwE164AddrSize == 0 )
  2042. {
  2043. H323DBG(( DEBUG_LEVEL_ERROR,
  2044. "invlid e164 callee alias ."));
  2045. return FALSE;
  2046. }
  2047. H323DBG(( DEBUG_LEVEL_TRACE,
  2048. "callee alias resolved to E.164 number." ));
  2049. H323DBG(( DEBUG_LEVEL_ERROR, "ResolveE164Address exited:%p.",this ));
  2050. //determine caller address
  2051. return ResolveCallerAddress();
  2052. }
  2053. DWORD
  2054. ValidateE164Address(
  2055. LPCWSTR pwszDialableAddr,
  2056. WCHAR* wszAddr
  2057. )
  2058. {
  2059. DWORD dwE164AddrSize = 0;
  2060. WCHAR * pwszValidE164Chars;
  2061. WCHAR wszValidE164Chars[] = { H323_ALIAS_H323_PHONE_CHARS L"\0" };
  2062. // process until termination char
  2063. while (*pwszDialableAddr != L'\0')
  2064. {
  2065. // reset pointer to valid characters
  2066. pwszValidE164Chars = wszValidE164Chars;
  2067. // process until termination char
  2068. while (*pwszValidE164Chars != L'\0')
  2069. {
  2070. // see if valid E.164 character specified
  2071. if (*pwszDialableAddr == *pwszValidE164Chars)
  2072. {
  2073. // save valid character in temp buffer
  2074. wszAddr[dwE164AddrSize++] = *pwszDialableAddr;
  2075. break;
  2076. }
  2077. // next valid char
  2078. ++pwszValidE164Chars;
  2079. }
  2080. // next input char
  2081. ++pwszDialableAddr;
  2082. }
  2083. // terminate string
  2084. wszAddr[dwE164AddrSize++] = L'\0';
  2085. // validate string
  2086. if (dwE164AddrSize == 0)
  2087. {
  2088. H323DBG(( DEBUG_LEVEL_TRACE,
  2089. "no valid E.164 characters in string." ));
  2090. }
  2091. return dwE164AddrSize;
  2092. }
  2093. /*++
  2094. Routine Description:
  2095. Resolves IP address ("172.31.255.231") or DNS entry ("NIKHILB1").
  2096. !!must be always called in a lock.
  2097. Arguments:
  2098. pszDialableAddr - Specifies a pointer to the dialable address specified
  2099. by the TAPI application.
  2100. Return Values:
  2101. Returns true if successful.
  2102. --*/
  2103. BOOL
  2104. CH323Call::ResolveIPAddress(
  2105. IN LPSTR pszDialableAddr
  2106. )
  2107. {
  2108. DWORD dwIPAddr;
  2109. struct hostent* pHost;
  2110. H323DBG(( DEBUG_LEVEL_ERROR, "ResolveIPAddress entered:%p.",this ));
  2111. // attempt to convert ip address
  2112. dwIPAddr = inet_addr(pszDialableAddr);
  2113. // see if address converted
  2114. if( dwIPAddr == INADDR_NONE )
  2115. {
  2116. // attempt to lookup hostname
  2117. pHost = gethostbyname(pszDialableAddr);
  2118. // validate pointer
  2119. if( pHost != NULL )
  2120. {
  2121. // retrieve host address from structure
  2122. dwIPAddr = *(unsigned long *)pHost->h_addr;
  2123. }
  2124. }
  2125. // see if address converted
  2126. if( dwIPAddr == INADDR_NONE )
  2127. {
  2128. H323DBG(( DEBUG_LEVEL_ERROR,
  2129. "error 0x%08lx resolving IP address.",
  2130. WSAGetLastError() ));
  2131. // failure
  2132. return FALSE;
  2133. }
  2134. // save converted address
  2135. m_CalleeAddr.nAddrType = H323_IP_BINARY;
  2136. m_CalleeAddr.Addr.IP_Binary.dwAddr = ntohl(dwIPAddr);
  2137. m_CalleeAddr.Addr.IP_Binary.wPort =
  2138. LOWORD(g_RegistrySettings.dwQ931ListenPort);
  2139. m_CalleeAddr.bMulticast =
  2140. IN_MULTICAST(m_CalleeAddr.Addr.IP_Binary.dwAddr);
  2141. H323DBG(( DEBUG_LEVEL_TRACE,
  2142. "callee address resolved to %s:%d.",
  2143. H323AddrToString(dwIPAddr),
  2144. m_CalleeAddr.Addr.IP_Binary.wPort ));
  2145. H323DBG(( DEBUG_LEVEL_ERROR, "ResolveIPAddress exited:%p.",this ));
  2146. // determine caller address
  2147. return ResolveCallerAddress();
  2148. }
  2149. BOOL
  2150. CH323Call::ResolveEmailAddress(
  2151. IN LPCWSTR pwszDialableAddr,
  2152. IN LPSTR pszUser,
  2153. IN LPSTR pszDomain
  2154. )
  2155. /*++
  2156. Routine Description:
  2157. Resolves e-mail address ("[email protected]").
  2158. !!must be always called in a lock.
  2159. Arguments:
  2160. pwszDialableAddr - Specifies a pointer to the dialable address specified
  2161. by the TAPI application.
  2162. pszUser - Specifies a pointer to the user component of e-mail name.
  2163. pszDomain - Specified a pointer to the domain component of e-mail name.
  2164. Return Values:
  2165. Returns true if successful.
  2166. --*/
  2167. {
  2168. DWORD dwAddrSize;
  2169. H323DBG(( DEBUG_LEVEL_ERROR, "ResolveEmailAddress entered:%p.",this ));
  2170. // size destination address string
  2171. dwAddrSize = wcslen(pwszDialableAddr) + 1;
  2172. // attempt to resolve domain locally
  2173. if( ResolveIPAddress( pszDomain) )
  2174. {
  2175. // success
  2176. return TRUE;
  2177. }
  2178. // make sure proxy has been specified
  2179. if( (g_RegistrySettings.fIsProxyEnabled == FALSE) ||
  2180. (g_RegistrySettings.proxyAddr.nAddrType == 0) )
  2181. {
  2182. H323DBG(( DEBUG_LEVEL_ERROR, "proxy not specified." ));
  2183. // failure
  2184. return FALSE;
  2185. }
  2186. // save proxy address as callee address
  2187. m_CalleeAddr = g_RegistrySettings.proxyAddr;
  2188. H323DBG(( DEBUG_LEVEL_TRACE,
  2189. "callee alias resolved to H.323 alias."));
  2190. H323DBG(( DEBUG_LEVEL_ERROR, "ResolveEmailAddress exited:%p.",this ));
  2191. // determine caller address
  2192. return ResolveCallerAddress();
  2193. }
  2194. /*++
  2195. Routine Description:
  2196. Resolves remote address and determines the correct local address
  2197. to use in order to reach remote address.
  2198. !!must be always called in a lock.
  2199. Arguments:
  2200. pwszDialableAddr - Specifies a pointer to the dialable address specified
  2201. by the TAPI application.
  2202. Return Values:
  2203. Returns true if successful.
  2204. --*/
  2205. BOOL
  2206. CH323Call::ResolveAddress(
  2207. IN LPCWSTR pwszDialableAddr
  2208. )
  2209. {
  2210. CHAR szDelimiters[] = "@ \t\n";
  2211. CHAR szAddr[H323_MAXDESTNAMELEN+1];
  2212. LPSTR pszUser = NULL;
  2213. LPSTR pszDomain = NULL;
  2214. H323DBG(( DEBUG_LEVEL_ERROR, "ResolveAddress entered:%p.",this ));
  2215. // validate pointerr
  2216. if (pwszDialableAddr == NULL)
  2217. {
  2218. H323DBG(( DEBUG_LEVEL_ERROR, "null destination address." ));
  2219. // failure
  2220. return FALSE;
  2221. }
  2222. H323DBG(( DEBUG_LEVEL_TRACE,
  2223. "resolving %s %S.",
  2224. H323AddressTypeToString( m_dwAddressType),
  2225. pwszDialableAddr ));
  2226. // check whether phone number has been specified
  2227. if( m_dwAddressType == LINEADDRESSTYPE_PHONENUMBER )
  2228. {
  2229. // need to direct call to pstn gateway
  2230. return ResolveE164Address( pwszDialableAddr);
  2231. }
  2232. // convert address from unicode
  2233. if (WideCharToMultiByte(
  2234. CP_ACP,
  2235. 0,
  2236. pwszDialableAddr,
  2237. -1,
  2238. szAddr,
  2239. sizeof(szAddr),
  2240. NULL,
  2241. NULL
  2242. ) == 0)
  2243. {
  2244. H323DBG(( DEBUG_LEVEL_ERROR,
  2245. "could not convert address from unicode." ));
  2246. // failure
  2247. return FALSE;
  2248. }
  2249. // parse user name
  2250. pszUser = strtok(szAddr, szDelimiters);
  2251. // parse domain name
  2252. pszDomain = strtok(NULL, szDelimiters);
  2253. // validate pointer
  2254. if (pszUser == NULL)
  2255. {
  2256. H323DBG(( DEBUG_LEVEL_ERROR, "could not parse destination address." ));
  2257. // failure
  2258. return FALSE;
  2259. }
  2260. // validate pointer
  2261. if (pszDomain == NULL)
  2262. {
  2263. // switch pointers
  2264. pszDomain = pszUser;
  2265. // re-initialize
  2266. pszUser = NULL;
  2267. }
  2268. H323DBG(( DEBUG_LEVEL_VERBOSE,
  2269. "resolving user %s domain %s.",
  2270. pszUser,
  2271. pszDomain
  2272. ));
  2273. H323DBG(( DEBUG_LEVEL_ERROR, "ResolveAddress exited:%p.",this ));
  2274. // process e-mail and domain names
  2275. return ResolveEmailAddress(
  2276. pwszDialableAddr,
  2277. pszUser,
  2278. pszDomain
  2279. );
  2280. }
  2281. BOOL
  2282. /*++
  2283. Routine Description:
  2284. Validate optional call parameters specified by user.
  2285. !!no need to call in a lock because not added to the call table yet
  2286. Arguments:
  2287. pCallParams - Pointer to specified call parameters to be
  2288. validated.
  2289. pwszDialableAddr - Pointer to the dialable address specified
  2290. by the TAPI application.
  2291. pdwStatus - Pointer to DWORD containing error code if this
  2292. routine fails for any reason.
  2293. Return Values:
  2294. Returns true if successful.
  2295. --*/
  2296. CH323Call::ValidateCallParams(
  2297. IN LPLINECALLPARAMS pCallParams,
  2298. IN LPCWSTR pwszDialableAddr,
  2299. IN PDWORD pdwStatus
  2300. )
  2301. {
  2302. DWORD dwMediaModes = H323_LINE_DEFMEDIAMODES;
  2303. DWORD dwAddrSize;
  2304. WCHAR wszAddr[H323_MAXDESTNAMELEN+1];
  2305. PH323_ALIASNAMES pAliasList;
  2306. WCHAR* wszMachineName;
  2307. H323DBG(( DEBUG_LEVEL_TRACE, "ValidateCallParams entered:%p.", this ));
  2308. H323DBG(( DEBUG_LEVEL_VERBOSE, "clearing unknown media mode." ));
  2309. // validate pointer
  2310. if( (pCallParams == NULL) || (pwszDialableAddr == NULL) )
  2311. {
  2312. return FALSE;
  2313. }
  2314. // retrieve media modes specified
  2315. dwMediaModes = pCallParams->dwMediaMode;
  2316. // retrieve address type specified
  2317. m_dwAddressType = pCallParams->dwAddressType;
  2318. // see if we support call parameters
  2319. if( pCallParams->dwCallParamFlags != 0 )
  2320. {
  2321. H323DBG(( DEBUG_LEVEL_ERROR,
  2322. "do not support call parameters 0x%08lx.",
  2323. pCallParams->dwCallParamFlags ));
  2324. // do not support param flags
  2325. *pdwStatus = LINEERR_INVALCALLPARAMS;
  2326. // failure
  2327. return FALSE;
  2328. }
  2329. // see if unknown bit is specified
  2330. if( dwMediaModes & LINEMEDIAMODE_UNKNOWN )
  2331. {
  2332. H323DBG(( DEBUG_LEVEL_VERBOSE,
  2333. "clearing unknown media mode." ));
  2334. // clear unknown bit from modes
  2335. dwMediaModes &= ~LINEMEDIAMODE_UNKNOWN;
  2336. }
  2337. // see if both audio bits are specified
  2338. if( (dwMediaModes & LINEMEDIAMODE_AUTOMATEDVOICE) &&
  2339. (dwMediaModes & LINEMEDIAMODE_INTERACTIVEVOICE) )
  2340. {
  2341. H323DBG(( DEBUG_LEVEL_VERBOSE,
  2342. "clearing automated voice media mode." ));
  2343. // clear extra audio bit from modes
  2344. dwMediaModes &= ~LINEMEDIAMODE_INTERACTIVEVOICE;
  2345. }
  2346. // see if we support media modes specified
  2347. if( dwMediaModes & ~H323_LINE_MEDIAMODES )
  2348. {
  2349. H323DBG(( DEBUG_LEVEL_ERROR,
  2350. "do not support media modes 0x%08lx.",
  2351. pCallParams->dwMediaMode ));
  2352. // do not support media mode
  2353. *pdwStatus = LINEERR_INVALMEDIAMODE;
  2354. // failure
  2355. return FALSE;
  2356. }
  2357. // see if we support bearer modes
  2358. if( pCallParams->dwBearerMode & ~H323_LINE_BEARERMODES )
  2359. {
  2360. H323DBG(( DEBUG_LEVEL_ERROR,
  2361. "do not support bearer mode 0x%08lx.",
  2362. pCallParams->dwBearerMode ));
  2363. // do not support bearer mode
  2364. *pdwStatus = LINEERR_INVALBEARERMODE;
  2365. // failure
  2366. return FALSE;
  2367. }
  2368. // see if we support address modes
  2369. if( pCallParams->dwAddressMode & ~H323_LINE_ADDRESSMODES )
  2370. {
  2371. H323DBG(( DEBUG_LEVEL_ERROR,
  2372. "do not support address mode 0x%08lx.",
  2373. pCallParams->dwAddressMode ));
  2374. // do not support address mode
  2375. *pdwStatus = LINEERR_INVALADDRESSMODE;
  2376. // failure
  2377. return FALSE;
  2378. }
  2379. // validate address id specified
  2380. if (pCallParams->dwAddressID != 0 )
  2381. {
  2382. H323DBG(( DEBUG_LEVEL_ERROR, "address id 0x%08lx invalid.",
  2383. pCallParams->dwAddressID ));
  2384. // invalid address id
  2385. *pdwStatus = LINEERR_INVALADDRESSID;
  2386. // failure
  2387. return FALSE;
  2388. }
  2389. // validate destination address type specified
  2390. if( m_dwAddressType & ~H323_LINE_ADDRESSTYPES )
  2391. {
  2392. H323DBG(( DEBUG_LEVEL_ERROR, "address type 0x%08lx invalid.",
  2393. pCallParams->dwAddressType ));
  2394. // invalid address type
  2395. *pdwStatus = LINEERR_INVALADDRESSTYPE;
  2396. //failure
  2397. return FALSE;
  2398. }
  2399. if( m_dwAddressType == LINEADDRESSTYPE_PHONENUMBER )
  2400. {
  2401. dwAddrSize = ValidateE164Address( pwszDialableAddr, wszAddr );
  2402. //add the callee alias
  2403. if( dwAddrSize==0 )
  2404. {
  2405. H323DBG(( DEBUG_LEVEL_ERROR,
  2406. "invlid e164 callee alias ."));
  2407. return FALSE;
  2408. }
  2409. if( (dwAddrSize > MAX_E164_ADDR_LEN) || (dwAddrSize == 0) )
  2410. return FALSE;
  2411. if(!AddAliasItem( m_pCalleeAliasNames,
  2412. (BYTE*)wszAddr,
  2413. dwAddrSize * sizeof(WCHAR),
  2414. e164_chosen ))
  2415. {
  2416. H323DBG(( DEBUG_LEVEL_ERROR,
  2417. "could not allocate for callee alias ."));
  2418. // invalid destination addr
  2419. *pdwStatus = LINEERR_INVALADDRESS;
  2420. return FALSE;
  2421. }
  2422. H323DBG(( DEBUG_LEVEL_ERROR, "callee alias added:%S.", wszAddr ));
  2423. }
  2424. else
  2425. {
  2426. dwAddrSize = (wcslen(pwszDialableAddr)+1);
  2427. if( (dwAddrSize > MAX_H323_ADDR_LEN) || (dwAddrSize == 0) )
  2428. return FALSE;
  2429. if(!AddAliasItem( m_pCalleeAliasNames,
  2430. (BYTE*)pwszDialableAddr,
  2431. dwAddrSize * sizeof(WCHAR),
  2432. h323_ID_chosen ))
  2433. {
  2434. H323DBG(( DEBUG_LEVEL_ERROR,
  2435. "could not allocate for callee alias ."));
  2436. // invalid destination addr
  2437. *pdwStatus = LINEERR_INVALADDRESS;
  2438. return FALSE;
  2439. }
  2440. H323DBG(( DEBUG_LEVEL_ERROR, "callee alias added:%S.", pwszDialableAddr ));
  2441. }
  2442. // see if callee alias specified
  2443. if( pCallParams->dwCalledPartySize > 0 )
  2444. {
  2445. //avoid duplicate aliases
  2446. dwAddrSize *= sizeof(WCHAR);
  2447. if( ( (m_dwAddressType != LINEADDRESSTYPE_PHONENUMBER) ||
  2448. (memcmp(
  2449. (PVOID)((BYTE*)pCallParams + pCallParams->dwCalledPartyOffset),
  2450. wszAddr,
  2451. pCallParams->dwCalledPartySize ) != 0 )
  2452. ) &&
  2453. ( memcmp(
  2454. (PVOID)((BYTE*)pCallParams + pCallParams->dwCalledPartyOffset),
  2455. pwszDialableAddr,
  2456. pCallParams->dwCalledPartySize ) != 0
  2457. )
  2458. )
  2459. {
  2460. // allocate memory for callee string
  2461. if( !AddAliasItem( m_pCalleeAliasNames,
  2462. (BYTE*)pCallParams + pCallParams->dwCalledPartyOffset,
  2463. pCallParams->dwCalledPartySize,
  2464. (m_dwAddressType != LINEADDRESSTYPE_PHONENUMBER)?
  2465. h323_ID_chosen : e164_chosen) )
  2466. {
  2467. H323DBG(( DEBUG_LEVEL_ERROR,
  2468. "could not allocate caller name." ));
  2469. // invalid address id
  2470. *pdwStatus = LINEERR_NOMEM;
  2471. // failure
  2472. return FALSE;
  2473. }
  2474. H323DBG(( DEBUG_LEVEL_ERROR, "callee alias added:%S.",
  2475. ((BYTE*)pCallParams + pCallParams->dwCalledPartyOffset) ));
  2476. }
  2477. }
  2478. // see if caller name specified
  2479. if( pCallParams->dwCallingPartyIDSize > 0 )
  2480. {
  2481. //H323DBG(( DEBUG_LEVEL_ERROR, "Caller alias count:%d : %p", m_pCallerAliasNames->wCount, this ));
  2482. // allocate memory for callee string
  2483. if(!AddAliasItem( m_pCallerAliasNames,
  2484. (BYTE*)pCallParams + pCallParams->dwCallingPartyIDOffset,
  2485. pCallParams->dwCallingPartyIDSize,
  2486. h323_ID_chosen ) )
  2487. {
  2488. H323DBG(( DEBUG_LEVEL_ERROR,
  2489. "could not allocate caller name." ));
  2490. // invalid address id
  2491. *pdwStatus = LINEERR_NOMEM;
  2492. // failure
  2493. return FALSE;
  2494. }
  2495. //H323DBG(( DEBUG_LEVEL_ERROR, "Caller alias count:%d : %p", m_pCallerAliasNames->wCount, this ));
  2496. }
  2497. else if( RasIsRegistered() )
  2498. {
  2499. //ARQ message must have a caller alias
  2500. pAliasList = RASGetRegisteredAliasList();
  2501. wszMachineName = pAliasList -> pItems[0].pData;
  2502. //H323DBG(( DEBUG_LEVEL_ERROR, "Caller alias count:%d : %p", m_pCallerAliasNames->wCount, this ));
  2503. //set the value for m_pCallerAliasNames
  2504. if( !AddAliasItem( m_pCallerAliasNames,
  2505. (BYTE*)(wszMachineName),
  2506. sizeof(WCHAR) * (wcslen(wszMachineName) + 1 ),
  2507. pAliasList -> pItems[0].wType ) )
  2508. {
  2509. H323DBG(( DEBUG_LEVEL_ERROR,
  2510. "could not allocate caller name." ));
  2511. // invalid address id
  2512. *pdwStatus = LINEERR_NOMEM;
  2513. // failure
  2514. return FALSE;
  2515. }
  2516. //H323DBG(( DEBUG_LEVEL_ERROR, "Caller alias count:%d : %p", m_pCallerAliasNames->wCount, this ));
  2517. }
  2518. // check for user user information
  2519. if( pCallParams->dwUserUserInfoSize > 0 )
  2520. {
  2521. // save user user info
  2522. if (AddU2U( U2U_OUTBOUND, pCallParams->dwUserUserInfoSize,
  2523. (LPBYTE)pCallParams + pCallParams->dwUserUserInfoOffset ) == FALSE )
  2524. {
  2525. //no need to free above aloocated memory for m_CalleeAlias and
  2526. //m_CallerAlias
  2527. // invalid address id
  2528. *pdwStatus = LINEERR_NOMEM;
  2529. // failure
  2530. return FALSE;
  2531. }
  2532. }
  2533. // save call data buffer.
  2534. if( SetCallData( (LPBYTE)pCallParams + pCallParams->dwCallDataOffset,
  2535. pCallParams->dwCallDataSize ) == FALSE )
  2536. {
  2537. //no need to free above aloocated memory for m_CalleeAlias and
  2538. //m_CallerAlias
  2539. // invalid address id
  2540. *pdwStatus = LINEERR_NOMEM;
  2541. // failure
  2542. return FALSE;
  2543. }
  2544. // clear incoming modes
  2545. m_dwIncomingModes = 0;
  2546. // outgoing modes will be finalized after H.245 stage
  2547. m_dwOutgoingModes = dwMediaModes | LINEMEDIAMODE_UNKNOWN;
  2548. // save media modes specified
  2549. m_dwRequestedModes = dwMediaModes;
  2550. H323DBG(( DEBUG_LEVEL_TRACE, "ValidateCallParams exited:%p.", this ));
  2551. // success
  2552. return TRUE;
  2553. }
  2554. /*++
  2555. Routine Description:
  2556. Associates call object with the specified conference id.
  2557. Arguments:
  2558. Return Values:
  2559. Returns true if successful.
  2560. --*/
  2561. PH323_CONFERENCE
  2562. CH323Call::CreateConference (
  2563. IN GUID* pConferenceId OPTIONAL)
  2564. {
  2565. int iresult;
  2566. H323DBG(( DEBUG_LEVEL_TRACE, "CreateConference entered:%p.", this ));
  2567. Lock();
  2568. _ASSERTE( m_hdConf == NULL );
  2569. // create conference
  2570. m_hdConf = new H323_CONFERENCE( this );
  2571. // validate
  2572. if ( m_hdConf == NULL )
  2573. {
  2574. H323DBG(( DEBUG_LEVEL_ERROR,
  2575. "could no allocate the conference object."));
  2576. Unlock();
  2577. return NULL;
  2578. }
  2579. if (pConferenceId)
  2580. {
  2581. m_ConferenceID = *pConferenceId;
  2582. }
  2583. else
  2584. {
  2585. iresult = UuidCreate (&m_ConferenceID);
  2586. if ((iresult == RPC_S_OK) || (iresult ==RPC_S_UUID_LOCAL_ONLY))
  2587. {
  2588. H323DBG ((DEBUG_LEVEL_INFO, "generated new conference id (GUID)."));
  2589. }
  2590. else
  2591. {
  2592. H323DBG(( DEBUG_LEVEL_ERROR,
  2593. "failed to generate GUID for conference id: %d.", iresult ));
  2594. ZeroMemory (&m_ConferenceID, sizeof m_ConferenceID);
  2595. }
  2596. }
  2597. Unlock();
  2598. H323DBG(( DEBUG_LEVEL_TRACE, "CreateConference exited:%p.", this ));
  2599. return m_hdConf;
  2600. }
  2601. /*++
  2602. Routine Description:
  2603. Initiates outbound call to specified destination.
  2604. !!always called in a lock
  2605. Arguments:
  2606. none
  2607. Return Values:
  2608. Returns true if successful.
  2609. --*/
  2610. BOOL
  2611. CH323Call::PlaceCall(void)
  2612. {
  2613. H323DBG(( DEBUG_LEVEL_TRACE, "PlaceCall entered:%p.", this ));
  2614. if( m_dwFlags & CALLOBJECT_SHUTDOWN )
  2615. {
  2616. return FALSE;
  2617. }
  2618. // see if user user information specified
  2619. CopyU2UAsNonStandard( U2U_OUTBOUND );
  2620. if( m_pwszDisplay == NULL )
  2621. {
  2622. // see if caller alias specified
  2623. if( m_pCallerAliasNames && m_pCallerAliasNames -> wCount )
  2624. {
  2625. if((m_pCallerAliasNames ->pItems[0].wType == h323_ID_chosen) ||
  2626. (m_pCallerAliasNames ->pItems[0].wType == e164_chosen) )
  2627. {
  2628. // send caller name as display
  2629. m_pwszDisplay = m_pCallerAliasNames -> pItems[0].pData;
  2630. //H323DBG(( DEBUG_LEVEL_ERROR, "Caller alias count:%d : %p", m_pCallerAliasNames->wCount, this ));
  2631. }
  2632. //H323DBG(( DEBUG_LEVEL_ERROR, "Caller alias count:%d : %p", m_pCallerAliasNames->wCount, this ));
  2633. }
  2634. }
  2635. // validate
  2636. if( !SetupCall() )
  2637. {
  2638. H323DBG(( DEBUG_LEVEL_VERBOSE, "Q931 call: failed." ));
  2639. return FALSE;
  2640. }
  2641. H323DBG(( DEBUG_LEVEL_TRACE, "PlaceCall exited:%p.", this ));
  2642. // return status
  2643. return TRUE;
  2644. }
  2645. void
  2646. CH323Call::DropUserInitiated(
  2647. IN DWORD dwDisconnectMode
  2648. )
  2649. {
  2650. //since this is a user initiated drop, the transfered call should also
  2651. //be dropped for a primary call and vice versa
  2652. if( IsTransferredCall( m_dwCallType ) && m_hdRelatedCall )
  2653. {
  2654. QueueTAPILineRequest(
  2655. TSPI_CLOSE_CALL,
  2656. m_hdRelatedCall,
  2657. NULL,
  2658. dwDisconnectMode,
  2659. m_wCallReference );
  2660. }
  2661. DropCall(dwDisconnectMode);
  2662. }
  2663. //always called in lock
  2664. BOOL
  2665. /*++
  2666. Routine Description:
  2667. Hangs up call (if necessary) and changes state to idle.
  2668. Arguments:
  2669. dwDisconnectMode - Status code for disconnect.
  2670. Return Values:
  2671. Returns true if successful.
  2672. --*/
  2673. CH323Call::DropCall(
  2674. IN DWORD dwDisconnectMode
  2675. )
  2676. {
  2677. PUserToUserLE pU2ULE = NULL;
  2678. if( m_dwFlags & CALLOBJECT_SHUTDOWN )
  2679. {
  2680. return FALSE;
  2681. }
  2682. H323DBG(( DEBUG_LEVEL_TRACE, "DropCall entered:%p.", this ));
  2683. if( (m_dwRASCallState == RASCALL_STATE_REGISTERED ) ||
  2684. (m_dwRASCallState == RASCALL_STATE_ARQSENT ) )
  2685. {
  2686. //disengage from the GK
  2687. SendDRQ( forcedDrop_chosen, NOT_RESEND_SEQ_NUM, TRUE );
  2688. }
  2689. // determine call state
  2690. switch (m_dwCallState)
  2691. {
  2692. case LINECALLSTATE_CONNECTED:
  2693. // hangup call (this will invoke async indication)
  2694. // validate
  2695. //encode ASN.1 and send Q931release message to the peer
  2696. if(!SendQ931Message( NO_INVOKEID,
  2697. 0,
  2698. 0,
  2699. RELEASECOMPLMESSAGETYPE,
  2700. NO_H450_APDU ))
  2701. {
  2702. //post a message to the callback thread to shutdown the H323 call
  2703. H323DBG(( DEBUG_LEVEL_ERROR,
  2704. "error hanging up call 0x%08lx.", this ));
  2705. }
  2706. else
  2707. {
  2708. m_dwStateMachine = Q931_RELEASE_SENT;
  2709. H323DBG(( DEBUG_LEVEL_VERBOSE, "call 0x%08lx hung up.", this ));
  2710. }
  2711. // change call state to disconnected
  2712. ChangeCallState(LINECALLSTATE_DISCONNECTED, dwDisconnectMode);
  2713. break;
  2714. case LINECALLSTATE_OFFERING:
  2715. // see if user user information specified
  2716. CopyU2UAsNonStandard( U2U_OUTBOUND );
  2717. // reject call
  2718. //encode ASN.1 and send Q931Setup message to the peer
  2719. if( SendQ931Message( NO_INVOKEID,
  2720. 0,
  2721. 0,
  2722. RELEASECOMPLMESSAGETYPE,
  2723. NO_H450_APDU ))
  2724. {
  2725. m_dwStateMachine = Q931_RELEASE_SENT;
  2726. H323DBG(( DEBUG_LEVEL_VERBOSE, "call 0x%08lx rejected.", this ));
  2727. }
  2728. else
  2729. {
  2730. H323DBG(( DEBUG_LEVEL_ERROR, "error reject call 0x%08lx.",this));
  2731. }
  2732. // change call state to disconnected
  2733. ChangeCallState(LINECALLSTATE_DISCONNECTED, dwDisconnectMode);
  2734. break;
  2735. case LINECALLSTATE_RINGBACK:
  2736. case LINECALLSTATE_ACCEPTED:
  2737. // cancel outbound call
  2738. if( SendQ931Message( NO_INVOKEID,
  2739. 0,
  2740. 0,
  2741. RELEASECOMPLMESSAGETYPE,
  2742. NO_H450_APDU ))
  2743. {
  2744. H323DBG(( DEBUG_LEVEL_ERROR,
  2745. "error cancelling call 0x%08lx.", this ));
  2746. }
  2747. else
  2748. {
  2749. H323DBG(( DEBUG_LEVEL_ERROR,
  2750. "error reject call 0x%08lx.", this ));
  2751. }
  2752. // change call state to disconnected
  2753. ChangeCallState(LINECALLSTATE_DISCONNECTED, dwDisconnectMode);
  2754. break;
  2755. case LINECALLSTATE_DIALING:
  2756. // change call state to disconnected
  2757. ChangeCallState(LINECALLSTATE_DISCONNECTED, dwDisconnectMode);
  2758. break;
  2759. case LINECALLSTATE_DISCONNECTED:
  2760. //
  2761. // disconnected but still need to clean up
  2762. //
  2763. break;
  2764. case LINECALLSTATE_IDLE:
  2765. //
  2766. // call object already idle
  2767. //
  2768. if( (m_dwCallType == CALLTYPE_NORMAL) &&
  2769. (m_dwStateMachine == Q931_SETUP_RECVD) )
  2770. {
  2771. if( SendQ931Message( NO_INVOKEID,
  2772. 0,
  2773. 0,
  2774. RELEASECOMPLMESSAGETYPE,
  2775. NO_H450_APDU ))
  2776. {
  2777. H323DBG(( DEBUG_LEVEL_ERROR,
  2778. "error cancelling call 0x%08lx.", this ));
  2779. }
  2780. else
  2781. {
  2782. H323DBG(( DEBUG_LEVEL_ERROR,
  2783. "error reject call 0x%08lx.", this ));
  2784. }
  2785. }
  2786. DropSupplementaryServicesCalls();
  2787. return TRUE;
  2788. }
  2789. if( ( (m_dwCallType & CALLTYPE_TRANSFEREDDEST) && m_hdRelatedCall ) ||
  2790. ( (m_dwCallType & CALLTYPE_TRANSFEREDSRC ) && m_hdRelatedCall ) )
  2791. {
  2792. m_dwCallState = LINECALLSTATE_IDLE;
  2793. }
  2794. else
  2795. {
  2796. // Tell the MSP to stop streaming.
  2797. SendMSPMessage( SP_MSG_CallShutdown, 0, 0, NULL );
  2798. // change call state to idle
  2799. ChangeCallState( LINECALLSTATE_IDLE, 0 );
  2800. }
  2801. if( (m_dwCallType & CALLTYPE_TRANSFEREDSRC ) && m_hdRelatedCall )
  2802. {
  2803. //drop the primary call
  2804. if( !QueueTAPILineRequest(
  2805. TSPI_CLOSE_CALL,
  2806. m_hdRelatedCall,
  2807. NULL,
  2808. LINEDISCONNECTMODE_NORMAL,
  2809. NULL ) )
  2810. {
  2811. H323DBG((DEBUG_LEVEL_ERROR, "could not post H323 close event"));
  2812. }
  2813. }
  2814. H323DBG(( DEBUG_LEVEL_TRACE, "DropCall exited:%p.", this ));
  2815. // success
  2816. return TRUE;
  2817. }
  2818. void
  2819. CH323Call::DropSupplementaryServicesCalls()
  2820. {
  2821. if( (m_dwCallType & CALLTYPE_FORWARDCONSULT) ||
  2822. (m_dwCallType & CALLTYPE_DIVERTED_SERVED) ||
  2823. (m_dwCallType & CALLTYPE_DIVERTEDSRC) ||
  2824. (m_dwCallType & CALLTYPE_DIVERTEDSRC_NOROUTING) )
  2825. {
  2826. if( m_dwQ931Flags & Q931_CALL_CONNECTED )
  2827. {
  2828. if( SendQ931Message( NO_INVOKEID,
  2829. 0,
  2830. 0,
  2831. RELEASECOMPLMESSAGETYPE,
  2832. NO_H450_APDU ))
  2833. {
  2834. m_dwStateMachine = Q931_RELEASE_SENT;
  2835. H323DBG(( DEBUG_LEVEL_VERBOSE, "call 0x%08lx rejected.", this ));
  2836. }
  2837. }
  2838. g_pH323Line->m_fForwardConsultInProgress = FALSE;
  2839. }
  2840. if( (m_dwCallType & CALLTYPE_FORWARDCONSULT) &&
  2841. (m_dwOrigin == LINECALLORIGIN_OUTBOUND ) )
  2842. {
  2843. //inform the user about failure of line forward operation
  2844. if( m_dwCallDiversionState != H4503_CHECKRESTRICTION_SUCC )
  2845. {
  2846. (*g_pfnLineEventProc)(
  2847. g_pH323Line->m_htLine,
  2848. (HTAPICALL)NULL,
  2849. (DWORD)LINE_ADDRESSSTATE,
  2850. (DWORD)LINEADDRESSSTATE_FORWARD,
  2851. (DWORD)LINEADDRESSSTATE_FORWARD,
  2852. (DWORD)0
  2853. );
  2854. }
  2855. }
  2856. if( m_dwCallType & CALLTYPE_DIVERTEDSRC )
  2857. {
  2858. ChangeCallState( LINECALLSTATE_IDLE, 0 );
  2859. }
  2860. }
  2861. //!!always called in a lock
  2862. BOOL
  2863. CH323Call::HandleConnectMessage(
  2864. IN Q931_CONNECT_ASN *pConnectASN
  2865. )
  2866. {
  2867. PH323_CALL pPrimaryCall = NULL;
  2868. H323DBG(( DEBUG_LEVEL_TRACE, "HandleConnectMessage entered:%p.", this ));
  2869. if( pConnectASN->fNonStandardDataPresent )
  2870. {
  2871. //add user user info
  2872. if( AddU2UNoAlloc( U2U_INBOUND,
  2873. pConnectASN->nonStandardData.sData.wOctetStringLength,
  2874. pConnectASN->nonStandardData.sData.pOctetString ) == TRUE )
  2875. {
  2876. H323DBG(( DEBUG_LEVEL_VERBOSE,
  2877. "user user info available in CONNECT PDU." ));
  2878. if( !(m_dwCallType & CALLTYPE_TRANSFEREDSRC) )
  2879. {
  2880. // signal incoming
  2881. PostLineEvent (
  2882. LINE_CALLINFO,
  2883. LINECALLINFOSTATE_USERUSERINFO, 0, 0 );
  2884. }
  2885. //don't release the data buffer
  2886. pConnectASN->fNonStandardDataPresent = FALSE;
  2887. }
  2888. else
  2889. {
  2890. H323DBG(( DEBUG_LEVEL_WARNING,
  2891. "could not save incoming user user info." ));
  2892. //memory failure : shutdown the H323 call
  2893. CloseCall( 0 );
  2894. goto cleanup;
  2895. }
  2896. }
  2897. //get the vendor info
  2898. if( pConnectASN->EndpointType.pVendorInfo )
  2899. {
  2900. FreeVendorInfo( &m_peerVendorInfo );
  2901. m_peerVendorInfo = pConnectASN->VendorInfo;
  2902. pConnectASN->EndpointType.pVendorInfo = NULL;
  2903. }
  2904. if( pConnectASN->h245AddrPresent )
  2905. {
  2906. m_peerH245Addr = pConnectASN->h245Addr;
  2907. }
  2908. //copy the fast start proposal
  2909. if( pConnectASN->fFastStartPresent &&
  2910. (m_dwFastStart!=FAST_START_NOTAVAIL) )
  2911. {
  2912. if( m_pPeerFastStart )
  2913. {
  2914. //we had received fast start params in previous proceeding
  2915. //or alerting message
  2916. FreeFastStart( m_pPeerFastStart );
  2917. }
  2918. m_pPeerFastStart = pConnectASN->pFastStart;
  2919. m_dwFastStart = FAST_START_AVAIL;
  2920. //we are keeping a reference to the fast start list so don't release it
  2921. pConnectASN->pFastStart = NULL;
  2922. }
  2923. else
  2924. {
  2925. m_dwFastStart = FAST_START_NOTAVAIL;
  2926. }
  2927. if( ( (m_dwCallType & CALLTYPE_TRANSFEREDSRC)||
  2928. (m_dwCallType & CALLTYPE_DIVERTEDTRANSFERED) ) && m_hdRelatedCall )
  2929. {
  2930. QueueSuppServiceWorkItem( SWAP_REPLACEMENT_CALL,
  2931. m_hdCall, (ULONG_PTR)m_hdRelatedCall );
  2932. }
  2933. else
  2934. {
  2935. //start H245
  2936. SendMSPStartH245( NULL, NULL );
  2937. SendMSPMessage( SP_MSG_ConnectComplete, 0, 0, NULL );
  2938. }
  2939. //If we join MCU we get the conference ID of the conference we
  2940. //joined and not the one that we sent in Setup message.
  2941. if( IsEqualConferenceID( &pConnectASN->ConferenceID ) == FALSE )
  2942. {
  2943. H323DBG ((DEBUG_LEVEL_ERROR,
  2944. "OnReceiveConnect: We received different conference id." ));
  2945. m_ConferenceID = pConnectASN->ConferenceID;
  2946. }
  2947. //tell TAPI about state change
  2948. ChangeCallState( LINECALLSTATE_CONNECTED, 0 );
  2949. FreeConnectASN( pConnectASN );
  2950. H323DBG(( DEBUG_LEVEL_TRACE, "HandleConnectMessage exited:%p.", this ));
  2951. return TRUE;
  2952. cleanup:
  2953. FreeConnectASN( pConnectASN );
  2954. return FALSE;
  2955. }
  2956. //!!always called in a lock
  2957. void
  2958. CH323Call::HandleAlertingMessage(
  2959. IN Q931_ALERTING_ASN * pAlertingASN
  2960. )
  2961. {
  2962. H323DBG(( DEBUG_LEVEL_TRACE, "HandleAlertingMessage entered:%p.", this ));
  2963. if( pAlertingASN->fNonStandardDataPresent )
  2964. {
  2965. // add user user info
  2966. if( AddU2UNoAlloc( U2U_INBOUND,
  2967. pAlertingASN->nonStandardData.sData.wOctetStringLength,
  2968. pAlertingASN->nonStandardData.sData.pOctetString ) == TRUE )
  2969. {
  2970. H323DBG(( DEBUG_LEVEL_VERBOSE,
  2971. "user user info available in ALERT PDU." ));
  2972. // signal incoming
  2973. if( !(m_dwCallType & CALLTYPE_TRANSFEREDSRC) )
  2974. {
  2975. PostLineEvent (
  2976. LINE_CALLINFO,
  2977. LINECALLINFOSTATE_USERUSERINFO, 0, 0 );
  2978. }
  2979. //don't release the data buffer
  2980. pAlertingASN->fNonStandardDataPresent = FALSE;
  2981. }
  2982. else
  2983. {
  2984. H323DBG(( DEBUG_LEVEL_WARNING,
  2985. "could not save incoming user user info." ));
  2986. //memory failure : shutdown the H323 call
  2987. CloseCall( 0 );
  2988. return;
  2989. }
  2990. }
  2991. if( pAlertingASN->fH245AddrPresent )
  2992. {
  2993. m_peerH245Addr = pAlertingASN->h245Addr;
  2994. }
  2995. if( pAlertingASN->fFastStartPresent &&
  2996. (m_dwFastStart!=FAST_START_NOTAVAIL) )
  2997. {
  2998. if( m_pPeerFastStart )
  2999. {
  3000. //we had received fast start params in previous proceeding
  3001. //or alerting message
  3002. FreeFastStart( m_pPeerFastStart );
  3003. }
  3004. m_pPeerFastStart = pAlertingASN->pFastStart;
  3005. m_dwFastStart = FAST_START_AVAIL;
  3006. //we are keeping a reference to the fast start list so don't release it
  3007. pAlertingASN->pFastStart = NULL;
  3008. pAlertingASN->fFastStartPresent = FALSE;
  3009. }
  3010. //for DIVERTEDSRC, call its ok to tell TAPI about this state
  3011. ChangeCallState( LINECALLSTATE_RINGBACK, 0 );
  3012. /*if( pAlertingASN->fH245AddrPresent && !(m_dwFlags & H245_START_MSG_SENT) )
  3013. {
  3014. //start early H245
  3015. SendMSPStartH245( NULL, NULL);
  3016. }*/
  3017. FreeAlertingASN( pAlertingASN );
  3018. H323DBG(( DEBUG_LEVEL_TRACE, "HandleAlertingMessage exited:%p.", this ));
  3019. return;
  3020. }
  3021. //!!must be always called in a lock
  3022. BOOL
  3023. CH323Call::HandleSetupMessage(
  3024. IN Q931MESSAGE* pMessage
  3025. )
  3026. {
  3027. PH323_ALIASITEM pwszDivertedToAlias = NULL;
  3028. WCHAR * pwszAliasName = NULL;
  3029. WORD wAliasLength = 0;
  3030. H323DBG(( DEBUG_LEVEL_TRACE, "HandleSetupMessage entered:%p.", this ));
  3031. if( m_pCallerAliasNames && (m_pCallerAliasNames -> wCount > 0) )
  3032. {
  3033. pwszAliasName = m_pCallerAliasNames->pItems[0].pData;
  3034. wAliasLength = (m_pCallerAliasNames->pItems[0].wDataLength+1)
  3035. * sizeof(WCHAR);
  3036. //H323DBG(( DEBUG_LEVEL_ERROR, "Caller alias count:%d : %p", m_pCallerAliasNames->wCount, this ));
  3037. }
  3038. pwszDivertedToAlias = g_pH323Line->CallToBeDiverted(
  3039. pwszAliasName,
  3040. wAliasLength,
  3041. LINEFORWARDMODE_UNCOND | LINEFORWARDMODE_UNCONDSPECIFIC );
  3042. if( pwszDivertedToAlias )
  3043. {
  3044. if( !InitiateCallDiversion( pwszDivertedToAlias, DiversionReason_cfu ) )
  3045. {
  3046. return FALSE;
  3047. }
  3048. return TRUE;
  3049. }
  3050. //send the proceeding message to the peer if not already sent by the GK
  3051. //SendProceeding();
  3052. if(RasIsRegistered())
  3053. {
  3054. if( !SendARQ( NOT_RESEND_SEQ_NUM ) )
  3055. {
  3056. return FALSE;
  3057. }
  3058. //copy the data to be sent in preparetoanswer message
  3059. if( m_prepareToAnswerMsgData.pbBuffer )
  3060. delete m_prepareToAnswerMsgData.pbBuffer;
  3061. ZeroMemory( (PVOID)&m_prepareToAnswerMsgData, sizeof(BUFFERDESCR) );
  3062. m_prepareToAnswerMsgData.pbBuffer =
  3063. (BYTE*)new char[pMessage->UserToUser.wUserInfoLen];
  3064. if( m_prepareToAnswerMsgData.pbBuffer == NULL )
  3065. {
  3066. return FALSE;
  3067. }
  3068. CopyMemory( (PVOID)m_prepareToAnswerMsgData.pbBuffer,
  3069. (PVOID)pMessage->UserToUser.pbUserInfo,
  3070. pMessage->UserToUser.wUserInfoLen );
  3071. m_prepareToAnswerMsgData.dwLength = pMessage->UserToUser.wUserInfoLen;
  3072. }
  3073. else
  3074. {
  3075. if( (m_dwCallType & CALLTYPE_TRANSFEREDDEST) && m_hdRelatedCall )
  3076. {
  3077. MSPMessageData* pMSPMessageData = new MSPMessageData;
  3078. if( pMSPMessageData == NULL )
  3079. {
  3080. return FALSE;
  3081. }
  3082. pMSPMessageData->hdCall = m_hdRelatedCall;
  3083. pMSPMessageData->messageType = SP_MSG_PrepareToAnswer;
  3084. pMSPMessageData->pbEncodedBuf =
  3085. new BYTE[pMessage->UserToUser.wUserInfoLen];
  3086. if( pMSPMessageData->pbEncodedBuf == NULL )
  3087. {
  3088. delete pMSPMessageData;
  3089. return FALSE;
  3090. }
  3091. CopyMemory( pMSPMessageData->pbEncodedBuf,
  3092. (PVOID)pMessage->UserToUser.pbUserInfo,
  3093. pMessage->UserToUser.wUserInfoLen );
  3094. pMSPMessageData->wLength = pMessage->UserToUser.wUserInfoLen;
  3095. pMSPMessageData->hReplacementCall = m_hdCall;
  3096. if( !QueueUserWorkItem( SendMSPMessageOnRelatedCall,
  3097. pMSPMessageData, WT_EXECUTEDEFAULT ) )
  3098. {
  3099. delete pMSPMessageData->pbEncodedBuf;
  3100. delete pMSPMessageData;
  3101. return FALSE;
  3102. }
  3103. }
  3104. else
  3105. {
  3106. // signal incoming call
  3107. _ASSERTE(!m_htCall);
  3108. PostLineEvent (
  3109. LINE_NEWCALL,
  3110. (DWORD_PTR)m_hdCall,
  3111. (DWORD_PTR)&m_htCall, 0);
  3112. _ASSERTE( m_htCall );
  3113. if( m_htCall == NULL )
  3114. return FALSE;
  3115. if( IsListEmpty(&m_IncomingU2U) == FALSE )
  3116. {
  3117. // signal incoming
  3118. PostLineEvent (
  3119. LINE_CALLINFO,
  3120. LINECALLINFOSTATE_USERUSERINFO, 0, 0);
  3121. }
  3122. ChangeCallState( LINECALLSTATE_OFFERING, 0 );
  3123. //Send the new call message to the unspecified MSP
  3124. SendMSPMessage( SP_MSG_PrepareToAnswer,
  3125. pMessage->UserToUser.pbUserInfo,
  3126. pMessage->UserToUser.wUserInfoLen, NULL );
  3127. }
  3128. }
  3129. H323DBG(( DEBUG_LEVEL_TRACE, "HandleSetupMessage exited:%p.", this ));
  3130. return TRUE;
  3131. }
  3132. BOOL
  3133. CH323Call::HandleCallDiversionFacility(
  3134. PH323_ADDR pAlternateAddress )
  3135. {
  3136. PSTR pszAlias;
  3137. WCHAR pwszAliasName[H323_MAXDESTNAMELEN];
  3138. in_addr addr;
  3139. if( m_pCallReroutingInfo == NULL )
  3140. {
  3141. m_pCallReroutingInfo = new CALLREROUTINGINFO;
  3142. if( m_pCallReroutingInfo == NULL )
  3143. {
  3144. return FALSE;
  3145. }
  3146. ZeroMemory( (PVOID)m_pCallReroutingInfo, sizeof(CALLREROUTINGINFO) );
  3147. }
  3148. m_pCallReroutingInfo->diversionCounter = 1;
  3149. m_pCallReroutingInfo->diversionReason = DiversionReason_cfu;
  3150. //free any previous divertedTo alias
  3151. if( m_pCallReroutingInfo->divertedToNrAlias )
  3152. {
  3153. FreeAliasNames( m_pCallReroutingInfo->divertedToNrAlias );
  3154. m_pCallReroutingInfo->divertedToNrAlias = NULL;
  3155. }
  3156. addr.S_un.S_addr = htonl( pAlternateAddress->Addr.IP_Binary.dwAddr );
  3157. pszAlias = inet_ntoa( addr );
  3158. if( pszAlias == NULL )
  3159. return FALSE;
  3160. m_pCallReroutingInfo->divertedToNrAlias = new H323_ALIASNAMES;
  3161. if( m_pCallReroutingInfo->divertedToNrAlias == NULL )
  3162. {
  3163. return FALSE;
  3164. }
  3165. ZeroMemory( m_pCallReroutingInfo->divertedToNrAlias,
  3166. sizeof(H323_ALIASNAMES) );
  3167. MultiByteToWideChar(
  3168. GetACP(),
  3169. MB_PRECOMPOSED,
  3170. pszAlias,
  3171. strlen(pszAlias)+1,
  3172. pwszAliasName,
  3173. H323_MAXDESTNAMELEN
  3174. );
  3175. if( !AddAliasItem( m_pCallReroutingInfo->divertedToNrAlias,
  3176. pwszAliasName, h323_ID_chosen ) )
  3177. {
  3178. delete m_pCallReroutingInfo->divertedToNrAlias;
  3179. m_pCallReroutingInfo->divertedToNrAlias = NULL;
  3180. return FALSE;
  3181. }
  3182. m_CalleeAddr = *pAlternateAddress;
  3183. if( m_pCalleeAliasNames && m_pCalleeAliasNames->wCount )
  3184. {
  3185. m_pCallReroutingInfo->divertingNrAlias = new H323_ALIASNAMES;
  3186. if( m_pCallReroutingInfo->divertingNrAlias != NULL )
  3187. {
  3188. ZeroMemory( (PVOID)m_pCallReroutingInfo->divertingNrAlias,
  3189. sizeof(H323_ALIASNAMES) );
  3190. if( !AddAliasItem( m_pCallReroutingInfo->divertingNrAlias,
  3191. m_pCalleeAliasNames->pItems[0].pData,
  3192. m_pCalleeAliasNames->pItems[0].wType ) )
  3193. {
  3194. delete m_pCallReroutingInfo->divertingNrAlias;
  3195. m_pCallReroutingInfo->divertingNrAlias = NULL;
  3196. }
  3197. }
  3198. }
  3199. m_dwCallType |= CALLTYPE_DIVERTEDSRC;
  3200. m_dwCallDiversionState = H4503_CALLREROUTING_RECVD;
  3201. H323DBG(( DEBUG_LEVEL_TRACE, "HandleCallDiversionFacility exited:%p.",
  3202. this ));
  3203. return TRUE;
  3204. }
  3205. BOOL
  3206. CH323Call::HandleCallDiversionFacility(
  3207. PH323_ALIASNAMES pAliasList )
  3208. {
  3209. if( !m_pCallReroutingInfo )
  3210. {
  3211. m_pCallReroutingInfo = new CALLREROUTINGINFO;
  3212. if( m_pCallReroutingInfo == NULL )
  3213. {
  3214. return FALSE;
  3215. }
  3216. ZeroMemory( (PVOID)m_pCallReroutingInfo, sizeof(CALLREROUTINGINFO) );
  3217. }
  3218. m_pCallReroutingInfo->diversionCounter = 1;
  3219. m_pCallReroutingInfo->diversionReason = DiversionReason_cfu;
  3220. if( m_pCallReroutingInfo->divertedToNrAlias )
  3221. {
  3222. FreeAliasNames( m_pCallReroutingInfo->divertedToNrAlias );
  3223. m_pCallReroutingInfo->divertedToNrAlias = NULL;
  3224. }
  3225. m_pCallReroutingInfo->divertedToNrAlias = pAliasList;
  3226. if( m_pCalleeAliasNames && m_pCalleeAliasNames->wCount )
  3227. {
  3228. m_pCallReroutingInfo->divertingNrAlias = new H323_ALIASNAMES;
  3229. if( m_pCallReroutingInfo->divertingNrAlias != NULL )
  3230. {
  3231. ZeroMemory( (PVOID)m_pCallReroutingInfo->divertingNrAlias,
  3232. sizeof(H323_ALIASNAMES) );
  3233. if( !AddAliasItem( m_pCallReroutingInfo->divertingNrAlias,
  3234. m_pCalleeAliasNames->pItems[0].pData,
  3235. m_pCalleeAliasNames->pItems[0].wType ) )
  3236. {
  3237. delete m_pCallReroutingInfo->divertingNrAlias;
  3238. m_pCallReroutingInfo->divertingNrAlias = NULL;
  3239. }
  3240. }
  3241. }
  3242. m_dwCallType |= CALLTYPE_DIVERTEDSRC;
  3243. m_dwCallDiversionState = H4503_CALLREROUTING_RECVD;
  3244. H323DBG(( DEBUG_LEVEL_TRACE, "HandleCallDiversionFacility exited:%p.",
  3245. this ));
  3246. return TRUE;
  3247. }
  3248. BOOL
  3249. CH323Call::HandleTransferFacility(
  3250. PH323_ALIASNAMES pAliasList )
  3251. {
  3252. H323DBG(( DEBUG_LEVEL_TRACE, "HandleTransferFacility entered:%p.", this ));
  3253. //argument.callIdentity
  3254. ZeroMemory( (PVOID)m_pCTCallIdentity, sizeof(m_pCTCallIdentity) );
  3255. //argument.reroutingNumber
  3256. FreeAliasNames( m_pTransferedToAlias );
  3257. m_pTransferedToAlias = pAliasList;
  3258. m_dwCallType |= CALLTYPE_TRANSFERED_PRIMARY;
  3259. m_dwCallDiversionState = H4502_CTINITIATE_RECV;
  3260. //queue an event for creating a new call
  3261. if( !QueueSuppServiceWorkItem( TSPI_DIAL_TRNASFEREDCALL, m_hdCall,
  3262. (ULONG_PTR)m_pTransferedToAlias ))
  3263. {
  3264. H323DBG(( DEBUG_LEVEL_TRACE, "could not post dial transfer event." ));
  3265. }
  3266. H323DBG(( DEBUG_LEVEL_TRACE, "HandleTransferFacility entered:%p.", this ));
  3267. return TRUE;
  3268. }
  3269. BOOL
  3270. CH323Call::HandleTransferFacility(
  3271. PH323_ADDR pAlternateAddress )
  3272. {
  3273. PSTR pszAlias;
  3274. WCHAR pwszAliasName[H323_MAXDESTNAMELEN];
  3275. in_addr addr;
  3276. H323DBG(( DEBUG_LEVEL_TRACE, "HandleTransferFacility entered:%p.", this ));
  3277. //argument.callIdentity
  3278. ZeroMemory( (PVOID)m_pCTCallIdentity, sizeof(m_pCTCallIdentity) );
  3279. //argument.reroutingNumber
  3280. //free any previous divertedTo alias
  3281. FreeAliasNames( m_pTransferedToAlias );
  3282. addr.S_un.S_addr = htonl( pAlternateAddress->Addr.IP_Binary.dwAddr );
  3283. pszAlias = inet_ntoa( addr );
  3284. if( pszAlias == NULL )
  3285. {
  3286. return FALSE;
  3287. }
  3288. m_pTransferedToAlias = new H323_ALIASNAMES;
  3289. if( m_pTransferedToAlias == NULL )
  3290. {
  3291. return FALSE;
  3292. }
  3293. ZeroMemory( m_pTransferedToAlias, sizeof(H323_ALIASNAMES) );
  3294. MultiByteToWideChar(
  3295. GetACP(),
  3296. MB_PRECOMPOSED,
  3297. pszAlias,
  3298. strlen(pszAlias)+1,
  3299. pwszAliasName,
  3300. H323_MAXDESTNAMELEN
  3301. );
  3302. if( !AddAliasItem( m_pTransferedToAlias, pwszAliasName, h323_ID_chosen ) )
  3303. {
  3304. delete m_pTransferedToAlias;
  3305. m_pTransferedToAlias = NULL;
  3306. return FALSE;
  3307. }
  3308. m_CalleeAddr = *pAlternateAddress;
  3309. m_dwCallType |= CALLTYPE_TRANSFERED_PRIMARY;
  3310. m_dwCallDiversionState = H4502_CTINITIATE_RECV;
  3311. //queue an event for creating a new call
  3312. if( !QueueSuppServiceWorkItem( TSPI_DIAL_TRNASFEREDCALL, m_hdCall,
  3313. (ULONG_PTR)m_pTransferedToAlias ))
  3314. {
  3315. H323DBG(( DEBUG_LEVEL_TRACE, "could not post dial transfer event." ));
  3316. }
  3317. H323DBG(( DEBUG_LEVEL_TRACE, "HandleTransferFacility entered:%p.", this ));
  3318. return TRUE;
  3319. }
  3320. //!!always called in a lock
  3321. void
  3322. CH323Call::HandleFacilityMessage(
  3323. IN DWORD dwInvokeID,
  3324. IN Q931_FACILITY_ASN * pFacilityASN
  3325. )
  3326. {
  3327. H323DBG(( DEBUG_LEVEL_TRACE, "HandleFacilityMessage entered:%p.", this ));
  3328. if( pFacilityASN->fNonStandardDataPresent )
  3329. {
  3330. // add user user info
  3331. if( AddU2UNoAlloc( U2U_INBOUND,
  3332. pFacilityASN->nonStandardData.sData.wOctetStringLength,
  3333. pFacilityASN->nonStandardData.sData.pOctetString ) == TRUE )
  3334. {
  3335. H323DBG(( DEBUG_LEVEL_VERBOSE,
  3336. "user user info available in ALERT PDU." ));
  3337. // signal incoming
  3338. if( !(m_dwCallType & CALLTYPE_TRANSFEREDSRC) )
  3339. {
  3340. PostLineEvent (
  3341. LINE_CALLINFO,
  3342. LINECALLINFOSTATE_USERUSERINFO, 0, 0);
  3343. }
  3344. //don't release the data buffer
  3345. pFacilityASN->fNonStandardDataPresent = FALSE;
  3346. }
  3347. else
  3348. {
  3349. H323DBG(( DEBUG_LEVEL_WARNING,
  3350. "could not save incoming user user info." ));
  3351. //memory failure : shutdown the H323 call
  3352. CloseCall( 0 );
  3353. return;
  3354. }
  3355. }
  3356. if( (pFacilityASN->bReason == callForwarded_chosen) ||
  3357. (pFacilityASN->bReason == FacilityReason_routeCallToGatekeeper_chosen) ||
  3358. (pFacilityASN->bReason == routeCallToMC_chosen) )
  3359. {
  3360. if( pFacilityASN->pAlternativeAliasList != NULL )
  3361. {
  3362. if( m_dwCallState == LINECALLSTATE_CONNECTED )
  3363. {
  3364. HandleTransferFacility( pFacilityASN->pAlternativeAliasList );
  3365. //don't free the alias list
  3366. pFacilityASN->pAlternativeAliasList = NULL;
  3367. }
  3368. else if( m_dwCallState != LINECALLSTATE_DISCONNECTED )
  3369. {
  3370. //redirect the call if not yet connected
  3371. if( HandleCallDiversionFacility(
  3372. pFacilityASN->pAlternativeAliasList ) )
  3373. {
  3374. OnCallReroutingReceive( NO_INVOKEID );
  3375. //don't free the alias list
  3376. pFacilityASN->pAlternativeAliasList = NULL;
  3377. }
  3378. }
  3379. }
  3380. else if( pFacilityASN->fAlternativeAddressPresent )
  3381. {
  3382. if( m_dwCallState == LINECALLSTATE_CONNECTED )
  3383. {
  3384. HandleTransferFacility( &pFacilityASN->AlternativeAddr );
  3385. }
  3386. else if( m_dwCallState != LINECALLSTATE_DISCONNECTED )
  3387. {
  3388. //redirect the call if not yet connected
  3389. if( HandleCallDiversionFacility( &pFacilityASN->AlternativeAddr ) )
  3390. {
  3391. OnCallReroutingReceive( NO_INVOKEID );
  3392. }
  3393. }
  3394. }
  3395. }
  3396. //Handle H.450 APDU
  3397. if( pFacilityASN->dwH450APDUType == DIVERTINGLEGINFO1_OPCODE )
  3398. {
  3399. if( m_dwOrigin != LINECALLORIGIN_OUTBOUND )
  3400. {
  3401. return;
  3402. }
  3403. if( m_pCallReroutingInfo->fPresentAllow )
  3404. {
  3405. PostLineEvent (
  3406. LINE_CALLINFO,
  3407. LINECALLINFOSTATE_REDIRECTINGID, 0, 0);
  3408. }
  3409. }
  3410. else if( pFacilityASN->dwH450APDUType == CALLREROUTING_OPCODE )
  3411. {
  3412. OnCallReroutingReceive( dwInvokeID );
  3413. }
  3414. else if( pFacilityASN->dwH450APDUType == REMOTEHOLD_OPCODE )
  3415. {
  3416. if( m_fRemoteHoldInitiated )
  3417. {
  3418. //Hold();
  3419. m_fRemoteHoldInitiated = FALSE;
  3420. }
  3421. }
  3422. else if( pFacilityASN->dwH450APDUType == REMOTERETRIEVE_OPCODE )
  3423. {
  3424. if( m_fRemoteRetrieveInitiated )
  3425. {
  3426. //UnHold();
  3427. m_fRemoteRetrieveInitiated = FALSE;
  3428. }
  3429. }
  3430. else if( pFacilityASN->fH245AddrPresent )
  3431. {
  3432. m_peerH245Addr = pFacilityASN->h245Addr;
  3433. H323DBG(( DEBUG_LEVEL_TRACE, "H245 address received in facility." ));
  3434. //If Q931 call already connected then send another StartH245.
  3435. if( m_dwCallState == LINECALLSTATE_CONNECTED )
  3436. {
  3437. SendMSPStartH245( NULL, NULL );
  3438. }
  3439. }
  3440. H323DBG(( DEBUG_LEVEL_TRACE, "HandleFacilityMessage exited:%p.", this ));
  3441. return;
  3442. }
  3443. void
  3444. CH323Call::SetNewCallInfo(
  3445. HANDLE hConnWait,
  3446. HANDLE hWSAEvent,
  3447. DWORD dwState
  3448. )
  3449. {
  3450. H323DBG(( DEBUG_LEVEL_TRACE, "SetNewCallInfo entered." ));
  3451. Lock();
  3452. m_hTransportWait = hConnWait;
  3453. m_hTransport = hWSAEvent;
  3454. SetQ931CallState( dwState );
  3455. Unlock();
  3456. H323DBG(( DEBUG_LEVEL_TRACE, "SetNewCallInfo exited." ));
  3457. }
  3458. //!!no need to call in a lock
  3459. void
  3460. CH323Call::SetQ931CallState( DWORD dwState )
  3461. {
  3462. H323DBG(( DEBUG_LEVEL_TRACE, "SetQ931CallState entered." ));
  3463. //turn off the current state
  3464. m_dwQ931Flags &= ~(Q931_CALL_CONNECTING |
  3465. Q931_CALL_CONNECTED |
  3466. Q931_CALL_DISCONNECTED );
  3467. //set the new state
  3468. m_dwQ931Flags |= dwState;
  3469. H323DBG(( DEBUG_LEVEL_TRACE, "SetQ931CallState exited." ));
  3470. }
  3471. void
  3472. CH323Call::DialCall()
  3473. {
  3474. H323DBG(( DEBUG_LEVEL_TRACE, "DialCall entered:%p.", this ));
  3475. Lock();
  3476. ChangeCallState( LINECALLSTATE_DIALING, 0);
  3477. if( RasIsRegistered() )
  3478. {
  3479. if( !SendARQ( NOT_RESEND_SEQ_NUM ) )
  3480. {
  3481. //If a forward consult call then enable theforwarding anyway.
  3482. if( (m_dwCallType & CALLTYPE_FORWARDCONSULT )&&
  3483. (m_dwOrigin == LINECALLORIGIN_OUTBOUND ) )
  3484. {
  3485. //Success of forwarding
  3486. EnableCallForwarding();
  3487. }
  3488. CloseCall( 0 );
  3489. }
  3490. }
  3491. else
  3492. {
  3493. if( !PlaceCall() )
  3494. {
  3495. //If a forward consult call then enable theforwarding anyway.
  3496. if( (m_dwCallType & CALLTYPE_FORWARDCONSULT )&&
  3497. (m_dwOrigin == LINECALLORIGIN_OUTBOUND ) )
  3498. {
  3499. //Success of forwarding
  3500. EnableCallForwarding();
  3501. }
  3502. CloseCall( LINEDISCONNECTMODE_UNREACHABLE );
  3503. }
  3504. }
  3505. Unlock();
  3506. H323DBG(( DEBUG_LEVEL_TRACE, "DialCall exited:%p.", this ));
  3507. }
  3508. //!!always called in a lock
  3509. void
  3510. CH323Call::MakeCall()
  3511. {
  3512. H323DBG(( DEBUG_LEVEL_TRACE, "MakeCall entered:%p.", this ));
  3513. ChangeCallState( LINECALLSTATE_DIALING, 0 );
  3514. // resolve dialable into local and remote address
  3515. if( !RasIsRegistered() &&
  3516. !ResolveAddress( GetDialableAddress() ) )
  3517. {
  3518. CloseCall( LINEDISCONNECTMODE_BADADDRESS );
  3519. }
  3520. else
  3521. {
  3522. if( RasIsRegistered() )
  3523. {
  3524. if( !SendARQ( NOT_RESEND_SEQ_NUM ) )
  3525. {
  3526. //If a forward consult call then enable theforwarding anyway.
  3527. if( (m_dwCallType & CALLTYPE_FORWARDCONSULT )&&
  3528. (m_dwOrigin == LINECALLORIGIN_OUTBOUND ) )
  3529. {
  3530. //Success of forwarding
  3531. EnableCallForwarding();
  3532. }
  3533. CloseCall( 0 );
  3534. }
  3535. }
  3536. else
  3537. {
  3538. if( !PlaceCall() )
  3539. {
  3540. //If a forward consult call then enable theforwarding anyway.
  3541. if( (m_dwCallType & CALLTYPE_FORWARDCONSULT )&&
  3542. (m_dwOrigin == LINECALLORIGIN_OUTBOUND ) )
  3543. {
  3544. //Success of forwarding
  3545. EnableCallForwarding();
  3546. }
  3547. CloseCall( LINEDISCONNECTMODE_UNREACHABLE );
  3548. }
  3549. }
  3550. }
  3551. H323DBG(( DEBUG_LEVEL_TRACE, "MakeCall exited:%p.", this ));
  3552. }
  3553. //!!always called in a lock
  3554. void
  3555. CH323Call::HandleProceedingMessage(
  3556. IN Q931_ALERTING_ASN * pProceedingASN
  3557. )
  3558. {
  3559. H323DBG(( DEBUG_LEVEL_TRACE, "HandleProceedingMessage entered:%p.", this ));
  3560. if( pProceedingASN->fNonStandardDataPresent )
  3561. {
  3562. // add user user info
  3563. if( AddU2UNoAlloc( U2U_INBOUND,
  3564. pProceedingASN->nonStandardData.sData.wOctetStringLength,
  3565. pProceedingASN->nonStandardData.sData.pOctetString ) == TRUE )
  3566. {
  3567. H323DBG(( DEBUG_LEVEL_VERBOSE,
  3568. "user user info available in ALERT PDU." ));
  3569. // signal incoming
  3570. if( !(m_dwCallType & CALLTYPE_TRANSFEREDSRC) )
  3571. {
  3572. PostLineEvent (
  3573. LINE_CALLINFO,
  3574. LINECALLINFOSTATE_USERUSERINFO, 0, 0);
  3575. }
  3576. //don't release the data buffer
  3577. pProceedingASN->fNonStandardDataPresent = FALSE;
  3578. }
  3579. else
  3580. {
  3581. H323DBG(( DEBUG_LEVEL_WARNING,
  3582. "could not save incoming user user info." ));
  3583. //memory failure : shutdown the H323 call
  3584. CloseCall( 0 );
  3585. return;
  3586. }
  3587. }
  3588. if( pProceedingASN->fH245AddrPresent )
  3589. {
  3590. m_peerH245Addr = pProceedingASN->h245Addr;
  3591. }
  3592. if( pProceedingASN->fFastStartPresent &&
  3593. (m_dwFastStart!=FAST_START_NOTAVAIL) )
  3594. {
  3595. if( m_pPeerFastStart )
  3596. {
  3597. //we had received fast start params in previous proceeding
  3598. //or alerting message
  3599. FreeFastStart( m_pPeerFastStart );
  3600. }
  3601. m_pPeerFastStart = pProceedingASN->pFastStart;
  3602. m_dwFastStart = FAST_START_AVAIL;
  3603. //we are keeping a reference to the fast start list so don't release it
  3604. pProceedingASN->pFastStart = NULL;
  3605. pProceedingASN->fFastStartPresent = FALSE;
  3606. }
  3607. /*
  3608. if( pProceedingASN->fH245AddrPresent && !(m_dwFlags & H245_START_MSG_SENT) )
  3609. {
  3610. //start early H245
  3611. SendMSPStartH245( NULL, NULL );
  3612. }*/
  3613. FreeProceedingASN( pProceedingASN );
  3614. H323DBG(( DEBUG_LEVEL_TRACE, "HandleProceedingMessage exited:%p.", this ));
  3615. return;
  3616. }
  3617. //!!always called in a lock
  3618. BOOL
  3619. CH323Call::HandleReleaseMessage(
  3620. IN Q931_RELEASE_COMPLETE_ASN *pReleaseASN
  3621. )
  3622. {
  3623. DWORD dwDisconnectMode = LINEDISCONNECTMODE_NORMAL;
  3624. H323DBG(( DEBUG_LEVEL_TRACE, "HandleReleaseMessage entered:%p.", this ));
  3625. if( (m_dwCallType & CALLTYPE_TRANSFERED_PRIMARY) &&
  3626. (m_hdRelatedCall != NULL) )
  3627. {
  3628. return QueueSuppServiceWorkItem( DROP_PRIMARY_CALL,
  3629. m_hdRelatedCall, (ULONG_PTR)m_hdCall );
  3630. }
  3631. //change the state to disconnected before callong drop call.
  3632. //This will ensure that release message is not sent to the peer
  3633. ChangeCallState( LINECALLSTATE_DISCONNECTED, 0 );
  3634. //release non standard data
  3635. if( pReleaseASN->fNonStandardDataPresent )
  3636. {
  3637. delete pReleaseASN->nonStandardData.sData.pOctetString;
  3638. pReleaseASN->nonStandardData.sData.pOctetString = NULL;
  3639. }
  3640. //Should we drop the primary call if the transfered call in rejected?
  3641. if( (m_dwCallType == CALLTYPE_TRANSFEREDSRC) && m_hdRelatedCall )
  3642. {
  3643. if( !QueueTAPILineRequest(
  3644. TSPI_CLOSE_CALL,
  3645. m_hdRelatedCall,
  3646. NULL,
  3647. LINEDISCONNECTMODE_NORMAL,
  3648. NULL ) )
  3649. {
  3650. H323DBG((DEBUG_LEVEL_ERROR, "could not post H323 close event"));
  3651. }
  3652. }
  3653. //close call
  3654. if( m_dwCallState != LINECALLSTATE_CONNECTED )
  3655. {
  3656. dwDisconnectMode = LINEDISCONNECTMODE_REJECT;
  3657. }
  3658. CloseCall( dwDisconnectMode );
  3659. H323DBG(( DEBUG_LEVEL_TRACE, "HandleReleaseMessage exited:%p.", this ));
  3660. return TRUE;
  3661. }
  3662. //never call in lock
  3663. BOOL
  3664. CH323Call::InitializeIncomingCall(
  3665. IN Q931_SETUP_ASN* pSetupASN,
  3666. IN DWORD dwCallType,
  3667. IN WORD wCallRef
  3668. )
  3669. {
  3670. PH323_CONFERENCE pConf;
  3671. WCHAR* wszMachineName;
  3672. H323DBG((DEBUG_LEVEL_TRACE, "InitializeIncomingCall entered:%p.",this));
  3673. //bind outgoing call
  3674. pConf = CreateConference( &(pSetupASN->ConferenceID) );
  3675. if( pConf == NULL )
  3676. {
  3677. H323DBG(( DEBUG_LEVEL_ERROR, "could not create conference." ));
  3678. goto cleanup;
  3679. }
  3680. if( !g_pH323Line -> GetH323ConfTable() -> Add( pConf ) )
  3681. {
  3682. H323DBG(( DEBUG_LEVEL_ERROR,
  3683. "could not add conf to conf table." ));
  3684. // failure
  3685. goto cleanup;
  3686. }
  3687. // save caller transport address
  3688. if( !GetPeerAddress(&m_CallerAddr) )
  3689. {
  3690. goto cleanup;
  3691. }
  3692. if( !GetHostAddress(&m_CalleeAddr) )
  3693. {
  3694. goto cleanup;
  3695. }
  3696. //get endpoint info
  3697. m_peerEndPointType = pSetupASN->EndpointType;
  3698. //get the vendor info
  3699. if( pSetupASN->EndpointType.pVendorInfo )
  3700. {
  3701. m_peerVendorInfo = pSetupASN->VendorInfo;
  3702. //we have copied the vendor info pointers. So dont release
  3703. //the pointers in the ASN's vendor info struct
  3704. pSetupASN->EndpointType.pVendorInfo = NULL;
  3705. }
  3706. if( pSetupASN -> fCallIdentifierPresent )
  3707. {
  3708. m_callIdentifier = pSetupASN->callIdentifier;
  3709. }
  3710. else
  3711. {
  3712. int iresult = UuidCreate( &m_callIdentifier );
  3713. if( (iresult != RPC_S_OK) && (iresult !=RPC_S_UUID_LOCAL_ONLY) )
  3714. {
  3715. goto cleanup;
  3716. }
  3717. }
  3718. _ASSERTE( !m_pPeerFastStart );
  3719. if( pSetupASN->fFastStartPresent &&
  3720. (m_dwFastStart!=FAST_START_NOTAVAIL) )
  3721. {
  3722. m_pPeerFastStart = pSetupASN->pFastStart;
  3723. m_dwFastStart = FAST_START_PEER_AVAIL;
  3724. //we are keeping a reference to the fast start list so don't release it
  3725. pSetupASN->pFastStart = NULL;
  3726. pSetupASN->fFastStartPresent = FALSE;
  3727. }
  3728. else
  3729. {
  3730. m_dwFastStart = FAST_START_NOTAVAIL;
  3731. }
  3732. //get the alias names
  3733. if( pSetupASN->pCalleeAliasList )
  3734. {
  3735. _ASSERTE( m_pCalleeAliasNames );
  3736. delete m_pCalleeAliasNames;
  3737. m_pCalleeAliasNames = pSetupASN->pCalleeAliasList;
  3738. pSetupASN->pCalleeAliasList = NULL;
  3739. }
  3740. else
  3741. {
  3742. if( RasIsRegistered() )
  3743. {
  3744. PH323_ALIASNAMES pAliasList = RASGetRegisteredAliasList();
  3745. AddAliasItem( m_pCalleeAliasNames,
  3746. pAliasList->pItems[0].pData,
  3747. pAliasList->pItems[0].wType );
  3748. }
  3749. else
  3750. {
  3751. wszMachineName = g_pH323Line->GetMachineName();
  3752. //set the value for m_pCalleeAliasNames
  3753. AddAliasItem( m_pCalleeAliasNames,
  3754. (BYTE*)(wszMachineName),
  3755. sizeof(WCHAR) * (wcslen(wszMachineName) + 1 ),
  3756. h323_ID_chosen );
  3757. }
  3758. }
  3759. _ASSERTE( m_pCallerAliasNames );
  3760. delete m_pCallerAliasNames;
  3761. m_pCallerAliasNames = NULL;
  3762. if( pSetupASN->pCallerAliasList )
  3763. {
  3764. m_pCallerAliasNames = pSetupASN->pCallerAliasList;
  3765. pSetupASN->pCallerAliasList = NULL;
  3766. //H323DBG(( DEBUG_LEVEL_ERROR, "Caller alias count:%d : %p", m_pCallerAliasNames->wCount, this ));
  3767. }
  3768. if( pSetupASN->pExtraAliasList )
  3769. {
  3770. m_pPeerExtraAliasNames = pSetupASN->pExtraAliasList;
  3771. pSetupASN->pExtraAliasList = NULL;
  3772. }
  3773. //non -standard info
  3774. if( pSetupASN->fNonStandardDataPresent )
  3775. {
  3776. // add user user info
  3777. if( AddU2UNoAlloc( U2U_INBOUND,
  3778. pSetupASN->nonStandardData.sData.wOctetStringLength,
  3779. pSetupASN->nonStandardData.sData.pOctetString ) == TRUE )
  3780. {
  3781. H323DBG(( DEBUG_LEVEL_VERBOSE,
  3782. "user user info available in Setup PDU." ));
  3783. //don't release the data buffer
  3784. pSetupASN->fNonStandardDataPresent = FALSE;
  3785. }
  3786. else
  3787. {
  3788. H323DBG(( DEBUG_LEVEL_WARNING,
  3789. "could not save incoming user user info." ));
  3790. goto cleanup;
  3791. }
  3792. }
  3793. if( pSetupASN->fSourceAddrPresent )
  3794. {
  3795. m_CallerAddr = pSetupASN->sourceAddr;
  3796. }
  3797. m_dwCallType = dwCallType;
  3798. if( wCallRef )
  3799. {
  3800. m_wQ931CallRef = (wCallRef | 0x8000);
  3801. }
  3802. //clear incoming modes
  3803. m_dwIncomingModes = 0;
  3804. //outgoing modes will be finalized during H.245 phase
  3805. m_dwOutgoingModes = g_pH323Line->GetMediaModes() | LINEMEDIAMODE_UNKNOWN;
  3806. //save media modes specified
  3807. m_dwRequestedModes = g_pH323Line->GetMediaModes();
  3808. H323DBG(( DEBUG_LEVEL_TRACE, "InitializeIncomingCall exited:%p.", this ));
  3809. return TRUE;
  3810. cleanup:
  3811. return FALSE;
  3812. }
  3813. //!!always called in a lock
  3814. BOOL
  3815. CH323Call::ChangeCallState(
  3816. IN DWORD dwCallState,
  3817. IN DWORD dwCallStateMode
  3818. )
  3819. /*++
  3820. Routine Description:
  3821. Reports call state of specified call object.
  3822. Arguments:
  3823. dwCallState - Specifies new state of call object.
  3824. dwCallStateMode - Specifies new state mode of call object.
  3825. Return Values:
  3826. Returns true if successful.
  3827. --*/
  3828. {
  3829. H323DBG(( DEBUG_LEVEL_VERBOSE, "call 0x%08lx %s. state mode: 0x%08lx.",
  3830. this, H323CallStateToString(dwCallState), dwCallStateMode ));
  3831. // save new call state
  3832. m_dwCallState = dwCallState;
  3833. m_dwCallStateMode = dwCallStateMode;
  3834. if(
  3835. ((m_dwCallType & CALLTYPE_TRANSFEREDDEST) && m_hdRelatedCall ) ||
  3836. ((m_dwCallType & CALLTYPE_TRANSFEREDSRC ) && m_hdRelatedCall ) ||
  3837. (m_dwCallType & CALLTYPE_FORWARDCONSULT )
  3838. )
  3839. {
  3840. return TRUE;
  3841. }
  3842. // report call status
  3843. PostLineEvent (
  3844. LINE_CALLSTATE,
  3845. m_dwCallState,
  3846. m_dwCallStateMode,
  3847. m_dwIncomingModes | m_dwOutgoingModes);
  3848. // success
  3849. return TRUE;
  3850. }
  3851. //always called in a lock
  3852. void
  3853. CH323Call::CopyU2UAsNonStandard(
  3854. IN DWORD dwDirection
  3855. )
  3856. {
  3857. PUserToUserLE pU2ULE = NULL;
  3858. H323DBG(( DEBUG_LEVEL_TRACE, "CopyU2UAsNonStandard entered:%p.", this ));
  3859. if( RemoveU2U( dwDirection, &pU2ULE ) )
  3860. {
  3861. // transfer header information
  3862. m_NonStandardData.bCountryCode = H221_COUNTRY_CODE_USA;
  3863. m_NonStandardData.bExtension = H221_COUNTRY_EXT_USA;
  3864. m_NonStandardData.wManufacturerCode = H221_MFG_CODE_MICROSOFT;
  3865. // initialize octet string containing data
  3866. m_NonStandardData.sData.wOctetStringLength = LOWORD(pU2ULE->dwU2USize);
  3867. if( m_NonStandardData.sData.pOctetString )
  3868. {
  3869. delete m_NonStandardData.sData.pOctetString;
  3870. m_NonStandardData.sData.pOctetString = NULL;
  3871. }
  3872. m_NonStandardData.sData.pOctetString = pU2ULE->pU2U;
  3873. }
  3874. else
  3875. {
  3876. //reset non standard data
  3877. memset( (PVOID)&m_NonStandardData,0,sizeof(H323NonStandardData ));
  3878. }
  3879. H323DBG(( DEBUG_LEVEL_TRACE, "CopyU2UAsNonStandard exited:%p.", this ));
  3880. }
  3881. void
  3882. CH323Call::AcceptCall(void)
  3883. /*++
  3884. Routine Description:
  3885. Accepts incoming call.
  3886. !!always called in lock
  3887. Arguments:
  3888. Return Values:
  3889. Returns true if successful.
  3890. --*/
  3891. {
  3892. PH323_CALL pCall = NULL;
  3893. H323DBG(( DEBUG_LEVEL_TRACE, "AcceptCall entered:%p.", this ));
  3894. if( m_dwFlags & CALLOBJECT_SHUTDOWN )
  3895. {
  3896. return;
  3897. }
  3898. // see if user user information specified
  3899. CopyU2UAsNonStandard( U2U_OUTBOUND );
  3900. if( m_pwszDisplay == NULL )
  3901. {
  3902. // see if callee alias specified
  3903. if( m_pCalleeAliasNames && m_pCalleeAliasNames -> wCount )
  3904. {
  3905. if((m_pCalleeAliasNames->pItems[0].wType == h323_ID_chosen) ||
  3906. (m_pCalleeAliasNames ->pItems[0].wType == e164_chosen) )
  3907. {
  3908. // send callee name as display
  3909. m_pwszDisplay = m_pCalleeAliasNames -> pItems[0].pData;
  3910. }
  3911. }
  3912. }
  3913. //send answer call message to the MSP instance
  3914. if( (m_dwCallType & CALLTYPE_TRANSFEREDDEST) && m_hdRelatedCall )
  3915. {
  3916. MSPMessageData* pMSPMessageData = new MSPMessageData;
  3917. if( pMSPMessageData == NULL )
  3918. {
  3919. CloseCall( 0 );
  3920. return;
  3921. }
  3922. pMSPMessageData->hdCall = m_hdRelatedCall;
  3923. pMSPMessageData->messageType = SP_MSG_AnswerCall;
  3924. pMSPMessageData->pbEncodedBuf = NULL;
  3925. pMSPMessageData->wLength = 0;
  3926. pMSPMessageData->hReplacementCall = m_hdCall;
  3927. if( !QueueUserWorkItem( SendMSPMessageOnRelatedCall, pMSPMessageData,
  3928. WT_EXECUTEDEFAULT ) )
  3929. {
  3930. delete pMSPMessageData;
  3931. CloseCall( 0 );
  3932. return;
  3933. }
  3934. }
  3935. else
  3936. {
  3937. SendMSPMessage( SP_MSG_AnswerCall, 0, 0, NULL );
  3938. }
  3939. m_fCallAccepted = TRUE;
  3940. if( m_fReadyToAnswer )
  3941. {
  3942. // validate status
  3943. if( !AcceptH323Call() )
  3944. {
  3945. H323DBG(( DEBUG_LEVEL_ERROR, "error answering call 0x%08lx.",
  3946. this ));
  3947. // drop call using disconnect mode
  3948. DropCall( LINEDISCONNECTMODE_TEMPFAILURE );
  3949. // failure
  3950. return;
  3951. }
  3952. if( !(m_dwFlags & H245_START_MSG_SENT) )
  3953. {
  3954. //start H245
  3955. SendMSPStartH245( NULL, NULL );
  3956. }
  3957. //tell MSP about connect state
  3958. SendMSPMessage( SP_MSG_ConnectComplete, 0, 0, NULL );
  3959. //change call state to accepted from offering
  3960. ChangeCallState( LINECALLSTATE_CONNECTED, 0 );
  3961. }
  3962. H323DBG(( DEBUG_LEVEL_TRACE, "AcceptCall exited:%p.", this ));
  3963. // success
  3964. return;
  3965. }
  3966. //always called in lock
  3967. void
  3968. CH323Call::ReleaseU2U(void)
  3969. {
  3970. PUserToUserLE pU2ULE = NULL;
  3971. PLIST_ENTRY pLE;
  3972. H323DBG(( DEBUG_LEVEL_TRACE, "ReleaseU2U entered:%p.", this ));
  3973. if( m_dwFlags & CALLOBJECT_SHUTDOWN )
  3974. {
  3975. return;
  3976. }
  3977. // see if list is empty
  3978. if( IsListEmpty( &m_IncomingU2U ) == FALSE )
  3979. {
  3980. // remove first entry from list
  3981. pLE = RemoveHeadList( &m_IncomingU2U );
  3982. // convert to user user structure
  3983. pU2ULE = CONTAINING_RECORD(pLE, UserToUserLE, Link);
  3984. // release memory
  3985. if(pU2ULE)
  3986. {
  3987. delete pU2ULE;
  3988. pU2ULE = NULL;
  3989. }
  3990. }
  3991. // see if list contains pending data
  3992. if( IsListEmpty( &m_IncomingU2U ) == FALSE )
  3993. {
  3994. H323DBG(( DEBUG_LEVEL_VERBOSE,
  3995. "more user user info available." ));
  3996. // signal incoming
  3997. PostLineEvent (
  3998. LINE_CALLINFO,
  3999. LINECALLINFOSTATE_USERUSERINFO, 0, 0);
  4000. }
  4001. H323DBG(( DEBUG_LEVEL_TRACE, "ReleaseU2U exited:%p.", this ));
  4002. }
  4003. //always called in lock
  4004. void
  4005. CH323Call::SendU2U(
  4006. IN BYTE* pUserUserInfo,
  4007. IN DWORD dwSize
  4008. )
  4009. {
  4010. H323DBG(( DEBUG_LEVEL_TRACE, "SendU2U entered:%p.", this ));
  4011. if( m_dwFlags & CALLOBJECT_SHUTDOWN )
  4012. {
  4013. return;
  4014. }
  4015. // check for user user info
  4016. if( pUserUserInfo != NULL )
  4017. {
  4018. // transfer header information
  4019. m_NonStandardData.bCountryCode = H221_COUNTRY_CODE_USA;
  4020. m_NonStandardData.bExtension = H221_COUNTRY_EXT_USA;
  4021. m_NonStandardData.wManufacturerCode = H221_MFG_CODE_MICROSOFT;
  4022. // initialize octet string containing data
  4023. m_NonStandardData.sData.wOctetStringLength = (WORD)dwSize;
  4024. if( m_NonStandardData.sData.pOctetString != NULL )
  4025. {
  4026. delete m_NonStandardData.sData.pOctetString;
  4027. m_NonStandardData.sData.pOctetString = NULL;
  4028. }
  4029. m_NonStandardData.sData.pOctetString = pUserUserInfo;
  4030. }
  4031. // send user user data
  4032. if( !SendQ931Message( 0, 0, 0, FACILITYMESSAGETYPE, NO_H450_APDU ) )
  4033. {
  4034. H323DBG(( DEBUG_LEVEL_ERROR,
  4035. "error sending non-standard message."));
  4036. }
  4037. H323DBG(( DEBUG_LEVEL_TRACE, "SendU2U exited:%p.", this ));
  4038. return;
  4039. }
  4040. BOOL
  4041. CH323Call::InitializeQ931(
  4042. IN SOCKET callSocket
  4043. )
  4044. {
  4045. BOOL fSuccess;
  4046. H323DBG((DEBUG_LEVEL_ERROR, "q931 call initialize entered:%p.", this ));
  4047. if( !BindIoCompletionCallback(
  4048. (HANDLE)callSocket,
  4049. CH323Call::IoCompletionCallback,
  4050. 0) )
  4051. {
  4052. H323DBG(( DEBUG_LEVEL_ERROR,
  4053. "couldn't bind i/o completion callabck:%d:%p.",
  4054. GetLastError(), this ));
  4055. return FALSE;
  4056. }
  4057. //initilize the member variables
  4058. m_callSocket = callSocket;
  4059. H323DBG((DEBUG_LEVEL_ERROR, "q931 call initialize exited:%lx, %p.",
  4060. m_callSocket, this ));
  4061. return TRUE;
  4062. }
  4063. //no need to lock
  4064. BOOL
  4065. CH323Call::GetPeerAddress(
  4066. IN H323_ADDR *pAddr
  4067. )
  4068. {
  4069. SOCKADDR_IN sockaddr;
  4070. int len = sizeof(sockaddr);
  4071. H323DBG((DEBUG_LEVEL_ERROR, "GetPeerAddress entered:%p.", this ));
  4072. if( getpeername( m_callSocket, (SOCKADDR*)&sockaddr, &len)
  4073. == SOCKET_ERROR )
  4074. {
  4075. H323DBG(( DEBUG_LEVEL_ERROR,
  4076. "error 0x%08lx calling getpeername.", WSAGetLastError() ));
  4077. return FALSE;
  4078. }
  4079. pAddr->nAddrType = H323_IP_BINARY;
  4080. pAddr->bMulticast = FALSE;
  4081. pAddr->Addr.IP_Binary.wPort = ntohs(sockaddr.sin_port);
  4082. pAddr->Addr.IP_Binary.dwAddr = ntohl(sockaddr.sin_addr.S_un.S_addr);
  4083. H323DBG(( DEBUG_LEVEL_ERROR, "GetPeerAddress exited:%p.", this ));
  4084. return TRUE;
  4085. }
  4086. //no need to lock
  4087. BOOL CH323Call::GetHostAddress(
  4088. IN H323_ADDR *pAddr
  4089. )
  4090. {
  4091. int len = sizeof(m_LocalAddr);
  4092. H323DBG((DEBUG_LEVEL_ERROR, "GetHostAddress entered:%p.", this ));
  4093. if( getsockname( m_callSocket, (SOCKADDR *)&m_LocalAddr, &len) ==
  4094. SOCKET_ERROR)
  4095. {
  4096. H323DBG(( DEBUG_LEVEL_ERROR,
  4097. "error 0x%08lx calling getockname.", WSAGetLastError() ));
  4098. return FALSE;
  4099. }
  4100. pAddr->nAddrType = H323_IP_BINARY;
  4101. pAddr->bMulticast = FALSE;
  4102. pAddr->Addr.IP_Binary.wPort = ntohs(m_LocalAddr.sin_port);
  4103. pAddr->Addr.IP_Binary.dwAddr = ntohl(m_LocalAddr.sin_addr.S_un.S_addr);
  4104. H323DBG((DEBUG_LEVEL_ERROR, "GetHostAddress exited:%p.", this ));
  4105. return TRUE;
  4106. }
  4107. //!!always called in a lock
  4108. BOOL
  4109. CH323Call::OnReceiveFacility(
  4110. IN Q931MESSAGE* pMessage
  4111. )
  4112. {
  4113. Q931_FACILITY_ASN facilityASN;
  4114. H323DBG((DEBUG_LEVEL_TRACE, "OnReceiveFacility entered: %p.", this ));
  4115. //decode the U2U information
  4116. if( !pMessage ->UserToUser.fPresent ||
  4117. pMessage ->UserToUser.wUserInfoLen == 0 )
  4118. {
  4119. //Ignore this message. Don't shutdown the call.
  4120. return FALSE;
  4121. }
  4122. if( !ParseFacilityASN( pMessage->UserToUser.pbUserInfo,
  4123. pMessage->UserToUser.wUserInfoLen, &facilityASN ))
  4124. {
  4125. //memory failure : shutdown the H323 call
  4126. CloseCall( 0 );
  4127. return FALSE;
  4128. }
  4129. if( (facilityASN.pH245PDU.length != 0) && facilityASN.pH245PDU.value )
  4130. {
  4131. SendMSPMessage( SP_MSG_H245PDU, facilityASN.pH245PDU.value,
  4132. facilityASN.pH245PDU.length, NULL );
  4133. delete facilityASN.pH245PDU.value;
  4134. }
  4135. HandleFacilityMessage( facilityASN.dwInvokeID, &facilityASN );
  4136. H323DBG((DEBUG_LEVEL_TRACE, "OnReceiveFacility exited: %p.", this ));
  4137. return TRUE;
  4138. }
  4139. //!!always called in a lock
  4140. BOOL
  4141. CH323Call::OnReceiveProceeding(
  4142. IN Q931MESSAGE* pMessage
  4143. )
  4144. {
  4145. Q931_CALL_PROCEEDING_ASN proceedingASN;
  4146. DWORD dwAPDUType = 0;
  4147. H323DBG((DEBUG_LEVEL_TRACE, "OnReceiveProceeding entered: %p.", this ));
  4148. //decode the U2U information
  4149. if( (pMessage ->UserToUser.fPresent == FALSE) ||
  4150. (pMessage ->UserToUser.wUserInfoLen == 0) )
  4151. {
  4152. //ignore this message. don't shutdown the call.
  4153. return FALSE;
  4154. }
  4155. if( (m_dwOrigin!=LINECALLORIGIN_OUTBOUND) ||
  4156. ( (m_dwStateMachine != Q931_SETUP_SENT) &&
  4157. (m_dwStateMachine != Q931_PROCEED_RECVD) )
  4158. )
  4159. {
  4160. //ignore this message. don't shutdown the Q931 call.
  4161. return FALSE;
  4162. }
  4163. if( !ParseProceedingASN(
  4164. pMessage->UserToUser.pbUserInfo,
  4165. pMessage->UserToUser.wUserInfoLen,
  4166. &proceedingASN,
  4167. &dwAPDUType ))
  4168. {
  4169. //Ignore the wrong proceeding message.
  4170. H323DBG(( DEBUG_LEVEL_ERROR, "wrong proceeding PDU:%p.", this ));
  4171. H323DUMPBUFFER( pMessage->UserToUser.pbUserInfo,
  4172. (DWORD)pMessage->UserToUser.wUserInfoLen );
  4173. return TRUE;
  4174. }
  4175. if( (m_dwCallType & CALLTYPE_FORWARDCONSULT )&&
  4176. (m_dwOrigin == LINECALLORIGIN_OUTBOUND ) )
  4177. {
  4178. //success of forwarding
  4179. EnableCallForwarding();
  4180. CloseCall( 0 );
  4181. return TRUE;
  4182. }
  4183. HandleProceedingMessage( &proceedingASN );
  4184. //reset the timeout for setup sent
  4185. if( m_hSetupSentTimer != NULL )
  4186. {
  4187. DeleteTimerQueueTimer( H323TimerQueue, m_hSetupSentTimer, NULL );
  4188. m_hSetupSentTimer = NULL;
  4189. }
  4190. H323DBG((DEBUG_LEVEL_TRACE, "OnReceiveProceeding exited: %p.", this ));
  4191. m_dwStateMachine = Q931_PROCEED_RECVD;
  4192. return TRUE;
  4193. }
  4194. //!!always called in a lock
  4195. BOOL
  4196. CH323Call::OnReceiveAlerting(
  4197. IN Q931MESSAGE* pMessage
  4198. )
  4199. {
  4200. Q931_ALERTING_ASN alertingASN;
  4201. DWORD dwAPDUType = 0;
  4202. H323DBG((DEBUG_LEVEL_TRACE, "OnReceiveAlerting entered: %p.", this ));
  4203. //decode the U2U information
  4204. if( (pMessage ->UserToUser.fPresent == FALSE) ||
  4205. (pMessage ->UserToUser.wUserInfoLen == 0) )
  4206. {
  4207. //ignore this message. don't shutdown the call.
  4208. return FALSE;
  4209. }
  4210. if( (m_dwOrigin!=LINECALLORIGIN_OUTBOUND) ||
  4211. !( (m_dwStateMachine==Q931_SETUP_SENT) ||
  4212. (m_dwStateMachine==Q931_PROCEED_RECVD)
  4213. )
  4214. )
  4215. {
  4216. //ignore this message. don't shutdown the Q931 call.
  4217. return FALSE;
  4218. }
  4219. if( !ParseAlertingASN( pMessage->UserToUser.pbUserInfo,
  4220. pMessage->UserToUser.wUserInfoLen,
  4221. &alertingASN,
  4222. &dwAPDUType ))
  4223. {
  4224. //memory failure : shutdown the H323 call
  4225. CloseCall( 0 );
  4226. return FALSE;
  4227. }
  4228. if( (m_dwCallType & CALLTYPE_FORWARDCONSULT )&&
  4229. (m_dwOrigin == LINECALLORIGIN_OUTBOUND ) )
  4230. {
  4231. //success of forwarding
  4232. EnableCallForwarding();
  4233. CloseCall( 0 );
  4234. return FALSE;
  4235. }
  4236. //reset the timeout for setup sent
  4237. if( m_hSetupSentTimer != NULL )
  4238. {
  4239. DeleteTimerQueueTimer( H323TimerQueue, m_hSetupSentTimer, NULL );
  4240. m_hSetupSentTimer = NULL;
  4241. }
  4242. if( !CreateTimerQueueTimer(
  4243. &m_hCallEstablishmentTimer,
  4244. H323TimerQueue,
  4245. CH323Call::CallEstablishmentExpiredCallback,
  4246. (PVOID)m_hdCall,
  4247. g_RegistrySettings.dwQ931AlertingTimeout, 0,
  4248. WT_EXECUTEINIOTHREAD | WT_EXECUTEONLYONCE ))
  4249. {
  4250. CloseCall( 0 );
  4251. return FALSE;
  4252. }
  4253. HandleAlertingMessage( &alertingASN );
  4254. m_dwStateMachine = Q931_ALERT_RECVD;
  4255. H323DBG((DEBUG_LEVEL_TRACE, "OnReceiveAlerting exited: %p.", this ));
  4256. return TRUE;
  4257. }
  4258. //!!always called in lock
  4259. void
  4260. CH323Call::SetupSentTimerExpired(void)
  4261. {
  4262. DWORD dwState;
  4263. H323DBG((DEBUG_LEVEL_TRACE, "SetupSentTimerExpired entered."));
  4264. dwState = m_dwStateMachine;
  4265. if( m_hSetupSentTimer != NULL )
  4266. {
  4267. DeleteTimerQueueTimer( H323TimerQueue, m_hSetupSentTimer, NULL );
  4268. m_hSetupSentTimer = NULL;
  4269. }
  4270. if( (dwState!= Q931_CONNECT_RECVD) &&
  4271. (dwState != Q931_ALERT_RECVD) &&
  4272. (dwState != Q931_PROCEED_RECVD) &&
  4273. (dwState != Q931_RELEASE_RECVD)
  4274. )
  4275. {
  4276. //time out has occured
  4277. CloseCall( 0 );
  4278. }
  4279. H323DBG((DEBUG_LEVEL_TRACE, "SetupSentTimerExpired exited." ));
  4280. }
  4281. //!!always called in a lock
  4282. BOOL
  4283. CH323Call::OnReceiveRelease(
  4284. IN Q931MESSAGE* pMessage
  4285. )
  4286. {
  4287. DWORD dwAPDUType = 0;
  4288. Q931_RELEASE_COMPLETE_ASN releaseASN;
  4289. //decode the U2U information
  4290. if( (pMessage ->UserToUser.fPresent == FALSE) ||
  4291. (pMessage ->UserToUser.wUserInfoLen == 0) )
  4292. {
  4293. H323DBG(( DEBUG_LEVEL_ERROR, "ReleaseComplete PDU did not contain "
  4294. "user-to-user information, ignoring message." ));
  4295. //ignore this message. don't shutdown the call.
  4296. return FALSE;
  4297. }
  4298. if( !ParseReleaseCompleteASN(
  4299. pMessage->UserToUser.pbUserInfo,
  4300. pMessage->UserToUser.wUserInfoLen,
  4301. &releaseASN,
  4302. &dwAPDUType ))
  4303. {
  4304. H323DBG(( DEBUG_LEVEL_ERROR,
  4305. "ReleaseComplete PDU could not be parsed, terminating call." ));
  4306. //memory failure : shutdown the H323 call
  4307. CloseCall( 0 );
  4308. return FALSE;
  4309. }
  4310. H323DBG ((DEBUG_LEVEL_INFO, "Received ReleaseComplete PDU."));
  4311. HandleReleaseMessage( &releaseASN );
  4312. m_dwStateMachine = Q931_RELEASE_RECVD;
  4313. return TRUE;
  4314. }
  4315. //!!always called in a lock
  4316. BOOL
  4317. CH323Call::OnReceiveConnect(
  4318. IN Q931MESSAGE* pMessage
  4319. )
  4320. {
  4321. Q931_CONNECT_ASN connectASN;
  4322. DWORD dwH450APDUType = 0;
  4323. H323DBG((DEBUG_LEVEL_TRACE, "OnReceiveConnect entered: %p.", this ));
  4324. //decode the U2U information
  4325. if( (pMessage ->UserToUser.fPresent == FALSE) ||
  4326. (pMessage ->UserToUser.wUserInfoLen == 0) )
  4327. {
  4328. //ignore this message. don't shutdown the call.
  4329. return FALSE;
  4330. }
  4331. if( m_dwOrigin!=LINECALLORIGIN_OUTBOUND )
  4332. {
  4333. //ignore this message. don't shutdown the Q931 call.
  4334. return FALSE;
  4335. }
  4336. if( (m_dwStateMachine != Q931_SETUP_SENT) &&
  4337. (m_dwStateMachine != Q931_ALERT_RECVD) &&
  4338. (m_dwStateMachine != Q931_PROCEED_RECVD)
  4339. )
  4340. {
  4341. //ignore this message. don't shutdown the Q931 call.
  4342. return FALSE;
  4343. }
  4344. if( ParseConnectASN( pMessage->UserToUser.pbUserInfo,
  4345. pMessage->UserToUser.wUserInfoLen,
  4346. &connectASN,
  4347. &dwH450APDUType) == FALSE )
  4348. {
  4349. //memory failure : shutdown the H323 call
  4350. CloseCall( 0 );
  4351. return FALSE;
  4352. }
  4353. if( m_dwCallType & CALLTYPE_FORWARDCONSULT )
  4354. {
  4355. FreeConnectASN( &connectASN );
  4356. if( dwH450APDUType == H4503_DUMMYTYPERETURNRESULT_APDU)
  4357. {
  4358. //assuming this return result is for check restriction operation
  4359. return TRUE;
  4360. }
  4361. else
  4362. {
  4363. //success of forwarding
  4364. EnableCallForwarding();
  4365. CloseCall( 0 );
  4366. return FALSE;
  4367. }
  4368. }
  4369. if( !HandleConnectMessage( &connectASN ) )
  4370. {
  4371. return FALSE;
  4372. }
  4373. //reset the timeout for setup sent
  4374. if( m_hSetupSentTimer != NULL )
  4375. {
  4376. DeleteTimerQueueTimer( H323TimerQueue, m_hSetupSentTimer, NULL );
  4377. m_hSetupSentTimer = NULL;
  4378. }
  4379. if( m_hCallEstablishmentTimer )
  4380. {
  4381. DeleteTimerQueueTimer(H323TimerQueue, m_hCallEstablishmentTimer, NULL);
  4382. m_hCallEstablishmentTimer = NULL;
  4383. }
  4384. m_dwStateMachine = Q931_CONNECT_RECVD;
  4385. H323DBG((DEBUG_LEVEL_TRACE, "OnReceiveConnect exited: %p.", this ));
  4386. return TRUE;
  4387. }
  4388. //!!always called in a lock
  4389. BOOL
  4390. CH323Call::OnReceiveSetup(
  4391. IN Q931MESSAGE* pMessage
  4392. )
  4393. {
  4394. Q931_SETUP_ASN setupASN;
  4395. DWORD dwH450APDUType = 0;
  4396. PH323_CALL pCall = NULL;
  4397. WCHAR pwszCallingPartyNr[H323_MAXPATHNAMELEN];
  4398. WCHAR pwszCalledPartyNr[H323_MAXPATHNAMELEN];
  4399. BYTE* pstrTemp;
  4400. //decode the U2U information
  4401. if( (pMessage ->UserToUser.fPresent == FALSE) ||
  4402. (pMessage ->UserToUser.wUserInfoLen == 0) )
  4403. {
  4404. H323DBG(( DEBUG_LEVEL_ERROR,
  4405. "Setup message did not contain H.323 UUIE, ignoring."));
  4406. //ignore this message. don't shutdown the call.
  4407. return FALSE;
  4408. }
  4409. if( m_dwOrigin != LINECALLORIGIN_INBOUND )
  4410. {
  4411. H323DBG(( DEBUG_LEVEL_ERROR,
  4412. "Received Setup message on outbound call, ignoring."));
  4413. //ignore this message. don't shutdown the call.
  4414. return FALSE;
  4415. }
  4416. if( m_dwStateMachine != Q931_CALL_STATE_NONE )
  4417. {
  4418. H323DBG( (DEBUG_LEVEL_ERROR,
  4419. "Received Setup message on a call that is already in progress." ));
  4420. //This Q931 call has already received a setup!!!!
  4421. CloseCall( 0 );
  4422. return FALSE;
  4423. }
  4424. if( !ParseSetupASN( pMessage->UserToUser.pbUserInfo,
  4425. pMessage->UserToUser.wUserInfoLen,
  4426. &setupASN,
  4427. &dwH450APDUType ))
  4428. {
  4429. H323DBG(( DEBUG_LEVEL_ERROR,
  4430. "Failed to parse Setup UUIE, closing call." ));
  4431. //shutdown the Q931 call
  4432. CloseCall( 0 );
  4433. return FALSE;
  4434. }
  4435. if( dwH450APDUType )
  4436. {
  4437. if( m_dwCallType & CALLTYPE_FORWARDCONSULT )
  4438. {
  4439. return TRUE;
  4440. }
  4441. }
  4442. if( (pMessage->CallingPartyNumber.fPresent == TRUE) &&
  4443. (pMessage->CallingPartyNumber.dwLength > 1) &&
  4444. (setupASN.pCallerAliasList == NULL ) )
  4445. {
  4446. // Always skip 1st byte in the contents.
  4447. // Skip the 2nd byte if its not an e.164 char (could be the screening indicator byte)
  4448. pstrTemp = pMessage->CallingPartyNumber.pbContents +
  4449. ((pMessage->CallingPartyNumber.pbContents[1] & 0x80)? 2 : 1);
  4450. MultiByteToWideChar( CP_ACP,
  4451. 0,
  4452. (const char *)(pstrTemp),
  4453. -1,
  4454. pwszCallingPartyNr,
  4455. sizeof(pwszCallingPartyNr)/sizeof(WCHAR));
  4456. setupASN.pCallerAliasList = new H323_ALIASNAMES;
  4457. if( setupASN.pCallerAliasList != NULL )
  4458. {
  4459. ZeroMemory( setupASN.pCallerAliasList, sizeof(H323_ALIASNAMES) );
  4460. AddAliasItem( setupASN.pCallerAliasList,
  4461. pwszCallingPartyNr,
  4462. e164_chosen );
  4463. }
  4464. }
  4465. if( (pMessage->CalledPartyNumber.fPresent == TRUE) &&
  4466. (pMessage->CalledPartyNumber.PartyNumberLength > 0) &&
  4467. (setupASN.pCalleeAliasList == NULL ) )
  4468. {
  4469. // Always skip 1st byte in the contents.
  4470. // Skip the 2nd byte if its not an e.164 char (could be the screening indicator byte)
  4471. MultiByteToWideChar(CP_ACP,
  4472. 0,
  4473. (const char *)(pMessage->CalledPartyNumber.PartyNumbers),
  4474. -1,
  4475. pwszCalledPartyNr,
  4476. sizeof(pwszCalledPartyNr) / sizeof(WCHAR) );
  4477. setupASN.pCalleeAliasList = new H323_ALIASNAMES;
  4478. if( setupASN.pCalleeAliasList != NULL )
  4479. {
  4480. ZeroMemory( setupASN.pCalleeAliasList, sizeof(H323_ALIASNAMES) );
  4481. AddAliasItem( setupASN.pCalleeAliasList,
  4482. pwszCalledPartyNr,
  4483. e164_chosen );
  4484. }
  4485. }
  4486. //don't change the call type here
  4487. if( !InitializeIncomingCall( &setupASN, m_dwCallType, pMessage->wCallRef ) )
  4488. {
  4489. H323DBG ((DEBUG_LEVEL_ERROR,
  4490. "Failed to initialize incoming call, closing call."));
  4491. //shutdown the Q931 call
  4492. FreeSetupASN( &setupASN );
  4493. CloseCall( 0 );
  4494. return FALSE;
  4495. }
  4496. FreeSetupASN( &setupASN );
  4497. m_dwStateMachine = Q931_SETUP_RECVD;
  4498. if( !HandleSetupMessage( pMessage ) )
  4499. {
  4500. H323DBG ((DEBUG_LEVEL_ERROR,
  4501. "Failed to process Setup message, closing call."));
  4502. CloseCall( 0 );
  4503. return FALSE;
  4504. }
  4505. return TRUE;
  4506. }
  4507. //!!always called in a lock
  4508. void
  4509. CH323Call::CloseCall(
  4510. IN DWORD dwDisconnectMode )
  4511. {
  4512. H323DBG((DEBUG_LEVEL_INFO, "[%08XH] Terminating call.", this ));
  4513. if (!QueueTAPILineRequest(
  4514. TSPI_CLOSE_CALL,
  4515. m_hdCall,
  4516. NULL,
  4517. dwDisconnectMode,
  4518. m_wCallReference ))
  4519. {
  4520. H323DBG(( DEBUG_LEVEL_ERROR, "could not post H323 close event." ));
  4521. }
  4522. }
  4523. //!!always called in a lock
  4524. void
  4525. CH323Call::ReadEvent(
  4526. IN DWORD cbTransfer
  4527. )
  4528. {
  4529. H323DBG((DEBUG_LEVEL_TRACE, "ReadEvent entered: %p.", this ));
  4530. H323DBG((DEBUG_LEVEL_TRACE, "bytes received: %d.", cbTransfer));
  4531. m_RecvBuf.dwBytesCopied += cbTransfer;
  4532. //update the recv buffer
  4533. if( m_bStartOfPDU )
  4534. {
  4535. if( m_RecvBuf.dwBytesCopied < sizeof(TPKT_HEADER_SIZE) )
  4536. {
  4537. //set the buffer to get the remainig TPKT_HEADER
  4538. m_RecvBuf.WSABuf.buf =
  4539. m_RecvBuf.arBuf + m_RecvBuf.dwBytesCopied;
  4540. m_RecvBuf.WSABuf.len =
  4541. TPKT_HEADER_SIZE - m_RecvBuf.dwBytesCopied;
  4542. }
  4543. else
  4544. {
  4545. m_RecvBuf.dwPDULen = GetTpktLength( m_RecvBuf.arBuf );
  4546. if( (m_RecvBuf.dwPDULen < TPKT_HEADER_SIZE) ||
  4547. (m_RecvBuf.dwPDULen > Q931_RECV_BUFFER_LENGTH) )
  4548. {
  4549. //messed up peer. close the call.
  4550. H323DBG(( DEBUG_LEVEL_ERROR, "error:PDULen:%d.",
  4551. m_RecvBuf.dwPDULen ));
  4552. //close the call
  4553. CloseCall( 0 );
  4554. return;
  4555. }
  4556. else if( m_RecvBuf.dwPDULen == TPKT_HEADER_SIZE )
  4557. {
  4558. InitializeRecvBuf();
  4559. }
  4560. else
  4561. {
  4562. //set the buffer to get the remaining PDU
  4563. m_bStartOfPDU = FALSE;
  4564. m_RecvBuf.WSABuf.buf = m_RecvBuf.arBuf +
  4565. m_RecvBuf.dwBytesCopied;
  4566. m_RecvBuf.WSABuf.len = m_RecvBuf.dwPDULen -
  4567. m_RecvBuf.dwBytesCopied;
  4568. }
  4569. }
  4570. }
  4571. else
  4572. {
  4573. _ASSERTE( m_RecvBuf.dwBytesCopied <= m_RecvBuf.dwPDULen );
  4574. if( m_RecvBuf.dwBytesCopied == m_RecvBuf.dwPDULen )
  4575. {
  4576. //we got the whole PDU
  4577. if( !ProcessQ931PDU( &m_RecvBuf ) )
  4578. {
  4579. H323DBG(( DEBUG_LEVEL_ERROR,
  4580. "error in processing PDU:%p.", this ));
  4581. H323DUMPBUFFER( (BYTE*)m_RecvBuf.arBuf, m_RecvBuf.dwPDULen );
  4582. }
  4583. //if the call has been already shutdown due to
  4584. //a fatal error while processing the PDU or because of receiveing
  4585. //release complete message then dont post any more read buffers
  4586. if( (m_dwFlags & CALLOBJECT_SHUTDOWN) ||
  4587. (m_dwQ931Flags & Q931_CALL_DISCONNECTED) )
  4588. {
  4589. return;
  4590. }
  4591. InitializeRecvBuf();
  4592. }
  4593. else
  4594. {
  4595. //set the buffer to get the remainig PDU
  4596. m_RecvBuf.WSABuf. buf =
  4597. m_RecvBuf.arBuf + m_RecvBuf.dwBytesCopied;
  4598. m_RecvBuf.WSABuf. len =
  4599. m_RecvBuf.dwPDULen - m_RecvBuf.dwBytesCopied;
  4600. }
  4601. }
  4602. //post a read for the remaining PDU
  4603. if(!PostReadBuffer())
  4604. {
  4605. //post a message to the callback thread to shutdown the H323 call
  4606. CloseCall( 0 );
  4607. }
  4608. H323DBG((DEBUG_LEVEL_TRACE, "ReadEvent exited: %p.", this ));
  4609. }
  4610. /*
  4611. Parse a generic Q931 message and place the fields of the buffer
  4612. into the appropriate structure fields.
  4613. Parameters:
  4614. pBuf Pointer to buffer descriptor of an
  4615. input packet containing the 931 message.
  4616. pMessage Pointer to space for parsed output information.
  4617. */
  4618. //!!always called in a lock
  4619. HRESULT
  4620. CH323Call::Q931ParseMessage(
  4621. IN BYTE * pbCodedBuffer,
  4622. IN DWORD dwCodedBufferLength,
  4623. OUT PQ931MESSAGE pMessage
  4624. )
  4625. {
  4626. HRESULT hr;
  4627. BUFFERDESCR pBuf;
  4628. pBuf.dwLength = dwCodedBufferLength;
  4629. pBuf.pbBuffer = pbCodedBuffer;
  4630. H323DBG((DEBUG_LEVEL_TRACE, "Q931ParseMessage entered: %p.", this ));
  4631. memset( (PVOID)pMessage, 0, sizeof(Q931MESSAGE));
  4632. hr = ParseProtocolDiscriminator(&pBuf, &pMessage->ProtocolDiscriminator);
  4633. if( hr != S_OK )
  4634. {
  4635. return hr;
  4636. }
  4637. hr = ParseCallReference( &pBuf, &pMessage->wCallRef);
  4638. if( hr != S_OK )
  4639. {
  4640. return hr;
  4641. }
  4642. hr = ParseMessageType( &pBuf, &pMessage->MessageType );
  4643. if( hr != S_OK )
  4644. {
  4645. return hr;
  4646. }
  4647. while (pBuf.dwLength)
  4648. {
  4649. hr = ParseQ931Field(&pBuf, pMessage);
  4650. if (hr != S_OK)
  4651. {
  4652. return hr;
  4653. }
  4654. }
  4655. H323DBG((DEBUG_LEVEL_TRACE, "Q931ParseMessage exited: %p.", this ));
  4656. return S_OK;
  4657. }
  4658. //decode the PDU and release the buffer
  4659. //!!always called in a lock
  4660. BOOL
  4661. CH323Call::ProcessQ931PDU(
  4662. IN CALL_RECV_CONTEXT* pRecvBuf
  4663. )
  4664. {
  4665. PQ931MESSAGE pMessage;
  4666. BOOL retVal;
  4667. HRESULT hr;
  4668. H323DBG((DEBUG_LEVEL_TRACE, "ProcessQ931PDU entered: %p.", this ));
  4669. pMessage = new Q931MESSAGE;
  4670. if( pMessage == NULL )
  4671. {
  4672. return FALSE;
  4673. }
  4674. hr = Q931ParseMessage( (BYTE*)(pRecvBuf->arBuf + sizeof(TPKT_HEADER_SIZE)),
  4675. pRecvBuf->dwPDULen - 4,
  4676. pMessage );
  4677. if( !SUCCEEDED( hr) )
  4678. {
  4679. delete pMessage;
  4680. return FALSE;
  4681. }
  4682. if( (m_dwCallType & CALLTYPE_TRANSFERED_PRIMARY ) &&
  4683. (m_dwCallDiversionState == H4502_CTINITIATE_RECV) &&
  4684. (pMessage->MessageType != RELEASECOMPLMESSAGETYPE) )
  4685. {
  4686. // If this endpoint has already been transferred then
  4687. // ignore any further messages on the primary call.
  4688. delete pMessage;
  4689. return FALSE;
  4690. }
  4691. switch( pMessage->MessageType )
  4692. {
  4693. case ALERTINGMESSAGETYPE:
  4694. retVal = OnReceiveAlerting( pMessage );
  4695. break;
  4696. case PROCEEDINGMESSAGETYPE:
  4697. retVal = OnReceiveProceeding( pMessage );
  4698. break;
  4699. case CONNECTMESSAGETYPE:
  4700. retVal = OnReceiveConnect( pMessage );
  4701. break;
  4702. case RELEASECOMPLMESSAGETYPE:
  4703. retVal = OnReceiveRelease( pMessage );
  4704. break;
  4705. case SETUPMESSAGETYPE:
  4706. retVal = OnReceiveSetup( pMessage );
  4707. break;
  4708. case FACILITYMESSAGETYPE:
  4709. retVal = OnReceiveFacility( pMessage );
  4710. break;
  4711. default:
  4712. H323DBG(( DEBUG_LEVEL_TRACE, "unrecognised PDU recvd:%d,%p.",
  4713. pMessage->MessageType, this ));
  4714. retVal = FALSE;
  4715. }
  4716. delete pMessage;
  4717. H323DBG((DEBUG_LEVEL_TRACE, "ProcessQ931PDU exited: %p.", this ));
  4718. return retVal;
  4719. }
  4720. //!!always called in a lock
  4721. void
  4722. CH323Call::OnConnectComplete(void)
  4723. {
  4724. BOOL fSuccess = TRUE;
  4725. PH323_CALL pCall = NULL;
  4726. H323DBG((DEBUG_LEVEL_TRACE, "OnConnectComplete entered: %p.", this ));
  4727. _ASSERTE( m_dwOrigin==LINECALLORIGIN_OUTBOUND );
  4728. if( !GetHostAddress( &m_CallerAddr) )
  4729. {
  4730. //memory failure : shutdown the H323 call
  4731. CloseCall( 0 );
  4732. return;
  4733. }
  4734. InitializeRecvBuf();
  4735. //post a buffer to winsock to accept messages from the peer
  4736. if( !PostReadBuffer() )
  4737. {
  4738. //memory failure : shutdown the H323 call
  4739. CloseCall( 0 );
  4740. return;
  4741. }
  4742. //set the state to connected
  4743. SetQ931CallState( Q931_CALL_CONNECTED );
  4744. if( (m_dwCallType == CALLTYPE_NORMAL) ||
  4745. (m_dwCallType & CALLTYPE_TRANSFERING_CONSULT) )
  4746. {
  4747. SendMSPMessage( SP_MSG_InitiateCall, 0, 0, NULL );
  4748. }
  4749. else if( m_dwCallType & CALLTYPE_TRANSFEREDSRC )
  4750. {
  4751. _ASSERTE( m_hdRelatedCall );
  4752. MSPMessageData* pMSPMessageData = new MSPMessageData;
  4753. if( pMSPMessageData == NULL )
  4754. {
  4755. CloseCall( 0 );
  4756. return;
  4757. }
  4758. pMSPMessageData->hdCall = m_hdRelatedCall;
  4759. pMSPMessageData->messageType = SP_MSG_InitiateCall;
  4760. pMSPMessageData->pbEncodedBuf = NULL;
  4761. pMSPMessageData->wLength = 0;
  4762. pMSPMessageData->hReplacementCall = m_hdCall;
  4763. if( !QueueUserWorkItem( SendMSPMessageOnRelatedCall, pMSPMessageData,
  4764. WT_EXECUTEDEFAULT ) )
  4765. {
  4766. delete pMSPMessageData;
  4767. CloseCall( 0 );
  4768. return;
  4769. }
  4770. }
  4771. else
  4772. {
  4773. //send the setup message
  4774. if( !SendSetupMessage() )
  4775. {
  4776. DropCall( 0 );
  4777. }
  4778. }
  4779. H323DBG((DEBUG_LEVEL_TRACE, "OnConnectComplete exited: %p.", this ));
  4780. }
  4781. //!!aleways called in a lock
  4782. BOOL
  4783. CH323Call::SendSetupMessage(void)
  4784. {
  4785. BOOL retVal = TRUE;
  4786. DWORD dwAPDUType = NO_H450_APDU;
  4787. H323DBG((DEBUG_LEVEL_TRACE, "SendSetupMessage entered: %p.", this ));
  4788. //encode ASN.1 and send Q931Setup message to the peer
  4789. if( m_dwCallType & CALLTYPE_FORWARDCONSULT )
  4790. {
  4791. //send the callRerouitng.invoke APDU if this is a forwardconsult call
  4792. retVal = SendQ931Message( NO_INVOKEID,
  4793. (DWORD)create_chosen,
  4794. (DWORD)pointToPoint_chosen,
  4795. SETUPMESSAGETYPE,
  4796. CHECKRESTRICTION_OPCODE| H450_INVOKE );
  4797. if( retVal )
  4798. {
  4799. m_dwStateMachine = Q931_SETUP_SENT;
  4800. m_dwCallDiversionState = H4503_CHECKRESTRICTION_SENT;
  4801. retVal = CreateTimerQueueTimer(
  4802. &m_hCheckRestrictionTimer,
  4803. H323TimerQueue,
  4804. CH323Call::CheckRestrictionTimerCallback,
  4805. (PVOID)m_hdCall,
  4806. CHECKRESTRICTION_EXPIRE_TIME, 0,
  4807. WT_EXECUTEINIOTHREAD | WT_EXECUTEONLYONCE );
  4808. }
  4809. }
  4810. else
  4811. {
  4812. if( ( m_dwCallType & CALLTYPE_DIVERTEDSRC ) ||
  4813. ( m_dwCallType & CALLTYPE_DIVERTEDSRC_NOROUTING ) )
  4814. {
  4815. dwAPDUType = DIVERTINGLEGINFO2_OPCODE | H450_INVOKE;
  4816. }
  4817. else if( m_dwCallType & CALLTYPE_TRANSFEREDSRC )
  4818. {
  4819. dwAPDUType = CTSETUP_OPCODE | H450_INVOKE;
  4820. }
  4821. retVal = SendQ931Message( NO_INVOKEID,
  4822. (DWORD)create_chosen,
  4823. (DWORD)pointToPoint_chosen,
  4824. SETUPMESSAGETYPE,
  4825. dwAPDUType );
  4826. if( retVal )
  4827. {
  4828. m_dwStateMachine = Q931_SETUP_SENT;
  4829. retVal = CreateTimerQueueTimer(
  4830. &m_hSetupSentTimer,
  4831. H323TimerQueue,
  4832. CH323Call::SetupSentTimerCallback,
  4833. (PVOID)m_hdCall,
  4834. SETUP_SENT_TIMEOUT, 0,
  4835. WT_EXECUTEINIOTHREAD | WT_EXECUTEONLYONCE );
  4836. }
  4837. }
  4838. if( retVal == FALSE )
  4839. {
  4840. CloseCall( 0 );
  4841. return FALSE;
  4842. }
  4843. H323DBG((DEBUG_LEVEL_TRACE, "SendSetupMessage exited: %p.", this ));
  4844. return TRUE;
  4845. }
  4846. //!!always called in a lock
  4847. BOOL
  4848. CH323Call::SendProceeding(void)
  4849. {
  4850. H323DBG((DEBUG_LEVEL_TRACE, "SendProceeding entered: %p.", this ));
  4851. _ASSERTE( m_dwOrigin == LINECALLORIGIN_INBOUND );
  4852. //encode ASN.1 and send Q931Setup message to the peer
  4853. if(!SendQ931Message( NO_INVOKEID, 0, 0, PROCEEDINGMESSAGETYPE, NO_H450_APDU ))
  4854. {
  4855. return FALSE;
  4856. }
  4857. m_dwStateMachine = Q931_PROCEED_SENT;
  4858. H323DBG((DEBUG_LEVEL_TRACE, "SendProceeding exited: %p.", this ));
  4859. return TRUE;
  4860. }
  4861. //!!always called in a lock
  4862. BOOL
  4863. CH323Call::PostReadBuffer(void)
  4864. {
  4865. int iError;
  4866. DWORD dwByteReceived = 0;
  4867. BOOL fDelete = FALSE;
  4868. H323DBG((DEBUG_LEVEL_TRACE, "PostReadBuffer entered: %p.", this ));
  4869. m_RecvBuf.Type = OVERLAPPED_TYPE_RECV;
  4870. m_RecvBuf.pCall = this;
  4871. m_RecvBuf.dwFlags = 0;
  4872. m_RecvBuf.BytesTransferred = 0;
  4873. ZeroMemory( (PVOID)&m_RecvBuf.Overlapped, sizeof(OVERLAPPED) );
  4874. //register with winsock for overlappped I/O
  4875. if( WSARecv( m_callSocket,
  4876. &(m_RecvBuf.WSABuf),
  4877. 1,
  4878. &(m_RecvBuf.BytesTransferred),
  4879. &(m_RecvBuf.dwFlags),
  4880. &(m_RecvBuf.Overlapped),
  4881. NULL ) == SOCKET_ERROR )
  4882. {
  4883. iError = WSAGetLastError();
  4884. if( iError != WSA_IO_PENDING )
  4885. {
  4886. //take care of error conditions here
  4887. H323DBG((DEBUG_LEVEL_ERROR, "error while recving buf: %d.",
  4888. iError ));
  4889. return FALSE;
  4890. }
  4891. }
  4892. else
  4893. {
  4894. //There is some data to read!!!!!
  4895. H323DBG(( DEBUG_LEVEL_TRACE, "bytes received immediately: %d.",
  4896. m_RecvBuf.BytesTransferred ));
  4897. }
  4898. m_IoRefCount++;
  4899. H323DBG((DEBUG_LEVEL_TRACE,
  4900. "PostReadBuffer:m_IoRefCount: %d:%p.", m_IoRefCount, this ));
  4901. H323DBG((DEBUG_LEVEL_TRACE, "PostReadBuffer exited: %p.", this ));
  4902. return TRUE;
  4903. }
  4904. //!!always called in a lock
  4905. BOOL
  4906. CH323Call::SendBuffer(
  4907. IN BYTE* pbBuffer,
  4908. IN DWORD dwLength
  4909. )
  4910. {
  4911. int iError;
  4912. CALL_SEND_CONTEXT* pSendBuf = NULL;
  4913. DWORD cbTransfer;
  4914. BOOL fDelete = FALSE;
  4915. H323DBG((DEBUG_LEVEL_TRACE, "SendBuffer entered: %p.", this ));
  4916. if( !(m_dwQ931Flags & Q931_CALL_CONNECTED) )
  4917. {
  4918. goto cleanup;
  4919. }
  4920. pSendBuf = new CALL_SEND_CONTEXT;
  4921. if( pSendBuf == NULL )
  4922. {
  4923. goto cleanup;
  4924. }
  4925. ZeroMemory( (PVOID)pSendBuf, sizeof(CALL_SEND_CONTEXT) );
  4926. pSendBuf->WSABuf.buf = (char*)pbBuffer;
  4927. pSendBuf->WSABuf.len = dwLength;
  4928. pSendBuf->BytesTransferred = 0;
  4929. pSendBuf->pCall = this;
  4930. pSendBuf->Type = OVERLAPPED_TYPE_SEND;
  4931. InsertTailList( &m_sendBufList, &(pSendBuf ->ListEntry) );
  4932. if( WSASend(m_callSocket,
  4933. &(pSendBuf->WSABuf),
  4934. 1,
  4935. &(pSendBuf->BytesTransferred),
  4936. 0,
  4937. &(pSendBuf->Overlapped),
  4938. NULL) == SOCKET_ERROR )
  4939. {
  4940. iError = WSAGetLastError();
  4941. if( iError != WSA_IO_PENDING )
  4942. {
  4943. H323DBG((DEBUG_LEVEL_TRACE, "error sending the buf: %lx.", iError));
  4944. RemoveEntryList( &pSendBuf->ListEntry );
  4945. goto cleanup;
  4946. }
  4947. }
  4948. else
  4949. {
  4950. //data was sent immediately!!!
  4951. H323DBG((DEBUG_LEVEL_TRACE, "data sent immediately!!." ));
  4952. }
  4953. m_IoRefCount++;
  4954. H323DBG((DEBUG_LEVEL_TRACE, "SendBuffer:m_IoRefCount11: %d:%p.",
  4955. m_IoRefCount, this ));
  4956. H323DBG((DEBUG_LEVEL_TRACE, "SendBuffer exited: %p.", this ));
  4957. return TRUE;
  4958. cleanup:
  4959. if(pSendBuf)
  4960. {
  4961. delete pSendBuf;
  4962. }
  4963. delete pbBuffer;
  4964. return FALSE;
  4965. }
  4966. //!!aleways called in a lock
  4967. BOOL
  4968. CH323Call::SetupCall(void)
  4969. {
  4970. SOCKET Q931CallSocket = INVALID_SOCKET;
  4971. SOCKADDR_IN sin;
  4972. HANDLE hWSAEvent;
  4973. HANDLE hConnWait;
  4974. BOOL fSuccess = TRUE;
  4975. int iError;
  4976. BOOL fDelete;
  4977. DWORD dwEnable = 1;
  4978. TCHAR ptstrEventName[100];
  4979. H323DBG((DEBUG_LEVEL_TRACE, "SetupCall entered."));
  4980. //create a socket
  4981. Q931CallSocket = WSASocket(
  4982. AF_INET,
  4983. SOCK_STREAM,
  4984. IPPROTO_IP,
  4985. NULL,
  4986. NULL,
  4987. WSA_FLAG_OVERLAPPED );
  4988. if( Q931CallSocket == INVALID_SOCKET )
  4989. {
  4990. H323DBG((DEBUG_LEVEL_ERROR, "error while creating socket: %lx.",
  4991. WSAGetLastError() ));
  4992. goto error1;
  4993. }
  4994. //create a new Q931 call object
  4995. if( InitializeQ931(Q931CallSocket) == NULL )
  4996. {
  4997. goto error2;
  4998. }
  4999. _stprintf( ptstrEventName, _T("%s-%p") ,
  5000. _T( "H323TSP_OutgoingCall_TransportHandlerEvent" ), this );
  5001. //create the wait event
  5002. hWSAEvent = H323CreateEvent( NULL, FALSE,
  5003. FALSE, ptstrEventName );
  5004. if( hWSAEvent == NULL )
  5005. {
  5006. H323DBG((DEBUG_LEVEL_ERROR, "couldn't create wsaevent" ));
  5007. goto error3;
  5008. }
  5009. //register with thread pool the event handle and handler proc
  5010. fSuccess = RegisterWaitForSingleObject(
  5011. &hConnWait, // pointer to the returned handle
  5012. hWSAEvent, // the event handle to wait for.
  5013. Q931TransportEventHandler, // the callback function.
  5014. (PVOID)m_hdCall, // the context for the callback.
  5015. INFINITE, // wait forever.
  5016. // probably don't need this flag set
  5017. WT_EXECUTEDEFAULT // use the wait thread to call the callback.
  5018. );
  5019. if ( ( !fSuccess ) || (hConnWait== NULL) )
  5020. {
  5021. GetLastError();
  5022. if( !CloseHandle( hWSAEvent ) )
  5023. {
  5024. H323DBG((DEBUG_LEVEL_ERROR, "couldn't close wsaevent" ));
  5025. }
  5026. goto error3;
  5027. }
  5028. //store this in the call context
  5029. SetNewCallInfo( hConnWait, hWSAEvent, Q931_CALL_CONNECTING );
  5030. //register with Winsock the event handle and the events
  5031. if( WSAEventSelect( Q931CallSocket,
  5032. hWSAEvent,
  5033. FD_CONNECT | FD_CLOSE
  5034. ) == SOCKET_ERROR )
  5035. {
  5036. H323DBG((DEBUG_LEVEL_ERROR,
  5037. "error selecting event outgoing call: %lx.", WSAGetLastError()));
  5038. goto error3;
  5039. }
  5040. if( setsockopt( Q931CallSocket,
  5041. IPPROTO_TCP,
  5042. TCP_NODELAY,
  5043. (char*)&dwEnable,
  5044. sizeof(DWORD)
  5045. ) == SOCKET_ERROR )
  5046. {
  5047. H323DBG(( DEBUG_LEVEL_WARNING,
  5048. "Couldn't set NODELAY option on outgoing call socket:%d, %p",
  5049. WSAGetLastError(), this ));
  5050. }
  5051. //set the address structure
  5052. memset( (PVOID)&sin, 0, sizeof(SOCKADDR_IN) );
  5053. sin.sin_family = AF_INET;
  5054. sin.sin_addr.s_addr = htonl( m_CalleeAddr.Addr.IP_Binary.dwAddr );
  5055. sin.sin_port = htons( m_CalleeAddr.Addr.IP_Binary.wPort );
  5056. //make the winsock connection
  5057. if( WSAConnect( Q931CallSocket,
  5058. (sockaddr*)&sin,
  5059. sizeof(SOCKADDR_IN),
  5060. NULL, NULL, NULL, NULL
  5061. )
  5062. == SOCKET_ERROR )
  5063. {
  5064. iError = WSAGetLastError();
  5065. if(iError != WSAEWOULDBLOCK )
  5066. {
  5067. H323DBG(( DEBUG_LEVEL_ERROR,
  5068. "error while connecting socket: %lx.", iError ));
  5069. goto error3;
  5070. }
  5071. }
  5072. else
  5073. { //connection went through immediately!!!
  5074. OnConnectComplete();
  5075. }
  5076. //success
  5077. H323DBG((DEBUG_LEVEL_TRACE, "SetupCall exited."));
  5078. return TRUE;
  5079. error3:
  5080. Unlock();
  5081. Shutdown( &fDelete );
  5082. Lock();
  5083. error2:
  5084. closesocket( Q931CallSocket );
  5085. error1:
  5086. return FALSE;
  5087. }
  5088. //!!aleways called in a lock
  5089. BOOL
  5090. CH323Call::AcceptH323Call(void)
  5091. {
  5092. DWORD dwAPDUType = NO_H450_APDU;
  5093. DWORD dwInvokeID = NO_INVOKEID;
  5094. H323DBG((DEBUG_LEVEL_TRACE, "AcceptH323Call entered: %p.", this ));
  5095. if( m_dwCallType & CALLTYPE_DIVERTEDDEST )
  5096. {
  5097. dwAPDUType = (DIVERTINGLEGINFO3_OPCODE | H450_INVOKE);
  5098. }
  5099. else if( m_dwCallType & CALLTYPE_TRANSFEREDDEST )
  5100. {
  5101. dwAPDUType = (CTSETUP_OPCODE | H450_RETURNRESULT);
  5102. dwInvokeID = m_dwInvokeID;
  5103. }
  5104. ChangeCallState( LINECALLSTATE_ACCEPTED, 0 );
  5105. //if pCall Divert On No Answer is enabled, then stop the timer
  5106. if( m_hCallDivertOnNATimer )
  5107. {
  5108. DeleteTimerQueueTimer( H323TimerQueue, m_hCallDivertOnNATimer, NULL );
  5109. m_hCallDivertOnNATimer = NULL;
  5110. }
  5111. //encode and send Q931Connect message to the peer
  5112. if( !SendQ931Message( dwInvokeID, 0, 0, CONNECTMESSAGETYPE, dwAPDUType ) )
  5113. {
  5114. //post a message to the callback thread to shutdown the H323 call
  5115. CloseCall( 0 );
  5116. return FALSE;
  5117. }
  5118. m_dwStateMachine = Q931_CONNECT_SENT;
  5119. H323DBG((DEBUG_LEVEL_TRACE, "AcceptH323Call exited: %p.", this ));
  5120. return TRUE;
  5121. }
  5122. //!!always called in a lock
  5123. BOOL
  5124. CH323Call::SendQ931Message(
  5125. IN DWORD dwInvokeID,
  5126. IN ULONG_PTR dwParam1,
  5127. IN ULONG_PTR dwParam2,
  5128. IN DWORD dwMessageType,
  5129. IN DWORD dwAPDUType
  5130. )
  5131. {
  5132. BINARY_STRING userUserData;
  5133. DWORD dwCodedLengthPDU;
  5134. BYTE *pbCodedPDU;
  5135. BOOL retVal = FALSE;
  5136. WCHAR * pwszCalledPartyNumber = NULL;
  5137. H323DBG((DEBUG_LEVEL_TRACE, "SendQ931Message entered: %p.", this ));
  5138. //check if socket is connected
  5139. if( !(m_dwQ931Flags & Q931_CALL_CONNECTED) )
  5140. {
  5141. return FALSE;
  5142. }
  5143. switch ( dwMessageType )
  5144. {
  5145. //encode the UU message
  5146. case SETUPMESSAGETYPE:
  5147. retVal = EncodeSetupMessage( dwInvokeID, (WORD)dwParam1, //dwGoal
  5148. (WORD)dwParam2, //dwCalType
  5149. &userUserData.pbBuffer,
  5150. &userUserData.length,
  5151. dwAPDUType );
  5152. break;
  5153. case ALERTINGMESSAGETYPE:
  5154. retVal = EncodeAlertMessage( dwInvokeID,
  5155. &userUserData.pbBuffer,
  5156. &userUserData.length,
  5157. dwAPDUType );
  5158. break;
  5159. case PROCEEDINGMESSAGETYPE:
  5160. retVal = EncodeProceedingMessage( dwInvokeID,
  5161. &userUserData.pbBuffer,
  5162. &userUserData.length,
  5163. dwAPDUType );
  5164. break;
  5165. case RELEASECOMPLMESSAGETYPE:
  5166. retVal = EncodeReleaseCompleteMessage( dwInvokeID,
  5167. (BYTE*)dwParam1, //pbReason
  5168. &userUserData.pbBuffer,
  5169. &userUserData.length,
  5170. dwAPDUType );
  5171. break;
  5172. case CONNECTMESSAGETYPE:
  5173. retVal = EncodeConnectMessage( dwInvokeID,
  5174. &userUserData.pbBuffer,
  5175. &userUserData.length,
  5176. dwAPDUType );
  5177. break;
  5178. case FACILITYMESSAGETYPE:
  5179. retVal = EncodeFacilityMessage( dwInvokeID,
  5180. (BYTE)dwParam1,
  5181. (ASN1octetstring_t*)dwParam2,
  5182. &userUserData.pbBuffer,
  5183. &userUserData.length,
  5184. dwAPDUType );
  5185. break;
  5186. }
  5187. if( retVal == FALSE )
  5188. {
  5189. H323DBG(( DEBUG_LEVEL_ERROR,
  5190. "could not encode message:%d.", dwMessageType));
  5191. if( userUserData.pbBuffer )
  5192. {
  5193. ASN1_FreeEncoded(m_ASNCoderInfo.pEncInfo, userUserData.pbBuffer );
  5194. }
  5195. return FALSE;
  5196. }
  5197. if (m_dwAddressType == LINEADDRESSTYPE_PHONENUMBER)
  5198. {
  5199. _ASSERTE( m_pCalleeAliasNames->pItems[0].wType == e164_chosen );
  5200. pwszCalledPartyNumber = m_pCalleeAliasNames ->pItems[0].pData;
  5201. }
  5202. //encode the PDU
  5203. retVal = EncodePDU( &userUserData,
  5204. &pbCodedPDU,
  5205. &dwCodedLengthPDU,
  5206. dwMessageType,
  5207. pwszCalledPartyNumber );
  5208. if( retVal == FALSE )
  5209. {
  5210. H323DBG(( DEBUG_LEVEL_ERROR,
  5211. "could not encode PDU: %d.", dwMessageType ));
  5212. }
  5213. else if(!SendBuffer( pbCodedPDU, dwCodedLengthPDU ))
  5214. {
  5215. retVal = FALSE;
  5216. }
  5217. if( userUserData.pbBuffer )
  5218. {
  5219. ASN1_FreeEncoded(m_ASNCoderInfo.pEncInfo, userUserData.pbBuffer );
  5220. }
  5221. H323DBG((DEBUG_LEVEL_TRACE, "SendQ931Message exited: %p.", this ));
  5222. return retVal;
  5223. }
  5224. //!!always called in a lock
  5225. BOOL
  5226. CH323Call::EncodeFastStartProposal(
  5227. PH323_FASTSTART pFastStart,
  5228. BYTE** ppEncodedBuf,
  5229. WORD* pwEncodedLength
  5230. )
  5231. {
  5232. int rc;
  5233. H323_UserInformation UserInfo;
  5234. H323DBG((DEBUG_LEVEL_TRACE, "EncodeFastStartProposal entered: %p.", this ));
  5235. CallProceeding_UUIE & proceedingMessage =
  5236. UserInfo.h323_uu_pdu.h323_message_body.u.callProceeding;
  5237. *ppEncodedBuf = NULL;
  5238. *pwEncodedLength = 0;
  5239. memset( (PVOID)&UserInfo, 0, sizeof(H323_UserInformation));
  5240. UserInfo.bit_mask = 0;
  5241. //copy the call identifier
  5242. proceedingMessage.bit_mask |= CallProceeding_UUIE_callIdentifier_present;
  5243. CopyMemory( (PVOID)&proceedingMessage.callIdentifier.guid.value,
  5244. (PVOID)&m_callIdentifier,
  5245. sizeof(GUID) );
  5246. proceedingMessage.callIdentifier.guid.length = sizeof(GUID);
  5247. // make sure the user_data_present flag is turned off.
  5248. UserInfo.bit_mask &= (~user_data_present);
  5249. UserInfo.h323_uu_pdu.bit_mask = 0;
  5250. UserInfo.h323_uu_pdu.h323_message_body.choice = callProceeding_chosen;
  5251. proceedingMessage.protocolIdentifier = OID_H225ProtocolIdentifierV2;
  5252. proceedingMessage.bit_mask |= CallProceeding_UUIE_fastStart_present;
  5253. proceedingMessage.fastStart = (PCallProceeding_UUIE_fastStart)pFastStart;
  5254. rc = EncodeASN( (void *) &UserInfo,
  5255. H323_UserInformation_PDU,
  5256. ppEncodedBuf,
  5257. pwEncodedLength);
  5258. if (ASN1_FAILED(rc) || (*ppEncodedBuf == NULL) || (pwEncodedLength == 0) )
  5259. {
  5260. return FALSE;
  5261. }
  5262. H323DBG((DEBUG_LEVEL_TRACE, "EncodeFastStartProposal exited: %p.", this ));
  5263. //success
  5264. return TRUE;
  5265. }
  5266. //!!always called in a lock
  5267. BOOL
  5268. CH323Call::EncodeFacilityMessage(
  5269. IN DWORD dwInvokeID,
  5270. IN BYTE bReason,
  5271. IN ASN1octetstring_t* pH245PDU,
  5272. OUT BYTE **ppEncodedBuf,
  5273. OUT WORD *pdwEncodedLength,
  5274. IN DWORD dwAPDUType
  5275. )
  5276. {
  5277. H323_UU_PDU_h4501SupplementaryService h4501APDU;
  5278. int rc;
  5279. H323_UserInformation UserInfo;
  5280. DWORD dwAPDULen = 0;
  5281. BYTE* pEncodedAPDU = NULL;
  5282. H323DBG((DEBUG_LEVEL_TRACE, "EncodeFacilityMessage entered: %p.", this ));
  5283. Facility_UUIE & facilityMessage =
  5284. UserInfo.h323_uu_pdu.h323_message_body.u.facility;
  5285. *ppEncodedBuf = NULL;
  5286. *pdwEncodedLength = 0;
  5287. memset( (PVOID)&UserInfo, 0, sizeof(H323_UserInformation));
  5288. UserInfo.bit_mask = 0;
  5289. // make sure the user_data_present flag is turned off.
  5290. UserInfo.bit_mask &= (~user_data_present);
  5291. UserInfo.h323_uu_pdu.bit_mask = 0;
  5292. //send the appropriate ADPDUS
  5293. if( dwAPDUType != NO_H450_APDU )
  5294. {
  5295. if( !EncodeH450APDU(dwInvokeID, dwAPDUType,
  5296. &pEncodedAPDU, &dwAPDULen ) )
  5297. {
  5298. return FALSE;
  5299. }
  5300. UserInfo.h323_uu_pdu.h4501SupplementaryService = &h4501APDU;
  5301. UserInfo.h323_uu_pdu.h4501SupplementaryService -> next = NULL;
  5302. UserInfo.h323_uu_pdu.h4501SupplementaryService -> value.value = pEncodedAPDU;
  5303. UserInfo.h323_uu_pdu.h4501SupplementaryService -> value.length = dwAPDULen;
  5304. UserInfo.h323_uu_pdu.bit_mask |= h4501SupplementaryService_present;
  5305. }
  5306. UserInfo.h323_uu_pdu.h245Tunneling = FALSE;//(m_fh245Tunneling & LOCAL_H245_TUNNELING);
  5307. UserInfo.h323_uu_pdu.bit_mask |= h245Tunneling_present;
  5308. SetNonStandardData( UserInfo );
  5309. UserInfo.h323_uu_pdu.h323_message_body.choice = facility_chosen;
  5310. facilityMessage.protocolIdentifier = OID_H225ProtocolIdentifierV2;
  5311. facilityMessage.bit_mask = 0;
  5312. TransportAddress& transportAddress = facilityMessage.alternativeAddress;
  5313. if( IsGuidSet( &m_ConferenceID ) )
  5314. {
  5315. CopyConferenceID(&facilityMessage.conferenceID, &m_ConferenceID);
  5316. facilityMessage.bit_mask |= Facility_UUIE_conferenceID_present;
  5317. }
  5318. switch (bReason)
  5319. {
  5320. case H323_REJECT_ROUTE_TO_GATEKEEPER:
  5321. facilityMessage.reason.choice =
  5322. FacilityReason_routeCallToGatekeeper_chosen;
  5323. break;
  5324. case H323_REJECT_CALL_FORWARDED:
  5325. facilityMessage.reason.choice = callForwarded_chosen;
  5326. break;
  5327. case H323_REJECT_ROUTE_TO_MC:
  5328. facilityMessage.reason.choice = routeCallToMC_chosen;
  5329. break;
  5330. default:
  5331. facilityMessage.reason.choice = FacilityReason_undefinedReason_chosen;
  5332. }
  5333. facilityMessage.bit_mask |= Facility_UUIE_callIdentifier_present;
  5334. CopyMemory( (PVOID)&facilityMessage.callIdentifier.guid.value,
  5335. (PVOID)"abcdabcdabcdabcdabcd",
  5336. sizeof(GUID) );
  5337. facilityMessage.callIdentifier.guid.length = sizeof(GUID);
  5338. if( pH245PDU && (pH245PDU->value != NULL) )
  5339. {
  5340. //h245 PDU to be sent
  5341. UserInfo.h323_uu_pdu.h245Control->next = NULL;
  5342. UserInfo.h323_uu_pdu.h245Control->value.length = pH245PDU->length;
  5343. UserInfo.h323_uu_pdu.h245Control->value.value = pH245PDU->value;
  5344. }
  5345. rc = EncodeASN((void *) &UserInfo,
  5346. H323_UserInformation_PDU,
  5347. ppEncodedBuf,
  5348. pdwEncodedLength);
  5349. if( ASN1_FAILED(rc) || (*ppEncodedBuf == NULL) || (pdwEncodedLength == 0) )
  5350. {
  5351. if( pEncodedAPDU != NULL )
  5352. {
  5353. ASN1_FreeEncoded(m_H450ASNCoderInfo.pEncInfo, pEncodedAPDU );
  5354. }
  5355. return FALSE;
  5356. }
  5357. if( pEncodedAPDU != NULL )
  5358. {
  5359. ASN1_FreeEncoded(m_H450ASNCoderInfo.pEncInfo, pEncodedAPDU );
  5360. }
  5361. H323DBG((DEBUG_LEVEL_TRACE, "EncodeFacilityMessage exited: %p.", this ));
  5362. //success
  5363. return TRUE;
  5364. }
  5365. //!!always called in a lock
  5366. BOOL
  5367. CH323Call::EncodeAlertMessage(
  5368. IN DWORD dwInvokeID,
  5369. OUT BYTE **ppEncodedBuf,
  5370. OUT WORD *pdwEncodedLength,
  5371. IN DWORD dwAPDUType
  5372. )
  5373. {
  5374. H323_UU_PDU_h4501SupplementaryService h4501APDU;
  5375. int rc;
  5376. H323_UserInformation UserInfo;
  5377. DWORD dwAPDULen = 0;
  5378. BYTE* pEncodedAPDU = NULL;
  5379. H323DBG(( DEBUG_LEVEL_TRACE, "EncodeAlertMessage entered: %p.", this ));
  5380. Alerting_UUIE & alertingMessage =
  5381. UserInfo.h323_uu_pdu.h323_message_body.u.alerting;
  5382. *ppEncodedBuf = NULL;
  5383. *pdwEncodedLength = 0;
  5384. memset( (PVOID)&UserInfo, 0, sizeof(H323_UserInformation));
  5385. UserInfo.bit_mask = 0;
  5386. // make sure the user_data_present flag is turned off.
  5387. UserInfo.bit_mask &= (~user_data_present);
  5388. UserInfo.h323_uu_pdu.bit_mask = 0;
  5389. if( dwAPDUType != NO_H450_APDU )
  5390. {
  5391. if( !EncodeH450APDU( dwInvokeID, dwAPDUType, &pEncodedAPDU, &dwAPDULen ) )
  5392. {
  5393. return FALSE;
  5394. }
  5395. UserInfo.h323_uu_pdu.h4501SupplementaryService = &h4501APDU;
  5396. UserInfo.h323_uu_pdu.h4501SupplementaryService -> next = NULL;
  5397. UserInfo.h323_uu_pdu.h4501SupplementaryService -> value.value = pEncodedAPDU;
  5398. UserInfo.h323_uu_pdu.h4501SupplementaryService -> value.length = dwAPDULen;
  5399. UserInfo.h323_uu_pdu.bit_mask |= h4501SupplementaryService_present;
  5400. }
  5401. UserInfo.h323_uu_pdu.h245Tunneling = FALSE;//(m_fh245Tunneling & LOCAL_H245_TUNNELING);
  5402. UserInfo.h323_uu_pdu.bit_mask |= h245Tunneling_present;
  5403. SetNonStandardData( UserInfo );
  5404. UserInfo.h323_uu_pdu.h323_message_body.choice = alerting_chosen;
  5405. alertingMessage.protocolIdentifier = OID_H225ProtocolIdentifierV2;
  5406. alertingMessage.destinationInfo.bit_mask = 0;
  5407. //copy the vendor info
  5408. alertingMessage.destinationInfo.bit_mask |= vendor_present;
  5409. CopyVendorInfo( &alertingMessage.destinationInfo.vendor );
  5410. //its a terminal
  5411. alertingMessage.destinationInfo.bit_mask = terminal_present;
  5412. alertingMessage.destinationInfo.terminal.bit_mask = 0;
  5413. //not na MC
  5414. alertingMessage.destinationInfo.mc = 0;
  5415. alertingMessage.destinationInfo.undefinedNode = 0;
  5416. TransportAddress& transportAddress = alertingMessage.h245Address;
  5417. //send H245 address only if the caller hasn't proposed FasrStart
  5418. //or the fast start proposal has been accepeted
  5419. if( (m_pPeerFastStart == NULL) || m_pFastStart )
  5420. {
  5421. if( m_selfH245Addr.Addr.IP_Binary.dwAddr != 0 )
  5422. {
  5423. CopyTransportAddress( transportAddress, &m_selfH245Addr );
  5424. alertingMessage.bit_mask |= (Alerting_UUIE_h245Address_present);
  5425. }
  5426. else
  5427. {
  5428. alertingMessage.bit_mask &= (~Alerting_UUIE_h245Address_present);
  5429. }
  5430. }
  5431. if( m_pFastStart != NULL )
  5432. {
  5433. _ASSERTE( m_pPeerFastStart );
  5434. alertingMessage.bit_mask |= Alerting_UUIE_fastStart_present;
  5435. alertingMessage.fastStart = (PAlerting_UUIE_fastStart)m_pFastStart;
  5436. }
  5437. else
  5438. {
  5439. alertingMessage.bit_mask &= ~Alerting_UUIE_fastStart_present;
  5440. }
  5441. //copy the call identifier
  5442. alertingMessage.bit_mask |= Alerting_UUIE_callIdentifier_present;
  5443. CopyMemory( (PVOID)&alertingMessage.callIdentifier.guid.value,
  5444. (PVOID)&m_callIdentifier,
  5445. sizeof(GUID) );
  5446. alertingMessage.callIdentifier.guid.length = sizeof(GUID);
  5447. rc = EncodeASN( (void *) &UserInfo,
  5448. H323_UserInformation_PDU,
  5449. ppEncodedBuf,
  5450. pdwEncodedLength);
  5451. if (ASN1_FAILED(rc) || (*ppEncodedBuf == NULL) || (pdwEncodedLength == 0) )
  5452. {
  5453. if( pEncodedAPDU != NULL )
  5454. {
  5455. ASN1_FreeEncoded(m_H450ASNCoderInfo.pEncInfo, pEncodedAPDU );
  5456. }
  5457. return FALSE;
  5458. }
  5459. if( pEncodedAPDU != NULL )
  5460. {
  5461. ASN1_FreeEncoded(m_H450ASNCoderInfo.pEncInfo, pEncodedAPDU );
  5462. }
  5463. H323DBG((DEBUG_LEVEL_TRACE, "EncodeAlertMessage exited: %p.", this ));
  5464. //success
  5465. return TRUE;
  5466. }
  5467. //!!always called in a lock
  5468. BOOL
  5469. CH323Call::EncodeProceedingMessage(
  5470. IN DWORD dwInvokeID,
  5471. OUT BYTE **ppEncodedBuf,
  5472. OUT WORD *pdwEncodedLength,
  5473. IN DWORD dwAPDUType
  5474. )
  5475. {
  5476. H323_UU_PDU_h4501SupplementaryService h4501APDU;
  5477. int rc;
  5478. H323_UserInformation UserInfo;
  5479. DWORD dwAPDULen = 0;
  5480. BYTE* pEncodedAPDU = NULL;
  5481. H323DBG((DEBUG_LEVEL_TRACE, "EncodeProceedingMessage entered: %p.", this ));
  5482. CallProceeding_UUIE & proceedingMessage =
  5483. UserInfo.h323_uu_pdu.h323_message_body.u.callProceeding;
  5484. *ppEncodedBuf = NULL;
  5485. *pdwEncodedLength = 0;
  5486. memset( (PVOID)&UserInfo, 0, sizeof(H323_UserInformation));
  5487. UserInfo.bit_mask = 0;
  5488. // make sure the user_data_present flag is turned off.
  5489. UserInfo.bit_mask &= (~user_data_present);
  5490. UserInfo.h323_uu_pdu.bit_mask = 0;
  5491. if( dwAPDUType != NO_H450_APDU )
  5492. {
  5493. if( !EncodeH450APDU( dwInvokeID, dwAPDUType, &pEncodedAPDU, &dwAPDULen ) )
  5494. {
  5495. return FALSE;
  5496. }
  5497. UserInfo.h323_uu_pdu.h4501SupplementaryService = &h4501APDU;
  5498. UserInfo.h323_uu_pdu.h4501SupplementaryService -> next = NULL;
  5499. UserInfo.h323_uu_pdu.h4501SupplementaryService -> value.value = pEncodedAPDU;
  5500. UserInfo.h323_uu_pdu.h4501SupplementaryService -> value.length = dwAPDULen;
  5501. UserInfo.h323_uu_pdu.bit_mask |= h4501SupplementaryService_present;
  5502. }
  5503. UserInfo.h323_uu_pdu.h245Tunneling = FALSE;//(m_fh245Tunneling & LOCAL_H245_TUNNELING);
  5504. UserInfo.h323_uu_pdu.bit_mask |= h245Tunneling_present;
  5505. SetNonStandardData( UserInfo );
  5506. UserInfo.h323_uu_pdu.h323_message_body.choice = callProceeding_chosen;
  5507. proceedingMessage.protocolIdentifier = OID_H225ProtocolIdentifierV2;
  5508. TransportAddress& transportAddress = proceedingMessage.h245Address;
  5509. //send H245 address only if the caller hasn't proposed FasrStart
  5510. //or the fast start proposal has been accepeted
  5511. if( (m_pPeerFastStart == NULL) || m_pFastStart )
  5512. {
  5513. if( m_selfH245Addr.Addr.IP_Binary.dwAddr != 0 )
  5514. {
  5515. CopyTransportAddress( transportAddress, &m_selfH245Addr );
  5516. proceedingMessage.bit_mask |= CallProceeding_UUIE_h245Address_present;
  5517. }
  5518. else
  5519. {
  5520. proceedingMessage.bit_mask &= ~CallProceeding_UUIE_h245Address_present;
  5521. }
  5522. }
  5523. proceedingMessage.destinationInfo.bit_mask = 0;
  5524. //copy the vendor info
  5525. proceedingMessage.destinationInfo.bit_mask |= vendor_present;
  5526. CopyVendorInfo( &proceedingMessage.destinationInfo.vendor );
  5527. proceedingMessage.destinationInfo.mc = 0;
  5528. proceedingMessage.destinationInfo.undefinedNode = 0;
  5529. if( m_pFastStart != NULL )
  5530. {
  5531. _ASSERTE( m_pPeerFastStart );
  5532. proceedingMessage.bit_mask |= Alerting_UUIE_fastStart_present;
  5533. proceedingMessage.fastStart =
  5534. (PCallProceeding_UUIE_fastStart)m_pFastStart;
  5535. }
  5536. else
  5537. {
  5538. proceedingMessage.bit_mask &= ~Alerting_UUIE_fastStart_present;
  5539. }
  5540. //copy the call identifier
  5541. proceedingMessage.bit_mask |= CallProceeding_UUIE_callIdentifier_present;
  5542. CopyMemory( (PVOID)&proceedingMessage.callIdentifier.guid.value,
  5543. (PVOID)&m_callIdentifier,
  5544. sizeof(GUID) );
  5545. proceedingMessage.callIdentifier.guid.length = sizeof(GUID);
  5546. rc = EncodeASN( (void *) &UserInfo,
  5547. H323_UserInformation_PDU,
  5548. ppEncodedBuf,
  5549. pdwEncodedLength);
  5550. if (ASN1_FAILED(rc) || (*ppEncodedBuf == NULL) || (pdwEncodedLength == 0) )
  5551. {
  5552. if( pEncodedAPDU != NULL )
  5553. {
  5554. ASN1_FreeEncoded(m_H450ASNCoderInfo.pEncInfo, pEncodedAPDU );
  5555. }
  5556. return FALSE;
  5557. }
  5558. if( pEncodedAPDU != NULL )
  5559. {
  5560. ASN1_FreeEncoded(m_H450ASNCoderInfo.pEncInfo, pEncodedAPDU );
  5561. }
  5562. H323DBG((DEBUG_LEVEL_TRACE, "EncodeProceedingMessage exited: %p.", this ));
  5563. //success
  5564. return TRUE;
  5565. }
  5566. //!!always called in a lock
  5567. BOOL
  5568. CH323Call::EncodeReleaseCompleteMessage(
  5569. IN DWORD dwInvokeID,
  5570. IN BYTE *pbReason,
  5571. OUT BYTE **ppEncodedBuf,
  5572. OUT WORD *pdwEncodedLength,
  5573. IN DWORD dwAPDUType
  5574. )
  5575. {
  5576. H323_UU_PDU_h4501SupplementaryService h4501APDU;
  5577. int rc;
  5578. H323_UserInformation UserInfo;
  5579. DWORD dwAPDULen = 0;
  5580. BYTE* pEncodedAPDU = NULL;
  5581. H323DBG((DEBUG_LEVEL_TRACE, "EncodeReleaseCompleteMessage entered: %p.", this ));
  5582. ReleaseComplete_UUIE & releaseMessage =
  5583. UserInfo.h323_uu_pdu.h323_message_body.u.releaseComplete;
  5584. *ppEncodedBuf = NULL;
  5585. *pdwEncodedLength = 0;
  5586. memset( (PVOID)&UserInfo, 0, sizeof(H323_UserInformation));
  5587. UserInfo.bit_mask = 0;
  5588. // make sure the user_data_present flag is turned off.
  5589. UserInfo.bit_mask &= (~user_data_present);
  5590. UserInfo.h323_uu_pdu.bit_mask = 0;
  5591. if( dwAPDUType != NO_H450_APDU )
  5592. {
  5593. if( !EncodeH450APDU( dwInvokeID, dwAPDUType, &pEncodedAPDU, &dwAPDULen ) )
  5594. {
  5595. return FALSE;
  5596. }
  5597. UserInfo.h323_uu_pdu.h4501SupplementaryService = &h4501APDU;
  5598. UserInfo.h323_uu_pdu.h4501SupplementaryService -> next = NULL;
  5599. UserInfo.h323_uu_pdu.h4501SupplementaryService -> value.value = pEncodedAPDU;
  5600. UserInfo.h323_uu_pdu.h4501SupplementaryService -> value.length = dwAPDULen;
  5601. UserInfo.h323_uu_pdu.bit_mask |= h4501SupplementaryService_present;
  5602. }
  5603. SetNonStandardData( UserInfo );
  5604. UserInfo.h323_uu_pdu.h323_message_body.choice = releaseComplete_chosen;
  5605. releaseMessage.protocolIdentifier = OID_H225ProtocolIdentifierV2;
  5606. if( pbReason )
  5607. {
  5608. releaseMessage.reason.choice = 0;
  5609. releaseMessage.bit_mask |= (ReleaseComplete_UUIE_reason_present);
  5610. switch (*pbReason)
  5611. {
  5612. case H323_REJECT_NO_BANDWIDTH:
  5613. releaseMessage.reason.choice = noBandwidth_chosen;
  5614. break;
  5615. case H323_REJECT_GATEKEEPER_RESOURCES:
  5616. releaseMessage.reason.choice = gatekeeperResources_chosen;
  5617. break;
  5618. case H323_REJECT_UNREACHABLE_DESTINATION:
  5619. releaseMessage.reason.choice = unreachableDestination_chosen;
  5620. break;
  5621. case H323_REJECT_DESTINATION_REJECTION:
  5622. releaseMessage.reason.choice = destinationRejection_chosen;
  5623. break;
  5624. case H323_REJECT_INVALID_REVISION:
  5625. releaseMessage.reason.choice
  5626. = ReleaseCompleteReason_invalidRevision_chosen;
  5627. break;
  5628. case H323_REJECT_NO_PERMISSION:
  5629. releaseMessage.reason.choice = noPermission_chosen;
  5630. break;
  5631. case H323_REJECT_UNREACHABLE_GATEKEEPER:
  5632. releaseMessage.reason.choice = unreachableGatekeeper_chosen;
  5633. break;
  5634. case H323_REJECT_GATEWAY_RESOURCES:
  5635. releaseMessage.reason.choice = gatewayResources_chosen;
  5636. break;
  5637. case H323_REJECT_BAD_FORMAT_ADDRESS:
  5638. releaseMessage.reason.choice = badFormatAddress_chosen;
  5639. break;
  5640. case H323_REJECT_ADAPTIVE_BUSY:
  5641. releaseMessage.reason.choice = adaptiveBusy_chosen;
  5642. break;
  5643. case H323_REJECT_IN_CONF:
  5644. releaseMessage.reason.choice = inConf_chosen;
  5645. break;
  5646. case H323_REJECT_CALL_DEFLECTION:
  5647. releaseMessage.reason.choice =
  5648. ReleaseCompleteReason_undefinedReason_chosen ;
  5649. break;
  5650. case H323_REJECT_UNDEFINED_REASON:
  5651. releaseMessage.reason.choice = ReleaseCompleteReason_undefinedReason_chosen ;
  5652. break;
  5653. case H323_REJECT_USER_BUSY:
  5654. releaseMessage.reason.choice = inConf_chosen;
  5655. break;
  5656. default:
  5657. //log
  5658. if( pEncodedAPDU != NULL )
  5659. {
  5660. ASN1_FreeEncoded(m_H450ASNCoderInfo.pEncInfo, pEncodedAPDU );
  5661. }
  5662. return FALSE;
  5663. }
  5664. }
  5665. rc = EncodeASN( (void *) &UserInfo,
  5666. H323_UserInformation_PDU,
  5667. ppEncodedBuf,
  5668. pdwEncodedLength);
  5669. if (ASN1_FAILED(rc) || (*ppEncodedBuf == NULL) || (pdwEncodedLength == 0) )
  5670. {
  5671. if( pEncodedAPDU != NULL )
  5672. {
  5673. ASN1_FreeEncoded(m_H450ASNCoderInfo.pEncInfo, pEncodedAPDU );
  5674. }
  5675. return FALSE;
  5676. }
  5677. if( pEncodedAPDU != NULL )
  5678. {
  5679. ASN1_FreeEncoded(m_H450ASNCoderInfo.pEncInfo, pEncodedAPDU );
  5680. }
  5681. H323DBG((DEBUG_LEVEL_TRACE, "EncodeReleaseCompleteMessage exited: %p.", this ));
  5682. //success
  5683. return TRUE;
  5684. }
  5685. //!!always called in a lock
  5686. BOOL
  5687. CH323Call::EncodeConnectMessage(
  5688. IN DWORD dwInvokeID,
  5689. OUT BYTE **ppEncodedBuf,
  5690. OUT WORD *pdwEncodedLength,
  5691. IN DWORD dwAPDUType
  5692. )
  5693. {
  5694. H323_UU_PDU_h4501SupplementaryService h4501APDU;
  5695. int rc;
  5696. H323_UserInformation UserInfo;
  5697. DWORD dwAPDULen = 0;
  5698. BYTE* pEncodedAPDU = NULL;
  5699. H323DBG((DEBUG_LEVEL_TRACE, "EncodeConnectMessage entered: %p.", this ));
  5700. Connect_UUIE & connectMessage =
  5701. UserInfo.h323_uu_pdu.h323_message_body.u.connect;
  5702. *ppEncodedBuf = NULL;
  5703. *pdwEncodedLength = 0;
  5704. memset( (PVOID)&UserInfo, 0, sizeof(H323_UserInformation));
  5705. UserInfo.bit_mask = 0;
  5706. // make sure the user_data_present flag is turned off.
  5707. UserInfo.bit_mask &= (~user_data_present);
  5708. UserInfo.h323_uu_pdu.bit_mask = 0;
  5709. //send the appropriate ADPDUS
  5710. if( dwAPDUType != NO_H450_APDU )
  5711. {
  5712. if( !EncodeH450APDU( dwInvokeID, dwAPDUType,
  5713. &pEncodedAPDU, &dwAPDULen ) )
  5714. {
  5715. return FALSE;
  5716. }
  5717. UserInfo.h323_uu_pdu.h4501SupplementaryService = &h4501APDU;
  5718. UserInfo.h323_uu_pdu.h4501SupplementaryService -> next = NULL;
  5719. UserInfo.h323_uu_pdu.h4501SupplementaryService -> value.value = pEncodedAPDU;
  5720. UserInfo.h323_uu_pdu.h4501SupplementaryService -> value.length = dwAPDULen;
  5721. UserInfo.h323_uu_pdu.bit_mask |= h4501SupplementaryService_present;
  5722. }
  5723. UserInfo.h323_uu_pdu.h245Tunneling = FALSE;//(m_fh245Tunneling & LOCAL_H245_TUNNELING);
  5724. UserInfo.h323_uu_pdu.bit_mask |= h245Tunneling_present;
  5725. SetNonStandardData( UserInfo );
  5726. UserInfo.h323_uu_pdu.h323_message_body.choice = connect_chosen;
  5727. connectMessage.protocolIdentifier = OID_H225ProtocolIdentifierV2;
  5728. TransportAddress& transportAddress = connectMessage.h245Address;
  5729. CopyTransportAddress( transportAddress, &m_selfH245Addr );
  5730. connectMessage.bit_mask |= (Connect_UUIE_h245Address_present);
  5731. connectMessage.destinationInfo.bit_mask = 0;
  5732. //copy the vendor info
  5733. connectMessage.destinationInfo.bit_mask |= vendor_present;
  5734. CopyVendorInfo( &connectMessage.destinationInfo.vendor );
  5735. //terminal is present
  5736. connectMessage.destinationInfo.bit_mask |= terminal_present;
  5737. connectMessage.destinationInfo.terminal.bit_mask = 0;
  5738. connectMessage.destinationInfo.mc = 0;
  5739. connectMessage.destinationInfo.undefinedNode = 0;
  5740. //copy the 16 byte conference ID
  5741. CopyConferenceID (&connectMessage.conferenceID, &m_ConferenceID);
  5742. if( m_pFastStart != NULL )
  5743. {
  5744. _ASSERTE( m_pPeerFastStart );
  5745. connectMessage.bit_mask |= Connect_UUIE_fastStart_present;
  5746. connectMessage.fastStart = (PConnect_UUIE_fastStart)m_pFastStart;
  5747. }
  5748. else
  5749. {
  5750. connectMessage.bit_mask &= ~Alerting_UUIE_fastStart_present;
  5751. }
  5752. //copy the call identifier
  5753. connectMessage.bit_mask |= Connect_UUIE_callIdentifier_present;
  5754. CopyMemory( (PVOID)&connectMessage.callIdentifier.guid.value,
  5755. (PVOID)&m_callIdentifier,
  5756. sizeof(GUID) );
  5757. connectMessage.callIdentifier.guid.length = sizeof(GUID);
  5758. rc = EncodeASN( (void *) &UserInfo,
  5759. H323_UserInformation_PDU,
  5760. ppEncodedBuf,
  5761. pdwEncodedLength);
  5762. if (ASN1_FAILED(rc) || (*ppEncodedBuf == NULL) || (pdwEncodedLength == 0) )
  5763. {
  5764. if( pEncodedAPDU != NULL )
  5765. {
  5766. ASN1_FreeEncoded(m_H450ASNCoderInfo.pEncInfo, pEncodedAPDU );
  5767. }
  5768. return FALSE;
  5769. }
  5770. if( pEncodedAPDU != NULL )
  5771. {
  5772. ASN1_FreeEncoded(m_H450ASNCoderInfo.pEncInfo, pEncodedAPDU );
  5773. }
  5774. H323DBG((DEBUG_LEVEL_TRACE, "EncodeConnectMessage exited: %p.", this ));
  5775. //success
  5776. return TRUE;
  5777. }
  5778. //!!always called in a lock
  5779. void CH323Call::SetNonStandardData(
  5780. OUT H323_UserInformation & UserInfo
  5781. )
  5782. {
  5783. if( m_NonStandardData.sData.pOctetString )
  5784. {
  5785. H221NonStandard & nonStd =
  5786. UserInfo.h323_uu_pdu.nonStandardData.nonStandardIdentifier.u.h221NonStandard;
  5787. UserInfo.h323_uu_pdu.bit_mask |= H323_UU_PDU_nonStandardData_present;
  5788. UserInfo.h323_uu_pdu.nonStandardData.nonStandardIdentifier.choice
  5789. = H225NonStandardIdentifier_h221NonStandard_chosen;
  5790. nonStd.t35CountryCode = m_NonStandardData.bCountryCode;
  5791. nonStd.t35Extension = m_NonStandardData.bExtension;
  5792. nonStd.manufacturerCode = m_NonStandardData.wManufacturerCode;
  5793. UserInfo.h323_uu_pdu.nonStandardData.data.length =
  5794. m_NonStandardData.sData.wOctetStringLength;
  5795. UserInfo.h323_uu_pdu.nonStandardData.data.value =
  5796. m_NonStandardData.sData.pOctetString;
  5797. // Maintain only one reference to the buffer.
  5798. m_NonStandardData.sData.pOctetString = NULL;
  5799. }
  5800. else
  5801. {
  5802. UserInfo.h323_uu_pdu.bit_mask &= (~H323_UU_PDU_nonStandardData_present);
  5803. }
  5804. }
  5805. //!!always called in a lock
  5806. BOOL
  5807. CH323Call::EncodeSetupMessage(
  5808. IN DWORD dwInvokeID,
  5809. IN WORD wGoal,
  5810. IN WORD wCallType,
  5811. OUT BYTE **ppEncodedBuf,
  5812. OUT WORD *pdwEncodedLength,
  5813. IN DWORD dwAPDUType
  5814. )
  5815. {
  5816. H323_UU_PDU_h4501SupplementaryService h4501APDU;
  5817. H323_UserInformation UserInfo;
  5818. int rc = 0;
  5819. BOOL retVal = TRUE;
  5820. DWORD dwAPDULen = 0;
  5821. BYTE* pEncodedAPDU = NULL;
  5822. *ppEncodedBuf = NULL;
  5823. *pdwEncodedLength = 0;
  5824. H323DBG((DEBUG_LEVEL_TRACE, "EncodeSetupMessage entered: %p.", this ));
  5825. Setup_UUIE & setupMessage = UserInfo.h323_uu_pdu.h323_message_body.u.setup;
  5826. TransportAddress& calleeAddr = setupMessage.destCallSignalAddress;
  5827. TransportAddress& callerAddr = setupMessage.sourceCallSignalAddress;
  5828. memset( (PVOID)&UserInfo, 0, sizeof(H323_UserInformation));
  5829. UserInfo.bit_mask = 0;
  5830. // make sure the user_data_present flag is turned off.
  5831. UserInfo.bit_mask &= (~user_data_present);
  5832. UserInfo.h323_uu_pdu.bit_mask = 0;
  5833. //send the appropriate ADPDUS
  5834. if( dwAPDUType != NO_H450_APDU )
  5835. {
  5836. if( !EncodeH450APDU( dwInvokeID, dwAPDUType, &pEncodedAPDU, &dwAPDULen ) )
  5837. {
  5838. return FALSE;
  5839. }
  5840. UserInfo.h323_uu_pdu.h4501SupplementaryService = &h4501APDU;
  5841. UserInfo.h323_uu_pdu.h4501SupplementaryService -> next = NULL;
  5842. UserInfo.h323_uu_pdu.h4501SupplementaryService -> value.value = pEncodedAPDU;
  5843. UserInfo.h323_uu_pdu.h4501SupplementaryService -> value.length = dwAPDULen;
  5844. UserInfo.h323_uu_pdu.bit_mask |= h4501SupplementaryService_present;
  5845. }
  5846. UserInfo.h323_uu_pdu.h245Tunneling = FALSE;//(m_fh245Tunneling & LOCAL_H245_TUNNELING);
  5847. UserInfo.h323_uu_pdu.bit_mask |= h245Tunneling_present;
  5848. SetNonStandardData( UserInfo );
  5849. UserInfo.h323_uu_pdu.h323_message_body.choice = setup_chosen;
  5850. setupMessage.bit_mask = 0;
  5851. setupMessage.protocolIdentifier = OID_H225ProtocolIdentifierV2;
  5852. if( m_pCallerAliasNames && m_pCallerAliasNames -> wCount )
  5853. {
  5854. //H323DBG(( DEBUG_LEVEL_ERROR, "Caller alias count:%d : %p", m_pCallerAliasNames->wCount, this ));
  5855. setupMessage.sourceAddress = SetMsgAddressAlias(m_pCallerAliasNames);
  5856. if( setupMessage.sourceAddress != NULL )
  5857. {
  5858. setupMessage.bit_mask |= (sourceAddress_present);
  5859. }
  5860. else
  5861. {
  5862. setupMessage.bit_mask &= (~sourceAddress_present);
  5863. }
  5864. }
  5865. else
  5866. {
  5867. setupMessage.bit_mask &= (~sourceAddress_present);
  5868. }
  5869. setupMessage.sourceInfo.bit_mask = 0;
  5870. //pass the vendor info
  5871. setupMessage.sourceInfo.bit_mask |= vendor_present;
  5872. CopyVendorInfo( &setupMessage.sourceInfo.vendor );
  5873. //terminal is present
  5874. setupMessage.sourceInfo.bit_mask |= terminal_present;
  5875. setupMessage.sourceInfo.terminal.bit_mask = 0;
  5876. //not an MC
  5877. setupMessage.sourceInfo.mc = FALSE;
  5878. setupMessage.sourceInfo.undefinedNode = 0;
  5879. if( m_pCalleeAliasNames && m_pCalleeAliasNames -> wCount )
  5880. {
  5881. setupMessage.destinationAddress = (PSetup_UUIE_destinationAddress)
  5882. SetMsgAddressAlias( m_pCalleeAliasNames );
  5883. if( setupMessage.destinationAddress != NULL )
  5884. {
  5885. setupMessage.bit_mask |= (destinationAddress_present);
  5886. }
  5887. else
  5888. {
  5889. setupMessage.bit_mask &= (~destinationAddress_present);
  5890. }
  5891. }
  5892. else
  5893. {
  5894. setupMessage.bit_mask &= (~destinationAddress_present);
  5895. }
  5896. //extra alias not present
  5897. setupMessage.bit_mask &= (~Setup_UUIE_destExtraCallInfo_present );
  5898. //If talking to gateway then don't pass on destn call signal address
  5899. if( m_dwAddressType != LINEADDRESSTYPE_PHONENUMBER )
  5900. {
  5901. CopyTransportAddress( calleeAddr, &m_CalleeAddr );
  5902. setupMessage.bit_mask |= Setup_UUIE_destCallSignalAddress_present;
  5903. }
  5904. //not an MC
  5905. setupMessage.activeMC = m_fActiveMC;
  5906. //copy the 16 byte conference ID
  5907. CopyConferenceID (&setupMessage.conferenceID, &m_ConferenceID);
  5908. //copy the call identifier
  5909. setupMessage.bit_mask |= Setup_UUIE_callIdentifier_present;
  5910. CopyConferenceID (&setupMessage.callIdentifier.guid, &m_callIdentifier);
  5911. //fast start params
  5912. if( m_pFastStart != NULL )
  5913. {
  5914. setupMessage.bit_mask |= Setup_UUIE_fastStart_present;
  5915. setupMessage.fastStart = (PSetup_UUIE_fastStart)m_pFastStart;
  5916. }
  5917. else
  5918. {
  5919. setupMessage.bit_mask &= ~Setup_UUIE_fastStart_present;
  5920. }
  5921. //copy media wait for connect
  5922. setupMessage.mediaWaitForConnect = FALSE;
  5923. setupMessage.conferenceGoal.choice = (BYTE)wGoal;
  5924. setupMessage.callType.choice = (BYTE)wCallType;
  5925. CopyTransportAddress( callerAddr, &m_CallerAddr );
  5926. setupMessage.bit_mask |= sourceCallSignalAddress_present;
  5927. //no extension alias
  5928. setupMessage.bit_mask &= (~Setup_UUIE_remoteExtensionAddress_present);
  5929. rc = EncodeASN( (void *) &UserInfo,
  5930. H323_UserInformation_PDU,
  5931. ppEncodedBuf,
  5932. pdwEncodedLength);
  5933. if( ASN1_FAILED(rc) || (*ppEncodedBuf == NULL) || (pdwEncodedLength == 0) )
  5934. {
  5935. if( pEncodedAPDU != NULL )
  5936. {
  5937. ASN1_FreeEncoded(m_H450ASNCoderInfo.pEncInfo, pEncodedAPDU );
  5938. }
  5939. retVal = FALSE;
  5940. }
  5941. // Free the alias name structures from the UserInfo area.
  5942. if( setupMessage.bit_mask & sourceAddress_present )
  5943. {
  5944. FreeAddressAliases( (PSetup_UUIE_destinationAddress)
  5945. setupMessage.sourceAddress );
  5946. }
  5947. if( setupMessage.bit_mask & destinationAddress_present )
  5948. {
  5949. FreeAddressAliases( setupMessage.destinationAddress );
  5950. }
  5951. if( pEncodedAPDU != NULL )
  5952. {
  5953. ASN1_FreeEncoded(m_H450ASNCoderInfo.pEncInfo, pEncodedAPDU );
  5954. }
  5955. H323DBG((DEBUG_LEVEL_TRACE, "EncodeSetupMessage exited: %p.", this ));
  5956. //success/failure
  5957. return retVal;
  5958. }
  5959. //!!always called in a lock
  5960. BOOL
  5961. CH323Call::EncodeH450APDU(
  5962. IN DWORD dwInvokeID,
  5963. IN DWORD dwAPDUType,
  5964. OUT BYTE** ppEncodedAPDU,
  5965. OUT DWORD* pdwAPDULen
  5966. )
  5967. {
  5968. H4501SupplementaryService SupplementaryServiceAPDU;
  5969. ServiceApdus_rosApdus rosAPDU;
  5970. DWORD dwErrorCode = 0;
  5971. DWORD dwOperationType = (dwAPDUType & 0x0000FF00);
  5972. dwAPDUType &= 0x000000FF;
  5973. H323DBG((DEBUG_LEVEL_TRACE, "EncodeH450APDU entered: %p.", this ));
  5974. ZeroMemory( (PVOID)&SupplementaryServiceAPDU,
  5975. sizeof(H4501SupplementaryService) );
  5976. //interpretationAPDU
  5977. SupplementaryServiceAPDU.interpretationApdu.choice =
  5978. rejectAnyUnrecognizedInvokePdu_chosen;
  5979. SupplementaryServiceAPDU.bit_mask |= interpretationApdu_present;
  5980. //NFE
  5981. SupplementaryServiceAPDU.networkFacilityExtension.bit_mask = 0;
  5982. SupplementaryServiceAPDU.networkFacilityExtension.destinationEntity.choice
  5983. = endpoint_chosen;
  5984. SupplementaryServiceAPDU.networkFacilityExtension.sourceEntity.choice
  5985. = endpoint_chosen;
  5986. SupplementaryServiceAPDU.bit_mask |= networkFacilityExtension_present;
  5987. //serviceAPDUS
  5988. SupplementaryServiceAPDU.serviceApdu.choice = rosApdus_chosen;
  5989. SupplementaryServiceAPDU.serviceApdu.u.rosApdus = &rosAPDU;
  5990. SupplementaryServiceAPDU.serviceApdu.u.rosApdus->next = NULL;
  5991. if( dwOperationType == H450_REJECT )
  5992. {
  5993. if( !EncodeRejectAPDU( &SupplementaryServiceAPDU, dwInvokeID,
  5994. ppEncodedAPDU, pdwAPDULen ) )
  5995. {
  5996. return FALSE;
  5997. }
  5998. }
  5999. else if( dwOperationType == H450_RETURNERROR )
  6000. {
  6001. EncodeReturnErrorAPDU( dwInvokeID, dwErrorCode,
  6002. &SupplementaryServiceAPDU, ppEncodedAPDU, pdwAPDULen );
  6003. }
  6004. else if( dwOperationType == H450_RETURNRESULT )
  6005. {
  6006. if( !EncodeDummyReturnResultAPDU( dwInvokeID,
  6007. dwAPDUType, &SupplementaryServiceAPDU,
  6008. ppEncodedAPDU, pdwAPDULen ) )
  6009. {
  6010. return FALSE;
  6011. }
  6012. }
  6013. else //H450_INVOKE
  6014. {
  6015. switch( dwAPDUType )
  6016. {
  6017. case CHECKRESTRICTION_OPCODE:
  6018. if( !EncodeCheckRestrictionAPDU( &SupplementaryServiceAPDU,
  6019. ppEncodedAPDU, pdwAPDULen ) )
  6020. {
  6021. return FALSE;
  6022. }
  6023. break;
  6024. case CALLREROUTING_OPCODE:
  6025. if( !EncodeCallReroutingAPDU( &SupplementaryServiceAPDU,
  6026. ppEncodedAPDU, pdwAPDULen ) )
  6027. {
  6028. return FALSE;
  6029. }
  6030. break;
  6031. case DIVERTINGLEGINFO2_OPCODE:
  6032. if( !EncodeDivertingLeg2APDU( &SupplementaryServiceAPDU,
  6033. ppEncodedAPDU, pdwAPDULen ) )
  6034. {
  6035. return FALSE;
  6036. }
  6037. break;
  6038. case DIVERTINGLEGINFO3_OPCODE:
  6039. if( !EncodeDivertingLeg3APDU( &SupplementaryServiceAPDU,
  6040. ppEncodedAPDU, pdwAPDULen ) )
  6041. {
  6042. return FALSE;
  6043. }
  6044. break;
  6045. case HOLDNOTIFIC_OPCODE:
  6046. case REMOTEHOLD_OPCODE:
  6047. case RETRIEVENOTIFIC_OPCODE:
  6048. case REMOTERETRIEVE_OPCODE:
  6049. case CTIDENTIFY_OPCODE:
  6050. if( !EncodeH450APDUNoArgument( dwAPDUType, &SupplementaryServiceAPDU,
  6051. ppEncodedAPDU, pdwAPDULen ) )
  6052. {
  6053. return FALSE;
  6054. }
  6055. break;
  6056. case CTSETUP_OPCODE:
  6057. if( !EncodeCTSetupAPDU( &SupplementaryServiceAPDU,
  6058. ppEncodedAPDU, pdwAPDULen ) )
  6059. {
  6060. return FALSE;
  6061. }
  6062. break;
  6063. case CTINITIATE_OPCODE:
  6064. if( !EncodeCTInitiateAPDU( &SupplementaryServiceAPDU,
  6065. ppEncodedAPDU, pdwAPDULen ) )
  6066. {
  6067. return FALSE;
  6068. }
  6069. break;
  6070. default:
  6071. _ASSERTE( 0 );
  6072. return FALSE;
  6073. }
  6074. }
  6075. H323DBG((DEBUG_LEVEL_TRACE, "EncodeH450APDU exited: %p.", this ));
  6076. return TRUE;
  6077. }
  6078. //!!always called in a lock
  6079. BOOL
  6080. CH323Call::EncodePDU(
  6081. IN BINARY_STRING *pUserUserData,
  6082. OUT BYTE ** ppbCodedBuffer,
  6083. OUT DWORD * pdwCodedBufferLength,
  6084. IN DWORD dwMessageType,
  6085. WCHAR * pwszCalledPartyNumber
  6086. )
  6087. {
  6088. PQ931MESSAGE pMessage;
  6089. BYTE bBandwidth;
  6090. char pszDisplay[131] = "";
  6091. DWORD dwMessageLength = 0;
  6092. BYTE indexI;
  6093. BOOL retVal;
  6094. H323DBG(( DEBUG_LEVEL_TRACE, "EncodePDU entered: %p.", this ));
  6095. pMessage = new Q931MESSAGE;
  6096. if( pMessage == NULL )
  6097. {
  6098. return FALSE;
  6099. }
  6100. // fill in the required fields for the Q931 message.
  6101. memset( (PVOID)pMessage, 0, sizeof(Q931MESSAGE));
  6102. pMessage->ProtocolDiscriminator = Q931PDVALUE;
  6103. pMessage->wCallRef = m_wQ931CallRef;
  6104. pMessage->MessageType = (BYTE)dwMessageType;
  6105. dwMessageLength +=
  6106. ( 1 + sizeof(PDTYPE) + sizeof(CRTYPE) + sizeof(MESSAGEIDTYPE) );
  6107. if( (dwMessageType == SETUPMESSAGETYPE) ||
  6108. (dwMessageType == CONNECTMESSAGETYPE) )
  6109. {
  6110. if( m_pwszDisplay &&
  6111. WideCharToMultiByte(CP_ACP,
  6112. 0,
  6113. m_pwszDisplay,
  6114. -1,
  6115. pszDisplay,
  6116. sizeof(pszDisplay),
  6117. NULL,
  6118. NULL) == 0)
  6119. {
  6120. delete pMessage;
  6121. return FALSE;
  6122. }
  6123. if( *pszDisplay )
  6124. {
  6125. pMessage->Display.fPresent = TRUE;
  6126. pMessage->Display.dwLength = (BYTE)(strlen(pszDisplay) + 1);
  6127. strcpy((char *)pMessage->Display.pbContents, pszDisplay);
  6128. dwMessageLength += (2 + pMessage->Display.dwLength);
  6129. }
  6130. pMessage->BearerCapability.fPresent = TRUE;
  6131. pMessage->BearerCapability.dwLength = 3;
  6132. pMessage->BearerCapability.pbContents[0] =
  6133. (BYTE)(BEAR_EXT_BIT | BEAR_CCITT | BEAR_UNRESTRICTED_DIGITAL);
  6134. pMessage->BearerCapability.pbContents[1] =
  6135. (BYTE)(BEAR_EXT_BIT | 0x17); //64kbps
  6136. pMessage->BearerCapability.pbContents[2] = (BYTE)
  6137. (BEAR_EXT_BIT | BEAR_LAYER1_INDICATOR | BEAR_LAYER1_H221_H242);
  6138. dwMessageLength += (2+pMessage->BearerCapability.dwLength);
  6139. }
  6140. //if talking to gateway encode the called party number
  6141. if( m_dwAddressType == LINEADDRESSTYPE_PHONENUMBER )
  6142. {
  6143. BYTE bLen = (BYTE)(wcslen(pwszCalledPartyNumber)+1);
  6144. pMessage->CalledPartyNumber.fPresent = TRUE;
  6145. pMessage->CalledPartyNumber.NumberType =
  6146. (BYTE)(CALLED_PARTY_EXT_BIT | CALLED_PARTY_TYPE_UNKNOWN);
  6147. pMessage->CalledPartyNumber.NumberingPlan =
  6148. (BYTE)(CALLED_PARTY_PLAN_E164);
  6149. pMessage->CalledPartyNumber.PartyNumberLength = bLen;
  6150. for( indexI =0; indexI < bLen; indexI++ )
  6151. {
  6152. pMessage->CalledPartyNumber.PartyNumbers[indexI] =
  6153. (BYTE)pwszCalledPartyNumber[indexI];
  6154. }
  6155. dwMessageLength += (2 + pMessage->CalledPartyNumber.PartyNumberLength);
  6156. }
  6157. if( dwMessageType == FACILITYMESSAGETYPE )
  6158. {
  6159. // The facility ie is encoded as present, but empty...
  6160. pMessage->Facility.fPresent = TRUE;
  6161. pMessage->Facility.dwLength = 0;
  6162. pMessage->Facility.pbContents[0] = 0;
  6163. dwMessageLength += (2 + pMessage->Facility.dwLength);
  6164. }
  6165. if (pUserUserData && pUserUserData->pbBuffer)
  6166. {
  6167. if (pUserUserData->length > sizeof(pMessage->UserToUser.pbUserInfo))
  6168. {
  6169. delete pMessage;
  6170. return FALSE;
  6171. }
  6172. pMessage->UserToUser.fPresent = TRUE;
  6173. pMessage->UserToUser.wUserInfoLen = pUserUserData->length;
  6174. //This CopyMemory should be avoided
  6175. //may be we should do:pMessage->UserToUser.pbUserInfo = pUserUserData->pbBuffer;
  6176. //change the definition of pMessage->UserToUser.pbUserInfo to BYTE* from BYTE[0x1000]
  6177. CopyMemory( (PVOID)pMessage->UserToUser.pbUserInfo,
  6178. (PVOID)pUserUserData->pbBuffer, pUserUserData->length );
  6179. dwMessageLength += (4+pMessage->UserToUser.wUserInfoLen);
  6180. }
  6181. _ASSERTE( dwMessageLength );
  6182. retVal = EncodeMessage( pMessage, ppbCodedBuffer,
  6183. pdwCodedBufferLength, dwMessageLength );
  6184. delete pMessage;
  6185. return retVal;
  6186. }
  6187. //!!always called in a lock
  6188. BOOL
  6189. CH323Call::EncodeMessage(
  6190. IN PQ931MESSAGE pMessage,
  6191. OUT BYTE **ppbCodedMessage,
  6192. OUT DWORD *pdwCodedMessageLength,
  6193. IN DWORD dwMessageLength
  6194. )
  6195. {
  6196. BUFFERDESCR pBuf;
  6197. DWORD dwPDULen = 0;
  6198. H323DBG((DEBUG_LEVEL_TRACE, "EncodeMessage entered: %p.", this ));
  6199. *ppbCodedMessage = (BYTE *)new char[ dwMessageLength + 100 ];
  6200. if( *ppbCodedMessage == NULL )
  6201. {
  6202. return FALSE;
  6203. }
  6204. pBuf.dwLength = dwMessageLength + 100;
  6205. pBuf.pbBuffer = *ppbCodedMessage + TPKT_HEADER_SIZE;
  6206. WriteQ931Fields(&pBuf, pMessage, &dwPDULen );
  6207. _ASSERTE( dwPDULen == dwMessageLength );
  6208. SetupTPKTHeader( *ppbCodedMessage , dwPDULen );
  6209. *pdwCodedMessageLength = dwPDULen + 4;
  6210. H323DBG((DEBUG_LEVEL_TRACE, "EncodeMessage exited: %p.", this ));
  6211. return TRUE;
  6212. }
  6213. //!!always called in a lock
  6214. void
  6215. CH323Call::WriteQ931Fields(
  6216. IN PBUFFERDESCR pBuf,
  6217. IN PQ931MESSAGE pMessage,
  6218. OUT DWORD * pdwPDULen
  6219. )
  6220. {
  6221. H323DBG((DEBUG_LEVEL_TRACE, "WriteQ931Fields entered: %p.", this ));
  6222. // write the required information elements...
  6223. WriteProtocolDiscriminator( pBuf, pdwPDULen );
  6224. WriteCallReference( pBuf, &pMessage->wCallRef,
  6225. pdwPDULen );
  6226. WriteMessageType(pBuf, &pMessage->MessageType,
  6227. pdwPDULen);
  6228. // try to write all other information elements...
  6229. // don't write this message.
  6230. if (pMessage->Facility.fPresent)
  6231. {
  6232. WriteVariableOctet(pBuf, IDENT_FACILITY,
  6233. pMessage->Facility.dwLength,
  6234. pMessage->Facility.pbContents,
  6235. pdwPDULen);
  6236. }
  6237. if( pMessage->BearerCapability.fPresent
  6238. && pMessage->BearerCapability.dwLength )
  6239. {
  6240. WriteVariableOctet(pBuf, IDENT_BEARERCAP,
  6241. pMessage->BearerCapability.dwLength,
  6242. pMessage->BearerCapability.pbContents,
  6243. pdwPDULen);
  6244. }
  6245. if (pMessage->Display.fPresent && pMessage->Display.dwLength)
  6246. {
  6247. WriteVariableOctet(pBuf, IDENT_DISPLAY,
  6248. pMessage->Display.dwLength,
  6249. pMessage->Display.pbContents,
  6250. pdwPDULen);
  6251. }
  6252. if( pMessage->CalledPartyNumber.fPresent )
  6253. {
  6254. WritePartyNumber(pBuf,
  6255. IDENT_CALLEDNUMBER,
  6256. pMessage->CalledPartyNumber.NumberType,
  6257. pMessage->CalledPartyNumber.NumberingPlan,
  6258. pMessage->CalledPartyNumber.PartyNumberLength,
  6259. pMessage->CalledPartyNumber.PartyNumbers,
  6260. pdwPDULen);
  6261. }
  6262. if( pMessage->UserToUser.fPresent &&
  6263. pMessage->UserToUser.wUserInfoLen )
  6264. {
  6265. WriteUserInformation(pBuf,
  6266. IDENT_USERUSER,
  6267. pMessage->UserToUser.wUserInfoLen,
  6268. pMessage->UserToUser.pbUserInfo,
  6269. pdwPDULen);
  6270. }
  6271. H323DBG((DEBUG_LEVEL_TRACE, "WriteQ931Fields exited: %p.", this ));
  6272. }
  6273. //!!always calld in a lock
  6274. void
  6275. CH323Call::HandleTransportEvent(void)
  6276. {
  6277. WSANETWORKEVENTS networkEvents;
  6278. int iError;
  6279. H323DBG(( DEBUG_LEVEL_TRACE, "HandleTransportEvent entered: %p.", this ));
  6280. if( (m_callSocket == INVALID_SOCKET) &&
  6281. (m_dwCallType == CALLTYPE_DIVERTEDSRC) )
  6282. {
  6283. H323DBG(( DEBUG_LEVEL_TRACE, "The diverted call is not initialized yet."
  6284. "This is probably an event for the primary call. Ignore it %p.",
  6285. this ));
  6286. return;
  6287. }
  6288. //find out the event that took place
  6289. if(WSAEnumNetworkEvents(m_callSocket,
  6290. m_hTransport,
  6291. &networkEvents ) == SOCKET_ERROR )
  6292. {
  6293. H323DBG((DEBUG_LEVEL_TRACE, "WSAEnumNetworkEvents error:%d, %lx, %p.",
  6294. WSAGetLastError(), m_callSocket, this ));
  6295. return;
  6296. }
  6297. if( networkEvents.lNetworkEvents & FD_CLOSE )
  6298. {
  6299. H323DBG((DEBUG_LEVEL_TRACE, "socket close event: %p.", this ));
  6300. //if the call is in transition then don't close the call when the
  6301. //old socket gets closed
  6302. if( m_fCallInTrnasition == TRUE )
  6303. {
  6304. //the call is noot in transition mode anymore
  6305. m_fCallInTrnasition = FALSE;
  6306. return;
  6307. }
  6308. //convey the Q931 close status to the TAPI call object
  6309. //and the tapisrv
  6310. iError = networkEvents.iErrorCode[FD_CLOSE_BIT];
  6311. SetQ931CallState( Q931_CALL_DISCONNECTED );
  6312. //clean up the Q931 call
  6313. CloseCall( 0 );
  6314. return;
  6315. }
  6316. //This can occur only for outbound calls
  6317. if( (networkEvents.lNetworkEvents) & FD_CONNECT )
  6318. {
  6319. H323DBG((DEBUG_LEVEL_TRACE, "socket connect event: %p.", this ));
  6320. //FD_CONNECT event received
  6321. //This func is called by the callback thread when m_hEventQ931Conn is
  6322. //signalled. This function takes care of the outgoing Q931 calls only
  6323. //call the member function
  6324. iError = networkEvents.iErrorCode[FD_CONNECT_BIT];
  6325. if(iError != ERROR_SUCCESS)
  6326. {
  6327. if( (m_dwCallType & CALLTYPE_FORWARDCONSULT )&&
  6328. (m_dwOrigin == LINECALLORIGIN_OUTBOUND ) )
  6329. {
  6330. //Success of forwarding
  6331. EnableCallForwarding();
  6332. }
  6333. H323DBG((DEBUG_LEVEL_ERROR, "FD_CONNECT returned error: %d.",
  6334. iError ));
  6335. CloseCall( 0 );
  6336. return;
  6337. }
  6338. OnConnectComplete();
  6339. }
  6340. H323DBG((DEBUG_LEVEL_TRACE, "HandleTransportEvent exited: %p.", this ));
  6341. }
  6342. //!!always called in a lock
  6343. int
  6344. CH323Call::InitASNCoder(void)
  6345. {
  6346. int rc;
  6347. H323DBG((DEBUG_LEVEL_TRACE, "InitASNCoder entered: %p.", this ));
  6348. memset((PVOID)&m_ASNCoderInfo, 0, sizeof(m_ASNCoderInfo));
  6349. if( H225ASN_Module == NULL)
  6350. {
  6351. return ASN1_ERR_BADARGS;
  6352. }
  6353. rc = ASN1_CreateEncoder(
  6354. H225ASN_Module, // ptr to mdule
  6355. &(m_ASNCoderInfo.pEncInfo), // ptr to encoder info
  6356. NULL, // buffer ptr
  6357. 0, // buffer size
  6358. NULL); // parent ptr
  6359. if (rc == ASN1_SUCCESS)
  6360. {
  6361. _ASSERTE(m_ASNCoderInfo.pEncInfo );
  6362. rc = ASN1_CreateDecoder(
  6363. H225ASN_Module, // ptr to mdule
  6364. &(m_ASNCoderInfo.pDecInfo), // ptr to decoder info
  6365. NULL, // buffer ptr
  6366. 0, // buffer size
  6367. NULL); // parent ptr
  6368. _ASSERTE(m_ASNCoderInfo.pDecInfo );
  6369. }
  6370. if (rc != ASN1_SUCCESS)
  6371. {
  6372. TermASNCoder();
  6373. }
  6374. H323DBG((DEBUG_LEVEL_TRACE, "InitASNCoder exited: %p.", this ));
  6375. return rc;
  6376. }
  6377. //!!always called in a lock
  6378. int
  6379. CH323Call::TermASNCoder(void)
  6380. {
  6381. if( H225ASN_Module == NULL )
  6382. {
  6383. return ASN1_ERR_BADARGS;
  6384. }
  6385. ASN1_CloseEncoder(m_ASNCoderInfo.pEncInfo);
  6386. ASN1_CloseDecoder(m_ASNCoderInfo.pDecInfo);
  6387. memset( (PVOID)&m_ASNCoderInfo, 0, sizeof(m_ASNCoderInfo));
  6388. return ASN1_SUCCESS;
  6389. }
  6390. //!!always called in a lock
  6391. int
  6392. CH323Call::EncodeASN(
  6393. IN void * pStruct,
  6394. IN int nPDU,
  6395. OUT BYTE ** ppEncoded,
  6396. OUT WORD * pcbEncodedSize
  6397. )
  6398. {
  6399. H323DBG((DEBUG_LEVEL_TRACE, "EncodeASN entered: %p.", this ));
  6400. ASN1encoding_t pEncInfo = m_ASNCoderInfo.pEncInfo;
  6401. int rc = ASN1_Encode(
  6402. pEncInfo, // ptr to encoder info
  6403. pStruct, // pdu data structure
  6404. nPDU, // pdu id
  6405. ASN1ENCODE_ALLOCATEBUFFER, // flags
  6406. NULL, // do not provide buffer
  6407. 0); // buffer size if provided
  6408. if (ASN1_SUCCEEDED(rc))
  6409. {
  6410. if( rc != ASN1_SUCCESS )
  6411. {
  6412. H323DBG((DEBUG_LEVEL_TRACE, "warning while encoding ASN:%d.", rc ));
  6413. }
  6414. *pcbEncodedSize = (WORD)pEncInfo->len; // len of encoded data in buffer
  6415. *ppEncoded = pEncInfo->buf; // buffer to encode into
  6416. }
  6417. else
  6418. {
  6419. H323DBG((DEBUG_LEVEL_TRACE, "error while encoding ASN:%d.", rc ));
  6420. *pcbEncodedSize = 0;
  6421. *ppEncoded = NULL;
  6422. }
  6423. H323DBG((DEBUG_LEVEL_TRACE, "EncodeASN exited: %p.", this ));
  6424. return rc;
  6425. }
  6426. //!!always called in a lock
  6427. int
  6428. CH323Call::DecodeASN(
  6429. OUT void ** ppStruct,
  6430. IN int nPDU,
  6431. IN BYTE * pEncoded,
  6432. IN DWORD cbEncodedSize
  6433. )
  6434. {
  6435. H323DBG((DEBUG_LEVEL_TRACE, "h323call DecodeASN entered: %p.", this ));
  6436. ASN1decoding_t pDecInfo = m_ASNCoderInfo.pDecInfo;
  6437. int rc = ASN1_Decode(
  6438. pDecInfo, // ptr to encoder info
  6439. ppStruct, // pdu data structure
  6440. nPDU, // pdu id
  6441. ASN1DECODE_SETBUFFER, // flags
  6442. pEncoded, // do not provide buffer
  6443. cbEncodedSize); // buffer size if provided
  6444. if (ASN1_SUCCEEDED(rc))
  6445. {
  6446. if( rc != ASN1_SUCCESS )
  6447. {
  6448. H323DBG((DEBUG_LEVEL_TRACE, "warning while deciding ASN:%d.", rc ));
  6449. }
  6450. }
  6451. else
  6452. {
  6453. H323DBG((DEBUG_LEVEL_TRACE, "error while deciding ASN:%d.", rc ));
  6454. H323DUMPBUFFER( (BYTE*)pEncoded, cbEncodedSize);
  6455. *ppStruct = NULL;
  6456. }
  6457. H323DBG((DEBUG_LEVEL_TRACE, "h323call DecodeASN exited: %p.", this ));
  6458. return rc;
  6459. }
  6460. //!!always called in a lock
  6461. int
  6462. CH323Call::InitH450ASNCoder(void)
  6463. {
  6464. int rc;
  6465. H323DBG((DEBUG_LEVEL_TRACE, "InitH450ASNCoder entered: %p.", this ));
  6466. memset((PVOID)&m_H450ASNCoderInfo, 0, sizeof(m_H450ASNCoderInfo));
  6467. if( H4503PP_Module == NULL)
  6468. {
  6469. return ASN1_ERR_BADARGS;
  6470. }
  6471. rc = ASN1_CreateEncoder(
  6472. H4503PP_Module, // ptr to mdule
  6473. &(m_H450ASNCoderInfo.pEncInfo), // ptr to encoder info
  6474. NULL, // buffer ptr
  6475. 0, // buffer size
  6476. NULL); // parent ptr
  6477. if (rc == ASN1_SUCCESS)
  6478. {
  6479. _ASSERTE(m_H450ASNCoderInfo.pEncInfo );
  6480. rc = ASN1_CreateDecoder(
  6481. H4503PP_Module, // ptr to mdule
  6482. &(m_H450ASNCoderInfo.pDecInfo), // ptr to decoder info
  6483. NULL, // buffer ptr
  6484. 0, // buffer size
  6485. NULL ); // parent ptr
  6486. _ASSERTE( m_H450ASNCoderInfo.pDecInfo );
  6487. }
  6488. if (rc != ASN1_SUCCESS)
  6489. {
  6490. TermH450ASNCoder();
  6491. }
  6492. H323DBG((DEBUG_LEVEL_TRACE, "InitH450ASNCoder exited: %p.", this ));
  6493. return rc;
  6494. }
  6495. //!!always called in a lock
  6496. int
  6497. CH323Call::TermH450ASNCoder(void)
  6498. {
  6499. if( H4503PP_Module == NULL )
  6500. {
  6501. return ASN1_ERR_BADARGS;
  6502. }
  6503. ASN1_CloseEncoder(m_H450ASNCoderInfo.pEncInfo);
  6504. ASN1_CloseDecoder(m_H450ASNCoderInfo.pDecInfo);
  6505. memset( (PVOID)&m_H450ASNCoderInfo, 0, sizeof(m_ASNCoderInfo));
  6506. return ASN1_SUCCESS;
  6507. }
  6508. //!!always called in a lock
  6509. int
  6510. CH323Call::EncodeH450ASN(
  6511. IN void * pStruct,
  6512. IN int nPDU,
  6513. OUT BYTE ** ppEncoded,
  6514. OUT WORD * pcbEncodedSize
  6515. )
  6516. {
  6517. H323DBG((DEBUG_LEVEL_TRACE, "EncodeH450ASN entered: %p.", this ));
  6518. ASN1encoding_t pEncInfo = m_H450ASNCoderInfo.pEncInfo;
  6519. int rc = ASN1_Encode(
  6520. pEncInfo, // ptr to encoder info
  6521. pStruct, // pdu data structure
  6522. nPDU, // pdu id
  6523. ASN1ENCODE_ALLOCATEBUFFER, // flags
  6524. NULL, // do not provide buffer
  6525. 0); // buffer size if provided
  6526. if (ASN1_SUCCEEDED(rc))
  6527. {
  6528. if( rc != ASN1_SUCCESS )
  6529. {
  6530. H323DBG((DEBUG_LEVEL_TRACE, "warning while encoding ASN:%d.", rc ));
  6531. }
  6532. *pcbEncodedSize = (WORD)pEncInfo->len; // len of encoded data in buffer
  6533. *ppEncoded = pEncInfo->buf; // buffer to encode into
  6534. }
  6535. else
  6536. {
  6537. H323DBG((DEBUG_LEVEL_TRACE, "error while encoding ASN:%d.", rc ));
  6538. *pcbEncodedSize = 0;
  6539. *ppEncoded = NULL;
  6540. }
  6541. H323DBG((DEBUG_LEVEL_TRACE, "EncodeH450ASN exited: %p.", this ));
  6542. return rc;
  6543. }
  6544. //!!always called in a lock
  6545. int
  6546. CH323Call::DecodeH450ASN(
  6547. OUT void ** ppStruct,
  6548. IN int nPDU,
  6549. IN BYTE * pEncoded,
  6550. IN DWORD cbEncodedSize
  6551. )
  6552. {
  6553. H323DBG((DEBUG_LEVEL_TRACE, "h323call DecodeH450ASN entered: %p.", this ));
  6554. ASN1decoding_t pDecInfo = m_H450ASNCoderInfo.pDecInfo;
  6555. int rc = ASN1_Decode(
  6556. pDecInfo, // ptr to encoder info
  6557. ppStruct, // pdu data structure
  6558. nPDU, // pdu id
  6559. ASN1DECODE_SETBUFFER, // flags
  6560. pEncoded, // do not provide buffer
  6561. cbEncodedSize); // buffer size if provided
  6562. if( ASN1_SUCCEEDED(rc) )
  6563. {
  6564. if( rc != ASN1_SUCCESS )
  6565. {
  6566. H323DBG((DEBUG_LEVEL_TRACE, "warning while deciding ASN:%d.", rc ));
  6567. }
  6568. }
  6569. else
  6570. {
  6571. H323DBG((DEBUG_LEVEL_TRACE, "error while deciding ASN:%d.", rc ));
  6572. H323DUMPBUFFER( (BYTE*)pEncoded, cbEncodedSize);
  6573. *ppStruct = NULL;
  6574. }
  6575. H323DBG(( DEBUG_LEVEL_TRACE, "h323call DecodeH450ASN exited: %p.", this ));
  6576. return rc;
  6577. }
  6578. //------------------------------------------------------------------------
  6579. //------------------------------------------------------------------------
  6580. //!!always called in a lock
  6581. BOOL
  6582. CH323Call::ParseReleaseCompleteASN(
  6583. IN BYTE *pEncodedBuf,
  6584. IN DWORD dwEncodedLength,
  6585. OUT Q931_RELEASE_COMPLETE_ASN *pReleaseASN,
  6586. OUT DWORD* pdwH450APDUType
  6587. )
  6588. {
  6589. H323_UserInformation *pUserInfo;
  6590. int iResult;
  6591. DWORD dwInvokeID = 0;
  6592. H323DBG((DEBUG_LEVEL_TRACE, "ParseReleaseCompleteASN entered: %p.", this ));
  6593. memset( (PVOID)pReleaseASN, 0, sizeof(Q931_RELEASE_COMPLETE_ASN));
  6594. iResult = DecodeASN((void **) &pUserInfo,
  6595. H323_UserInformation_PDU,
  6596. pEncodedBuf,
  6597. dwEncodedLength);
  6598. if (ASN1_FAILED(iResult) || (pUserInfo == NULL))
  6599. {
  6600. return FALSE;
  6601. }
  6602. *pdwH450APDUType = 0;
  6603. if( (pUserInfo->h323_uu_pdu.bit_mask & h4501SupplementaryService_present) &&
  6604. pUserInfo->h323_uu_pdu.h4501SupplementaryService )
  6605. {
  6606. if( !HandleH450APDU( pUserInfo->h323_uu_pdu.h4501SupplementaryService,
  6607. pdwH450APDUType, &dwInvokeID, NULL ) )
  6608. {
  6609. goto cleanup;
  6610. }
  6611. }
  6612. // validate that the PDU user-data uses ASN encoding.
  6613. if( (pUserInfo->bit_mask & user_data_present) &&
  6614. (pUserInfo->user_data.protocol_discriminator != USE_ASN1_ENCODING) )
  6615. {
  6616. goto cleanup;
  6617. }
  6618. // validate that the PDU is H323 Release Complete information.
  6619. if( pUserInfo->h323_uu_pdu.h323_message_body.choice != releaseComplete_chosen )
  6620. {
  6621. goto cleanup;
  6622. }
  6623. // parse the message contained in pUserInfo.
  6624. pReleaseASN->fNonStandardDataPresent = FALSE;
  6625. if( pUserInfo->h323_uu_pdu.bit_mask & H323_UU_PDU_nonStandardData_present )
  6626. {
  6627. if( !ParseNonStandardData( &pReleaseASN -> nonStandardData,
  6628. &pUserInfo->h323_uu_pdu.nonStandardData ) )
  6629. {
  6630. goto cleanup;
  6631. }
  6632. pReleaseASN->fNonStandardDataPresent = TRUE;
  6633. }
  6634. if (pUserInfo->h323_uu_pdu.h323_message_body.u.releaseComplete.bit_mask &
  6635. ReleaseComplete_UUIE_reason_present)
  6636. {
  6637. switch( pUserInfo->h323_uu_pdu.h323_message_body.u.releaseComplete.reason.choice )
  6638. {
  6639. case noBandwidth_chosen:
  6640. pReleaseASN->bReason = H323_REJECT_NO_BANDWIDTH;
  6641. break;
  6642. case gatekeeperResources_chosen:
  6643. pReleaseASN->bReason = H323_REJECT_GATEKEEPER_RESOURCES;
  6644. break;
  6645. case unreachableDestination_chosen:
  6646. pReleaseASN->bReason = H323_REJECT_UNREACHABLE_DESTINATION;
  6647. break;
  6648. case destinationRejection_chosen:
  6649. pReleaseASN->bReason = H323_REJECT_DESTINATION_REJECTION;
  6650. break;
  6651. case ReleaseCompleteReason_invalidRevision_chosen:
  6652. pReleaseASN->bReason = H323_REJECT_INVALID_REVISION;
  6653. break;
  6654. case noPermission_chosen:
  6655. pReleaseASN->bReason = H323_REJECT_NO_PERMISSION;
  6656. break;
  6657. case unreachableGatekeeper_chosen:
  6658. pReleaseASN->bReason = H323_REJECT_UNREACHABLE_GATEKEEPER;
  6659. break;
  6660. case gatewayResources_chosen:
  6661. pReleaseASN->bReason = H323_REJECT_GATEWAY_RESOURCES;
  6662. break;
  6663. case badFormatAddress_chosen:
  6664. pReleaseASN->bReason = H323_REJECT_BAD_FORMAT_ADDRESS;
  6665. break;
  6666. case adaptiveBusy_chosen:
  6667. pReleaseASN->bReason = H323_REJECT_ADAPTIVE_BUSY;
  6668. break;
  6669. case inConf_chosen:
  6670. pReleaseASN->bReason = H323_REJECT_IN_CONF;
  6671. break;
  6672. case facilityCallDeflection_chosen:
  6673. pReleaseASN->bReason = H323_REJECT_CALL_DEFLECTION;
  6674. break;
  6675. default:
  6676. pReleaseASN->bReason = H323_REJECT_UNDEFINED_REASON;
  6677. } // switch
  6678. }
  6679. else
  6680. {
  6681. pReleaseASN->bReason = H323_REJECT_UNDEFINED_REASON;
  6682. }
  6683. H323DBG(( DEBUG_LEVEL_TRACE,
  6684. "ParseReleaseCompleteASN error:%d, q931 error:%d, exit:%p.",
  6685. pReleaseASN->bReason,
  6686. pUserInfo->h323_uu_pdu.h323_message_body.u.releaseComplete.reason.choice,
  6687. this ));
  6688. // Free the PDU data.
  6689. ASN1_FreeDecoded(m_ASNCoderInfo.pDecInfo, pUserInfo,
  6690. H323_UserInformation_PDU );
  6691. return TRUE;
  6692. cleanup:
  6693. if( pReleaseASN->fNonStandardDataPresent )
  6694. {
  6695. delete pReleaseASN -> nonStandardData.sData.pOctetString;
  6696. pReleaseASN -> nonStandardData.sData.pOctetString = NULL;
  6697. pReleaseASN->fNonStandardDataPresent = FALSE;
  6698. }
  6699. ASN1_FreeDecoded( m_ASNCoderInfo.pDecInfo, pUserInfo,
  6700. H323_UserInformation_PDU);
  6701. return FALSE;
  6702. }
  6703. //------------------------------------------------------------------------
  6704. //------------------------------------------------------------------------
  6705. //!!always called in a lock
  6706. BOOL
  6707. CH323Call::ParseConnectASN(
  6708. IN BYTE *pEncodedBuf,
  6709. IN DWORD dwEncodedLength,
  6710. OUT Q931_CONNECT_ASN *pConnectASN,
  6711. OUT DWORD* pdwH450APDUType
  6712. )
  6713. {
  6714. H323_UserInformation *pUserInfo;
  6715. int iResult;
  6716. DWORD dwInvokeID = 0;
  6717. H323DBG((DEBUG_LEVEL_TRACE, "ParseConnectASN entered: %p.", this ));
  6718. memset( (PVOID) pConnectASN, 0, sizeof(Q931_CONNECT_ASN) );
  6719. iResult = DecodeASN((void **) &pUserInfo ,
  6720. H323_UserInformation_PDU,
  6721. pEncodedBuf,
  6722. dwEncodedLength);
  6723. if (ASN1_FAILED(iResult) || (pUserInfo == NULL))
  6724. {
  6725. return FALSE;
  6726. }
  6727. Connect_UUIE & connectMessage =
  6728. pUserInfo->h323_uu_pdu.h323_message_body.u.connect;
  6729. *pdwH450APDUType = 0;
  6730. if( (pUserInfo->h323_uu_pdu.bit_mask & h4501SupplementaryService_present) &&
  6731. pUserInfo->h323_uu_pdu.h4501SupplementaryService )
  6732. {
  6733. if( !HandleH450APDU( pUserInfo->h323_uu_pdu.h4501SupplementaryService,
  6734. pdwH450APDUType, &dwInvokeID, NULL ) )
  6735. {
  6736. goto cleanup;
  6737. }
  6738. }
  6739. // validate that the PDU user-data uses ASN encoding.
  6740. if( (pUserInfo->bit_mask & user_data_present) &&
  6741. (pUserInfo->user_data.protocol_discriminator != USE_ASN1_ENCODING) )
  6742. {
  6743. goto cleanup;
  6744. }
  6745. // validate that the PDU is H323 Connect information.
  6746. if (pUserInfo->h323_uu_pdu.h323_message_body.choice != connect_chosen)
  6747. {
  6748. goto cleanup;
  6749. }
  6750. // make sure that the conference id is formed correctly.
  6751. if (connectMessage.conferenceID.length >
  6752. sizeof(connectMessage.conferenceID.value))
  6753. {
  6754. goto cleanup;
  6755. }
  6756. // parse the message contained in pUserInfo.
  6757. pConnectASN->h245Addr.bMulticast = FALSE;
  6758. pConnectASN->fNonStandardDataPresent = FALSE;
  6759. if( pUserInfo->h323_uu_pdu.bit_mask & H323_UU_PDU_nonStandardData_present )
  6760. {
  6761. if( !ParseNonStandardData( &pConnectASN -> nonStandardData,
  6762. &pUserInfo->h323_uu_pdu.nonStandardData ) )
  6763. {
  6764. goto cleanup;
  6765. }
  6766. pConnectASN->fNonStandardDataPresent = TRUE;
  6767. }
  6768. pConnectASN->h245AddrPresent = FALSE;
  6769. if( connectMessage.bit_mask & Connect_UUIE_h245Address_present )
  6770. {
  6771. if( connectMessage.h245Address.choice != ipAddress_chosen )
  6772. {
  6773. goto cleanup;
  6774. }
  6775. pConnectASN->h245Addr.nAddrType = H323_IP_BINARY;
  6776. pConnectASN->h245Addr.Addr.IP_Binary.wPort =
  6777. connectMessage.h245Address.u.ipAddress.port;
  6778. pConnectASN->h245Addr.Addr.IP_Binary.dwAddr =
  6779. ntohl( *((DWORD*)connectMessage.h245Address.u.ipAddress.ip.value) );
  6780. pConnectASN->h245AddrPresent = TRUE;
  6781. }
  6782. // no validation of destinationInfo needed.
  6783. pConnectASN->EndpointType.pVendorInfo = NULL;
  6784. if( connectMessage.destinationInfo.bit_mask & (vendor_present))
  6785. {
  6786. if( !ParseVendorInfo( &pConnectASN->VendorInfo,
  6787. &connectMessage.destinationInfo.vendor) )
  6788. {
  6789. goto cleanup;
  6790. }
  6791. pConnectASN->EndpointType.pVendorInfo = &(pConnectASN->VendorInfo);
  6792. }
  6793. pConnectASN->EndpointType.bIsTerminal = FALSE;
  6794. if (connectMessage.destinationInfo.bit_mask & (terminal_present))
  6795. {
  6796. pConnectASN->EndpointType.bIsTerminal = TRUE;
  6797. }
  6798. pConnectASN->EndpointType.bIsGateway = FALSE;
  6799. if (connectMessage.destinationInfo.bit_mask & (gateway_present))
  6800. {
  6801. pConnectASN->EndpointType.bIsGateway = TRUE;
  6802. }
  6803. pConnectASN -> fFastStartPresent = FALSE;
  6804. if( (connectMessage.bit_mask & Connect_UUIE_fastStart_present) &&
  6805. connectMessage.fastStart )
  6806. {
  6807. pConnectASN->pFastStart = CopyFastStart(
  6808. (PSetup_UUIE_fastStart)connectMessage.fastStart );
  6809. if( pConnectASN->pFastStart != NULL )
  6810. {
  6811. pConnectASN -> fFastStartPresent = TRUE;
  6812. }
  6813. }
  6814. CopyConferenceID( &pConnectASN -> ConferenceID,
  6815. &connectMessage.conferenceID );
  6816. if( pUserInfo->h323_uu_pdu.h245Tunneling )
  6817. {
  6818. //the remote endpoint has sent a tunneling proposal
  6819. m_fh245Tunneling |= REMOTE_H245_TUNNELING;
  6820. }
  6821. // Free the PDU data.
  6822. ASN1_FreeDecoded(m_ASNCoderInfo.pDecInfo, pUserInfo,
  6823. H323_UserInformation_PDU);
  6824. H323DBG((DEBUG_LEVEL_TRACE, "ParseConnectASN exited: %p.", this ));
  6825. return TRUE;
  6826. cleanup:
  6827. FreeConnectASN( pConnectASN );
  6828. ASN1_FreeDecoded(m_ASNCoderInfo.pDecInfo, pUserInfo,
  6829. H323_UserInformation_PDU );
  6830. return FALSE;
  6831. }
  6832. //!!always called in a lock
  6833. BOOL
  6834. CH323Call::ParseAlertingASN(
  6835. IN BYTE *pEncodedBuf,
  6836. IN DWORD dwEncodedLength,
  6837. OUT Q931_ALERTING_ASN *pAlertingASN,
  6838. OUT DWORD* pdwH450APDUType
  6839. )
  6840. {
  6841. H323_UserInformation *pUserInfo;
  6842. int iResult;
  6843. DWORD dwInvokeID = 0;
  6844. H323DBG((DEBUG_LEVEL_TRACE, "ParseAlertingASN entered: %p.", this ));
  6845. memset( (PVOID) pAlertingASN, 0, sizeof(Q931_ALERTING_ASN) );
  6846. iResult = DecodeASN((void **) &pUserInfo,
  6847. H323_UserInformation_PDU,
  6848. pEncodedBuf,
  6849. dwEncodedLength);
  6850. if (ASN1_FAILED(iResult) || (pUserInfo == NULL))
  6851. {
  6852. return FALSE;
  6853. }
  6854. Alerting_UUIE & alertingMessage =
  6855. pUserInfo->h323_uu_pdu.h323_message_body.u.alerting;
  6856. *pdwH450APDUType = 0;
  6857. if( (pUserInfo->h323_uu_pdu.bit_mask & h4501SupplementaryService_present) &&
  6858. pUserInfo->h323_uu_pdu.h4501SupplementaryService )
  6859. {
  6860. if( !HandleH450APDU( pUserInfo->h323_uu_pdu.h4501SupplementaryService,
  6861. pdwH450APDUType, &dwInvokeID, NULL ) )
  6862. {
  6863. goto cleanup;
  6864. }
  6865. }
  6866. // validate that the PDU user-data uses ASN encoding.
  6867. if( (pUserInfo->bit_mask & user_data_present ) &&
  6868. (pUserInfo->user_data.protocol_discriminator != USE_ASN1_ENCODING) )
  6869. {
  6870. goto cleanup;
  6871. }
  6872. // validate that the PDU is H323 Alerting information.
  6873. if (pUserInfo->h323_uu_pdu.h323_message_body.choice != alerting_chosen)
  6874. {
  6875. goto cleanup;
  6876. }
  6877. // parse the message contained in pUserInfo.
  6878. pAlertingASN->h245Addr.bMulticast = FALSE;
  6879. pAlertingASN->fNonStandardDataPresent = FALSE;
  6880. if( pUserInfo->h323_uu_pdu.bit_mask & H323_UU_PDU_nonStandardData_present )
  6881. {
  6882. if( !ParseNonStandardData( &pAlertingASN -> nonStandardData,
  6883. &pUserInfo->h323_uu_pdu.nonStandardData ) )
  6884. {
  6885. goto cleanup;
  6886. }
  6887. pAlertingASN->fNonStandardDataPresent = TRUE;
  6888. }
  6889. if( alertingMessage.bit_mask & Alerting_UUIE_h245Address_present )
  6890. {
  6891. if( alertingMessage.h245Address.choice != ipAddress_chosen )
  6892. {
  6893. goto cleanup;
  6894. }
  6895. pAlertingASN->h245Addr.nAddrType = H323_IP_BINARY;
  6896. pAlertingASN->h245Addr.Addr.IP_Binary.wPort =
  6897. alertingMessage.h245Address.u.ipAddress.port;
  6898. AddressReverseAndCopy(
  6899. &(pAlertingASN->h245Addr.Addr.IP_Binary.dwAddr),
  6900. alertingMessage.h245Address.u.ipAddress.ip.value );
  6901. }
  6902. pAlertingASN -> fFastStartPresent = FALSE;
  6903. if( (alertingMessage.bit_mask & Alerting_UUIE_fastStart_present) &&
  6904. alertingMessage.fastStart )
  6905. {
  6906. pAlertingASN->pFastStart = CopyFastStart(
  6907. (PSetup_UUIE_fastStart)alertingMessage.fastStart);
  6908. if( pAlertingASN->pFastStart != NULL )
  6909. pAlertingASN-> fFastStartPresent = TRUE;
  6910. }
  6911. if( pUserInfo->h323_uu_pdu.h245Tunneling )
  6912. {
  6913. m_fh245Tunneling |= REMOTE_H245_TUNNELING;
  6914. }
  6915. // Free the PDU data.
  6916. ASN1_FreeDecoded(m_ASNCoderInfo.pDecInfo, pUserInfo,
  6917. H323_UserInformation_PDU);
  6918. H323DBG((DEBUG_LEVEL_TRACE, "ParseAlertingASN exited: %p.", this ));
  6919. return TRUE;
  6920. cleanup:
  6921. FreeAlertingASN( pAlertingASN );
  6922. ASN1_FreeDecoded( m_ASNCoderInfo.pDecInfo, pUserInfo,
  6923. H323_UserInformation_PDU );
  6924. return FALSE;
  6925. }
  6926. //!!aleways called in a lock
  6927. BOOL
  6928. CH323Call::ParseProceedingASN(
  6929. IN BYTE *pEncodedBuf,
  6930. IN DWORD dwEncodedLength,
  6931. OUT Q931_CALL_PROCEEDING_ASN *pProceedingASN,
  6932. OUT DWORD* pdwH450APDUType
  6933. )
  6934. {
  6935. H323_UserInformation * pUserInfo;
  6936. int iResult;
  6937. DWORD dwInvokeID = 0;
  6938. H323DBG((DEBUG_LEVEL_TRACE, "ParseProceedingASN entered: %p.", this ));
  6939. memset( (PVOID) pProceedingASN, 0, sizeof(Q931_CALL_PROCEEDING_ASN) );
  6940. iResult = DecodeASN((void **) &pUserInfo,
  6941. H323_UserInformation_PDU,
  6942. pEncodedBuf,
  6943. dwEncodedLength);
  6944. if (ASN1_FAILED(iResult) || (pUserInfo == NULL))
  6945. {
  6946. return FALSE;
  6947. }
  6948. CallProceeding_UUIE & proceedingMessage =
  6949. pUserInfo->h323_uu_pdu.h323_message_body.u.callProceeding;
  6950. *pdwH450APDUType = 0;
  6951. if( (pUserInfo->h323_uu_pdu.bit_mask & h4501SupplementaryService_present) &&
  6952. pUserInfo->h323_uu_pdu.h4501SupplementaryService )
  6953. {
  6954. if( !HandleH450APDU( pUserInfo->h323_uu_pdu.h4501SupplementaryService,
  6955. pdwH450APDUType, &dwInvokeID, NULL ) )
  6956. goto cleanup;
  6957. }
  6958. // validate that the PDU user-data uses ASN encoding.
  6959. if( (pUserInfo->bit_mask & user_data_present) &&
  6960. (pUserInfo->user_data.protocol_discriminator != USE_ASN1_ENCODING) )
  6961. {
  6962. goto cleanup;
  6963. }
  6964. // validate that the PDU is H323 Proceeding information.
  6965. // validate that the PDU is H323 pCall Proceeding information.
  6966. if( pUserInfo->h323_uu_pdu.h323_message_body.choice != callProceeding_chosen )
  6967. {
  6968. goto cleanup;
  6969. }
  6970. // parse the message contained in pUserInfo.
  6971. pProceedingASN->fNonStandardDataPresent = FALSE;
  6972. if( pUserInfo->h323_uu_pdu.bit_mask & H323_UU_PDU_nonStandardData_present )
  6973. {
  6974. if( !ParseNonStandardData( &pProceedingASN -> nonStandardData,
  6975. &pUserInfo->h323_uu_pdu.nonStandardData ) )
  6976. {
  6977. goto cleanup;
  6978. }
  6979. pProceedingASN->fNonStandardDataPresent = TRUE;
  6980. }
  6981. //copy the H245 address information
  6982. pProceedingASN->fH245AddrPresent = FALSE;
  6983. if( proceedingMessage.bit_mask & CallProceeding_UUIE_h245Address_present )
  6984. {
  6985. if( proceedingMessage.h245Address.choice != ipAddress_chosen )
  6986. {
  6987. goto cleanup;
  6988. }
  6989. pProceedingASN->h245Addr.nAddrType = H323_IP_BINARY;
  6990. pProceedingASN->h245Addr.Addr.IP_Binary.wPort =
  6991. proceedingMessage.h245Address.u.ipAddress.port;
  6992. AddressReverseAndCopy(
  6993. &(pProceedingASN->h245Addr.Addr.IP_Binary.dwAddr),
  6994. proceedingMessage.h245Address.u.ipAddress.ip.value );
  6995. pProceedingASN->h245Addr.bMulticast = FALSE;
  6996. pProceedingASN->fH245AddrPresent = TRUE;
  6997. }
  6998. pProceedingASN -> fFastStartPresent = FALSE;
  6999. if( (proceedingMessage.bit_mask & CallProceeding_UUIE_fastStart_present) &&
  7000. proceedingMessage.fastStart )
  7001. {
  7002. pProceedingASN->pFastStart = CopyFastStart(
  7003. (PSetup_UUIE_fastStart)proceedingMessage.fastStart);
  7004. if( pProceedingASN->pFastStart != NULL )
  7005. pProceedingASN-> fFastStartPresent = TRUE;
  7006. }
  7007. //ignore the destinationInfo field.
  7008. if( pUserInfo->h323_uu_pdu.h245Tunneling )
  7009. {
  7010. if( m_dwOrigin == LINECALLORIGIN_INBOUND )
  7011. {
  7012. //the msp has enabled tunneling in ProceedWithAnswer messsage
  7013. m_fh245Tunneling |= LOCAL_H245_TUNNELING;
  7014. }
  7015. else
  7016. //the remote endpoint has sent a tunneling proposal
  7017. m_fh245Tunneling |= REMOTE_H245_TUNNELING;
  7018. }
  7019. // Free the PDU data.
  7020. ASN1_FreeDecoded(m_ASNCoderInfo.pDecInfo, pUserInfo,
  7021. H323_UserInformation_PDU );
  7022. H323DBG((DEBUG_LEVEL_TRACE, "ParseProceedingASN exited: %p.", this ));
  7023. return TRUE;
  7024. cleanup:
  7025. FreeProceedingASN( pProceedingASN );
  7026. ASN1_FreeDecoded(m_ASNCoderInfo.pDecInfo, pUserInfo,
  7027. H323_UserInformation_PDU );
  7028. return FALSE;
  7029. }
  7030. //!!always called in a lock
  7031. BOOL
  7032. CH323Call::ParseFacilityASN(
  7033. IN BYTE * pEncodedBuf,
  7034. IN DWORD dwEncodedLength,
  7035. OUT Q931_FACILITY_ASN * pFacilityASN
  7036. )
  7037. {
  7038. H323_UserInformation *pUserInfo;
  7039. int iResult;
  7040. H323DBG((DEBUG_LEVEL_TRACE, "ParseFacilityASN entered: %p.", this ));
  7041. ZeroMemory( (PVOID) pFacilityASN, sizeof(Q931_FACILITY_ASN) );
  7042. iResult = DecodeASN((void **) &pUserInfo,
  7043. H323_UserInformation_PDU,
  7044. pEncodedBuf,
  7045. dwEncodedLength);
  7046. if( ASN1_FAILED(iResult) || (pUserInfo == NULL) )
  7047. {
  7048. return FALSE;
  7049. }
  7050. // validate that the PDU is H323 facility information.
  7051. if( pUserInfo->h323_uu_pdu.h323_message_body.choice == facility_chosen )
  7052. {
  7053. Facility_UUIE & facilityMessage =
  7054. pUserInfo->h323_uu_pdu.h323_message_body.u.facility;
  7055. // validate that the PDU user-data uses ASN encoding.
  7056. if( (pUserInfo->bit_mask & user_data_present) &&
  7057. (pUserInfo->user_data.protocol_discriminator != USE_ASN1_ENCODING) )
  7058. {
  7059. goto cleanup;
  7060. }
  7061. // make sure that the conference id is formed correctly.
  7062. if( facilityMessage.conferenceID.length >
  7063. sizeof(facilityMessage.conferenceID.value) )
  7064. {
  7065. //goto cleanup;
  7066. }
  7067. // parse the message contained in pUserInfo.
  7068. pFacilityASN->fNonStandardDataPresent = FALSE;
  7069. if( pUserInfo->h323_uu_pdu.bit_mask & H323_UU_PDU_nonStandardData_present )
  7070. {
  7071. if( !ParseNonStandardData( &pFacilityASN -> nonStandardData,
  7072. &pUserInfo->h323_uu_pdu.nonStandardData ) )
  7073. {
  7074. goto cleanup;
  7075. }
  7076. pFacilityASN->fNonStandardDataPresent = TRUE;
  7077. }
  7078. pFacilityASN->fAlternativeAddressPresent = FALSE;
  7079. if( facilityMessage.bit_mask & alternativeAddress_present )
  7080. {
  7081. if( facilityMessage.alternativeAddress.choice == ipAddress_chosen )
  7082. {
  7083. pFacilityASN->AlternativeAddr.nAddrType = H323_IP_BINARY;
  7084. pFacilityASN->AlternativeAddr.Addr.IP_Binary.wPort =
  7085. facilityMessage.alternativeAddress.u.ipAddress.port;
  7086. AddressReverseAndCopy(
  7087. &(pFacilityASN->AlternativeAddr.Addr.IP_Binary.dwAddr),
  7088. facilityMessage.alternativeAddress.u.ipAddress.ip.value );
  7089. pFacilityASN->fAlternativeAddressPresent = TRUE;
  7090. }
  7091. }
  7092. if( facilityMessage.bit_mask & alternativeAliasAddress_present )
  7093. {
  7094. if( !AliasAddrToAliasNames( &(pFacilityASN->pAlternativeAliasList),
  7095. (PSetup_UUIE_sourceAddress)
  7096. &(facilityMessage.alternativeAliasAddress) ) )
  7097. {
  7098. pFacilityASN -> pAlternativeAliasList = NULL;
  7099. //goto cleanup;
  7100. }
  7101. }
  7102. if( facilityMessage.bit_mask & Facility_UUIE_conferenceID_present )
  7103. {
  7104. CopyConferenceID( &pFacilityASN -> ConferenceID,
  7105. &facilityMessage.conferenceID );
  7106. pFacilityASN -> ConferenceIDPresent = TRUE;
  7107. }
  7108. pFacilityASN->bReason = facilityMessage.reason.choice;
  7109. pFacilityASN->fH245AddrPresent = FALSE;
  7110. if( facilityMessage.bit_mask & Facility_UUIE_h245Address_present )
  7111. {
  7112. if( facilityMessage.h245Address.choice == ipAddress_chosen )
  7113. {
  7114. pFacilityASN->h245Addr.nAddrType = H323_IP_BINARY;
  7115. pFacilityASN->h245Addr.Addr.IP_Binary.wPort =
  7116. facilityMessage.h245Address.u.ipAddress.port;
  7117. pFacilityASN->h245Addr.Addr.IP_Binary.dwAddr =
  7118. ntohl( *((DWORD*)facilityMessage.h245Address.u.ipAddress.ip.value) );
  7119. pFacilityASN->fH245AddrPresent = TRUE;
  7120. }
  7121. }
  7122. }
  7123. pFacilityASN->dwH450APDUType = 0;
  7124. if( (pUserInfo->h323_uu_pdu.bit_mask & h4501SupplementaryService_present) &&
  7125. pUserInfo->h323_uu_pdu.h4501SupplementaryService )
  7126. {
  7127. pFacilityASN->dwInvokeID = 0;
  7128. if( !HandleH450APDU( pUserInfo->h323_uu_pdu.h4501SupplementaryService,
  7129. &pFacilityASN->dwH450APDUType, &pFacilityASN->dwInvokeID, NULL ) )
  7130. {
  7131. goto cleanup;
  7132. }
  7133. }
  7134. if( pUserInfo->h323_uu_pdu.bit_mask & h245Control_present )
  7135. {
  7136. if( pUserInfo->h323_uu_pdu.h245Control != NULL )
  7137. {
  7138. pFacilityASN->pH245PDU.value =
  7139. new BYTE[pUserInfo->h323_uu_pdu.h245Control->value.length];
  7140. if( pFacilityASN->pH245PDU.value != NULL )
  7141. {
  7142. CopyMemory( (PVOID)pFacilityASN->pH245PDU.value,
  7143. (PVOID)pUserInfo->h323_uu_pdu.h245Control->value.value,
  7144. pUserInfo->h323_uu_pdu.h245Control->value.length );
  7145. }
  7146. pFacilityASN->pH245PDU.length =
  7147. pUserInfo->h323_uu_pdu.h245Control->value.length;
  7148. }
  7149. }
  7150. ASN1_FreeDecoded( m_ASNCoderInfo.pDecInfo, pUserInfo,
  7151. H323_UserInformation_PDU );
  7152. H323DBG((DEBUG_LEVEL_TRACE, "ParseFacilityASN exited: %p.", this ));
  7153. return TRUE;
  7154. cleanup:
  7155. if( pFacilityASN -> pAlternativeAliasList != NULL )
  7156. {
  7157. FreeAliasNames( pFacilityASN -> pAlternativeAliasList );
  7158. pFacilityASN -> pAlternativeAliasList = NULL;
  7159. }
  7160. if( pFacilityASN->fNonStandardDataPresent != NULL )
  7161. {
  7162. delete pFacilityASN->nonStandardData.sData.pOctetString;
  7163. pFacilityASN->nonStandardData.sData.pOctetString = NULL;
  7164. pFacilityASN->fNonStandardDataPresent = NULL;
  7165. }
  7166. ASN1_FreeDecoded(m_ASNCoderInfo.pDecInfo, pUserInfo,
  7167. H323_UserInformation_PDU );
  7168. return FALSE;
  7169. }
  7170. //!!aleways called in a lock
  7171. BOOL
  7172. CH323Call::ParseSetupASN(
  7173. IN BYTE *pEncodedBuf,
  7174. IN DWORD dwEncodedLength,
  7175. OUT Q931_SETUP_ASN *pSetupASN,
  7176. OUT DWORD* pdwH450APDUType
  7177. )
  7178. {
  7179. H323_UserInformation *pUserInfo;
  7180. HRESULT hr;
  7181. int iResult;
  7182. DWORD dwInvokeID = 0;
  7183. H323DBG((DEBUG_LEVEL_TRACE, "ParseSetupASN entered: %p.", this ));
  7184. memset( (PVOID)pSetupASN, 0, sizeof(Q931_SETUP_ASN));
  7185. iResult = DecodeASN((void **) &pUserInfo,
  7186. H323_UserInformation_PDU,
  7187. pEncodedBuf,
  7188. dwEncodedLength);
  7189. if (ASN1_FAILED(iResult) || (pUserInfo == NULL))
  7190. {
  7191. return FALSE;
  7192. }
  7193. Setup_UUIE & setupMessage = pUserInfo->h323_uu_pdu.h323_message_body.u.setup;
  7194. // validate that the PDU user-data uses ASN encoding.
  7195. if( (pUserInfo->bit_mask & user_data_present) &&
  7196. (pUserInfo->user_data.protocol_discriminator != USE_ASN1_ENCODING) )
  7197. {
  7198. //log
  7199. goto cleanup;
  7200. }
  7201. // validate that the PDU is H323 Setup information.
  7202. if( pUserInfo->h323_uu_pdu.h323_message_body.choice != setup_chosen )
  7203. {
  7204. //log
  7205. goto cleanup;
  7206. }
  7207. // make sure that the conference id is formed correctly.
  7208. if (setupMessage.conferenceID.length >
  7209. sizeof(setupMessage.conferenceID.value))
  7210. {
  7211. goto cleanup;
  7212. }
  7213. // parse the message contained in pUserInfo.
  7214. pSetupASN->sourceAddr.bMulticast = FALSE;
  7215. pSetupASN->callerAddr.bMulticast = FALSE;
  7216. pSetupASN->calleeDestAddr.bMulticast = FALSE;
  7217. pSetupASN->calleeAddr.bMulticast = FALSE;
  7218. // no validation of sourceInfo needed.
  7219. //copy thevendor info
  7220. pSetupASN->EndpointType.pVendorInfo = NULL;
  7221. if( setupMessage.sourceInfo.bit_mask & vendor_present )
  7222. {
  7223. if( !ParseVendorInfo( &pSetupASN->VendorInfo,
  7224. &setupMessage.sourceInfo.vendor) )
  7225. {
  7226. goto cleanup;
  7227. }
  7228. pSetupASN->EndpointType.pVendorInfo = &(pSetupASN->VendorInfo);
  7229. }
  7230. pSetupASN->EndpointType.bIsTerminal = FALSE;
  7231. if( setupMessage.sourceInfo.bit_mask & terminal_present )
  7232. {
  7233. pSetupASN->EndpointType.bIsTerminal = TRUE;
  7234. }
  7235. pSetupASN->EndpointType.bIsGateway = FALSE;
  7236. if( setupMessage.sourceInfo.bit_mask & gateway_present )
  7237. {
  7238. pSetupASN->EndpointType.bIsGateway = TRUE;
  7239. }
  7240. pSetupASN->fNonStandardDataPresent = FALSE;
  7241. if( pUserInfo->h323_uu_pdu.bit_mask & H323_UU_PDU_nonStandardData_present )
  7242. {
  7243. if( !ParseNonStandardData( &pSetupASN -> nonStandardData,
  7244. &pUserInfo->h323_uu_pdu.nonStandardData ) )
  7245. {
  7246. goto cleanup;
  7247. }
  7248. pSetupASN->fNonStandardDataPresent = TRUE;
  7249. }
  7250. // parse the sourceAddress aliases here...
  7251. if( setupMessage.bit_mask & sourceAddress_present )
  7252. {
  7253. if( !AliasAddrToAliasNames( &(pSetupASN->pCallerAliasList),
  7254. setupMessage.sourceAddress ) )
  7255. {
  7256. pSetupASN->pCallerAliasList = NULL;
  7257. //goto cleanup;
  7258. }
  7259. }
  7260. // parse the destinationAddress aliases here...
  7261. if( (setupMessage.bit_mask & destinationAddress_present) &&
  7262. setupMessage.destinationAddress )
  7263. {
  7264. if( !AliasAddrToAliasNames( &(pSetupASN->pCalleeAliasList),
  7265. (PSetup_UUIE_sourceAddress)setupMessage.destinationAddress) )
  7266. {
  7267. pSetupASN->pCalleeAliasList = NULL;
  7268. //goto cleanup;
  7269. }
  7270. }
  7271. // parse the destExtraCallInfo aliases here...
  7272. if( (setupMessage.bit_mask & Setup_UUIE_destExtraCallInfo_present) &&
  7273. setupMessage.destExtraCallInfo )
  7274. {
  7275. if( !AliasAddrToAliasNames(&(pSetupASN->pExtraAliasList),
  7276. (PSetup_UUIE_sourceAddress)setupMessage.destExtraCallInfo) )
  7277. {
  7278. pSetupASN->pExtraAliasList = NULL;
  7279. //goto cleanup;
  7280. }
  7281. }
  7282. // parse the remoteExtensionAddress aliases here...
  7283. if( setupMessage.bit_mask & Setup_UUIE_remoteExtensionAddress_present )
  7284. {
  7285. pSetupASN->pExtensionAliasItem = new H323_ALIASITEM;
  7286. if( pSetupASN->pExtensionAliasItem == NULL )
  7287. {
  7288. goto cleanup;
  7289. }
  7290. hr = AliasAddrToAliasItem(pSetupASN->pExtensionAliasItem,
  7291. &(setupMessage.remoteExtensionAddress));
  7292. if( hr == E_OUTOFMEMORY )
  7293. {
  7294. goto cleanup;
  7295. }
  7296. }
  7297. pSetupASN -> fCalleeDestAddrPresent = FALSE;
  7298. if( setupMessage.bit_mask & Setup_UUIE_destCallSignalAddress_present )
  7299. {
  7300. if( setupMessage.destCallSignalAddress.choice != ipAddress_chosen )
  7301. {
  7302. goto cleanup;
  7303. }
  7304. pSetupASN->calleeDestAddr.nAddrType = H323_IP_BINARY;
  7305. pSetupASN->calleeDestAddr.Addr.IP_Binary.wPort =
  7306. setupMessage.destCallSignalAddress.u.ipAddress.port;
  7307. AddressReverseAndCopy(
  7308. &(pSetupASN->calleeDestAddr.Addr.IP_Binary.dwAddr),
  7309. setupMessage.destCallSignalAddress.u.ipAddress.ip.value );
  7310. pSetupASN -> fCalleeDestAddrPresent = TRUE;
  7311. }
  7312. pSetupASN->fSourceAddrPresent = FALSE;
  7313. if( setupMessage.bit_mask & sourceCallSignalAddress_present )
  7314. {
  7315. if( setupMessage.sourceCallSignalAddress.choice != ipAddress_chosen )
  7316. {
  7317. goto cleanup;
  7318. }
  7319. pSetupASN->sourceAddr.nAddrType = H323_IP_BINARY;
  7320. pSetupASN->sourceAddr.Addr.IP_Binary.wPort =
  7321. setupMessage.sourceCallSignalAddress.u.ipAddress.port;
  7322. pSetupASN->sourceAddr.Addr.IP_Binary.dwAddr = ntohl( *((DWORD*)
  7323. setupMessage.sourceCallSignalAddress.u.ipAddress.ip.value) );
  7324. pSetupASN->fSourceAddrPresent = TRUE;
  7325. }
  7326. pSetupASN->bCallerIsMC = setupMessage.activeMC;
  7327. pSetupASN -> fFastStartPresent = FALSE;
  7328. if( (setupMessage.bit_mask & Setup_UUIE_fastStart_present) &&
  7329. setupMessage.fastStart )
  7330. {
  7331. pSetupASN->pFastStart = CopyFastStart( setupMessage.fastStart );
  7332. if( pSetupASN->pFastStart != NULL )
  7333. {
  7334. pSetupASN -> fFastStartPresent = TRUE;
  7335. }
  7336. }
  7337. CopyConferenceID (&pSetupASN -> ConferenceID, &setupMessage.conferenceID);
  7338. //copy the call identifier
  7339. pSetupASN -> fCallIdentifierPresent = FALSE;
  7340. if( setupMessage.bit_mask & Setup_UUIE_callIdentifier_present )
  7341. {
  7342. pSetupASN -> fCallIdentifierPresent = TRUE;
  7343. CopyMemory( (PVOID)&(pSetupASN->callIdentifier),
  7344. setupMessage.callIdentifier.guid.value,
  7345. sizeof(GUID) );
  7346. }
  7347. if( pUserInfo->h323_uu_pdu.h245Tunneling )
  7348. {
  7349. if( m_dwOrigin == LINECALLORIGIN_INBOUND )
  7350. {
  7351. //the remote endpoint has sent a tunneling proposal
  7352. m_fh245Tunneling |= REMOTE_H245_TUNNELING;
  7353. }
  7354. else
  7355. {
  7356. //the msp has enabled tunneling in ReadyToInitiate messsage
  7357. m_fh245Tunneling |= LOCAL_H245_TUNNELING;
  7358. }
  7359. }
  7360. pSetupASN->wGoal = (WORD)setupMessage.conferenceGoal.choice;
  7361. pSetupASN->wCallType = setupMessage.callType.choice;
  7362. *pdwH450APDUType = 0;
  7363. if( (pUserInfo->h323_uu_pdu.bit_mask & h4501SupplementaryService_present) &&
  7364. pUserInfo->h323_uu_pdu.h4501SupplementaryService )
  7365. {
  7366. if( !HandleH450APDU( pUserInfo->h323_uu_pdu.h4501SupplementaryService,
  7367. pdwH450APDUType, &dwInvokeID, pSetupASN ) )
  7368. {
  7369. goto cleanup;
  7370. }
  7371. }
  7372. // Free the PDU data.
  7373. ASN1_FreeDecoded( m_ASNCoderInfo.pDecInfo, pUserInfo,
  7374. H323_UserInformation_PDU );
  7375. H323DBG(( DEBUG_LEVEL_TRACE, "ParseSetupASN exited: %p.", this ));
  7376. return TRUE;
  7377. cleanup:
  7378. FreeSetupASN( pSetupASN );
  7379. ASN1_FreeDecoded(m_ASNCoderInfo.pDecInfo, pUserInfo,
  7380. H323_UserInformation_PDU);
  7381. return FALSE;
  7382. }
  7383. //-----------------------------------------------------------------------------
  7384. //GLOBAL CALLBACK FUNCTIONS CALLED BY THREAD POOL
  7385. //-----------------------------------------------------------------------------
  7386. // static
  7387. void
  7388. NTAPI CH323Call::IoCompletionCallback(
  7389. IN DWORD dwStatus,
  7390. IN DWORD dwBytesTransferred,
  7391. IN OVERLAPPED * pOverlapped
  7392. )
  7393. {
  7394. CALL_OVERLAPPED *pCallOverlapped;
  7395. CH323Call* pCall;
  7396. H323DBG(( DEBUG_LEVEL_TRACE, "CH323Call-IoCompletionCallback entered." ));
  7397. _ASSERTE (pOverlapped);
  7398. pCallOverlapped = CONTAINING_RECORD( pOverlapped, CALL_OVERLAPPED,
  7399. Overlapped );
  7400. pCall = pCallOverlapped -> pCall;
  7401. switch (pCallOverlapped -> Type)
  7402. {
  7403. case OVERLAPPED_TYPE_SEND:
  7404. pCall -> OnWriteComplete( dwStatus,
  7405. static_cast<CALL_SEND_CONTEXT *>(pCallOverlapped) );
  7406. break;
  7407. case OVERLAPPED_TYPE_RECV:
  7408. pCallOverlapped -> BytesTransferred = dwBytesTransferred;
  7409. pCall -> OnReadComplete( dwStatus,
  7410. static_cast<CALL_RECV_CONTEXT *>(pCallOverlapped) );
  7411. break;
  7412. default:
  7413. _ASSERTE(FALSE);
  7414. }
  7415. H323DBG(( DEBUG_LEVEL_TRACE, "CH323Call-IoCompletionCallback exited." ));
  7416. }
  7417. void
  7418. CH323Call::OnWriteComplete(
  7419. IN DWORD dwStatus,
  7420. IN CALL_SEND_CONTEXT * pSendContext
  7421. )
  7422. {
  7423. H323DBG(( DEBUG_LEVEL_TRACE, "OnWriteComplete entered:%p.",this ));
  7424. Lock();
  7425. _ASSERTE( m_IoRefCount != 0 );
  7426. m_IoRefCount--;
  7427. H323DBG((DEBUG_LEVEL_TRACE, "WriteComplete:m_IoRefCount: %d:%p.",
  7428. m_IoRefCount, this ));
  7429. if( m_dwFlags & CALLOBJECT_SHUTDOWN )
  7430. {
  7431. if( m_IoRefCount == 0 )
  7432. {
  7433. QueueTAPICallRequest( TSPI_DELETE_CALL, NULL );
  7434. H323DBG((DEBUG_LEVEL_TRACE, "call delete:%p.", this ));
  7435. }
  7436. }
  7437. else if( dwStatus == ERROR_SUCCESS )
  7438. {
  7439. if( IsInList( &m_sendBufList, &pSendContext->ListEntry ) )
  7440. {
  7441. RemoveEntryList( &pSendContext->ListEntry );
  7442. delete pSendContext->WSABuf.buf;
  7443. delete pSendContext;
  7444. }
  7445. }
  7446. Unlock();
  7447. H323DBG(( DEBUG_LEVEL_TRACE, "OnWriteComplete exited:%p.",this ));
  7448. }
  7449. void
  7450. CH323Call::OnReadComplete(
  7451. IN DWORD dwStatus,
  7452. IN CALL_RECV_CONTEXT * pRecvContext )
  7453. {
  7454. H323DBG(( DEBUG_LEVEL_TRACE, "OnReadComplete entered:%p.",this ));
  7455. Lock();
  7456. _ASSERTE( m_IoRefCount != 0 );
  7457. m_IoRefCount --;
  7458. H323DBG(( DEBUG_LEVEL_TRACE, "RecvBuffer:m_IoRefCount:%d:%p.",
  7459. m_IoRefCount, this ));
  7460. if( m_dwFlags & CALLOBJECT_SHUTDOWN )
  7461. {
  7462. if( m_IoRefCount == 0 )
  7463. {
  7464. QueueTAPICallRequest( TSPI_DELETE_CALL, NULL );
  7465. H323DBG((DEBUG_LEVEL_TRACE, "call delete:%p.", this ));
  7466. }
  7467. }
  7468. else
  7469. {
  7470. if( dwStatus == ERROR_SUCCESS )
  7471. {
  7472. _ASSERTE( m_pRecvBuffer == pRecvContext );
  7473. if( pRecvContext->BytesTransferred == 0 )
  7474. {
  7475. CloseCall( 0 );
  7476. H323DBG((DEBUG_LEVEL_TRACE, "0 bytes recvd:%p.", this ));
  7477. }
  7478. else
  7479. {
  7480. ReadEvent( pRecvContext->BytesTransferred );
  7481. }
  7482. }
  7483. }
  7484. Unlock();
  7485. H323DBG(( DEBUG_LEVEL_TRACE, "OnReadComplete exited:%p.",this ));
  7486. }
  7487. // static
  7488. void
  7489. NTAPI CH323Call::SetupSentTimerCallback(
  7490. IN PVOID Parameter1,
  7491. IN BOOLEAN bTimer
  7492. )
  7493. {
  7494. PH323_CALL pCall = NULL;
  7495. //if the timer expired
  7496. _ASSERTE( bTimer );
  7497. H323DBG(( DEBUG_LEVEL_TRACE, "Q931 setup expired event recvd." ));
  7498. pCall=g_pH323Line -> FindH323CallAndLock((HDRVCALL) Parameter1);
  7499. if( pCall != NULL )
  7500. {
  7501. pCall -> SetupSentTimerExpired();
  7502. pCall -> Unlock();
  7503. }
  7504. }
  7505. // static
  7506. void
  7507. NTAPI CH323Call::CheckRestrictionTimerCallback(
  7508. IN PVOID Parameter1,
  7509. IN BOOLEAN bTimer
  7510. )
  7511. {
  7512. //if the timer expired
  7513. _ASSERTE( bTimer );
  7514. H323DBG(( DEBUG_LEVEL_TRACE, "CheckRestrictionTimerCallback entered." ));
  7515. if(!QueueTAPILineRequest(
  7516. TSPI_CLOSE_CALL,
  7517. (HDRVCALL) Parameter1,
  7518. NULL,
  7519. LINEDISCONNECTMODE_NOANSWER,
  7520. NULL) )
  7521. {
  7522. H323DBG(( DEBUG_LEVEL_ERROR, "could not post H323 close event." ));
  7523. }
  7524. H323DBG(( DEBUG_LEVEL_TRACE, "CheckRestrictionTimerCallback exited." ));
  7525. }
  7526. // static
  7527. void
  7528. NTAPI CH323Call::CallReroutingTimerCallback(
  7529. IN PVOID Parameter1,
  7530. IN BOOLEAN bTimer
  7531. )
  7532. {
  7533. //If the timer expired
  7534. _ASSERTE( bTimer );
  7535. H323DBG(( DEBUG_LEVEL_TRACE, "CallReroutingTimerCallback entered." ));
  7536. if(!QueueTAPILineRequest(
  7537. TSPI_CLOSE_CALL,
  7538. (HDRVCALL) Parameter1,
  7539. NULL,
  7540. LINEDISCONNECTMODE_NOANSWER,
  7541. NULL) )
  7542. {
  7543. H323DBG(( DEBUG_LEVEL_ERROR, "could not post H323 close event." ));
  7544. }
  7545. H323DBG(( DEBUG_LEVEL_TRACE, "CallReroutingTimerCallback exited." ));
  7546. }
  7547. //-----------------------------------------------------------------------------
  7548. //CALL DIVERSION (H450.3) ENCODE/DECODE ROUTINES
  7549. //-----------------------------------------------------------------------------
  7550. BOOL
  7551. CH323Call::HandleH450APDU(
  7552. IN PH323_UU_PDU_h4501SupplementaryService pH450APDU,
  7553. IN DWORD* pdwH450APDUType,
  7554. OUT DWORD* pdwInvokeID,
  7555. IN Q931_SETUP_ASN* pSetupASN
  7556. )
  7557. {
  7558. BOOL retVal = TRUE;
  7559. H4501SupplementaryService * pH450APDUStruct = NULL;
  7560. ServiceApdus_rosApdus * pROSApdu = NULL;
  7561. int iResult;
  7562. BYTE pEncodedArg[H450_ENCODED_ARG_LEN];
  7563. DWORD dwEncodedArgLen;
  7564. DWORD dwOpcode;
  7565. H323DBG(( DEBUG_LEVEL_TRACE, "HandleH450APDU entered:%p.", this ));
  7566. //right now assuming that only one APDU is passed at a time
  7567. iResult = DecodeH450ASN( (void **) &pH450APDUStruct,
  7568. H4501SupplementaryService_PDU,
  7569. pH450APDU->value.value,
  7570. pH450APDU->value.length );
  7571. if( ASN1_FAILED(iResult) || (pH450APDUStruct == NULL) )
  7572. {
  7573. return FALSE;
  7574. }
  7575. if( pH450APDUStruct->serviceApdu.choice != rosApdus_chosen )
  7576. {
  7577. ASN1_FreeDecoded( m_H450ASNCoderInfo.pDecInfo, pH450APDUStruct,
  7578. H4501SupplementaryService_PDU );
  7579. return FALSE;
  7580. }
  7581. pROSApdu = pH450APDUStruct->serviceApdu.u.rosApdus;
  7582. switch( pROSApdu->value.choice )
  7583. {
  7584. case H4503ROS_invoke_chosen:
  7585. if( (pROSApdu->value.u.invoke.opcode.choice != local_chosen) ||
  7586. (pROSApdu->value.u.invoke.argument.length > H450_ENCODED_ARG_LEN) )
  7587. {
  7588. ASN1_FreeDecoded( m_H450ASNCoderInfo.pDecInfo, pH450APDUStruct,
  7589. H4501SupplementaryService_PDU );
  7590. return FALSE;
  7591. }
  7592. *pdwInvokeID = pROSApdu->value.u.invoke.invokeId;
  7593. dwEncodedArgLen = pROSApdu->value.u.invoke.argument.length;
  7594. CopyMemory( (PVOID)pEncodedArg,
  7595. (PVOID)pROSApdu->value.u.invoke.argument.value,
  7596. dwEncodedArgLen );
  7597. dwOpcode = pROSApdu->value.u.invoke.opcode.u.local;
  7598. ASN1_FreeDecoded( m_H450ASNCoderInfo.pDecInfo, pH450APDUStruct,
  7599. H4501SupplementaryService_PDU );
  7600. *pdwH450APDUType = dwOpcode;
  7601. switch( dwOpcode )
  7602. {
  7603. case CALLREROUTING_OPCODE:
  7604. retVal = HandleCallRerouting( pEncodedArg, dwEncodedArgLen );
  7605. break;
  7606. case DIVERTINGLEGINFO1_OPCODE:
  7607. retVal = HandleDiversionLegInfo1( pEncodedArg, dwEncodedArgLen );
  7608. break;
  7609. case DIVERTINGLEGINFO2_OPCODE:
  7610. retVal = HandleDiversionLegInfo2( pEncodedArg, dwEncodedArgLen );
  7611. break;
  7612. case DIVERTINGLEGINFO3_OPCODE:
  7613. //Don't bail out even if this function fails.
  7614. HandleDiversionLegInfo3( pEncodedArg, dwEncodedArgLen );
  7615. break;
  7616. case CHECKRESTRICTION_OPCODE:
  7617. if( pSetupASN == NULL )
  7618. {
  7619. retVal = FALSE;
  7620. }
  7621. else
  7622. {
  7623. retVal = HandleCheckRestriction( pEncodedArg, dwEncodedArgLen,
  7624. pSetupASN );
  7625. }
  7626. if( retVal )
  7627. {
  7628. retVal = SendQ931Message( *pdwInvokeID, 0, 0,
  7629. CONNECTMESSAGETYPE,
  7630. H450_RETURNRESULT|CHECKRESTRICTION_OPCODE );
  7631. }
  7632. break;
  7633. case CTIDENTIFY_OPCODE:
  7634. retVal = HandleCTIdentify( *pdwInvokeID );
  7635. m_dwInvokeID = *pdwInvokeID;
  7636. break;
  7637. case CTINITIATE_OPCODE:
  7638. retVal = HandleCTInitiate( pEncodedArg, dwEncodedArgLen );
  7639. m_dwInvokeID = *pdwInvokeID;
  7640. break;
  7641. case CTSETUP_OPCODE:
  7642. retVal = HandleCTSetup( pEncodedArg, dwEncodedArgLen );
  7643. m_dwInvokeID = *pdwInvokeID;
  7644. break;
  7645. case HOLDNOTIFIC_OPCODE:
  7646. //local hold request from the remote endpoint
  7647. if( m_dwCallState != LINECALLSTATE_ONHOLD )
  7648. {
  7649. SendMSPMessage( SP_MSG_Hold, 0, 1, NULL );
  7650. ChangeCallState( LINECALLSTATE_ONHOLD, 0 );
  7651. }
  7652. break;
  7653. case RETRIEVENOTIFIC_OPCODE:
  7654. //local retrieve request from the remote endpoint
  7655. if( (m_dwCallState == LINECALLSTATE_ONHOLD) &&
  7656. !(m_dwFlags & TSPI_CALL_LOCAL_HOLD) )
  7657. {
  7658. SendMSPMessage( SP_MSG_Hold, 0, 0, NULL );
  7659. ChangeCallState( LINECALLSTATE_CONNECTED, 0 );
  7660. }
  7661. break;
  7662. case REMOTEHOLD_OPCODE:
  7663. //remote hold request from remote endpoint
  7664. if( m_dwCallState != LINECALLSTATE_ONHOLD )
  7665. {
  7666. SendMSPMessage( SP_MSG_Hold, 0, 1, NULL );
  7667. ChangeCallState( LINECALLSTATE_ONHOLD, 0 );
  7668. retVal = SendQ931Message( *pdwInvokeID, 0, 0,
  7669. FACILITYMESSAGETYPE,
  7670. REMOTEHOLD_OPCODE| H450_RETURNRESULT );
  7671. }
  7672. break;
  7673. case REMOTERETRIEVE_OPCODE:
  7674. //remote retrieve request from remote endpoint
  7675. if( m_dwCallState == LINECALLSTATE_ONHOLD )
  7676. {
  7677. SendMSPMessage( SP_MSG_Hold, 0, 0, NULL );
  7678. ChangeCallState( LINECALLSTATE_CONNECTED, 0 );
  7679. retVal = SendQ931Message( *pdwInvokeID, 0, 0,
  7680. FACILITYMESSAGETYPE,
  7681. REMOTERETRIEVE_OPCODE| H450_RETURNRESULT );
  7682. }
  7683. break;
  7684. default:
  7685. _ASSERTE( 0 );
  7686. return FALSE;
  7687. }
  7688. break;
  7689. case H4503ROS_returnResult_chosen:
  7690. *pdwH450APDUType = H4503_DUMMYTYPERETURNRESULT_APDU;
  7691. *pdwInvokeID =
  7692. pH450APDUStruct->serviceApdu.u.rosApdus->value.u.returnResult.invokeId;
  7693. retVal = HandleReturnResultDummyType( pH450APDUStruct );
  7694. // Free the PDU data.
  7695. ASN1_FreeDecoded( m_H450ASNCoderInfo.pDecInfo, pH450APDUStruct,
  7696. H4501SupplementaryService_PDU );
  7697. break;
  7698. case H4503ROS_returnError_chosen:
  7699. *pdwH450APDUType = H4503_RETURNERROR_APDU;
  7700. *pdwInvokeID =
  7701. pH450APDUStruct->serviceApdu.u.rosApdus->value.u.returnError.invokeId;
  7702. retVal = HandleReturnError( pH450APDUStruct );
  7703. // Free the PDU data.
  7704. ASN1_FreeDecoded( m_H450ASNCoderInfo.pDecInfo, pH450APDUStruct,
  7705. H4501SupplementaryService_PDU );
  7706. break;
  7707. case reject_chosen:
  7708. *pdwH450APDUType = H4503_REJECT_APDU;
  7709. *pdwInvokeID =
  7710. pH450APDUStruct->serviceApdu.u.rosApdus->value.u.reject.invokeId;
  7711. retVal = HandleReject( pH450APDUStruct );
  7712. // Free the PDU data.
  7713. ASN1_FreeDecoded( m_H450ASNCoderInfo.pDecInfo, pH450APDUStruct,
  7714. H4501SupplementaryService_PDU );
  7715. break;
  7716. default:
  7717. _ASSERTE( 0 );
  7718. ASN1_FreeDecoded( m_H450ASNCoderInfo.pDecInfo, pH450APDUStruct,
  7719. H4501SupplementaryService_PDU );
  7720. return FALSE;
  7721. break;
  7722. }
  7723. if( retVal == FALSE )
  7724. {
  7725. SendQ931Message( *pdwInvokeID,
  7726. 0,
  7727. 0,
  7728. RELEASECOMPLMESSAGETYPE,
  7729. H450_REJECT );
  7730. }
  7731. H323DBG(( DEBUG_LEVEL_TRACE, "HandleH450APDU exited:%p.", this ));
  7732. return retVal;
  7733. }
  7734. BOOL
  7735. CH323Call::HandleReturnError(
  7736. IN H4501SupplementaryService * pH450APDUStruct
  7737. )
  7738. {
  7739. H323DBG(( DEBUG_LEVEL_TRACE, "HandleReturnError entered:%p.", this ));
  7740. ReturnError * pReturnError =
  7741. &(pH450APDUStruct->serviceApdu.u.rosApdus->value.u.returnError);
  7742. if( IsValidInvokeID( pReturnError->invokeId ) == FALSE )
  7743. {
  7744. //ignore APDU
  7745. return TRUE;
  7746. }
  7747. CloseCall( 0 );
  7748. H323DBG(( DEBUG_LEVEL_TRACE, "HandleReturnError exited:%p.", this ));
  7749. return TRUE;
  7750. }
  7751. BOOL
  7752. CH323Call::HandleReject(
  7753. IN H4501SupplementaryService * pH450APDUStruct
  7754. )
  7755. {
  7756. H323DBG(( DEBUG_LEVEL_TRACE, "HandleReject entered:%p.", this ));
  7757. Reject * pReject =
  7758. &(pH450APDUStruct->serviceApdu.u.rosApdus->value.u.reject);
  7759. if( IsValidInvokeID( pReject->invokeId ) == FALSE )
  7760. {
  7761. //ignore the APDU
  7762. return TRUE;
  7763. }
  7764. CloseCall( 0 );
  7765. H323DBG(( DEBUG_LEVEL_TRACE, "HandleReject exited:%p.", this ));
  7766. return TRUE;
  7767. }
  7768. BOOL
  7769. CH323Call::HandleReturnResultDummyType(
  7770. IN H4501SupplementaryService * pH450APDUStruct
  7771. )
  7772. {
  7773. H323DBG(( DEBUG_LEVEL_TRACE, "HandleReturnResultDummyType entered:%p.",
  7774. this ));
  7775. ReturnResult* dummyResult =
  7776. &(pH450APDUStruct->serviceApdu.u.rosApdus->value.u.returnResult);
  7777. if( dummyResult->bit_mask & result_present )
  7778. {
  7779. if( dummyResult->result.opcode.choice != local_chosen )
  7780. {
  7781. return FALSE;
  7782. }
  7783. switch( dummyResult->result.opcode.u.local )
  7784. {
  7785. case CHECKRESTRICTION_OPCODE:
  7786. //forwarding has been enabled. inform the user
  7787. if( !EnableCallForwarding() )
  7788. {
  7789. return FALSE;
  7790. }
  7791. //close the call
  7792. CloseCall( 0 );
  7793. break;
  7794. case CALLREROUTING_OPCODE:
  7795. //call has been rerouted. log the info or inform the user
  7796. m_dwCallDiversionState = H4503_CALLREROUTING_RRSUCC;
  7797. _ASSERTE( m_hCallReroutingTimer );
  7798. if( m_hCallReroutingTimer != NULL )
  7799. {
  7800. DeleteTimerQueueTimer( H323TimerQueue,
  7801. m_hCallReroutingTimer, NULL );
  7802. m_hCallReroutingTimer = NULL;
  7803. }
  7804. break;
  7805. case CTIDENTIFY_OPCODE:
  7806. //call tranfer has been accepted by transfered-to endpoint
  7807. m_dwCallDiversionState = H4502_CIIDENTIFY_RRSUCC;
  7808. _ASSERTE( m_hCTIdentifyTimer );
  7809. if( m_hCTIdentifyTimer != NULL )
  7810. {
  7811. DeleteTimerQueueTimer( H323TimerQueue, m_hCTIdentifyTimer, NULL );
  7812. m_hCTIdentifyTimer = NULL;
  7813. }
  7814. return HandleCTIdentifyReturnResult( dummyResult->result.result.value,
  7815. dummyResult->result.result.length );
  7816. break;
  7817. case CTINITIATE_OPCODE:
  7818. _ASSERTE( m_hCTInitiateTimer );
  7819. if( m_hCTInitiateTimer != NULL )
  7820. {
  7821. DeleteTimerQueueTimer( H323TimerQueue, m_hCTInitiateTimer, NULL );
  7822. m_hCTInitiateTimer = NULL;
  7823. }
  7824. break;
  7825. case CTSETUP_OPCODE:
  7826. case REMOTEHOLD_OPCODE:
  7827. case REMOTERETRIEVE_OPCODE:
  7828. //no processing required
  7829. break;
  7830. default:
  7831. H323DBG(( DEBUG_LEVEL_ERROR, "wrong opcode.",
  7832. dummyResult->result.opcode.u.local ));
  7833. break;
  7834. }
  7835. }
  7836. else if( IsValidInvokeID( dummyResult->invokeId ) == FALSE )
  7837. {
  7838. return FALSE;
  7839. }
  7840. H323DBG(( DEBUG_LEVEL_TRACE, "HandleReturnResultDummyType exited:%p.",
  7841. this ));
  7842. return TRUE;
  7843. }
  7844. BOOL
  7845. CH323Call::EnableCallForwarding()
  7846. {
  7847. m_dwCallDiversionState = H4503_CHECKRESTRICTION_SUCC;
  7848. if( m_pCallForwardParams != NULL )
  7849. {
  7850. g_pH323Line->SetCallForwardParams( m_pCallForwardParams );
  7851. m_pCallForwardParams = NULL;
  7852. }
  7853. else if( m_pForwardAddress != NULL )
  7854. {
  7855. if( !g_pH323Line->SetCallForwardParams( m_pForwardAddress ) )
  7856. {
  7857. return FALSE;
  7858. }
  7859. m_pForwardAddress = NULL;
  7860. }
  7861. //_ASSERTE( m_hCheckRestrictionTimer );
  7862. //stop the timer
  7863. if( m_hCheckRestrictionTimer )
  7864. {
  7865. DeleteTimerQueueTimer( H323TimerQueue, m_hCheckRestrictionTimer,
  7866. NULL );
  7867. m_hCheckRestrictionTimer = NULL;
  7868. }
  7869. //inform the user about change in line forward state
  7870. (*g_pfnLineEventProc)(
  7871. g_pH323Line->m_htLine,
  7872. (HTAPICALL)NULL,
  7873. (DWORD)LINE_ADDRESSSTATE,
  7874. (DWORD)LINEADDRESSSTATE_FORWARD,
  7875. (DWORD)LINEADDRESSSTATE_FORWARD,
  7876. (DWORD)0
  7877. );
  7878. return TRUE;
  7879. }
  7880. BOOL
  7881. CH323Call::HandleCTIdentifyReturnResult(
  7882. IN BYTE * pEncodeArg,
  7883. IN DWORD dwEncodedArgLen
  7884. )
  7885. {
  7886. PH323_CALL pCall = NULL;
  7887. CTIdentifyRes * pCTIdentifyRes;
  7888. int iResult;
  7889. H323DBG(( DEBUG_LEVEL_TRACE, "HandleCTIdentifyReturnResult entered:%p.", this ));
  7890. if( (pEncodeArg == NULL) || (dwEncodedArgLen==0) )
  7891. {
  7892. return FALSE;
  7893. }
  7894. iResult = DecodeH450ASN( (void **) &pCTIdentifyRes,
  7895. CTIdentifyRes_PDU, pEncodeArg, dwEncodedArgLen );
  7896. if( ASN1_FAILED(iResult) || (pCTIdentifyRes == NULL) )
  7897. {
  7898. return FALSE;
  7899. }
  7900. //send a CTInitiate message on the primary call
  7901. if( !QueueSuppServiceWorkItem( SEND_CTINITIATE_MESSAGE, m_hdRelatedCall,
  7902. (ULONG_PTR)pCTIdentifyRes ))
  7903. {
  7904. //close the consultation call.
  7905. CloseCall( 0 );
  7906. }
  7907. H323DBG(( DEBUG_LEVEL_TRACE, "HandleCTIdentifyReturnResult exited:%p.", this ));
  7908. return TRUE;
  7909. }
  7910. BOOL
  7911. CH323Call::HandleCTIdentify(
  7912. IN DWORD dwInvokeID
  7913. )
  7914. {
  7915. H323DBG(( DEBUG_LEVEL_TRACE, "HandleCTIdentify entered:%p.", this ));
  7916. BOOL retVal = TRUE;
  7917. //send the return result for CTIdentify
  7918. retVal = SendQ931Message( dwInvokeID, 0, 0, FACILITYMESSAGETYPE,
  7919. H450_RETURNRESULT|CTIDENTIFY_OPCODE );
  7920. m_dwCallType |= CALLTYPE_TRANSFERED2_CONSULT;
  7921. //start the timer for CTIdenity message
  7922. if( retVal )
  7923. {
  7924. retVal = CreateTimerQueueTimer(
  7925. &m_hCTIdentifyRRTimer,
  7926. H323TimerQueue,
  7927. CH323Call::CTIdentifyRRExpiredCallback,
  7928. (PVOID)m_hdCall,
  7929. CTIDENTIFYRR_SENT_TIMEOUT, 0,
  7930. WT_EXECUTEINIOTHREAD | WT_EXECUTEONLYONCE );
  7931. }
  7932. H323DBG(( DEBUG_LEVEL_TRACE, "HandleCTIdentify exited:%p.", this ));
  7933. return retVal;
  7934. }
  7935. BOOL
  7936. CH323Call::HandleCTInitiate(
  7937. IN BYTE * pEncodeArg,
  7938. IN DWORD dwEncodedArgLen
  7939. )
  7940. {
  7941. H323DBG(( DEBUG_LEVEL_TRACE, "HandleCTInitiate entered:%p.", this ));
  7942. CTInitiateArg * pCTInitiateArg;
  7943. int iResult = DecodeH450ASN( (void **) &pCTInitiateArg,
  7944. CTInitiateArg_PDU,
  7945. pEncodeArg, dwEncodedArgLen );
  7946. if( ASN1_FAILED(iResult) || (pCTInitiateArg == NULL) )
  7947. {
  7948. return FALSE;
  7949. }
  7950. //argument.callIdentity
  7951. CopyMemory( (PVOID)m_pCTCallIdentity, pCTInitiateArg->callIdentity,
  7952. sizeof(m_pCTCallIdentity) );
  7953. //argument.reroutingNumber
  7954. if( !AliasAddrToAliasNames( &m_pTransferedToAlias,
  7955. (PSetup_UUIE_sourceAddress)
  7956. pCTInitiateArg->reroutingNumber.destinationAddress ) )
  7957. {
  7958. goto cleanup;
  7959. }
  7960. m_dwCallType |= CALLTYPE_TRANSFERED_PRIMARY;
  7961. m_dwCallDiversionState = H4502_CTINITIATE_RECV;
  7962. ASN1_FreeDecoded( m_H450ASNCoderInfo.pDecInfo, pCTInitiateArg,
  7963. CTInitiateArg_PDU );
  7964. //queue an event for creating a new call
  7965. if( !QueueSuppServiceWorkItem( TSPI_DIAL_TRNASFEREDCALL, m_hdCall,
  7966. (ULONG_PTR)m_pTransferedToAlias ))
  7967. {
  7968. H323DBG(( DEBUG_LEVEL_TRACE, "could not post dial transfer event." ));
  7969. }
  7970. H323DBG(( DEBUG_LEVEL_TRACE, "HandleCTInitiate exited:%p.", this ));
  7971. return TRUE;
  7972. cleanup:
  7973. ASN1_FreeDecoded( m_H450ASNCoderInfo.pDecInfo, pCTInitiateArg,
  7974. CTInitiateArg_PDU );
  7975. return FALSE;
  7976. }
  7977. //!!always called in a lock
  7978. BOOL
  7979. CH323Call::HandleCTSetup(
  7980. IN BYTE * pEncodeArg,
  7981. IN DWORD dwEncodedArgLen
  7982. )
  7983. {
  7984. PH323_CALL pCall = NULL;
  7985. WORD wRelatedCallRef = 0;
  7986. int iCTCallID;
  7987. H323DBG(( DEBUG_LEVEL_TRACE, "HandleCTSetup entered:%p.", this ));
  7988. CTSetupArg * pCTSetupArg;
  7989. int iResult = DecodeH450ASN( (void **) &pCTSetupArg,
  7990. CTSetupArg_PDU, pEncodeArg, dwEncodedArgLen );
  7991. if( ASN1_FAILED(iResult) || (pCTSetupArg == NULL) )
  7992. {
  7993. return FALSE;
  7994. }
  7995. m_dwCallType |= CALLTYPE_TRANSFEREDDEST;
  7996. m_dwCallDiversionState = H4502_CTSETUP_RECV;
  7997. iCTCallID = atoi( pCTSetupArg->callIdentity );
  7998. if( iCTCallID != 0 )
  7999. {
  8000. m_hdRelatedCall = g_pH323Line -> GetCallFromCTCallIdentity( iCTCallID );
  8001. if( m_hdRelatedCall )
  8002. {
  8003. if( !QueueSuppServiceWorkItem( STOP_CTIDENTIFYRR_TIMER,
  8004. m_hdRelatedCall, (ULONG_PTR)m_hdCall ))
  8005. {
  8006. m_hdRelatedCall = NULL;
  8007. }
  8008. }
  8009. }
  8010. ASN1_FreeDecoded( m_H450ASNCoderInfo.pDecInfo, pCTSetupArg,
  8011. CTSetupArg_PDU );
  8012. H323DBG(( DEBUG_LEVEL_TRACE, "HandleCTSEtup exited:%p.", this ));
  8013. return TRUE;
  8014. }
  8015. BOOL
  8016. CH323Call::HandleCheckRestriction(
  8017. IN BYTE * pEncodeArg,
  8018. IN DWORD dwEncodedArgLen,
  8019. IN Q931_SETUP_ASN* pSetupASN
  8020. )
  8021. {
  8022. H323DBG(( DEBUG_LEVEL_TRACE, "HandleCheckRestriction entered:%p.", this ));
  8023. CheckRestrictionArgument * pCheckRestriction;
  8024. int iResult = DecodeH450ASN( (void **) &pCheckRestriction,
  8025. CheckRestrictionArgument_PDU,
  8026. pEncodeArg, dwEncodedArgLen );
  8027. if( ASN1_FAILED(iResult) || (pCheckRestriction == NULL) )
  8028. {
  8029. return FALSE;
  8030. }
  8031. if( pSetupASN->pCalleeAliasList != NULL )
  8032. {
  8033. FreeAliasNames( pSetupASN->pCalleeAliasList );
  8034. pSetupASN->pCalleeAliasList = NULL;
  8035. }
  8036. if( !AliasAddrToAliasNames( &(pSetupASN->pCalleeAliasList),
  8037. (PSetup_UUIE_sourceAddress)pCheckRestriction->divertedToNr.destinationAddress ) )
  8038. {
  8039. pSetupASN->pCalleeAliasList = NULL;
  8040. goto cleanup;
  8041. }
  8042. if( pSetupASN->pCallerAliasList != NULL )
  8043. {
  8044. FreeAliasNames( pSetupASN->pCallerAliasList );
  8045. pSetupASN->pCallerAliasList = NULL;
  8046. }
  8047. if( !AliasAddrToAliasNames( &(pSetupASN->pCallerAliasList),
  8048. (PSetup_UUIE_sourceAddress)
  8049. pCheckRestriction->servedUserNr.destinationAddress ) )
  8050. {
  8051. pSetupASN->pCallerAliasList = NULL;
  8052. goto cleanup;
  8053. }
  8054. m_dwCallType |= CALLTYPE_FORWARDCONSULT;
  8055. if( !InitializeIncomingCall( pSetupASN, CALLTYPE_FORWARDCONSULT, 0 ) )
  8056. {
  8057. goto cleanup;
  8058. }
  8059. FreeSetupASN( pSetupASN );
  8060. m_dwStateMachine = Q931_SETUP_RECVD;
  8061. m_dwCallDiversionState = H4503_CHECKRESTRICTION_RECV;
  8062. ASN1_FreeDecoded( m_H450ASNCoderInfo.pDecInfo, pCheckRestriction,
  8063. CheckRestrictionArgument_PDU );
  8064. H323DBG(( DEBUG_LEVEL_TRACE, "HandleCheckRestriction exited:%p.", this ));
  8065. return TRUE;
  8066. cleanup:
  8067. ASN1_FreeDecoded( m_H450ASNCoderInfo.pDecInfo, pCheckRestriction,
  8068. CheckRestrictionArgument_PDU );
  8069. return FALSE;
  8070. }
  8071. BOOL
  8072. CH323Call::HandleDiversionLegInfo1(
  8073. IN BYTE * pEncodeArg,
  8074. IN DWORD dwEncodedArgLen
  8075. )
  8076. {
  8077. H323DBG(( DEBUG_LEVEL_TRACE, "HandleDiversionLegInfo1 entered:%p.", this ));
  8078. DivertingLegInformation1Argument * plegInfo1Invoke;
  8079. int iResult = DecodeH450ASN( (void **) &plegInfo1Invoke,
  8080. DivertingLegInformation1Argument_PDU,
  8081. pEncodeArg, dwEncodedArgLen );
  8082. if( ASN1_FAILED(iResult) || (plegInfo1Invoke == NULL) )
  8083. {
  8084. return FALSE;
  8085. }
  8086. if( m_pCallReroutingInfo == NULL )
  8087. {
  8088. m_pCallReroutingInfo = new CALLREROUTINGINFO;
  8089. if( m_pCallReroutingInfo == NULL )
  8090. {
  8091. return FALSE;
  8092. }
  8093. ZeroMemory( (PVOID)m_pCallReroutingInfo, sizeof(CALLREROUTINGINFO) );
  8094. }
  8095. m_pCallReroutingInfo->diversionReason = plegInfo1Invoke->diversionReason;
  8096. m_pCallReroutingInfo->fPresentAllow = plegInfo1Invoke->subscriptionOption;
  8097. //argument.divertedToNr
  8098. if( m_pCallReroutingInfo->divertedToNrAlias != NULL )
  8099. {
  8100. FreeAliasNames( m_pCallReroutingInfo->divertedToNrAlias );
  8101. m_pCallReroutingInfo->divertedToNrAlias = NULL;
  8102. }
  8103. if( !AliasAddrToAliasNames( &(m_pCallReroutingInfo->divertedToNrAlias),
  8104. (PSetup_UUIE_sourceAddress)
  8105. (plegInfo1Invoke->nominatedNr.destinationAddress) ) )
  8106. {
  8107. goto cleanup;
  8108. }
  8109. m_dwCallType |= CALLTYPE_DIVERTEDSRC_NOROUTING;
  8110. m_dwCallDiversionState = H4503_DIVERSIONLEG1_RECVD;
  8111. ASN1_FreeDecoded( m_H450ASNCoderInfo.pDecInfo, plegInfo1Invoke,
  8112. DivertingLegInformation1Argument_PDU );
  8113. H323DBG(( DEBUG_LEVEL_TRACE, "HandleDiversionLegInfo1 exited:%p.", this ));
  8114. return TRUE;
  8115. cleanup:
  8116. ASN1_FreeDecoded( m_H450ASNCoderInfo.pDecInfo, plegInfo1Invoke,
  8117. DivertingLegInformation1Argument_PDU );
  8118. FreeCallReroutingInfo();
  8119. return FALSE;
  8120. }
  8121. BOOL
  8122. CH323Call::HandleDiversionLegInfo2(
  8123. IN BYTE * pEncodeArg,
  8124. IN DWORD dwEncodedArgLen
  8125. )
  8126. {
  8127. H323DBG(( DEBUG_LEVEL_TRACE, "HandleDiversionLegInfo2 entered:%p.", this ));
  8128. DivertingLegInformation2Argument * plegInfo2Invoke;
  8129. int iResult = DecodeH450ASN( (void **) &plegInfo2Invoke,
  8130. DivertingLegInformation2Argument_PDU,
  8131. pEncodeArg, dwEncodedArgLen );
  8132. if( ASN1_FAILED(iResult) || (plegInfo2Invoke == NULL) )
  8133. {
  8134. return FALSE;
  8135. }
  8136. _ASSERTE(!m_pCallReroutingInfo);
  8137. m_pCallReroutingInfo = new CALLREROUTINGINFO;
  8138. if( m_pCallReroutingInfo == NULL )
  8139. {
  8140. H323DBG(( DEBUG_LEVEL_TRACE, "memory failure." ));
  8141. goto cleanup;
  8142. }
  8143. ZeroMemory( (PVOID)m_pCallReroutingInfo, sizeof(CALLREROUTINGINFO) );
  8144. //argument.diversionCounter
  8145. m_pCallReroutingInfo->diversionCounter =
  8146. plegInfo2Invoke->diversionCounter;
  8147. //argument.diversionReason
  8148. m_pCallReroutingInfo->diversionReason = plegInfo2Invoke->diversionReason;
  8149. if( m_pCallReroutingInfo->divertingNrAlias != NULL )
  8150. {
  8151. FreeAliasNames( m_pCallReroutingInfo->divertingNrAlias );
  8152. m_pCallReroutingInfo->divertingNrAlias = NULL;
  8153. }
  8154. if( (plegInfo2Invoke->bit_mask & divertingNr_present ) &&
  8155. plegInfo2Invoke->divertingNr.destinationAddress )
  8156. {
  8157. //argument.divertingNr
  8158. if( !AliasAddrToAliasNames( &(m_pCallReroutingInfo->divertingNrAlias),
  8159. (PSetup_UUIE_sourceAddress)
  8160. (plegInfo2Invoke->divertingNr.destinationAddress) ) )
  8161. {
  8162. H323DBG(( DEBUG_LEVEL_TRACE, "no divertingnr alias." ));
  8163. //goto cleanup;
  8164. }
  8165. }
  8166. //argument.originalCalledNr
  8167. if( (plegInfo2Invoke->bit_mask &
  8168. DivertingLegInformation2Argument_originalCalledNr_present ) &&
  8169. plegInfo2Invoke->originalCalledNr.destinationAddress )
  8170. {
  8171. if( m_pCallReroutingInfo->originalCalledNr != NULL )
  8172. {
  8173. FreeAliasNames( m_pCallReroutingInfo->originalCalledNr );
  8174. m_pCallReroutingInfo->originalCalledNr = NULL;
  8175. }
  8176. if( !AliasAddrToAliasNames( &(m_pCallReroutingInfo->originalCalledNr),
  8177. (PSetup_UUIE_sourceAddress)
  8178. (plegInfo2Invoke->originalCalledNr.destinationAddress)) )
  8179. {
  8180. H323DBG(( DEBUG_LEVEL_TRACE, "no originalcalled alias." ));
  8181. //goto cleanup;
  8182. }
  8183. }
  8184. m_dwCallType |= CALLTYPE_DIVERTEDDEST;
  8185. m_dwCallDiversionState = H4503_DIVERSIONLEG2_RECVD;
  8186. ASN1_FreeDecoded( m_H450ASNCoderInfo.pDecInfo, plegInfo2Invoke,
  8187. DivertingLegInformation2Argument_PDU );
  8188. H323DBG(( DEBUG_LEVEL_TRACE, "HandleDiversionLegInfo2 exited:%p.", this ));
  8189. return TRUE;
  8190. cleanup:
  8191. ASN1_FreeDecoded( m_H450ASNCoderInfo.pDecInfo, plegInfo2Invoke,
  8192. DivertingLegInformation2Argument_PDU );
  8193. FreeCallReroutingInfo();
  8194. return FALSE;
  8195. }
  8196. void
  8197. CH323Call::FreeCallReroutingInfo(void)
  8198. {
  8199. H323DBG(( DEBUG_LEVEL_TRACE, "FreeCallReroutingInfo entered:%p.", this ));
  8200. if( m_pCallReroutingInfo != NULL )
  8201. {
  8202. FreeAliasNames( m_pCallReroutingInfo->divertingNrAlias );
  8203. FreeAliasNames( m_pCallReroutingInfo->originalCalledNr );
  8204. FreeAliasNames( m_pCallReroutingInfo->divertedToNrAlias );
  8205. FreeAliasNames( m_pCallReroutingInfo->diversionNrAlias );
  8206. delete m_pCallReroutingInfo;
  8207. m_pCallReroutingInfo = NULL;
  8208. }
  8209. H323DBG(( DEBUG_LEVEL_TRACE, "FreeCallReroutingInfo exited:%p.", this ));
  8210. }
  8211. BOOL
  8212. CH323Call::HandleDiversionLegInfo3(
  8213. IN BYTE * pEncodeArg,
  8214. IN DWORD dwEncodedArgLen
  8215. )
  8216. {
  8217. H323DBG(( DEBUG_LEVEL_TRACE, "HandleDiversionLegInfo3 entered:%p.", this ));
  8218. DivertingLegInformation3Argument * plegInfo3Invoke;
  8219. int iResult = DecodeH450ASN( (void **) &plegInfo3Invoke,
  8220. DivertingLegInformation3Argument_PDU,
  8221. pEncodeArg, dwEncodedArgLen );
  8222. if( ASN1_FAILED(iResult) || (plegInfo3Invoke == NULL) )
  8223. {
  8224. return FALSE;
  8225. }
  8226. _ASSERTE(m_pCallReroutingInfo);
  8227. m_pCallReroutingInfo-> fPresentAllow =
  8228. plegInfo3Invoke->presentationAllowedIndicator;
  8229. if( m_pCallReroutingInfo->diversionNrAlias )
  8230. {
  8231. FreeAliasNames( m_pCallReroutingInfo->diversionNrAlias );
  8232. m_pCallReroutingInfo->diversionNrAlias = NULL;
  8233. }
  8234. //argument.redirectionNr
  8235. if( (plegInfo3Invoke->bit_mask & redirectionNr_present ) &&
  8236. plegInfo3Invoke->redirectionNr.destinationAddress )
  8237. {
  8238. if( !AliasAddrToAliasNames( &(m_pCallReroutingInfo->diversionNrAlias),
  8239. (PSetup_UUIE_sourceAddress)
  8240. (plegInfo3Invoke->redirectionNr.destinationAddress) ) )
  8241. {
  8242. //goto cleanup;
  8243. }
  8244. }
  8245. _ASSERTE( (m_dwCallType & CALLTYPE_DIVERTEDSRC ) ||
  8246. (m_dwCallType & CALLTYPE_DIVERTEDSRC_NOROUTING ) );
  8247. m_dwCallDiversionState = H4503_DIVERSIONLEG3_RECVD;
  8248. ASN1_FreeDecoded( m_H450ASNCoderInfo.pDecInfo, plegInfo3Invoke,
  8249. DivertingLegInformation3Argument_PDU );
  8250. H323DBG(( DEBUG_LEVEL_TRACE, "HandleDiversionLegInfo3 exited:%p.", this ));
  8251. return TRUE;
  8252. /*cleanup:
  8253. ASN1_FreeDecoded( m_H450ASNCoderInfo.pDecInfo, plegInfo3Invoke,
  8254. DivertingLegInformation3Argument_PDU );
  8255. FreeCallReroutingInfo();
  8256. return FALSE;
  8257. */
  8258. }
  8259. BOOL
  8260. CH323Call::HandleCallRerouting(
  8261. IN BYTE * pEncodeArg,
  8262. IN DWORD dwEncodedArgLen
  8263. )
  8264. {
  8265. H323DBG(( DEBUG_LEVEL_TRACE, "HandleCallRerouting entered:%p.", this ));
  8266. CallReroutingArgument* pCallReroutingInv;
  8267. int iResult = DecodeH450ASN( (void **) &pCallReroutingInv,
  8268. CallReroutingArgument_PDU,
  8269. pEncodeArg, dwEncodedArgLen );
  8270. if( ASN1_FAILED(iResult) || (pCallReroutingInv == NULL) )
  8271. {
  8272. return FALSE;
  8273. }
  8274. if( m_pCallReroutingInfo == NULL )
  8275. {
  8276. m_pCallReroutingInfo = new CALLREROUTINGINFO;
  8277. if( m_pCallReroutingInfo == NULL )
  8278. {
  8279. goto cleanup;
  8280. }
  8281. ZeroMemory( (PVOID)m_pCallReroutingInfo, sizeof(CALLREROUTINGINFO) );
  8282. }
  8283. if( pCallReroutingInv->diversionCounter > MAX_DIVERSION_COUNTER )
  8284. return FALSE;
  8285. m_pCallReroutingInfo->diversionCounter =
  8286. pCallReroutingInv->diversionCounter;
  8287. m_pCallReroutingInfo->diversionReason = pCallReroutingInv->reroutingReason;
  8288. if( pCallReroutingInv->bit_mask & originalReroutingReason_present )
  8289. {
  8290. m_pCallReroutingInfo->originalDiversionReason =
  8291. pCallReroutingInv->originalReroutingReason;
  8292. }
  8293. else
  8294. {
  8295. m_pCallReroutingInfo->originalDiversionReason =
  8296. pCallReroutingInv->reroutingReason;
  8297. }
  8298. if( ( pCallReroutingInv->bit_mask &
  8299. CallReroutingArgument_originalCalledNr_present ) &&
  8300. pCallReroutingInv->originalCalledNr.destinationAddress )
  8301. {
  8302. if( m_pCallReroutingInfo->originalCalledNr != NULL )
  8303. {
  8304. FreeAliasNames( m_pCallReroutingInfo->originalCalledNr );
  8305. m_pCallReroutingInfo->originalCalledNr = NULL;
  8306. }
  8307. if( !AliasAddrToAliasNames( &(m_pCallReroutingInfo->originalCalledNr),
  8308. (PSetup_UUIE_sourceAddress)
  8309. (pCallReroutingInv->originalCalledNr.destinationAddress) ) )
  8310. {
  8311. //goto cleanup;
  8312. }
  8313. }
  8314. if( m_pCallReroutingInfo->divertingNrAlias != NULL )
  8315. {
  8316. FreeAliasNames( m_pCallReroutingInfo->divertingNrAlias );
  8317. m_pCallReroutingInfo->divertingNrAlias = NULL;
  8318. }
  8319. if( !AliasAddrToAliasNames( &(m_pCallReroutingInfo->divertingNrAlias),
  8320. (PSetup_UUIE_sourceAddress)
  8321. (pCallReroutingInv->lastReroutingNr.destinationAddress) ) )
  8322. {
  8323. goto cleanup;
  8324. }
  8325. if( m_pCallReroutingInfo->divertedToNrAlias != NULL )
  8326. {
  8327. FreeAliasNames( m_pCallReroutingInfo->divertedToNrAlias );
  8328. m_pCallReroutingInfo->divertedToNrAlias = NULL;
  8329. }
  8330. if( !AliasAddrToAliasNames( &(m_pCallReroutingInfo->divertedToNrAlias),
  8331. (PSetup_UUIE_sourceAddress)
  8332. (pCallReroutingInv->calledAddress.destinationAddress) ) )
  8333. {
  8334. goto cleanup;
  8335. }
  8336. m_dwCallType |= CALLTYPE_DIVERTEDSRC;
  8337. m_dwCallDiversionState = H4503_CALLREROUTING_RECVD;
  8338. ASN1_FreeDecoded( m_H450ASNCoderInfo.pDecInfo, pCallReroutingInv,
  8339. CallReroutingArgument_PDU );
  8340. H323DBG(( DEBUG_LEVEL_TRACE, "HandleCallRerouting exited:%p.", this ));
  8341. return TRUE;
  8342. cleanup:
  8343. ASN1_FreeDecoded( m_H450ASNCoderInfo.pDecInfo, pCallReroutingInv,
  8344. CallReroutingArgument_PDU );
  8345. FreeCallReroutingInfo();
  8346. return FALSE;
  8347. }
  8348. BOOL
  8349. CH323Call::EncodeRejectAPDU(
  8350. IN H4501SupplementaryService * pSupplementaryServiceAPDU,
  8351. IN DWORD dwInvokeID,
  8352. OUT BYTE** ppEncodedAPDU,
  8353. OUT DWORD* pdwAPDULen
  8354. )
  8355. {
  8356. WORD wAPDULen;
  8357. H323DBG(( DEBUG_LEVEL_TRACE, "EncodeRejectAPDU entered:%p.", this ));
  8358. ServiceApdus_rosApdus *pROSAPDU =
  8359. pSupplementaryServiceAPDU->serviceApdu.u.rosApdus;
  8360. pROSAPDU->next = NULL;
  8361. pROSAPDU->value.choice = reject_chosen;
  8362. pROSAPDU->value.u.reject.invokeId = (WORD)dwInvokeID;
  8363. pROSAPDU->value.u.reject.problem.choice = H4503ROS_invoke_chosen;
  8364. pROSAPDU->value.u.reject.problem.u.invoke = InvokeProblem_mistypedArgument;
  8365. //call ASN.1 encoding functions
  8366. int rc = EncodeH450ASN( (void *) pSupplementaryServiceAPDU,
  8367. H4501SupplementaryService_PDU,
  8368. ppEncodedAPDU,
  8369. &wAPDULen );
  8370. *pdwAPDULen = wAPDULen;
  8371. if( ASN1_FAILED(rc) || (*ppEncodedAPDU == NULL) || (pdwAPDULen == 0) )
  8372. {
  8373. return FALSE;
  8374. }
  8375. H323DBG(( DEBUG_LEVEL_TRACE, "EncodeRejectAPDU exited:%p.", this ));
  8376. return TRUE;
  8377. }
  8378. BOOL
  8379. CH323Call::EncodeReturnErrorAPDU(
  8380. IN DWORD dwInvokeID,
  8381. IN DWORD dwErrorCode,
  8382. IN H4501SupplementaryService *pH450APDU,
  8383. OUT BYTE** ppEncodedAPDU,
  8384. OUT DWORD* pdwAPDULen
  8385. )
  8386. {
  8387. WORD wAPDULen;
  8388. H323DBG(( DEBUG_LEVEL_TRACE, "EncodeReturnErrorAPDU entered:%p.", this ));
  8389. ServiceApdus_rosApdus *pROSAPDU = pH450APDU->serviceApdu.u.rosApdus;
  8390. pROSAPDU->next = NULL;
  8391. pROSAPDU ->value.choice = H4503ROS_returnError_chosen;
  8392. pROSAPDU ->value.u.returnError.invokeId = (WORD)dwInvokeID;
  8393. pROSAPDU ->value.u.returnError.errcode.choice = local_chosen;
  8394. pROSAPDU ->value.u.returnError.errcode.u.local = dwErrorCode;
  8395. //call ASN.1 encoding functions
  8396. int rc = EncodeH450ASN( (void *) pH450APDU,
  8397. H4501SupplementaryService_PDU,
  8398. ppEncodedAPDU,
  8399. &wAPDULen );
  8400. *pdwAPDULen = wAPDULen;
  8401. if( ASN1_FAILED(rc) || (*ppEncodedAPDU == NULL) || (pdwAPDULen == 0) )
  8402. {
  8403. return FALSE;
  8404. }
  8405. H323DBG(( DEBUG_LEVEL_TRACE, "EncodeReturnErrorAPDU exited:%p.", this ));
  8406. return TRUE;
  8407. }
  8408. BOOL
  8409. CH323Call::EncodeDummyReturnResultAPDU(
  8410. IN DWORD dwInvokeID,
  8411. IN DWORD dwOpCode,
  8412. IN H4501SupplementaryService *pH450APDU,
  8413. OUT BYTE** ppEncodedAPDU,
  8414. OUT DWORD* pdwAPDULen
  8415. )
  8416. {
  8417. BYTE pBufEncodedArg[H450_ENCODED_ARG_LEN];
  8418. WORD wEncodedLen = 0;
  8419. int rc;
  8420. H323DBG(( DEBUG_LEVEL_TRACE, "EncodeDummyReturnResultAPDU entered:%p.",
  8421. this ));
  8422. ServiceApdus_rosApdus *pROSAPDU = pH450APDU->serviceApdu.u.rosApdus;
  8423. pROSAPDU->next = NULL;
  8424. pROSAPDU ->value.choice = H4503ROS_returnResult_chosen;
  8425. pROSAPDU ->value.u.returnResult.invokeId = (WORD)dwInvokeID;
  8426. pROSAPDU ->value.u.returnResult.bit_mask = result_present;
  8427. pROSAPDU ->value.u.returnResult.result.opcode.choice = local_chosen;
  8428. pROSAPDU ->value.u.returnResult.result.opcode.u.local = dwOpCode;
  8429. //dummy result not present
  8430. pROSAPDU ->value.u.returnResult.result.result.length = 0;
  8431. pROSAPDU ->value.u.returnResult.result.result.value = NULL;
  8432. switch( dwOpCode )
  8433. {
  8434. case CTIDENTIFY_OPCODE:
  8435. pROSAPDU ->value.u.returnResult.result.result.value = pBufEncodedArg;
  8436. if( !EncodeCTIdentifyReturnResult( pROSAPDU ) )
  8437. {
  8438. return FALSE;
  8439. }
  8440. break;
  8441. default:
  8442. pROSAPDU ->value.u.returnResult.result.result.value = pBufEncodedArg;
  8443. if( !EncodeDummyResult( pROSAPDU ) )
  8444. {
  8445. return FALSE;
  8446. }
  8447. break;
  8448. }
  8449. //call ASN.1 encoding functions
  8450. rc = EncodeH450ASN( (void *) pH450APDU,
  8451. H4501SupplementaryService_PDU,
  8452. ppEncodedAPDU,
  8453. &wEncodedLen );
  8454. *pdwAPDULen = wEncodedLen;
  8455. if( ASN1_FAILED(rc) || (*ppEncodedAPDU == NULL) || (pdwAPDULen == 0) )
  8456. {
  8457. return FALSE;
  8458. }
  8459. H323DBG(( DEBUG_LEVEL_TRACE, "EncodeDummyReturnResultAPDU exited:%p.",
  8460. this ));
  8461. return TRUE;
  8462. }
  8463. BOOL
  8464. CH323Call::EncodeDummyResult(
  8465. OUT ServiceApdus_rosApdus *pROSAPDU
  8466. )
  8467. {
  8468. DummyRes dummyRes;
  8469. BYTE *pEncodedArg = NULL;
  8470. WORD wEncodedLen = 0;
  8471. int rc;
  8472. UCHAR sData[3] = "MS";
  8473. H323DBG(( DEBUG_LEVEL_TRACE, "EncodeDummyResult entered:%p.", this ));
  8474. ZeroMemory( (PVOID)&dummyRes, sizeof(DummyRes) );
  8475. dummyRes.choice = DummyRes_nonStandardData_chosen;
  8476. dummyRes.u.nonStandardData.nonStandardIdentifier.choice
  8477. = H225NonStandardIdentifier_h221NonStandard_chosen;
  8478. dummyRes.u.nonStandardData.nonStandardIdentifier.u.h221NonStandard.t35CountryCode
  8479. = H221_COUNTRY_CODE_USA;
  8480. dummyRes.u.nonStandardData.nonStandardIdentifier.u.h221NonStandard.t35Extension
  8481. = H221_COUNTRY_EXT_USA;
  8482. dummyRes.u.nonStandardData.nonStandardIdentifier.u.h221NonStandard.manufacturerCode
  8483. = H221_MFG_CODE_MICROSOFT;
  8484. dummyRes.u.nonStandardData.data.length = 2;
  8485. dummyRes.u.nonStandardData.data.value = sData;
  8486. //encode the return result argument.
  8487. rc = EncodeH450ASN( (void*) &dummyRes,
  8488. DummyRes_PDU,
  8489. &pEncodedArg,
  8490. &wEncodedLen );
  8491. if( ASN1_FAILED(rc) || (pEncodedArg == NULL) || (wEncodedLen == 0) )
  8492. {
  8493. return FALSE;
  8494. }
  8495. pROSAPDU ->value.u.returnResult.result.result.length = wEncodedLen;
  8496. CopyMemory( (PVOID)pROSAPDU ->value.u.returnResult.result.result.value,
  8497. pEncodedArg, wEncodedLen );
  8498. //free the previous asn buffer before
  8499. ASN1_FreeEncoded(m_ASNCoderInfo.pEncInfo, pEncodedArg );
  8500. H323DBG(( DEBUG_LEVEL_TRACE, "EncodeDummyResult exited:%p.", this ));
  8501. return TRUE;
  8502. }
  8503. BOOL
  8504. CH323Call::EncodeCTIdentifyReturnResult(
  8505. OUT ServiceApdus_rosApdus *pROSAPDU
  8506. )
  8507. {
  8508. CTIdentifyRes cTIdentifyRes;
  8509. BYTE *pEncodedArg = NULL;
  8510. WORD wEncodedLen = 0;
  8511. int iCallID;
  8512. int rc;
  8513. ZeroMemory( (PVOID)&cTIdentifyRes, sizeof(CTIdentifyRes) );
  8514. iCallID = g_pH323Line -> GetCTCallIdentity(m_hdCall );
  8515. if( iCallID == 0 )
  8516. {
  8517. return FALSE;
  8518. }
  8519. //argument.callIdentity
  8520. _itoa( iCallID, (char*)m_pCTCallIdentity, 10 );
  8521. CopyMemory( (PVOID)cTIdentifyRes.callIdentity, (PVOID)m_pCTCallIdentity,
  8522. sizeof(m_pCTCallIdentity) );
  8523. //argument.reroutingNumber
  8524. cTIdentifyRes.reroutingNumber.bit_mask = 0;
  8525. cTIdentifyRes.reroutingNumber.destinationAddress =
  8526. (PEndpointAddress_destinationAddress)
  8527. SetMsgAddressAlias( m_pCalleeAliasNames );
  8528. if( cTIdentifyRes.reroutingNumber.destinationAddress == NULL )
  8529. {
  8530. return FALSE;
  8531. }
  8532. //encode the return result argument.
  8533. rc = EncodeH450ASN( (void *) &cTIdentifyRes,
  8534. CTIdentifyRes_PDU,
  8535. &pEncodedArg,
  8536. &wEncodedLen );
  8537. if( ASN1_FAILED(rc) || (pEncodedArg == NULL) || (wEncodedLen == 0) )
  8538. {
  8539. FreeAddressAliases( (PSetup_UUIE_destinationAddress)
  8540. cTIdentifyRes.reroutingNumber.destinationAddress );
  8541. return FALSE;
  8542. }
  8543. pROSAPDU ->value.u.returnResult.result.result.length = wEncodedLen;
  8544. CopyMemory( (PVOID)pROSAPDU ->value.u.returnResult.result.result.value,
  8545. pEncodedArg, wEncodedLen );
  8546. //free the previous asn buffer before
  8547. ASN1_FreeEncoded(m_ASNCoderInfo.pEncInfo, pEncodedArg );
  8548. FreeAddressAliases( (PSetup_UUIE_destinationAddress)
  8549. cTIdentifyRes.reroutingNumber.destinationAddress );
  8550. return TRUE;
  8551. }
  8552. //supplemantary services functions
  8553. BOOL
  8554. CH323Call::EncodeCheckRestrictionAPDU(
  8555. OUT H4501SupplementaryService *pSupplementaryServiceAPDU,
  8556. OUT BYTE** ppEncodedAPDU,
  8557. OUT DWORD* pdwAPDULen
  8558. )
  8559. {
  8560. BYTE *pEncodedArg = NULL;
  8561. WORD wEncodedLen = 0;
  8562. BYTE pBufEncodedArg[H450_ENCODED_ARG_LEN];
  8563. BOOL retVal = FALSE;
  8564. int rc = 0;
  8565. TCHAR szMsg[20];
  8566. H323DBG(( DEBUG_LEVEL_TRACE, "EncodeCheckRestrictionAPDU entered:%p.",
  8567. this ));
  8568. ServiceApdus_rosApdus *pROSAPDU =
  8569. pSupplementaryServiceAPDU->serviceApdu.u.rosApdus;
  8570. pROSAPDU->next = NULL;
  8571. pROSAPDU->value.choice = H4503ROS_invoke_chosen;
  8572. pROSAPDU->value.u.invoke.bit_mask = argument_present;
  8573. //invoke ID
  8574. pROSAPDU->value.u.invoke.invokeId = g_pH323Line->GetNextInvokeID();
  8575. m_dwInvokeID = pROSAPDU->value.u.invoke.invokeId;
  8576. //opcode
  8577. pROSAPDU->value.u.invoke.opcode.choice = local_chosen;
  8578. pROSAPDU->value.u.invoke.opcode.u.local = CHECKRESTRICTION_OPCODE;
  8579. //argument
  8580. CheckRestrictionArgument checkRestrictionArgument;
  8581. ZeroMemory( (PVOID)&checkRestrictionArgument,
  8582. sizeof(CheckRestrictionArgument) );
  8583. //argument.divertedToNR
  8584. checkRestrictionArgument.divertedToNr.bit_mask = 0;
  8585. checkRestrictionArgument.divertedToNr.destinationAddress =
  8586. (PEndpointAddress_destinationAddress)
  8587. SetMsgAddressAlias( m_pCalleeAliasNames );
  8588. if( checkRestrictionArgument.divertedToNr.destinationAddress == NULL )
  8589. {
  8590. goto cleanup;
  8591. }
  8592. if( m_pCallerAliasNames == NULL )
  8593. {
  8594. m_pCallerAliasNames = new H323_ALIASNAMES;
  8595. if( m_pCallerAliasNames == NULL )
  8596. {
  8597. H323DBG(( DEBUG_LEVEL_ERROR, "could not allocate caller name." ));
  8598. goto cleanup;
  8599. }
  8600. memset( (PVOID)m_pCallerAliasNames, 0, sizeof(H323_ALIASNAMES) );
  8601. LoadString( g_hInstance,
  8602. IDS_UNKNOWN,
  8603. szMsg,
  8604. 20
  8605. );
  8606. if( !AddAliasItem( m_pCallerAliasNames,
  8607. szMsg,
  8608. h323_ID_chosen ) )
  8609. {
  8610. goto cleanup;
  8611. }
  8612. //H323DBG(( DEBUG_LEVEL_ERROR, "Caller alias count:%d : %p", m_pCallerAliasNames->wCount, this ));
  8613. }
  8614. //argument.servedUserNR
  8615. checkRestrictionArgument.servedUserNr.bit_mask = 0;
  8616. checkRestrictionArgument.servedUserNr.destinationAddress =
  8617. (PEndpointAddress_destinationAddress)
  8618. SetMsgAddressAlias( m_pCallerAliasNames );
  8619. //H323DBG(( DEBUG_LEVEL_ERROR, "Caller alias count:%d : %p", m_pCallerAliasNames->wCount, this ));
  8620. if( checkRestrictionArgument.servedUserNr.destinationAddress == NULL )
  8621. {
  8622. goto cleanup;
  8623. }
  8624. //argument.basicservice
  8625. checkRestrictionArgument.basicService = allServices;
  8626. //encode the checkrestriction argument.
  8627. rc = EncodeH450ASN( (void *) &checkRestrictionArgument,
  8628. CheckRestrictionArgument_PDU,
  8629. &pEncodedArg,
  8630. &wEncodedLen );
  8631. if( ASN1_FAILED(rc) || (pEncodedArg == NULL) || (wEncodedLen == 0) )
  8632. {
  8633. goto cleanup;
  8634. }
  8635. pROSAPDU->value.u.invoke.argument.value = pBufEncodedArg;
  8636. pROSAPDU->value.u.invoke.argument.length = wEncodedLen;
  8637. CopyMemory( (PVOID)pROSAPDU->value.u.invoke.argument.value,
  8638. pEncodedArg, wEncodedLen );
  8639. //free the previous asn buffer before
  8640. ASN1_FreeEncoded(m_ASNCoderInfo.pEncInfo, pEncodedArg );
  8641. //call ASN.1 encoding functions
  8642. rc = EncodeH450ASN( (void *) pSupplementaryServiceAPDU,
  8643. H4501SupplementaryService_PDU,
  8644. ppEncodedAPDU,
  8645. &wEncodedLen );
  8646. *pdwAPDULen = wEncodedLen;
  8647. if( ASN1_FAILED(rc) || (*ppEncodedAPDU == NULL) || (pdwAPDULen == 0) )
  8648. {
  8649. goto cleanup;
  8650. }
  8651. H323DBG(( DEBUG_LEVEL_TRACE, "EncodeCheckRestrictionAPDU exited:%p.",
  8652. this ));
  8653. retVal = TRUE;
  8654. cleanup:
  8655. if( checkRestrictionArgument.servedUserNr.destinationAddress )
  8656. {
  8657. FreeAddressAliases( (PSetup_UUIE_destinationAddress)
  8658. checkRestrictionArgument.servedUserNr.destinationAddress );
  8659. }
  8660. if( checkRestrictionArgument.divertedToNr.destinationAddress )
  8661. {
  8662. FreeAddressAliases( (PSetup_UUIE_destinationAddress)
  8663. checkRestrictionArgument.divertedToNr.destinationAddress );
  8664. }
  8665. return retVal;
  8666. }
  8667. BOOL
  8668. CH323Call::EncodeDivertingLeg2APDU(
  8669. OUT H4501SupplementaryService *pSupplementaryServiceAPDU,
  8670. OUT BYTE** ppEncodedAPDU,
  8671. OUT DWORD* pdwAPDULen
  8672. )
  8673. {
  8674. BYTE *pEncodedArg = NULL;
  8675. WORD wEncodedLen = 0;
  8676. BYTE pBufEncodedArg[H450_ENCODED_ARG_LEN];
  8677. BOOL retVal = FALSE;
  8678. int rc = 0;
  8679. H323DBG(( DEBUG_LEVEL_TRACE, "EncodeDivertingLeg2APDU entered:%p.", this ));
  8680. pSupplementaryServiceAPDU->interpretationApdu.choice =
  8681. discardAnyUnrecognizedInvokePdu_chosen;
  8682. ServiceApdus_rosApdus *pROSAPDU =
  8683. pSupplementaryServiceAPDU->serviceApdu.u.rosApdus;
  8684. pROSAPDU->next = NULL;
  8685. pROSAPDU->value.choice = H4503ROS_invoke_chosen;
  8686. pROSAPDU->value.u.invoke.bit_mask = argument_present;
  8687. //invoke ID
  8688. pROSAPDU->value.u.invoke.invokeId = g_pH323Line->GetNextInvokeID();
  8689. //opcode
  8690. pROSAPDU->value.u.invoke.opcode.choice = local_chosen;
  8691. pROSAPDU->value.u.invoke.opcode.u.local = DIVERTINGLEGINFO2_OPCODE;
  8692. //argument
  8693. DivertingLegInformation2Argument divertLegInfo2Arg;
  8694. ZeroMemory( (PVOID)&divertLegInfo2Arg,
  8695. sizeof(DivertingLegInformation2Argument) );
  8696. //argument.diversionCounter
  8697. divertLegInfo2Arg.diversionCounter
  8698. = (WORD)m_pCallReroutingInfo->diversionCounter;
  8699. //argument.diversionreason
  8700. divertLegInfo2Arg.diversionReason = m_pCallReroutingInfo->diversionReason;
  8701. //argument.originalDiversionReason
  8702. if( m_pCallReroutingInfo->originalDiversionReason != 0 )
  8703. {
  8704. divertLegInfo2Arg.originalDiversionReason =
  8705. m_pCallReroutingInfo->originalDiversionReason;
  8706. divertLegInfo2Arg.bit_mask |= originalDiversionReason_present;
  8707. }
  8708. //argument.divertingNr
  8709. if( m_pCallReroutingInfo->divertingNrAlias != NULL )
  8710. {
  8711. divertLegInfo2Arg.bit_mask |= divertingNr_present;
  8712. divertLegInfo2Arg.divertingNr.bit_mask = 0;
  8713. divertLegInfo2Arg.divertingNr.destinationAddress
  8714. = (PEndpointAddress_destinationAddress)
  8715. SetMsgAddressAlias( m_pCallReroutingInfo->divertingNrAlias );
  8716. if( divertLegInfo2Arg.divertingNr.destinationAddress == NULL )
  8717. {
  8718. return FALSE;
  8719. }
  8720. }
  8721. //argument.originalCalledNr
  8722. if( m_pCallReroutingInfo->originalCalledNr != NULL )
  8723. {
  8724. divertLegInfo2Arg.bit_mask |=
  8725. DivertingLegInformation2Argument_originalCalledNr_present;
  8726. divertLegInfo2Arg.originalCalledNr.bit_mask = 0;
  8727. divertLegInfo2Arg.originalCalledNr.destinationAddress
  8728. = (PEndpointAddress_destinationAddress)
  8729. SetMsgAddressAlias( m_pCallReroutingInfo->originalCalledNr );
  8730. if( divertLegInfo2Arg.originalCalledNr.destinationAddress == NULL )
  8731. {
  8732. goto cleanup;
  8733. }
  8734. }
  8735. //encode the divertingleg2 argument.
  8736. rc = EncodeH450ASN( (void *) &divertLegInfo2Arg,
  8737. DivertingLegInformation2Argument_PDU,
  8738. &pEncodedArg,
  8739. &wEncodedLen );
  8740. if( ASN1_FAILED(rc) || (pEncodedArg == NULL) || (wEncodedLen == 0) )
  8741. {
  8742. goto cleanup;
  8743. }
  8744. pROSAPDU->value.u.invoke.argument.value = pBufEncodedArg;
  8745. pROSAPDU->value.u.invoke.argument.length = wEncodedLen;
  8746. CopyMemory( (PVOID)pROSAPDU->value.u.invoke.argument.value,
  8747. pEncodedArg, wEncodedLen );
  8748. //free the previous asn buffer before encoding new one
  8749. ASN1_FreeEncoded(m_ASNCoderInfo.pEncInfo, pEncodedArg );
  8750. //call ASN.1 encoding function for APDU
  8751. rc = EncodeH450ASN( (void *) pSupplementaryServiceAPDU,
  8752. H4501SupplementaryService_PDU,
  8753. ppEncodedAPDU,
  8754. &wEncodedLen );
  8755. *pdwAPDULen = wEncodedLen;
  8756. if( ASN1_FAILED(rc) || (*ppEncodedAPDU == NULL) || (pdwAPDULen == 0) )
  8757. {
  8758. goto cleanup;
  8759. }
  8760. H323DBG(( DEBUG_LEVEL_TRACE, "EncodeDivertingLeg2APDU exited:%p.", this ));
  8761. retVal= TRUE;
  8762. cleanup:
  8763. if( divertLegInfo2Arg.divertingNr.destinationAddress )
  8764. {
  8765. FreeAddressAliases( (PSetup_UUIE_destinationAddress)
  8766. divertLegInfo2Arg.divertingNr.destinationAddress );
  8767. }
  8768. if( divertLegInfo2Arg.originalCalledNr.destinationAddress )
  8769. {
  8770. FreeAddressAliases( (PSetup_UUIE_destinationAddress)
  8771. divertLegInfo2Arg.originalCalledNr.destinationAddress );
  8772. }
  8773. return retVal;
  8774. }
  8775. BOOL
  8776. CH323Call::EncodeDivertingLeg3APDU(
  8777. OUT H4501SupplementaryService *pSupplementaryServiceAPDU,
  8778. OUT BYTE** ppEncodedAPDU,
  8779. OUT DWORD* pdwAPDULen
  8780. )
  8781. {
  8782. BYTE *pEncodedArg = NULL;
  8783. WORD wEncodedLen = 0;
  8784. BYTE pBufEncodedArg[H450_ENCODED_ARG_LEN];
  8785. H323DBG(( DEBUG_LEVEL_TRACE, "EncodeDivertingLeg3APDU entered:%p.", this ));
  8786. pSupplementaryServiceAPDU->interpretationApdu.choice =
  8787. discardAnyUnrecognizedInvokePdu_chosen;
  8788. ServiceApdus_rosApdus *pROSAPDU =
  8789. pSupplementaryServiceAPDU->serviceApdu.u.rosApdus;
  8790. pROSAPDU->next = NULL;
  8791. pROSAPDU->value.choice = H4503ROS_invoke_chosen;
  8792. pROSAPDU->value.u.invoke.bit_mask = argument_present;
  8793. //invoke ID
  8794. pROSAPDU->value.u.invoke.invokeId = g_pH323Line->GetNextInvokeID();
  8795. //opcode
  8796. pROSAPDU->value.u.invoke.opcode.choice = local_chosen;
  8797. pROSAPDU->value.u.invoke.opcode.u.local = DIVERTINGLEGINFO3_OPCODE;
  8798. //argument
  8799. DivertingLegInformation3Argument divertLegInfo3Arg;
  8800. ZeroMemory( (PVOID)&divertLegInfo3Arg,
  8801. sizeof(DivertingLegInformation3Argument) );
  8802. //argument.presentationallowed
  8803. divertLegInfo3Arg.presentationAllowedIndicator = TRUE;
  8804. //argument.redirectionNr
  8805. divertLegInfo3Arg.redirectionNr.bit_mask = 0;
  8806. divertLegInfo3Arg.redirectionNr.destinationAddress =
  8807. (PEndpointAddress_destinationAddress)
  8808. SetMsgAddressAlias( m_pCalleeAliasNames );
  8809. if( divertLegInfo3Arg.redirectionNr.destinationAddress )
  8810. {
  8811. divertLegInfo3Arg.bit_mask |= redirectionNr_present;
  8812. }
  8813. //encode the divertingleg3 argument.
  8814. int rc = EncodeH450ASN( (void *) &divertLegInfo3Arg,
  8815. DivertingLegInformation3Argument_PDU,
  8816. &pEncodedArg,
  8817. &wEncodedLen );
  8818. if( ASN1_FAILED(rc) || (pEncodedArg == NULL) || (wEncodedLen == 0) )
  8819. {
  8820. if( divertLegInfo3Arg.redirectionNr.destinationAddress )
  8821. {
  8822. FreeAddressAliases( (PSetup_UUIE_destinationAddress)
  8823. divertLegInfo3Arg.redirectionNr.destinationAddress );
  8824. }
  8825. return FALSE;
  8826. }
  8827. pROSAPDU->value.u.invoke.argument.value = pBufEncodedArg;
  8828. pROSAPDU->value.u.invoke.argument.length = wEncodedLen;
  8829. CopyMemory( (PVOID)pROSAPDU->value.u.invoke.argument.value,
  8830. pEncodedArg, wEncodedLen );
  8831. //free the previous asn buffer before encoding new one
  8832. ASN1_FreeEncoded(m_ASNCoderInfo.pEncInfo, pEncodedArg );
  8833. if( divertLegInfo3Arg.redirectionNr.destinationAddress )
  8834. {
  8835. FreeAddressAliases( (PSetup_UUIE_destinationAddress)
  8836. divertLegInfo3Arg.redirectionNr.destinationAddress );
  8837. }
  8838. //call ASN.1 encoding function for APDU
  8839. rc = EncodeH450ASN( (void *) pSupplementaryServiceAPDU,
  8840. H4501SupplementaryService_PDU,
  8841. ppEncodedAPDU,
  8842. &wEncodedLen );
  8843. *pdwAPDULen = wEncodedLen;
  8844. if( ASN1_FAILED(rc) || (*ppEncodedAPDU == NULL) || (pdwAPDULen == 0) )
  8845. {
  8846. return FALSE;
  8847. }
  8848. H323DBG(( DEBUG_LEVEL_TRACE, "EncodeDivertingLeg3APDU exited:%p.", this ));
  8849. return TRUE;
  8850. }
  8851. BOOL
  8852. CH323Call::EncodeCallReroutingAPDU(
  8853. OUT H4501SupplementaryService *pSupplementaryServiceAPDU,
  8854. OUT BYTE** ppEncodedAPDU,
  8855. OUT DWORD* pdwAPDULen
  8856. )
  8857. {
  8858. BYTE *pEncodedArg = NULL;
  8859. WORD wEncodedLen = 0;
  8860. BYTE pBufEncodedArg[H450_ENCODED_ARG_LEN];
  8861. BOOL retVal = FALSE;
  8862. int rc = 0;
  8863. UCHAR bearerCap[5];
  8864. TCHAR szMsg[20];
  8865. PH323_ALIASNAMES pCallerAliasNames = m_pCallerAliasNames;
  8866. H323DBG(( DEBUG_LEVEL_TRACE, "EncodeCallReroutingAPDU entered:%p.", this ));
  8867. _ASSERTE( m_pCallReroutingInfo );
  8868. ServiceApdus_rosApdus *pROSAPDU =
  8869. pSupplementaryServiceAPDU->serviceApdu.u.rosApdus;
  8870. pROSAPDU->next = NULL;
  8871. pROSAPDU->value.choice = H4503ROS_invoke_chosen;
  8872. pROSAPDU->value.u.invoke.bit_mask = argument_present;
  8873. //invoke ID
  8874. pROSAPDU->value.u.invoke.invokeId = g_pH323Line->GetNextInvokeID();
  8875. m_dwInvokeID = pROSAPDU->value.u.invoke.invokeId;
  8876. //opcode
  8877. pROSAPDU->value.u.invoke.opcode.choice = local_chosen;
  8878. pROSAPDU->value.u.invoke.opcode.u.local = CALLREROUTING_OPCODE;
  8879. //argument
  8880. CallReroutingArgument callReroutingArg;
  8881. ZeroMemory( (PVOID)&callReroutingArg, sizeof(CallReroutingArgument) );
  8882. //argument.reroutingReason
  8883. callReroutingArg.reroutingReason = m_pCallReroutingInfo->diversionReason;
  8884. //argument.originalReroutingReason
  8885. if( m_pCallReroutingInfo->originalDiversionReason != 0 )
  8886. {
  8887. callReroutingArg.originalReroutingReason
  8888. = m_pCallReroutingInfo->originalDiversionReason;
  8889. }
  8890. else
  8891. {
  8892. callReroutingArg.originalReroutingReason
  8893. = m_pCallReroutingInfo->diversionReason;
  8894. }
  8895. //argument.diversionCounter
  8896. callReroutingArg.diversionCounter =
  8897. ++(m_pCallReroutingInfo->diversionCounter);
  8898. //argument.calledAddress
  8899. callReroutingArg.calledAddress.bit_mask = 0;
  8900. callReroutingArg.calledAddress.destinationAddress
  8901. = (PEndpointAddress_destinationAddress)
  8902. SetMsgAddressAlias(m_pCallReroutingInfo->divertedToNrAlias);
  8903. if( callReroutingArg.calledAddress.destinationAddress == NULL )
  8904. {
  8905. goto cleanup;
  8906. }
  8907. //argument.lastReroutingNr
  8908. callReroutingArg.lastReroutingNr.bit_mask = 0;
  8909. callReroutingArg.lastReroutingNr.destinationAddress
  8910. = (PEndpointAddress_destinationAddress)
  8911. SetMsgAddressAlias(m_pCalleeAliasNames);
  8912. if( callReroutingArg.lastReroutingNr.destinationAddress == NULL )
  8913. {
  8914. goto cleanup;
  8915. }
  8916. //argument.subscriptionoption
  8917. callReroutingArg.subscriptionOption = notificationWithDivertedToNr;
  8918. //argument.callingNumber
  8919. callReroutingArg.callingNumber.bit_mask = 0;
  8920. if( pCallerAliasNames == NULL )
  8921. {
  8922. pCallerAliasNames = new H323_ALIASNAMES;
  8923. if( pCallerAliasNames == NULL )
  8924. {
  8925. H323DBG(( DEBUG_LEVEL_ERROR, "could not allocate caller name." ));
  8926. goto cleanup;
  8927. }
  8928. memset( (PVOID)pCallerAliasNames, 0, sizeof(H323_ALIASNAMES) );
  8929. LoadString( g_hInstance,
  8930. IDS_UNKNOWN,
  8931. szMsg,
  8932. 20
  8933. );
  8934. if( !AddAliasItem( pCallerAliasNames,
  8935. szMsg,
  8936. h323_ID_chosen ) )
  8937. {
  8938. goto cleanup;
  8939. }
  8940. }
  8941. callReroutingArg.callingNumber.destinationAddress
  8942. = (PEndpointAddress_destinationAddress)
  8943. SetMsgAddressAlias(pCallerAliasNames);
  8944. if( callReroutingArg.callingNumber.destinationAddress == NULL )
  8945. {
  8946. goto cleanup;
  8947. }
  8948. //argumnt.h225infoelement
  8949. callReroutingArg.h225InfoElement.length = 5;
  8950. callReroutingArg.h225InfoElement.value = bearerCap;
  8951. bearerCap[0]= IDENT_BEARERCAP;
  8952. bearerCap[1]= 0x03; //length of the bearer capability
  8953. bearerCap[2]= (BYTE)(BEAR_EXT_BIT | BEAR_CCITT | BEAR_UNRESTRICTED_DIGITAL);
  8954. bearerCap[3]= BEAR_EXT_BIT | 0x17;
  8955. bearerCap[4]= (BYTE)(BEAR_EXT_BIT | BEAR_LAYER1_INDICATOR |
  8956. BEAR_LAYER1_H221_H242);
  8957. //argument.callingNumber
  8958. if( m_pCallReroutingInfo->originalCalledNr != NULL )
  8959. {
  8960. callReroutingArg.originalCalledNr.bit_mask = 0;
  8961. callReroutingArg.originalCalledNr.destinationAddress
  8962. = (PEndpointAddress_destinationAddress)
  8963. SetMsgAddressAlias( m_pCallReroutingInfo->originalCalledNr );
  8964. if( callReroutingArg.originalCalledNr.destinationAddress != NULL )
  8965. {
  8966. callReroutingArg.bit_mask |=
  8967. CallReroutingArgument_originalCalledNr_present;
  8968. }
  8969. }
  8970. //encode the callrerouting argument.
  8971. rc = EncodeH450ASN( (void *) &callReroutingArg,
  8972. CallReroutingArgument_PDU,
  8973. &pEncodedArg,
  8974. &wEncodedLen );
  8975. if( ASN1_FAILED(rc) || (pEncodedArg == NULL) || (wEncodedLen == 0) )
  8976. {
  8977. goto cleanup;
  8978. }
  8979. pROSAPDU->value.u.invoke.argument.value = pBufEncodedArg;
  8980. pROSAPDU->value.u.invoke.argument.length = wEncodedLen;
  8981. CopyMemory( (PVOID)pROSAPDU->value.u.invoke.argument.value,
  8982. pEncodedArg, wEncodedLen );
  8983. //free the previous asn buffer before encoding new one
  8984. ASN1_FreeEncoded(m_ASNCoderInfo.pEncInfo, pEncodedArg );
  8985. //call ASN.1 encoding function for APDU
  8986. rc = EncodeH450ASN( (void *) pSupplementaryServiceAPDU,
  8987. H4501SupplementaryService_PDU,
  8988. ppEncodedAPDU,
  8989. &wEncodedLen );
  8990. *pdwAPDULen = wEncodedLen;
  8991. if( ASN1_FAILED(rc) || (*ppEncodedAPDU == NULL) || (pdwAPDULen == 0) )
  8992. {
  8993. goto cleanup;
  8994. }
  8995. H323DBG(( DEBUG_LEVEL_TRACE, "EncodeCallReroutingAPDU exited:%p.", this ));
  8996. retVal = TRUE;
  8997. cleanup:
  8998. if( pCallerAliasNames != m_pCallerAliasNames )
  8999. {
  9000. FreeAliasNames( pCallerAliasNames );
  9001. }
  9002. FreeCallReroutingArg( &callReroutingArg );
  9003. return retVal;
  9004. }
  9005. //No need to call in a lock!!
  9006. void
  9007. CH323Call::FreeCallReroutingArg(
  9008. CallReroutingArgument* pCallReroutingArg
  9009. )
  9010. {
  9011. //free all the aliases
  9012. if( pCallReroutingArg->calledAddress.destinationAddress != NULL )
  9013. {
  9014. FreeAddressAliases( (PSetup_UUIE_destinationAddress)
  9015. pCallReroutingArg->calledAddress.destinationAddress );
  9016. }
  9017. if( pCallReroutingArg->lastReroutingNr.destinationAddress != NULL )
  9018. {
  9019. FreeAddressAliases( (PSetup_UUIE_destinationAddress)
  9020. pCallReroutingArg->lastReroutingNr.destinationAddress );
  9021. }
  9022. if( pCallReroutingArg->callingNumber.destinationAddress != NULL )
  9023. {
  9024. FreeAddressAliases( (PSetup_UUIE_destinationAddress)
  9025. pCallReroutingArg->callingNumber.destinationAddress );
  9026. }
  9027. if( pCallReroutingArg->originalCalledNr.destinationAddress != NULL )
  9028. {
  9029. FreeAddressAliases( (PSetup_UUIE_destinationAddress)
  9030. pCallReroutingArg->originalCalledNr.destinationAddress );
  9031. }
  9032. }
  9033. // static
  9034. void
  9035. NTAPI CH323Call::CallEstablishmentExpiredCallback(
  9036. IN PVOID DriverCallHandle, // HDRVCALL
  9037. IN BOOLEAN bTimer)
  9038. {
  9039. PH323_CALL pCall = NULL;
  9040. H323DBG(( DEBUG_LEVEL_TRACE, "CallEstablishmentExpiredCallback entered." ));
  9041. //if the timer expired
  9042. _ASSERTE( bTimer );
  9043. H323DBG(( DEBUG_LEVEL_TRACE, "Q931 setup expired event recvd." ));
  9044. pCall=g_pH323Line -> FindH323CallAndLock((HDRVCALL) DriverCallHandle);
  9045. if( pCall != NULL )
  9046. {
  9047. if( pCall -> GetStateMachine() != Q931_CONNECT_RECVD )
  9048. {
  9049. //time out has occured
  9050. pCall -> CloseCall( LINEDISCONNECTMODE_NOANSWER );
  9051. }
  9052. pCall -> Unlock();
  9053. }
  9054. H323DBG(( DEBUG_LEVEL_TRACE, "CallEstablishmentExpiredCallback exited." ));
  9055. }
  9056. //-----------------------------------------------------------------------------
  9057. //CALL TRANSFER (H450.2) ENCODE/DECODE ROUTINES
  9058. //-----------------------------------------------------------------------------
  9059. BOOL
  9060. CH323Call::EncodeH450APDUNoArgument(
  9061. IN DWORD dwOpcode,
  9062. OUT H4501SupplementaryService *pSupplementaryServiceAPDU,
  9063. OUT BYTE** ppEncodedAPDU,
  9064. OUT DWORD* pdwAPDULen
  9065. )
  9066. {
  9067. BYTE *pEncodedArg = NULL;
  9068. WORD wEncodedLen = 0;
  9069. int rc;
  9070. H323DBG(( DEBUG_LEVEL_TRACE, "EncodeH450APDUNoArgument entered:%p.",
  9071. this ));
  9072. ServiceApdus_rosApdus *pROSAPDU =
  9073. pSupplementaryServiceAPDU->serviceApdu.u.rosApdus;
  9074. pROSAPDU->next = NULL;
  9075. pROSAPDU->value.choice = H4503ROS_invoke_chosen;
  9076. pROSAPDU->value.u.invoke.bit_mask = 0;
  9077. //invoke ID
  9078. pROSAPDU->value.u.invoke.invokeId = g_pH323Line->GetNextInvokeID();
  9079. m_dwInvokeID = pROSAPDU->value.u.invoke.invokeId;
  9080. //opcode
  9081. pROSAPDU->value.u.invoke.opcode.choice = local_chosen;
  9082. pROSAPDU->value.u.invoke.opcode.u.local = dwOpcode;
  9083. //no argument passed
  9084. //call ASN.1 encoding function for APDU
  9085. rc = EncodeH450ASN( (void *) pSupplementaryServiceAPDU,
  9086. H4501SupplementaryService_PDU,
  9087. ppEncodedAPDU,
  9088. &wEncodedLen );
  9089. *pdwAPDULen = wEncodedLen;
  9090. if( ASN1_FAILED(rc) || (*ppEncodedAPDU == NULL) || (pdwAPDULen == 0) )
  9091. {
  9092. return FALSE;
  9093. }
  9094. H323DBG(( DEBUG_LEVEL_TRACE, "EncodeH450APDUNoArgument exited:%p.",
  9095. this ));
  9096. return TRUE;
  9097. }
  9098. BOOL
  9099. CH323Call::EncodeCTInitiateAPDU(
  9100. OUT H4501SupplementaryService *pSupplementaryServiceAPDU,
  9101. OUT BYTE** ppEncodedAPDU,
  9102. OUT DWORD* pdwAPDULen
  9103. )
  9104. {
  9105. BYTE *pEncodedArg = NULL;
  9106. WORD wEncodedLen = 0;
  9107. BYTE pBufEncodedArg[H450_ENCODED_ARG_LEN];
  9108. int rc = 0;
  9109. H323DBG(( DEBUG_LEVEL_TRACE, "EncodeCTInitiateAPDU entered:%p.", this ));
  9110. ServiceApdus_rosApdus *pROSAPDU =
  9111. pSupplementaryServiceAPDU->serviceApdu.u.rosApdus;
  9112. pROSAPDU->next = NULL;
  9113. pROSAPDU->value.choice = H4503ROS_invoke_chosen;
  9114. pROSAPDU->value.u.invoke.bit_mask = argument_present;
  9115. //invoke ID
  9116. pROSAPDU->value.u.invoke.invokeId = g_pH323Line->GetNextInvokeID();
  9117. m_dwInvokeID = pROSAPDU->value.u.invoke.invokeId;
  9118. //opcode
  9119. pROSAPDU->value.u.invoke.opcode.choice = local_chosen;
  9120. pROSAPDU->value.u.invoke.opcode.u.local = CTINITIATE_OPCODE;
  9121. //argument
  9122. CTInitiateArg cTInitiateArg;
  9123. ZeroMemory( (PVOID)&cTInitiateArg, sizeof(CTInitiateArg) );
  9124. //argument.callIdentity
  9125. CopyMemory( (PVOID)cTInitiateArg.callIdentity,
  9126. (PVOID)m_pCTCallIdentity, sizeof(m_pCTCallIdentity) );
  9127. //argument.reroutingNumber
  9128. cTInitiateArg.reroutingNumber.bit_mask = 0;
  9129. cTInitiateArg.reroutingNumber.destinationAddress =
  9130. (PEndpointAddress_destinationAddress)
  9131. SetMsgAddressAlias( m_pTransferedToAlias );
  9132. if( cTInitiateArg.reroutingNumber.destinationAddress == NULL )
  9133. {
  9134. return FALSE;
  9135. }
  9136. //encode the CTSetup argument.
  9137. rc = EncodeH450ASN( (void *) &cTInitiateArg,
  9138. CTInitiateArg_PDU,
  9139. &pEncodedArg,
  9140. &wEncodedLen );
  9141. if( ASN1_FAILED(rc) || (pEncodedArg == NULL) || (wEncodedLen == 0) )
  9142. {
  9143. FreeAddressAliases( (PSetup_UUIE_destinationAddress)
  9144. cTInitiateArg.reroutingNumber.destinationAddress );
  9145. return FALSE;
  9146. }
  9147. pROSAPDU->value.u.invoke.argument.value = pBufEncodedArg;
  9148. pROSAPDU->value.u.invoke.argument.length = wEncodedLen;
  9149. CopyMemory( (PVOID)pROSAPDU->value.u.invoke.argument.value,
  9150. pEncodedArg, wEncodedLen );
  9151. //free the previous asn buffer before encoding new one
  9152. ASN1_FreeEncoded(m_ASNCoderInfo.pEncInfo, pEncodedArg );
  9153. FreeAddressAliases( (PSetup_UUIE_destinationAddress)
  9154. cTInitiateArg.reroutingNumber.destinationAddress );
  9155. //call ASN.1 encoding function for APDU
  9156. rc = EncodeH450ASN( (void *) pSupplementaryServiceAPDU,
  9157. H4501SupplementaryService_PDU,
  9158. ppEncodedAPDU,
  9159. &wEncodedLen );
  9160. *pdwAPDULen = wEncodedLen;
  9161. if( ASN1_FAILED(rc) || (*ppEncodedAPDU == NULL) || (pdwAPDULen == 0) )
  9162. {
  9163. return FALSE;
  9164. }
  9165. H323DBG(( DEBUG_LEVEL_TRACE, "EncodeCTInitiateAPDU exited:%p.", this ));
  9166. return TRUE;
  9167. }
  9168. BOOL
  9169. CH323Call::EncodeCTSetupAPDU(
  9170. OUT H4501SupplementaryService *pSupplementaryServiceAPDU,
  9171. OUT BYTE** ppEncodedAPDU,
  9172. OUT DWORD* pdwAPDULen
  9173. )
  9174. {
  9175. BYTE *pEncodedArg = NULL;
  9176. WORD wEncodedLen = 0;
  9177. BYTE pBufEncodedArg[H450_ENCODED_ARG_LEN];
  9178. H323DBG(( DEBUG_LEVEL_TRACE, "EncodeCTSetupAPDU entered:%p.", this ));
  9179. ServiceApdus_rosApdus *pROSAPDU =
  9180. pSupplementaryServiceAPDU->serviceApdu.u.rosApdus;
  9181. pROSAPDU->next = NULL;
  9182. pROSAPDU->value.choice = H4503ROS_invoke_chosen;
  9183. pROSAPDU->value.u.invoke.bit_mask = argument_present;
  9184. //invoke ID
  9185. pROSAPDU->value.u.invoke.invokeId = g_pH323Line->GetNextInvokeID();
  9186. m_dwInvokeID = pROSAPDU->value.u.invoke.invokeId;
  9187. //opcode
  9188. pROSAPDU->value.u.invoke.opcode.choice = local_chosen;
  9189. pROSAPDU->value.u.invoke.opcode.u.local = CTSETUP_OPCODE;
  9190. //argument
  9191. CTSetupArg cTSetupArg;
  9192. ZeroMemory( (PVOID)&cTSetupArg, sizeof(CTSetupArg) );
  9193. //argument.callIdentity
  9194. CopyMemory( (PVOID)cTSetupArg.callIdentity,
  9195. (PVOID)m_pCTCallIdentity, sizeof(m_pCTCallIdentity) );
  9196. //no argument.transferingNumber
  9197. //encode the CTSetup argument.
  9198. int rc = EncodeH450ASN( (void *) &cTSetupArg,
  9199. CTSetupArg_PDU,
  9200. &pEncodedArg,
  9201. &wEncodedLen );
  9202. if( ASN1_FAILED(rc) || (pEncodedArg == NULL) || (wEncodedLen == 0) )
  9203. {
  9204. return FALSE;
  9205. }
  9206. pROSAPDU->value.u.invoke.argument.value = pBufEncodedArg;
  9207. pROSAPDU->value.u.invoke.argument.length = wEncodedLen;
  9208. CopyMemory( (PVOID)pROSAPDU->value.u.invoke.argument.value,
  9209. pEncodedArg, wEncodedLen );
  9210. //free the previous asn buffer before encoding new one
  9211. ASN1_FreeEncoded(m_ASNCoderInfo.pEncInfo, pEncodedArg );
  9212. //call ASN.1 encoding function for APDU
  9213. rc = EncodeH450ASN( (void *) pSupplementaryServiceAPDU,
  9214. H4501SupplementaryService_PDU,
  9215. ppEncodedAPDU,
  9216. &wEncodedLen );
  9217. *pdwAPDULen = wEncodedLen;
  9218. if( ASN1_FAILED(rc) || (*ppEncodedAPDU == NULL) || (pdwAPDULen == 0) )
  9219. {
  9220. return FALSE;
  9221. }
  9222. H323DBG(( DEBUG_LEVEL_TRACE, "EncodeCTSetupAPDU exited:%p.", this ));
  9223. return TRUE;
  9224. }
  9225. void CH323Call::PostLineEvent (
  9226. IN DWORD MessageID,
  9227. IN DWORD_PTR Parameter1,
  9228. IN DWORD_PTR Parameter2,
  9229. IN DWORD_PTR Parameter3)
  9230. {
  9231. (*g_pfnLineEventProc) (
  9232. g_pH323Line -> m_htLine,
  9233. m_htCall,
  9234. MessageID,
  9235. Parameter1,
  9236. Parameter2,
  9237. Parameter3);
  9238. }
  9239. //!!must be always called in a lock
  9240. void
  9241. CH323Call::DecrementIoRefCount(
  9242. OUT BOOL * pfDelete
  9243. )
  9244. {
  9245. _ASSERTE( m_IoRefCount != 0 );
  9246. m_IoRefCount--;
  9247. H323DBG((DEBUG_LEVEL_TRACE, "DecrementIoRefCount:m_IoRefCount:%d:%p.",
  9248. m_IoRefCount, this ));
  9249. *pfDelete = FALSE;
  9250. if( m_dwFlags & CALLOBJECT_SHUTDOWN )
  9251. {
  9252. *pfDelete = (m_IoRefCount==0) ? TRUE : FALSE;
  9253. }
  9254. }
  9255. //!!must be always called in a lock
  9256. void
  9257. CH323Call::StopCTIdentifyRRTimer(
  9258. HDRVCALL hdRelatedCall
  9259. )
  9260. {
  9261. if( m_hCTIdentifyRRTimer != NULL )
  9262. {
  9263. DeleteTimerQueueTimer( H323TimerQueue, m_hCTIdentifyRRTimer, NULL );
  9264. m_hCTIdentifyRRTimer = NULL;
  9265. }
  9266. m_hdRelatedCall = hdRelatedCall;
  9267. }
  9268. void
  9269. CH323Call::InitializeRecvBuf()
  9270. {
  9271. m_RecvBuf.WSABuf.len = sizeof(TPKT_HEADER_SIZE);
  9272. m_RecvBuf.WSABuf.buf = m_RecvBuf.arBuf;
  9273. m_RecvBuf.dwPDULen = m_RecvBuf.dwBytesCopied = 0;
  9274. m_bStartOfPDU = TRUE;
  9275. }
  9276. BOOL
  9277. CH323Call::SetCallData(
  9278. LPVOID lpCallData,
  9279. DWORD dwSize )
  9280. {
  9281. if( m_CallData.pOctetString != NULL )
  9282. {
  9283. delete m_CallData.pOctetString;
  9284. }
  9285. m_CallData.pOctetString = new BYTE[dwSize];
  9286. if( m_CallData.pOctetString == NULL )
  9287. {
  9288. m_CallData.wOctetStringLength = 0;
  9289. return FALSE;
  9290. }
  9291. CopyMemory( (PVOID)m_CallData.pOctetString, lpCallData, dwSize );
  9292. m_CallData.wOctetStringLength = (WORD)dwSize;
  9293. return TRUE;
  9294. }
  9295. // Global Functions
  9296. BOOL
  9297. IsPhoneNumber(
  9298. char * szAddr
  9299. )
  9300. {
  9301. while( *szAddr )
  9302. {
  9303. if( !isdigit(*szAddr) &&
  9304. ('#' != *szAddr) &&
  9305. ('*' != *szAddr) &&
  9306. ('+' != *szAddr)
  9307. )
  9308. return FALSE;
  9309. szAddr++;
  9310. }
  9311. return TRUE;
  9312. }
  9313. BOOL
  9314. IsValidE164String(
  9315. IN WCHAR* wszDigits
  9316. )
  9317. {
  9318. for( ; (*wszDigits) != L'\0'; wszDigits++ )
  9319. {
  9320. if(!(
  9321. ((*wszDigits >= L'0') && (*wszDigits <= L'9')) ||
  9322. (*wszDigits == L'*') ||
  9323. (*wszDigits == L'#') ||
  9324. (*wszDigits == L'!') ||
  9325. (*wszDigits == L',')
  9326. ))
  9327. {
  9328. return FALSE;
  9329. }
  9330. }
  9331. return TRUE;
  9332. }