Select one of the symbols to view example projects that use it.
 
Outline
Includes
#include "usbd_msc_bot.h"
#include "usbd_msc_scsi.h"
#include "usbd_msc.h"
#include "usbd_msc_data.h"
SCSI_ProcessCmd(USBD_HandleTypeDef *, uint8_t, uint8_t *)
SCSI_TestUnitReady(USBD_HandleTypeDef *, uint8_t, uint8_t *)
SCSI_Inquiry(USBD_HandleTypeDef *, uint8_t, uint8_t *)
SCSI_ReadCapacity10(USBD_HandleTypeDef *, uint8_t, uint8_t *)
SCSI_ReadCapacity16(USBD_HandleTypeDef *, uint8_t, uint8_t *)
SCSI_ReadFormatCapacity(USBD_HandleTypeDef *, uint8_t, uint8_t *)
SCSI_ModeSense6(USBD_HandleTypeDef *, uint8_t, uint8_t *)
SCSI_ModeSense10(USBD_HandleTypeDef *, uint8_t, uint8_t *)
SCSI_RequestSense(USBD_HandleTypeDef *, uint8_t, uint8_t *)
SCSI_SenseCode(USBD_HandleTypeDef *, uint8_t, uint8_t, uint8_t)
SCSI_StartStopUnit(USBD_HandleTypeDef *, uint8_t, uint8_t *)
SCSI_AllowPreventRemovable(USBD_HandleTypeDef *, uint8_t, uint8_t *)
SCSI_Read10(USBD_HandleTypeDef *, uint8_t, uint8_t *)
SCSI_Read12(USBD_HandleTypeDef *, uint8_t, uint8_t *)
SCSI_Write10(USBD_HandleTypeDef *, uint8_t, uint8_t *)
SCSI_Write12(USBD_HandleTypeDef *, uint8_t, uint8_t *)
SCSI_Verify10(USBD_HandleTypeDef *, uint8_t, uint8_t *)
SCSI_CheckAddressRange(USBD_HandleTypeDef *, uint8_t, uint32_t, uint32_t)
SCSI_ProcessRead(USBD_HandleTypeDef *, uint8_t)
SCSI_ProcessWrite(USBD_HandleTypeDef *, uint8_t)
SCSI_UpdateBotData(USBD_MSC_BOT_HandleTypeDef *, uint8_t *, uint16_t)
Files
loading...
SourceVuSTM32 Libraries and SamplesSTM32_USB_Device_LibraryClass/MSC/Src/usbd_msc_scsi.c
 
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file usbd_msc_scsi.c * @author MCD Application Team * @brief This file provides all the USBD SCSI layer functions. ****************************************************************************** * @attention * * Copyright (c) 2015 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** *//* ... */ /* BSPDependencies - "stm32xxxxx_{eval}{discovery}{nucleo_144}.c" - "stm32xxxxx_{eval}{discovery}_io.c" - "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c" EndBSPDependencies *//* ... */ /* Includes ------------------------------------------------------------------*/ #include "usbd_msc_bot.h" #include "usbd_msc_scsi.h" #include "usbd_msc.h" #include "usbd_msc_data.h" /** @addtogroup STM32_USB_DEVICE_LIBRARY * @{ *//* ... */ /** @defgroup MSC_SCSI * @brief Mass storage SCSI layer module * @{ *//* ... */ /** @defgroup MSC_SCSI_Private_TypesDefinitions * @{ *//* ... */ /** * @} *//* ... */ /** @defgroup MSC_SCSI_Private_Defines * @{ *//* ... */ /** * @} *//* ... */ /** @defgroup MSC_SCSI_Private_Macros * @{ *//* ... */ /** * @} *//* ... */ /** @defgroup MSC_SCSI_Private_Variables * @{ *//* ... */ extern uint8_t MSCInEpAdd; extern uint8_t MSCOutEpAdd; /** * @} *//* ... */ /** @defgroup MSC_SCSI_Private_FunctionPrototypes * @{ *//* ... */ static int8_t SCSI_TestUnitReady(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); static int8_t SCSI_Inquiry(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); static int8_t SCSI_ReadFormatCapacity(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); static int8_t SCSI_ReadCapacity10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); static int8_t SCSI_ReadCapacity16(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); static int8_t SCSI_RequestSense(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); static int8_t SCSI_StartStopUnit(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); static int8_t SCSI_AllowPreventRemovable(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); static int8_t SCSI_ModeSense6(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); static int8_t SCSI_ModeSense10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); static int8_t SCSI_Write10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); static int8_t SCSI_Write12(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); static int8_t SCSI_Read10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); static int8_t SCSI_Read12(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); static int8_t SCSI_Verify10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params); static int8_t SCSI_CheckAddressRange(USBD_HandleTypeDef *pdev, uint8_t lun, uint32_t blk_offset, uint32_t blk_nbr); static int8_t SCSI_ProcessRead(USBD_HandleTypeDef *pdev, uint8_t lun); static int8_t SCSI_ProcessWrite(USBD_HandleTypeDef *pdev, uint8_t lun); static int8_t SCSI_UpdateBotData(USBD_MSC_BOT_HandleTypeDef *hmsc, uint8_t *pBuff, uint16_t length); /** * @} *//* ... */ /** @defgroup MSC_SCSI_Private_Functions * @{ *//* ... */ /** * @brief SCSI_ProcessCmd * Process SCSI commands * @param pdev: device instance * @param lun: Logical unit number * @param params: Command parameters * @retval status *//* ... */ int8_t SCSI_ProcessCmd(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *cmd) { int8_t ret; USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; if (hmsc == NULL) { return -1; }if (hmsc == NULL) { ... } switch (cmd[0]) { case SCSI_TEST_UNIT_READY: ret = SCSI_TestUnitReady(pdev, lun, cmd); break; case SCSI_TEST_UNIT_READY: case SCSI_REQUEST_SENSE: ret = SCSI_RequestSense(pdev, lun, cmd); break; case SCSI_REQUEST_SENSE: case SCSI_INQUIRY: ret = SCSI_Inquiry(pdev, lun, cmd); break; case SCSI_INQUIRY: case SCSI_START_STOP_UNIT: ret = SCSI_StartStopUnit(pdev, lun, cmd); break; case SCSI_START_STOP_UNIT: case SCSI_ALLOW_MEDIUM_REMOVAL: ret = SCSI_AllowPreventRemovable(pdev, lun, cmd); break; case SCSI_ALLOW_MEDIUM_REMOVAL: case SCSI_MODE_SENSE6: ret = SCSI_ModeSense6(pdev, lun, cmd); break; case SCSI_MODE_SENSE6: case SCSI_MODE_SENSE10: ret = SCSI_ModeSense10(pdev, lun, cmd); break; case SCSI_MODE_SENSE10: case SCSI_READ_FORMAT_CAPACITIES: ret = SCSI_ReadFormatCapacity(pdev, lun, cmd); break; case SCSI_READ_FORMAT_CAPACITIES: case SCSI_READ_CAPACITY10: ret = SCSI_ReadCapacity10(pdev, lun, cmd); break; case SCSI_READ_CAPACITY10: case SCSI_READ_CAPACITY16: ret = SCSI_ReadCapacity16(pdev, lun, cmd); break; case SCSI_READ_CAPACITY16: case SCSI_READ10: ret = SCSI_Read10(pdev, lun, cmd); break; case SCSI_READ10: case SCSI_READ12: ret = SCSI_Read12(pdev, lun, cmd); break; case SCSI_READ12: case SCSI_WRITE10: ret = SCSI_Write10(pdev, lun, cmd); break; case SCSI_WRITE10: case SCSI_WRITE12: ret = SCSI_Write12(pdev, lun, cmd); break; case SCSI_WRITE12: case SCSI_VERIFY10: ret = SCSI_Verify10(pdev, lun, cmd); break; case SCSI_VERIFY10: default: SCSI_SenseCode(pdev, lun, ILLEGAL_REQUEST, INVALID_CDB); hmsc->bot_status = USBD_BOT_STATUS_ERROR; ret = -1; break;default }switch (cmd[0]) { ... } return ret; }{ ... } /** * @brief SCSI_TestUnitReady * Process SCSI Test Unit Ready Command * @param lun: Logical unit number * @param params: Command parameters * @retval status *//* ... */ static int8_t SCSI_TestUnitReady(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) { UNUSED(params); USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; if (hmsc == NULL) { return -1; }if (hmsc == NULL) { ... } /* case 9 : Hi > D0 */ if (hmsc->cbw.dDataLength != 0U) { SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); return -1; }if (hmsc->cbw.dDataLength != 0U) { ... } if (hmsc->scsi_medium_state == SCSI_MEDIUM_EJECTED) { SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT); hmsc->bot_state = USBD_BOT_NO_DATA; return -1; }if (hmsc->scsi_medium_state == SCSI_MEDIUM_EJECTED) { ... } if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->IsReady(lun) != 0) { SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT); hmsc->bot_state = USBD_BOT_NO_DATA; return -1; }if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->IsReady(lun) != 0) { ... } hmsc->bot_data_length = 0U; return 0; }{ ... } /** * @brief SCSI_Inquiry * Process Inquiry command * @param lun: Logical unit number * @param params: Command parameters * @retval status *//* ... */ static int8_t SCSI_Inquiry(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) { uint8_t *pPage; uint16_t len; USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; if (hmsc == NULL) { return -1; }if (hmsc == NULL) { ... } if (hmsc->cbw.dDataLength == 0U) { SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); return -1; }if (hmsc->cbw.dDataLength == 0U) { ... } if ((params[1] & 0x01U) != 0U) /* Evpd is set */ { if (params[2] == 0U) /* Request for Supported Vital Product Data Pages*/ { (void)SCSI_UpdateBotData(hmsc, MSC_Page00_Inquiry_Data, LENGTH_INQUIRY_PAGE00); ...} else if (params[2] == 0x80U) /* Request for VPD page 0x80 Unit Serial Number */ { (void)SCSI_UpdateBotData(hmsc, MSC_Page80_Inquiry_Data, LENGTH_INQUIRY_PAGE80); ...} else /* Request Not supported */ { SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_FIELED_IN_COMMAND); return -1; }else { ... } ...} else { pPage = (uint8_t *) & ((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId]) \ ->pInquiry[lun * STANDARD_INQUIRY_DATA_LEN]; len = (uint16_t)pPage[4] + 5U; if (params[4] <= len) { len = params[4]; }if (params[4] <= len) { ... } (void)SCSI_UpdateBotData(hmsc, pPage, len); }else { ... } return 0; }{ ... } /** * @brief SCSI_ReadCapacity10 * Process Read Capacity 10 command * @param lun: Logical unit number * @param params: Command parameters * @retval status *//* ... */ static int8_t SCSI_ReadCapacity10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) { UNUSED(params); int8_t ret; USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; if (hmsc == NULL) { return -1; }if (hmsc == NULL) { ... } ret = ((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->GetCapacity(lun, &hmsc->scsi_blk_nbr, &hmsc->scsi_blk_size); if ((ret != 0) || (hmsc->scsi_medium_state == SCSI_MEDIUM_EJECTED)) { SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT); return -1; }if ((ret != 0) || (hmsc->scsi_medium_state == SCSI_MEDIUM_EJECTED)) { ... } hmsc->bot_data[0] = (uint8_t)((hmsc->scsi_blk_nbr - 1U) >> 24); hmsc->bot_data[1] = (uint8_t)((hmsc->scsi_blk_nbr - 1U) >> 16); hmsc->bot_data[2] = (uint8_t)((hmsc->scsi_blk_nbr - 1U) >> 8); hmsc->bot_data[3] = (uint8_t)(hmsc->scsi_blk_nbr - 1U); hmsc->bot_data[4] = (uint8_t)(hmsc->scsi_blk_size >> 24); hmsc->bot_data[5] = (uint8_t)(hmsc->scsi_blk_size >> 16); hmsc->bot_data[6] = (uint8_t)(hmsc->scsi_blk_size >> 8); hmsc->bot_data[7] = (uint8_t)(hmsc->scsi_blk_size); hmsc->bot_data_length = 8U; return 0; }{ ... } /** * @brief SCSI_ReadCapacity16 * Process Read Capacity 16 command * @param lun: Logical unit number * @param params: Command parameters * @retval status *//* ... */ static int8_t SCSI_ReadCapacity16(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) { UNUSED(params); uint32_t idx; int8_t ret; USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; if (hmsc == NULL) { return -1; }if (hmsc == NULL) { ... } ret = ((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->GetCapacity(lun, &hmsc->scsi_blk_nbr, &hmsc->scsi_blk_size); if ((ret != 0) || (hmsc->scsi_medium_state == SCSI_MEDIUM_EJECTED)) { SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT); return -1; }if ((ret != 0) || (hmsc->scsi_medium_state == SCSI_MEDIUM_EJECTED)) { ... } hmsc->bot_data_length = ((uint32_t)params[10] << 24) | ((uint32_t)params[11] << 16) | ((uint32_t)params[12] << 8) | (uint32_t)params[13]; for (idx = 0U; idx < hmsc->bot_data_length; idx++) { hmsc->bot_data[idx] = 0U; }for (idx = 0U; idx < hmsc->bot_data_length; idx++) { ... } hmsc->bot_data[4] = (uint8_t)((hmsc->scsi_blk_nbr - 1U) >> 24); hmsc->bot_data[5] = (uint8_t)((hmsc->scsi_blk_nbr - 1U) >> 16); hmsc->bot_data[6] = (uint8_t)((hmsc->scsi_blk_nbr - 1U) >> 8); hmsc->bot_data[7] = (uint8_t)(hmsc->scsi_blk_nbr - 1U); hmsc->bot_data[8] = (uint8_t)(hmsc->scsi_blk_size >> 24); hmsc->bot_data[9] = (uint8_t)(hmsc->scsi_blk_size >> 16); hmsc->bot_data[10] = (uint8_t)(hmsc->scsi_blk_size >> 8); hmsc->bot_data[11] = (uint8_t)(hmsc->scsi_blk_size); hmsc->bot_data_length = ((uint32_t)params[10] << 24) | ((uint32_t)params[11] << 16) | ((uint32_t)params[12] << 8) | (uint32_t)params[13]; return 0; }{ ... } /** * @brief SCSI_ReadFormatCapacity * Process Read Format Capacity command * @param lun: Logical unit number * @param params: Command parameters * @retval status *//* ... */ static int8_t SCSI_ReadFormatCapacity(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) { UNUSED(params); uint16_t blk_size; uint32_t blk_nbr; uint16_t i; int8_t ret; USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; if (hmsc == NULL) { return -1; }if (hmsc == NULL) { ... } ret = ((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->GetCapacity(lun, &blk_nbr, &blk_size); if ((ret != 0) || (hmsc->scsi_medium_state == SCSI_MEDIUM_EJECTED)) { SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT); return -1; }if ((ret != 0) || (hmsc->scsi_medium_state == SCSI_MEDIUM_EJECTED)) { ... } for (i = 0U; i < 12U ; i++) { hmsc->bot_data[i] = 0U; }for (i = 0U; i < 12U ; i++) { ... } hmsc->bot_data[3] = 0x08U; hmsc->bot_data[4] = (uint8_t)((blk_nbr - 1U) >> 24); hmsc->bot_data[5] = (uint8_t)((blk_nbr - 1U) >> 16); hmsc->bot_data[6] = (uint8_t)((blk_nbr - 1U) >> 8); hmsc->bot_data[7] = (uint8_t)(blk_nbr - 1U); hmsc->bot_data[8] = 0x02U; hmsc->bot_data[9] = (uint8_t)(blk_size >> 16); hmsc->bot_data[10] = (uint8_t)(blk_size >> 8); hmsc->bot_data[11] = (uint8_t)(blk_size); hmsc->bot_data_length = 12U; return 0; }{ ... } /** * @brief SCSI_ModeSense6 * Process Mode Sense6 command * @param lun: Logical unit number * @param params: Command parameters * @retval status *//* ... */ static int8_t SCSI_ModeSense6(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) { UNUSED(lun); USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; uint16_t len = MODE_SENSE6_LEN; if (hmsc == NULL) { return -1; }if (hmsc == NULL) { ... } /* Check If media is write-protected */ if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->IsWriteProtected(lun) != 0) { MSC_Mode_Sense6_data[2] |= 0x80U; }if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->IsWriteProtected(lun) != 0) { ... } if (params[4] <= len) { len = params[4]; }if (params[4] <= len) { ... } (void)SCSI_UpdateBotData(hmsc, MSC_Mode_Sense6_data, len); return 0; }{ ... } /** * @brief SCSI_ModeSense10 * Process Mode Sense10 command * @param lun: Logical unit number * @param params: Command parameters * @retval status *//* ... */ static int8_t SCSI_ModeSense10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) { UNUSED(lun); USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; uint16_t len = MODE_SENSE10_LEN; if (hmsc == NULL) { return -1; }if (hmsc == NULL) { ... } /* Check If media is write-protected */ if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->IsWriteProtected(lun) != 0) { MSC_Mode_Sense10_data[3] |= 0x80U; }if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->IsWriteProtected(lun) != 0) { ... } if (params[8] <= len) { len = params[8]; }if (params[8] <= len) { ... } (void)SCSI_UpdateBotData(hmsc, MSC_Mode_Sense10_data, len); return 0; }{ ... } /** * @brief SCSI_RequestSense * Process Request Sense command * @param lun: Logical unit number * @param params: Command parameters * @retval status *//* ... */ static int8_t SCSI_RequestSense(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) { UNUSED(lun); uint8_t i; USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; if (hmsc == NULL) { return -1; }if (hmsc == NULL) { ... } if (hmsc->cbw.dDataLength == 0U) { SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); return -1; }if (hmsc->cbw.dDataLength == 0U) { ... } for (i = 0U; i < REQUEST_SENSE_DATA_LEN; i++) { hmsc->bot_data[i] = 0U; }for (i = 0U; i < REQUEST_SENSE_DATA_LEN; i++) { ... } hmsc->bot_data[0] = 0x70U; hmsc->bot_data[7] = REQUEST_SENSE_DATA_LEN - 6U; if ((hmsc->scsi_sense_head != hmsc->scsi_sense_tail)) { hmsc->bot_data[2] = (uint8_t)hmsc->scsi_sense[hmsc->scsi_sense_head].Skey; hmsc->bot_data[12] = (uint8_t)hmsc->scsi_sense[hmsc->scsi_sense_head].w.b.ASC; hmsc->bot_data[13] = (uint8_t)hmsc->scsi_sense[hmsc->scsi_sense_head].w.b.ASCQ; hmsc->scsi_sense_head++; if (hmsc->scsi_sense_head == SENSE_LIST_DEEPTH) { hmsc->scsi_sense_head = 0U; }if (hmsc->scsi_sense_head == SENSE_LIST_DEEPTH) { ... } }if ((hmsc->scsi_sense_head != hmsc->scsi_sense_tail)) { ... } hmsc->bot_data_length = REQUEST_SENSE_DATA_LEN; if (params[4] <= REQUEST_SENSE_DATA_LEN) { hmsc->bot_data_length = params[4]; }if (params[4] <= REQUEST_SENSE_DATA_LEN) { ... } return 0; }{ ... } /** * @brief SCSI_SenseCode * Load the last error code in the error list * @param lun: Logical unit number * @param sKey: Sense Key * @param ASC: Additional Sense Code * @retval none *//* ... */ void SCSI_SenseCode(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t sKey, uint8_t ASC) { UNUSED(lun); USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; if (hmsc == NULL) { return; }if (hmsc == NULL) { ... } hmsc->scsi_sense[hmsc->scsi_sense_tail].Skey = sKey; hmsc->scsi_sense[hmsc->scsi_sense_tail].w.b.ASC = ASC; hmsc->scsi_sense[hmsc->scsi_sense_tail].w.b.ASCQ = 0U; hmsc->scsi_sense_tail++; if (hmsc->scsi_sense_tail == SENSE_LIST_DEEPTH) { hmsc->scsi_sense_tail = 0U; }if (hmsc->scsi_sense_tail == SENSE_LIST_DEEPTH) { ... } }{ ... } /** * @brief SCSI_StartStopUnit * Process Start Stop Unit command * @param lun: Logical unit number * @param params: Command parameters * @retval status *//* ... */ static int8_t SCSI_StartStopUnit(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) { UNUSED(lun); USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; if (hmsc == NULL) { return -1; }if (hmsc == NULL) { ... } if ((hmsc->scsi_medium_state == SCSI_MEDIUM_LOCKED) && ((params[4] & 0x3U) == 2U)) { SCSI_SenseCode(pdev, lun, ILLEGAL_REQUEST, INVALID_FIELED_IN_COMMAND); return -1; }if ((hmsc->scsi_medium_state == SCSI_MEDIUM_LOCKED) && ((params[4] & 0x3U) == 2U)) { ... } if ((params[4] & 0x3U) == 0x1U) /* START=1 */ { hmsc->scsi_medium_state = SCSI_MEDIUM_UNLOCKED; ...} else if ((params[4] & 0x3U) == 0x2U) /* START=0 and LOEJ Load Eject=1 */ { hmsc->scsi_medium_state = SCSI_MEDIUM_EJECTED; ...} else if ((params[4] & 0x3U) == 0x3U) /* START=1 and LOEJ Load Eject=1 */ { hmsc->scsi_medium_state = SCSI_MEDIUM_UNLOCKED; ...} else { /* .. */ }else { ... } hmsc->bot_data_length = 0U; return 0; }{ ... } /** * @brief SCSI_AllowPreventRemovable * Process Allow Prevent Removable medium command * @param lun: Logical unit number * @param params: Command parameters * @retval status *//* ... */ static int8_t SCSI_AllowPreventRemovable(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) { UNUSED(lun); USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; if (hmsc == NULL) { return -1; }if (hmsc == NULL) { ... } if (params[4] == 0U) { hmsc->scsi_medium_state = SCSI_MEDIUM_UNLOCKED; }if (params[4] == 0U) { ... } else { hmsc->scsi_medium_state = SCSI_MEDIUM_LOCKED; }else { ... } hmsc->bot_data_length = 0U; return 0; }{ ... } /** * @brief SCSI_Read10 * Process Read10 command * @param lun: Logical unit number * @param params: Command parameters * @retval status *//* ... */ static int8_t SCSI_Read10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) { USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; if (hmsc == NULL) { return -1; }if (hmsc == NULL) { ... } if (hmsc->bot_state == USBD_BOT_IDLE) /* Idle */ { /* case 10 : Ho <> Di */ if ((hmsc->cbw.bmFlags & 0x80U) != 0x80U) { SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); return -1; }if ((hmsc->cbw.bmFlags & 0x80U) != 0x80U) { ... } if (hmsc->scsi_medium_state == SCSI_MEDIUM_EJECTED) { SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT); return -1; }if (hmsc->scsi_medium_state == SCSI_MEDIUM_EJECTED) { ... } if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->IsReady(lun) != 0) { SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT); return -1; }if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->IsReady(lun) != 0) { ... } hmsc->scsi_blk_addr = ((uint32_t)params[2] << 24) | ((uint32_t)params[3] << 16) | ((uint32_t)params[4] << 8) | (uint32_t)params[5]; hmsc->scsi_blk_len = ((uint32_t)params[7] << 8) | (uint32_t)params[8]; if (SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr, hmsc->scsi_blk_len) < 0) { return -1; /* error */ }if (SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr, hmsc->scsi_blk_len) < 0) { ... } /* cases 4,5 : Hi <> Dn */ if (hmsc->cbw.dDataLength != (hmsc->scsi_blk_len * hmsc->scsi_blk_size)) { SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); return -1; }if (hmsc->cbw.dDataLength != (hmsc->scsi_blk_len * hmsc->scsi_blk_size)) { ... } hmsc->bot_state = USBD_BOT_DATA_IN; ...} hmsc->bot_data_length = MSC_MEDIA_PACKET; return SCSI_ProcessRead(pdev, lun); }{ ... } /** * @brief SCSI_Read12 * Process Read12 command * @param lun: Logical unit number * @param params: Command parameters * @retval status *//* ... */ static int8_t SCSI_Read12(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) { USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; if (hmsc == NULL) { return -1; }if (hmsc == NULL) { ... } if (hmsc->bot_state == USBD_BOT_IDLE) /* Idle */ { /* case 10 : Ho <> Di */ if ((hmsc->cbw.bmFlags & 0x80U) != 0x80U) { SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); return -1; }if ((hmsc->cbw.bmFlags & 0x80U) != 0x80U) { ... } if (hmsc->scsi_medium_state == SCSI_MEDIUM_EJECTED) { SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT); return -1; }if (hmsc->scsi_medium_state == SCSI_MEDIUM_EJECTED) { ... } if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->IsReady(lun) != 0) { SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT); return -1; }if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->IsReady(lun) != 0) { ... } hmsc->scsi_blk_addr = ((uint32_t)params[2] << 24) | ((uint32_t)params[3] << 16) | ((uint32_t)params[4] << 8) | (uint32_t)params[5]; hmsc->scsi_blk_len = ((uint32_t)params[6] << 24) | ((uint32_t)params[7] << 16) | ((uint32_t)params[8] << 8) | (uint32_t)params[9]; if (SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr, hmsc->scsi_blk_len) < 0) { return -1; /* error */ }if (SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr, hmsc->scsi_blk_len) < 0) { ... } /* cases 4,5 : Hi <> Dn */ if (hmsc->cbw.dDataLength != (hmsc->scsi_blk_len * hmsc->scsi_blk_size)) { SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); return -1; }if (hmsc->cbw.dDataLength != (hmsc->scsi_blk_len * hmsc->scsi_blk_size)) { ... } hmsc->bot_state = USBD_BOT_DATA_IN; ...} hmsc->bot_data_length = MSC_MEDIA_PACKET; return SCSI_ProcessRead(pdev, lun); }{ ... } /** * @brief SCSI_Write10 * Process Write10 command * @param lun: Logical unit number * @param params: Command parameters * @retval status *//* ... */ static int8_t SCSI_Write10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) { USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; uint32_t len; if (hmsc == NULL) { return -1; }if (hmsc == NULL) { ... } #ifdef USE_USBD_COMPOSITE /* Get the Endpoints addresses allocated for this class instance */ MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);/* ... */ #endif /* USE_USBD_COMPOSITE */ if (hmsc->bot_state == USBD_BOT_IDLE) /* Idle */ { if (hmsc->cbw.dDataLength == 0U) { SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); return -1; }if (hmsc->cbw.dDataLength == 0U) { ... } /* case 8 : Hi <> Do */ if ((hmsc->cbw.bmFlags & 0x80U) == 0x80U) { SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); return -1; }if ((hmsc->cbw.bmFlags & 0x80U) == 0x80U) { ... } /* Check whether Media is ready */ if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->IsReady(lun) != 0) { SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT); return -1; }if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->IsReady(lun) != 0) { ... } /* Check If media is write-protected */ if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->IsWriteProtected(lun) != 0) { SCSI_SenseCode(pdev, lun, NOT_READY, WRITE_PROTECTED); return -1; }if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->IsWriteProtected(lun) != 0) { ... } hmsc->scsi_blk_addr = ((uint32_t)params[2] << 24) | ((uint32_t)params[3] << 16) | ((uint32_t)params[4] << 8) | (uint32_t)params[5]; hmsc->scsi_blk_len = ((uint32_t)params[7] << 8) | (uint32_t)params[8]; /* check if LBA address is in the right range */ if (SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr, hmsc->scsi_blk_len) < 0) { return -1; /* error */ }if (SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr, hmsc->scsi_blk_len) < 0) { ... } len = hmsc->scsi_blk_len * hmsc->scsi_blk_size; /* cases 3,11,13 : Hn,Ho <> D0 */ if (hmsc->cbw.dDataLength != len) { SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); return -1; }if (hmsc->cbw.dDataLength != len) { ... } len = MIN(len, MSC_MEDIA_PACKET); /* Prepare EP to receive first data packet */ hmsc->bot_state = USBD_BOT_DATA_OUT; (void)USBD_LL_PrepareReceive(pdev, MSCOutEpAdd, hmsc->bot_data, len); ...} else /* Write Process ongoing */ { return SCSI_ProcessWrite(pdev, lun); }else { ... } return 0; }{ ... } /** * @brief SCSI_Write12 * Process Write12 command * @param lun: Logical unit number * @param params: Command parameters * @retval status *//* ... */ static int8_t SCSI_Write12(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) { USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; uint32_t len; if (hmsc == NULL) { return -1; }if (hmsc == NULL) { ... } #ifdef USE_USBD_COMPOSITE /* Get the Endpoints addresses allocated for this class instance */ MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);/* ... */ #endif /* USE_USBD_COMPOSITE */ if (hmsc->bot_state == USBD_BOT_IDLE) /* Idle */ { if (hmsc->cbw.dDataLength == 0U) { SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); return -1; }if (hmsc->cbw.dDataLength == 0U) { ... } /* case 8 : Hi <> Do */ if ((hmsc->cbw.bmFlags & 0x80U) == 0x80U) { SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); return -1; }if ((hmsc->cbw.bmFlags & 0x80U) == 0x80U) { ... } /* Check whether Media is ready */ if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->IsReady(lun) != 0) { SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT); hmsc->bot_state = USBD_BOT_NO_DATA; return -1; }if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->IsReady(lun) != 0) { ... } /* Check If media is write-protected */ if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->IsWriteProtected(lun) != 0) { SCSI_SenseCode(pdev, lun, NOT_READY, WRITE_PROTECTED); hmsc->bot_state = USBD_BOT_NO_DATA; return -1; }if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->IsWriteProtected(lun) != 0) { ... } hmsc->scsi_blk_addr = ((uint32_t)params[2] << 24) | ((uint32_t)params[3] << 16) | ((uint32_t)params[4] << 8) | (uint32_t)params[5]; hmsc->scsi_blk_len = ((uint32_t)params[6] << 24) | ((uint32_t)params[7] << 16) | ((uint32_t)params[8] << 8) | (uint32_t)params[9]; /* check if LBA address is in the right range */ if (SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr, hmsc->scsi_blk_len) < 0) { return -1; /* error */ }if (SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr, hmsc->scsi_blk_len) < 0) { ... } len = hmsc->scsi_blk_len * hmsc->scsi_blk_size; /* cases 3,11,13 : Hn,Ho <> D0 */ if (hmsc->cbw.dDataLength != len) { SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); return -1; }if (hmsc->cbw.dDataLength != len) { ... } len = MIN(len, MSC_MEDIA_PACKET); /* Prepare EP to receive first data packet */ hmsc->bot_state = USBD_BOT_DATA_OUT; (void)USBD_LL_PrepareReceive(pdev, MSCOutEpAdd, hmsc->bot_data, len); ...} else /* Write Process ongoing */ { return SCSI_ProcessWrite(pdev, lun); }else { ... } return 0; }{ ... } /** * @brief SCSI_Verify10 * Process Verify10 command * @param lun: Logical unit number * @param params: Command parameters * @retval status *//* ... */ static int8_t SCSI_Verify10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) { USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; if (hmsc == NULL) { return -1; }if (hmsc == NULL) { ... } if ((params[1] & 0x02U) == 0x02U) { SCSI_SenseCode(pdev, lun, ILLEGAL_REQUEST, INVALID_FIELED_IN_COMMAND); return -1; /* Error, Verify Mode Not supported*/ }if ((params[1] & 0x02U) == 0x02U) { ... } if (SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr, hmsc->scsi_blk_len) < 0) { return -1; /* error */ }if (SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr, hmsc->scsi_blk_len) < 0) { ... } hmsc->bot_data_length = 0U; return 0; }{ ... } /** * @brief SCSI_CheckAddressRange * Check address range * @param lun: Logical unit number * @param blk_offset: first block address * @param blk_nbr: number of block to be processed * @retval status *//* ... */ static int8_t SCSI_CheckAddressRange(USBD_HandleTypeDef *pdev, uint8_t lun, uint32_t blk_offset, uint32_t blk_nbr) { USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; if (hmsc == NULL) { return -1; }if (hmsc == NULL) { ... } if ((blk_offset + blk_nbr) > hmsc->scsi_blk_nbr) { SCSI_SenseCode(pdev, lun, ILLEGAL_REQUEST, ADDRESS_OUT_OF_RANGE); return -1; }if ((blk_offset + blk_nbr) > hmsc->scsi_blk_nbr) { ... } return 0; }{ ... } /** * @brief SCSI_ProcessRead * Handle Read Process * @param lun: Logical unit number * @retval status *//* ... */ static int8_t SCSI_ProcessRead(USBD_HandleTypeDef *pdev, uint8_t lun) { USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; uint32_t len; if (hmsc == NULL) { return -1; }if (hmsc == NULL) { ... } len = hmsc->scsi_blk_len * hmsc->scsi_blk_size; #ifdef USE_USBD_COMPOSITE /* Get the Endpoints addresses allocated for this class instance */ MSCInEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_IN, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);/* ... */ #endif /* USE_USBD_COMPOSITE */ len = MIN(len, MSC_MEDIA_PACKET); if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->Read(lun, hmsc->bot_data, hmsc->scsi_blk_addr, (len / hmsc->scsi_blk_size)) < 0) { SCSI_SenseCode(pdev, lun, HARDWARE_ERROR, UNRECOVERED_READ_ERROR); return -1; }if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->Read(lun, hmsc->bot_data, hmsc->scsi_blk_addr, (len / hmsc->scsi_blk_size)) < 0) { ... } (void)USBD_LL_Transmit(pdev, MSCInEpAdd, hmsc->bot_data, len); hmsc->scsi_blk_addr += (len / hmsc->scsi_blk_size); hmsc->scsi_blk_len -= (len / hmsc->scsi_blk_size); /* case 6 : Hi = Di */ hmsc->csw.dDataResidue -= len; if (hmsc->scsi_blk_len == 0U) { hmsc->bot_state = USBD_BOT_LAST_DATA_IN; }if (hmsc->scsi_blk_len == 0U) { ... } return 0; }{ ... } /** * @brief SCSI_ProcessWrite * Handle Write Process * @param lun: Logical unit number * @retval status *//* ... */ static int8_t SCSI_ProcessWrite(USBD_HandleTypeDef *pdev, uint8_t lun) { USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId]; uint32_t len; if (hmsc == NULL) { return -1; }if (hmsc == NULL) { ... } len = hmsc->scsi_blk_len * hmsc->scsi_blk_size; #ifdef USE_USBD_COMPOSITE /* Get the Endpoints addresses allocated for this class instance */ MSCOutEpAdd = USBD_CoreGetEPAdd(pdev, USBD_EP_OUT, USBD_EP_TYPE_BULK, (uint8_t)pdev->classId);/* ... */ #endif /* USE_USBD_COMPOSITE */ len = MIN(len, MSC_MEDIA_PACKET); if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->Write(lun, hmsc->bot_data, hmsc->scsi_blk_addr, (len / hmsc->scsi_blk_size)) < 0) { SCSI_SenseCode(pdev, lun, HARDWARE_ERROR, WRITE_FAULT); return -1; }if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->Write(lun, hmsc->bot_data, hmsc->scsi_blk_addr, (len / hmsc->scsi_blk_size)) < 0) { ... } hmsc->scsi_blk_addr += (len / hmsc->scsi_blk_size); hmsc->scsi_blk_len -= (len / hmsc->scsi_blk_size); /* case 12 : Ho = Do */ hmsc->csw.dDataResidue -= len; if (hmsc->scsi_blk_len == 0U) { MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_PASSED); }if (hmsc->scsi_blk_len == 0U) { ... } else { len = MIN((hmsc->scsi_blk_len * hmsc->scsi_blk_size), MSC_MEDIA_PACKET); /* Prepare EP to Receive next packet */ (void)USBD_LL_PrepareReceive(pdev, MSCOutEpAdd, hmsc->bot_data, len); }else { ... } return 0; }{ ... } /** * @brief SCSI_UpdateBotData * fill the requested Data to transmit buffer * @param hmsc handler * @param pBuff: Data buffer * @param length: Data length * @retval status *//* ... */ static int8_t SCSI_UpdateBotData(USBD_MSC_BOT_HandleTypeDef *hmsc, uint8_t *pBuff, uint16_t length) { uint16_t len = length; if (hmsc == NULL) { return -1; }if (hmsc == NULL) { ... } hmsc->bot_data_length = len; while (len != 0U) { len--; hmsc->bot_data[len] = pBuff[len]; }while (len != 0U) { ... } return 0; }{ ... } /** * @} *//* ... */ /** * @} *//* ... */ /** * @} *//* ... */ Includes
Details
Show:
from
Types: Columns:
This file uses the notable symbols shown below. Click anywhere in the file to view more details.