#include #include #include #include #include #include #include #include "myscsi.h" #include "myfunc.h" /* Program Version */ char *P_Ver="1.01 Alpha\0"; typedef unsigned char BYTE; typedef unsigned short WORD; typedef unsigned int DWORD; typedef int HANDLE; typedef int BOOL; #define TRUE 1 #define FALSE 0 /* COMMAND CDBLEN CDB-------------------------------------------------------------------*/ BYTE Inquiry[7] = {0x06, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00}; BYTE ModeSense[7] = {0x06, 0x1A, 0x00, 0x3E, 0x00, 0x00, 0x00}; BYTE RAIDSensePage1[13] = {0x0C, 0xDA, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; BYTE RAIDSensePage2[13] = {0x0C, 0xDA, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; int main(int argc, char **argv) { HANDLE hDev; int i, loop, n; caddr_t CDB; caddr_t Buffer; BYTE HostID; BYTE TargetID; BYTE Func; BYTE Length; BYTE Get_Length; BYTE Device_Name[32]; if(argc < 4) { fprintf(stdout,"usage: %s HostID TargetID Function\n", argv[0]); return (-1); } HostID = (BYTE)atoi(argv[1]); TargetID = (BYTE)atoi(argv[2]); Func = (BYTE)atoi(argv[3]); /* create target device name */ sprintf(Device_Name,"/dev/rdsk/c%dt%dd0s2\0", (0x00ff & HostID), (0x00ff & TargetID)); if((Buffer = (caddr_t)malloc(256)) == NULL) { fprintf(stderr, "Can't Allocalte Memory\n"); exit(-1); } /* open device */ if((hDev = open(Device_Name, O_RDWR)) == -1) { fprintf(stderr,"Can not open device %s!!\n", Device_Name); return(-1); } switch(Func){ case 0: CDB = Inquiry; Length = 32L; Get_Length = FALSE; break; case 1: CDB = ModeSense; Length = 1L; Get_Length = TRUE; break; case 2: CDB = RAIDSensePage1; //Length = 1L; Length = 255L; Get_Length = FALSE; //Get_Length = TRUE; break; case 3: CDB = RAIDSensePage2; //Length = 1L; Length = 255L; Get_Length = FALSE; //Get_Length = TRUE; break; } if(Get_Length == TRUE) loop = 1; else loop = 0; for( i = 0; i <= loop; i++) { switch(*CDB){ case 0x06: (CDB+1)[4] = (BYTE)(0x000000FF & Length); break; case 0x0C: (CDB+1)[8] = (BYTE)((0x0000FF00 & Length)>> 8); (CDB+1)[9] = (BYTE)(0x000000FF & Length); break; } if( do_scsi_cmd(hDev, (CDB+1), (int)*CDB, Buffer, Length, USCSI_READ|USCSI_SYNC|USCSI_RQENABLE) != 0) { return(-1); } if(Get_Length == TRUE) Length = *Buffer+(BYTE)1; } fprintf(stdout,"00 "); Length = *Buffer+(BYTE)1; for( i = 0; i < Length; i++){ fprintf(stdout,"%02X ", (0x00FF & Buffer[i])); } return(0); } int do_scsi_cmd(fd, cdb, cdb_len, buf, buf_len, flags) int fd; caddr_t cdb; int cdb_len; caddr_t buf; int buf_len; int flags; { struct uscsi_cmd scsi_cmd; char rqbuff[0x24]; /* set cdb to uscsi_command */ scsi_cmd.uscsi_cdb = cdb; scsi_cmd.uscsi_cdblen = cdb_len; scsi_cmd.uscsi_bufaddr = buf; scsi_cmd.uscsi_buflen = buf_len; scsi_cmd.uscsi_status = 0; scsi_cmd.uscsi_flags = flags; scsi_cmd.uscsi_rqbuf = rqbuff; scsi_cmd.uscsi_rqlen = 0x24; scsi_cmd.uscsi_timeout = 0x7fff; if(ioctl(fd, USCSICMD, scsi_cmd) == -1) { switch(errno) { case EBADF: /*fildes is not a valid open file descriptor.*/ printf("FE"); break; case EINTR: /*A signal was caught during the ioctl() function.*/ printf("FD"); break; case ENOTTY: /*fildes is not associated with a device driver */ /*that accepts control functions.*/ printf("FC"); case EFAULT: /*request requires a data transfer to or from a buffer */ /*pointed to by arg, but arg points to an illegal address.*/ printf("FB"); break; case EINVAL: /*request or arg is not valid for this device.*/ printf("FA"); break; case EIO: /*Some physical I/O error has occurred.*/ printf("F9"); break; case ENOLINK: /* fildes is on a remote machine */ /*and the link to that machine is no longer active.\n");*/ printf("F8"); break; case ENXIO: /* The request and arg are valid for this device driver,*/ /* but the service requested can not be performed on this particular subdevice.;*/ printf("F7"); break; default:/*Unknown Error*/ printf("FF"); break; } return(-1); } if( scsi_cmd.uscsi_status != STATUS_GOOD) { printf("04 "); printf("%02X %02X %02X", (rqbuff[2] & 0x000f), (0x00ff & rqbuff[12]), (0x00ff & rqbuff[13])); } return(0); }