-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDevice.cpp
More file actions
1259 lines (1110 loc) · 39.5 KB
/
Device.cpp
File metadata and controls
1259 lines (1110 loc) · 39.5 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "stdafx.h"
#include "stdio.h"
#include "Aspi.h"
#include "CDVDMain.h"
#include "ntddscsi.h"
// #define DISCInfo_DEBUG
typedef struct _Known
{
char h,l;
char *desc;
} Known;
Known Types2[]=
{
{'R','E',"SD-C 2002"},
{'X','C',"SD-C 2102/SD-M 1202"},
{'X','I',"SD-C 2502"},
{'X','W',"SD-C 2732"},
{'X','A',"SD-M 1002"},
{'X','B',"SD-M 1102"},
{'Y','D',"SD-M 1201"},
{'X','D',"SD-M 1212/SD-C 2202"},
{'X','H',"SD-M 1222"},
{'X','F',"SD-M 1302/SD-C 2302"},
{'Y','G',"SD-M 1401"},
{'X','G',"SD-M 1402 revA/SD-C 2402"},
{'X','K',"SD-M 1402 revB"},
{'X','J',"SD-M 1502 revA/SD-C 2512"},
{'X','M',"SD-M 1502 revB"},
{'X','N',"SD-M 1612 revA"},
{'X','O',"SD-M 1612 revB/SD-C 2612"},
{'X','P',"SD-M 1612 revC"},
{'X','Q',"SD-M 1712"},
{'X','S',"SD-M 1802"},
{'X','U',"SD-M 1802 Bose OEM"},
{'H','M',"SD-R 1002"},
{'H','N',"SD-R 1102"},
{'H','P',"SD-R 1202/1202F"},
{'H','Q',"SD-R 1312"},
{'H','R',"SD-R 1412"},
{'H','S',"SD-R 1512"},
{'I','M',"SD-R 2002 revA"},
{'I','N',"SD-R 2002 revB"},
{'I','O',"SD-R 2102 revA"},
{'I','P',"SD-R 2102 revB"},
{'I','Q',"SD-R 2212 revA"},
{'I','R',"SD-R 2212 revB"},
{'I','S',"SD-R 2312"},
{'I','T',"SD-R 2412"},
{'I','U',"SD-R 2512"},
{'K','M',"SD-R 5002"},
{'K','N',"SD-R 5112 revA"},
{'K','P',"SD-R 5112 revB"},
{'K','Q',"SD-R 5272"},
{'E','B',"SD-R 5372"},
{'E','D',"SD-R 5372V"},
{'L','M',"SD-R 6012"},
{'L','O',"SD-R 6112"},
{'P','M',"SD-R 6252"},
{'P','N',"SD-R 6372"},
{'O','A',"SD-R 6472"},
{'O','B',"SD-R 6572M"},
{'O','C',"SD-R 6472U"},
{'M','M',"SD-R 9012"},
{'Z','C',"SD-W1101"},
{'Z','D',"SD-W1111"},
{'Z','G',"SD-W2002"},
{'J','M',"SR-C8002"},
{'J','N',"SR-C8102"}
};
Device *devices = NULL;
int deviceCount = 0;
HANDLE event = NULL;
//char LogFileDir[255];
//sprintf(LogFileDir[255],"%s",GetCurrentDir());
bool DumpableDrive(Device* dev)
{
char* goodDrive[] =
{
"TOSHIBA",
"Toshiba",
"KiSS",
"Compaq",
"TSSTCorp",
"Samsung",
NULL
};
for (char** current = &goodDrive[0]; *current; ++current) if (strncmp (dev->name, *current, strlen(*current)) == 0) return true;
return false;
}
// Make a list of available SCSI devices
DWORD Device::makeDeviceList(void)
{
unsigned long i;
char name[16];
unsigned long len;
unsigned long bank,offset,Length;
char fk[20];
unsigned char buffer[2048];
unsigned char b[256];
unsigned char cmd[12];
BYTE CDB[16];
unsigned char bx[255];
char flags;
char resets;
char changes;
char *r_mask[1];
int foundit=0;
DWORD d,calc;
int lenData;
int AdditionalLength, NumberofProfiles;
BYTE *p;
BYTE *pMax = b + 256;
SRB_ExecSCSICmd s;
BYTE CDComp[20];
int adaptorID, targetID, unitID;
Inquiry inq;
Device *dev;
DWORD status;
DWORD dwFlags = GENERIC_READ;
int iOSVer = getOsVersion();
if ( iOSVer >= OS_WIN2K )
dwFlags |= GENERIC_WRITE;
//FILE* fx = fopen("_data.bin", "wb");
// Delete the current devices if any are there
if (devices)
{
Device *temp = devices, *p;
for (; temp; temp = p)
{
p = temp->next;
delete temp;
}
devices = NULL;
deviceCount = 0;
}
// Loop to create list of devices
// SPTI
if (Main_Form->SPTI1->Checked)
{
#ifdef DISCInfo_DEBUG
write_log("---------------------------------------------");
write_log("Searching for drives in SPTI mode");
#endif
for (char c='C';c<='Z';c++)
{
String S = String(c) + ":";
if ( GetDriveType( S.c_str() ) == DRIVE_CDROM || GetDriveType( S.c_str() ) == DRIVE_FIXED || GetDriveType( S.c_str() ) == DRIVE_REMOVABLE)
{
dev = new Device();
if (!Main_Form->Displayotherdevices1->Checked)
{
// Is it a CD-ROM?
if ((GetDriveType( S.c_str() ) != DRIVE_CDROM))
{
delete dev;
continue;
}
}
memset((void *) &inq, 0, sizeof(Inquiry));
//sprintf( dev->letter, "%c", c );
dev->letter[0] = c;
dev->letter[1]=0;
// Send SCSI command
memset((void *) CDB, 0, sizeof(CDB));
CDB[0] = SCSI_INQUIRY;
CDB[4] = 56;
status=dev->SendSPTICommand(CDB, 6, dwFlags, SCSI_IOCTL_DATA_IN,(BYTE *) &inq, sizeof(Inquiry));
if (status!=0)
{
#ifdef DISCInfo_DEBUG
char logz[255];
sprintf(logz,"Inquiry doesn't work with drive letter %s:",(AnsiString)dev->letter);
write_log(logz);
#endif
delete dev;
// No device is a normal error
continue;
}
// Not needed for SPTI
dev->HaId = 0;
dev->Target = 0;
dev->Lun = 0;
// Not needed for SPTI
memcpy(dev->name, inq.Vendor, 49);
dev->name[49] = 0;
memcpy(dev->interfacex, &inq.interfx[1], 1);
dev->type=inq.devType;
memcpy(dev->vendor_name, inq.Vendor, 24);
dev->vendor_name[24] = 0;
memcpy(dev->firmware_version, &(inq.Vendor[24]), 4);
dev->firmware_version[4] = 0;
char extra_string[20];
strcpy(extra_string, &(inq.Vendor[28]));
extra_string[20]=0;
strcpy(dev->extra_info, extra_string);
char combo_string[50];
char combo_vendor[25];
memcpy(combo_vendor, dev->name, 24);
combo_vendor[24] = 0;
sprintf(combo_string,"%s: %s",dev->letter,combo_vendor);
#ifdef DISCInfo_DEBUG
char logz[255];
sprintf(logz,"Added the drive %s into the combobox",(AnsiString)combo_string);
write_log(logz);
#endif
Main_Form->ComboBox->Items->Add(combo_string);
Main_Form->ComboBox->ItemIndex=0;
deviceCount++;
dev->next = devices;
dev->prev = NULL;
if (devices)
devices->prev = dev;
devices = dev;
}
}
} else
{
// ASPI
status = GetASPI32SupportInfo();
int tempCount = LOBYTE(status);
deviceCount = 0;
// SCSI error occurred?
if (HIBYTE(LOWORD(status)) != SS_COMP)
return (DWORD) -1;
// Are there no adaptors? This isn't an error condition.
if (!tempCount)
return 0;
for (adaptorID = (tempCount - 1); adaptorID >= 0; adaptorID--)
for (targetID = (MAX_ID - 1); targetID >= 0; targetID--)
for (unitID = (MAX_ID - 1); unitID >= 0; unitID--)
{
// Create a new Device and initialize it
dev = new Device();
dev->HaId = adaptorID;
dev->Target = targetID;
dev->Lun = unitID;
memset((void *) &inq, 0, sizeof(Inquiry));
// Send SCSI command
memset((void *) CDB, 0, sizeof(CDB));
CDB[0] = SCSI_INQUIRY;
CDB[4] = 56;
if (!!(dev->SendCommand(CDB, 6, SRB_DIR_IN,(BYTE *) &inq, sizeof(Inquiry))))
{
delete dev;
// No device is a normal error
continue;
}
memcpy(dev->name, inq.Vendor, 49);
dev->name[49] = 0;
memcpy(dev->interfacex, &inq.interfx[1], 1);
dev->type=inq.devType;
if (!Main_Form->Displayotherdevices1->Checked)
{
// Is it a CD-ROM?
if ((inq.devType != DTYPE_CROM) && (inq.devType != DTYPE_WORM))
{
delete dev;
continue;
}
}
if (inq.devType == DTYPE_PROC) // SPECIAL CASE FOR RAID MOBOs
{
delete dev;
continue;
}
memcpy(dev->vendor_name, inq.Vendor, 24);
dev->vendor_name[24] = 0;
memcpy(dev->firmware_version, &(inq.Vendor[24]), 4);
dev->firmware_version[4] = 0;
char extra_string[20];
strcpy(extra_string, &(inq.Vendor[28]));
extra_string[20]=0;
strcpy(dev->extra_info, extra_string);
char combo_string[50];
char combo_vendor[25];
memcpy(combo_vendor, dev->name, 24);
combo_vendor[24] = 0;
sprintf(combo_string,"%i:%i:%i %s",dev->HaId,dev->Target,dev->Lun,combo_vendor);
#ifdef DISCInfo_DEBUG
char logz[255];
sprintf(logz,"Added the drive %s into the combobox",(AnsiString)combo_string);
write_log(logz);
#endif
Main_Form->ComboBox->Items->Add(combo_string);
Main_Form->ComboBox->ItemIndex=0;
deviceCount++;
dev->next = devices;
dev->prev = NULL;
if (devices)
devices->prev = dev;
devices = dev;
}
}
for (dev = devices; dev; dev = dev->next)
{
#ifdef DISCInfo_DEBUG
char logz[255];
sprintf(logz,"*** Started to query %s for info ***",AnsiString(dev->vendor_name).Trim());
write_log("---------------------------------------------");
write_log(logz);
#endif
dev->if_toshiba=false;
// BEGIN TOSHIBA DUMPING OF TWO BYTE
// Change March, 2006 - Try this on every drive. Doesn't hurt them.
#ifdef DISCInfo_DEBUG
write_log("Checking the drive to fetch the two byte revision ID");
#endif
// TWO CHAR INFO
// first write the bank into bank switch register at F003
memset(cmd, 0, sizeof(cmd));
memset(buffer, 0, sizeof(buffer));
cmd[0] = 0x1D;
cmd[4] = 0x08;
buffer[0] = 0x88;
buffer[3] = 0x04;
buffer[5] = 0x40;
if (Main_Form->SPTI1->Checked)
{
status = dev->SendSPTICommand(cmd, 12, dwFlags, SCSI_IOCTL_DATA_OUT, (unsigned char *) buffer, 0x0A);
}
else
{
status = dev->SendCommand(cmd, 12, SRB_DIR_OUT, (unsigned char *) buffer, 0x0A);
}
if (status != 0)
{
#ifdef DISCInfo_DEBUG
write_log("First Toshiba command failed");
#endif
dev->if_toshiba=false;
} else
{
#ifdef DISCInfo_DEBUG
write_log("First Toshiba command completed successfully");
#endif
memset(cmd, 0, sizeof(cmd));
cmd[0] = 0x1C;
cmd[3] = 0xFF; // Lenght
cmd[4] = 0xFF;
if (Main_Form->SPTI1->Checked)
{
status = dev->SendSPTICommand(cmd, 12, dwFlags, SCSI_IOCTL_DATA_IN, (unsigned char *) buffer, 255);
}
else
{
status = dev->SendCommand(cmd, 12, SRB_DIR_IN, (unsigned char *) buffer, 255);
}
if (status != 0)
{
#ifdef DISCInfo_DEBUG
write_log("Second Toshiba command failed");
#endif
dev->if_toshiba=false;
} else
{
#ifdef DISCInfo_DEBUG
write_log("Second Toshiba command completed successfully");
#endif
if ( !isalpha(buffer[6]) || !isalpha(buffer[7]) )
{
dev->if_toshiba=false;
memcpy(dev->fw_code, "", 25);
dev->fw_code[25]=0;
memcpy(dev->tosh_model, "", 35);
dev->tosh_model[35]=0;
} else
{
dev->if_toshiba=true;
sprintf(fk,"%c%c", toupper(buffer[6]), toupper(buffer[7]));
memcpy(dev->fw_code, fk, 2);
dev->fw_code[2] = 0;
for (i = 0; i < (sizeof(Types2)/sizeof(Types2[0])); i++)
{
if ((Types2[i].h == toupper(buffer[6])) && (Types2[i].l == toupper(buffer[7])))
{
sprintf(dev->tosh_model,"Toshiba %s",Types2[i].desc);
#ifdef DISCInfo_DEBUG
char logz[255];
sprintf(logz,"Toshiba drive identified as %s",Types2[i].desc);
write_log(logz);
#endif
foundit = 1;
}
}
if (foundit!=1)
{
sprintf(dev->tosh_model,"Unknown model");
#ifdef DISCInfo_DEBUG
char logz[255];
sprintf(logz,"Unknowned Toshiba model with code %c%c",toupper(buffer[6]),toupper(buffer[7]));
write_log(logz);
#endif
}
}
}
}
if (dev->if_toshiba == false)
{
#ifdef DISCInfo_DEBUG
write_log("Checking the drive to fetch the two byte revision ID (VOS)");
#endif
memset(cmd, 0, sizeof(cmd));
memset(buffer, 0, sizeof(buffer));
cmd[0] = 0x1D;
cmd[1] = 0x10;
cmd[4] = 0x06;
buffer[0] = 0x85;
buffer[3] = 0x02;
buffer[4] = 0x01;
buffer[5] = 0x01;
if (Main_Form->SPTI1->Checked)
{
status = dev->SendSPTICommand(cmd, 6, dwFlags, SCSI_IOCTL_DATA_OUT, (unsigned char *) buffer, 12);
}
else
{
status = dev->SendCommand(cmd, 6, SRB_DIR_OUT, (unsigned char *) buffer, 12);
}
if (status != 0)
{
#ifdef DISCInfo_DEBUG
write_log("First VOS command failed");
#endif
dev->if_toshiba=false;
} else
{
#ifdef DISCInfo_DEBUG
write_log("First VOS command completed successfully");
#endif
memset(cmd, 0, sizeof(cmd));
cmd[0] = 0x1C;
cmd[4] = 0x0C;
if (Main_Form->SPTI1->Checked)
{
status = dev->SendSPTICommand(cmd, 6, dwFlags, SCSI_IOCTL_DATA_IN, (unsigned char *) buffer, 8);
}
else
{
status = dev->SendCommand(cmd, 6, SRB_DIR_IN, (unsigned char *) buffer, 8);
}
if (status != 0)
{
#ifdef DISCInfo_DEBUG
write_log("Second VOS command failed");
#endif
dev->if_toshiba=false;
} else
{
#ifdef DISCInfo_DEBUG
write_log("Second VOS command completed successfully");
#endif
if ( !isalpha(buffer[4]) || !isalpha(buffer[5]) )
{
dev->if_toshiba=false;
memcpy(dev->fw_code, "", 25);
dev->fw_code[25]=0;
memcpy(dev->tosh_model, "", 35);
dev->tosh_model[35]=0;
} else
{
dev->if_toshiba=true;
sprintf(fk,"%c%c", toupper(buffer[4]), toupper(buffer[5]));
memcpy(dev->fw_code, fk, 2);
dev->fw_code[2] = 0;
for (i = 0; i < (sizeof(Types2)/sizeof(Types2[0])); i++)
{
if ((Types2[i].h == toupper(buffer[4])) && (Types2[i].l == toupper(buffer[5])))
{
sprintf(dev->tosh_model,"Toshiba %s",Types2[i].desc);
#ifdef DISCInfo_DEBUG
char logz[255];
sprintf(logz,"Toshiba drive identified as %s",Types2[i].desc);
write_log(logz);
#endif
foundit = 1;
}
}
if (foundit!=1)
{
sprintf(dev->tosh_model,"Unknown model");
#ifdef DISCInfo_DEBUG
char logz[255];
sprintf(logz,"Unknowned Toshiba model with code %c%c",toupper(buffer[6]),toupper(buffer[7]));
write_log(logz);
#endif
}
}
}
}
}
if (dev->if_toshiba == false)
{
#ifdef DISCInfo_DEBUG
write_log("Checking the drive to fetch the two byte OEM ID");
#endif
memset(cmd, 0, sizeof(cmd));
cmd[0] = 0xFF;
cmd[2] = 0xFF;
cmd[11] = 0xAA;
if (Main_Form->SPTI1->Checked)
{
status = dev->SendSPTICommand(cmd, 12, dwFlags, SCSI_IOCTL_DATA_IN, (unsigned char *) buffer, 8);
}
else
{
status = dev->SendCommand(cmd, 12, SRB_DIR_IN, (unsigned char *) buffer, 8);
}
if (status != 0)
{
#ifdef DISCInfo_DEBUG
write_log("OEM ID command failed");
#endif
dev->if_toshiba=false;
} else
{
#ifdef DISCInfo_DEBUG
write_log("OEM ID command completed successfully");
#endif
if ( !isalpha(buffer[4]) || !isalpha(buffer[5]) )
{
dev->if_toshiba=false;
memcpy(dev->fw_code, "", 25);
dev->fw_code[25]=0;
memcpy(dev->tosh_model, "", 35);
dev->tosh_model[35]=0;
} else
{
dev->if_toshiba=true;
memcpy(dev->fw_code, "", 25);
dev->fw_code[25]=0;
memcpy(dev->tosh_model, "", 35);
dev->tosh_model[35]=0;
sprintf(fk,"OEM %c%c", toupper(buffer[4]), toupper(buffer[5]));
memcpy(dev->fw_code, fk, 6);
dev->fw_code[6] = 0;
}
}
}
if (dev->if_toshiba == false)
{
dev->fw_code[0]=0;
dev->tosh_model[0]=0;
}
// END TOSHIBA DUMPING OF TWO BYTE
if ((dev->type == DTYPE_CROM) || (dev->type == DTYPE_WORM))
{
#ifdef DISCInfo_DEBUG
write_log("Issueing the Mode Sense (10) command");
#endif
dev->cdRRead = FALSE;
dev->cdRWRead = FALSE;
dev->cdMethod2Read = FALSE;
dev->dvdRomRead = FALSE;
dev->dvdRRead = FALSE;
dev->dvdRWRead = FALSE;
dev->dvdRamRead = FALSE;
dev->dvdPRRead = FALSE;
dev->dvdPRWRead = FALSE;
dev->cdRWrite = FALSE;
dev->cdRWWrite = FALSE;
dev->testWrite = FALSE;
dev->dvdRWrite = FALSE;
dev->dvdRWWrite = FALSE;
dev->dvdRamWrite = FALSE;
dev->dvdPRWrite = FALSE;
dev->dvdPRWWrite = FALSE;
dev->read_s=0;
dev->write_s=0;
dev->audioplay = FALSE;
dev->composite = FALSE;
dev->digport1 = FALSE;
dev->digport2 = FALSE;
dev->mode1form = FALSE;
dev->mode2form = FALSE;
dev->multisession = FALSE;
dev->buffunder = FALSE;
dev->ISRC = FALSE;
dev->UPC = FALSE;
dev->barcode = FALSE;
dev->mechanism[0] = 0;
dev->mtrainier = FALSE;
dev->iscdRRead = FALSE;
dev->iscdRWrite = FALSE;
dev->isdvdDrive = FALSE;
dev->iscdDrive = FALSE;
dev->buffersize=0;
dev->levels=0;
dev->isdvdDrive = FALSE;
memset( &s, 0, sizeof( s ) );
memset( bx, 0xFF, 256 );
memset(cmd, 0, sizeof(cmd));
cmd[0] = 0x5A;
cmd[2] = 0x3F;
cmd[7] = 0x01;
cmd[8] = 0x00;
if (Main_Form->SPTI1->Checked)
{
status = dev->SendSPTICommand(cmd, 10, dwFlags, SCSI_IOCTL_DATA_IN, (unsigned char *) bx, 256 );
} else
{
status = dev->SendCommand(cmd, 10, SRB_DIR_IN,(unsigned char *) bx, 256);
}
if (status != 0)
{
#ifdef DISCInfo_DEBUG
write_log("Mode Sense (10) command failed");
#endif
} else
{
#ifdef DISCInfo_DEBUG
write_log("Mode Sense (10) completed successfully");
#endif
lenData = ((unsigned int)bx[0] << 8) + bx[1];
p = bx + 8;
while( (p < &(bx[2+lenData])) && (p < pMax) )
{
BYTE which;
which = p[0] & 0x3F;
switch( which )
{
case 0x2A:
memcpy( CDComp, p, p[1]+2 );
if(CDComp[2] & 0x01) dev->cdRRead = true;
if(CDComp[2] & 0x02) dev->cdRWRead = true;
if(CDComp[2] & 0x04) dev->cdMethod2Read = true;
if(CDComp[2] & 0x08) dev->dvdRomRead = true;
if(CDComp[2] & 0x10)
{
dev->dvdRRead = true;
dev->dvdRWRead = true;
}
if(CDComp[2] & 0x20) dev->dvdRamRead = true;
if(CDComp[3] & 0x01) dev->cdRWrite = true;
if(CDComp[3] & 0x02) dev->cdRWWrite = true;
if(CDComp[3] & 0x04) dev->testWrite = true;
if(CDComp[3] & 0x10) dev->dvdRWrite = true;
if(CDComp[3] & 0x20) dev->dvdRamWrite = true;
if(CDComp[4] & 0x01) dev->audioplay = true;
if(CDComp[4] & 0x02) dev->composite = true;
if(CDComp[4] & 0x04) dev->digport1 = true;
if(CDComp[4] & 0x08) dev->digport2 = true;
if(CDComp[4] & 0x10) dev->mode1form = true;
if(CDComp[4] & 0x20) dev->mode2form = true;
if(CDComp[4] & 0x40) dev->multisession = true;
if(CDComp[4] & 0x80) dev->buffunder = true;
if(CDComp[5] & 0x20) dev->ISRC = true;
if(CDComp[5] & 0x40) dev->UPC = true;
if(CDComp[5] & 0x80) dev->barcode = true;
switch(CDComp[6] & 0xE0)
{
case 0x00:
sprintf(dev->mechanism,"%s","Caddy");
break;
case 0x20:
sprintf(dev->mechanism,"%s","Tray");
break;
case 0x40:
sprintf(dev->mechanism,"%s","Popup");
break;
case 0x60:
sprintf(dev->mechanism,"%s","Unasigned");
break;
case 0x80:
sprintf(dev->mechanism,"%s","Induvidual discs changer");
break;
case 0xA0:
sprintf(dev->mechanism,"%s","Magazine mechanism changer");
break;
case 0xC0:
sprintf(dev->mechanism,"%s","Unasigned");
break;
case 0xE0:
sprintf(dev->mechanism,"%s","Unasigned");
break;
default:
ShowMessage("Unknowned "+AnsiString(dev->vendor_name));
}
if( dev->dvdRomRead ||
dev->dvdRRead ||
dev->dvdRamRead ||
dev->dvdRWrite ||
dev->dvdRamWrite )
dev->isdvdDrive = true;
if( dev->cdRRead ||
dev->cdRWRead ||
dev->cdMethod2Read ||
dev->cdRWrite ||
dev->cdRWWrite )
dev->iscdDrive = true;
if( dev->cdRRead ||
dev->cdRWRead ||
dev->cdMethod2Read)
dev->iscdRRead = true;
if( dev->cdRWrite ||
dev->cdRWWrite )
dev->iscdRWrite = true;
memcpy( CDComp, p, p[1]+2 );
calc = ((DWORD)CDComp[8] << 8) + (DWORD)CDComp[9];
dev->read_s=(long)calc / 175 ;
calc = ((DWORD)CDComp[18] << 8) + (DWORD)CDComp[19];
dev->write_s=(long)calc / 175 ;
calc = ((DWORD)CDComp[10] << 8) + (DWORD)CDComp[11];
dev->levels=calc;
calc = ((DWORD)CDComp[12] << 8) + (DWORD)CDComp[13];
dev->buffersize=calc;
}
p += (p[1] + 2);
}
}
// AnsiString capable=Trim(AnsiString(dev->name).SubString(0,24))+":\n";
memset(cmd, 0, sizeof(cmd));
#ifdef DISCInfo_DEBUG
write_log("Issueing the Get Configuration command part 1");
#endif
cmd[0] = 0x46;
cmd[7] = (2048 & 0xFF00) >> 8;
cmd[8] = (2048 & 0x00FF);
if (Main_Form->SPTI1->Checked)
{
status = dev->SendSPTICommand(cmd, 10, dwFlags, SCSI_IOCTL_DATA_IN, (unsigned char *) buffer, 2048 );
}
else
{
status = dev->SendCommand(cmd, 10, SRB_DIR_IN, (unsigned char *) buffer, 2048 );
}
if (status != 0)
{
#ifdef DISCInfo_DEBUG
write_log("Get Configuration command part 1 failed");
#endif
} else
{
#ifdef DISCInfo_DEBUG
write_log("Get Configuration command part 1 completed successfully");
#endif
Length = buffer[0] << 24 | buffer[1] << 16 | buffer[2] <<8 | buffer[3];
AdditionalLength = buffer[11];
NumberofProfiles = AdditionalLength / 4;
offset = 12; //first feature offset in buffer MSB
for(int f=0; f < NumberofProfiles; f++)
{
int profile = buffer[offset] << 8 | buffer[offset + 1];
switch (profile)
{
case 3:
case 5: //capable += "asynchronous magneto optical\n";
break;
case 8: //capable += "cdrom read\n";
break;
case 9: //capable += "cdr write\n";
break;
case 0xA: //capable += "cdrw write\n";
break;
case 0x10: //capable += "dvdrom read\n";
break;
case 0x11: //capable += "dvd-r write\n";
dev->dvdRWrite=true; dev->dvdRRead=true;
break;
case 0x12: //capable += "dvd-ram write\n";
break;
case 0x13: //capable += "dvd-rw restricted overwrite\n";
dev->dvdRWWrite=true; dev->dvdRWRead=true;
break;
case 0x14: //capable += "dvd-rw sequential recording\n";
dev->dvdRWWrite=true; dev->dvdRWRead=true;
break;
case 0x1A: //capable += "dvd+rw write\n";
dev->dvdPRWWrite=true; dev->dvdPRWRead=true;
break; //make some assumptions here if write then read too
case 0x1B: //capable += "dvd+r write\n";
dev->dvdPRWrite=true; dev->dvdPRRead=true;
break; //and here if write then read too
case 0xFFFF: //capable += "Not good\n";
break;
}
offset += 4;
Length -= 4;
if (Length <= 12 || offset >= 2048)
break;
}
//capable += "\n";
}
// Mt. Rainier
memset(cmd, 0, sizeof(cmd));
memset(buffer, 0, sizeof(buffer));
#ifdef DISCInfo_DEBUG
write_log("Issueing the Get Configuration command part 2");
#endif
cmd[0] = 0x46;
cmd[3] = 1;
cmd[7] = (2048 & 0xFF00) >> 8;
cmd[8] = (2048 & 0x00FF);
if (Main_Form->SPTI1->Checked)
{
status = dev->SendSPTICommand(cmd, 10, dwFlags, SCSI_IOCTL_DATA_IN, (unsigned char *) buffer, 2048 );
}
else
{
status = dev->SendCommand(cmd, 10, SRB_DIR_IN, (unsigned char *) buffer, 2048 );
}
if (status != 0)
{
#ifdef DISCInfo_DEBUG
write_log("Get Configuration command part 2 failed");
#endif
} else
{
#ifdef DISCInfo_DEBUG
write_log("Get Configuration command part 2 completed successfully");
#endif
Length = buffer[0] << 24 | buffer[1] << 16 | buffer[2] <<8 | buffer[3];
AdditionalLength = buffer[11];
NumberofProfiles = AdditionalLength / 4;
#ifdef DISCInfo_DEBUG
write_log("Filled in the values");
#endif
offset = 8; //first feature offset in buffer MSB
do
{
int feature = buffer[offset] << 8 | buffer[offset + 1];
switch (feature)
{
case 0x28: //capable += "mt rainier read write\n";
#ifdef DISCInfo_DEBUG
write_log("Profile 28: Mt Rainier");
#endif
dev->mtrainier=true;
break;
case 0x2B: //capable += "dvd+r read\n";
#ifdef DISCInfo_DEBUG
write_log("Profile 2B: dvd+r read");
#endif
dev->dvdPRRead=true;
break;
case 0x2A: //capable += "dvd+rw read\n";
#ifdef DISCInfo_DEBUG
write_log("Profile 2A: dvd+rw read");
#endif
dev->dvdPRWRead=true; dev->dvdPRRead=true;
break;
case 0xFFFF: //capable += "Not good\n";
#ifdef DISCInfo_DEBUG
write_log("FFFF ERROR");
#endif
break;
}
offset += (4 + buffer[offset + 3]);
Length -= 4;
if (Length <= 12 || offset >= 2048)
break;
} while(offset < (Length - 4));
}
//ShowMessage(capable);
//fwrite(buffer, 2048, 1, fx);
//fwrite("YYYXXX", 6, 1, fx);
}
if ((dev->type == DTYPE_CROM) || (dev->type == DTYPE_WORM))
{
// Serial number
dev->serial[0]=0;
memset((void *) CDB, 0, sizeof(CDB));
memset(buffer, 0, sizeof(buffer));
#ifdef DISCInfo_DEBUG
write_log("Issueing the Get Configuration command (SN)");
#endif
CDB[0] = 0x46; // Get Configuration
CDB[2] = (0x108 & 0xFF00) >> 8;
CDB[3] = (0x108 & 0xFF);
CDB[7] = 0;
CDB[8] = 30;
if (Main_Form->SPTI1->Checked)
{
status = dev->SendSPTICommand(CDB, 10, dwFlags, SCSI_IOCTL_DATA_IN, (unsigned char *) buffer, 50 );
}
else
{
status = dev->SendCommand(CDB, 10, SRB_DIR_IN, (unsigned char *) buffer, 50 );