sg_pt_common.c (sdparm-1.11.tgz) | : | sg_pt_common.c (sdparm-1.12.tgz) | ||
---|---|---|---|---|
/* | /* | |||
* Copyright (c) 2009-2019 Douglas Gilbert. | * Copyright (c) 2009-2020 Douglas Gilbert. | |||
* All rights reserved. | * All rights reserved. | |||
* Use of this source code is governed by a BSD-style | * Use of this source code is governed by a BSD-style | |||
* license that can be found in the BSD_LICENSE file. | * license that can be found in the BSD_LICENSE file. | |||
* | * | |||
* SPDX-License-Identifier: BSD-2-Clause | * SPDX-License-Identifier: BSD-2-Clause | |||
*/ | */ | |||
#include <stdio.h> | #include <stdio.h> | |||
#include <stdlib.h> | #include <stdlib.h> | |||
#include <stdarg.h> | #include <stdarg.h> | |||
skipping to change at line 33 | skipping to change at line 33 | |||
#include "sg_lib.h" | #include "sg_lib.h" | |||
#include "sg_pt.h" | #include "sg_pt.h" | |||
#include "sg_unaligned.h" | #include "sg_unaligned.h" | |||
#include "sg_pr2serr.h" | #include "sg_pr2serr.h" | |||
#include "sg_pr2serr.h" | #include "sg_pr2serr.h" | |||
#if (HAVE_NVME && (! IGNORE_NVME)) | #if (HAVE_NVME && (! IGNORE_NVME)) | |||
#include "sg_pt_nvme.h" | #include "sg_pt_nvme.h" | |||
#endif | #endif | |||
static const char * scsi_pt_version_str = "3.12 20190612"; | static const char * scsi_pt_version_str = "3.16 20200722"; | |||
const char * | const char * | |||
scsi_pt_version() | scsi_pt_version() | |||
{ | { | |||
return scsi_pt_version_str; | return scsi_pt_version_str; | |||
} | } | |||
const char * | const char * | |||
sg_pt_version() | sg_pt_version() | |||
{ | { | |||
skipping to change at line 71 | skipping to change at line 71 | |||
/* Table of SCSI operation code (opcodes) supported by SNTL */ | /* Table of SCSI operation code (opcodes) supported by SNTL */ | |||
static struct sg_opcode_info_t sg_opcode_info_arr[] = | static struct sg_opcode_info_t sg_opcode_info_arr[] = | |||
{ | { | |||
{0x0, 0, 0, {6, /* TEST UNIT READY */ | {0x0, 0, 0, {6, /* TEST UNIT READY */ | |||
0, 0, 0, 0, 0xc7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, | 0, 0, 0, 0, 0xc7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, | |||
{0x3, 0, 0, {6, /* REQUEST SENSE */ | {0x3, 0, 0, {6, /* REQUEST SENSE */ | |||
0xe1, 0, 0, 0xff, 0xc7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, | 0xe1, 0, 0, 0xff, 0xc7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, | |||
{0x12, 0, 0, {6, /* INQUIRY */ | {0x12, 0, 0, {6, /* INQUIRY */ | |||
0xe3, 0xff, 0xff, 0xff, 0xc7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, | 0xe3, 0xff, 0xff, 0xff, 0xc7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, | |||
{0x1b, 0, 0, {6, /* START STOP UNIT */ | ||||
0x1, 0, 0xf, 0xf7, 0xc7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, | ||||
{0x1c, 0, 0, {6, /* RECEIVE DIAGNOSTIC RESULTS */ | {0x1c, 0, 0, {6, /* RECEIVE DIAGNOSTIC RESULTS */ | |||
0x1, 0xff, 0xff, 0xff, 0xc7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, | 0x1, 0xff, 0xff, 0xff, 0xc7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, | |||
{0x1d, 0, 0, {6, /* SEND DIAGNOSTIC */ | {0x1d, 0, 0, {6, /* SEND DIAGNOSTIC */ | |||
0xf7, 0x0, 0xff, 0xff, 0xc7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, | 0xf7, 0x0, 0xff, 0xff, 0xc7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, | |||
{0x25, 0, 0, {10, /* READ CAPACITY(10) */ | ||||
0x1, 0xff, 0xff, 0xff, 0xff, 0, 0, 0x1, 0xc7, 0, 0, 0, 0, 0, 0} }, | ||||
{0x28, 0, 0, {10, /* READ(10) */ | ||||
0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xc7, 0, 0, 0, 0, | ||||
0, 0} }, | ||||
{0x2a, 0, 0, {10, /* WRITE(10) */ | ||||
0xfb, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xc7, 0, 0, 0, 0, | ||||
0, 0} }, | ||||
{0x2f, 0, 0, {10, /* VERIFY(10) */ | ||||
0xf6, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xc7, 0, 0, 0, 0, | ||||
0, 0} }, | ||||
{0x35, 0, 0, {10, /* SYNCHRONIZE CACHE(10) */ | ||||
0x7, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xc7, 0, 0, 0, 0, | ||||
0, 0} }, | ||||
{0x41, 0, 0, {10, /* WRITE SAME(10) */ | ||||
0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xc7, 0, 0, 0, 0, | ||||
0, 0} }, | ||||
{0x55, 0, 0, {10, /* MODE SELECT(10) */ | {0x55, 0, 0, {10, /* MODE SELECT(10) */ | |||
0x13, 0x0, 0x0, 0x0, 0x0, 0x0, 0xff, 0xff, 0xc7, 0, 0, 0, 0, 0, 0} }, | 0x13, 0x0, 0x0, 0x0, 0x0, 0x0, 0xff, 0xff, 0xc7, 0, 0, 0, 0, 0, 0} }, | |||
{0x5a, 0, 0, {10, /* MODE SENSE(10) */ | {0x5a, 0, 0, {10, /* MODE SENSE(10) */ | |||
0x18, 0xff, 0xff, 0x0, 0x0, 0x0, 0xff, 0xff, 0xc7, 0, 0, 0, 0, 0, 0} }, | 0x18, 0xff, 0xff, 0x0, 0x0, 0x0, 0xff, 0xff, 0xc7, 0, 0, 0, 0, 0, 0} }, | |||
{0x88, 0, 0, {16, /* READ(16) */ | ||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||||
0xff, 0xff, 0xff, 0xc7} }, | ||||
{0x8a, 0, 0, {16, /* WRITE(16) */ | ||||
0xfb, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||||
0xff, 0xff, 0xff, 0xc7} }, | ||||
{0x8f, 0, 0, {16, /* VERIFY(16) */ | ||||
0xf6, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||||
0xff, 0xff, 0x3f, 0xc7} }, | ||||
{0x91, 0, 0, {16, /* SYNCHRONIZE CACHE(16) */ | ||||
0x7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||||
0xff, 0xff, 0x3f, 0xc7} }, | ||||
{0x93, 0, 0, {16, /* WRITE SAME(16) */ | ||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||||
0xff, 0xff, 0x3f, 0xc7} }, | ||||
{0x9e, 0x10, F_SA_LOW, {16, /* READ CAPACITY(16) [service action in] */ | ||||
0x10, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||||
0xff, 0xff, 0x1, 0xc7} }, | ||||
{0xa0, 0, 0, {12, /* REPORT LUNS */ | {0xa0, 0, 0, {12, /* REPORT LUNS */ | |||
0xe3, 0xff, 0, 0, 0, 0xff, 0xff, 0xff, 0xff, 0, 0xc7, 0, 0, 0, 0} }, | 0xe3, 0xff, 0, 0, 0, 0xff, 0xff, 0xff, 0xff, 0, 0xc7, 0, 0, 0, 0} }, | |||
{0xa3, 0xc, F_SA_LOW, {12, /* REPORT SUPPORTED OPERATION CODES */ | {0xa3, 0xc, F_SA_LOW, {12, /* REPORT SUPPORTED OPERATION CODES */ | |||
0xc, 0x87, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0, 0xc7, 0, 0, 0, | 0xc, 0x87, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0, 0xc7, 0, 0, 0, | |||
0} }, | 0} }, | |||
{0xa3, 0xd, F_SA_LOW, {12, /* REPORT SUPPORTED TASK MAN. FUNCTIONS */ | {0xa3, 0xd, F_SA_LOW, {12, /* REPORT SUPPORTED TASK MAN. FUNCTIONS */ | |||
0xd, 0x80, 0, 0, 0, 0xff, 0xff, 0xff, 0xff, 0, 0xc7, 0, 0, 0, 0} }, | 0xd, 0x80, 0, 0, 0, 0xff, 0xff, 0xff, 0xff, 0, 0xc7, 0, 0, 0, 0} }, | |||
{0xff, 0xffff, 0xffff, {0, /* Sentinel, keep as last element */ | {0xff, 0xffff, 0xffff, {0, /* Sentinel, keep as last element */ | |||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, | |||
skipping to change at line 217 | skipping to change at line 254 | |||
{ | { | |||
uint8_t disconnect_pg[] = {0x2, 0xe, 128, 128, 0, 10, 0, 0, | uint8_t disconnect_pg[] = {0x2, 0xe, 128, 128, 0, 10, 0, 0, | |||
0, 0, 0, 0, 0, 0, 0, 0}; | 0, 0, 0, 0, 0, 0, 0, 0}; | |||
memcpy(p, disconnect_pg, sizeof(disconnect_pg)); | memcpy(p, disconnect_pg, sizeof(disconnect_pg)); | |||
if (1 == pcontrol) | if (1 == pcontrol) | |||
memset(p + 2, 0, sizeof(disconnect_pg) - 2); | memset(p + 2, 0, sizeof(disconnect_pg) - 2); | |||
return sizeof(disconnect_pg); | return sizeof(disconnect_pg); | |||
} | } | |||
static uint8_t caching_m_pg[] = {0x8, 18, 0x14, 0, 0xff, 0xff, 0, 0, | ||||
0xff, 0xff, 0xff, 0xff, 0x80, 0x14, 0, 0, | ||||
0, 0, 0, 0}; | ||||
/* Control mode page (SBC) for mode_sense */ | ||||
static int | ||||
resp_caching_m_pg(unsigned char *p, int pcontrol, bool wce) | ||||
{ /* Caching page for mode_sense */ | ||||
uint8_t ch_caching_m_pg[] = {/* 0x8, 18, */ 0x4, 0, 0, 0, 0, 0, | ||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; | ||||
uint8_t d_caching_m_pg[] = {0x8, 18, 0x14, 0, 0xff, 0xff, 0, 0, | ||||
0xff, 0xff, 0xff, 0xff, 0x80, 0x14, 0, 0, 0, 0, 0, 0}; | ||||
// if (SDEBUG_OPT_N_WCE & sdebug_opts) | ||||
caching_m_pg[2] &= ~0x4; /* set WCE=0 (default WCE=1) */ | ||||
if ((0 == pcontrol) || (3 == pcontrol)) { | ||||
if (wce) | ||||
caching_m_pg[2] |= 0x4; | ||||
else | ||||
caching_m_pg[2] &= ~0x4; | ||||
} | ||||
memcpy(p, caching_m_pg, sizeof(caching_m_pg)); | ||||
if (1 == pcontrol) { | ||||
if (wce) | ||||
ch_caching_m_pg[2] |= 0x4; | ||||
else | ||||
ch_caching_m_pg[2] &= ~0x4; | ||||
memcpy(p + 2, ch_caching_m_pg, sizeof(ch_caching_m_pg)); | ||||
} | ||||
else if (2 == pcontrol) { | ||||
if (wce) | ||||
d_caching_m_pg[2] |= 0x4; | ||||
else | ||||
d_caching_m_pg[2] &= ~0x4; | ||||
memcpy(p, d_caching_m_pg, sizeof(d_caching_m_pg)); | ||||
} | ||||
return sizeof(caching_m_pg); | ||||
} | ||||
static uint8_t ctrl_m_pg[] = {0xa, 10, 2, 0, 0, 0, 0, 0, | static uint8_t ctrl_m_pg[] = {0xa, 10, 2, 0, 0, 0, 0, 0, | |||
0, 0, 0x2, 0x4b}; | 0, 0, 0x2, 0x4b}; | |||
/* Control mode page for mode_sense */ | /* Control mode page for mode_sense */ | |||
static int | static int | |||
resp_ctrl_m_pg(uint8_t *p, int pcontrol) | resp_ctrl_m_pg(uint8_t *p, int pcontrol) | |||
{ | { | |||
uint8_t ch_ctrl_m_pg[] = {/* 0xa, 10, */ 0x6, 0, 0, 0, 0, 0, | uint8_t ch_ctrl_m_pg[] = {/* 0xa, 10, */ 0x6, 0, 0, 0, 0, 0, | |||
0, 0, 0, 0}; | 0, 0, 0, 0}; | |||
uint8_t d_ctrl_m_pg[] = {0xa, 10, 2, 0, 0, 0, 0, 0, | uint8_t d_ctrl_m_pg[] = {0xa, 10, 2, 0, 0, 0, 0, 0, | |||
skipping to change at line 333 | skipping to change at line 409 | |||
uint8_t dev_spec; | uint8_t dev_spec; | |||
uint8_t * ap; | uint8_t * ap; | |||
uint8_t arr[SDEBUG_MAX_MSENSE_SZ]; | uint8_t arr[SDEBUG_MAX_MSENSE_SZ]; | |||
memset(resp, 0, sizeof(*resp)); | memset(resp, 0, sizeof(*resp)); | |||
dbd = !! (cdbp[1] & 0x8); /* disable block descriptors */ | dbd = !! (cdbp[1] & 0x8); /* disable block descriptors */ | |||
pcontrol = (cdbp[2] & 0xc0) >> 6; | pcontrol = (cdbp[2] & 0xc0) >> 6; | |||
pcode = cdbp[2] & 0x3f; | pcode = cdbp[2] & 0x3f; | |||
subpcode = cdbp[3]; | subpcode = cdbp[3]; | |||
llbaa = !!(cdbp[1] & 0x10); | llbaa = !!(cdbp[1] & 0x10); | |||
is_disk = (dsp->pdt == PDT_DISK); | is_disk = ((dsp->pdt == PDT_DISK) || (dsp->pdt == PDT_ZBC)); | |||
if (is_disk && !dbd) | if (is_disk && !dbd) | |||
bd_len = llbaa ? 16 : 8; | bd_len = llbaa ? 16 : 8; | |||
else | else | |||
bd_len = 0; | bd_len = 0; | |||
alloc_len = sg_get_unaligned_be16(cdbp + 7); | alloc_len = sg_get_unaligned_be16(cdbp + 7); | |||
memset(arr, 0, SDEBUG_MAX_MSENSE_SZ); | memset(arr, 0, SDEBUG_MAX_MSENSE_SZ); | |||
if (0x3 == pcontrol) { /* Saving values not supported */ | if (0x3 == pcontrol) { /* Saving values not supported */ | |||
resp->asc = SAVING_PARAMS_UNSUP; | resp->asc = SAVING_PARAMS_UNSUP; | |||
goto err_out; | goto err_out; | |||
} | } | |||
skipping to change at line 379 | skipping to change at line 455 | |||
switch (pcode) { | switch (pcode) { | |||
case 0x2: /* Disconnect-Reconnect page, all devices */ | case 0x2: /* Disconnect-Reconnect page, all devices */ | |||
if (0x0 == subpcode) | if (0x0 == subpcode) | |||
len = resp_disconnect_pg(ap, pcontrol); | len = resp_disconnect_pg(ap, pcontrol); | |||
else { | else { | |||
len = 0; | len = 0; | |||
bad_pcode = true; | bad_pcode = true; | |||
} | } | |||
offset += len; | offset += len; | |||
break; | break; | |||
case 0x8: /* Caching Mode page, disk (like) devices */ | ||||
if (! is_disk) { | ||||
len = 0; | ||||
bad_pcode = true; | ||||
} else if (0x0 == subpcode) | ||||
len = resp_caching_m_pg(ap, pcontrol, dsp->wce); | ||||
else { | ||||
len = 0; | ||||
bad_pcode = true; | ||||
} | ||||
offset += len; | ||||
break; | ||||
case 0xa: /* Control Mode page, all devices */ | case 0xa: /* Control Mode page, all devices */ | |||
if (0x0 == subpcode) | if (0x0 == subpcode) | |||
len = resp_ctrl_m_pg(ap, pcontrol); | len = resp_ctrl_m_pg(ap, pcontrol); | |||
else if (0x1 == subpcode) | else if (0x1 == subpcode) | |||
len = resp_ctrl_ext_m_pg(ap, pcontrol); | len = resp_ctrl_ext_m_pg(ap, pcontrol); | |||
else { | else { | |||
len = 0; | len = 0; | |||
bad_pcode = true; | bad_pcode = true; | |||
} | } | |||
offset += len; | offset += len; | |||
skipping to change at line 403 | skipping to change at line 491 | |||
else { | else { | |||
len = 0; | len = 0; | |||
bad_pcode = true; | bad_pcode = true; | |||
} | } | |||
offset += len; | offset += len; | |||
break; | break; | |||
case 0x3f: /* Read all Mode pages */ | case 0x3f: /* Read all Mode pages */ | |||
if ((0 == subpcode) || (0xff == subpcode)) { | if ((0 == subpcode) || (0xff == subpcode)) { | |||
len = 0; | len = 0; | |||
len = resp_disconnect_pg(ap + len, pcontrol); | len = resp_disconnect_pg(ap + len, pcontrol); | |||
if (is_disk) | ||||
len += resp_caching_m_pg(ap + len, pcontrol, dsp->wce); | ||||
len += resp_ctrl_m_pg(ap + len, pcontrol); | len += resp_ctrl_m_pg(ap + len, pcontrol); | |||
if (0xff == subpcode) | if (0xff == subpcode) | |||
len += resp_ctrl_ext_m_pg(ap + len, pcontrol); | len += resp_ctrl_ext_m_pg(ap + len, pcontrol); | |||
len += resp_iec_m_pg(ap + len, pcontrol); | len += resp_iec_m_pg(ap + len, pcontrol); | |||
len += resp_vs_ua_m_pg(ap + len, pcontrol); | len += resp_vs_ua_m_pg(ap + len, pcontrol); | |||
offset += len; | offset += len; | |||
} else { | } else { | |||
resp->asc = INVALID_FIELD_IN_CDB; | resp->asc = INVALID_FIELD_IN_CDB; | |||
resp->in_byte = 3; | resp->in_byte = 3; | |||
resp->in_bit = 255; | resp->in_bit = 255; | |||
skipping to change at line 502 | skipping to change at line 592 | |||
} | } | |||
spf = !!(arr[off] & 0x40); | spf = !!(arr[off] & 0x40); | |||
pg_len = spf ? (sg_get_unaligned_be16(arr + off + 2) + 4) : | pg_len = spf ? (sg_get_unaligned_be16(arr + off + 2) + 4) : | |||
(arr[off + 1] + 2); | (arr[off + 1] + 2); | |||
sub_mpage = spf ? arr[off + 1] : 0; | sub_mpage = spf ? arr[off + 1] : 0; | |||
if ((pg_len + off) > param_len) { | if ((pg_len + off) > param_len) { | |||
resp->asc = PARAMETER_LIST_LENGTH_ERR; | resp->asc = PARAMETER_LIST_LENGTH_ERR; | |||
goto err_out; | goto err_out; | |||
} | } | |||
switch (mpage) { | switch (mpage) { | |||
case 0x8: /* Caching Mode page */ | ||||
if (0x0 == sub_mpage) { | ||||
if (caching_m_pg[1] == arr[off + 1]) { | ||||
memcpy(caching_m_pg + 2, arr + off + 2, | ||||
sizeof(caching_m_pg) - 2); | ||||
dsp->wce = !!(caching_m_pg[2] & 0x4); | ||||
dsp->wce_changed = true; | ||||
break; | ||||
} | ||||
} | ||||
goto def_case; | ||||
case 0xa: /* Control Mode page */ | case 0xa: /* Control Mode page */ | |||
if (0x0 == sub_mpage) { | if (0x0 == sub_mpage) { | |||
if (ctrl_m_pg[1] == arr[off + 1]) { | if (ctrl_m_pg[1] == arr[off + 1]) { | |||
memcpy(ctrl_m_pg + 2, arr + off + 2, | memcpy(ctrl_m_pg + 2, arr + off + 2, | |||
sizeof(ctrl_m_pg) - 2); | sizeof(ctrl_m_pg) - 2); | |||
dsp->scsi_dsense = !!(ctrl_m_pg[2] & 0x4); | dsp->scsi_dsense = !!(ctrl_m_pg[2] & 0x4); | |||
break; | break; | |||
} | } | |||
} | } | |||
goto def_case; | goto def_case; | |||
End of changes. 10 change blocks. | ||||
3 lines changed or deleted | 104 lines changed or added |