From df3f195dcb8d32ac0e8efc31e540d454dac601a2 Mon Sep 17 00:00:00 2001
From: dpgilbert <dpgilbert@4ea69e1a-61f1-4043-bf83-b5c94c648137>
Date: Fri, 30 Apr 2004 06:15:49 +0000
Subject: [PATCH] more sanity checks before declaring SCSI transport type

git-svn-id: https://smartmontools.svn.sourceforge.net/svnroot/smartmontools/trunk@1694 4ea69e1a-61f1-4043-bf83-b5c94c648137
---
 sm5/scsicmds.c   | 13 ++++++++-----
 sm5/scsicmds.cpp | 13 ++++++++-----
 2 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/sm5/scsicmds.c b/sm5/scsicmds.c
index 5a50776e7..73166b313 100644
--- a/sm5/scsicmds.c
+++ b/sm5/scsicmds.c
@@ -47,7 +47,7 @@
 #include "scsicmds.h"
 #include "utility.h"
 
-const char *scsicmds_c_cvsid="$Id: scsicmds.c,v 1.74 2004/03/23 13:08:40 ballen4705 Exp $"
+const char *scsicmds_c_cvsid="$Id: scsicmds.c,v 1.75 2004/04/30 06:15:49 dpgilbert Exp $"
 CONFIG_H_CVSID EXTERN_H_CVSID INT64_H_CVSID SCSICMDS_H_CVSID UTILITY_H_CVSID;
 
 /* for passing global control variables */
@@ -305,7 +305,7 @@ int scsiLogSense(int device, int pagenum, UINT8 *pBuf, int bufLen,
 /* Send MODE SENSE (6 byte) command. Returns 0 if ok, 1 if NOT READY,
  * 2 if command not supported (then MODE SENSE(10) should be supported),
  * 3 if field in command not supported or returns negated errno. 
- * SPC sections 7.9 and 8.4 */
+ * SPC sections 7.9 and 8.4 [mode subpage==0] */
 int scsiModeSense(int device, int pagenum, int pc, UINT8 *pBuf, int bufLen)
 {
     struct scsi_cmnd_io io_hdr;
@@ -395,7 +395,7 @@ int scsiModeSelect(int device, int sp, UINT8 *pBuf, int bufLen)
 /* MODE SENSE (10 byte). Returns 0 if ok, 1 if NOT READY, 2 if command 
  * not supported (then MODE SENSE(6) might be supported), 3 if field in
  * command not supported or returns negated errno.  
- * SPC sections 7.10 and 8.4 */
+ * SPC sections 7.10 and 8.4 [mode subpage==0] */
 int scsiModeSense10(int device, int pagenum, int pc, UINT8 *pBuf, int bufLen)
 {
     struct scsi_cmnd_io io_hdr;
@@ -1914,8 +1914,11 @@ int scsiFetchTransportProtocol(int device, int modese_len)
             return -EINVAL;
     } 
     offset = scsiModePageOffset(buff, sizeof(buff), modese_len);
-    if ((offset >= 0) && (buff[offset + 1] > 1))
-        return (buff[offset + 2] & 0xf);
+    if ((offset >= 0) && (buff[offset + 1] > 1)) {
+        if ((0 == (buff[offset] & 0x40)) &&       /* SPF==0 */
+            (PROTOCOL_SPECIFIC_PORT_PAGE == (buff[offset] & 0x3f))) 
+                return (buff[offset + 2] & 0xf);
+    }
     return -EINVAL;
 }
 
diff --git a/sm5/scsicmds.cpp b/sm5/scsicmds.cpp
index 2aabc1cc6..bcc29226d 100644
--- a/sm5/scsicmds.cpp
+++ b/sm5/scsicmds.cpp
@@ -47,7 +47,7 @@
 #include "scsicmds.h"
 #include "utility.h"
 
-const char *scsicmds_c_cvsid="$Id: scsicmds.cpp,v 1.74 2004/03/23 13:08:40 ballen4705 Exp $"
+const char *scsicmds_c_cvsid="$Id: scsicmds.cpp,v 1.75 2004/04/30 06:15:49 dpgilbert Exp $"
 CONFIG_H_CVSID EXTERN_H_CVSID INT64_H_CVSID SCSICMDS_H_CVSID UTILITY_H_CVSID;
 
 /* for passing global control variables */
@@ -305,7 +305,7 @@ int scsiLogSense(int device, int pagenum, UINT8 *pBuf, int bufLen,
 /* Send MODE SENSE (6 byte) command. Returns 0 if ok, 1 if NOT READY,
  * 2 if command not supported (then MODE SENSE(10) should be supported),
  * 3 if field in command not supported or returns negated errno. 
- * SPC sections 7.9 and 8.4 */
+ * SPC sections 7.9 and 8.4 [mode subpage==0] */
 int scsiModeSense(int device, int pagenum, int pc, UINT8 *pBuf, int bufLen)
 {
     struct scsi_cmnd_io io_hdr;
@@ -395,7 +395,7 @@ int scsiModeSelect(int device, int sp, UINT8 *pBuf, int bufLen)
 /* MODE SENSE (10 byte). Returns 0 if ok, 1 if NOT READY, 2 if command 
  * not supported (then MODE SENSE(6) might be supported), 3 if field in
  * command not supported or returns negated errno.  
- * SPC sections 7.10 and 8.4 */
+ * SPC sections 7.10 and 8.4 [mode subpage==0] */
 int scsiModeSense10(int device, int pagenum, int pc, UINT8 *pBuf, int bufLen)
 {
     struct scsi_cmnd_io io_hdr;
@@ -1914,8 +1914,11 @@ int scsiFetchTransportProtocol(int device, int modese_len)
             return -EINVAL;
     } 
     offset = scsiModePageOffset(buff, sizeof(buff), modese_len);
-    if ((offset >= 0) && (buff[offset + 1] > 1))
-        return (buff[offset + 2] & 0xf);
+    if ((offset >= 0) && (buff[offset + 1] > 1)) {
+        if ((0 == (buff[offset] & 0x40)) &&       /* SPF==0 */
+            (PROTOCOL_SPECIFIC_PORT_PAGE == (buff[offset] & 0x3f))) 
+                return (buff[offset + 2] & 0xf);
+    }
     return -EINVAL;
 }
 
-- 
GitLab