home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / include / seclink.h < prev    next >
C/C++ Source or Header  |  1998-04-25  |  15KB  |  291 lines

  1. /* Copyright Data Connection Ltd. 1989 */
  2. /*****************************************************************************/
  3. /* Link Device Driver interface constants and structures.                    */
  4. /*****************************************************************************/
  5. /*****************************************************************************/
  6. /* WIN32  16/04/92  SW   Added more helpful names from WIN32 hdr file        */
  7. /* IHV    03/06/92  MF2  Add semfisui.h                                      */
  8. /* CDDD1  06/04/93  CD   Change TxFrame DevIoctl code                        */
  9. /* STAT1  21/01/94  CD   Fix what we do with stats (& general cleanup)       */
  10. /* MODEM  06/04/95  AB   Add support for the modem status program            */
  11. /*****************************************************************************/
  12.  
  13. /*****************************************************************************/
  14. /* This include file is used in 3 components                                 */
  15. /*                                                                           */
  16. /* - the NT   driver                         LINK_NTDRIVER                   */
  17. /* - the X25  link service for NT            LINK_NTX25                      */
  18. /* - the SDLC link service for NT            LINK_NTSDLC                     */
  19. /*                                                                           */
  20. /* These are distinguished based on #defines as set in the following         */
  21. /*                                                                           */
  22. /*****************************************************************************/
  23.  
  24. #ifdef        IMADRIVER
  25.   #define     LINK_NTDRIVER
  26. #else
  27.   #ifdef      SDLC
  28.     #define LINK_NTSDLC
  29.   #else
  30.     #define LINK_NTX25
  31.   #endif
  32. #endif
  33.  
  34.  
  35. /*****************************************************************************/
  36. /* Device function codes for DosDevIOCtl to link device driver               */
  37. /*****************************************************************************/
  38. #define IoctlCodeSetEvent               0x410
  39. #define IoctlCodeSetLinkChar            0x420
  40. #define IoctlCodeSetV24                 0x430
  41. #define IoctlCodeTxFrame                0x441   /* Main Tx so 1         CDDD1*/
  42. #define IoctlCodeAbortTransmit          0x450
  43. #define IoctlCodeAbortReceiver          0x460
  44. #define IoctlCodeSetInterfaceRecord     0x610   /* Retired                   */
  45. #define IoctlCodeGetV24                 0x623   /* No data buffer so 3       */
  46. #define IoctlCodeRxFrame                0x632   /* Main Rx so 2              */
  47. #define IoctlCodeReadInterfaceRecord    0x642
  48.  
  49. /*****************************************************************************/
  50. /* Constants for the driver-specific IOCtl return codes.                     */
  51. /*****************************************************************************/
  52. #define CEDNODMA 0xff80     /* Warning (NO DMA!) from set link chrctrstcs    */
  53.  
  54. /*****************************************************************************/
  55. /* Equates for the link options byte 1.                                      */
  56. /*****************************************************************************/
  57. #define CEL4WIRE 0x80
  58. #define CELNRZI  0x40
  59. #define CELPDPLX 0x20
  60. #define CELSDPLX 0x10
  61. #define CELCLOCK 0x08
  62. #define CELDSRS  0x04
  63. #define CELSTNBY 0x02
  64. #define CELDMA   0x01
  65.  
  66. /*****************************************************************************/
  67. /* Equates for the driver set link characteristics byte 1.                   */
  68. /*****************************************************************************/
  69. #define CED4WIRE 0x80
  70. #define CEDNRZI  0x40
  71. #define CEDHDLC  0x20
  72. #define CEDFDPLX 0x10
  73. #define CEDCLOCK 0x08
  74. #define CEDDMA   0x04
  75. #define CEDRSTAT 0x02
  76. #define CEDCSTAT 0x01
  77.  
  78. /* Nicer names for NT-style code */
  79.  
  80. #define LinkOption_4Wire           CED4WIRE
  81. #define LinkOption_NRZI            CEDNRZI
  82. #define LinkOption_HDLC            CEDHDLC
  83. #define LinkOption_FullDuplex      CEDFDPLX
  84. #define LinkOption_InternalClock   CEDCLOCK
  85. #define LinkOption_DMA             CEDDMA
  86. #define LinkOption_ResetStatistics CEDRSTAT
  87.  
  88.  
  89. /*****************************************************************************/
  90. /* Equates for the ouput V24 interface flags.                                */
  91. /*****************************************************************************/
  92. #define CED24RTS 0x01
  93. #define CED24DTR 0x02
  94. #define CED24DRS 0x04
  95. #define CED24SLS 0x08
  96. #define CED24TST 0x10
  97.  
  98. /* Nicer names for NT-style code */
  99.  
  100. #define IR_OV24RTS  CED24RTS
  101. #define IR_OV24DTR  CED24DTR
  102. #define IR_OV24DSRS CED24DRS
  103. #define IR_OV24SlSt CED24SLS
  104. #define IR_OV24Test CED24TST
  105.  
  106.  
  107. /*****************************************************************************/
  108. /* Equates for the input V24 interface flags.                                */
  109. /*****************************************************************************/
  110. #define CED24CTS 0x01
  111. #define CED24DSR 0x02
  112. #define CED24DCD 0x04
  113. #define CED24RI  0x08
  114.  
  115. /* Nicer names for NT-style code */
  116.  
  117. #define IR_IV24CTS  CED24CTS
  118. #define IR_IV24DSR  CED24DSR
  119. #define IR_IV24DCD  CED24DCD
  120. #define IR_IV24RI   CED24RI
  121. #define IR_IV24Test 0x10
  122.  
  123.  
  124. /*****************************************************************************/
  125. /* Structure for the device driver interface record.                         */
  126. /*****************************************************************************/
  127.  
  128. #define CEDSTCRC  0         /* Frames received with incorrect CRC            */
  129. #define CEDSTOFL  1         /* Frames received longer than the maximum       */
  130. #define CEDSTUFL  2         /* Frames received less than 4 octets long       */
  131. #define CEDSTSPR  3         /* Frames received ending on a non-octet bndry   */
  132. #define CEDSTABT  4         /* Aborted frames received                       */
  133. #define CEDSTTXU  5         /* Transmitter interrupt underruns               */
  134. #define CEDSTRXO  6         /* Receiver    interrupt overruns                */
  135. #define CEDSTDCD  7         /* DCD (RLSD) lost during frame reception        */
  136. #define CEDSTCTS  8         /* CTS lost while transmitting                   */
  137. #define CEDSTDSR  9         /* DSR drops                                     */
  138. #define CEDSTHDW 10         /* Hardware failures - adapter errors            */
  139.  
  140. #define CEDSTMAX 11
  141.  
  142. #define SA_CRC_Error       CEDSTCRC
  143. #define SA_RxFrameTooBig   CEDSTOFL
  144. #define SA_RxFrameTooShort CEDSTUFL
  145. #define SA_Spare           CEDSTSPR
  146. #define SA_RxAbort         CEDSTABT
  147. #define SA_TxUnderrun      CEDSTTXU
  148. #define SA_RxOverrun       CEDSTRXO
  149. #define SA_DCDDrop         CEDSTDCD
  150. #define SA_CTSDrop         CEDSTCTS
  151. #define SA_DSRDrop         CEDSTDSR
  152. #define SA_HardwareError   CEDSTHDW  /* e.g. CmdBufferFull not set  */
  153.  
  154. #define SA_Max_Stat        CEDSTMAX
  155.  
  156.  
  157. typedef struct         _INTERFACE_RECORD
  158. {
  159.   /***************************************************************************/
  160.   /* Note: we are here trying to mirror the OS/2 layout, complete with       */
  161.   /*       lengths.  However, due to the (justifiable) pickiness of the 32-  */
  162.   /*       bit compiler, all shorts have been changed to 'int's - that way   */
  163.   /*       the results of calculations can be assigned to them without a lot */
  164.   /*       of shenanigans (or typecasting).                                  */
  165.   /***************************************************************************/
  166.   int                   RxFrameCount;   /* incremented after each frame rx'd */
  167.   int                   TxMaxFrSizeNow; /* max available frame size av. now  */
  168.                                         /* (changes after each Tx DevIoctl   */
  169.                                         /* to DD or after Tx completed)      */
  170.   int                   StatusCount;    /* How many status events have been  */
  171.                                         /* triggered.                        */
  172.   UCHAR                 V24In;          /* Last 'getv24i/f' value got        */
  173.   UCHAR                 V24Out;         /* Last 'setv24 outputs' value set   */
  174.  
  175. /*       The values for the indices into the link statistics array of the    */
  176. /*       various types of statistic.                                         */
  177.   int                   StatusArray[SA_Max_Stat];
  178.  
  179. }                       IR,
  180.                      * PIR;
  181.  
  182. /*****************************************************************************/
  183. /* New structure used by the link to acumulate stats                   *STAT1*/
  184. /*****************************************************************************/
  185. typedef struct _STATS
  186. {
  187.   int                   StatusCount;
  188.   int                   StatusArray[SA_Max_Stat];
  189. } STATS;
  190.  
  191.  
  192. /*****************************************************************************/
  193. /* Structure for the set link characteristics parameter block.               */
  194. /*****************************************************************************/
  195.  
  196. typedef struct  _SLPARMS
  197. {
  198.         int     SLFrameSize;            /* max frame size on link - must be  */
  199.                                          /* in range 270 to ?2K-ish          */
  200.         LONG    SLDataRate;             /* not used by us - external clocks  */
  201.         UCHAR   SLOurAddress1;          /* ) e.g C1/FF or 00/00 or 01/03     */
  202.         UCHAR   SLOurAddress2;          /* )                                 */
  203.         UCHAR   SLLinkOptionsByte;      /* see documentation & LinkOption_*  */
  204.         UCHAR   SLSpare1;
  205. }
  206.                 SLPARMS;
  207.  
  208. #ifndef IMADRIVER
  209. /*****************************************************************************/
  210. /* DEVICEIOCTL macros                                                        */
  211. /*****************************************************************************/
  212. /* NT_SUCCESS ripped of from DDK's ntdef.h, which we do not want to include  */
  213. /* for now temporarily (12/5/92)                                             */
  214.  
  215. #define NT_SUCCESS(Status) ((NTSTATUS)(Status) >= 0)
  216.  
  217. #define SETEVENTHANDLE(H)                                                    \
  218.            NtDeviceIoControlFile(seldrvrh,H,NULL,NULL,&IoStatus,             \
  219.                                    IoctlCodeSetEvent,NULL,0L,NULL,0L)
  220.  
  221. #define SETINTERFACERECORD(R)                                                \
  222.            NtDeviceIoControlFile(seldrvrh,NULL,NULL,NULL,&IoStatus,          \
  223.                                    IoctlCodeSetInterfaceRecord,&R,sizeof(R), \
  224.                                    NULL,0L)
  225.  
  226. #define SETV24STATUS                                                         \
  227.            NtDeviceIoControlFile(seldrvrh,NULL,NULL,NULL,&IoStatus,          \
  228.                                    IoctlCodeSetV24,NULL,0L,                  \
  229.                                    &pInterfaceRecord->V24Out,1L);            \
  230.                                                                              \
  231.          if (SavedIROut != (pInterfaceRecord->V24Out & 0x03))                \
  232.          {                                                                   \
  233.            SavedIROut = (pInterfaceRecord->V24Out & 0x03);                   \
  234.            pModemStatus->V24Out = pInterfaceRecord->V24Out;                  \
  235.          }
  236.  
  237. #define GETV24STATUS(rc)                                                     \
  238.          rc |= NtDeviceIoControlFile(seldrvrh,NULL,NULL,NULL,&IoStatus,      \
  239.                                    IoctlCodeGetV24,NULL,0L,NULL,0L);         \
  240.          rc |= READINTERFACERECORD;                                          \
  241.          if (SavedIRIn != (InterfaceRecord.V24In & 0x0F))                    \
  242.          {                                                                   \
  243.            SavedIRIn = (InterfaceRecord.V24In & 0x0F);                       \
  244.            pModemStatus->V24In = InterfaceRecord.V24In;                      \
  245.          }
  246.  
  247.  
  248. /*****************************************************************************/
  249. /* Check for reset stats request and reset if required                 *STAT1*/
  250. /*****************************************************************************/
  251. #define SETLINKCHARACTERISTICS(A,rc)                                         \
  252.            rc = NtDeviceIoControlFile(seldrvrh,NULL,NULL,NULL,&IoStatus,     \
  253.                                   IoctlCodeSetLinkChar,&A,sizeof(A),NULL,0L);\
  254.            if (A.SLLinkOptionsByte & CEDRSTAT)                               \
  255.            {                                                                 \
  256.              memset(&Stats,0,sizeof(STATS));                                 \
  257.            }
  258.  
  259. /*****************************************************************************/
  260. /* Note we now pass the user buffer in the input fields, not the output      */
  261. /* fields                                                               CDDD1*/
  262. /*****************************************************************************/
  263. #define TRANSMITFRAME(A,B)                                                   \
  264.            NtDeviceIoControlFile(seldrvrh,NULL,NULL,NULL,&IoStatus,          \
  265.                                    IoctlCodeTxFrame,A,B,NULL,0L);
  266.  
  267.  
  268. #define RECEIVEFRAME(A,B)                                                    \
  269.            NtDeviceIoControlFile(seldrvrh,NULL,NULL,NULL,&IoStatus,          \
  270.                                    IoctlCodeRxFrame,NULL,0L,A,B);
  271.  
  272. /*****************************************************************************/
  273. /* Due to a problem sharing a structure between the driver and link we're    */
  274. /* going to get the driver to reset it's stats after every call to read the  */
  275. /* interface record, and get the link to accumulate the stats          *STAT1*/
  276. /*****************************************************************************/
  277. #define READINTERFACERECORD                                                  \
  278.            NtDeviceIoControlFile(seldrvrh,NULL,NULL,NULL,&IoStatus,          \
  279.                                    IoctlCodeReadInterfaceRecord,NULL,0L,     \
  280.                                    &InterfaceRecord,sizeof(InterfaceRecord));\
  281.            if (!rc)                                                          \
  282.            {                                                                 \
  283.              int i;                                                          \
  284.              Stats.StatusCount += InterfaceRecord.StatusCount;               \
  285.              for (i=0;i<SA_Max_Stat;i++)                                     \
  286.              {                                                               \
  287.                Stats.StatusArray[i] += InterfaceRecord.StatusArray[i];       \
  288.              }                                                               \
  289.            }
  290. #endif
  291.