-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged in mode_sense (pull request #6)
add mode sense scsi command.
- Loading branch information
Showing
9 changed files
with
144 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
import static net.alphadev.usbstorage.util.BitStitching.convertToInt; | ||
|
||
/** | ||
* | ||
* @author Jan Seeger <[email protected]> | ||
*/ | ||
public class CommandStatusWrapper { | ||
|
40 changes: 40 additions & 0 deletions
40
lib/src/main/java/net/alphadev/usbstorage/scsi/answer/ModeSenseResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package net.alphadev.usbstorage.scsi.answer; | ||
|
||
import java.util.BitSet; | ||
|
||
/** | ||
* @author Jan Seeger <[email protected]> | ||
*/ | ||
public class ModeSenseResponse { | ||
public static final int LENGTH = 8; | ||
|
||
private byte mModeDataLength; | ||
private MediumType mMediumType; | ||
private byte mDeviceSpecificParameter; | ||
private byte mBlockDescriptorLength; | ||
private boolean mWriteProtection; | ||
private boolean mDPOFUA; | ||
|
||
public ModeSenseResponse(byte[] answer) { | ||
mModeDataLength = answer[0]; | ||
mMediumType = determineMediumType(answer[1]); | ||
|
||
BitSet bs = new BitSet(answer[2]); | ||
mWriteProtection = bs.get(7); | ||
mDPOFUA = bs.get(4); | ||
|
||
mBlockDescriptorLength = answer[3]; | ||
} | ||
|
||
private MediumType determineMediumType(byte typeField) { | ||
switch (typeField) { | ||
case 00: | ||
return MediumType.SCB_DEVICE; | ||
} | ||
return null; | ||
} | ||
|
||
public static enum MediumType { | ||
SCB_DEVICE | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
lib/src/main/java/net/alphadev/usbstorage/scsi/command/ModeSense.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package net.alphadev.usbstorage.scsi.command; | ||
|
||
/** | ||
* @author Jan Seeger <[email protected]> | ||
*/ | ||
@SuppressWarnings("unused") | ||
public class ModeSense extends ScsiCommand { | ||
public static final byte MODE_SENSE = 0x1a; | ||
/** | ||
* DBD (disable block descriptors) bit | ||
* Ifset to zero specifies that the device server may return zero or more block descriptors in the returned MODE SENSE data. | ||
* A DBD bit set to one specifies that the device server shall not return any block descriptors in the returned MODE SENSE data, | ||
*/ | ||
private boolean mDisableBlockDescriptor; | ||
private byte mPageCode; | ||
private byte mSubPageCode; | ||
private PageControlValues mPageControl; | ||
|
||
public ModeSense() { | ||
super(MODE_SENSE); | ||
} | ||
|
||
@Override | ||
public byte[] asBytes() { | ||
byte[] retval = new byte[6]; | ||
retval[0] = MODE_SENSE; // opcode | ||
retval[1] = (byte) (mDisableBlockDescriptor ? 1 : 0); // DBD bit | ||
retval[2] = getPageField(); | ||
retval[3] = mSubPageCode; | ||
retval[4] = (byte) 192; | ||
// 5 == control bit | ||
return retval; | ||
} | ||
|
||
private byte getPageField() { | ||
byte retval = 0; | ||
|
||
switch (mPageControl) { | ||
case Changeable: | ||
retval = 64; | ||
break; | ||
case Default: | ||
retval = (byte) 128; | ||
break; | ||
case Saved: | ||
retval = (byte) 192; | ||
break; | ||
} | ||
|
||
return (byte) (retval + mPageCode); | ||
} | ||
|
||
@Override | ||
public int getExpectedAnswerLength() { | ||
return 0; | ||
} | ||
|
||
public void setDisableBlockDescriptor(boolean value) { | ||
this.mDisableBlockDescriptor = value; | ||
} | ||
|
||
public void setPageCode(byte pageCode) { | ||
this.mPageCode = pageCode; | ||
} | ||
|
||
public void setSubPageCode(byte subPageCode) { | ||
this.mSubPageCode = subPageCode; | ||
} | ||
|
||
public void setPageControl(PageControlValues pageControl) { | ||
this.mPageControl = pageControl; | ||
} | ||
|
||
public static enum PageControlValues { | ||
Current, | ||
Changeable, | ||
Default, | ||
Saved | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
package net.alphadev.usbstorage.scsi.command; | ||
|
||
import net.alphadev.usbstorage.bbb.CommandBlockWrapper; | ||
|
||
/** | ||
* @author Jan Seeger <[email protected]> | ||
*/ | ||
|
@@ -12,11 +10,6 @@ public TestUnitReady() { | |
super(TEST_UNIT_READY); | ||
} | ||
|
||
@Override | ||
public CommandBlockWrapper.Direction getDirection() { | ||
return CommandBlockWrapper.Direction.DEVICE_TO_HOST; | ||
} | ||
|
||
@Override | ||
public byte[] asBytes() { | ||
// all zero since even opcode == 0x0 | ||
|