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.

495 lines
16 KiB

  1. /* Mplex.h
  2. *
  3. * Copyright (c) 1994-1995 by DataBeam Corporation, Lexington, KY
  4. *
  5. * Abstract:
  6. * This is the multiplexer class. It inherits from the ProtocolLayer
  7. * class which means it is one of the layers in a Transport stack. This
  8. * class has these capabilities:
  9. *
  10. * 1. It takes stream data from the lower layer and packetizes it.
  11. * If the lower layer gives us data in a stream format, we run it
  12. * through a packet framer to build up a packet. This class uses
  13. * a framer object passed in by the constructor. When data is
  14. * received from the lower layer, the data is given to the framer
  15. * object. The framer notifies us of a complete packet. The
  16. * framer could be any type of framer (i.e RFC1006, flagged data
  17. * with bit or byte stuffing, ...). If no framer is passed in by
  18. * the constructor, we assume that the data is being received in
  19. * packets.
  20. *
  21. * A packet received from the higher layer is run through the
  22. * framer to encode the data. It is then fed to the lower layer
  23. * in a stream fashion.
  24. *
  25. * 2. It multiplexes multiple higher layers. It currently assumes the
  26. * incoming packets are in Q.922 packet format. Each higher layer
  27. * is identified by its DLCI. This class is capable of looking at
  28. * the packet and determining the DLCI and thus where to route it.
  29. *
  30. * Since this is a multiplexer, we receive packets for many
  31. * different stacks and we do not buffer them if the higher layer
  32. * is not ready for them. If it attempts to send the packet to the
  33. * higher layer and it does not accept it, it may trash it. This
  34. * must be done in order to maintain the other transport
  35. * connections. If necessary, in the future, we could buffer
  36. * packets at this layer.
  37. *
  38. * 3. This class receives a CRC object during construction (if it is
  39. * NULL, no CRC is necessary). The object runs a packet thru the
  40. * CRC generator and attaches it to the end of the packet. On the
  41. * reception of a packet from a lower layer, we check the CRC for
  42. * validity.
  43. *
  44. * Caveats:
  45. * 1. If a framer exists, it assumes the packet is in Q.922 format
  46. * 2. This class is currently Q.922 oriented as far as finding the
  47. * packet identifier (DLCI). This will be fixed in the future.
  48. *
  49. * Authors:
  50. * James W. Lawwill
  51. */
  52. #ifndef _MULTIPLEXER_H_
  53. #define _MULTIPLEXER_H_
  54. #include "q922.h"
  55. #define MULTIPLEXER_MAXIMUM_PACKET_SIZE 1024
  56. #define TRANSPORT_HASHING_BUCKETS 3
  57. /*
  58. ** If the identifier (DLCI) contained by the packet is not legal, the following
  59. ** identifier is returned
  60. */
  61. #define ILLEGAL_DLCI 0xffff
  62. /*
  63. ** Multiplexer return codes
  64. */
  65. typedef enum
  66. {
  67. MULTIPLEXER_NO_ERROR
  68. }
  69. MultiplexerError;
  70. typedef struct
  71. {
  72. IProtocolLayer *q922;
  73. PMemoryManager data_request_memory_manager;
  74. }
  75. MPlexStruct, * PMPlexStruct;
  76. class Multiplexer : public IProtocolLayer
  77. {
  78. public:
  79. Multiplexer(T123 *owner_object,
  80. ComPort *lower_layer,
  81. PhysicalHandle lower_layer_identifier,
  82. USHORT message_base,
  83. PPacketFrame framer,
  84. PCRC crc,
  85. BOOL *initialized);
  86. virtual ~Multiplexer(void);
  87. MultiplexerError ConnectRequest (void);
  88. MultiplexerError DisconnectRequest (void);
  89. /*
  90. ** Functions overridden from the ProtocolLayer object
  91. */
  92. ProtocolLayerError DataRequest (
  93. ULONG_PTR dlci,
  94. LPBYTE buffer_address,
  95. ULONG length,
  96. PULong bytes_accepted);
  97. ProtocolLayerError DataRequest (
  98. ULONG_PTR dlci,
  99. PMemory memory,
  100. PULong bytes_accepted);
  101. ProtocolLayerError DataIndication (
  102. LPBYTE buffer_address,
  103. ULONG length,
  104. PULong bytes_accepted);
  105. ProtocolLayerError RegisterHigherLayer (
  106. ULONG_PTR dlci,
  107. PMemoryManager memory_manager,
  108. IProtocolLayer * higher_layer);
  109. ProtocolLayerError RemoveHigherLayer (
  110. ULONG_PTR dlci);
  111. ProtocolLayerError PollTransmitter (
  112. ULONG_PTR dlci,
  113. USHORT data_to_transmit,
  114. USHORT * pending_data,
  115. USHORT * holding_data);
  116. ProtocolLayerError PollReceiver(void);
  117. ProtocolLayerError GetParameters (
  118. USHORT * max_packet_size,
  119. USHORT * prepend_bytes,
  120. USHORT * append_bytes);
  121. private:
  122. void SendDataToHigherLayer (
  123. LPBYTE buffer_address,
  124. USHORT buffer_length);
  125. DLCI GetDLCI (
  126. LPBYTE buffer_address,
  127. USHORT buffer_size);
  128. private:
  129. DictionaryClass Q922_Layers;
  130. T123 *m_pT123; // owner object
  131. ComPort *m_pComPort; // lower layer
  132. PhysicalHandle m_hCommLink; // physical handle
  133. USHORT m_nMsgBase;
  134. USHORT Maximum_Packet_Size;
  135. USHORT Packet_Size;
  136. LPBYTE Data_Request_Buffer;
  137. PMemory Data_Request_Memory_Object;
  138. DLCI Data_Request_DLCI;
  139. USHORT Data_Request_Length;
  140. USHORT Data_Request_Offset;
  141. LPBYTE Data_Indication_Buffer;
  142. USHORT Data_Indication_Length;
  143. BOOL Data_Indication_Ready;
  144. PPacketFrame Framer;
  145. PCRC CRC;
  146. USHORT CRC_Size;
  147. BOOL Decode_In_Progress;
  148. BOOL Disconnect;
  149. };
  150. #endif
  151. /*
  152. * Documentation for Public class members
  153. */
  154. /*
  155. * Multiplexer::Multiplexer (
  156. * IObject * object_owner,
  157. * IProtocolLayer * lower_layer,
  158. * ULONG identifier,
  159. * USHORT message_base,
  160. * PPacketFrame framer,
  161. * PCRC crc,
  162. * BOOL * initialized);
  163. *
  164. * Functional Description
  165. * This is the constructor for the Multiplexer layer
  166. *
  167. * Formal Parameters
  168. * object_owner - (i) Address of owner object.
  169. * lower_layer - (i) Address of the layer below the multiplexer
  170. * identifier - (i) A lower layer identifier that is passed to the
  171. * lower layer with each call to it. The
  172. * identifier tells the lower layer which "channel"
  173. * to use.
  174. * message_base - (i) Message identifier that is passed back to the
  175. * owner object during a callback
  176. * framer - (i) Address of a framer object
  177. * crc - (i) Address of a crc object
  178. * initialized - (o) Set to TRUE if the multiplexer initialized OK
  179. *
  180. * Return Value
  181. * None
  182. *
  183. * Side Effects
  184. * None
  185. *
  186. * Caveats
  187. * None
  188. *
  189. */
  190. /*
  191. * Multiplexer::~Multiplexer (void)
  192. *
  193. * Functional Description
  194. * This is the destructor for the Multiplexer layer. It removes itself
  195. * from the lower layer and frees all buffers and filters (i.e. framer)
  196. *
  197. * Formal Parameters
  198. * None
  199. *
  200. * Return Value
  201. * None
  202. *
  203. * Side Effects
  204. * None
  205. *
  206. * Caveats
  207. * None
  208. *
  209. */
  210. /*
  211. * MultiplexerError Multiplexer::ConnectRequest (void);
  212. *
  213. * Functional Description
  214. * This function issues an immediate NEW_CONNECTION message to the owner
  215. * of this object. If this was a more sophisticated layer, it would
  216. * communicate with the remote multiplexer layer to establish itself.
  217. *
  218. * Formal Parameters
  219. * None
  220. *
  221. * Return Value
  222. * None
  223. *
  224. * Side Effects
  225. * None
  226. *
  227. * Caveats
  228. * None
  229. *
  230. */
  231. /*
  232. * MultiplexerError Multiplexer::DisconnectRequest (void);
  233. *
  234. * Functional Description
  235. * This function removes its connection with the lower layer and does
  236. * a BROKEN_CONNECTION callback to the owner object
  237. *
  238. * Formal Parameters
  239. * None
  240. *
  241. * Return Value
  242. * None
  243. *
  244. * Side Effects
  245. * None
  246. *
  247. * Caveats
  248. * None
  249. *
  250. */
  251. /*
  252. * ProtocolLayerError Multiplexer::DataRequest (
  253. * ULONG identifier,
  254. * LPBYTE buffer_address,
  255. * USHORT length,
  256. * USHORT * bytes_accepted);
  257. *
  258. * Functional Description
  259. * This function is called by a higher layer to request transmission of
  260. * a packet.
  261. *
  262. * Formal Parameters
  263. * identifier (i) - Identifier of the higher layer
  264. * buffer_address (i) - Buffer address
  265. * length (i) - Length of packet to transmit
  266. * bytes_accepted (o) - Number of bytes accepted by the Multiplexer.
  267. * This value will either be 0 or the packet
  268. * length since this layer is a packet to byte
  269. * converter.
  270. *
  271. * Return Value
  272. * PROTOCOL_LAYER_NO_ERROR - No error occured
  273. *
  274. * Side Effects
  275. * None
  276. *
  277. * Caveats
  278. * None
  279. *
  280. */
  281. /*
  282. * ProtocolLayerError Multiplexer::DataRequest (
  283. * ULONG identifier,
  284. * PMemory memory,
  285. * PULong bytes_accepted);
  286. *
  287. * Functional Description
  288. * This function is called by a higher layer to request transmission of
  289. * a packet.
  290. *
  291. * Formal Parameters
  292. * identifier (i) - Identifier of the higher layer
  293. * memory (o) - Pointer to memory object holding the packet
  294. * bytes_accepted (o) - Number of bytes accepted by the Multiplexer.
  295. * This value will either be 0 or the packet
  296. * length since this layer is a packet to byte
  297. * converter.
  298. *
  299. * Return Value
  300. * PROTOCOL_LAYER_NO_ERROR - No error occured
  301. *
  302. * Side Effects
  303. * None
  304. *
  305. * Caveats
  306. * None
  307. *
  308. */
  309. /*
  310. * ProtocolLayerError Multiplexer::DataIndication (
  311. * LPBYTE buffer_address,
  312. * USHORT length,
  313. * USHORT * bytes_accepted);
  314. *
  315. * Functional Description
  316. * This function is called by the lower layer when it has data to pass up
  317. *
  318. * Formal Parameters
  319. * buffer_address (i) - Buffer address
  320. * length (i) - Number of bytes available
  321. * bytes_accepted (o) - Number of bytes accepted
  322. *
  323. * Return Value
  324. * PROTOCOL_LAYER_NO_ERROR - No error occured
  325. *
  326. * Side Effects
  327. * None
  328. *
  329. * Caveats
  330. * None
  331. *
  332. */
  333. /*
  334. * ProtocolLayerError Multiplexer::RegisterHigherLayer (
  335. * ULONG identifier,
  336. * IProtocolLayer * higher_layer);
  337. *
  338. * Functional Description
  339. * This function is called by the higher layer to register its identifier
  340. * and its address. In some cases, the identifier is the DLCI number in
  341. * the packet. If this multiplexer is being used as a stream to packet
  342. * converter only, the identifer is not used and all data is passed to the
  343. * higher layer.
  344. *
  345. * Formal Parameters
  346. * identifier (i) - Identifier used to identify the higher layer
  347. * higher_layer (i) - Address of higher layer
  348. *
  349. * Return Value
  350. * PROTOCOL_LAYER_NO_ERROR - No error occured
  351. * PROTOCOL_LAYER_REGISTRATION_ERROR - Illegal identifier
  352. *
  353. * Side Effects
  354. * None
  355. *
  356. * Caveats
  357. * None
  358. *
  359. */
  360. /*
  361. * ProtocolLayerError Multiplexer::RemoveHigherLayer (
  362. * ULONG identifier);
  363. *
  364. * Functional Description
  365. * This function is called by the higher layer to remove the higher layer.
  366. * If any more data is received with its identifier on it, it will be
  367. * trashed.
  368. *
  369. * Formal Parameters
  370. * identifier (i) - Identifier used to identify the higher layer
  371. *
  372. * Return Value
  373. * PROTOCOL_LAYER_NO_ERROR - No error occured
  374. * PROTOCOL_LAYER_REGISTRATION_ERROR - Illegal identifier
  375. *
  376. * Side Effects
  377. * None
  378. *
  379. * Caveats
  380. * None
  381. *
  382. */
  383. /*
  384. * ProtocolLayerError Multiplexer::PollTransmitter (
  385. * ULONG identifier,
  386. * USHORT data_to_transmit,
  387. * USHORT * pending_data);
  388. *
  389. * Functional Description
  390. * This function is called to give the Multiplexer a chance transmit data
  391. * in its Data_Request buffer.
  392. *
  393. * Formal Parameters
  394. * identifier (i) - Not used
  395. * data_to_transmit (i) - This is a mask that tells us to send Control
  396. * data, User data, or both. Since the
  397. * Multiplexer does not differentiate between
  398. * data types it transmits any data it has
  399. * pending_data (o) - Return value to indicat which data is left
  400. * to be transmitted.
  401. *
  402. * Return Value
  403. * PROTOCOL_LAYER_NO_ERROR - No error occured
  404. *
  405. * Side Effects
  406. * None
  407. *
  408. * Caveats
  409. * None
  410. *
  411. */
  412. /*
  413. * ProtocolLayerError Multiplexer::PollReceiver (
  414. * ULONG identifier);
  415. *
  416. * Functional Description
  417. * This function is called to give the Multiplexer a chance pass packets
  418. * to higher layers
  419. *
  420. * Formal Parameters
  421. * identifier (i) - Not used
  422. *
  423. * Return Value
  424. * PROTOCOL_LAYER_NO_ERROR - No error occured
  425. *
  426. * Side Effects
  427. * None
  428. *
  429. * Caveats
  430. * None
  431. *
  432. */
  433. /*
  434. * ProtocolLayerError Multiplexer::GetParameters (
  435. * ULONG identifier,
  436. * USHORT * max_packet_size,
  437. * USHORT * prepend_bytes,
  438. * USHORT * append_bytes);
  439. *
  440. * Functional Description
  441. * This function is called to get the maximum packet size
  442. *
  443. * Formal Parameters
  444. * identifier (i) - Not used
  445. * max_packet_size (o) - Returns the maximum packet size
  446. * prepend_bytes (o) - Returns the Number of bytes prepended by
  447. * this layer
  448. * append_bytes (o) - Returns the Number of bytes appended by
  449. * this layer
  450. *
  451. * Return Value
  452. * PROTOCOL_LAYER_NO_ERROR - No error occured
  453. *
  454. * Side Effects
  455. * None
  456. *
  457. * Caveats
  458. * None
  459. *
  460. */
  461.