home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / drivers / scsi / futrdomn / samples / oemsmple.c < prev    next >
Encoding:
Text File  |  1990-08-18  |  6.5 KB  |  256 lines

  1. /***************************************************************************/
  2.     SAMPLE ROUTINES TO ACCESS THE OEM TOOLKIT
  3.         Note: This is a sample program which gives you a general idea
  4.                 on how to use the OEM Toolkit.  This program is not
  5.                 meant to be compiled but may be modified to create
  6.                 a working program with little effort.
  7. /***************************************************************************/
  8.  
  9. #include <stdio.h>
  10. #include <dos.h>
  11. #include <string.h>
  12. #include <ctype.h>
  13. #include <malloc.h>
  14.  
  15. #define PASS 0
  16. #define FAIL 1
  17. #define ESC 0x1B
  18. #define CMDS_LENGTH 10        /* length of command block */
  19.  
  20.     /* structure passed to the oem toolkit */
  21.     struct oemtable
  22.       {
  23.       unsigned char (far *cmdblock)[];
  24.       unsigned char (far *datablock)[];
  25.       long expectlen;
  26.       long actuallen;
  27.       int timeout;
  28.       int blkfactora;
  29.       int blkfactorb;
  30.       unsigned char scsistatus;
  31.       unsigned char scsimsg;
  32.       unsigned char scsibits;
  33.       unsigned char scsiaddress;
  34.       unsigned char scsiparity;
  35.       int adaptererr;
  36.       } ;
  37.  
  38.    struct oemtable oem ;
  39.    struct SREGS segregs ;
  40.  
  41.    unsigned char *scsi_buf;   /* character pointer to data buffer */
  42.    int *scsi_bufw;            /* integer pointer to data buffer */
  43.  
  44.    unsigned char cmds[CMDS_LENGTH]; /* command block */
  45.  
  46.  
  47. /***************************************************************************
  48.  
  49.     (IssueCommand) - This routine issues the command block to the
  50.                           specified scsi device.
  51.  
  52.     Arguments: expected transfer length (long value)
  53.                   timeout in seconds (int value)
  54.                     
  55.     Returns:   0 - completed succesfully
  56.                1 - adapter or device error
  57.  
  58. ****************************************************************************/
  59. int IssueCommand (long explen, int timeout)
  60. {
  61.    int ierr, prm_stat = FAIL;
  62.  
  63.    union
  64.       {
  65.       unsigned char (far *point)[];
  66.       unsigned char *ptnear;
  67.       long longval;
  68.       int intval[2];
  69.       unsigned char ch [4];
  70.       } cnvtr ;
  71.  
  72.    /* set block factor to 512 for read & writes */
  73.    if (cmds[0] == 0x08 || cmds[0] == 0x0a)
  74.       {
  75.       oem.blkfactora = 512;
  76.       oem.blkfactorb = 512;
  77.       }
  78.    else
  79.       {
  80.       oem.blkfactora = 1;
  81.       oem.blkfactorb = 1;
  82.       }
  83.    
  84.    segread (&segregs);         /* get the system registers */
  85.    cnvtr.intval[1] = segregs.ds;
  86.    cnvtr.ptnear = &cmds[0];
  87.    oem.cmdblock = cnvtr.point; /* set pointer to command block */
  88.    cnvtr.ptnear = &scsi_buf[0];
  89.    oem.datablock = cnvtr.point;/* set pointer to transfer buffer */
  90.    oem.expectlen = explen;     /* set expected length */
  91.  
  92.     /* issue command to device - call to oem toolkit */
  93.     ierr = oemscsi (&oem);
  94.    
  95.    oem.scsistatus &= ~drive_lun; /* remove lun bits from status byte */
  96.  
  97.    /* do not display error message for buffer overflow or underflow */
  98.    if (oem.adaptererr == 2 && oem.scsistatus != 2)
  99.       ierr = oem.adaptererr = 0;
  100.  
  101.    if ( ierr == -2 )
  102.       return (FAIL);    /* do not reset bus on selection timeout */
  103.    if ( ierr < 0 )
  104.       oemclear (adpt_nbr); /* must reset bus if timeout in any other phase */
  105.  
  106.     if ( (ierr == 0) && (oem.scsistatus == 0) )
  107.       return (PASS);
  108.    else
  109.       return (FAIL);
  110. }
  111.  
  112. void GetInquiry (void)
  113. {
  114.    cmds[0] = 0x12;            /* inquiry command */
  115.    cmds[4] = 0x24;            /* inquiry length */
  116.  
  117.    if (IssueCommand (0x24l, 2, 1))
  118.       {
  119.       ShowResult ("GET INQUIRY", "ERROR");
  120.       return ;
  121.       }
  122.  
  123.    ShowInquiry ();            /* display inquiry information window */
  124. }
  125.  
  126. void ShowInquiry (void)
  127. {
  128.    char si_idn [25];                /* store product indentification */
  129.     char si_rev [5];                /* store product revision level */
  130.  
  131.    char pq, dt, rmb, ansi_ver;
  132.    int i, j, si_dmy;
  133.  
  134.     /* get product identification */
  135.    strncpy (si_idn, &scsi_buf[8], 24);
  136.     si_idn[24] = NULL;              /* make sure we have a null at the end */
  137.     printf ("Product Identification: %s\n", si_idn);
  138.     
  139.     /* get product revision level */
  140.     strncpy (si_rev, &scsi_buf[32], 4);
  141.     si_rev[4] = NULL;                /* make sure we have a null at the end */
  142.     printf ("Product revision level: %s\n", si_rev);
  143.     
  144.    rmb = scsi_buf[1]&0x80;
  145.    if (rmb)
  146.         printf ("Physical medium removable\n");
  147.    else
  148.         printf ("Physical medium fixed/not removable\n");
  149. }
  150.  
  151. void ReadCapacity (void)
  152. {
  153.    union
  154.       {
  155.       unsigned char byteval[4];
  156.       int integerval[2];
  157.       long intlongval;
  158.       } number;
  159.    
  160.    long drivecap, blklength;
  161.  
  162.    cmds[0] = 0x25;                /* read capacity command */
  163.  
  164.    if (IssueCommand (8l, 6, 1))
  165.       {
  166.       ShowResult ("DISPLAY CAPACITY", "ERROR");
  167.       return ;
  168.       }
  169.  
  170.    number.byteval[0] = scsi_buf[3];
  171.    number.byteval[1] = scsi_buf[2];
  172.    number.byteval[2] = scsi_buf[1];
  173.    number.byteval[3] = scsi_buf[0];
  174.    if (number.intlongval)
  175.       drivecap=number.intlongval+1;
  176.    else
  177.       drivecap = 0l;
  178.    number.byteval[0] = scsi_buf[0];
  179.    number.byteval[1] = scsi_buf[6];
  180.    blklength=number.integerval[0];
  181.  
  182.     printf ("Number of sectors: %ld\n", drivecap);
  183.     printf ("Block length: %ld\n", blklength);
  184.     printf ("Drive capacity: %ld\n", drivecap*blklength);
  185.  
  186. }
  187.  
  188. void RequestSense (void)
  189. {
  190.    unsigned char cc;
  191.    int i;
  192.  
  193.    cmds[0] = 0x03;                /* request sense command */
  194.    cmds[4] = 16;              /* transfer length */
  195.  
  196.    if (IssueCommand (16l, 2, 1))
  197.       {
  198.       ShowResult ("REQUEST SENSE", "ERROR");
  199.       return ;
  200.       }
  201.  
  202.     /* display resense sense bytes */
  203.    for (i=0;i<16;i++)
  204.       printf ("Byte %2i->%02X",i, scsi_buf[i]&0xff);
  205. }
  206.  
  207. void RezRewUnit (void)
  208. {
  209.    int rru_timeout;
  210.    
  211.    cmds[0] = 0x01;
  212.    if (IssueCommand (0x05l, rru_timeout, 1))
  213.       {
  214.       ShowResult ("REZERO/REWIND", "ERROR");
  215.       return ;
  216.       }
  217.    
  218.    ShowResult ("REZERO/REWIND", "Command Completed Succesfully");
  219. }
  220.  
  221. void TestUnitRdy (void)
  222. {
  223.    cmds[0] = 0x00;
  224.  
  225.    if (IssueCommand (0x05l, 30, 1))
  226.       {
  227.       ShowResult ("TEST UNIT READY", "ERROR");
  228.       return ;
  229.       }
  230.  
  231.    ShowResult ("TEST UNIT READY", "Drive is Ready");
  232. }
  233.  
  234. void RezRewUnit (void)
  235. {
  236.    int rru_timeout;
  237.    
  238.    cmds[0] = 0x01;
  239.    if (IssueCommand (0x05l, rru_timeout, 1))
  240.       {
  241.       ShowResult ("REZERO/REWIND", "ERROR");
  242.       return ;
  243.       }
  244.    
  245.    ShowResult ("REZERO/REWIND", "Command Completed Succesfully");
  246. }
  247.  
  248. void ResetBus (void)
  249. {
  250.    oemclear (adpt_nbr);       /* reset the scsi bus */
  251.    ShowStatus ();             /* clear the status window */
  252.  
  253.    ShowResult ("RESET SCSI BUS",  "SCSI Bus has been reset");
  254. }
  255. 
  256.