1 | /* $Id: VSCSISense.cpp 82968 2020-02-04 10:35:17Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Virtual SCSI driver: Sense handling
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2020 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 | #define LOG_GROUP LOG_GROUP_VSCSI
|
---|
18 | #include <VBox/log.h>
|
---|
19 | #include <iprt/assert.h>
|
---|
20 | #include <iprt/string.h>
|
---|
21 |
|
---|
22 | #include "VSCSIInternal.h"
|
---|
23 |
|
---|
24 | void vscsiSenseInit(PVSCSISENSE pVScsiSense)
|
---|
25 | {
|
---|
26 | memset(pVScsiSense->abSenseBuf, 0, sizeof(pVScsiSense->abSenseBuf));
|
---|
27 |
|
---|
28 | /* Fill in valid sense information (can't be just zeros). */
|
---|
29 | pVScsiSense->abSenseBuf[0] = (1 << 7) | SCSI_SENSE_RESPONSE_CODE_CURR_FIXED; /* Fixed format */
|
---|
30 | pVScsiSense->abSenseBuf[2] = SCSI_SENSE_NONE;
|
---|
31 | pVScsiSense->abSenseBuf[7] = 10;
|
---|
32 | pVScsiSense->abSenseBuf[12] = SCSI_ASC_NONE;
|
---|
33 | }
|
---|
34 |
|
---|
35 | int vscsiReqSenseOkSet(PVSCSISENSE pVScsiSense, PVSCSIREQINT pVScsiReq)
|
---|
36 | {
|
---|
37 | memset(pVScsiSense->abSenseBuf, 0, sizeof(pVScsiSense->abSenseBuf));
|
---|
38 |
|
---|
39 | pVScsiSense->abSenseBuf[0] = (1 << 7) | SCSI_SENSE_RESPONSE_CODE_CURR_FIXED; /* Fixed format */
|
---|
40 | pVScsiSense->abSenseBuf[2] = SCSI_SENSE_NONE;
|
---|
41 | pVScsiSense->abSenseBuf[7] = 10;
|
---|
42 | pVScsiSense->abSenseBuf[12] = SCSI_ASC_NONE;
|
---|
43 | pVScsiSense->abSenseBuf[13] = SCSI_ASC_NONE; /* Should be ASCQ but it has the same value for success. */
|
---|
44 |
|
---|
45 | if (pVScsiReq->pbSense && pVScsiReq->cbSense)
|
---|
46 | {
|
---|
47 | pVScsiReq->cbSenseWritten = RT_MIN(sizeof(pVScsiSense->abSenseBuf), pVScsiReq->cbSense);
|
---|
48 | memcpy(pVScsiReq->pbSense, pVScsiSense->abSenseBuf, pVScsiReq->cbSenseWritten);
|
---|
49 | }
|
---|
50 |
|
---|
51 | return SCSI_STATUS_OK;
|
---|
52 | }
|
---|
53 |
|
---|
54 | int vscsiReqSenseErrorSet(PVSCSISENSE pVScsiSense, PVSCSIREQINT pVScsiReq, uint8_t uSCSISenseKey, uint8_t uSCSIASC, uint8_t uSCSIASCQ)
|
---|
55 | {
|
---|
56 | memset(pVScsiSense->abSenseBuf, 0, sizeof(pVScsiSense->abSenseBuf));
|
---|
57 | pVScsiSense->abSenseBuf[0] = (1 << 7) | SCSI_SENSE_RESPONSE_CODE_CURR_FIXED; /* Fixed format */
|
---|
58 | pVScsiSense->abSenseBuf[2] = uSCSISenseKey;
|
---|
59 | pVScsiSense->abSenseBuf[7] = 10;
|
---|
60 | pVScsiSense->abSenseBuf[12] = uSCSIASC;
|
---|
61 | pVScsiSense->abSenseBuf[13] = uSCSIASCQ;
|
---|
62 |
|
---|
63 | if (pVScsiReq->pbSense && pVScsiReq->cbSense)
|
---|
64 | {
|
---|
65 | pVScsiReq->cbSenseWritten = RT_MIN(sizeof(pVScsiSense->abSenseBuf), pVScsiReq->cbSense);
|
---|
66 | memcpy(pVScsiReq->pbSense, pVScsiSense->abSenseBuf, pVScsiReq->cbSenseWritten);
|
---|
67 | }
|
---|
68 |
|
---|
69 | return SCSI_STATUS_CHECK_CONDITION;
|
---|
70 | }
|
---|
71 |
|
---|
72 | int vscsiReqSenseErrorInfoSet(PVSCSISENSE pVScsiSense, PVSCSIREQINT pVScsiReq, uint8_t uSCSISenseKey, uint8_t uSCSIASC, uint8_t uSCSIASCQ, uint32_t uInfo)
|
---|
73 | {
|
---|
74 | memset(pVScsiSense->abSenseBuf, 0, sizeof(pVScsiSense->abSenseBuf));
|
---|
75 | pVScsiSense->abSenseBuf[0] = RT_BIT(7) | SCSI_SENSE_RESPONSE_CODE_CURR_FIXED; /* Fixed format */
|
---|
76 | pVScsiSense->abSenseBuf[2] = uSCSISenseKey;
|
---|
77 | scsiH2BE_U32(&pVScsiSense->abSenseBuf[3], uInfo);
|
---|
78 | pVScsiSense->abSenseBuf[7] = 10;
|
---|
79 | pVScsiSense->abSenseBuf[12] = uSCSIASC;
|
---|
80 | pVScsiSense->abSenseBuf[13] = uSCSIASCQ;
|
---|
81 |
|
---|
82 | if (pVScsiReq->pbSense && pVScsiReq->cbSense)
|
---|
83 | {
|
---|
84 | pVScsiReq->cbSenseWritten = RT_MIN(sizeof(pVScsiSense->abSenseBuf), pVScsiReq->cbSense);
|
---|
85 | memcpy(pVScsiReq->pbSense, pVScsiSense->abSenseBuf, pVScsiReq->cbSenseWritten);
|
---|
86 | }
|
---|
87 |
|
---|
88 | return SCSI_STATUS_CHECK_CONDITION;
|
---|
89 | }
|
---|
90 |
|
---|
91 | int vscsiReqSenseCmd(PVSCSISENSE pVScsiSense, PVSCSIREQINT pVScsiReq)
|
---|
92 | {
|
---|
93 | /* Copy the current sense data to the buffer. */
|
---|
94 | RTSgBufCopyFromBuf(&pVScsiReq->SgBuf, pVScsiSense->abSenseBuf, sizeof(pVScsiSense->abSenseBuf));
|
---|
95 | return vscsiReqSenseOkSet(pVScsiSense, pVScsiReq);
|
---|
96 | }
|
---|
97 |
|
---|