Clean (void) casts from usr.sbin
[dragonfly.git] / usr.sbin / dpt / dpt_sig / dpt_sig.c
1 /*
2  *       Copyright (c) 1997 by Simon Shapiro
3  *       All Rights Reserved
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions, and the following disclaimer,
10  *    without modification, immediately at the beginning of the file.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. The name of the author may not be used to endorse or promote products
15  *    derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
21  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * $FreeBSD: src/usr.sbin/dpt/dpt_sig/dpt_sig.c,v 1.3 1999/08/28 01:16:09 peter Exp $
30  * $DragonFly: src/usr.sbin/dpt/dpt_sig/dpt_sig.c,v 1.3 2004/12/18 22:48:03 swildner Exp $
31  */
32
33 /* dpt_sig.c:  Dunp a DPT Signature */
34
35 #include <fcntl.h>
36 #include <stdio.h>
37 #include <string.h>
38 #include <errno.h>
39 #include <sys/time.h>
40 #include <sys/stat.h>
41 #include <sys/queue.h>
42 #include <sys/ioctl.h>
43 #include <scsi/scsi_all.h>
44 #include <scsi/scsi_message.h>
45 #include <scsi/scsiconf.h>
46
47 #define DPT_MEASURE_PERFORMANCE
48
49 #include <sys/dpt.h>
50
51 /* A primitive subset of isgraph.       Used by hex_dump below */
52 #define IsGraph(val)    ( (((val) >= ' ') && ((val) <= '~')) )
53
54 /*
55  * This function dumps bytes to the screen in hex format.
56  */
57 void
58 hex_dump(u_int8_t * data, int length, char *name, int no)
59 {
60     int line, column, ndx;
61         
62     fprintf(stdout, "Kernel Hex Dump for %s-%d at %p (%d bytes)\n",
63             name, no, data, length);
64         
65     /* Zero out all the counters and repeat for as many bytes as we have */
66     for (ndx = 0, column = 0, line = 0; ndx < length; ndx++) {
67                 /* Print relative offset at the beginning of every line */
68                 if (column == 0)
69                         fprintf(stdout, "%04x ", ndx);
70         
71                 /* Print the byte as two hex digits, followed by a space */
72                 fprintf(stdout, "%02x ", data[ndx]);
73         
74                 /* Split the row of 16 bytes in half */
75                 if (++column == 8) {
76                         fprintf(stdout, " ");
77                 }
78                 /* St the end of each row of 16 bytes, put a space ... */
79                 if (column == 16) {
80                         fprintf(stdout, "       ");
81                 
82                         /* ... and then print the ASCII-visible on a line. */
83                         for (column = 0; column < 16; column++) {
84                                 int     ascii_pos = ndx - 15 + column;
85         
86                                 /*
87                                  * Non-printable and non-ASCII are just a
88                                  * dot. ;-(
89                                  */
90                                 if (IsGraph(data[ascii_pos]))
91                                         fprintf(stdout, "%c", data[ascii_pos]);
92                                 else
93                                         fprintf(stdout, ".");
94                         }
95                 
96                         /* Each line ends with a new line */
97                         fprintf(stdout, "\n");
98                         column = 0;
99                 
100                         /*
101                          * Every 256 bytes (16 lines of 16 bytes each) have
102                          * an empty line, separating them from the next
103                          * ``page''. Yes, I programmed on a Z-80, where a
104                          * page was 256 bytes :-)
105                          */
106                         if (++line > 15) {
107                                 fprintf(stdout, "\n");
108                                 line = 0;
109                         }
110                 }
111     }
112         
113     /*
114      * We are basically done. We do want, however, to handle the ASCII
115      * translation of fractional lines.
116      */
117     if ((ndx == length) && (column != 0)) {
118                 int     modulus = 16 - column, spaces = modulus * 3, skip;
119         
120                 /*
121                  * Skip to the right, as many spaces as there are bytes
122                  * ``missing'' ...
123                  */
124                 for (skip = 0; skip < spaces; skip++)
125                         fprintf(stdout, " ");
126         
127                 /* ... And the gap separating the hex dump from the ASCII */
128                 fprintf(stdout, "  ");
129         
130                 /*
131                  * Do not forget the extra space that splits the hex dump
132                  * vertically
133                  */
134                 if (column < 8)
135             fprintf(stdout, " ");
136         
137                 for (column = 0; column < (16 - modulus); column++) {
138                         int     ascii_pos = ndx - (16 - modulus) + column;
139                 
140                         if (IsGraph(data[ascii_pos]))
141                                 fprintf(stdout, "%c", data[ascii_pos]);
142                         else
143                                 fprintf(stdout, ".");
144                 }
145                 fprintf(stdout, "\n");
146     }
147 }
148
149
150 int
151 main(int argc, char **argv, char **argp)
152 {
153     eata_pt_t pass_thru;
154     dpt_sig_t signature;
155     char     *sp1;
156     char     *sp2;
157     
158     int result;
159     int fd;
160     int ndx;
161
162     /* If we do not do that, gcc complains about uninitialized usage (?) */
163     sp1 = "Unknown";
164     sp2 = "Unknown";
165     
166     if ( (fd = open(argv[1], O_RDWR, S_IRUSR | S_IWUSR)) == -1 ) {
167                 fprintf(stderr, "%s ERROR:  Failed to open \"%s\" "
168                         "- %s\n",
169                         argv[0], argv[1], strerror(errno));
170                 exit(1);
171     }
172
173     pass_thru.eataID[0] = 'E';
174     pass_thru.eataID[1] = 'A';
175     pass_thru.eataID[2] = 'T';
176     pass_thru.eataID[3] = 'A';
177     pass_thru.command   = DPT_SIGNATURE;
178     pass_thru.command_buffer = (u_int8_t *)&signature;
179
180     if ( (result = ioctl(fd, DPT_IOCTL_SEND, &pass_thru)) != 0 ) {
181                 fprintf(stderr, "%s ERROR:  Failed to send IOCTL "
182                         "%lx - %s\n",
183                         argv[0], DPT_IOCTL_SEND,
184                         strerror(errno));
185                 exit(1);
186     }
187
188     /* dsSignature is not null terminated! */
189     for (ndx = 0; ndx < sizeof(signature.dsSignature); ndx++)
190                 fputc(signature.dsSignature[ndx], stdout);
191     
192     fprintf(stdout, ":%x:", signature.SigVersion);
193
194     switch (signature.ProcessorFamily) {
195     case PROC_INTEL:
196                 sp1 = "Intel";
197         switch ( signature.Processor ) {
198         case PROC_8086:
199             sp2 = "8086";
200             break;
201         case PROC_286:
202             sp2 = "80286";
203             break;
204         case PROC_386:
205             sp2 = "386";
206             break;
207         case PROC_486:
208             sp2 = "486";
209             break;
210         case PROC_PENTIUM:
211             sp2 = "Pentium";
212             break;
213         case PROC_P6:
214             sp2 = "PentiumPro";
215             break;
216         default:
217             sp2 = "Unknown Processor";
218             break;
219         }
220         break;
221     case PROC_MOTOROLA:
222                 sp1 = "Motorola";
223         switch ( signature.Processor ) {
224         case PROC_68000:
225             sp2 = "68000";
226             break;
227         case PROC_68020:
228             sp2 = "68020";
229             break;
230         case PROC_68030:
231             sp2 = "68030";
232             break;
233         case PROC_68040:
234             sp2 = "68040";
235             break;
236         default:
237             sp2 = "Unknown Processor";
238             break;
239         }
240         break;
241     case PROC_MIPS4000:
242                 sp1 = "MIPS/SGI";
243                 break;
244     case PROC_ALPHA:
245                 sp1 = "DEC Alpha";
246                 break;
247     default:
248                 sp1 = "Unknown Processor Family";
249                 break;
250     }
251     
252     fprintf(stdout, "%s:%s:", sp1, sp2);
253
254     switch ( signature.Filetype ) {
255     case FT_EXECUTABLE:
256                 sp1 = "Executable";
257                 break;
258     case FT_SCRIPT:
259                 sp1 = "Script";
260                 break;
261     case FT_HBADRVR:
262                 sp1 = "HBA Driver";
263                 break;
264     case FT_OTHERDRVR:
265                 sp1 = "Other Driver";
266                 break;
267     case FT_IFS:
268                 sp1 = "Installable FileSystem";
269                 break;
270     case FT_ENGINE:
271                 sp1 = "DPT Engine";
272                 break;
273     case FT_COMPDRVR:
274                 sp1 = "Compressed Driver";
275                 break;
276     case FT_LANGUAGE:
277                 sp1 = "Language File";
278                 break;
279     case FT_FIRMWARE:
280                 sp1 = "DownLoadable Firmware";
281                 break;
282     case FT_COMMMODL:
283                 sp1 = "Communications Module";
284                 break;
285     case FT_INT13:
286                 sp1 = "INT13 Type HBA Driver";
287                 break;
288     case FT_HELPFILE:
289                 sp1 = "Help File";
290                 break;
291     case FT_LOGGER:
292                 sp1 = "Event Logger";
293                 break;
294     case FT_INSTALL:
295                 sp1 = "Installation Procedure";
296                 break;
297     case FT_LIBRARY:
298                 sp1 = "Storage Manager Real-Mode Call";
299                 break;
300     case FT_RESOURCE:
301                 sp1 = "Storage Manager Resource File";
302                 break;
303     case FT_MODEM_DB:
304                 sp1 = "Storage Manager Modem Database";
305                 break;
306     default:
307                 sp1 = "Unknown File Type";
308                 break;
309     }
310     
311     switch ( signature.FiletypeFlags ) {
312     case FTF_DLL:
313                 sp2 = "Dynamically Linked Library";
314                 break;
315     case FTF_NLM:
316                 sp2 = "NetWare Loadable Module";
317                 break;
318     case FTF_OVERLAYS:
319                 sp2 = "Uses Overlays";
320                 break;
321     case FTF_DEBUG:
322                 sp2 = "Debug Version";
323                 break;
324     case FTF_TSR:
325                 sp2 = "DOS Terminate-n-Stay Resident Thing";
326                 break;
327     case FTF_SYS:
328                 sp2 = "DOS Loadable Driver";
329                 break;
330     case FTF_PROTECTED:
331                 sp2 = "Runs in Protected Mode";
332                 break;
333     case FTF_APP_SPEC:
334                 sp2 = "Application Specific";
335                 break;
336     default:
337                 sp2 = "Unknown File Type Flag";
338                 break;
339     }
340     
341     fprintf(stdout, "%s:%s:", sp1, sp2);
342
343     switch ( signature.OEM ) {
344     case OEM_DPT:
345                 sp1 = "DPT";
346                 break;
347     case OEM_ATT:
348                 sp1 = "AT&T";
349                 break;
350     case OEM_NEC:
351                 sp1 = "NEC";
352                 break;
353     case OEM_ALPHA:
354                 sp1 = "Alphatronix";
355                 break;
356     case OEM_AST:
357                 sp1 = "AST";
358                 break;
359     case OEM_OLIVETTI:
360                 sp1 = "Olivetti";
361                 break;
362     case OEM_SNI:
363                 sp1 = "Siemens/Nixdorf";
364                 break;
365     default:
366                 sp1 = "Unknown OEM";
367                 break;
368     }
369    
370     switch ( signature.OS ) {
371     case OS_DOS:
372                 sp2 = "DOS";
373                 break;
374     case OS_WINDOWS:
375                 sp2 = "Microsoft Windows 3.x";
376                 break;
377     case OS_WINDOWS_NT:
378                 sp2 = "Microsoft Windows NT";
379                 break;
380     case OS_OS2M:
381                 sp2 = "OS/2 1.2.x,MS 1.3.0,IBM 1.3.x";
382                 break;
383     case OS_OS2L:
384                 sp2 = "Microsoft OS/2 1.301 - LADDR";
385                 break;
386     case OS_OS22x:
387                 sp2 = "IBM OS/2 2.x";
388                 break;
389     case OS_NW286:
390                 sp2 = "Novell NetWare 286";
391                 break;
392     case OS_NW386:
393                 sp2 = "Novell NetWare 386";
394                 break;
395     case OS_GEN_UNIX:
396                 sp2 = "Generic Unix";
397                 break;
398     case OS_SCO_UNIX:
399                 sp2 = "SCO Unix";
400                 break;
401     case OS_ATT_UNIX:
402                 sp2 = "AT&T Unix";
403                 break;
404     case OS_UNIXWARE:
405                 sp2 = "UnixWare Unix";
406                 break;
407     case OS_INT_UNIX:
408                 sp2 = "Interactive Unix";
409                 break;
410     case OS_SOLARIS:
411                 sp2 = "SunSoft Solaris";
412                 break;
413     case OS_QNX:
414                 sp2 = "QNX for Tom Moch";
415                 break;
416     case OS_NEXTSTEP:
417                 sp2 = "NeXTSTEP";
418                 break;
419     case OS_BANYAN:
420                 sp2 = "Banyan Vines";
421                 break;
422     case OS_OLIVETTI_UNIX:
423                 sp2 = "Olivetti Unix";
424                 break;
425     case OS_FREEBSD:
426                 sp2 = "FreeBSD 2.2 and later";
427                 break;
428     case OS_OTHER:
429                 sp2 = "Other";
430                 break;
431     default:
432                 sp2 = "Unknown O/S";
433                 break;
434     }
435     
436     fprintf(stdout, "%s:%s:\n", sp1, sp2);
437
438     if ( signature.Capabilities & CAP_RAID0 )
439                 fprintf(stdout, "RAID-0:");
440     
441     if ( signature.Capabilities & CAP_RAID1 )
442                 fprintf(stdout, "RAID-1:");
443     
444     if ( signature.Capabilities & CAP_RAID3 )
445                 fprintf(stdout, "RAID-3:");
446     
447     if ( signature.Capabilities & CAP_RAID5 )
448                 fprintf(stdout, "RAID-5:");
449     
450     if ( signature.Capabilities & CAP_SPAN )
451                 fprintf(stdout, "SPAN:");
452     
453     if ( signature.Capabilities & CAP_PASS )
454                 fprintf(stdout, "PASS:");
455     
456     if ( signature.Capabilities & CAP_OVERLAP )
457                 fprintf(stdout, "OVERLAP:");
458     
459     if ( signature.Capabilities & CAP_ASPI )
460                 fprintf(stdout, "ASPI:");
461     
462     if ( signature.Capabilities & CAP_ABOVE16MB )
463                 fprintf(stdout, "ISA16MB:");
464     
465     if ( signature.Capabilities & CAP_EXTEND )
466                 fprintf(stdout, "ISA16MB:");
467
468     fprintf(stdout, "\n");
469
470     if ( signature.DeviceSupp & DEV_DASD )
471                 fprintf(stdout, "DASD:");
472
473     if ( signature.DeviceSupp & DEV_TAPE )
474                 fprintf(stdout, "Tape:");
475
476     if ( signature.DeviceSupp & DEV_PRINTER )
477                 fprintf(stdout, "Printer:");
478
479     if ( signature.DeviceSupp & DEV_PROC )
480                 fprintf(stdout, "CPU:");
481
482     if ( signature.DeviceSupp & DEV_WORM )
483                 fprintf(stdout, "WORM:");
484
485     if ( signature.DeviceSupp & DEV_CDROM )
486                 fprintf(stdout, "CDROM:");
487
488     if ( signature.DeviceSupp & DEV_SCANNER )
489                 fprintf(stdout, "Scanner:");
490
491     if ( signature.DeviceSupp & DEV_OPTICAL )
492                 fprintf(stdout, "Optical:");
493
494     if ( signature.DeviceSupp & DEV_JUKEBOX )
495                 fprintf(stdout, "Jukebox:");
496
497     if ( signature.DeviceSupp & DEV_COMM )
498                 fprintf(stdout, "Comm:");
499
500     if ( signature.DeviceSupp & DEV_OTHER )
501                 fprintf(stdout, "Other:");
502
503     if ( signature.DeviceSupp & DEV_ALL )
504                 fprintf(stdout, "All:");
505
506     fprintf(stdout, "\n");
507
508     if ( signature.AdapterSupp & ADF_2001 )
509                 fprintf(stdout, "PM2001:");
510
511     if ( signature.AdapterSupp & ADF_2012A )
512                 fprintf(stdout, "PM2012A:");
513
514     if ( signature.AdapterSupp & ADF_PLUS_ISA )
515                 fprintf(stdout, "PM2011+PM2021:");
516
517     if ( signature.AdapterSupp & ADF_PLUS_EISA )
518                 fprintf(stdout, "PM2012B+PM2022:");
519
520     if ( signature.AdapterSupp & ADF_SC3_ISA )
521                 fprintf(stdout, "PM2021:");
522
523     if ( signature.AdapterSupp & ADF_SC3_EISA )
524                 fprintf(stdout, "PM2022+PM2122:");
525
526     if ( signature.AdapterSupp & ADF_SC3_PCI )
527                 fprintf(stdout, "SmartCache III PCI:");
528
529     if ( signature.AdapterSupp & ADF_SC4_ISA )
530                 fprintf(stdout, "SmartCache IV ISA:");
531
532     if ( signature.AdapterSupp & ADF_SC4_EISA )
533                 fprintf(stdout, "SmartCache IV EISA:");
534
535     if ( signature.AdapterSupp & ADF_SC4_PCI )
536                 fprintf(stdout, "SmartCache IV PCI:");
537
538     if ( signature.AdapterSupp & ADF_ALL_MASTER )
539                 fprintf(stdout, "All Bus Mastering:");
540
541     if ( signature.AdapterSupp & ADF_ALL_CACHE )
542                 fprintf(stdout, "All Caching:");
543
544     if ( signature.AdapterSupp & ADF_ALL )
545                 fprintf(stdout, "All HBAs:");
546     
547     fprintf(stdout, "\n");
548
549     if ( signature.Application & APP_DPTMGR )
550                 fprintf(stdout, "DPTMGR:");
551     
552     if ( signature.Application & APP_ENGINE )
553                 fprintf(stdout, "Engine:");
554     
555     if ( signature.Application & APP_SYTOS )
556                 fprintf(stdout, "Systron Sytos Plus:");
557     
558     if ( signature.Application & APP_CHEYENNE )
559                 fprintf(stdout, "Cheyenne ARCServe + ARCSolo:");
560     
561     if ( signature.Application & APP_MSCDEX )
562                 fprintf(stdout, "Microsoft CD-ROM extensions:");
563     
564     if ( signature.Application & APP_NOVABACK )
565                 fprintf(stdout, "NovaStor Novaback:");
566     
567     if ( signature.Application & APP_AIM )
568                 fprintf(stdout, "Archive Information Manager:");
569     
570     fprintf(stdout, "\n");
571
572     if ( signature.Requirements & REQ_SMARTROM )
573                 fprintf(stdout, "SmartROM:");
574     
575     if ( signature.Requirements & REQ_DPTDDL )
576                 fprintf(stdout, "DPTDDL.SYS:");
577     
578     if ( signature.Requirements & REQ_HBA_DRIVER )
579                 fprintf(stdout, "HBA Driver:");
580     
581     if ( signature.Requirements & REQ_ASPI_TRAN )
582                 fprintf(stdout, "ASPI Transport Modules:");
583     
584     if ( signature.Requirements & REQ_ENGINE )
585                 fprintf(stdout, "DPT Engine:");
586     
587     if ( signature.Requirements & REQ_COMM_ENG )
588                 fprintf(stdout, "DPT Comm Engine:");
589     
590     fprintf(stdout, "\n");
591     
592     fprintf(stdout, "%x.%x.%x:%d.%d.%d\n",
593             signature.Version, signature.Revision,
594             signature.SubRevision,
595             signature.Month, signature.Day, signature.Year + 1980);
596     
597     return(0);
598 }