home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_02_05 / 2n05032a < prev    next >
Text File  |  1991-03-27  |  3KB  |  159 lines

  1. /*
  2.  *  File:    IOCTL.C
  3.  *  Purpose:    Contains device driver IOCTL
  4.  *        command function handlers
  5.  */
  6.  
  7. #include    "device.h"
  8.  
  9. /*  External Data  */
  10. extern    WORD    DevHeader;
  11.  
  12. /*  External Functions  */
  13. int NetAddname (char *name);
  14. int NetDelname (char *name);
  15. int NetCall (char *local, char *remote, BYTE *session);
  16. int NetSend (FPTR buf, int size, BYTE session);
  17. int NetReceive (FPTR buf, int size, BYTE session);
  18. WORD UnknownCommand (FPTR rh);
  19.  
  20.  
  21. /*  Global Data  */
  22. BYTE    localSession = 0;
  23. char    clientName[] = "CDROM_CLIENT";
  24. char    serverName[] = "CDROM_SERVER";
  25. int    dtaInSize[] = { 5, 6, 1, 1,
  26.             9, 130, 5, 4,
  27.             5, 2, 7, 7,
  28.             11, 13, 11, 11 };
  29. int    dtaOutSize[] = { 1, 2, 1, 9, 130, 1 };
  30.  
  31.  
  32. /*
  33.  * IOProcess : General IOCTL (Input/Output) handler
  34.  *   Sends request header to ther server
  35.  *   for processing, followed by the DTA.  
  36.  *   First Receive is for the request
  37.  *   header coming back with status and
  38.  *   any other data.  If all ok second Receive
  39.  *   is for the DTA stuff.
  40.  */
  41.  
  42. WORD IOProcess (RH_IO far *rh, int dta_size)
  43. {
  44.     int    ret;
  45.  
  46.     /**  Are we connected?  **/
  47.     if (!localSession)
  48.         return DEV_ERROR | DEV_EGEN | DEV_DONE;
  49.     
  50.     /**  Send request header and DTA  **/
  51.     ret = NetSend (rh, rh->rh.length, localSession);
  52.     if (!ret)
  53.         ret = NetSend (rh->dta, dta_size,
  54.                    localSession);
  55.  
  56.     /**  Wait for RH to come back  **/
  57.     if (!ret)
  58.         ret = NetReceive (rh, rh->rh.length,
  59.                   localSession);
  60.  
  61.     /**  If good, get dta also  **/
  62.     if (!ret) {
  63.         if (rh->rh.status != 0x100)
  64.             /**  Error on server  **/
  65.             return rh->rh.status;
  66.  
  67.         ret = NetReceive (rh->dta, dta_size,
  68.                   localSession);
  69.     }
  70.  
  71.     if (ret)
  72.         /**  An error occurred somewhere  **/
  73.         return DEV_ERROR|DEV_DONE|DEV_EREAD;
  74.     else
  75.         return DEV_DONE;
  76. }
  77.  
  78. /*
  79.  * IOInput0 : Return Device Header Address
  80.  *   Establishes communications with the CDROM
  81.  *   server and returns the device header address
  82.  *   in the data transfer area.
  83.  *   DTA format is :
  84.  *         BYTE  cmd;
  85.  *         FPTR  address;
  86.  */
  87.  
  88. WORD IOInput0 (RH_IO far *rh)
  89. {
  90.     struct {
  91.         BYTE    cmd;
  92.         FPTR    addr;
  93.     } far *dta;
  94.  
  95.     /**  Attach to server  **/
  96.     if (NetAddname (clientName) ||
  97.         NetCall (clientName, serverName, 
  98.              &localSession)) {
  99.  
  100.         /**  Error making connection  **/
  101.         NetDelname (clientName);
  102.         return DEV_DONE | DEV_ERROR | DEV_EGEN;
  103.     }
  104.  
  105.     /**  Setup device header address  **/
  106.     dta = rh->dta;
  107.     dta->addr = (void far *) &DevHeader;
  108.  
  109.     return DEV_DONE;
  110. }
  111.  
  112. /* 
  113.  * IOInput : IOCTL INPUT function handler
  114.  *   Dispatches desired request to proper
  115.  *   IO-In function handler
  116.  */
  117.  
  118.  
  119. WORD IOInput (RH_IO far *rh)
  120. {
  121.     BYTE    io_cmd;
  122.  
  123.     /* first byte of dta buffer has
  124.        sub-command code */
  125.     io_cmd = *((char far *) (rh->dta));
  126.  
  127.     if (io_cmd == 0)
  128.         return IOInput0 (rh);
  129.     else if (io_cmd == 1 ||
  130.          io_cmd > 2 && io_cmd < 16)
  131.         return IOProcess (rh, dtaInSize[io_cmd]);
  132.     else
  133.         return UnknownCommand (rh);
  134.  
  135. }
  136.  
  137.  
  138. /* 
  139.  * IOOutput : IOCTL OUTPUT function handler
  140.  *   Dispatches desired request to proper
  141.  *   IO-In function handler
  142.  */
  143.  
  144.  
  145. WORD IOOutput (RH_IO far *rh)
  146. {
  147.     BYTE    io_cmd;
  148.  
  149.     /* first byte of dta buffer has
  150.        sub-command code */
  151.     io_cmd = *((char far *) (rh->dta));
  152.  
  153.     if (io_cmd < 6)
  154.         return IOProcess (rh, dtaOutSize[io_cmd]);
  155.     else
  156.         return UnknownCommand (rh);
  157.  
  158. }
  159.