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.

684 lines
23 KiB

  1. /* Q922.h
  2. *
  3. * Copyright (c) 1993-1995 by DataBeam Corporation, Lexington, KY
  4. *
  5. * Abstract:
  6. * This is the interface file for the Q.922 data link protocol.
  7. * This class handles all error correction over the link. It also insures
  8. * that all packets are sequenced properly. Its lower layer receives
  9. * packets in raw Q922 format. It is responsible for framing and error
  10. * detecting the packets. Q922 passes packets to its higher layer that
  11. * have been sequenced properly.
  12. *
  13. * Q.922 is a full duplex protocol .
  14. *
  15. * This class assumes that the layers above and below it have packet input
  16. * and output interfaces.
  17. *
  18. * Read the Q.922 specification before diving into the code.
  19. *
  20. * Caveats:
  21. * None.
  22. *
  23. * Authors:
  24. * James P. Galvin
  25. * James W. Lawwill
  26. */
  27. #ifndef _Q922_H_
  28. #define _Q922_H_
  29. /*
  30. ** Possible error conditions from this layer
  31. */
  32. typedef enum
  33. {
  34. DATALINK_NO_ERROR,
  35. DATALINK_READ_QUEUE_EMPTY,
  36. DATALINK_WRITE_QUEUE_FULL,
  37. DATALINK_RECEIVE_SEQUENCE_VIOLATION
  38. }
  39. DataLinkError, * PDataLinkError;
  40. /*
  41. ** The data link layer can be in the following modes
  42. */
  43. typedef enum
  44. {
  45. TEI_ASSIGNED,
  46. AWAITING_ESTABLISHMENT,
  47. MULTIPLE_FRAME_ESTABLISHED,
  48. AWAITING_RELEASE,
  49. TIMER_RECOVERY
  50. }
  51. DataLinkMode, * PDataLinkMode;
  52. /*
  53. ** Q922 Disconnect Types
  54. */
  55. typedef enum
  56. {
  57. DATALINK_NORMAL_DISCONNECT,
  58. DATALINK_ILLEGAL_PACKET_RECEIVED,
  59. DATALINK_RECEIVE_SEQUENCE_EXCEPTION,
  60. DATALINK_REMOTE_SITE_TIMED_OUT
  61. }
  62. DataLinkDisconnectType, * PDataLinkDisconnectType;
  63. /*
  64. ** Q922 Status messages
  65. */
  66. typedef enum
  67. {
  68. DATALINK_TIMING_ERROR
  69. }
  70. DataLinkStatusMessage, * PDataLinkStatusMessage;
  71. /*
  72. ** Default packet size
  73. */
  74. #define DATALINK_OUTPUT_MAXIMUM_PACKET_SIZE 1024
  75. /*
  76. ** Transmit and receive packets are managed via the DataQueue structure
  77. */
  78. typedef struct
  79. {
  80. LPBYTE buffer_address;
  81. USHORT length;
  82. }
  83. DataQueue, * PDataQueue;
  84. /*
  85. ** In this implementation of Q922, the DLCI is 10 bits.
  86. ** For this reason, we will make it a USHORT
  87. */
  88. typedef USHORT DLCI;
  89. /*
  90. ** Q922 definitions
  91. */
  92. #define COMMAND_BIT 0x02
  93. #define POLL_FINAL_BIT 0x01
  94. #define RESPONSE_FRAME COMMAND_BIT
  95. #define COMMAND_FRAME 0x00
  96. #define PF_RESET 0x00
  97. #define PF_SET POLL_FINAL_BIT
  98. #define UNNUMBERED_PF_RESET 0x00
  99. #define UNNUMBERED_PF_SET 0x10
  100. #define ADDRESS_BYTE_HIGH 0
  101. #define ADDRESS_BYTE_LOW 1
  102. #define CONTROL_BYTE_HIGH 2
  103. #define CONTROL_BYTE_LOW 3
  104. #define ADDRESS_MSB 0x00
  105. #define ADDRESS_LSB 0x01
  106. #define CONTROL_MSB 0x01
  107. #define ADDRESS_HIGH(X) ((X >> 2) & 0xfc)
  108. #define ADDRESS_LOW(X) ((X & 0x0f) << 4)
  109. #define UNNUMBERED_HEADER_SIZE 3
  110. #define SUPERVISORY_FRAME_BIT 0x01
  111. #define SUPERVISORY_COMMAND_MASK 0x0c
  112. #define RECEIVER_READY 0x00
  113. #define RECEIVER_NOT_READY 0x04
  114. #define REJECT 0x08
  115. #define UNNUMBERED_FRAME_BIT 0x02
  116. #define UNNUMBERED_COMMAND_MASK 0xec
  117. #define SABME 0x6c
  118. #define UNNUMBERED_ACKNOWLEDGE 0x60
  119. #define FRAME_REJECT 0x84
  120. #define DISCONNECTED_MODE 0x0c
  121. #define DISC 0x40
  122. #define SEQUENCE_MODULUS 128
  123. #define RECEIVE_SEQUENCE_VIOLATION 1
  124. /*
  125. ** DATALINK_MAXIMUM_PACKET_SIZE = User data + overhead
  126. */
  127. #define DATALINK_MAXIMUM_PACKET_SIZE 1024
  128. /*
  129. ** The maximum Q922 packet overhead is 4 bytes
  130. */
  131. #define DATALINK_PACKET_OVERHEAD 4
  132. /*
  133. ** Default timeouts
  134. */
  135. #define DEFAULT_T203_COMM_TIMEOUT 600
  136. #define DEFAULT_T203_TIMEOUT 30000
  137. #define DEFAULT_MAXIMUM_T200_TIMEOUTS 5
  138. class CLayerQ922 : public IProtocolLayer
  139. {
  140. public:
  141. CLayerQ922(
  142. T123 *owner_object,
  143. Multiplexer *lower_layer,
  144. USHORT message_base,
  145. USHORT identifier,
  146. BOOL link_originator,
  147. USHORT data_indication_queue_size,
  148. USHORT data_request_queue_size,
  149. USHORT k_factor,
  150. USHORT max_packet_size,
  151. USHORT t200,
  152. USHORT max_outstanding_bytes,
  153. PMemoryManager memory_manager,
  154. PLUGXPRT_PSTN_CALL_CONTROL,
  155. PLUGXPRT_PARAMETERS *,
  156. BOOL * initialized);
  157. virtual ~CLayerQ922(void);
  158. DataLinkError ReleaseRequest (void);
  159. /*
  160. ** Functions overridden from the ProtocolLayer object
  161. */
  162. ProtocolLayerError DataRequest (
  163. ULONG_PTR identifier,
  164. LPBYTE buffer_address,
  165. ULONG length,
  166. PULong bytes_accepted);
  167. ProtocolLayerError DataRequest (
  168. ULONG_PTR identifier,
  169. PMemory memory,
  170. PULong bytes_accepted);
  171. ProtocolLayerError DataIndication (
  172. LPBYTE buffer_address,
  173. ULONG length,
  174. PULong bytes_accepted);
  175. ProtocolLayerError RegisterHigherLayer (
  176. ULONG_PTR identifier,
  177. PMemoryManager dr_memory_manager,
  178. IProtocolLayer * higher_layer);
  179. ProtocolLayerError RemoveHigherLayer (
  180. ULONG_PTR identifier);
  181. ProtocolLayerError PollTransmitter (
  182. ULONG_PTR identifier,
  183. USHORT data_to_transmit,
  184. USHORT * pending_data,
  185. USHORT * holding_data);
  186. ProtocolLayerError PollReceiver(void);
  187. ProtocolLayerError GetParameters (
  188. USHORT * max_packet_size,
  189. USHORT * prepend_size,
  190. USHORT * append_size);
  191. private:
  192. void ProcessReadQueue (void);
  193. void ProcessWriteQueue (
  194. USHORT data_to_transmit);
  195. BOOL TransmitSupervisoryFrame (
  196. UChar frame_type,
  197. UChar poll_final_bit);
  198. BOOL TransmitInformationFrame (void);
  199. BOOL TransmitUnnumberedFrame (void);
  200. void ProcessReceiverReady (
  201. LPBYTE packet_address,
  202. USHORT packet_length);
  203. void ProcessReceiverNotReady (
  204. LPBYTE packet_address,
  205. USHORT packet_length);
  206. void ProcessReject (
  207. LPBYTE packet_address,
  208. USHORT packet_length);
  209. BOOL ProcessInformationFrame (
  210. LPBYTE packet_address,
  211. USHORT packet_length);
  212. DataLinkError ParsePacketHeader (
  213. LPBYTE packet_address,
  214. USHORT packet_length,
  215. BOOL * command_frame,
  216. LPBYTE receive_sequence_number,
  217. BOOL * poll_final_bit);
  218. void ProcessSABME (
  219. LPBYTE packet_address,
  220. USHORT packet_length);
  221. void ProcessFrameReject (
  222. LPBYTE packet_address,
  223. USHORT packet_length);
  224. void ProcessUnnumberedAcknowledge (
  225. LPBYTE packet_address,
  226. USHORT packet_length);
  227. void ProcessDisconnectMode (
  228. LPBYTE packet_address,
  229. USHORT packet_length);
  230. void ProcessDISC (
  231. LPBYTE packet_address,
  232. USHORT packet_length);
  233. DataLinkError ParseUnnumberedPacketHeader (
  234. LPBYTE packet_address,
  235. BOOL * command_frame,
  236. BOOL * poll_final_bit);
  237. void UpdateAcknowledgeState (
  238. UChar sequence_number);
  239. void ResetSendState (
  240. void);
  241. void StartTimerT200 (void);
  242. void StopTimerT200 (void);
  243. void T200Timeout (
  244. TimerEventHandle);
  245. void StartTimerT203 (void);
  246. void StopTimerT203 (void);
  247. void T203Timeout (
  248. TimerEventHandle);
  249. void Reset (void);
  250. private:
  251. T123 *m_pT123; // owner object
  252. Multiplexer *m_pMultiplexer; // lower layer
  253. IProtocolLayer *Higher_Layer;
  254. USHORT m_nMsgBase;
  255. DLCI DLCI;
  256. BOOL Link_Originator;
  257. USHORT Maximum_Information_Size;
  258. BOOL SABME_Pending;
  259. BOOL Unnumbered_Acknowledge_Pending;
  260. BOOL DISC_Pending;
  261. BOOL Disconnected_Mode_Pending;
  262. BOOL Frame_Reject_Pending;
  263. USHORT Unnumbered_PF_State;
  264. BOOL Final_Packet;
  265. USHORT Data_Indication_Size;
  266. PDataQueue Data_Indication;
  267. LPBYTE Data_Indication_Buffer;
  268. USHORT Data_Indication_Head;
  269. USHORT Data_Indication_Tail;
  270. USHORT Data_Indication_Count;
  271. USHORT Data_Request_Size;
  272. USHORT Data_Request_Total_Size;
  273. PMemory *Data_Request;
  274. USHORT Data_Request_Head;
  275. USHORT Data_Request_Tail;
  276. USHORT Data_Request_Count;
  277. USHORT Data_Request_Acknowledge_Tail;
  278. PMemoryManager Data_Request_Memory_Manager;
  279. USHORT Lower_Layer_Prepend;
  280. USHORT Lower_Layer_Append;
  281. PMemory Supervisory_Write_Struct;
  282. LPBYTE Supervisory_Write_Buffer;
  283. UChar Send_State_Variable;
  284. UChar Receive_State_Variable;
  285. UChar Acknowledge_State_Variable;
  286. BOOL Own_Receiver_Busy;
  287. BOOL Peer_Receiver_Busy;
  288. BOOL Command_Pending;
  289. BOOL Poll_Pending;
  290. BOOL Final_Pending;
  291. BOOL Acknowledge_Pending;
  292. BOOL Reject_Pending;
  293. BOOL Reject_Outstanding;
  294. ULONG T200_Timeout;
  295. TimerEventHandle T200_Handle;
  296. BOOL T200_Active;
  297. ULONG N200_Count;
  298. ULONG Maximum_T200_Timeouts;
  299. ULONG Startup_Maximum_T200_Timeouts;
  300. ULONG Link_Maximum_T200_Timeouts;
  301. ULONG T203_Timeout;
  302. TimerEventHandle T203_Handle;
  303. BOOL T203_Active;
  304. DataLinkMode Data_Link_Mode;
  305. BOOL Link_Stable;
  306. USHORT Receive_Sequence_Exception;
  307. USHORT Receive_Sequence_Recovery;
  308. USHORT Maximum_Outstanding_Packets;
  309. USHORT Outstanding_Packets;
  310. USHORT Maximum_Outstanding_Bytes;
  311. USHORT Outstanding_Bytes;
  312. ULONG Total_Retransmitted;
  313. };
  314. #endif
  315. /*
  316. * Documentation for Public class members
  317. */
  318. /*
  319. * CLayerQ922::CLayerQ922 (
  320. * PTransportResources transport_resources,
  321. * IObject * owner_object,
  322. * IProtocolLayer * lower_layer,
  323. * USHORT message_base,
  324. * USHORT identifier,
  325. * BOOL link_originator,
  326. * USHORT data_indication_queue_siz,
  327. * USHORT data_request_queue_size,
  328. * USHORT k_factor,
  329. * USHORT max_information_size,
  330. * USHORT t200,
  331. * USHORT max_outstanding_bytes,
  332. * PMemoryManager memory_manager,
  333. * BOOL * initialized)
  334. *
  335. * Functional Description
  336. * This is the constructor for the Q.922 data link layer. It prepares
  337. * for communications by allocating buffers and setting its internal
  338. * buffers properly. It also registers itself with its lower layer.
  339. *
  340. * Formal Parameters
  341. * transport_resources (i) - Pointer to TransportResources structure.
  342. * owner_object (i) - Address of the object that owns us. This
  343. * address is used for owner callbacks.
  344. * lower_layer (i) - Address of the layer below us. We pass packets
  345. * to this layer and receive packets from it.
  346. * message_base (i) - Message base used in owner callbacks.
  347. * identifier (i) - Identifier of this object. It is passed to the
  348. * lower layer along with our address, to identify
  349. * us.
  350. * link_originator (i) - TRUE if this object should initiate a link.
  351. * data_indication_queue_size (i) - Number of queues available for
  352. * reception of data from the lower layer
  353. * data_request_queue_size (i) - Number of queues available for
  354. * transmission of data to the lower layer.
  355. * k_factor (i) - Number of outstanding packets allowed.
  356. * max_information_size (i) - Max. number of bytes in the information
  357. * part of a packet
  358. * t200 (i) - T200 timeout
  359. * max_outstanding_bytes (i) - Maximum number of outstanding bytes at
  360. * any one time
  361. * initialized (o) - BOOL returned to user telling him if the
  362. * object initialized o.k.
  363. *
  364. * Return Value
  365. * None
  366. *
  367. * Side Effects
  368. * None
  369. *
  370. * Caveats
  371. * None
  372. */
  373. /*
  374. * CLayerQ922::~CLayerQ922 (void);
  375. *
  376. * Functional Description
  377. * This is the destructor for the Q.922 data link layer. It destroys
  378. * the read and write buffers.
  379. *
  380. * Formal Parameters
  381. * None
  382. *
  383. * Return Value
  384. * None
  385. *
  386. * Side Effects
  387. * None
  388. *
  389. * Caveats
  390. * None
  391. */
  392. /*
  393. * DataLinkError CLayerQ922::ReleaseRequest (void);
  394. *
  395. * Functional Description
  396. * This function is called to terminate a connection. When this function
  397. * is called we queue up a DISC packet to be sent to the remote site.
  398. * When we receive an Unnumbered Ack packet, we notify the owner object
  399. * that the link is terminated
  400. *
  401. * Formal Parameters
  402. * None
  403. *
  404. * Return Value
  405. * None
  406. *
  407. * Side Effects
  408. * None
  409. *
  410. * Caveats
  411. * None
  412. */
  413. /*
  414. * ProtocolLayerError CLayerQ922::DataRequest (
  415. * ULONG identifier,
  416. * PMemory memory,
  417. * PULong bytes_accepted);
  418. *
  419. * Functional Description
  420. * This function is called by a higher layer to request transmission of
  421. * a packet. The packet is held in a memory object.
  422. *
  423. * Formal Parameters
  424. * identifier (i) - Identifier of the higher layer
  425. * memory (i) - Memory object containing packet.
  426. * bytes_accepted (o) - Number of bytes accepted by the CLayerQ922.
  427. * This value will either be 0 or the packet
  428. * length since this layer has a packet interface.
  429. *
  430. * Return Value
  431. * PROTOCOL_LAYER_NO_ERROR - No error occured
  432. *
  433. * Side Effects
  434. * None
  435. *
  436. * Caveats
  437. * None
  438. *
  439. */
  440. /*
  441. * ProtocolLayerError CLayerQ922::DataRequest (
  442. * ULONG identifier,
  443. * LPBYTE buffer_address,
  444. * USHORT length,
  445. * USHORT * bytes_accepted);
  446. *
  447. * Functional Description
  448. * This function is called by a higher layer to request transmission of
  449. * a packet.
  450. *
  451. * Formal Parameters
  452. * identifier (i) - Identifier of the higher layer
  453. * buffer_address (i) - Buffer address
  454. * length (i) - Length of packet to transmit
  455. * bytes_accepted (o) - Number of bytes accepted by the CLayerQ922.
  456. * This value will either be 0 or the packet
  457. * length since this layer has a packet interface.
  458. *
  459. * Return Value
  460. * PROTOCOL_LAYER_NO_ERROR - No error occured
  461. *
  462. * Side Effects
  463. * None
  464. *
  465. * Caveats
  466. * None
  467. */
  468. /*
  469. * ProtocolLayerError CLayerQ922::DataIndication (
  470. * LPBYTE buffer_address,
  471. * USHORT length,
  472. * USHORT * bytes_accepted);
  473. *
  474. * Functional Description
  475. * This function is called by the lower layer when it has data to pass up
  476. * to us. This layer assumes that the data coming to us is in packet
  477. * format.
  478. *
  479. * Formal Parameters
  480. * buffer_address (i) - Buffer address
  481. * length (i) - Number of bytes available
  482. * bytes_accepted (o) - Number of bytes accepted
  483. *
  484. * Return Value
  485. * PROTOCOL_LAYER_NO_ERROR - No error occured
  486. *
  487. * Side Effects
  488. * None
  489. *
  490. * Caveats
  491. * None
  492. *
  493. */
  494. /*
  495. * ProtocolLayerError CLayerQ922::RegisterHigherLayer (
  496. * ULONG identifier,
  497. * PMemoryManager memory_manager,
  498. * IProtocolLayer * higher_layer);
  499. *
  500. * Functional Description
  501. * This function is called by the higher layer to register its identifier
  502. * and its address. When this object needs to send a packet up, it calls
  503. * the higher_layer with a Data Indication
  504. *
  505. * Formal Parameters
  506. * identifier (i) - Unique identifier of the higher layer. If we
  507. * were doing multiplexing at this layer, this
  508. * would have greater significance.
  509. * memory_manager (i) - Pointer to outbound memory manager
  510. * higher_layer (i) - Address of higher layer
  511. *
  512. * Return Value
  513. * PROTOCOL_LAYER_NO_ERROR - No error occured
  514. * PROTOCOL_LAYER_REGISTRATION_ERROR - Error occured on registration
  515. *
  516. * Side Effects
  517. * None
  518. *
  519. * Caveats
  520. * None
  521. *
  522. */
  523. /*
  524. * ProtocolLayerError CLayerQ922::RemoveHigherLayer (
  525. * ULONG);
  526. *
  527. * Functional Description
  528. * This function is called by the higher layer to remove its identifier
  529. * and its address. If the higher layer removes itself from us, we have
  530. * no place to send incoming data
  531. *
  532. * Formal Parameters
  533. * None used
  534. *
  535. * Return Value
  536. * PROTOCOL_LAYER_NO_ERROR - No error occured
  537. *
  538. * Side Effects
  539. * None
  540. *
  541. * Caveats
  542. * None
  543. */
  544. /*
  545. * ProtocolLayerError CLayerQ922::PollTransmitter (
  546. * ULONG,
  547. * USHORT data_to_transmit,
  548. * USHORT * pending_data,
  549. * USHORT * holding_data);
  550. *
  551. * Functional Description
  552. * This function is called to give the CLayerQ922 a chance to transmit data
  553. * in its Data_Request buffer.
  554. *
  555. * Formal Parameters
  556. * identifier (i) - Not used
  557. * data_to_transmit (i) - This is a mask that tells us to send Control
  558. * data, User data, or both.
  559. * pending_data (o) - Return value to indicate which data is left
  560. * to be transmitted.
  561. * holding_data (o) - Returns the number of packets currently
  562. * outstanding.
  563. *
  564. * Return Value
  565. * PROTOCOL_LAYER_NO_ERROR - No error occured
  566. *
  567. * Side Effects
  568. * None
  569. *
  570. * Caveats
  571. * None
  572. */
  573. /*
  574. * ProtocolLayerError CLayerQ922::PollReceiver (
  575. * ULONG identifier);
  576. *
  577. * Functional Description
  578. * This function is called to give the CLayerQ922 a chance pass packets
  579. * to higher layers
  580. *
  581. * Formal Parameters
  582. * identifier (i) - Not used
  583. *
  584. * Return Value
  585. * PROTOCOL_LAYER_NO_ERROR - No error occured
  586. *
  587. * Side Effects
  588. * None
  589. *
  590. * Caveats
  591. * None
  592. */
  593. /*
  594. * ProtocolLayerError CLayerQ922::GetParameters (
  595. * ULONG identifier,
  596. * USHORT * max_packet_size,
  597. * USHORT * prepend_size,
  598. * USHORT * append_size);
  599. *
  600. * Functional Description:
  601. * This function returns the maximum packet size that it can handle via
  602. * its DataRequest() function.
  603. *
  604. * Formal Parameters
  605. * identifier (i) - Not used
  606. * max_packet_size (o) - Address to return max. packet size in.
  607. * prepend_size (o) - Return number of bytes prepended to each packet
  608. * append_size (o) - Return number of bytes appended to each packet
  609. *
  610. * Return Value
  611. * PROTOCOL_LAYER_NO_ERROR - No error occured
  612. *
  613. * Side Effects
  614. * None
  615. *
  616. * Caveats
  617. * None
  618. */
  619.