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.

1763 lines
46 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. line.cpp
  5. Abstract:
  6. TAPI Service Provider functions related to manipulating lines.
  7. TSPI_lineClose
  8. TSPI_lineGetDevCaps
  9. TSPI_lineGetLineDevStatus
  10. TSPI_lineGetNumAddressIDs
  11. TSPI_lineOpen
  12. Author:
  13. Nikhil Bobde (NikhilB)
  14. Revision History:
  15. --*/
  16. //
  17. // Include files
  18. //
  19. #include "globals.h"
  20. #include "line.h"
  21. #include "call.h"
  22. #include "q931obj.h"
  23. #include "ras.h"
  24. static LONG g_CTCallIdentity;
  25. CH323Line g_H323Line;
  26. H323_OCTETSTRING g_ProductID =
  27. {
  28. (BYTE*)H323_PRODUCT_ID,
  29. sizeof(H323_PRODUCT_ID)
  30. };
  31. H323_OCTETSTRING g_ProductVersion =
  32. {
  33. (BYTE*)H323_PRODUCT_VERSION,
  34. sizeof(H323_PRODUCT_VERSION)
  35. };
  36. //Queues a request made by TAPI to the thread pool
  37. BOOL
  38. QueueTAPILineRequest(
  39. IN DWORD EventID,
  40. IN HDRVCALL hdCall1,
  41. IN HDRVCALL hdCall2,
  42. IN DWORD dwDisconnectMode,
  43. IN WORD wCallReference)
  44. {
  45. BOOL fResult = TRUE;
  46. TAPI_LINEREQUEST_DATA * pLineRequestData = new TAPI_LINEREQUEST_DATA;
  47. H323DBG(( DEBUG_LEVEL_TRACE, "QueueTAPILineRequest entered." ));
  48. if( pLineRequestData != NULL )
  49. {
  50. pLineRequestData -> EventID = EventID;
  51. pLineRequestData -> hdCall1 = hdCall1;
  52. if( hdCall2 != NULL )
  53. {
  54. pLineRequestData -> hdCall2 = hdCall2;
  55. }
  56. else
  57. {
  58. pLineRequestData -> dwDisconnectMode = dwDisconnectMode;
  59. }
  60. pLineRequestData -> wCallReference = wCallReference;
  61. if( !QueueUserWorkItem( ProcessTAPILineRequest, pLineRequestData,
  62. WT_EXECUTEDEFAULT) )
  63. {
  64. delete pLineRequestData;
  65. fResult = FALSE;
  66. }
  67. }
  68. else
  69. {
  70. fResult = FALSE;
  71. }
  72. H323DBG(( DEBUG_LEVEL_TRACE, "QueueTAPILineRequest exited." ));
  73. return fResult;
  74. }
  75. #if DBG
  76. DWORD
  77. ProcessTAPILineRequest(
  78. IN PVOID ContextParameter
  79. )
  80. {
  81. __try
  82. {
  83. return ProcessTAPILineRequestFre( ContextParameter );
  84. }
  85. __except( 1 )
  86. {
  87. TAPI_LINEREQUEST_DATA* pRequestData = (TAPI_LINEREQUEST_DATA*)ContextParameter;
  88. H323DBG(( DEBUG_LEVEL_TRACE, "TSPI %s event threw exception: %p, %p, %d.",
  89. EventIDToString(pRequestData -> EventID),
  90. pRequestData -> hdCall1,
  91. pRequestData -> hdCall2,
  92. pRequestData -> wCallReference ));
  93. _ASSERTE( FALSE );
  94. return 0;
  95. }
  96. }
  97. #endif
  98. DWORD
  99. ProcessTAPILineRequestFre(
  100. IN PVOID ContextParam
  101. )
  102. {
  103. _ASSERTE( ContextParam );
  104. PH323_CALL pCall = NULL;
  105. PH323_CALL pConsultCall = NULL;
  106. TAPI_LINEREQUEST_DATA* pLineRequestData = (TAPI_LINEREQUEST_DATA*)ContextParam;
  107. H323DBG(( DEBUG_LEVEL_TRACE, "TSPI %s event recvd.",
  108. EventIDToString(pLineRequestData -> EventID) ));
  109. switch( pLineRequestData -> EventID )
  110. {
  111. case TSPI_CLOSE_CALL:
  112. g_pH323Line -> H323ReleaseCall(
  113. pLineRequestData->hdCall1,
  114. pLineRequestData->dwDisconnectMode,
  115. pLineRequestData->wCallReference );
  116. break;
  117. case TSPI_COMPLETE_TRANSFER:
  118. pConsultCall = g_pH323Line -> Find2H323CallsAndLock(
  119. pLineRequestData->hdCall2, pLineRequestData->hdCall1, &pCall );
  120. if( pConsultCall != NULL )
  121. {
  122. pConsultCall -> CompleteTransfer( pCall );
  123. pCall -> Unlock();
  124. pConsultCall -> Unlock();
  125. }
  126. break;
  127. }
  128. delete pLineRequestData;
  129. return EXIT_SUCCESS;
  130. }
  131. //
  132. // Private procedures
  133. //
  134. CH323Line::CH323Line()
  135. {
  136. m_nState = H323_LINESTATE_NONE;
  137. m_hdLine = NULL;
  138. m_htLine = NULL;
  139. m_dwDeviceID = -1;
  140. m_dwTSPIVersion = NULL;
  141. m_dwMediaModes = NULL;
  142. m_hdNextMSPHandle = NULL;
  143. m_wszAddr[0] = UNICODE_NULL;
  144. m_dwInitState = NULL;
  145. m_VendorInfo.bCountryCode = H221_COUNTRY_CODE_USA;
  146. m_VendorInfo.bExtension = H221_COUNTRY_EXT_USA;
  147. m_VendorInfo.wManufacturerCode = H221_MFG_CODE_MICROSOFT;
  148. m_VendorInfo.pProductNumber = &(g_ProductID);
  149. m_VendorInfo.pVersionNumber = &(g_ProductVersion);
  150. m_pCallForwardParams = NULL;
  151. m_dwInvokeID = 256;
  152. m_fForwardConsultInProgress = FALSE;
  153. }
  154. PH323_CALL
  155. CH323Line::Find2H323CallsAndLock (
  156. IN HDRVCALL hdCall1,
  157. IN HDRVCALL hdCall2,
  158. OUT PH323_CALL * ppCall2
  159. )
  160. {
  161. int iIndex1 = MakeCallIndex (hdCall1);
  162. int iIndex2 = MakeCallIndex (hdCall2);
  163. PH323_CALL pCall1 = NULL, pCall2 = NULL;
  164. H323DBG(( DEBUG_LEVEL_TRACE, "Find2H323CallsAndLock entered:%lx:%lx.",
  165. hdCall1, hdCall2 ));
  166. LockCallTable();
  167. //lock the call so that nobody else would be able to delete the call
  168. pCall1 = m_H323CallTable[iIndex1];
  169. if( pCall1 != NULL )
  170. {
  171. pCall1 -> Lock();
  172. if( pCall1->GetCallHandle() != hdCall1 )
  173. {
  174. pCall1 -> Unlock();
  175. pCall1 = NULL;
  176. }
  177. else
  178. {
  179. if( pCall2=m_H323CallTable[iIndex2] )
  180. {
  181. pCall2 -> Lock();
  182. if( pCall2->GetCallHandle() != hdCall2 )
  183. {
  184. pCall2 -> Unlock();
  185. pCall2 = NULL;
  186. pCall1 -> Unlock();
  187. pCall1 = NULL;
  188. }
  189. }
  190. else
  191. {
  192. pCall1 -> Unlock();
  193. pCall1 = NULL;
  194. }
  195. }
  196. }
  197. UnlockCallTable();
  198. *ppCall2 = pCall2;
  199. H323DBG(( DEBUG_LEVEL_TRACE, "Find2H323CallsAndLock exited:%lx:%lx.",
  200. hdCall1, hdCall2 ));
  201. return pCall1;
  202. }
  203. PH323_CALL
  204. CH323Line::FindH323CallAndLock (
  205. IN HDRVCALL hdCall)
  206. {
  207. H323DBG(( DEBUG_LEVEL_TRACE, "FindH323CallAndLock entered:%lx.", hdCall ));
  208. int iIndex = MakeCallIndex (hdCall);
  209. PH323_CALL pCall = NULL;
  210. LockCallTable();
  211. //lock the call so that nobody else would be able to delete the call
  212. if( pCall=m_H323CallTable[iIndex] )
  213. {
  214. pCall -> Lock();
  215. if( pCall->GetCallHandle() != hdCall )
  216. {
  217. pCall -> Unlock();
  218. pCall = NULL;
  219. }
  220. }
  221. UnlockCallTable();
  222. H323DBG(( DEBUG_LEVEL_TRACE, "FindH323CallAndLock exited:%p.", pCall ));
  223. return pCall;
  224. }
  225. PH323_CALL
  226. CH323Line::FindCallByARQSeqNumAndLock(
  227. WORD seqNumber
  228. )
  229. {
  230. PH323_CALL pCall = NULL;
  231. int iIndex;
  232. H323DBG(( DEBUG_LEVEL_TRACE, "FindCallByARQSeqNumAndLock entered:%d.",
  233. seqNumber ));
  234. LockCallTable();
  235. //lock the call so that nobody else would be able to delete the call
  236. for( iIndex=0; iIndex < m_H323CallTable.GetAllocSize(); iIndex++ )
  237. {
  238. if( pCall=m_H323CallTable[iIndex] )
  239. {
  240. if( pCall->GetARQSeqNumber() == seqNumber )
  241. {
  242. pCall -> Lock();
  243. break;
  244. }
  245. pCall = NULL;
  246. }
  247. }
  248. UnlockCallTable();
  249. H323DBG(( DEBUG_LEVEL_TRACE, "FindCallByARQSeqNumAndLock exited." ));
  250. return pCall;
  251. }
  252. //the code is replicated for the purpose of effeciency
  253. PH323_CALL
  254. CH323Line::FindCallByDRQSeqNumAndLock(
  255. WORD seqNumber
  256. )
  257. {
  258. PH323_CALL pCall = NULL;
  259. int iIndex;
  260. H323DBG(( DEBUG_LEVEL_TRACE, "FindCallByDRQSeqNumAndLock entered:%d.",
  261. seqNumber ));
  262. LockCallTable();
  263. //lock the call so that nobody else would be able to delete the call
  264. for( iIndex=0; iIndex < m_H323CallTable.GetAllocSize(); iIndex++ )
  265. {
  266. if( pCall=m_H323CallTable[iIndex] )
  267. {
  268. if( pCall->GetDRQSeqNumber() == seqNumber )
  269. {
  270. pCall -> Lock();
  271. break;
  272. }
  273. pCall = NULL;
  274. }
  275. }
  276. UnlockCallTable();
  277. H323DBG(( DEBUG_LEVEL_TRACE, "FindCallByDRQSeqNumAndLock exited:%d.",
  278. seqNumber ));
  279. return pCall;
  280. }
  281. //the code is replicated for the purpose of effeciency
  282. PH323_CALL
  283. CH323Line::FindCallByCallRefAndLock(
  284. WORD wCallRef
  285. )
  286. {
  287. PH323_CALL pCall = NULL;
  288. int iIndex;
  289. H323DBG(( DEBUG_LEVEL_TRACE, "FindCallByCallRefAndLock entered:%d.",
  290. wCallRef ));
  291. wCallRef &= 0x7fff;
  292. LockCallTable();
  293. //lock the call so that nobody else would be able to delete the call
  294. for( iIndex=0; iIndex < m_H323CallTable.GetAllocSize(); iIndex++ )
  295. {
  296. if( pCall=m_H323CallTable[iIndex] )
  297. {
  298. if( pCall->GetCallRef() == wCallRef )
  299. {
  300. pCall -> Lock();
  301. break;
  302. }
  303. pCall = NULL;
  304. }
  305. }
  306. UnlockCallTable();
  307. H323DBG(( DEBUG_LEVEL_TRACE, "FindCallByCallRefAndLock exited:%d.",
  308. wCallRef ));
  309. return pCall;
  310. }
  311. void
  312. CH323Line::RemoveFromCTCallIdentityTable(
  313. HDRVCALL hdCall )
  314. {
  315. int iIndex;
  316. PCTCALLID_CONTEXT pCTCallIDContext = NULL;
  317. H323DBG(( DEBUG_LEVEL_TRACE, "RemoveFromCTCallIdentityTable entered:%lx.",
  318. hdCall ));
  319. m_CTCallIDTable.Lock();
  320. for( iIndex=0; iIndex < m_CTCallIDTable.GetAllocSize(); iIndex++ )
  321. {
  322. pCTCallIDContext = m_CTCallIDTable[iIndex];
  323. if( pCTCallIDContext != NULL )
  324. {
  325. if( pCTCallIDContext -> hdCall == hdCall)
  326. {
  327. m_CTCallIDTable.RemoveAt(iIndex);
  328. }
  329. }
  330. }
  331. m_CTCallIDTable.Unlock();
  332. H323DBG(( DEBUG_LEVEL_TRACE, "RemoveFromCTCallIdentityTable exited:%lx.",
  333. hdCall ));
  334. }
  335. void
  336. CH323Line::ShutdownCTCallIDTable()
  337. {
  338. int iIndex;
  339. PCTCALLID_CONTEXT pCTCallIDContext = NULL;
  340. H323DBG(( DEBUG_LEVEL_TRACE, "ShutdownCTCallIDTable entered." ));
  341. m_CTCallIDTable.Lock();
  342. for( iIndex=0; iIndex < m_CTCallIDTable.GetAllocSize(); iIndex++ )
  343. {
  344. pCTCallIDContext = m_CTCallIDTable[iIndex];
  345. if( pCTCallIDContext != NULL )
  346. {
  347. delete pCTCallIDContext;
  348. m_CTCallIDTable[iIndex] = NULL;
  349. }
  350. }
  351. m_CTCallIDTable.Unlock();
  352. H323DBG(( DEBUG_LEVEL_TRACE, "ShutdownCTCallIDTable exited." ));
  353. }
  354. BOOL
  355. CH323Line::CallReferenceDuped(
  356. WORD wCallRef
  357. )
  358. {
  359. PH323_CALL pCall = NULL;
  360. int iIndex;
  361. H323DBG(( DEBUG_LEVEL_TRACE, "CallReferenceDuped entered:%d.", wCallRef ));
  362. wCallRef &= 0x7FFF;
  363. LockCallTable();
  364. for( iIndex=0; iIndex < m_H323CallTable.GetAllocSize(); iIndex++ )
  365. {
  366. if( pCall=m_H323CallTable[iIndex] )
  367. {
  368. if( pCall->GetCallRef() == wCallRef )
  369. {
  370. UnlockCallTable();
  371. return TRUE;
  372. }
  373. }
  374. }
  375. UnlockCallTable();
  376. H323DBG(( DEBUG_LEVEL_TRACE, "CallReferenceDuped exited:%d.", wCallRef ));
  377. return FALSE;
  378. }
  379. HDRVCALL
  380. CH323Line::GetCallFromCTCallIdentity(
  381. int iCTCallID
  382. )
  383. {
  384. int iIndex;
  385. PCTCALLID_CONTEXT pCTCallIDContext = NULL;
  386. H323DBG(( DEBUG_LEVEL_TRACE, "GetCallFromCTCallIdentity entered:%d.",
  387. iCTCallID ));
  388. m_CTCallIDTable.Lock();
  389. for( iIndex=0; iIndex < m_CTCallIDTable.GetAllocSize(); iIndex++ )
  390. {
  391. pCTCallIDContext = m_CTCallIDTable[iIndex];
  392. if( pCTCallIDContext != NULL )
  393. {
  394. if( pCTCallIDContext -> iCTCallIdentity == iCTCallID )
  395. {
  396. m_CTCallIDTable.Unlock();
  397. return (HDRVCALL)(pCTCallIDContext -> hdCall);
  398. }
  399. }
  400. }
  401. m_CTCallIDTable.Unlock();
  402. H323DBG(( DEBUG_LEVEL_TRACE, "GetCallFromCTCallIdentity exited:%d.",
  403. iCTCallID ));
  404. return NULL;
  405. }
  406. int
  407. CH323Line::GetCTCallIdentity(
  408. IN HDRVCALL hdCall)
  409. {
  410. int CTCallID = 0;
  411. int iIndex;
  412. PCTCALLID_CONTEXT pCTCallIDContext = NULL;
  413. H323DBG(( DEBUG_LEVEL_TRACE, "GetCTCallIdentity entered:%lx.", hdCall ));
  414. m_CTCallIDTable.Lock();
  415. do
  416. {
  417. g_CTCallIdentity++;
  418. if( g_CTCallIdentity == 10000 )
  419. {
  420. g_CTCallIdentity = 1;
  421. }
  422. //lock the call so that nobody else would be able to delete the call
  423. for( iIndex=0; iIndex < m_CTCallIDTable.GetAllocSize(); iIndex++ )
  424. {
  425. pCTCallIDContext = m_CTCallIDTable[iIndex] ;
  426. if( pCTCallIDContext != NULL )
  427. {
  428. if( pCTCallIDContext -> iCTCallIdentity == g_CTCallIdentity )
  429. {
  430. break;
  431. }
  432. }
  433. }
  434. if( iIndex == m_CTCallIDTable.GetAllocSize() )
  435. {
  436. CTCallID = g_CTCallIdentity;
  437. }
  438. }while( CTCallID == 0 );
  439. pCTCallIDContext = new CTCALLID_CONTEXT;
  440. if( pCTCallIDContext == NULL )
  441. {
  442. m_CTCallIDTable.Unlock();
  443. return 0;
  444. }
  445. pCTCallIDContext->iCTCallIdentity = CTCallID;
  446. pCTCallIDContext->hdCall = hdCall;
  447. if( m_CTCallIDTable.Add(pCTCallIDContext) == -1 )
  448. {
  449. m_CTCallIDTable.Unlock();
  450. delete pCTCallIDContext;
  451. return 0;
  452. }
  453. m_CTCallIDTable.Unlock();
  454. H323DBG(( DEBUG_LEVEL_TRACE, "GetCTCallIdentity exited:%lx.", hdCall ));
  455. return CTCallID;
  456. }
  457. void
  458. CH323Line::SetCallForwardParams(
  459. IN CALLFORWARDPARAMS* pCallForwardParams )
  460. {
  461. H323DBG(( DEBUG_LEVEL_TRACE, "SetCallForwardParams entered." ));
  462. if( m_pCallForwardParams != NULL )
  463. {
  464. FreeCallForwardParams( m_pCallForwardParams );
  465. m_pCallForwardParams = NULL;
  466. }
  467. m_pCallForwardParams = pCallForwardParams;
  468. H323DBG(( DEBUG_LEVEL_TRACE, "SetCallForwardParams exited." ));
  469. }
  470. BOOL
  471. CH323Line::SetCallForwardParams(
  472. IN LPFORWARDADDRESS pForwardAddress
  473. )
  474. {
  475. H323DBG(( DEBUG_LEVEL_TRACE, "SetCallForwardParams entered." ));
  476. if( m_pCallForwardParams != NULL )
  477. {
  478. pForwardAddress->next = m_pCallForwardParams->pForwardedAddresses;
  479. m_pCallForwardParams->pForwardedAddresses = pForwardAddress;
  480. }
  481. else
  482. {
  483. m_pCallForwardParams = new CALLFORWARDPARAMS;
  484. if( m_pCallForwardParams == NULL )
  485. {
  486. return FALSE;
  487. }
  488. ZeroMemory( m_pCallForwardParams, sizeof(CALLFORWARDPARAMS) );
  489. m_pCallForwardParams->fForwardingEnabled = TRUE;
  490. m_pCallForwardParams->pForwardedAddresses = pForwardAddress;
  491. pForwardAddress -> next = NULL;
  492. }
  493. //set unconditional forwarding
  494. m_pCallForwardParams->fForwardForAllOrigins = FALSE;
  495. H323DBG(( DEBUG_LEVEL_TRACE, "SetCallForwardParams exited." ));
  496. return TRUE;
  497. }
  498. CH323Line::~CH323Line()
  499. {
  500. DeleteCriticalSection (&m_CriticalSection);
  501. }
  502. /*++
  503. Routine Description:
  504. Hangs up call (if necessary) and closes call object.
  505. Arguments:
  506. Handle of the call.
  507. Return Values:
  508. none.
  509. --*/
  510. void
  511. CH323Line::H323ReleaseCall(
  512. IN HDRVCALL hdCall,
  513. IN DWORD dwDisconnectMode,
  514. IN WORD wCallReference
  515. )
  516. {
  517. H323DBG(( DEBUG_LEVEL_TRACE, "H323ReleaseCall entered:%lx.", hdCall ));
  518. int iIndex = MakeCallIndex (hdCall);
  519. PH323_CALL pCall;
  520. BOOL fDelete = FALSE;
  521. LockCallTable();
  522. //lock the call so that nobody else would be able to delete the call
  523. if( (pCall=m_H323CallTable[iIndex]) && (hdCall==pCall->GetCallHandle()) )
  524. {
  525. pCall -> Lock();
  526. if( (wCallReference != 0) &&
  527. (wCallReference != pCall->GetCallRef()) )
  528. {
  529. //This message is for some other call. Ignore the message.
  530. H323DBG(( DEBUG_LEVEL_VERBOSE, "TSPI_CLOSE_CALL message ignored."));
  531. }
  532. else
  533. {
  534. // drop call using normal disconnect code
  535. pCall -> DropCall( dwDisconnectMode );
  536. pCall -> Shutdown( &fDelete );
  537. H323DBG(( DEBUG_LEVEL_VERBOSE, "call 0x%08lx closed.", pCall ));
  538. }
  539. pCall -> Unlock();
  540. //release the H323 call object
  541. if( fDelete == TRUE )
  542. {
  543. H323DBG(( DEBUG_LEVEL_VERBOSE, "call delete:0x%08lx.", pCall ));
  544. delete pCall;
  545. }
  546. }
  547. UnlockCallTable();
  548. H323DBG(( DEBUG_LEVEL_TRACE, "H323ReleaseCall exited: %p.", pCall ));
  549. }
  550. BOOL
  551. CH323Line::Initialize (
  552. IN DWORD dwLineDeviceIDBase)
  553. {
  554. DWORD dwSize;
  555. H323DBG((DEBUG_LEVEL_TRACE, "line Initialize entered."));
  556. if( m_dwInitState & LINEOBJECT_INITIALIZED )
  557. {
  558. return TRUE;
  559. }
  560. __try
  561. {
  562. if( !InitializeCriticalSectionAndSpinCount( &m_CriticalSection,
  563. 0x80000000 ) )
  564. {
  565. return FALSE;
  566. }
  567. }
  568. __except( 1 )
  569. {
  570. return FALSE;
  571. }
  572. m_dwDeviceID = dwLineDeviceIDBase;
  573. m_dwInitState = LINEOBJECT_INITIALIZED;
  574. //m_dwMediaModes = H323_LINE_MEDIAMODES;
  575. m_hdLine = (HDRVLINE__ *)this;
  576. m_dwNumRingsNoAnswer = H323_NUMRINGS_NOANSWER;
  577. dwSize = sizeof( m_wszAddr );
  578. //create displayable address
  579. GetComputerNameW( m_wszAddr, &dwSize );
  580. H323DBG(( DEBUG_LEVEL_TRACE, "line %d initialized (addr=%S)(hdLine=%d).",
  581. m_dwDeviceID, m_wszAddr, m_hdLine));
  582. // change line device state to closed
  583. m_nState = H323_LINESTATE_NONE;
  584. //init the mSP handles list
  585. m_MSPHandleList = NULL;
  586. H323DBG(( DEBUG_LEVEL_TRACE, "line Initialize exited." ));
  587. // success
  588. return TRUE;
  589. }
  590. BOOL
  591. CH323Line::AddMSPInstance(
  592. HTAPIMSPLINE htMSPLine,
  593. HDRVMSPLINE hdMSPLine )
  594. {
  595. MSPHANDLEENTRY* pMSPHandleEntry;
  596. H323DBG(( DEBUG_LEVEL_TRACE, "AddMSPInstance entered." ));
  597. Lock();
  598. pMSPHandleEntry = new MSPHANDLEENTRY;
  599. if( pMSPHandleEntry == NULL )
  600. {
  601. Unlock();
  602. return FALSE;
  603. }
  604. pMSPHandleEntry->htMSPLine = htMSPLine;
  605. pMSPHandleEntry->hdMSPLine = hdMSPLine;
  606. pMSPHandleEntry->next = m_MSPHandleList;
  607. m_MSPHandleList = pMSPHandleEntry;
  608. Unlock();
  609. H323DBG(( DEBUG_LEVEL_TRACE, "AddMSPInstance exited." ));
  610. return TRUE;
  611. }
  612. BOOL
  613. CH323Line::IsValidMSPHandle(
  614. HDRVMSPLINE hdMSPLine,
  615. HTAPIMSPLINE* phtMSPLine )
  616. {
  617. Lock();
  618. MSPHANDLEENTRY* pMSPHandle = m_MSPHandleList;
  619. while( pMSPHandle )
  620. {
  621. if( pMSPHandle->hdMSPLine == hdMSPLine )
  622. {
  623. *phtMSPLine = pMSPHandle->htMSPLine;
  624. Unlock();
  625. return TRUE;
  626. }
  627. pMSPHandle = pMSPHandle->next;
  628. }
  629. Unlock();
  630. return FALSE;
  631. }
  632. BOOL
  633. CH323Line::DeleteMSPInstance(
  634. HTAPIMSPLINE* phtMSPLine,
  635. HDRVMSPLINE hdMSPLine )
  636. {
  637. MSPHANDLEENTRY* pMSPHandle;
  638. MSPHANDLEENTRY* pMSPHandleDel;
  639. BOOL fRetVal = TRUE;
  640. H323DBG(( DEBUG_LEVEL_TRACE, "DeleteMSPInstance entered." ));
  641. Lock();
  642. if( m_MSPHandleList == NULL )
  643. {
  644. fRetVal = FALSE;
  645. goto func_exit;
  646. }
  647. if( m_MSPHandleList->hdMSPLine == hdMSPLine )
  648. {
  649. *phtMSPLine = m_MSPHandleList->htMSPLine;
  650. pMSPHandleDel = m_MSPHandleList;
  651. m_MSPHandleList = m_MSPHandleList->next;
  652. delete pMSPHandleDel;
  653. fRetVal = TRUE;
  654. goto func_exit;
  655. }
  656. for( pMSPHandle=m_MSPHandleList; pMSPHandle->next; pMSPHandle=pMSPHandle->next )
  657. {
  658. if( pMSPHandle->next->hdMSPLine == hdMSPLine )
  659. {
  660. *phtMSPLine = pMSPHandle->next->htMSPLine;
  661. pMSPHandleDel = pMSPHandle->next;
  662. pMSPHandle->next = pMSPHandle->next->next;
  663. delete pMSPHandleDel;
  664. fRetVal = TRUE;
  665. goto func_exit;
  666. }
  667. }
  668. func_exit:
  669. Unlock();
  670. H323DBG(( DEBUG_LEVEL_TRACE, "DeleteMSPInstance exited." ));
  671. return fRetVal;
  672. }
  673. //!!always called in a lock
  674. void
  675. CH323Line::ShutdownAllCalls(void)
  676. {
  677. PH323_CALL pCall;
  678. H323_CONFERENCE* pConf;
  679. DWORD indexI;
  680. DWORD dwSize;
  681. BOOL fDelete = FALSE;
  682. if( !(m_dwInitState & LINEOBJECT_INITIALIZED) )
  683. return;
  684. H323DBG((DEBUG_LEVEL_TRACE, "ShutdownAllCalls entered."));
  685. if( m_dwInitState & LINEOBJECT_SHUTDOWN )
  686. {
  687. return;
  688. }
  689. //shutdown all calls, delete all calls
  690. LockCallTable();
  691. dwSize = m_H323CallTable.GetAllocSize();
  692. for( indexI=0; indexI < dwSize; indexI++ )
  693. {
  694. pCall = m_H323CallTable[indexI];
  695. if( pCall != NULL )
  696. {
  697. pCall -> DropCall( 0 );
  698. pCall -> Shutdown(&fDelete);
  699. if(fDelete)
  700. {
  701. H323DBG((DEBUG_LEVEL_TRACE, "call delete:%p.", pCall ));
  702. delete pCall;
  703. }
  704. }
  705. }
  706. UnlockCallTable();
  707. dwSize = m_H323ConfTable.GetSize();
  708. for( indexI=0; indexI < dwSize; indexI++ )
  709. {
  710. pConf = m_H323ConfTable[indexI];
  711. //m_H323ConfTable.RemoveAt( indexI );
  712. if( pConf != NULL )
  713. {
  714. delete pConf;
  715. m_H323ConfTable[indexI] = NULL;
  716. }
  717. }
  718. H323DBG((DEBUG_LEVEL_TRACE, "ShutdownAllCalls exited."));
  719. }
  720. void
  721. CH323Line::Shutdown(void)
  722. {
  723. BOOL fDelete = FALSE;
  724. MSPHANDLEENTRY* pMSPHandle;
  725. if( !(m_dwInitState & LINEOBJECT_INITIALIZED) )
  726. {
  727. return;
  728. }
  729. H323DBG((DEBUG_LEVEL_TRACE, "line Shutdown entered."));
  730. Lock();
  731. if( m_dwInitState & LINEOBJECT_SHUTDOWN )
  732. {
  733. Unlock();
  734. return;
  735. }
  736. FreeCallForwardParams( m_pCallForwardParams );
  737. m_pCallForwardParams = NULL;
  738. Close();
  739. m_dwMediaModes = NULL;
  740. //m_hdLine = NULL;
  741. m_hdNextMSPHandle = NULL;
  742. m_htLine = NULL;
  743. //Free the MSP handles list
  744. while( m_MSPHandleList )
  745. {
  746. pMSPHandle = m_MSPHandleList;
  747. m_MSPHandleList = m_MSPHandleList->next;
  748. delete pMSPHandle;
  749. }
  750. m_dwInitState |= LINEOBJECT_SHUTDOWN;
  751. Unlock();
  752. H323DBG(( DEBUG_LEVEL_TRACE, "line Shutdown exited." ));
  753. }
  754. LONG
  755. CH323Line::CopyLineInfo(
  756. IN DWORD dwDeviceID,
  757. OUT LPLINEADDRESSCAPS pAddressCaps
  758. )
  759. {
  760. DWORD dwAddressSize;
  761. H323DBG((DEBUG_LEVEL_TRACE, "line CopyLineInfo entered."));
  762. // determine size of address name
  763. dwAddressSize = H323SizeOfWSZ( m_wszAddr );
  764. // calculate number of bytes needed
  765. pAddressCaps->dwNeededSize = sizeof(LINEADDRESSCAPS) +
  766. dwAddressSize
  767. ;
  768. // validate buffer allocated is large enough
  769. if (pAddressCaps->dwTotalSize >= pAddressCaps->dwNeededSize)
  770. {
  771. // record amount of memory used
  772. pAddressCaps->dwUsedSize = pAddressCaps->dwNeededSize;
  773. // position address name after fixed portion
  774. pAddressCaps->dwAddressSize = dwAddressSize;
  775. pAddressCaps->dwAddressOffset = sizeof(LINEADDRESSCAPS);
  776. // copy address name after fixed portion
  777. CopyMemory((LPBYTE)pAddressCaps + pAddressCaps->dwAddressOffset,
  778. (LPBYTE)m_wszAddr,
  779. pAddressCaps->dwAddressSize );
  780. }
  781. else if (pAddressCaps->dwTotalSize >= sizeof(LINEADDRESSCAPS))
  782. {
  783. H323DBG(( DEBUG_LEVEL_WARNING,
  784. "lineaddresscaps structure too small for strings." ));
  785. // record amount of memory used
  786. pAddressCaps->dwUsedSize = sizeof(LINEADDRESSCAPS);
  787. }
  788. else
  789. {
  790. H323DBG((DEBUG_LEVEL_ERROR, "lineaddresscaps structure too small."));
  791. // allocated structure too small
  792. return LINEERR_STRUCTURETOOSMALL;
  793. }
  794. H323DBG(( DEBUG_LEVEL_VERBOSE, "addr 0 capabilities requested." ));
  795. // transfer associated device id
  796. pAddressCaps->dwLineDeviceID = dwDeviceID;
  797. // initialize number of calls allowed per address
  798. pAddressCaps->dwMaxNumActiveCalls = H323_MAXCALLSPERADDR;
  799. // initialize supported address capabilities
  800. pAddressCaps->dwAddressSharing = H323_ADDR_ADDRESSSHARING;
  801. pAddressCaps->dwCallInfoStates = H323_ADDR_CALLINFOSTATES;
  802. pAddressCaps->dwCallStates = H323_ADDR_CALLSTATES;
  803. pAddressCaps->dwDisconnectModes = H323_ADDR_DISCONNECTMODES;
  804. pAddressCaps->dwAddrCapFlags = H323_ADDR_CAPFLAGS;
  805. pAddressCaps->dwCallFeatures = H323_ADDR_CALLFEATURES;
  806. pAddressCaps->dwAddressFeatures = H323_ADDR_ADDRFEATURES;
  807. pAddressCaps->dwCallerIDFlags = H323_ADDR_CALLPARTYIDFLAGS;
  808. pAddressCaps->dwCalledIDFlags = H323_ADDR_CALLPARTYIDFLAGS;
  809. // initialize unsupported address capabilities
  810. pAddressCaps->dwConnectedIDFlags = LINECALLPARTYID_UNAVAIL;
  811. pAddressCaps->dwRedirectionIDFlags = LINECALLPARTYID_UNAVAIL;
  812. pAddressCaps->dwRedirectingIDFlags = LINECALLPARTYID_UNAVAIL;
  813. H323DBG((DEBUG_LEVEL_TRACE, "line CopyLineInfo exited."));
  814. H323DBG(( DEBUG_LEVEL_TRACE, "TSPI_lineGetAddressCaps - Exited." ));
  815. // success
  816. return NOERROR;
  817. }
  818. /*++
  819. Routine Description:
  820. Initiate activities on line device and allocate resources.
  821. Arguments:
  822. htLine - TAPI's handle describing line device to open.
  823. dwTSPIVersion - The TSPI version negotiated through
  824. TSPI_lineNegotiateTSPIVersion under which the Service Provider is
  825. willing to operate.
  826. Return Values:
  827. Returns true if successful.
  828. --*/
  829. LONG CH323Line::Open(
  830. IN DWORD DeviceID,
  831. IN HTAPILINE TapiLine,
  832. IN DWORD TspiVersion,
  833. IN HDRVLINE * ReturnDriverLine)
  834. {
  835. HRESULT hr;
  836. LONG dwStatus = ERROR_SUCCESS;
  837. H323DBG(( DEBUG_LEVEL_TRACE, "H323 line open entered." ));
  838. if (GetDeviceID() != DeviceID)
  839. {
  840. // do not recognize device
  841. return LINEERR_BADDEVICEID;
  842. }
  843. // make sure this is a version we support
  844. if (!H323ValidateTSPIVersion (TspiVersion))
  845. {
  846. return LINEERR_INCOMPATIBLEAPIVERSION;
  847. }
  848. Lock();
  849. switch (m_nState)
  850. {
  851. case H323_LINESTATE_OPENED:
  852. H323DBG ((DEBUG_LEVEL_ERROR,
  853. "H323 line is already open (H323_LINESTATE_OPENED), cannot reopen"));
  854. dwStatus = LINEERR_INUSE;
  855. break;
  856. case H323_LINESTATE_LISTENING:
  857. H323DBG ((DEBUG_LEVEL_ERROR,
  858. "H323 line is already open (H323_LINESTATE_LISTENING), cannot reopen"));
  859. dwStatus = LINEERR_INUSE;
  860. break;
  861. case H323_LINESTATE_CLOSING:
  862. H323DBG ((DEBUG_LEVEL_ERROR,
  863. "H323 line cannot be opened (H323_LINESTATE_CLOSING)"));
  864. dwStatus = LINEERR_INVALLINESTATE;
  865. break;
  866. case H323_LINESTATE_OPENING:
  867. H323DBG ((DEBUG_LEVEL_ERROR,
  868. "H323 line cannot be opened (H323_LINESTATE_OPENING)"));
  869. dwStatus = LINEERR_INVALLINESTATE;
  870. break;
  871. case H323_LINESTATE_NONE:
  872. // attempt to open line device
  873. H323DBG ((DEBUG_LEVEL_TRACE, "H323 line is opening"));
  874. // start listen if necessary
  875. if (IsMediaDetectionEnabled())
  876. {
  877. hr = Q931AcceptStart();
  878. if (hr == S_OK)
  879. {
  880. dwStatus = ERROR_SUCCESS;
  881. RasStart();
  882. }
  883. else
  884. {
  885. H323DBG ((DEBUG_LEVEL_ERROR, "failed to listen on Q.931"));
  886. dwStatus = LINEERR_OPERATIONFAILED;
  887. }
  888. }
  889. if (dwStatus == ERROR_SUCCESS)
  890. {
  891. H323DBG ((DEBUG_LEVEL_TRACE, "H323 line successfully opened"));
  892. // save line variables now
  893. m_nState = IsMediaDetectionEnabled()?
  894. H323_LINESTATE_LISTENING:H323_LINESTATE_OPENED;
  895. m_htLine = TapiLine;
  896. m_dwTSPIVersion = TspiVersion;
  897. *ReturnDriverLine = (HDRVLINE) this;
  898. }
  899. else
  900. {
  901. Q931AcceptStop();
  902. }
  903. break;
  904. default:
  905. _ASSERTE( FALSE );
  906. }
  907. Unlock();
  908. H323DBG(( DEBUG_LEVEL_TRACE, "H323 line open exited." ));
  909. return dwStatus;
  910. }
  911. /*++
  912. Routine Description:
  913. Terminate activities on line device.
  914. Arguments:
  915. Return Values:
  916. Returns true if successful.
  917. --*/
  918. LONG
  919. CH323Line::Close(void)
  920. {
  921. LONG dwStatus;
  922. H323DBG(( DEBUG_LEVEL_TRACE, "H323 line close entered." ));
  923. Lock();
  924. switch (m_nState)
  925. {
  926. case H323_LINESTATE_OPENED:
  927. case H323_LINESTATE_LISTENING:
  928. if( m_fForwardConsultInProgress == TRUE )
  929. {
  930. H323DBG(( DEBUG_LEVEL_TRACE, "H323 line closed while forward is in progress." ));
  931. //Unlock();
  932. //return NOERROR;
  933. }
  934. // change line device state to closing
  935. m_nState = H323_LINESTATE_CLOSING;
  936. //shutdown all the calls
  937. ShutdownAllCalls();
  938. RasStop();
  939. if (IsMediaDetectionEnabled())
  940. {
  941. Q931AcceptStop();
  942. }
  943. ShutdownCTCallIDTable();
  944. // reset variables
  945. m_htLine = (HTAPILINE) NULL;
  946. m_dwTSPIVersion = 0;
  947. // change line device state to closed
  948. m_nState = H323_LINESTATE_NONE;
  949. dwStatus = ERROR_SUCCESS;
  950. break;
  951. default:
  952. H323DBG(( DEBUG_LEVEL_ERROR,
  953. "H323: lineclose called in bogus state:%d", m_nState ));
  954. dwStatus = LINEERR_OPERATIONFAILED;
  955. break;
  956. }
  957. Unlock();
  958. H323DBG(( DEBUG_LEVEL_TRACE, "H323 line close exited." ));
  959. return dwStatus;
  960. }
  961. //
  962. // TSPI procedures
  963. //
  964. /*++
  965. Routine Description:
  966. This function closes the specified open line device after completing or
  967. aborting all outstanding calls and asynchronous operations on the device.
  968. The Service Provider has the responsibility to (eventually) report
  969. completion for every operation it decides to execute asynchronously.
  970. If this procedure is called for a line on which there are outstanding
  971. asynchronous operations, the operations should be reported complete with an
  972. appropriate result or error code before this procedure returns. Generally
  973. the TAPI DLL would wait for these to complete in an orderly fashion.
  974. However, the Service Provider should be prepared to handle an early call to
  975. TSPI_lineClose in "abort" or "emergency shutdown" situtations.
  976. A similar requirement exists for active calls on the line. Such calls must
  977. be dropped, with outstanding operations reported complete with appropriate
  978. result or error codes.
  979. After this procedure returns the Service Provider must report no further
  980. events on the line or calls that were on the line. The Service Provider's
  981. opaque handles for the line and calls on the line become "invalid".
  982. The Service Provider must relinquish non-sharable resources it reserves
  983. while the line is open. For example, closing a line accessed through a
  984. comm port and modem should result in closing the comm port, making it once
  985. available for use by other applications.
  986. This function is presumed to complete successfully and synchronously.
  987. Arguments:
  988. hdLine - Specifies the Service Provider's opaque handle to the line to be
  989. closed. After the line has been successfully closed, this handle is
  990. no longer valid.
  991. Return Values:
  992. Returns zero if the function is successful, or a negative error
  993. number if an error has occurred. Possible error returns are:
  994. LINEERR_INVALLINEHANDLE - The specified device handle is invalid.
  995. LINEERR_OPERATIONFAILED - The specified operation failed for unknown
  996. reasons.
  997. --*/
  998. LONG
  999. TSPIAPI
  1000. TSPI_lineClose (
  1001. IN HDRVLINE DriverLine)
  1002. {
  1003. _ASSERTE(DriverLine);
  1004. _ASSERTE(DriverLine == (HDRVLINE) &g_H323Line);
  1005. H323DBG(( DEBUG_LEVEL_TRACE, "TSPI_lineClose - Entered." ));
  1006. return ((CH323Line *) DriverLine) -> Close();
  1007. }
  1008. /*++
  1009. Routine Description:
  1010. This function queries a specified line device to determine its telephony
  1011. capabilities. The returned information is valid for all addresses on the
  1012. line device.
  1013. Line device ID numbering for a Service Provider is sequential from the
  1014. value set by the function TSPI_lineSetDeviceIDBase.
  1015. The dwExtVersion field of pLineDevCaps has already been filled in to
  1016. indicate the version number of the Extension information requested. If
  1017. it is zero, no Extension information is requested. If it is non-zero it
  1018. holds a value that has already been negotiated for this device with the
  1019. function TSPI_lineNegotiateExtVersion. The Service Provider should fill
  1020. in Extension information according to the Extension version specified.
  1021. One of the fields in the LINEDEVCAPS structure returned by this function
  1022. contains the number of addresses assigned to the specified line device.
  1023. The actual address IDs used to reference individual addresses vary from
  1024. zero to one less than the returned number. The capabilities of each
  1025. address may be different. Use TSPI_lineGetAddressCaps for each available
  1026. <dwDeviceID, dwAddressID> combination to determine the exact capabilities
  1027. of each address.
  1028. Arguments:
  1029. dwDeviceID - Specifies the line device to be queried.
  1030. dwTSPIVersion - Specifies the negotiated TSPI version number. This value
  1031. has already been negotiated for this device through the
  1032. TSPI_lineNegotiateTSPIVersion function.
  1033. pLineDevCaps - Specifies a far pointer to a variable sized structure of
  1034. type LINEDEVCAPS. Upon successful completion of the request, this
  1035. structure is filled with line device capabilities information.
  1036. Return Values:
  1037. Returns zero if the function is successful or a negative error
  1038. number if an error has occurred. Possible error returns are:
  1039. LINEERR_BADDEVICEID - The specified line device ID is out of range.
  1040. LINEERR_INCOMPATIBLEAPIVERSION - The application requested an API
  1041. version or version range that is either incompatible or cannot
  1042. be supported by the Telephony API implementation and/or
  1043. corresponding service provider.
  1044. LINEERR_STRUCTURETOOSMALL - The dwTotalSize member of a structure
  1045. does not specify enough memory to contain the fixed portion of
  1046. the structure. The dwNeededSize field has been set to the amount
  1047. required.
  1048. --*/
  1049. LONG
  1050. TSPIAPI
  1051. TSPI_lineGetDevCaps(
  1052. DWORD dwDeviceID,
  1053. DWORD dwTSPIVersion,
  1054. DWORD dwExtVersion,
  1055. LPLINEDEVCAPS pLineDevCaps
  1056. )
  1057. {
  1058. DWORD dwLineNameSize;
  1059. DWORD dwProviderInfoSize;
  1060. H323DBG(( DEBUG_LEVEL_TRACE, "TSPI_lineGetDevCaps - Entered." ));
  1061. if( g_pH323Line -> GetDeviceID() != dwDeviceID )
  1062. {
  1063. // do not recognize device
  1064. return LINEERR_BADDEVICEID;
  1065. }
  1066. // make sure this is a version we support
  1067. if (!H323ValidateTSPIVersion(dwTSPIVersion))
  1068. {
  1069. // do not support tspi version
  1070. return LINEERR_INCOMPATIBLEAPIVERSION;
  1071. }
  1072. // determine string lengths
  1073. dwProviderInfoSize = H323SizeOfWSZ(g_pwszProviderInfo);
  1074. dwLineNameSize = H323SizeOfWSZ(g_pwszLineName);
  1075. // calculate number of bytes required
  1076. pLineDevCaps->dwNeededSize = sizeof(LINEDEVCAPS) +
  1077. dwProviderInfoSize +
  1078. dwLineNameSize
  1079. ;
  1080. // make sure buffer is large enough for variable length data
  1081. if (pLineDevCaps->dwTotalSize >= pLineDevCaps->dwNeededSize)
  1082. {
  1083. // record amount of memory used
  1084. pLineDevCaps->dwUsedSize = pLineDevCaps->dwNeededSize;
  1085. // position provider info after fixed portion
  1086. pLineDevCaps->dwProviderInfoSize = dwProviderInfoSize;
  1087. pLineDevCaps->dwProviderInfoOffset = sizeof(LINEDEVCAPS);
  1088. // position line name after device class
  1089. pLineDevCaps->dwLineNameSize = dwLineNameSize;
  1090. pLineDevCaps->dwLineNameOffset =
  1091. pLineDevCaps->dwProviderInfoOffset +
  1092. pLineDevCaps->dwProviderInfoSize
  1093. ;
  1094. // copy provider info after fixed portion
  1095. CopyMemory((LPBYTE)pLineDevCaps + pLineDevCaps->dwProviderInfoOffset,
  1096. (LPBYTE)g_pwszProviderInfo,
  1097. pLineDevCaps->dwProviderInfoSize
  1098. );
  1099. // copy line name after device class
  1100. CopyMemory((LPBYTE)pLineDevCaps + pLineDevCaps->dwLineNameOffset,
  1101. (LPBYTE)g_pwszLineName,
  1102. pLineDevCaps->dwLineNameSize
  1103. );
  1104. }
  1105. else if (pLineDevCaps->dwTotalSize >= sizeof(LINEDEVCAPS))
  1106. {
  1107. H323DBG(( DEBUG_LEVEL_WARNING,
  1108. "linedevcaps structure too small for strings." ));
  1109. // structure only contains fixed portion
  1110. pLineDevCaps->dwUsedSize = sizeof(LINEDEVCAPS);
  1111. }
  1112. else
  1113. {
  1114. H323DBG(( DEBUG_LEVEL_WARNING, "linedevcaps structure too small." ));
  1115. // structure is too small
  1116. return LINEERR_STRUCTURETOOSMALL;
  1117. }
  1118. H323DBG(( DEBUG_LEVEL_VERBOSE, "line capabilities requested."));
  1119. // construct permanent line identifier
  1120. pLineDevCaps->dwPermanentLineID = (DWORD)MAKELONG(
  1121. dwDeviceID - g_dwLineDeviceIDBase,
  1122. g_dwPermanentProviderID
  1123. );
  1124. // notify tapi that strings returned are in unicode
  1125. pLineDevCaps->dwStringFormat = STRINGFORMAT_UNICODE;
  1126. // initialize line device capabilities
  1127. pLineDevCaps->dwNumAddresses = H323_MAXADDRSPERLINE;
  1128. pLineDevCaps->dwMaxNumActiveCalls = H323_MAXCALLSPERLINE;
  1129. pLineDevCaps->dwAddressModes = H323_LINE_ADDRESSMODES;
  1130. pLineDevCaps->dwBearerModes = H323_LINE_BEARERMODES;
  1131. pLineDevCaps->dwDevCapFlags = H323_LINE_DEVCAPFLAGS;
  1132. pLineDevCaps->dwLineFeatures = H323_LINE_LINEFEATURES;
  1133. pLineDevCaps->dwMaxRate = H323_LINE_MAXRATE;
  1134. pLineDevCaps->dwMediaModes = H323_LINE_MEDIAMODES;
  1135. pLineDevCaps->dwRingModes = 0;
  1136. // initialize address types to include phone numbers
  1137. pLineDevCaps->dwAddressTypes = H323_LINE_ADDRESSTYPES;
  1138. // line guid
  1139. pLineDevCaps->PermanentLineGuid = LINE_H323;
  1140. // modify GUID to be unique for each line
  1141. pLineDevCaps->PermanentLineGuid.Data1 +=
  1142. dwDeviceID - g_dwLineDeviceIDBase;
  1143. // protocol guid
  1144. pLineDevCaps->ProtocolGuid = TAPIPROTOCOL_H323;
  1145. // add dtmf support via H.245 user input messages
  1146. pLineDevCaps->dwGenerateDigitModes = LINEDIGITMODE_DTMF;
  1147. pLineDevCaps->dwMonitorDigitModes = LINEDIGITMODE_DTMF;
  1148. H323DBG(( DEBUG_LEVEL_TRACE, "TSPI_lineGetDevCaps - Exited." ));
  1149. // success
  1150. return NOERROR;
  1151. }
  1152. /*++
  1153. Routine Description:
  1154. This operation enables the TAPI DLL to query the specified open line
  1155. device for its current status.
  1156. The TAPI DLL uses TSPI_lineGetLineDevStatus to query the line device
  1157. for its current line status. This status information applies globally
  1158. to all addresses on the line device. Use TSPI_lineGetAddressStatus to
  1159. determine status information about a specific address on a line.
  1160. Arguments:
  1161. hdLine - Specifies the Service Provider's opaque handle to the line
  1162. to be queried.
  1163. pLineDevStatus - Specifies a far pointer to a variable sized data
  1164. structure of type LINEDEVSTATUS. Upon successful completion of
  1165. the request, this structure is filled with the line's device status.
  1166. Return Values:
  1167. Returns zero if the function is successful or a negative error
  1168. number if an error has occurred. Possible error returns are:
  1169. LINEERR_INVALLINEHANDLE - The specified line device handle is invalid.
  1170. LINEERR_STRUCTURETOOSMALL - The dwTotalSize member of a structure does
  1171. not specify enough memory to contain the fixed portion of the
  1172. structure. The dwNeededSize field has been set to the amount
  1173. required.
  1174. --*/
  1175. LONG
  1176. TSPIAPI
  1177. TSPI_lineGetLineDevStatus(
  1178. HDRVLINE hdLine,
  1179. LPLINEDEVSTATUS pLineDevStatus
  1180. )
  1181. {
  1182. H323DBG(( DEBUG_LEVEL_TRACE, "TSPI_lineGetDevStatus - Entered." ));
  1183. if( hdLine != g_pH323Line -> GetHDLine() )
  1184. {
  1185. return LINEERR_INVALLINEHANDLE;
  1186. }
  1187. // determine number of bytes needed
  1188. pLineDevStatus->dwNeededSize = sizeof(LINEDEVSTATUS);
  1189. // see if allocated structure is large enough
  1190. if (pLineDevStatus->dwTotalSize < pLineDevStatus->dwNeededSize)
  1191. {
  1192. H323DBG(( DEBUG_LEVEL_ERROR, "linedevstatus structure too small." ));
  1193. // structure too small
  1194. return LINEERR_STRUCTURETOOSMALL;
  1195. }
  1196. // record number of bytes used
  1197. pLineDevStatus->dwUsedSize = pLineDevStatus->dwNeededSize;
  1198. // initialize supported line device status fields
  1199. pLineDevStatus->dwLineFeatures = H323_LINE_LINEFEATURES;
  1200. pLineDevStatus->dwDevStatusFlags = H323_LINE_DEVSTATUSFLAGS;
  1201. // determine number of active calls on the line device
  1202. pLineDevStatus -> dwNumActiveCalls = g_pH323Line -> GetNoOfCalls();
  1203. H323DBG(( DEBUG_LEVEL_TRACE, "TSPI_lineGetDevStatus - Exited." ));
  1204. // success
  1205. return NOERROR;
  1206. }
  1207. /*++
  1208. Routine Description:
  1209. Retrieves the number of address IDs supported on the indicated line.
  1210. This function is called by TAPI.DLL in response to an application calling
  1211. lineSetNumRings, lineGetNumRings, or lineGetNewCalls. TAPI.DLL uses the
  1212. retrieved value to determine if the specified address ID is within the
  1213. range supported by the service provider.
  1214. Arguments:
  1215. hdLine - Specifies the handle to the line for which the number of address
  1216. IDs is to be retrieved.
  1217. pdwNumAddressIDs - Specifies a far pointer to a DWORD. The location is
  1218. filled with the number of address IDs supported on the indicated line.
  1219. The value should be one or larger.
  1220. Return Values:
  1221. Returns zero if the function is successful, or a negative error number
  1222. if an error has occurred. Possible return values are as follows:
  1223. LINEERR_INVALLINEHANDLE - The specified line device handle is invalid.
  1224. --*/
  1225. LONG
  1226. TSPIAPI
  1227. TSPI_lineGetNumAddressIDs(
  1228. HDRVLINE hdLine,
  1229. LPDWORD pdwNumAddressIDs
  1230. )
  1231. {
  1232. H323DBG(( DEBUG_LEVEL_TRACE, "TSPI_lineGetNumAddressIDs - Entered." ));
  1233. if( hdLine != g_pH323Line -> GetHDLine() )
  1234. {
  1235. H323DBG(( DEBUG_LEVEL_TRACE, "TSPI_lineGetNumAddressIDs - bad linehandle:%lx, %lx.",
  1236. hdLine, g_pH323Line -> GetHDLine() ));
  1237. return LINEERR_INVALLINEHANDLE ;
  1238. }
  1239. // transfer number of addresses
  1240. *pdwNumAddressIDs = H323_MAXADDRSPERLINE;
  1241. H323DBG(( DEBUG_LEVEL_TRACE, "TSPI_lineGetNumAddressIDs - Exited." ));
  1242. // success
  1243. return NOERROR;
  1244. }
  1245. /*++
  1246. Routine Description:
  1247. This function opens the line device whose device ID is given, returning
  1248. the Service Provider's opaque handle for the device and retaining the TAPI
  1249. DLL's opaque handle for the device for use in subsequent calls to the
  1250. LINEEVENT procedure.
  1251. Opening a line entitles the TAPI DLL to make further requests on the line.
  1252. The line becomes "active" in the sense that the TAPI DLL can initiate
  1253. outbound calls and the Service Provider can report inbound calls. The
  1254. Service Provider reserves whatever non-sharable resources are required to
  1255. manage the line. For example, opening a line accessed through a comm port
  1256. and modem should result in opening the comm port, making it no longer
  1257. available for use by other applications.
  1258. If the function is successful, both the TAPI DLL and the Service Provider
  1259. become committed to operating under the specified interface version number
  1260. for this open device. Subsquent operations and events identified using
  1261. the exchanged opaque line handles conform to that interface version. This
  1262. commitment and the validity of the handles remain in effect until the TAPI
  1263. DLL closes the line using the TSPI_lineClose operation or the Service
  1264. Provider reports the LINE_CLOSE event. If the function is not successful,
  1265. no such commitment is made and the handles are not valid.
  1266. Arguments:
  1267. dwDeviceID - Identifies the line device to be opened. The value
  1268. LINE_MAPPER for a device ID is not permitted.
  1269. htLine - Specifies the TAPI DLL's opaque handle for the line device to be
  1270. used in subsequent calls to the LINEEVENT callback procedure to
  1271. identify the device.
  1272. phdLine - A far pointer to a HDRVLINE where the Service Provider fills in
  1273. its opaque handle for the line device to be used by the TAPI DLL in
  1274. subsequent calls to identify the device.
  1275. dwTSPIVersion - The TSPI version negotiated through
  1276. TSPI_lineNegotiateTSPIVersion under which the Service Provider is
  1277. willing to operate.
  1278. pfnEventProc - A far pointer to the LINEEVENT callback procedure supplied
  1279. by the TAPI DLL that the Service Provider will call to report
  1280. subsequent events on the line.
  1281. Return Values:
  1282. Returns zero if the function is successful, or a negative error number
  1283. if an error has occurred. Possible return values are as follows:
  1284. LINEERR_BADDEVICEID - The specified line device ID is out of range.
  1285. LINEERR_INCOMPATIBLEAPIVERSION - The passed TSPI version or version
  1286. range did not match an interface version definition supported by
  1287. the service provider.
  1288. LINEERR_INUSE - The line device is in use and cannot currently be
  1289. configured, allow a party to be added, allow a call to be
  1290. answered, or allow a call to be placed.
  1291. LINEERR_OPERATIONFAILED - The operation failed for an unspecified or
  1292. unknown reason.
  1293. --*/
  1294. LONG
  1295. TSPIAPI
  1296. TSPI_lineOpen (
  1297. IN DWORD DeviceID,
  1298. IN HTAPILINE TapiLine,
  1299. IN LPHDRVLINE ReturnDriverLine,
  1300. IN DWORD TspiVersion,
  1301. IN LINEEVENT pfnEventProc)
  1302. {
  1303. return g_H323Line.Open (DeviceID, TapiLine, TspiVersion, ReturnDriverLine);
  1304. }
  1305. LONG
  1306. TSPIAPI
  1307. TSPI_lineCreateMSPInstance(
  1308. HDRVLINE hdLine,
  1309. DWORD dwAddressID,
  1310. HTAPIMSPLINE htMSPLine,
  1311. LPHDRVMSPLINE phdMSPLine
  1312. )
  1313. {
  1314. H323DBG(( DEBUG_LEVEL_TRACE, "TSPI_lineCreateMSPInstance - Entered." ));
  1315. if( hdLine != g_pH323Line -> GetHDLine() )
  1316. {
  1317. return LINEERR_RESOURCEUNAVAIL;
  1318. }
  1319. // We are not keeping the msp handles. Just fake a handle here.
  1320. *phdMSPLine = g_pH323Line->GetNextMSPHandle();
  1321. if( !g_pH323Line->AddMSPInstance( htMSPLine , *phdMSPLine ) )
  1322. {
  1323. return LINEERR_NOMEM;
  1324. }
  1325. H323DBG(( DEBUG_LEVEL_TRACE, "MSP instance created. hdMSP:%lx, htMSP:%lx.",
  1326. *phdMSPLine, htMSPLine ));
  1327. H323DBG(( DEBUG_LEVEL_TRACE, "TSPI_lineCreateMSPInstance - Exited." ));
  1328. // success
  1329. return NOERROR;
  1330. }
  1331. LONG
  1332. TSPIAPI
  1333. TSPI_lineCloseMSPInstance(
  1334. HDRVMSPLINE hdMSPLine
  1335. )
  1336. {
  1337. HTAPIMSPLINE htMSPLine;
  1338. H323DBG(( DEBUG_LEVEL_TRACE, "TSPI_lineCloseMSPInstance - Entered." ));
  1339. if( !g_pH323Line->DeleteMSPInstance( &htMSPLine , hdMSPLine ) )
  1340. {
  1341. return LINEERR_INVALPOINTER;
  1342. }
  1343. H323DBG(( DEBUG_LEVEL_TRACE, "MSP instance deleted. hdMSP:%lx, htMSP:%lx.",
  1344. hdMSPLine, htMSPLine ));
  1345. H323DBG(( DEBUG_LEVEL_TRACE, "TSPI_lineCloseMSPInstance - Exited." ));
  1346. // success
  1347. return NOERROR;
  1348. }