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.

928 lines
27 KiB

  1. #include "precomp.h"
  2. DEBUG_FILEZONE(ZONE_T120_T123PSTN);
  3. /* Mplex.cpp
  4. *
  5. * Copyright (c) 1994-1995 by DataBeam Corporation, Lexington, KY
  6. *
  7. * Abstract:
  8. * This is the implementation file for the Q922 multiplexer class. This
  9. * class multiplexes higher layers to a single lower layer.
  10. *
  11. * Private Instance Variables:
  12. * Q922_Layers - List of the higher layers we are multiplexing
  13. * Owner_Object - Address of our owner object.
  14. * m_pComPort - Address of our lower layer
  15. * m_hCommLink- The identifier we pass to the lower layer. This
  16. * is how the lower layer identifies us
  17. * m_nMsgBase - Message base we use for owner callbacks. The
  18. * owner identifies us by the message base
  19. * Maximum_Packet_Size Maximum packet size we can send to lower layer
  20. * Packet_Size - Maximum packet size the higher layer can send
  21. * to us
  22. * Data_Request_Buffer Buffer we use for data coming from higher layer
  23. * Data_Request_Memory_Object Memory object used for data transmission
  24. * Data_Request_Length Length of packet from higher layer
  25. * Data_Request_Offset Current offset into packet. Maintains current
  26. * position as we send to lower layer.
  27. * Data_Indication_Buffer Buffer we use for data coming from lower layer
  28. * Data_Indication_Length Length of packet
  29. * Data_Indication_Ready Flag indicating that packet is ready to send up
  30. *
  31. * Framer - Address of packet framer object
  32. * CRC - Address of crc generator and checker
  33. *
  34. * Decode_In_Progress Flag telling us if we are in the middle of a
  35. * packet
  36. * CRC_Size - Number of bytes in the CRC
  37. * Disconnect - TRUE if a disconnect is pending
  38. *
  39. * Caveats:
  40. * None.
  41. *
  42. * Authors:
  43. * James W. Lawwill
  44. */
  45. #include "mplex.h"
  46. /*
  47. * Multiplexer::Multiplexer (
  48. * IObject * owner_object,
  49. * IProtocolLayer * lower_layer,
  50. * USHORT identifier,
  51. * USHORT message_base,
  52. * PPacketFrame framer,
  53. * PCRC crc,
  54. * BOOL * initialized)
  55. *
  56. * Public
  57. *
  58. * Functional Description:
  59. * This function initializes the Q922 multiplexer.
  60. */
  61. Multiplexer::Multiplexer
  62. (
  63. T123 *owner_object,
  64. ComPort *comport, // lower layer
  65. PhysicalHandle physical_handle,
  66. USHORT message_base,
  67. PPacketFrame framer,
  68. PCRC crc,
  69. BOOL *initialized
  70. )
  71. :
  72. Q922_Layers(TRANSPORT_HASHING_BUCKETS)
  73. {
  74. TRACE_OUT(("Multiplexer::Multiplexer"));
  75. USHORT overhead;
  76. ProtocolLayerError error;
  77. USHORT lower_layer_prepend;
  78. USHORT lower_layer_append;
  79. *initialized = TRUE;
  80. m_pT123 = owner_object;
  81. m_pComPort = comport;
  82. m_hCommLink = physical_handle;
  83. m_nMsgBase = message_base;
  84. Framer = framer;
  85. CRC = crc;
  86. CRC_Size = 0;
  87. m_pComPort->GetParameters(
  88. &Maximum_Packet_Size,
  89. &lower_layer_prepend,
  90. &lower_layer_append);
  91. if (Maximum_Packet_Size == 0xffff)
  92. {
  93. /*
  94. ** The lower layer is a stream device, base the higher maximum packet
  95. ** size on the Multiplexer max. packet size
  96. */
  97. Packet_Size = MULTIPLEXER_MAXIMUM_PACKET_SIZE;
  98. Maximum_Packet_Size = Packet_Size;
  99. if (CRC != NULL)
  100. {
  101. CRC -> GetOverhead (0, &CRC_Size);
  102. Maximum_Packet_Size += CRC_Size;
  103. }
  104. if (Framer != NULL)
  105. Framer -> GetOverhead (Maximum_Packet_Size, &Maximum_Packet_Size);
  106. }
  107. else
  108. {
  109. /*
  110. ** The lower layer is a packet device, determine the max. packet
  111. ** size of the higher layer.
  112. */
  113. overhead = 0;
  114. if (Framer != NULL)
  115. Framer -> GetOverhead (overhead, &overhead);
  116. if (CRC != NULL)
  117. {
  118. CRC -> GetOverhead (0, &CRC_Size);
  119. overhead += CRC_Size;
  120. }
  121. Packet_Size = Maximum_Packet_Size - overhead;
  122. }
  123. TRACE_OUT(("MPlex: max_packet = %d", Maximum_Packet_Size));
  124. /*
  125. ** Now we have to allocate a buffer for data going to the lower layer
  126. */
  127. if (Framer != NULL)
  128. {
  129. Data_Request_Buffer = (LPBYTE) LocalAlloc (LMEM_FIXED, Maximum_Packet_Size);
  130. Data_Indication_Buffer = (LPBYTE) LocalAlloc (LMEM_FIXED, Maximum_Packet_Size);
  131. if ((Data_Request_Buffer == NULL) ||
  132. (Data_Indication_Buffer == NULL))
  133. {
  134. *initialized = FALSE;
  135. }
  136. }
  137. Data_Request_Length = 0;
  138. Data_Request_Offset = 0;
  139. Data_Request_Memory_Object = NULL;
  140. Data_Indication_Length = 0;
  141. Data_Indication_Ready = FALSE;
  142. Decode_In_Progress = FALSE;
  143. Disconnect = FALSE;
  144. /*
  145. ** Register with the lower layer
  146. */
  147. error = m_pComPort->RegisterHigherLayer(
  148. (ULONG_PTR) m_hCommLink,
  149. NULL,
  150. (IProtocolLayer *) this);
  151. if (error != PROTOCOL_LAYER_NO_ERROR)
  152. {
  153. TRACE_OUT(("Multiplexer: constructor: Error registering with lower layer"));
  154. }
  155. }
  156. /*
  157. * Multiplexer::~Multiplexer (void);
  158. *
  159. * Public
  160. *
  161. * Functional Description:
  162. * Destructor
  163. */
  164. Multiplexer::~Multiplexer (void)
  165. {
  166. TRACE_OUT(("Multiplexer::~Multiplexer"));
  167. PMPlexStruct lpmpStruct;
  168. /*
  169. ** Remove our reference from the lower layer
  170. */
  171. m_pComPort->RemoveHigherLayer((ULONG_PTR) m_hCommLink);
  172. if (Framer != NULL)
  173. {
  174. if (Data_Request_Buffer != NULL)
  175. LocalFree ((HLOCAL) Data_Request_Buffer);
  176. if (Data_Indication_Buffer != NULL)
  177. LocalFree ((HLOCAL) Data_Indication_Buffer);
  178. }
  179. else
  180. {
  181. if (Data_Request_Memory_Object != NULL)
  182. {
  183. if (Q922_Layers.find ((DWORD_PTR) Data_Request_DLCI, (PDWORD_PTR) &lpmpStruct))
  184. lpmpStruct->data_request_memory_manager->UnlockMemory (Data_Request_Memory_Object);
  185. }
  186. }
  187. Q922_Layers.reset();
  188. while (Q922_Layers.iterate((PDWORD_PTR) &lpmpStruct))
  189. delete lpmpStruct;
  190. /*
  191. ** Delete the Framer that was instantiated by the controller.
  192. */
  193. if (Framer != NULL)
  194. delete Framer;
  195. if (CRC != NULL)
  196. delete CRC;
  197. }
  198. /*
  199. * MultiplexerError Multiplexer::ConnectRequest (void)
  200. *
  201. * Public
  202. *
  203. * Functional Description:
  204. * This function simply notifies the higher layer that it is ready
  205. * for operation
  206. */
  207. MultiplexerError Multiplexer::ConnectRequest (void)
  208. {
  209. TRACE_OUT(("Multiplexer::ConnectRequest"));
  210. m_pT123->OwnerCallback(m_nMsgBase + NEW_CONNECTION);
  211. return (MULTIPLEXER_NO_ERROR);
  212. }
  213. /*
  214. * MultiplexerError Multiplexer::DisconnectRequest (void)
  215. *
  216. * Public
  217. *
  218. * Functional Description:
  219. * This function removes itself from the lower layer and notifies the
  220. * owner.
  221. */
  222. MultiplexerError Multiplexer::DisconnectRequest (void)
  223. {
  224. TRACE_OUT(("Multiplexer::DisconnectRequest"));
  225. if (Data_Request_Length == 0)
  226. {
  227. m_pT123->OwnerCallback(m_nMsgBase + BROKEN_CONNECTION);
  228. }
  229. Disconnect = TRUE;
  230. return (MULTIPLEXER_NO_ERROR);
  231. }
  232. /*
  233. * ProtocolLayerError Multiplexer::PollReceiver (
  234. * ULONG)
  235. *
  236. * Public
  237. *
  238. * Functional Description:
  239. * If this function has a packet ready to send to a higher layer, it
  240. * attempts to send it.
  241. */
  242. ProtocolLayerError Multiplexer::PollReceiver(void)
  243. {
  244. // TRACE_OUT(("Multiplexer::PollReceiver"));
  245. if (Data_Indication_Ready)
  246. {
  247. SendDataToHigherLayer (
  248. Data_Indication_Buffer,
  249. Data_Indication_Length);
  250. Data_Indication_Ready = FALSE;
  251. }
  252. return (PROTOCOL_LAYER_NO_ERROR);
  253. }
  254. /*
  255. * ProtocolLayerError Multiplexer::PollTransmitter (
  256. * ULONG)
  257. *
  258. * Public
  259. *
  260. * Functional Description:
  261. * If we have data to send to the lower layer, we attempt to send it.
  262. */
  263. ProtocolLayerError Multiplexer::PollTransmitter (
  264. ULONG_PTR,
  265. USHORT,
  266. USHORT *,
  267. USHORT *)
  268. {
  269. // TRACE_OUT(("Multiplexer::PollTransmitter"));
  270. ULONG bytes_accepted;
  271. HPUChar packet_address;
  272. ProtocolLayerError return_value = PROTOCOL_LAYER_NO_ERROR;
  273. if (Data_Request_Length != 0)
  274. {
  275. if (Framer != NULL)
  276. {
  277. m_pComPort->DataRequest(
  278. (ULONG_PTR) m_hCommLink,
  279. Data_Request_Buffer + Data_Request_Offset,
  280. Data_Request_Length - Data_Request_Offset,
  281. &bytes_accepted);
  282. }
  283. else
  284. {
  285. packet_address = (HPUChar) Data_Request_Memory_Object->GetPointer ();
  286. m_pComPort->DataRequest(
  287. (ULONG_PTR) m_hCommLink,
  288. ((LPBYTE) packet_address) + Data_Request_Offset,
  289. Data_Request_Length - Data_Request_Offset,
  290. &bytes_accepted);
  291. }
  292. /*
  293. ** If the lower layer has accepted all of the packet, reset
  294. ** our length and offset variables
  295. */
  296. if (bytes_accepted <=
  297. (ULONG) (Data_Request_Length - Data_Request_Offset))
  298. {
  299. Data_Request_Offset += (USHORT) bytes_accepted;
  300. if (Data_Request_Offset == Data_Request_Length)
  301. {
  302. Data_Request_Offset = 0;
  303. Data_Request_Length = 0;
  304. if (Framer == NULL)
  305. {
  306. PMPlexStruct lpmpStruct;
  307. /*
  308. ** Unlock the memory object so that it can be released
  309. */
  310. if (Q922_Layers.find ((DWORD_PTR) Data_Request_DLCI, (PDWORD_PTR) &lpmpStruct))
  311. lpmpStruct->data_request_memory_manager->UnlockMemory (Data_Request_Memory_Object);
  312. Data_Request_Memory_Object = NULL;
  313. }
  314. /*
  315. ** If the Disconnect is pending, issue the callback
  316. */
  317. if (Disconnect)
  318. {
  319. Disconnect = FALSE;
  320. m_pT123->OwnerCallback(m_nMsgBase + BROKEN_CONNECTION);
  321. }
  322. }
  323. }
  324. }
  325. return (return_value);
  326. }
  327. /*
  328. * ProtocolLayerError Multiplexer::RegisterHigherLayer (
  329. * ULONG identifier,
  330. * PMemoryManager memory_manager,
  331. * IProtocolLayer * q922);
  332. *
  333. * Public
  334. *
  335. * Functional Description:
  336. * This function is called to register an identifier with a higher
  337. * layer address.
  338. */
  339. ProtocolLayerError Multiplexer::RegisterHigherLayer (
  340. ULONG_PTR identifier,
  341. PMemoryManager memory_manager,
  342. IProtocolLayer * q922)
  343. {
  344. TRACE_OUT(("Multiplexer::RegisterHigherLayer"));
  345. DLCI dlci;
  346. PMPlexStruct lpmpStruct;
  347. dlci = (DLCI) identifier;
  348. if (Q922_Layers.find ((DWORD) dlci))
  349. return (PROTOCOL_LAYER_REGISTRATION_ERROR);
  350. lpmpStruct = new MPlexStruct;
  351. if (lpmpStruct != NULL)
  352. {
  353. Q922_Layers.insert ((DWORD_PTR) dlci, (DWORD_PTR) lpmpStruct);
  354. lpmpStruct -> q922 = q922;
  355. lpmpStruct -> data_request_memory_manager = memory_manager;
  356. }
  357. else
  358. {
  359. return (PROTOCOL_LAYER_ERROR);
  360. }
  361. return (PROTOCOL_LAYER_NO_ERROR);
  362. }
  363. /*
  364. * ProtocolLayerError Multiplexer::RemoveHigherLayer (
  365. * ULONG identifier);
  366. *
  367. * Public
  368. *
  369. * Functional Description:
  370. * This function removes the higher layer from our list
  371. */
  372. ProtocolLayerError Multiplexer::RemoveHigherLayer (
  373. ULONG_PTR identifier)
  374. {
  375. TRACE_OUT(("Multiplexer::RemoveHigherLayer"));
  376. DLCI dlci;
  377. PMPlexStruct lpmpStruct;
  378. dlci = (DLCI) identifier;
  379. if (Q922_Layers.find ((DWORD_PTR) dlci, (PDWORD_PTR) &lpmpStruct) == FALSE)
  380. return (PROTOCOL_LAYER_REGISTRATION_ERROR);
  381. if (Data_Request_Memory_Object != NULL)
  382. {
  383. if (Data_Request_DLCI == dlci)
  384. {
  385. /*
  386. ** Unlock the memory object so that it can be released
  387. */
  388. lpmpStruct->data_request_memory_manager->UnlockMemory (Data_Request_Memory_Object);
  389. Data_Request_Offset = 0;
  390. Data_Request_Length = 0;
  391. Data_Request_Memory_Object = NULL;
  392. }
  393. }
  394. delete lpmpStruct;
  395. Q922_Layers.remove ((DWORD) dlci);
  396. return (PROTOCOL_LAYER_NO_ERROR);
  397. }
  398. /*
  399. * ProtocolLayerError Multiplexer::GetParameters (
  400. * ULONG,
  401. * USHORT * max_packet_size,
  402. * USHORT * prepend_bytes,
  403. * USHORT * append_bytes)
  404. *
  405. * Public
  406. *
  407. * Functional Description:
  408. * This function returns the maximum packet size permitted by
  409. * the higher layer.
  410. */
  411. ProtocolLayerError Multiplexer::GetParameters (
  412. USHORT * max_packet_size,
  413. USHORT * prepend_bytes,
  414. USHORT * append_bytes)
  415. {
  416. TRACE_OUT(("Multiplexer::GetParameters"));
  417. *max_packet_size = Packet_Size;
  418. *prepend_bytes = 0;
  419. *append_bytes = CRC_Size;
  420. return (PROTOCOL_LAYER_NO_ERROR);
  421. }
  422. /*
  423. * MultiplexerError Multiplexer::DataRequest (
  424. * ULONG identifier,
  425. * PMemory memory,
  426. * PULong bytes_accepted)
  427. *
  428. * Public
  429. *
  430. * Functional Description:
  431. * This function takes the packet passed in, runs it thru the framer and
  432. * CRC, and passes it to the lower layer.
  433. */
  434. ProtocolLayerError Multiplexer::DataRequest (
  435. ULONG_PTR identifier,
  436. PMemory memory,
  437. PULong bytes_accepted)
  438. {
  439. TRACE_OUT(("Multiplexer::DataRequest"));
  440. USHORT crc;
  441. USHORT pending_data;
  442. HPUChar packet_address;
  443. ULONG length;
  444. USHORT holding_data;
  445. USHORT i;
  446. DLCI dlci;
  447. PMPlexStruct lpmpStruct;
  448. dlci = (DLCI) identifier;
  449. /*
  450. ** Set bytes_accepted to 0
  451. */
  452. *bytes_accepted = 0;
  453. if (Data_Request_Length != 0)
  454. return (PROTOCOL_LAYER_NO_ERROR);
  455. /*
  456. ** Get the address of the memory block
  457. */
  458. packet_address = (HPUChar) memory -> GetPointer ();
  459. length = memory -> GetLength ();
  460. /*
  461. ** Remove the CRC length from the total size of the packet.
  462. */
  463. length -= CRC_Size;
  464. if (length > Packet_Size)
  465. {
  466. TRACE_OUT(("MPLEX: DataRequest: Packet too big"));
  467. return (PROTOCOL_LAYER_PACKET_TOO_BIG);
  468. }
  469. /*
  470. ** Lock the memory object so that it won't be released
  471. */
  472. if (Q922_Layers.find ((DWORD_PTR) dlci, (PDWORD_PTR) &lpmpStruct))
  473. lpmpStruct->data_request_memory_manager->LockMemory (memory);
  474. if (CRC != NULL)
  475. {
  476. /*
  477. ** Generate the CRC and put it at the end of the packet.
  478. */
  479. crc = (USHORT) CRC -> CRCGenerator (
  480. (LPBYTE) packet_address, length);
  481. for (i=0; i<CRC_Size; i++)
  482. *(packet_address + length + i) = (crc >> (i * 8)) & 0xff;
  483. }
  484. /*
  485. ** Add the CRC size to the packet length.
  486. */
  487. length += CRC_Size;
  488. if (Framer != NULL)
  489. {
  490. /*
  491. ** Use the framer to encode the packet
  492. */
  493. Framer -> PacketEncode (
  494. (LPBYTE) packet_address,
  495. (USHORT) length,
  496. Data_Request_Buffer,
  497. Maximum_Packet_Size,
  498. TRUE,
  499. TRUE,
  500. &Data_Request_Length);
  501. /*
  502. ** If we are using a framer, we can release the memory object
  503. ** right now.
  504. */
  505. lpmpStruct->data_request_memory_manager->UnlockMemory (memory);
  506. *bytes_accepted = length;
  507. }
  508. else
  509. {
  510. /*
  511. ** Save the memory object and the identifier
  512. */
  513. Data_Request_DLCI = (DLCI) dlci;
  514. Data_Request_Memory_Object = memory;
  515. Data_Request_Length = (USHORT) length;
  516. *bytes_accepted = length;
  517. }
  518. /*
  519. ** Attempt to send the packet to the lower layer
  520. */
  521. PollTransmitter (
  522. 0,
  523. PROTOCOL_CONTROL_DATA | PROTOCOL_USER_DATA,
  524. &pending_data,
  525. &holding_data);
  526. return (PROTOCOL_LAYER_NO_ERROR);
  527. }
  528. /*
  529. * MultiplexerError Multiplexer::DataRequest (
  530. * ULONG,
  531. * LPBYTE
  532. * ULONG
  533. * PULong bytes_accepted)
  534. *
  535. * Public
  536. *
  537. * Functional Description:
  538. * This function takes the packet passed in, runs it thru the framer and
  539. * CRC, and passes it to the lower layer.
  540. */
  541. ProtocolLayerError Multiplexer::DataRequest (
  542. ULONG_PTR,
  543. LPBYTE,
  544. ULONG,
  545. PULong bytes_accepted)
  546. {
  547. *bytes_accepted = 0;
  548. return (PROTOCOL_LAYER_ERROR);
  549. }
  550. /*
  551. * ProtocolLayerError Multiplexer::DataIndication (
  552. * LPBYTE buffer_address,
  553. * ULONG length,
  554. * PULong bytes_accepted)
  555. *
  556. * Public
  557. *
  558. * Functional Description:
  559. * This function is called by the lower layer when it has data
  560. * ready for us.
  561. */
  562. ProtocolLayerError Multiplexer::DataIndication (
  563. LPBYTE buffer_address,
  564. ULONG length,
  565. PULong bytes_accepted)
  566. {
  567. // TRACE_OUT(("Multiplexer::DataIndication"));
  568. BOOL process_packet = TRUE;
  569. USHORT packet_size;
  570. LPBYTE source_address;
  571. USHORT source_length;
  572. LPBYTE dest_address;
  573. USHORT dest_length;
  574. PacketFrameError return_value;
  575. BOOL crc_valid;
  576. USHORT bytes_processed;
  577. *bytes_accepted = 0;
  578. if (Framer == NULL)
  579. {
  580. *bytes_accepted = length;
  581. /*
  582. ** If the framer does NOT exist, the data is coming to us in packet
  583. ** format
  584. */
  585. if (CRC != NULL)
  586. {
  587. crc_valid = CRC -> CheckCRC (buffer_address, length);
  588. if (crc_valid == FALSE)
  589. {
  590. TRACE_OUT(("MPLEX: Invalid CRC"));
  591. return (PROTOCOL_LAYER_NO_ERROR);
  592. }
  593. length -= CRC_Size;
  594. }
  595. SendDataToHigherLayer (buffer_address, (USHORT) length);
  596. }
  597. else
  598. {
  599. /*
  600. ** A framer exists; the lower layer is giving us the data
  601. ** in a stream fashion
  602. */
  603. Data_Indication_Ready = FALSE;
  604. source_address = buffer_address;
  605. source_length = (USHORT) length;
  606. while (process_packet)
  607. {
  608. if (Decode_In_Progress)
  609. {
  610. dest_length = 0;
  611. dest_address = NULL;
  612. }
  613. else
  614. {
  615. dest_address = Data_Indication_Buffer;
  616. dest_length = Maximum_Packet_Size;
  617. }
  618. /*
  619. ** Pass the data to the framer to decode it.
  620. */
  621. return_value = Framer -> PacketDecode (
  622. source_address,
  623. source_length,
  624. dest_address,
  625. dest_length,
  626. &bytes_processed,
  627. &packet_size,
  628. Decode_In_Progress);
  629. source_address = NULL;
  630. switch (return_value)
  631. {
  632. case PACKET_FRAME_NO_ERROR:
  633. /*
  634. ** A complete packet was not found by the decoder
  635. */
  636. Decode_In_Progress = TRUE;
  637. Data_Indication_Ready = FALSE;
  638. process_packet = FALSE;
  639. *bytes_accepted += bytes_processed;
  640. break;
  641. case PACKET_FRAME_PACKET_DECODED:
  642. /*
  643. ** Complete packet found, check the CRC, and pass it to
  644. ** the higher layer.
  645. */
  646. Decode_In_Progress = FALSE;
  647. *bytes_accepted += bytes_processed;
  648. if (CRC != NULL)
  649. {
  650. if (packet_size <= CRC_Size)
  651. break;
  652. crc_valid = CRC -> CheckCRC (
  653. Data_Indication_Buffer,
  654. packet_size);
  655. if (crc_valid == FALSE)
  656. {
  657. TRACE_OUT(("MPLEX: Invalid CRC: packet_size = %d", packet_size));
  658. break;
  659. }
  660. packet_size -= CRC_Size;
  661. }
  662. Data_Indication_Ready = TRUE;
  663. Data_Indication_Length = packet_size;
  664. /*
  665. ** Send packet on up
  666. */
  667. PollReceiver();
  668. break;
  669. case PACKET_FRAME_DEST_BUFFER_TOO_SMALL:
  670. /*
  671. ** The packet received is too big for our buffer.
  672. ** This sometimes occurs if a trailing flag is lost
  673. ** during transmission
  674. */
  675. TRACE_OUT(("PACKET_FRAME_DEST_BUFFER_TOO_SMALL"));
  676. Decode_In_Progress = FALSE;
  677. *bytes_accepted += bytes_processed;
  678. break;
  679. case PACKET_FRAME_ILLEGAL_FLAG_FOUND:
  680. /*
  681. ** The packet received contained an illegal flag.
  682. */
  683. Decode_In_Progress = FALSE;
  684. *bytes_accepted += bytes_processed;
  685. break;
  686. case PACKET_FRAME_FATAL_ERROR:
  687. /*
  688. ** Incoming packets do not meet framer requirements.
  689. ** Tell the owner object to break the link
  690. */
  691. m_pT123->OwnerCallback(m_nMsgBase + BROKEN_CONNECTION);
  692. process_packet = FALSE;
  693. break;
  694. }
  695. }
  696. }
  697. return (PROTOCOL_LAYER_NO_ERROR);
  698. }
  699. /*
  700. * void Multiplexer::SendDataToHigherLayer (
  701. * LPBYTE buffer_address,
  702. * USHORT length)
  703. *
  704. * Functional Description
  705. * This function is called to send a packet to the higher layer
  706. *
  707. * Formal Parameters
  708. * buffer_address (i) - Buffer address
  709. * length (i) - Number of bytes in packet
  710. *
  711. * Return Value
  712. * TRUE - The packet was sent to the higher layer
  713. * FALSE - The packet was NOT sent to the higher layer
  714. *
  715. * Side Effects
  716. * None
  717. *
  718. * Caveats
  719. * None
  720. */
  721. void Multiplexer::SendDataToHigherLayer (
  722. LPBYTE buffer_address,
  723. USHORT buffer_length)
  724. {
  725. TRACE_OUT(("Multiplexer::SendDataToHigherLayer"));
  726. DLCI dlci;
  727. ProtocolLayerError error;
  728. IProtocolLayer * q922;
  729. ULONG bytes_accepted;
  730. PMPlexStruct lpmpStruct;
  731. /*
  732. ** Find out who the packet is intended for
  733. */
  734. dlci = GetDLCI (buffer_address, buffer_length);
  735. if (Q922_Layers.find((DWORD_PTR) dlci, (PDWORD_PTR) &lpmpStruct))
  736. {
  737. q922 = lpmpStruct->q922;
  738. error = q922 -> DataIndication (
  739. buffer_address,
  740. buffer_length,
  741. &bytes_accepted);
  742. if (error != PROTOCOL_LAYER_NO_ERROR)
  743. {
  744. ERROR_OUT(("Multiplexer: SendDataToHigherLayer: Error occured on data indication to %d", dlci));
  745. }
  746. else
  747. {
  748. if (bytes_accepted != 0)
  749. {
  750. if (bytes_accepted != buffer_length)
  751. {
  752. ERROR_OUT((" Multiplexer: SendDataToHigherLayer: Error: "
  753. "The upper layer thinks he can accept partial packets!!!"));
  754. }
  755. }
  756. }
  757. }
  758. else
  759. {
  760. /*
  761. ** Packet can NOT be sent up, trash it.
  762. */
  763. WARNING_OUT(("MPLEX: PollReceiver: packet received with illegal DLCI = %d", dlci));
  764. }
  765. return;
  766. }
  767. /*
  768. * DLCI Multiplexer::GetDLCI (
  769. * LPBYTE buffer_address,
  770. * USHORT length)
  771. *
  772. * Functional Description
  773. * This function returns the dlci of the packet.
  774. *
  775. * Formal Parameters
  776. * buffer_address (i) - Buffer address
  777. * length (i) - Number of bytes in packet
  778. *
  779. * Return Value
  780. * dlci
  781. *
  782. * Side Effects
  783. * None
  784. *
  785. * Caveats
  786. * None
  787. */
  788. DLCI Multiplexer::GetDLCI (
  789. LPBYTE buffer_address,
  790. USHORT buffer_size)
  791. {
  792. DLCI dlci;
  793. if (buffer_size < 2)
  794. return (ILLEGAL_DLCI);
  795. dlci = *(buffer_address + ADDRESS_BYTE_HIGH) & 0xfc;
  796. dlci <<= 2;
  797. dlci |= ((*(buffer_address + ADDRESS_BYTE_LOW) & 0xf0) >> 4);
  798. return (dlci);
  799. }
  800.