-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathInquireUsb.cpp
More file actions
173 lines (130 loc) · 3.79 KB
/
Copy pathInquireUsb.cpp
File metadata and controls
173 lines (130 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include "StdAfx.h"
#include "scsi_struct.h"
#include "InquireUsb.h"
//ON_BN_CLICKED(IDC_BTN_REFRESH, OnBtnRefresh)
//ON_CBN_SELCHANGE(IDC_DRIVES_COMBO, OnSelchangeDrivesCombo)
/////////////////////////////////////////////////////////////////////////////
// CMyregionDlg message handlers
//BOOL CMyregionDlg::OnInitDialog()
//{
// CDialog::OnInitDialog();
//
// // Set the icon for this dialog. The framework does this automatically
// // when the application's main window is not a dialog
// SetIcon(m_hIcon, TRUE); // Set big icon
// SetIcon(m_hIcon, FALSE); // Set small icon
//
// PopulateDrivesList();
//
// UpdateDeviceInfos();
//
// return TRUE; // return TRUE unless you set the focus to a control
//}
//void CMyregionDlg::OnBtnRefresh()
//{
// PopulateDrivesList();
//}
bool carry_cdb(HANDLE device, void *cdb, UCHAR cdb_length, void *buffer, DWORD buffer_length, int data_in = SCSI_IOCTL_DATA_IN)
{
DWORD returned;
// size of SCSI_PASS_THROUGH + 96 bytes for sense data
unsigned char cmd[sizeof(SCSI_PASS_THROUGH_DIRECT) + 96] = {0};
// shortcut to the buffer
SCSI_PASS_THROUGH_DIRECT *pcmd = (SCSI_PASS_THROUGH_DIRECT *)cmd;
// Copy the CDB to the SCSI_PASS_THROUGH structure
memcpy(pcmd->Cdb, cdb, cdb_length);
pcmd->Length = sizeof(SCSI_PASS_THROUGH_DIRECT);
//pcmd->CdbLength = cdb_length;
pcmd->CdbLength = sizeof(pcmd->Cdb);//0x10;
pcmd->TargetId = 0x01;
pcmd->SenseInfoLength = sizeof(cmd) - sizeof(SCSI_PASS_THROUGH_DIRECT);
pcmd->DataIn = data_in;
pcmd->DataTransferLength = buffer_length;
//pcmd->TimeOutValue = 6000;
pcmd->TimeOutValue = 0x258;
pcmd->DataBuffer = buffer;
pcmd->SenseInfoOffset = sizeof(SCSI_PASS_THROUGH_DIRECT);
/// CMD
pcmd->Cdb[0] = 0xfe;
pcmd->Cdb[1] = 0x6f;
pcmd->Cdb[2] = 0x01;
TRACE("sizeof(cmd):%d\n", sizeof(cmd));
BOOL bRet = DeviceIoControl(
device,
IOCTL_SCSI_PASS_THROUGH_DIRECT,
(LPVOID)&cmd,
sizeof(cmd),
(LPVOID)&cmd,
sizeof(cmd),
&returned,
NULL);
#ifdef _DEBUG
DWORD err = ::GetLastError();
if(err != ERROR_SUCCESS)
{
printf("carry_cdb(): last error = %08X\n", err);
}
#endif
return bRet ? true : false;
}
bool UpdateDeviceInfos()
{
char devname[20];
HANDLE device;
//sprintf(devname, "\\\\.\\%c:", m_cbDrives.GetItemData(m_cbDrives.GetCurSel()) + 'A');
device = ::CreateFile(/*devname,*/
"\\\\?\\USBSTOR#Disk&Ven_NISEC&Prod_TCG-01&Rev_5.00#7&2dca610a&0#{53f56307-b6bf-11d0-94f2-00a0c91efb8b}",
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
0);
CString strInquiry = "Could not retrieve Inquiry information!";
CString strRegion = "Could not retrieve region info!";
//m_edtInquiry.SetWindowText(strInquiry);
//m_edtRegion.SetWindowText(strRegion);
if(device == INVALID_HANDLE_VALUE)
{
AfxMessageBox("Cannot access the drive!");
return false;
}
// Get Inquiry information
do
{
CDB_INQUIRY6 inquiry = {0};
SCSI_INQUIRY_STD_DATA data = {0};
//inquiry.AllocationLength = sizeof(data);
inquiry.OperationCode6 = SCSIOP_INQUIRY;
if(!carry_cdb(device, &inquiry, sizeof(inquiry), &data, sizeof(data)))
{
break;
}
strInquiry = "";
CString s;
/*
char snip[100] = {0};
int i;
strncpy(snip, data.vendor_id, i = sizeof(data.vendor_id));
snip[i] = 0;
s.Format("Vendor id: %s\r\n", snip);
strInquiry += s;
strncpy(snip, data.product_id , i = sizeof(data.product_id));
snip[i] = 0;
s.Format("Product id: %s\r\n", snip);
strInquiry += s;
strncpy(snip, data.product_revision_level , i = sizeof(data.product_revision_level));
snip[i] = 0;
s.Format("Product rev level: %s\r\n", snip);
*/
strInquiry += s;
} while (false);
//m_edtInquiry.SetWindowText(strInquiry);
//m_edtRegion.SetWindowText(strRegion);
::CloseHandle(device);
return true;
}
//void CMyregionDlg::OnSelchangeDrivesCombo()
//{
// UpdateDeviceInfos();
//}