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.

673 lines
25 KiB

  1. /* TransportController.h
  2. *
  3. * Copyright (c) 1993-1995 by DataBeam Corporation, Lexington, KY
  4. *
  5. * Abstract:
  6. * This is the Transport Controller file for the MCATPSTN DLL.
  7. *
  8. * This DLL instantiates a PSTNController which controls the
  9. * making and breaking of connections. This routine also constructs and
  10. * destructs T123 stacks. When the physical layer creates or detects a
  11. * connection this class is notified. It then instantiates a T123 object
  12. * which sets up a T123 stack to control this physical connection. The
  13. * T123 stace notifies this controller when a connection is up and running.
  14. * It also notifies this controller if the link is broken for some reason.
  15. * As a result, this controller notifies the user of the new or broken
  16. * connection.
  17. *
  18. * When the user wants to make a data request of a specific transport
  19. * connection, this controller maps the connection id to a T123 stack. The
  20. * data request is passed on to that stack. Data Indications are passed
  21. * to the user by the T123 stack. The controller does not need to know
  22. * about these and lets the T123 stack handle them.
  23. *
  24. * POLLING THE DLL:
  25. * This stack is maintained by the Poll calls (PollTransmitter() and
  26. * PollReceiver()). During these calls we transmit and receive
  27. * packets with the remote sites. It is extremely important that
  28. * this DLL receive a time slice from the CPU on a regular and
  29. * frequent basis. This will give us the time we need to properly
  30. * maintain the link. If these calls are not used in a frequent and
  31. * regular basis, the communications link will be unproductive and
  32. * could eventually be lost.
  33. *
  34. * USER CALLBACKS:
  35. * The user communicates with this DLL by making calls directly to the
  36. * DLL. The DLL communicates with the user by issuing callbacks.
  37. * The TInitialize() call accepts as a parameter, a callback address and
  38. * a user defined variable. When a significant event occurs in the DLL,
  39. * the DLL will jump to the callback address. The first parameter of
  40. * the callback is the message. This could be a
  41. * TRANSPORT_CONNECT_INDICATION, TRANSPORT_DISCONNECT_INDICATION, or any
  42. * number of significant events. The second parameter is a message
  43. * specific parameter. The third parameter is the user defined variable
  44. * that was passed in during the TInitialize() function. See the
  45. * mcattprt.h interface file for a complete description of the callback
  46. * messages.
  47. *
  48. * MAKING A CALL:
  49. * After the initialization has been done, the user will eventually,
  50. * want to attempt a connection. The user issues a TConnectRequest() call
  51. * with the PSTN address of the remote location. The connection request
  52. * is passed on to the PSTNcontroller. It eventually issues a callback to
  53. * the this controller to say that the connection was successful and passes
  54. * up the address of the physical layer. If the physical handle passed up
  55. * by the PSTNController is a new handle, we create a T123 object, and
  56. * issue a ConnectRequest() to it. The T123 object creates a T.123
  57. * compliant stack and notifies the Controller when it is up and running.
  58. * If the handle passed up from the PSTNController is currently associated
  59. * with an already active T123 object, we simply make a ConnectRequest()
  60. * call to the T123 object so that it will create another logical
  61. * connection over the same physical connection.
  62. *
  63. * RECEIVING A CALL:
  64. * If we receive a call from a remote location, the PSTNController notifies
  65. * us that a new connection is being attempted. We then create a new
  66. * T123 stack associated with the physical connection. The T123 stack
  67. * will notify us if new a Transport Connection id need to be generated.
  68. * It will also notify us when the Transport Connection is up and running.
  69. *
  70. * SENDING PACKETS:
  71. * To send data to the remote location, use the DataRequest() function
  72. * call. This controller will pass the packet to the T123 stack that it is
  73. * associated with. The send may actually occur after the call has
  74. * returned to the user.
  75. *
  76. * RECEIVING PACKETS:
  77. * The user receives packets by DATA_INDICATION callbacks. When the
  78. * user makes PollReceiver() calls, the Transport Layer checks its input
  79. * buffers for packets. If a packet is found, we issue a DATA_INDICATION
  80. * callback to the user with the Transport Connection handle, the address
  81. * of the packet, and the packet length.
  82. *
  83. * DISCONNECTING A TRANSPORT:
  84. * To disconnect a transport connection, use the DisconnectRequest()
  85. * function. After the link has been brought down, we perform a
  86. * callback to the user to verify the disconnect.
  87. *
  88. * Caveats:
  89. * None.
  90. *
  91. * Author:
  92. * James W. Lawwill
  93. *
  94. */
  95. #ifndef _TRANSPORT_CONTROLLER_
  96. #define _TRANSPORT_CONTROLLER_
  97. #include "t123.h"
  98. #define TRANSPORT_CONTROLLER_MESSAGE_BASE 0
  99. /*
  100. ** Each Logical Connection has a LogicalConnectionStruct associated
  101. ** with it.
  102. **
  103. ** physical_layer - Pointer to physical layer associated with
  104. ** this logical connection.
  105. ** physical_handle - Each physical connection has a
  106. ** physical_handle associated with it.
  107. ** protocol_stack - The T123 object associated with it.
  108. ** priority - Priority of the logical connection
  109. ** t123_connection_requested - TRUE if this logical connection has issued
  110. ** a ConnectRequest() to the t123 object.
  111. ** t123_disconnect_requested - TRUE if this logical connection has issued
  112. ** a DiconnectRequest() to the t123 object.
  113. */
  114. typedef struct
  115. {
  116. BOOL fCaller;
  117. ComPort *comport; // physical layer
  118. PhysicalHandle hCommLink; // physical handle
  119. T123 *t123; // protocal stack
  120. TransportPriority priority;
  121. BOOL t123_connection_requested;
  122. BOOL t123_disconnect_requested;
  123. }
  124. LogicalConnectionStruct, * PLogicalConnectionStruct;
  125. class TransportController
  126. {
  127. public:
  128. TransportController(void);
  129. ~TransportController (void);
  130. /*
  131. ** Functions related making and breaking a link
  132. */
  133. TransportError CreateTransportStack(
  134. BOOL fCaller,
  135. HANDLE hCommLink,
  136. HANDLE hevtClose,
  137. PLUGXPRT_PARAMETERS *);
  138. TransportError CloseTransportStack(
  139. HANDLE hCommLink);
  140. TransportError ConnectRequest (
  141. LogicalHandle *logical_handle,
  142. HANDLE hCommLink,
  143. TransportPriority transport_priority = DEFAULT_PRIORITY);
  144. TransportError ConnectResponse (
  145. LogicalHandle logical_handle);
  146. TransportError DisconnectRequest (
  147. LogicalHandle logical_handle,
  148. UINT_PTR trash_packet);
  149. /*
  150. ** This function is used to send a data packet
  151. */
  152. TransportError DataRequest (
  153. LogicalHandle logical_handle,
  154. LPBYTE user_data,
  155. ULONG user_data_length);
  156. TransportError PurgeRequest (
  157. LogicalHandle logical_handle);
  158. void EnableReceiver (void);
  159. /*
  160. ** These four functions are the heartbeat of the DLL. Transmission
  161. ** and reception of data occur during these calls.
  162. */
  163. void PollReceiver(void);
  164. void PollReceiver(PhysicalHandle);
  165. void PollTransmitter(void);
  166. void PollTransmitter(PhysicalHandle);
  167. /*
  168. ** Miscellaneous utilities
  169. */
  170. TransportError ProcessCommand (
  171. USHORT message,
  172. PVoid input_structure,
  173. PVoid output_structure);
  174. /*
  175. ** Callback used by the PSTNController and the T123 objects
  176. */
  177. ULONG_PTR OwnerCallback(ULONG, void *p1 = NULL, void *p2 = NULL, void *p3 = NULL);
  178. PhysicalHandle GetPhysicalHandle (
  179. LogicalHandle logical_handle);
  180. private:
  181. LogicalHandle GetNextLogicalHandle (void);
  182. void ProcessMessages (void);
  183. void RemoveLogicalConnections (
  184. PhysicalHandle physical_handle);
  185. void Reset (
  186. BOOL notify_user);
  187. TransportError NewConnection (
  188. PhysicalHandle physical_handle,
  189. BOOL link_originator,
  190. ComPort *physical_layer);
  191. TransportError CreateT123Stack(
  192. PhysicalHandle hCommLink,
  193. BOOL link_originator, // fCaller
  194. ComPort *comport,
  195. PLUGXPRT_PARAMETERS *pParams);
  196. private:
  197. /*
  198. ** This is a list of the physical connections we currently have.
  199. ** It is associated with a structure that holds each layer in
  200. ** the stack(s).
  201. */
  202. DictionaryClass Protocol_Stacks; // list of T123 objects
  203. DictionaryClass Logical_Connection_List;
  204. SListClass Transmitter_List;
  205. SListClass Message_List;
  206. BOOL Emergency_Shutdown;
  207. BOOL Poll_Active;
  208. };
  209. #endif
  210. /*
  211. * Documentation for Public class members
  212. */
  213. /*
  214. * TransportController::TransportController (
  215. * PTransportResources transport_resources);
  216. *
  217. * Functional Description
  218. * This is the Transport Controller constructor. This routine instantiates
  219. * a PSTNController() and routes calls to the proper location.
  220. *
  221. * Formal Parameters
  222. * transport_resources - (i) This is the address TransportResources
  223. * structure.
  224. *
  225. * Return Value
  226. * None
  227. *
  228. * Side Effects
  229. * None
  230. *
  231. * Caveats
  232. * None
  233. */
  234. /*
  235. * TransportController::~TransportController (void)
  236. *
  237. * Functional Description
  238. * This is the TransportController destructor. It deletes the
  239. * PSTNController and any T123 objects that are alive.
  240. *
  241. * Formal Parameters
  242. * None
  243. *
  244. * Return Value
  245. * None
  246. *
  247. * Side Effects
  248. * None
  249. *
  250. * Caveats
  251. * None
  252. */
  253. /*
  254. * TransportError TransportController::ConnectRequest (
  255. * TransportAddress transport_address,
  256. * TransportPriority transport_priority,
  257. * LogicalHandle *logical_handle);
  258. *
  259. * Functional Description
  260. * This function initiates a connection. It calls the PSTNController with
  261. * the transport_address so that it can start the connection procedure.
  262. * When this routine returns, it does NOT mean that a connection exists.
  263. * It means that a connection is in progress and will eventually be
  264. * completed when the user receives a TRANSPORT_CONNECT_CONFIRM or
  265. * TRANSPORT_DISCONNECT_INDICATION.
  266. *
  267. * Formal Parameters
  268. * transport_address - (i) Address of ascii string containing the
  269. * telephone number or physical handle.
  270. * transport_priority - (i) Requested priority of the connection.
  271. * This value can be 0-14 inclusive.
  272. * logical_handle - (o) Address of transport connection. We return
  273. * a unique transport connection number as the
  274. * result of a successful dial operation.
  275. *
  276. * Return Value
  277. * TRANSPORT_NO_ERROR - No Error
  278. * TRANSPORT_NO_CONNECTION_AVAILABLE - No resources for the connection
  279. * TRANSPORT_CONNECT_REQUEST_FAILED - Unable to reach the address
  280. *
  281. * Side Effects
  282. * None
  283. *
  284. * Caveats
  285. * None
  286. */
  287. /*
  288. * TransportError TransportController::ConnectResponse (
  289. * LogicalHandle logical_handle);
  290. *
  291. * Functional Description
  292. * This function is called in response to a TRANSPORT_CONNECT_INDICATION
  293. * callback. The user should call this function or the
  294. * DisconnectRequest() function if that don't want the logical connection.
  295. *
  296. * Formal Parameters
  297. * logical_handle - (i) Logical handle that we are responding to.
  298. *
  299. * Return Value
  300. * TRANSPORT_NO_ERROR - No Error
  301. * TRANSPORT_NO_SUCH_CONNECTION - Transport connection does not exist
  302. *
  303. * Side Effects
  304. * None
  305. *
  306. * Caveats
  307. * None
  308. */
  309. /*
  310. * TransportError TransportController::DisconnectRequest (
  311. * LogicalHandle logical_handle);
  312. *
  313. * Functional Description
  314. * This function terminates the user's transport connection. The user
  315. * will receive a DISCONNECT_INDICATION when the connection is broken.
  316. * If we are multiplexing multiple connections over the same physical
  317. * connection, we will not break the physical comm. link until the last
  318. * connection is broken.
  319. *
  320. * Formal Parameters
  321. * logical_handle - (i) Transport connection number to terminate
  322. *
  323. * Return Value
  324. * TRANSPORT_NO_ERROR - No Error
  325. * TRANSPORT_NO_SUCH_CONNECTION - Transport connection does not exist
  326. *
  327. * Side Effects
  328. * None
  329. *
  330. * Caveats
  331. * None
  332. */
  333. /*
  334. * TransportError TransportController::DataRequest (
  335. * LogicalHandle logical_handle,
  336. * LPBYTE user_data,
  337. * ULONG user_data_length);
  338. *
  339. * Functional Description
  340. * This function is used to send a data packet to the remote location.
  341. *
  342. * Formal Parameters
  343. * logical_handle - (i) Transport connection number
  344. * user_data - (i) Address of data to send
  345. * user_data_length - (i) Length of data to send
  346. *
  347. * Return Value
  348. * TRANSPORT_NO_ERROR - No Error
  349. * TRANSPORT_NO_SUCH_CONNECTION - Transport connection does not exist
  350. * TRANSPORT_PACKET_TOO_LARGE - Packet is bigger than acceptable
  351. * size
  352. * TRANSPORT_WRITE_QUEUE_FULL - Transport write queues are already
  353. * full.
  354. * TRANSPORT_NOT_READY_TO_TRANSMIT - The transport layer is in the
  355. * process of building or breaking
  356. * down the transport stack and is
  357. * not ready for user data.
  358. *
  359. * Side Effects
  360. * None
  361. *
  362. * Caveats
  363. * The maximum size of a packet is 8192 bytes.
  364. */
  365. /*
  366. * void TransportController::EnableReceiver (void);
  367. *
  368. * Functional Description
  369. * This function is called by the user application to notify us that
  370. * it is ready for more data. We only receive this call if we had
  371. * previously attempted a TRANSPORT_DATA_INDICATION and it was rejected.
  372. *
  373. * Formal Parameters
  374. * None.
  375. *
  376. * Return Value
  377. * None.
  378. *
  379. * Side Effects
  380. * None
  381. *
  382. * Caveats
  383. * None
  384. */
  385. /*
  386. * TransportError TransportController::PurgeRequest (
  387. * LogicalHandle logical_handle)
  388. *
  389. * Functional Description
  390. * This function is used purge outbound packets
  391. *
  392. * Formal Parameters
  393. * logical_handle - (i) Transport connection number
  394. *
  395. * Return Value
  396. * TRANSPORT_NO_ERROR - No Error
  397. * TRANSPORT_NO_SUCH_CONNECTION - Transport connection does not exist
  398. *
  399. * Side Effects
  400. * None
  401. */
  402. /*
  403. * void TransportController::PollReceiver (void);
  404. *
  405. * Functional Description
  406. * This function gives the DLL a chance to take the data received and
  407. * pass it to the user.
  408. *
  409. * Formal Parameters
  410. * None.
  411. *
  412. * Return Value
  413. * None.
  414. *
  415. * Side Effects
  416. * None
  417. *
  418. * Caveats
  419. * None
  420. */
  421. /*
  422. * void TransportController::PollReceiver (
  423. * PhysicalHandle physical_handle)
  424. *
  425. * Functional Description
  426. * This function calls the T123 stack associated with the physical
  427. * handle.
  428. *
  429. * Formal Parameters
  430. * physical_handle (i) - Handle of the T123 stack that we need
  431. * to maintain.
  432. *
  433. * Return Value
  434. * None.
  435. *
  436. * Side Effects
  437. * None
  438. *
  439. * Caveats
  440. * None
  441. */
  442. /*
  443. * void TransportController::PollTransmitter (void);
  444. *
  445. * Functional Description
  446. * This function processes output data to remote locations.
  447. *
  448. * Formal Parameters
  449. * None.
  450. *
  451. * Return Value
  452. * None.
  453. *
  454. * Side Effects
  455. * None
  456. *
  457. * Caveats
  458. * None
  459. */
  460. /*
  461. * void TransportController::PollTransmitter (
  462. * PhysicalHandle physical_handle)
  463. *
  464. * Functional Description
  465. * This function calls the T123 stack associated with the physical
  466. * handle.
  467. *
  468. * Formal Parameters
  469. * physical_handle (i) - Handle of the T123 stack that we need
  470. * to maintain.
  471. *
  472. * Return Value
  473. * None.
  474. *
  475. * Side Effects
  476. * None
  477. *
  478. * Caveats
  479. * None
  480. */
  481. /*
  482. * TransportError TransportController::ProcessCommand (
  483. * USHORT message,
  484. * PVoid input_structure,
  485. * PVoid output_structure)
  486. *
  487. * Functional Description
  488. * This function passes in a command and command-specific parameters.
  489. *
  490. * Formal Parameters
  491. * message - (i) Message to execute
  492. * input_structure - (i) Pointer to data type related to message
  493. * output_structure - (o) Pointer to data type related to message
  494. *
  495. * Return Value
  496. * TRANSPORT_NO_ERROR - No Error
  497. *
  498. * Side Effects
  499. * None
  500. *
  501. * Caveats
  502. * None
  503. */
  504. /*
  505. * TPhysicalError TransportController::PhysicalConnectRequest (
  506. * ULONG connect_type,
  507. * PVoid connect_parameter,
  508. * PVoid physical_configuration,
  509. * PPhysicalHandle physical_handle);
  510. *
  511. * Functional Description
  512. * This function initiates a physical connection.
  513. *
  514. * Formal Parameters
  515. * connect_type - (i) Type of connection to make
  516. * connect_parameter - (i) Pointer to parameter associated with
  517. * connect_type.
  518. * physical_configuration - (i) Pointer to configuration structure.
  519. * physical_handle - (o) Pointer to PhysicalHandle.
  520. *
  521. * Return Value
  522. * TPHYSICAL_NO_ERROR - No error
  523. *
  524. * Side Effects
  525. * None
  526. *
  527. * Caveats
  528. * None
  529. */
  530. /*
  531. * TPhysicalError TransportController::PhysicalListen (
  532. * ULONG listen_type,
  533. * PVoid listen_parameter,
  534. * PVoid physical_configuration,
  535. * PPhysicalHandle physical_handle);
  536. *
  537. * Functional Description
  538. * This function initiates a physical connection listen.
  539. *
  540. * Formal Parameters
  541. * listen_type - (i) Type of connection to make
  542. * listen_parameter - (i) Pointer to parameter associated with
  543. * listen_type.
  544. * physical_configuration - (i) Pointer to configuration structure.
  545. * physical_handle - (o) Pointer to PhysicalHandle.
  546. *
  547. * Return Value
  548. * TPHYSICAL_NO_ERROR - No error
  549. *
  550. * Side Effects
  551. * None
  552. *
  553. * Caveats
  554. * None
  555. */
  556. /*
  557. * TPhysicalError TransportController::PhysicalUnlisten (
  558. * PhysicalHandle physical_handle);
  559. *
  560. * Functional Description
  561. * This function takes a physical connection out of the listen mode.
  562. *
  563. * Formal Parameters
  564. * physical_handle - (i) physical handle
  565. *
  566. * Return Value
  567. * TPHYSICAL_NO_ERROR - No error
  568. *
  569. * Side Effects
  570. * None
  571. *
  572. * Caveats
  573. * None
  574. */
  575. /*
  576. * TPhysicalError TransportController::PhysicalDisconnectRequest (
  577. * PhysicalHandle physical_handle,
  578. * PhysicalDisconnectMode disconnect_mode);
  579. *
  580. * Functional Description
  581. * This function disconnects a physical connection. Depending on the
  582. * disconnect_mode, the port may be released to the user. If the
  583. * mode is TPHYSICAL_NOWAIT, the port is released when the function
  584. * returns. Otherwise, it is released when the
  585. * TPHYSICAL_DISCONNECT_CONFIRM callback is issued.
  586. *
  587. * Formal Parameters
  588. * physical_handle - (i) physical handle
  589. * disconnect_mode - (i) TPHYSICAL_WAIT, if you want to shutdown cleanly.
  590. * TPHYSICAL_NOWAIT, if you want to do a hard
  591. * shutdown of the physical connection.
  592. *
  593. * Return Value
  594. * TPHYSICAL_NO_ERROR - No error
  595. *
  596. * Side Effects
  597. * None
  598. *
  599. * Caveats
  600. * None
  601. */
  602. /*
  603. * ULONG TransportController::OwnerCallback (
  604. * USHORT layer_message,
  605. * ULONG parameter1,
  606. * ULONG parameter2,
  607. * PVoid parameter3);
  608. *
  609. * Functional Description
  610. * This is the owner callback function. This function is called by
  611. * objects that are owned by the TransportController. This is basically
  612. * their way of communicating with the TransportController. When the
  613. * controller calls an object (i.e. PSTNController or a T123 object), it
  614. * can call the owner back with message it wants processed. This is a
  615. * little tricky but it works well.
  616. *
  617. * Formal Parameters
  618. * command_string - (i) String containing the operation to perform. It
  619. * also contains any parameters that are necessary
  620. * for the function.
  621. * parameter1 - (i) Message specific parameter
  622. * parameter2 - (i) Message specific parameter
  623. * parameter3 - (i) Message specific parameter
  624. *
  625. * Return Value
  626. * TRANSPORT_NO_ERROR - No Error
  627. *
  628. * Side Effects
  629. * None
  630. *
  631. * Caveats
  632. * None
  633. */
  634.