home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / sys / hp / 8343 < prev    next >
Encoding:
Internet Message Format  |  1992-07-21  |  3.2 KB

  1. From: rdg@hpfcso.FC.HP.COM (Rob Gardner)
  2. Date: Tue, 21 Jul 1992 18:58:57 GMT
  3. Subject: Re: Writing a non-disc SCSI device driver for HP 700 (Snake)
  4. Message-ID: <7371158@hpfcso.FC.HP.COM>
  5. Organization: Hewlett-Packard, Fort Collins, CO, USA
  6. Path: sparky!uunet!europa.asd.contel.com!darwin.sura.net!mips!sdd.hp.com!hpscdc!cupnews0.cup.hp.com!hppad.waterloo.hp.com!hppad!hpfcso!rdg
  7. Newsgroups: comp.sys.hp
  8. References: <1992Jul21.141340.1615@sni.ca>
  9. Lines: 113
  10.  
  11.  
  12. > Can anyone out there point to to information that would allow me
  13. > to write a non-disc SCSI driver (printers, scanners in particular)
  14. > for HP-UX on a Snake?  I have checked all the documentation we have
  15. > for our 710 and can't find anything other than dire warnings against
  16. > using unsupported equipment.
  17.  
  18. In many cases, you can communicate with your device adequately using
  19. scsi ioctl's. These allow you to send raw scsi commands to a target
  20. without (much) interference from the disk driver. At the risk of
  21. reducing my job security (;-) I am posting an example program that
  22. you should be able to use to talk to your printer/scanner/whatever.
  23.  
  24. > Is there a Device Driver manual somewhere that I have missed?
  25.  
  26. No. There will undoubtedly be some responses to your message telling
  27. you about the HPUX Driver Development Guide, but you should ignore
  28. them. The DDG contains absotively no information on SCSI!
  29.  
  30. Rob
  31.  
  32. /*
  33.  * Example SCSI ioctl program
  34.  *
  35.  * Use scsi disk driver (major 47)
  36.  *
  37.  */
  38.  
  39. /*
  40.  *  This program is the creation of Rob Gardner, and is not for
  41.  *  sale, trade, or barter. It may not be copied for any reason.
  42.  *  It may not even be examined, and as a matter of fact, it is
  43.  *  forbidden for human eyes to see this program. You are probably
  44.  *  violating this decree right now. This program is probably the
  45.  *  property of Hewlett-Packard, since they own me and everything
  46.  *  I have ever done. May the Source be with you.
  47.  */
  48.  
  49.  
  50. #include <sys/types.h>
  51. #include <sys/scsi.h>
  52. #include <fcntl.h>
  53. #include <stdio.h>
  54.  
  55. struct scsi_cmd_parms scsi_inquiry = {
  56.     6, 1, 5000,
  57.     0x12, 0x00, 0x00, 0x00, 0xff, 0x00
  58. };
  59.  
  60. main(argc, argv)
  61. int argc;
  62. char *argv[];
  63. {
  64.     int eid, flag = 1, ret;
  65.     unsigned char buffer[256];
  66.  
  67.     if (argc < 2) 
  68.     {
  69.     fprintf(stderr, "usage: %s device\n", argv[0]);
  70.     exit(1);
  71.     }
  72.     
  73.     eid = open(argv[1], O_RDWR | O_NDELAY);
  74.     if (eid < 0) 
  75.     {
  76.     perror("open");
  77.     exit(2);
  78.     }
  79.  
  80.     printf("-->Opened Succesfully eid = %d\n",eid);    
  81.  
  82.     ret = ioctl(eid, SIOC_CMD_MODE, &flag); 
  83.     if (ret < 0) 
  84.     {
  85.     perror("setting command mode");
  86.     exit(3);
  87.     }
  88.     
  89.     ioctl(eid, SIOC_SET_CMD, &scsi_inquiry);
  90.     
  91.     ret = read(eid, buffer, 256);
  92.     if (ret < 0) 
  93.     {
  94.     perror("inquiry");
  95.     printf("ret = %d\n", ret);
  96.     do_sense(eid);
  97.     }
  98.     else 
  99.     {
  100.     struct inquiry *i = (struct inquiry *) buffer;
  101.     printf("%s\n", i->vendor_id);
  102.     }
  103.     close(eid);
  104. }
  105.  
  106.  
  107. do_sense(eid)
  108. int eid;
  109. {
  110.     char buffer[256];
  111.     int ret;
  112.     union sense_data *foo = (union sense_data *) buffer;
  113.  
  114.     if (ioctl(eid, SIOC_XSENSE, buffer) < 0) {
  115.     perror("request sense");
  116.     printf("ret = %d\n", ret);
  117.     return;
  118.     }
  119.     printf("*error code = %d\n", buffer[0] & 0xf);
  120.     printf("*sense key = %d\n", buffer[2] & 0xf);
  121.     printf("*additional sense byte = 0x%x\n", buffer[8]);
  122.     exit(42);
  123. }
  124.