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.

674 lines
20 KiB

  1. /* X224.h
  2. *
  3. * Copyright (c) 1994-1995 by DataBeam Corporation, Lexington, KY
  4. *
  5. * Abstract:
  6. * This class represents the X.224 class 0 Transport functionality. This
  7. * is the highest layer in the T.123 specification. This layer is unique
  8. * in that it has direct access to the User. When data packets are
  9. * received from the remote site and reassembled by this class, they are
  10. * passed on to the user via a callback.
  11. *
  12. * This class has only limited functionality. It basically has a simple
  13. * link establishment procedure (which includes arbitration of maximum PDU
  14. * size). It is then responsible for transmitting and receiving user data.
  15. * Its maximum TSDU size is 8K, and its TPDU size can range from 128 bytes
  16. * to 2K. Its TSDU size is larger than its TPDU size, it must be able to
  17. * segment and reassemble the user packet.
  18. *
  19. * This layer ASSUMES that its lower layer has a packet interface rather
  20. * than a stream interface.
  21. *
  22. * This layer ASSUMES that the disconnect of a call is handled by the
  23. * Network layer (as specified in the X.224 class 0 document).
  24. *
  25. * Prior knowledge of the X.224 class 0 specification would help the user
  26. * understand the code.
  27. *
  28. * Caveats:
  29. * None.
  30. *
  31. * Authors:
  32. * James W. Lawwill
  33. */
  34. #ifndef _X224_H_
  35. #define _X224_H_
  36. #include "tmemory2.h"
  37. /*
  38. ** The following, are states that the class can be in.
  39. */
  40. typedef enum
  41. {
  42. NO_CONNECTION,
  43. SENT_CONNECT_REQUEST_PACKET,
  44. SENT_CONNECT_CONFIRM_PACKET,
  45. SENT_DISCONNECT_REQUEST_PACKET,
  46. SENT_ERROR_PACKET,
  47. CONNECTION_ACTIVE,
  48. RECEIVED_CONNECT_REQUEST_PACKET,
  49. FAILED_TO_INITIALIZE
  50. }
  51. X224State;
  52. #define TRANSPORT_HASHING_BUCKETS 3
  53. /*
  54. ** Packet types
  55. */
  56. #define TPDU_CODE_MASK 0xf0
  57. #define TRANSPORT_NO_PACKET 0x00
  58. #define CONNECTION_REQUEST_PACKET 0xe0
  59. #define CONNECTION_CONFIRM_PACKET 0xd0
  60. #define DISCONNECT_REQUEST_PACKET 0x80
  61. #define ERROR_PACKET 0x70
  62. #define DATA_PACKET 0xf0
  63. #define TSAP_CALLING_IDENTIFIER 0xc1
  64. #define TSAP_CALLED_IDENTIFIER 0xc2
  65. #define TPDU_SIZE 0xc0
  66. /*
  67. ** These defines are used for the ERROR packet
  68. */
  69. #define INVALID_TPDU 0xc1
  70. /*
  71. ** Packet size codes
  72. */
  73. #define PACKET_SIZE_128 0x07
  74. #define PACKET_SIZE_256 0x08
  75. #define PACKET_SIZE_512 0x09
  76. #define PACKET_SIZE_1024 0x0a
  77. #define PACKET_SIZE_2048 0x0b
  78. /*
  79. ** Miscellaneous definitions
  80. */
  81. #define MAXIMUM_USER_DATA_SIZE 8192
  82. #define DATA_PACKET_HEADER_SIZE 3
  83. #define EOT_BIT 0x80
  84. #define CONNECT_REQUEST_HEADER_SIZE 6
  85. #define CONNECT_CONFIRM_HEADER_SIZE 6
  86. #define DISCONNECT_REQUEST_HEADER_SIZE 6
  87. #define ERROR_HEADER_SIZE 6
  88. #define TPDU_ARBITRATION_PACKET_SIZE 3
  89. #define DISCONNECT_REASON_NOT_SPECIFIED 0
  90. typedef SListClass DataRequestQueue;
  91. typedef SListClass PacketQueue;
  92. class CLayerX224 : public IProtocolLayer
  93. {
  94. public:
  95. CLayerX224(
  96. T123 *owner_object,
  97. CLayerQ922 *lower_layer,
  98. USHORT message_base,
  99. LogicalHandle logical_handle,
  100. ULONG identifier,
  101. USHORT data_indication_queue_size,
  102. USHORT default_PDU_size,
  103. PMemoryManager dr_memory_manager,
  104. BOOL *initialization_success);
  105. virtual ~CLayerX224(void);
  106. /*
  107. ** Making and breaking links
  108. */
  109. TransportError ConnectRequest (void);
  110. TransportError ConnectResponse (void);
  111. TransportError DisconnectRequest (void);
  112. /*
  113. ** Functions overridden from the ProtocolLayer object
  114. */
  115. ProtocolLayerError DataRequest (
  116. ULONG_PTR identifier,
  117. LPBYTE buffer_address,
  118. ULONG length,
  119. PULong bytes_accepted);
  120. ProtocolLayerError DataRequest (
  121. ULONG_PTR identifier,
  122. PMemory,
  123. PULong bytes_accepted);
  124. ProtocolLayerError DataIndication (
  125. LPBYTE buffer_address,
  126. ULONG length,
  127. PULong bytes_accepted);
  128. ProtocolLayerError RegisterHigherLayer (
  129. ULONG_PTR,
  130. PMemoryManager,
  131. IProtocolLayer *);
  132. ProtocolLayerError RemoveHigherLayer (
  133. ULONG_PTR);
  134. ProtocolLayerError PollTransmitter (
  135. ULONG_PTR identifier,
  136. USHORT data_to_transmit,
  137. USHORT * pending_data,
  138. USHORT * holding_data);
  139. ProtocolLayerError PollReceiver(void);
  140. ProtocolLayerError GetParameters (
  141. USHORT *,
  142. USHORT *,
  143. USHORT *);
  144. void ShutdownReceiver (void);
  145. void EnableReceiver (void);
  146. void ShutdownTransmitter (void);
  147. void PurgeRequest (void);
  148. void CheckUserBuffers (void);
  149. static ULONG GetMaxTPDUSize (
  150. ULONG max_lower_layer_pdu);
  151. private:
  152. BOOL AllocateBuffers (void);
  153. void ErrorPacket (
  154. LPBYTE packet_address,
  155. USHORT packet_length);
  156. private:
  157. DataRequestQueue Data_Request_Queue;
  158. PacketQueue Data_Indication_Queue;
  159. PacketQueue Data_Indication_Memory_Pool;
  160. PTMemory Active_Data_Indication;
  161. T123 *m_pT123; // owner object
  162. CLayerQ922 *m_pQ922; // lower layer;
  163. USHORT m_nMsgBase;
  164. USHORT Default_PDU_Size;
  165. USHORT Maximum_PDU_Size;
  166. USHORT Arbitrated_PDU_Size;
  167. ULONG Identifier;
  168. PMemoryManager Data_Request_Memory_Manager;
  169. USHORT Lower_Layer_Prepend;
  170. USHORT Lower_Layer_Append;
  171. ULONG User_Data_Pending;
  172. USHORT Data_Indication_Queue_Size;
  173. BOOL Data_Indication_Reassembly_Active;
  174. X224State State;
  175. USHORT Packet_Pending;
  176. UChar Reject_Cause;
  177. BOOL Packet_Size_Respond;
  178. BOOL Shutdown_Receiver;
  179. BOOL Shutdown_Transmitter;
  180. LPBYTE Error_Buffer;
  181. USHORT Error_Buffer_Length;
  182. LogicalHandle m_nLocalLogicalHandle;
  183. LogicalHandle m_nRemoteLogicalHandle;
  184. };
  185. #endif
  186. /*
  187. * Documentation for Public class members
  188. */
  189. /*
  190. * Transport::Transport (
  191. * PTransportResources transport_resources,
  192. * IObject * owner_object,
  193. * IProtocolLayer * lower_layer,
  194. * USHORT message_base,
  195. * USHORT logical_handle,
  196. * USHORT identifier,
  197. * USHORT data_request_queue_size,
  198. * USHORT data_indication_queue_size,
  199. * USHORT default_PDU_size,
  200. * PMemoryManager dr_memory_manager,
  201. * BOOL * initialization_success);
  202. *
  203. * Functional Description
  204. * This is the class constructor. During construction, this object
  205. * registers itself with its lower layer and allocates buffer space for
  206. * sending and receiving data.
  207. *
  208. * Formal Parameters
  209. * transport_resources (i) - Pointer to TransportResources structure.
  210. * owner_object (i) - Address of owner object. We use this
  211. * address for owner callbacks.
  212. * lower_layer (i) - Address of the lower layer that we will use
  213. * for data reception and transmission. This
  214. * layer must inherit from ProtocolLayer.
  215. * message_base (i) - Message base for messages used for owner
  216. * callbacks.
  217. * logical_handle (i) - This identification must be passed back to
  218. * the owner during owner callbacks to identify
  219. * itself.
  220. * identifier (i) - This identifier is passed to the lower layer
  221. * to identify itself (in case the lower layer
  222. * is doing multiplexing.
  223. * data_request_queue_size (i) - Number of buffers to be used for data
  224. * requests from user.
  225. * data_indication_queue_size (i) - Number of buffers to be used for
  226. * data requests from user.
  227. * default_PDU_size (i) - If the remote site does not support packet
  228. * size arbitration, this is the default
  229. * dr_memory_manager (i) - Data Request memory manager
  230. * initialization_success (o) - Return TRUE if initialization was
  231. * successful
  232. *
  233. * Return Value
  234. * None
  235. *
  236. * Side Effects
  237. * None
  238. *
  239. * Caveats
  240. * None
  241. *
  242. */
  243. /*
  244. * Transport::~Transport (void)
  245. *
  246. * Functional Description
  247. * This is the destructor for the class. It does all cleanup
  248. *
  249. * Formal Parameters
  250. * None
  251. *
  252. * Return Value
  253. * None
  254. *
  255. * Side Effects
  256. * None
  257. *
  258. * Caveats
  259. * None
  260. *
  261. */
  262. /*
  263. * TransportError Transport::ConnectRequest (void);
  264. *
  265. * Functional Description
  266. * This function is called to initiate the connection. As a result the
  267. * owner will either receive a TRANSPORT_CONNECT_CONFIRM or a
  268. * TRANSPORT_DISCONNECT_INDICATION message on completion of arbitration.
  269. *
  270. * Formal Parameters
  271. * None
  272. *
  273. * Return Value
  274. * TRANSPORT_NO_ERROR - No error occured
  275. * TRANSPORT_ERROR - Error
  276. *
  277. * Side Effects
  278. * None
  279. *
  280. * Caveats
  281. * None
  282. *
  283. */
  284. /*
  285. * TransportError Transport::ConnectResponse (void);
  286. *
  287. * Functional Description
  288. * This function is called in response to a TRANSPORT_CONNECT_INDICATION
  289. * message issued by this class. By calling this function, the user is
  290. * accepting the transport connection.
  291. *
  292. * Formal Parameters
  293. * None
  294. *
  295. * Return Value
  296. * TRANSPORT_NO_ERROR - No error occured
  297. * TRANSPORT_ERROR - Error
  298. *
  299. * Side Effects
  300. * None
  301. *
  302. * Caveats
  303. * None
  304. *
  305. */
  306. /*
  307. * TransportError Transport::DisconnectRequest (void);
  308. *
  309. * Functional Description
  310. * This function is called in response to a TRANSPORT_CONNECT_INDICATION
  311. * message issued by this class. By calling this function, the user is
  312. * not accepting the transport connection.
  313. *
  314. * Formal Parameters
  315. * None
  316. *
  317. * Return Value
  318. * TRANSPORT_NO_ERROR - No error occured
  319. * TRANSPORT_ERROR - Error
  320. *
  321. * Side Effects
  322. * None
  323. *
  324. * Caveats
  325. * None
  326. *
  327. */
  328. /*
  329. * ProtocolLayerError Transport::DataRequest (
  330. * USHORT identifier,
  331. * LPBYTE buffer_address,
  332. * USHORT length,
  333. * USHORT * bytes_accepted);
  334. *
  335. * Functional Description
  336. * This function is called by a higher layer to request transmission of
  337. * a packet.
  338. *
  339. * Formal Parameters
  340. * identifier (i) - Identifier of the higher layer
  341. * buffer_address (i) - Buffer address
  342. * length (i) - Length of packet to transmit
  343. * bytes_accepted (o) - Number of bytes accepted by the Transport.
  344. * This value will either be 0 or the packet
  345. * length since this layer is a packet to byte
  346. * converter.
  347. *
  348. * Return Value
  349. * PROTOCOL_LAYER_NO_ERROR - No error occured
  350. *
  351. * Side Effects
  352. * None
  353. *
  354. * Caveats
  355. * None
  356. *
  357. */
  358. /*
  359. * ProtocolLayerError Transport::DataIndication (
  360. * LPBYTE buffer_address,
  361. * USHORT length,
  362. * USHORT * bytes_accepted);
  363. *
  364. * Functional Description
  365. * This function is called by the lower layer when it has data to pass up
  366. *
  367. * Formal Parameters
  368. * buffer_address (i) - Buffer address
  369. * length (i) - Number of bytes available
  370. * bytes_accepted (o) - Number of bytes accepted
  371. *
  372. * Return Value
  373. * PROTOCOL_LAYER_NO_ERROR - No error occured
  374. *
  375. * Side Effects
  376. * None
  377. *
  378. * Caveats
  379. * None
  380. *
  381. */
  382. /*
  383. * ProtocolLayerError Transport::RegisterHigherLayer (
  384. * USHORT,
  385. * IProtocolLayer *);
  386. *
  387. * Functional Description
  388. * This function is called by the higher layer to register its identifier
  389. * and its address. This function is not used by this class. It is only
  390. * in here because this class inherits from ProtocolLayer and this function
  391. * is a pure virtual function.
  392. *
  393. * Formal Parameters
  394. * None used
  395. *
  396. * Return Value
  397. * PROTOCOL_LAYER_NO_ERROR - No error occured
  398. *
  399. * Side Effects
  400. * None
  401. *
  402. * Caveats
  403. * None
  404. *
  405. */
  406. /*
  407. * ProtocolLayerError Transport::RemoveHigherLayer (
  408. * USHORT);
  409. *
  410. * Functional Description
  411. * This function is called by the higher layer to remove its identifier
  412. * and its address. This function is not used by this class. It is only
  413. * in here because this class inherits from ProtocolLayer and this function
  414. * is a pure virtual function.
  415. *
  416. * Formal Parameters
  417. * None used
  418. *
  419. * Return Value
  420. * PROTOCOL_LAYER_NO_ERROR - No error occured
  421. *
  422. * Side Effects
  423. * None
  424. *
  425. * Caveats
  426. * None
  427. */
  428. /*
  429. * ProtocolLayerError Transport::PollTransmitter (
  430. * USHORT,
  431. * USHORT data_to_transmit,
  432. * USHORT * pending_data,
  433. * USHORT *)
  434. *
  435. * Functional Description
  436. * This function is called to give the Transport a chance transmit data
  437. * in its Data_Request buffer.
  438. *
  439. * Formal Parameters
  440. * identifier (i) - Not used
  441. * data_to_transmit (i) - This is a mask that tells us to send Control
  442. * data, User data, or both. Since the
  443. * Transport does not differentiate between
  444. * data types it transmits any data it has
  445. * pending_data (o) - Return value to indicate which data is left
  446. * to be transmitted.
  447. *
  448. * Return Value
  449. * PROTOCOL_LAYER_NO_ERROR - No error occured
  450. *
  451. * Side Effects
  452. * None
  453. *
  454. * Caveats
  455. * None
  456. *
  457. */
  458. /*
  459. * ProtocolLayerError Transport::PollReceiver (
  460. * USHORT identifier);
  461. *
  462. * Functional Description
  463. * This function is called to give the Transport a chance pass packets
  464. * to higher layers
  465. *
  466. * Formal Parameters
  467. * identifier (i) - Not used
  468. *
  469. * Return Value
  470. * PROTOCOL_LAYER_NO_ERROR - No error occured
  471. *
  472. * Side Effects
  473. * None
  474. *
  475. * Caveats
  476. * None
  477. */
  478. /*
  479. * ProtocolLayerError Transport::GetParameters (
  480. * USHORT identifier,
  481. * USHORT * max_packet_size,
  482. * USHORT * prepend,
  483. * USHORT * append);
  484. *
  485. * Functional Description:
  486. * This function is not used by this class. It is only in here because
  487. * this class inherits from ProtocolLayer and this function
  488. * is a pure virtual function.
  489. *
  490. * Formal Parameters
  491. * None used
  492. *
  493. * Return Value
  494. * PROTOCOL_LAYER_NO_ERROR - No error occured
  495. *
  496. * Side Effects
  497. * None
  498. *
  499. * Caveats
  500. * None
  501. */
  502. /*
  503. * void Transport::ShutdownReceiver ();
  504. *
  505. * Functional Description:
  506. * This function tells the object to stop accepting packets from the
  507. * lower layer
  508. *
  509. * Formal Parameters
  510. * None used
  511. *
  512. * Return Value
  513. * None
  514. *
  515. * Side Effects
  516. * None
  517. *
  518. * Caveats
  519. * None
  520. */
  521. /*
  522. * void Transport::EnableReceiver (void);
  523. *
  524. * Functional Description:
  525. * This function tells the object to start sending packets up to the user
  526. * again. If the X224 object ever issues a DATA_INDICATION and it fails,
  527. * we shutdown the receiver. We wait for this call to be issued before
  528. * we start sending up packets again.
  529. *
  530. * Formal Parameters
  531. * None used
  532. *
  533. * Return Value
  534. * None
  535. *
  536. * Side Effects
  537. * None
  538. *
  539. * Caveats
  540. * None
  541. */
  542. /*
  543. * void Transport::ShutdownTransmitter (void);
  544. *
  545. * Functional Description:
  546. * This function tells the object to stop accepting packets from
  547. * higher layers.
  548. *
  549. * Formal Parameters
  550. * None used
  551. *
  552. * Return Value
  553. * None
  554. *
  555. * Side Effects
  556. * None
  557. *
  558. * Caveats
  559. * None
  560. */
  561. /*
  562. * void Transport::PurgeRequest (void);
  563. *
  564. * Functional Description:
  565. * This function removes all packets from the Transport's outbound queue
  566. *
  567. * Formal Parameters
  568. * None used
  569. *
  570. * Return Value
  571. * None
  572. *
  573. * Side Effects
  574. * None
  575. *
  576. * Caveats
  577. * None
  578. */
  579. /*
  580. * void Transport::CheckUserBuffers (void);
  581. *
  582. * Functional Description:
  583. * This function determines if the user has recently failed to pass a
  584. * packet down to the Transport because we didn't have enough memory
  585. * available to handle it. If he did and we NOW have space for that
  586. * packet, we will issue a TRANSPORT_BUFFER_EMPTY_INDICATION callback
  587. * to the user, to notify him that we can accept it.
  588. *
  589. * Formal Parameters
  590. * None used
  591. *
  592. * Return Value
  593. * None
  594. *
  595. * Side Effects
  596. * None
  597. *
  598. * Caveats
  599. * None
  600. */
  601. /*
  602. * static ULONG Transport::GetMaxTPDUSize (
  603. * ULONG max_lower_layer_pdu)
  604. *
  605. * Public
  606. *
  607. * Functional Description:
  608. * This function accepts a value for the lower layer max. PDU size
  609. * and returns the max. PDU size that this Transport can support
  610. * based on it. X224 only suports max PDU sizes of 128, 256, 512,
  611. * 1024, and 2048. So, if the max_lower_layer_pdu is 260, the
  612. * Transport can only have a max pdu size of 256.
  613. *
  614. * Formal Parameters
  615. * max_lower_layer_pdu - Since we pass data to the lower layer,
  616. * we must conform to its max packet size.
  617. *
  618. * Return Value
  619. * The largest TPDU that we will send based on the max_lower_layer_pdu.
  620. *
  621. * Side Effects
  622. * None
  623. *
  624. * Caveats
  625. * None
  626. */
  627.