Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

860 lines
24 KiB

  1. /******************************************************************************
  2. *
  3. * File: h245_sr.c
  4. *
  5. * INTEL Corporation Proprietary Information
  6. * Copyright (c) 1994, 1995, 1996 Intel Corporation.
  7. *
  8. * This listing is supplied under the terms of a license agreement
  9. * with INTEL Corporation and may not be used, copied, nor disclosed
  10. * except in accordance with the terms of that agreement.
  11. *
  12. *****************************************************************************/
  13. /******************************************************************************
  14. *
  15. * $Workfile: h245_sr.c $
  16. * $Revision: 1.10 $
  17. * $Modtime: Mar 04 1997 17:30:56 $
  18. * $Log: S:/STURGEON/SRC/H245/SRC/VCS/h245_sr.c_v $
  19. *
  20. * Rev 1.11 Jun 25 1998 00:00:00 mikev@microsoft.com
  21. * STRIPPED PLUGIN LINK LAYER AND COMBINED THE SEPARATE DLLs
  22. *
  23. * Rev 1.10 Mar 04 1997 17:51:22 tomitowx
  24. * process detach fix
  25. *
  26. * Rev 1.9 11 Dec 1996 13:55:20 SBELL1
  27. * Changed linkLayerInit parameters
  28. *
  29. * Rev 1.8 14 Oct 1996 14:05:52 EHOWARDX
  30. *
  31. * Used cast to get rid of warning.
  32. *
  33. * Rev 1.7 14 Oct 1996 14:01:30 EHOWARDX
  34. * Unicode changes.
  35. *
  36. * Rev 1.6 23 Jul 1996 08:57:08 EHOWARDX
  37. *
  38. * Moved H245 interop logger init/deinit from H245_SR.C (per-instance)
  39. * to H245MAIN.C (per-DLL). With multiple instances and a global variable,
  40. * per-instance init/deinit is fundamentally brain-dead.
  41. *
  42. * Rev 1.5 22 Jul 1996 17:33:44 EHOWARDX
  43. * Updated to latest Interop API.
  44. *
  45. * Rev 1.4 05 Jun 1996 17:13:50 EHOWARDX
  46. * Further work on converting to HRESULT; added PrintOssError to eliminate
  47. * pErrorString from instance structure.
  48. *
  49. * Rev 1.3 04 Jun 1996 18:17:32 EHOWARDX
  50. * Interop Logging changes inside #if defined(PCS_COMPLIANCE) conditionals.
  51. *
  52. * Rev 1.2 29 May 1996 15:20:20 EHOWARDX
  53. * Change to use HRESULT.
  54. *
  55. * Rev 1.1 28 May 1996 14:25:32 EHOWARDX
  56. * Tel Aviv update.
  57. *
  58. * Rev 1.0 09 May 1996 21:06:28 EHOWARDX
  59. * Initial revision.
  60. *
  61. * Rev 1.17.1.6 09 May 1996 19:34:40 EHOWARDX
  62. * Redesigned locking logic.
  63. * Simplified link API.
  64. *
  65. * Rev 1.17.1.5 29 Apr 1996 19:42:42 EHOWARDX
  66. * Commented out linkLayerFlushAll() call and synchronized with Rev 1.30.
  67. *
  68. * Rev 1.26 29 Apr 1996 12:53:16 EHOWARDX
  69. * Commented out receive thread/receive queue code.
  70. *
  71. * Rev 1.17.1.4 25 Apr 1996 21:27:04 EHOWARDX
  72. * Changed to use h245Instance->p_ossWorld instead of bAsnInitialized.
  73. *
  74. * Rev 1.17.1.3 23 Apr 1996 14:44:22 EHOWARDX
  75. * Updated.
  76. *
  77. * Rev 1.17.1.2 15 Apr 1996 15:11:54 EHOWARDX
  78. * Updated.
  79. *
  80. * Rev 1.17.1.1 26 Mar 1996 19:13:50 EHOWARDX
  81. *
  82. * Commented out hTraceFile.
  83. *
  84. * Rev 1.17.1.0 26 Mar 1996 13:11:22 EHOWARDX
  85. * Branced and added H245_CONF_H323 to sendRecvInit
  86. *
  87. * Rev 1.17 19 Mar 1996 18:09:04 helgebax
  88. * removed old timer code
  89. *
  90. * Rev 1.16 13 Mar 1996 11:30:44 DABROWN1
  91. *
  92. * Enable logging for ring 0
  93. *
  94. * Rev 1.15 11 Mar 1996 15:39:18 DABROWN1
  95. *
  96. * modifications required for ring0/ring3 compatiblity
  97. *
  98. * Rev 1.13 06 Mar 1996 13:12:24 DABROWN1
  99. *
  100. * flush link layer buffers at shutdown
  101. *
  102. * Rev 1.12 02 Mar 1996 22:11:10 DABROWN1
  103. *
  104. * changed h245_bzero to memset
  105. *
  106. * Rev 1.11 01 Mar 1996 17:24:46 DABROWN1
  107. *
  108. * moved oss 'world' context to h245instance
  109. *
  110. * Rev 1.10 28 Feb 1996 18:45:00 EHOWARDX
  111. *
  112. * Added H245TimerStart and H245TimerStop to linkLayerInit call.
  113. *
  114. * Rev 1.9 28 Feb 1996 15:43:52 EHOWARDX
  115. *
  116. * Removed sample code.
  117. * Added code to free up all events on timer queue before deallocating.
  118. *
  119. * Rev 1.8 27 Feb 1996 13:35:10 DABROWN1
  120. *
  121. * added h245instance in datalink initialization routine
  122. *
  123. * Rev 1.7 26 Feb 1996 18:59:34 EHOWARDX
  124. *
  125. * Added H245TimerStart and H245TimerStop functions.
  126. * Also added sample timer function, which should be removed later.
  127. *
  128. * Rev 1.6 23 Feb 1996 22:17:26 EHOWARDX
  129. *
  130. * Fixed check at start of sendRecvShutdown.
  131. * It's an error if dwInst is greater than or equal to MAXINST, not less than!
  132. *
  133. * Rev 1.5 23 Feb 1996 21:59:28 EHOWARDX
  134. *
  135. * winspox changes.
  136. *
  137. * Rev 1.4 23 Feb 1996 13:55:30 DABROWN1
  138. *
  139. * added h245TRACE ASSERT calls
  140. *
  141. * Rev 1.3 21 Feb 1996 15:12:36 EHOWARDX
  142. *
  143. * Forgot to replace H245ReceiveComplete with H245ReceivePost.
  144. *
  145. * Rev 1.2 20 Feb 1996 19:14:20 EHOWARDX
  146. * Added in mailbox changes.
  147. *
  148. * Rev 1.1 21 Feb 1996 08:26:28 DABROWN1
  149. *
  150. * create and free multiple receive buffers.
  151. * Make size of buffer dependent on protocol in use
  152. *
  153. * Rev 1.0 09 Feb 1996 17:34:24 cjutzi
  154. * Initial revision.
  155. *
  156. *****************************************************************************/
  157. #ifndef STRICT
  158. #define STRICT
  159. #endif
  160. /***********************/
  161. /* SYSTEM INCLUDES */
  162. /***********************/
  163. #include <stdio.h>
  164. #include <stdlib.h>
  165. #include <stddef.h>
  166. #include <limits.h>
  167. #include "precomp.h"
  168. /***********************/
  169. /* H245 INCLUDES */
  170. /***********************/
  171. #include "h245com.h"
  172. #include "sr_api.h"
  173. #include "linkapi.h"
  174. #if defined(USE_RECEIVE_QUEUE)
  175. DWORD
  176. ReceiveThread(VOID *lpThreadParameter)
  177. {
  178. struct InstanceStruct *pInstance = (struct InstanceStruct *)lpThreadParameter;
  179. RXMSG RxMsg;
  180. Uns uTimeout;
  181. Bool bPendResult;
  182. SETTASK("H245RCVTASK0");
  183. if (pInstance == NULL) {
  184. H245PANIC();
  185. return SR_INVALID_CONTEXT;
  186. }
  187. // Loop until thread is ready to terminate
  188. pInstance->SendReceive.bReceiveThread = TRUE;
  189. for ( ; ; )
  190. {
  191. uTimeout = SYS_FOREVER;
  192. // Wait for an event (or a queued callback function) to wake us up.
  193. // This is an alertable wait state (fAlertable == TRUE)
  194. pInstance->SendReceive.bReceiveThread = FALSE;
  195. H245TRACE(pInstance->dwInst, 2, "ReceiveThread, uTimeout = %d", uTimeout);
  196. RESETTASK();
  197. bPendResult = MBX_pend(pInstance->SendReceive.pMailbox, &RxMsg, uTimeout);
  198. SETTASK("H245RCVTASK");
  199. H245TRACE(pInstance->pInstance->dwInst, 2, "ReceiveThread, bPendResult = %d", bPendResult);
  200. pInstance->SendReceive.bReceiveThread = TRUE;
  201. switch (RxMsg.dwMessage) {
  202. case EXIT_RECEIVE_THREAD:
  203. // Thread exiting....signal app
  204. TRACE("H245: Receive Thread Exiting");
  205. SEM_post(pInstance->SendReceive.hReceiveSemphore);
  206. RESETTASK();
  207. return 0;
  208. break;
  209. default:
  210. // Ignore timer message, which should have dwLength == 0
  211. if (RxMsg.dwLength)
  212. {
  213. h245ReceiveComplete(RxMsg.h245Inst,
  214. RxMsg.dwMessage,
  215. RxMsg.pbDataBuf,
  216. RxMsg.dwLength);
  217. }
  218. else
  219. {
  220. TRACE1("H245SEND: SendTask %d", RxMsg.dwMessage);
  221. h245SendComplete(RxMsg.h245Inst,
  222. RxMsg.dwMessage,
  223. RxMsg.pbDataBuf,
  224. RxMsg.dwLength);
  225. }
  226. break;
  227. } // switch
  228. } // for
  229. return 0;
  230. } // ReceiveThread()
  231. static void
  232. h245ReceivePost(DWORD h245Inst,
  233. DWORD dwMessage,
  234. PBYTE pbDataBuf,
  235. DWORD dwLength)
  236. {
  237. register struct InstanceStruct *pInstance;
  238. RXMSG RxMsg;
  239. // Validate the instance handle
  240. pInstance = InstanceLock(h245Inst);
  241. if (pInstance == NULL) {
  242. H245TRACE(h245Inst, 1, "h245ReceivePost h245Inst Invalid");
  243. H245PANIC();
  244. return;
  245. }
  246. RxMsg.h245Inst = h245Inst;
  247. RxMsg.dwMessage = dwMessage;
  248. RxMsg.pbDataBuf = pbDataBuf;
  249. RxMsg.dwLength = dwLength;
  250. if (MBX_post(pInstance->SendReceive.pMailbox, &RxMsg, 0) == FALSE) {
  251. H245TRACE(h245Inst, 1, "SR: MBX POST FAIL");
  252. H245PANIC();
  253. }
  254. InstanceUnlock(pInstance);
  255. } // h245ReceivePost()
  256. #endif // (USE_RECEIVE_QUEUE)
  257. HRESULT
  258. initializeLinkDllEntry
  259. (
  260. struct InstanceStruct * pInstance,
  261. LPCTSTR szDLLFile
  262. )
  263. {
  264. #if(0)
  265. if (!(pInstance->SendReceive.hLinkModule = LoadLibrary(szDLLFile))) {
  266. return H245_ERROR_FATAL;
  267. }
  268. if (!(pInstance->SendReceive.hLinkLayerInit = (PFxnlinkLayerInit)
  269. GetProcAddress(pInstance->SendReceive.hLinkModule,
  270. LINKINITIALIZE))) {
  271. return H245_ERROR_FATAL;
  272. }
  273. if (!(pInstance->SendReceive.hLinkShutdown = (PFxnlinkLayerShutdown)
  274. GetProcAddress(pInstance->SendReceive.hLinkModule,
  275. LINKSHUTDOWN))) {
  276. return H245_ERROR_FATAL;
  277. }
  278. if (!(pInstance->SendReceive.hLinkGetInstance = (PFxnlinkLayerGetInstance)
  279. GetProcAddress(pInstance->SendReceive.hLinkModule,
  280. LINKGETINSTANCE))) {
  281. return H245_ERROR_FATAL;
  282. }
  283. if (!(pInstance->SendReceive.hLinkReceiveReq = (PFxndatalinkReceiveRequest)
  284. GetProcAddress(pInstance->SendReceive.hLinkModule,
  285. LINKRECEIVEREQUEST))) {
  286. return H245_ERROR_FATAL;
  287. }
  288. if (!(pInstance->SendReceive.hLinkSendReq = (PFxndatalinkSendRequest)
  289. GetProcAddress(pInstance->SendReceive.hLinkModule,
  290. LINKSENDREQUEST))) {
  291. return H245_ERROR_FATAL;
  292. }
  293. if (!(pInstance->SendReceive.hLinkLayerFlushChannel = (PFxnlinkLayerFlushChannel)
  294. GetProcAddress(pInstance->SendReceive.hLinkModule,
  295. LINKFLUSHCHANNEL))) {
  296. return H245_ERROR_FATAL;
  297. }
  298. if (!(pInstance->SendReceive.hLinkLayerFlushAll = (PFxnlinkLayerFlushAll)
  299. GetProcAddress(pInstance->SendReceive.hLinkModule,
  300. LINKFLUSHALL))) {
  301. return H245_ERROR_FATAL;
  302. }
  303. #else
  304. pInstance->SendReceive.hLinkLayerInit = linkLayerInit;
  305. pInstance->SendReceive.hLinkShutdown = linkLayerShutdown;
  306. pInstance->SendReceive.hLinkGetInstance = linkLayerGetInstance;
  307. pInstance->SendReceive.hLinkReceiveReq = datalinkReceiveRequest;
  308. pInstance->SendReceive.hLinkSendReq = datalinkSendRequest;
  309. pInstance->SendReceive.hLinkLayerFlushChannel = linkLayerFlushChannel;
  310. pInstance->SendReceive.hLinkLayerFlushAll = linkLayerFlushAll;
  311. #endif //if(0)
  312. H245TRACE(pInstance->dwInst,
  313. 3,
  314. "SR: %s Loaded", szDLLFile);
  315. return (0);
  316. }
  317. #if defined(_DEBUG) && defined(H324)
  318. void
  319. srInitializeLogging
  320. (
  321. struct InstanceStruct *pInstance,
  322. BOOL bTracingEnabled
  323. )
  324. {
  325. FILE *hTraceFile;
  326. char initTraceFile[20] = "c:\\tmp\\h2450.000";
  327. BOOL bSearch = TRUE; // search for filename
  328. if (pInstance == NULL) {
  329. H245TRACE(h245Inst, 1, "SR:Enable Log Instance Error");
  330. H245PANIC();
  331. return;
  332. }
  333. // eventually will be from registry
  334. pInstance->SendReceive.bLoggingEnabled = bTracingEnabled;
  335. if (pInstance->SendReceive.bLoggingEnabled) {
  336. // Init the logger file for Ring0/SPOX implementations. Loop until
  337. // we get the next available revision
  338. memcpy(pInstance->SendReceive.fTraceFile,
  339. initTraceFile,
  340. 20);
  341. pInstance->SendReceive.fTraceFile[11] = ((unsigned char)pInstance->dwInst & 0xF) + 0x30;
  342. do {
  343. hTraceFile = fopen(pInstance->SendReceive.fTraceFile, "r");
  344. if ((hTraceFile == NULL) || ((int)hTraceFile == -1)) {
  345. bSearch = FALSE;
  346. }
  347. else {
  348. // able to open the file. close it and try the next one
  349. fclose(hTraceFile);
  350. // get the next revision number
  351. if (pInstance->SendReceive.fTraceFile[15] == '9') {
  352. pInstance->SendReceive.fTraceFile[15] = '0';
  353. if (pInstance->SendReceive.fTraceFile[14] == '9') {
  354. pInstance->SendReceive.fTraceFile[14] = '0';
  355. pInstance->SendReceive.fTraceFile[13]++;
  356. }
  357. else {
  358. pInstance->SendReceive.fTraceFile[14]++;
  359. }
  360. }
  361. else {
  362. pInstance->SendReceive.fTraceFile[15]++;
  363. }
  364. }
  365. }while (bSearch);
  366. hTraceFile = fopen(pInstance->SendReceive.fTraceFile, "wb");
  367. if ((hTraceFile == NULL) || ((int)hTraceFile == -1)) {
  368. pInstance->SendReceive.bLoggingEnabled = FALSE;
  369. H245TRACE(h245Inst,
  370. 1,
  371. "SR: Trace File CREATE ERROR");
  372. }
  373. else {
  374. // Close the file. Will be opened immediately before writing
  375. // and closed immediately thereafter
  376. pInstance->SendReceive.bLoggingEnabled = TRUE;
  377. fclose(hTraceFile);
  378. }
  379. }
  380. }
  381. #endif // (_DEBUG)
  382. HRESULT
  383. sendRcvShutdown
  384. (
  385. struct InstanceStruct *pInstance
  386. )
  387. {
  388. #if defined(USE_RECEIVE_QUEUE)
  389. RXMSG RxMsg;
  390. #endif // (USE_RECEIVE_QUEUE)
  391. int i;
  392. if (pInstance == NULL) {
  393. H245TRACE(pInstance->dwInst, 1, "SR: Shutdown Instance Error");
  394. return H245_ERROR_INVALID_INST;
  395. }
  396. if (pInstance->pWorld) {
  397. // Shutdown the ASN.1 libraries
  398. terminateASN1(pInstance->pWorld);
  399. // Free the ASN.1 global structure
  400. MemFree( pInstance->pWorld);
  401. pInstance->pWorld = NULL;
  402. }
  403. // Shutdown link layer
  404. #if(0)
  405. if (pInstance->SendReceive.hLinkModule) {
  406. // First get all buffers back that may still be lurking
  407. // if (pInstance->SendReceive.hLinkLayerFlushAll) {
  408. // pInstance->SendReceive.hLinkLayerFlushAll(pInstance->SendReceive.hLinkLayerInstance);
  409. // }
  410. if (pInstance->SendReceive.hLinkShutdown) {
  411. pInstance->SendReceive.hLinkShutdown(pInstance->SendReceive.hLinkLayerInstance);
  412. }
  413. FreeLibrary(pInstance->SendReceive.hLinkModule);
  414. pInstance->SendReceive.hLinkModule = NULL;
  415. }
  416. #else
  417. pInstance->SendReceive.hLinkShutdown(pInstance->SendReceive.hLinkLayerInstance);
  418. #endif // if(0)
  419. // return buffers from data link layer
  420. for (i = 0; i < pInstance->SendReceive.dwNumRXBuffers; ++i) {
  421. if (pInstance->SendReceive.lpRxBuffer[i]) {
  422. MemFree( pInstance->SendReceive.lpRxBuffer[i]);
  423. pInstance->SendReceive.lpRxBuffer[i] = NULL;
  424. }
  425. }
  426. #if defined(USE_RECEIVE_QUEUE)
  427. // Terminate receive thread
  428. if (pInstance->SendReceive.pTaskReceive && pInstance->SendReceive.pMailbox) {
  429. TRACE("H245: Task/Mbox Present");
  430. // First post a message to have it exit
  431. RxMsg.h245Inst = (DWORD)pInstance;
  432. RxMsg.dwMessage = EXIT_RECEIVE_THREAD;
  433. RxMsg.pbDataBuf = NULL;
  434. RxMsg.dwLength = 0;
  435. #ifdef _IA_SPOX_
  436. if (RIL_WriteMailbox(pInstance->SendReceive.pMailbox, (PMBoxMessage)&RxMsg, 0) == OIL_TIMEOUT) {
  437. #else
  438. if (MBX_post(pInstance->SendReceive.pMailbox, &RxMsg, 0) == FALSE) {
  439. #endif //_IA_SPOX_
  440. H245TRACE(h245Inst, 1, "SR: Shutdown MBX POST FAIL");
  441. H245PANIC();
  442. }
  443. // Wait on semaphore for receive task to exit
  444. #ifdef _IA_SPOX_
  445. RIL_WaitForSemaphore(pInstance->SendReceive.hReceiveSemphore, OIL_WAITFOREVER);
  446. #else
  447. SEM_pend(pInstance->SendReceive.hReceiveSemphore, SYS_FOREVER);
  448. #endif //_IA_SPOX_
  449. TRACE("H245: ReceiveTask Semaphore");
  450. #ifdef _IA_SPOX_
  451. RIL_DeleteTask(pInstance->SendReceive.pTaskReceive);
  452. #else
  453. TSK_delete(pInstance->SendReceive.pTaskReceive);
  454. #endif //_IA_SPOX_
  455. pInstance->SendReceive.pTaskReceive = NULL;
  456. #ifdef _IA_SPOX_
  457. RIL_DeleteSemaphore(pInstance->SendReceive.hReceiveSemphore);
  458. #else
  459. SEM_delete(pInstance->SendReceive.hReceiveSemphore);
  460. #endif //_IA_SPOX_
  461. pInstance->SendReceive.hReceiveSemphore = NULL;
  462. TRACE("H245: Semaphore Delete");
  463. }
  464. // Deallocate mailbox
  465. if (pInstance->SendReceive.pMailbox) {
  466. #ifdef _IA_SPOX_
  467. RIL_DeleteMailbox(pInstance->SendReceive.pMailbox);
  468. #else
  469. MBX_delete(pInstance->SendReceive.pMailbox);
  470. #endif //_IA_SPOX_
  471. pInstance->SendReceive.pMailbox = NULL;
  472. }
  473. #endif // (USE_RECEIVE_QUEUE)
  474. H245TRACE(pInstance->dwInst, 3, "SR: Shutdown Complete");
  475. return H245_ERROR_OK;
  476. } // sendRcvShutdown()
  477. HRESULT
  478. sendRcvShutdown_ProcessDetach( struct InstanceStruct *pInstance, BOOL fProcessDetach)
  479. {
  480. #if defined(USE_RECEIVE_QUEUE)
  481. RXMSG RxMsg;
  482. #endif // (USE_RECEIVE_QUEUE)
  483. int i;
  484. if (pInstance == NULL) {
  485. H245TRACE(pInstance->dwInst, 1, "SR: Shutdown Instance Error");
  486. return H245_ERROR_INVALID_INST;
  487. }
  488. if (pInstance->pWorld) {
  489. // Shutdown the ASN.1 libraries
  490. terminateASN1(pInstance->pWorld);
  491. // Free the ASN.1 global structure
  492. MemFree( pInstance->pWorld);
  493. pInstance->pWorld = NULL;
  494. }
  495. // Shutdown link layer
  496. if (pInstance->SendReceive.hLinkModule) {
  497. // First get all buffers back that may still be lurking
  498. // if (pInstance->SendReceive.hLinkLayerFlushAll) {
  499. // pInstance->SendReceive.hLinkLayerFlushAll(pInstance->SendReceive.hLinkLayerInstance);
  500. // }
  501. //[email protected]
  502. if(!fProcessDetach)
  503. {
  504. H245TRACE(0, 0, "***** fProcessDetach = FALSE");
  505. if (pInstance->SendReceive.hLinkShutdown) {
  506. pInstance->SendReceive.hLinkShutdown(pInstance->SendReceive.hLinkLayerInstance);
  507. }
  508. }
  509. //[email protected]
  510. FreeLibrary(pInstance->SendReceive.hLinkModule);
  511. pInstance->SendReceive.hLinkModule = NULL;
  512. }
  513. // return buffers from data link layer
  514. for (i = 0; i < pInstance->SendReceive.dwNumRXBuffers; ++i) {
  515. if (pInstance->SendReceive.lpRxBuffer[i]) {
  516. MemFree( pInstance->SendReceive.lpRxBuffer[i]);
  517. pInstance->SendReceive.lpRxBuffer[i] = NULL;
  518. }
  519. }
  520. #if defined(USE_RECEIVE_QUEUE)
  521. // Terminate receive thread
  522. if (pInstance->SendReceive.pTaskReceive && pInstance->SendReceive.pMailbox) {
  523. TRACE("H245: Task/Mbox Present");
  524. // First post a message to have it exit
  525. RxMsg.h245Inst = (DWORD)pInstance;
  526. RxMsg.dwMessage = EXIT_RECEIVE_THREAD;
  527. RxMsg.pbDataBuf = NULL;
  528. RxMsg.dwLength = 0;
  529. #ifdef _IA_SPOX_
  530. if (RIL_WriteMailbox(pInstance->SendReceive.pMailbox, (PMBoxMessage)&RxMsg, 0) == OIL_TIMEOUT) {
  531. #else
  532. if (MBX_post(pInstance->SendReceive.pMailbox, &RxMsg, 0) == FALSE) {
  533. #endif //_IA_SPOX_
  534. H245TRACE(h245Inst, 1, "SR: Shutdown MBX POST FAIL");
  535. H245PANIC();
  536. }
  537. // Wait on semaphore for receive task to exit
  538. #ifdef _IA_SPOX_
  539. RIL_WaitForSemaphore(pInstance->SendReceive.hReceiveSemphore, OIL_WAITFOREVER);
  540. #else
  541. SEM_pend(pInstance->SendReceive.hReceiveSemphore, SYS_FOREVER);
  542. #endif //_IA_SPOX_
  543. TRACE("H245: ReceiveTask Semaphore");
  544. #ifdef _IA_SPOX_
  545. RIL_DeleteTask(pInstance->SendReceive.pTaskReceive);
  546. #else
  547. TSK_delete(pInstance->SendReceive.pTaskReceive);
  548. #endif //_IA_SPOX_
  549. pInstance->SendReceive.pTaskReceive = NULL;
  550. #ifdef _IA_SPOX_
  551. RIL_DeleteSemaphore(pInstance->SendReceive.hReceiveSemphore);
  552. #else
  553. SEM_delete(pInstance->SendReceive.hReceiveSemphore);
  554. #endif //_IA_SPOX_
  555. pInstance->SendReceive.hReceiveSemphore = NULL;
  556. TRACE("H245: Semaphore Delete");
  557. }
  558. // Deallocate mailbox
  559. if (pInstance->SendReceive.pMailbox) {
  560. #ifdef _IA_SPOX_
  561. RIL_DeleteMailbox(pInstance->SendReceive.pMailbox);
  562. #else
  563. MBX_delete(pInstance->SendReceive.pMailbox);
  564. #endif //_IA_SPOX_
  565. pInstance->SendReceive.pMailbox = NULL;
  566. }
  567. #endif // (USE_RECEIVE_QUEUE)
  568. H245TRACE(pInstance->dwInst, 3, "SR: Shutdown Complete");
  569. return H245_ERROR_OK;
  570. } // sendRcvShutdown_ProcessDetach()
  571. HRESULT
  572. sendRcvInit
  573. (
  574. struct InstanceStruct *pInstance
  575. )
  576. {
  577. int rc;
  578. LPTSTR szDLLFile;
  579. int i;
  580. //MULTITHREAD
  581. DWORD dwTmpPhysID = INVALID_PHYS_ID;
  582. // Overall oss ASN.1 initialization routine. First allocate
  583. // resources for its global structure, then initialize the
  584. // subsystem.
  585. pInstance->pWorld = (ASN1_CODER_INFO *)MemAlloc(sizeof(ASN1_CODER_INFO));
  586. if (pInstance->pWorld == NULL) {
  587. H245TRACE(pInstance->dwInst, 1, "SR: SndRecvInit - No Memory");
  588. return H245_ERROR_NOMEM;
  589. }
  590. if (initializeASN1(pInstance->pWorld) != 0) {
  591. H245TRACE(pInstance->dwInst, 1, "SR: SndRecvInit - ASN.1 Encoder/Decoder initialization failed");
  592. // Free the ASN.1 global structure
  593. MemFree(pInstance->pWorld);
  594. pInstance->pWorld = NULL;
  595. return H245_ERROR_ASN1;
  596. }
  597. // Initialization proceeding well. Wake up the
  598. // data link layers, if necessary, based on the
  599. // underlying protocol.
  600. switch (pInstance->Configuration) {
  601. #if(0)
  602. case H245_CONF_H324:
  603. // Get the DLL
  604. szDLLFile = (LPTSTR)SRPDLLFILE;
  605. // Initialize default size of PDU for SRP
  606. pInstance->SendReceive.dwPDUSize = LL_PDU_SIZE + 4;
  607. pInstance->SendReceive.dwNumRXBuffers = NUM_SRP_LL_RCV_BUFFERS;
  608. break;
  609. #endif
  610. case H245_CONF_H323:
  611. // Get the DLL
  612. szDLLFile = (LPTSTR)H245WSDLLFILE;
  613. // Initialize default size of PDU
  614. pInstance->SendReceive.dwPDUSize = LL_PDU_SIZE;
  615. pInstance->SendReceive.dwNumRXBuffers = MAX_LL_BUFFERS;
  616. break;
  617. default:
  618. H245TRACE(pInstance->dwInst, 1, "SR: SndRecvInit - Invalid configuration %d", pInstance->Configuration);
  619. return H245_ERROR_SUBSYS;
  620. }
  621. // Load and Initialize Datalink layer
  622. if ((rc = initializeLinkDllEntry(pInstance, szDLLFile)) != 0) {
  623. H245TRACE(pInstance->dwInst, 1, "SR: Link Open Lib Fail %d", rc);
  624. return rc;
  625. }
  626. //MULTITHREAD
  627. //use dwTmpPhysID so PhysID doesn't change.
  628. //PhysID is different var for H245 than H245ws.
  629. //Use hLinkLayerInstance for H245ws PhysID.
  630. rc = pInstance->SendReceive.hLinkLayerInit(&dwTmpPhysID,
  631. pInstance->dwInst,
  632. #if defined(USE_RECEIVE_QUEUE)
  633. h245ReceivePost,
  634. h245SendPost);
  635. #else // (USE_RECEIVE_QUEUE)
  636. h245ReceiveComplete,
  637. h245SendComplete);
  638. #endif // (USE_RECEIVE_QUEUE)
  639. if (FAILED(rc)) {
  640. H245TRACE(pInstance->dwInst, 1, "SR: Link Init Fail");
  641. return rc;
  642. }
  643. // Get the Link layer's instance handle
  644. pInstance->SendReceive.hLinkLayerInstance = pInstance->SendReceive.hLinkGetInstance(dwTmpPhysID);
  645. #if defined(USE_RECEIVE_QUEUE)
  646. // Allocate semaphore for task deletion procedures
  647. #ifdef _IA_SPOX_
  648. RIL_CreateSemaphore(0, &(pInstance->SendReceive.hReceiveSemphore));
  649. #else
  650. pInstance->SendReceive.hReceiveSemphore = SEM_create(0, NULL);
  651. #endif //_IA_SPOX_
  652. if (pInstance->SendReceive.hReceiveSemphore == NULL) {
  653. H245TRACE(pInstance->dwInst, 1, "SR: Semaphore creation failed");
  654. return SR_CREATE_SEM_FAIL;
  655. }
  656. // Allocate mailbox
  657. #ifdef _IA_SPOX_
  658. RIL_CreateMailbox(pInstance->dwInst,
  659. ID_H245,
  660. 16,
  661. OIL_LOCAL,
  662. &(pInstance->SendReceive.pMailbox));
  663. #else
  664. pInstance->SendReceive.pMailbox = MBX_create(sizeof(RXMSG), 16, NULL);
  665. #endif _IA_SPOX_
  666. if (pInstance->SendReceive.pMailbox == NULL) {
  667. H245TRACE(pInstance->dwInst, 1, "SR: Mailbox creation failed");
  668. return SR_CREATE_MBX_FAIL;
  669. }
  670. #if defined(_DEBUG) && defined(H324)
  671. // Turn logging on/off
  672. srInitializeLogging(pInstance, H245_TRACE_ENABLED);
  673. #endif // (_DEBUG)
  674. #ifdef _IA_SPOX_
  675. // Initialize the task and
  676. // Start the receive thread
  677. srTaskAttr.idwPriority = OIL_MINPRI;
  678. srTaskAttr.pStack = NULL;
  679. srTaskAttr.dwStackSize = 8192;
  680. srTaskAttr.pEnviron = NULL;
  681. srTaskAttr.szName = "H245ReceiveThread";
  682. srTaskAttr.bExitFlag = TRUE;
  683. RIL_CreateTask((PFxn)ReceiveThread,
  684. &srTaskAttr,
  685. srContext,
  686. &pInstance->SendReceive.pTaskReceive);
  687. #else
  688. // Initialize the task and
  689. // Start the receive thread
  690. srTaskAttr.priority = TSK_MINPRI;
  691. srTaskAttr.stack = NULL;
  692. srTaskAttr.stacksize = 8192;
  693. srTaskAttr.stackseg = 0;
  694. // srTaskAttr.environ = NULL;
  695. srTaskAttr.name = " ";
  696. srTaskAttr.exitflag = FALSE;
  697. // srTaskAttr.debug = TSK_DBG_NO;
  698. pInstance->SendReceive.pTaskReceive = TSK_create((Fxn)ReceiveThread,
  699. &srTaskAttr,
  700. srContext);
  701. #endif //_IA_SPOX_
  702. if (pInstance->SendReceive.pTaskReceive == NULL)
  703. {
  704. H245TRACE(pInstance->dwInst, 1, "SR: Thread Create FAIL"); H245PANIC();
  705. return SR_THREAD_CREATE_ERROR;
  706. }
  707. #endif // (USE_RECEIVE_QUEUE)
  708. // post buffers to link layer for receive
  709. for (i = 0; i < pInstance->SendReceive.dwNumRXBuffers; ++i) {
  710. pInstance->SendReceive.lpRxBuffer[i] = MemAlloc(pInstance->SendReceive.dwPDUSize);
  711. if (pInstance->SendReceive.lpRxBuffer[i] == NULL) {
  712. H245TRACE(pInstance->dwInst, 1, "SR: SndRecvInit - No Memory");
  713. return H245_ERROR_NOMEM;
  714. }
  715. rc = pInstance->SendReceive.hLinkReceiveReq(pInstance->SendReceive.hLinkLayerInstance,
  716. (PBYTE)pInstance->SendReceive.lpRxBuffer[i],
  717. pInstance->SendReceive.dwPDUSize);
  718. if (rc != 0) {
  719. H245TRACE(pInstance->dwInst, 1, "SR: SndRecvInit - Receive Buffer Post returned %d", rc);
  720. return rc;
  721. }
  722. }
  723. H245TRACE(pInstance->dwInst, 3, "SR: INIT Complete");
  724. return H245_ERROR_OK;
  725. } // sendRcvInit()
  726. HRESULT
  727. sendRcvFlushPDUs
  728. (
  729. struct InstanceStruct *pInstance,
  730. DWORD dwDirection,
  731. BOOL bShutdown
  732. )
  733. {
  734. pInstance->SendReceive.dwFlushMap = dwDirection;
  735. if (bShutdown) {
  736. pInstance->SendReceive.dwFlushMap |= SHUTDOWN_PENDING;
  737. }
  738. // Flush the requested queue(s)
  739. return(pInstance->SendReceive.hLinkLayerFlushChannel(pInstance->SendReceive.hLinkLayerInstance,
  740. dwDirection));
  741. }