1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
27
28
29
30
31
32
35
36
39
40
43
44
48
49
50
53
56
57
60
63
64
67
70
71
72
75
76
79
80
81
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
105
106
107
110
113
114
115
118
124
125
126
127
128
129
130
131
132
133
134
135
142
143
144
145
146
147
148
149
150
151
152
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
174
178
182
185
186
187
193
194
195
196
197
198
199
200
201
207
208
209
210
211
212
213
214
220
221
222
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
257
258
262
263
264
265
266
267
268
269
270
271
272
277
278
279
285
286
287
288
289
290
291
292
293
299
300
301
302
303
304
305
306
312
313
314
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
343
344
345
346
347
348
349
350
356
357
358
359
360
361
362
363
364
365
366
367
368
369
375
376
377
378
379
380
381
382
383
389
390
391
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
417
421
422
423
424
425
426
427
428
434
435
436
440
441
442
446
448
449
450
451
452
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
509
510
511
512
513
514
515
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
543
547
548
549
550
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
618
625
626
627
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
661
662
663
664
665
666
667
668
669
670
671
672
673
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
739
740
741
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
766
770
774
778
782
786
790
795
798
802
807
809
810
811
812
813
820
821
822
823
824
825
826
827
828
829
830
831
835
836
837
838
839
840
841
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
876
877
878
879
880
881
882
883
884
885
891
892
893
894
901
902
903
904
905
906
907
912
913
914
915
922
923
924
925
926
927
928
933
934
935
936
941
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
984
985
986
987
991
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
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
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
1109
1110
1111
1112
1121
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
1171
1172
1173
1174
1183
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
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1236
1237
1238
1239
1248
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1301
1302
1303
1304
1313
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1370
1371
1372
1373
1384
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1437
1438
1439
1440
1449
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1499
1500
1501
1502
1506
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1644
1645
1646
1647
1663
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1717
1718
1719
1720
1729
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1785
1786
1787
1788
1797
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1863
1864
1865
1866
1875
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1935
1936
1937
1938
1942
1944
1945
1946
1947
1950
1951
1954
1955
1958
1959
1962
1963
1966
1967
1968
/* ... */
/* ... */
#include "usbh_mtp_ptp.h"
#include "usbh_mtp.h"
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
static void PTP_DecodeDeviceInfo(USBH_HandleTypeDef *phost, PTP_DeviceInfoTypedef *dev_info);
static void PTP_GetStorageIDs(USBH_HandleTypeDef *phost, PTP_StorageIDsTypedef *stor_ids);
static void PTP_GetStorageInfo(USBH_HandleTypeDef *phost, uint32_t storage_id, PTP_StorageInfoTypedef *stor_info);
static void PTP_GetObjectInfo(USBH_HandleTypeDef *phost, PTP_ObjectInfoTypedef *object_info);
static void PTP_GetObjectPropDesc(USBH_HandleTypeDef *phost, PTP_ObjectPropDescTypeDef *opd, uint32_t opdlen);
static void PTP_DecodeDeviceInfo(USBH_HandleTypeDef *phost, PTP_DeviceInfoTypedef *dev_info);
static void PTP_GetDevicePropValue(USBH_HandleTypeDef *phost, uint32_t *offset,
uint32_t total, PTP_PropertyValueTypedef *value, uint16_t datatype);
static uint32_t PTP_GetObjectPropList(USBH_HandleTypeDef *phost,
MTP_PropertiesTypedef *props,
uint32_t len);
static void PTP_BufferFullCallback(USBH_HandleTypeDef *phost);
static void PTP_GetString(uint8_t *str, uint8_t *data, uint16_t *len);
static uint32_t PTP_GetArray16(uint16_t *array, uint8_t *data, uint32_t offset);
static uint32_t PTP_GetArray32(uint32_t *array, uint8_t *data, uint32_t offset);
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
USBH_StatusTypeDef USBH_PTP_Init(USBH_HandleTypeDef *phost)
{
MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
MTP_Handle->ptp.state = PTP_IDLE;
MTP_Handle->ptp.req_state = PTP_REQ_SEND;
return USBH_OK;
}{ ... }
/* ... */
USBH_StatusTypeDef USBH_PTP_Process(USBH_HandleTypeDef *phost)
{
USBH_StatusTypeDef status = USBH_BUSY;
USBH_URBStateTypeDef URB_Status = USBH_URB_IDLE;
MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
PTP_ContainerTypedef ptp_container;
uint32_t len;
switch (MTP_Handle->ptp.state)
{
case PTP_IDLE:
break;
case PTP_IDLE:
case PTP_OP_REQUEST_STATE:
(void)USBH_BulkSendData(phost,
(uint8_t *)(void *) & (MTP_Handle->ptp.op_container),
(uint16_t)MTP_Handle->ptp.op_container.length,
MTP_Handle->DataOutPipe,
1U);
MTP_Handle->ptp.state = PTP_OP_REQUEST_WAIT_STATE;
break;
case PTP_OP_REQUEST_STATE:
case PTP_OP_REQUEST_WAIT_STATE:
URB_Status = USBH_LL_GetURBState(phost, MTP_Handle->DataOutPipe);
if (URB_Status == USBH_URB_DONE)
{
if (MTP_Handle->ptp.flags == PTP_DP_NODATA)
{
MTP_Handle->ptp.state = PTP_RESPONSE_STATE;
}if (MTP_Handle->ptp.flags == PTP_DP_NODATA) { ... }
else if (MTP_Handle->ptp.flags == PTP_DP_SENDDATA)
{
MTP_Handle->ptp.state = PTP_DATA_OUT_PHASE_STATE;
}else if (MTP_Handle->ptp.flags == PTP_DP_SENDDATA) { ... }
else if (MTP_Handle->ptp.flags == PTP_DP_GETDATA)
{
MTP_Handle->ptp.state = PTP_DATA_IN_PHASE_STATE;
}else if (MTP_Handle->ptp.flags == PTP_DP_GETDATA) { ... }
else
{
}else { ... }
#if (USBH_USE_OS == 1U)
phost->os_msg = (uint32_t)USBH_URB_EVENT;
#if (osCMSIS < 0x20000U)
(void)osMessagePut(phost->os_event, phost->os_msg, 0U);
#else
(void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, 0U);
#endif/* ... */
#endif
}if (URB_Status == USBH_URB_DONE) { ... }
else if (URB_Status == USBH_URB_NOTREADY)
{
MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
#if (USBH_USE_OS == 1U)
phost->os_msg = (uint32_t)USBH_URB_EVENT;
#if (osCMSIS < 0x20000U)
(void)osMessagePut(phost->os_event, phost->os_msg, 0U);
#else
(void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, 0U);
#endif/* ... */
#endif
}else if (URB_Status == USBH_URB_NOTREADY) { ... }
else if (URB_Status == USBH_URB_STALL)
{
MTP_Handle->ptp.state = PTP_ERROR;
#if (USBH_USE_OS == 1U)
phost->os_msg = (uint32_t)USBH_URB_EVENT;
#if (osCMSIS < 0x20000U)
(void)osMessagePut(phost->os_event, phost->os_msg, 0U);
#else
(void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, 0U);
#endif/* ... */
#endif
}else if (URB_Status == USBH_URB_STALL) { ... }
else
{
}else { ... }
break;
case PTP_OP_REQUEST_WAIT_STATE:
case PTP_DATA_OUT_PHASE_STATE:
(void)USBH_BulkSendData(phost,
MTP_Handle->ptp.data_ptr,
MTP_Handle->DataOutEpSize,
MTP_Handle->DataOutPipe,
1U);
MTP_Handle->ptp.state = PTP_DATA_OUT_PHASE_WAIT_STATE;
break;
case PTP_DATA_OUT_PHASE_STATE:
case PTP_DATA_OUT_PHASE_WAIT_STATE:
URB_Status = USBH_LL_GetURBState(phost, MTP_Handle->DataOutPipe);
if (URB_Status == USBH_URB_DONE)
{
if (MTP_Handle->ptp.data_length > MTP_Handle->DataOutEpSize)
{
MTP_Handle->ptp.data_ptr += MTP_Handle->DataOutEpSize;
MTP_Handle->ptp.data_length -= MTP_Handle->DataOutEpSize;
MTP_Handle->ptp.data_packet += MTP_Handle->DataOutEpSize;
if (MTP_Handle->ptp.data_packet >= PTP_USB_BULK_PAYLOAD_LEN_READ)
{
PTP_BufferFullCallback(phost);
MTP_Handle->ptp.data_packet = 0U;
MTP_Handle->ptp.iteration++;
}if (MTP_Handle->ptp.data_packet >= PTP_USB_BULK_PAYLOAD_LEN_READ) { ... }
}if (MTP_Handle->ptp.data_length > MTP_Handle->DataOutEpSize) { ... }
else
{
MTP_Handle->ptp.data_length = 0U;
}else { ... }
if (MTP_Handle->ptp.data_length > 0U)
{
(void)USBH_BulkSendData(phost,
MTP_Handle->ptp.data_ptr,
MTP_Handle->DataOutEpSize,
MTP_Handle->DataOutPipe,
1U);
}if (MTP_Handle->ptp.data_length > 0U) { ... }
else
{
MTP_Handle->ptp.state = PTP_RESPONSE_STATE;
}else { ... }
#if (USBH_USE_OS == 1U)
phost->os_msg = (uint32_t)USBH_URB_EVENT;
#if (osCMSIS < 0x20000U)
(void)osMessagePut(phost->os_event, phost->os_msg, 0U);
#else
(void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, 0U);
#endif/* ... */
#endif
}if (URB_Status == USBH_URB_DONE) { ... }
else if (URB_Status == USBH_URB_NOTREADY)
{
MTP_Handle->ptp.state = PTP_DATA_OUT_PHASE_STATE;
#if (USBH_USE_OS == 1U)
phost->os_msg = (uint32_t)USBH_URB_EVENT;
#if (osCMSIS < 0x20000U)
(void)osMessagePut(phost->os_event, phost->os_msg, 0U);
#else
(void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, 0U);
#endif/* ... */
#endif
}else if (URB_Status == USBH_URB_NOTREADY) { ... }
else if (URB_Status == USBH_URB_STALL)
{
MTP_Handle->ptp.state = PTP_ERROR;
#if (USBH_USE_OS == 1U)
phost->os_msg = (uint32_t)USBH_URB_EVENT;
#if (osCMSIS < 0x20000U)
(void)osMessagePut(phost->os_event, phost->os_msg, 0U);
#else
(void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, 0U);
#endif/* ... */
#endif
}else if (URB_Status == USBH_URB_STALL) { ... }
else
{
}else { ... }
break;
case PTP_DATA_OUT_PHASE_WAIT_STATE:
case PTP_DATA_IN_PHASE_STATE:
(void)USBH_BulkReceiveData(phost,
MTP_Handle->ptp.data_ptr,
MTP_Handle->DataInEpSize,
MTP_Handle->DataInPipe);
MTP_Handle->ptp.state = PTP_DATA_IN_PHASE_WAIT_STATE;
break;
case PTP_DATA_IN_PHASE_STATE:
case PTP_DATA_IN_PHASE_WAIT_STATE:
URB_Status = USBH_LL_GetURBState(phost, MTP_Handle->DataInPipe);
if (URB_Status == USBH_URB_DONE)
{
len = USBH_LL_GetLastXferSize(phost, MTP_Handle->DataInPipe);
if (MTP_Handle->ptp.data_packet_counter++ == 0U)
{
MTP_Handle->ptp.data_length = *(uint32_t *)(void *)(MTP_Handle->ptp.data_ptr);
MTP_Handle->ptp.iteration = 0U;
}if (MTP_Handle->ptp.data_packet_counter++ == 0U) { ... }
if ((len >= MTP_Handle->DataInEpSize) && (MTP_Handle->ptp.data_length > 0U))
{
MTP_Handle->ptp.data_ptr += len;
MTP_Handle->ptp.data_length -= len;
MTP_Handle->ptp.data_packet += len;
if (MTP_Handle->ptp.data_packet >= PTP_USB_BULK_PAYLOAD_LEN_READ)
{
PTP_BufferFullCallback(phost);
MTP_Handle->ptp.data_packet = 0U;
MTP_Handle->ptp.iteration++;
}if (MTP_Handle->ptp.data_packet >= PTP_USB_BULK_PAYLOAD_LEN_READ) { ... }
(void)USBH_BulkReceiveData(phost,
MTP_Handle->ptp.data_ptr,
MTP_Handle->DataInEpSize,
MTP_Handle->DataInPipe);
}if ((len >= MTP_Handle->DataInEpSize) && (MTP_Handle->ptp.data_length > 0U)) { ... }
else
{
MTP_Handle->ptp.data_length -= len;
MTP_Handle->ptp.state = PTP_RESPONSE_STATE;
#if (USBH_USE_OS == 1U)
phost->os_msg = (uint32_t)USBH_URB_EVENT;
#if (osCMSIS < 0x20000U)
(void)osMessagePut(phost->os_event, phost->os_msg, 0U);
#else
(void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, 0U);
#endif/* ... */
#endif
}else { ... }
}if (URB_Status == USBH_URB_DONE) { ... }
else if (URB_Status == USBH_URB_STALL)
{
MTP_Handle->ptp.state = PTP_ERROR;
#if (USBH_USE_OS == 1U)
phost->os_msg = (uint32_t)USBH_URB_EVENT;
#if (osCMSIS < 0x20000U)
(void)osMessagePut(phost->os_event, phost->os_msg, 0U);
#else
(void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, 0U);
#endif/* ... */
#endif
}else if (URB_Status == USBH_URB_STALL) { ... }
else
{
}else { ... }
break;
case PTP_DATA_IN_PHASE_WAIT_STATE:
case PTP_RESPONSE_STATE:
(void)USBH_BulkReceiveData(phost,
(uint8_t *)(void *) & (MTP_Handle->ptp.resp_container),
PTP_USB_BULK_REQ_RESP_MAX_LEN,
MTP_Handle->DataInPipe);
MTP_Handle->ptp.state = PTP_RESPONSE_WAIT_STATE;
break;
case PTP_RESPONSE_STATE:
case PTP_RESPONSE_WAIT_STATE:
URB_Status = USBH_LL_GetURBState(phost, MTP_Handle->DataInPipe);
if (URB_Status == USBH_URB_DONE)
{
(void)USBH_PTP_GetResponse(phost, &ptp_container);
if (ptp_container.Code == PTP_RC_OK)
{
status = USBH_OK;
}if (ptp_container.Code == PTP_RC_OK) { ... }
else
{
status = USBH_FAIL;
}else { ... }
MTP_Handle->ptp.req_state = PTP_REQ_SEND;
}if (URB_Status == USBH_URB_DONE) { ... }
else if (URB_Status == USBH_URB_STALL)
{
MTP_Handle->ptp.state = PTP_ERROR;
#if (USBH_USE_OS == 1U)
phost->os_msg = (uint32_t)USBH_URB_EVENT;
#if (osCMSIS < 0x20000U)
(void)osMessagePut(phost->os_event, phost->os_msg, 0U);
#else
(void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, 0U);
#endif/* ... */
#endif
}else if (URB_Status == USBH_URB_STALL) { ... }
else
{
}else { ... }
break;
case PTP_RESPONSE_WAIT_STATE:
case PTP_ERROR:
MTP_Handle->ptp.req_state = PTP_REQ_SEND;
break;
case PTP_ERROR:
default:
break;default
}switch (MTP_Handle->ptp.state) { ... }
return status;
}{ ... }
/* ... */
USBH_StatusTypeDef USBH_PTP_SendRequest(USBH_HandleTypeDef *phost, PTP_ContainerTypedef *req)
{
USBH_StatusTypeDef status = USBH_OK;
MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
(void)USBH_memset(&(MTP_Handle->ptp.op_container), 0, sizeof(PTP_OpContainerTypedef));
MTP_Handle->ptp.op_container.length = PTP_USB_BULK_REQ_LEN - ((sizeof(uint32_t) * (5U - (uint32_t)req->Nparam)));
MTP_Handle->ptp.op_container.type = PTP_USB_CONTAINER_COMMAND;
MTP_Handle->ptp.op_container.code = req->Code;
MTP_Handle->ptp.op_container.trans_id = req->Transaction_ID;
MTP_Handle->ptp.op_container.param1 = req->Param1;
MTP_Handle->ptp.op_container.param2 = req->Param2;
MTP_Handle->ptp.op_container.param3 = req->Param3;
MTP_Handle->ptp.op_container.param4 = req->Param4;
MTP_Handle->ptp.op_container.param5 = req->Param5;
return status;
}{ ... }
/* ... */
USBH_StatusTypeDef USBH_PTP_GetResponse(USBH_HandleTypeDef *phost, PTP_ContainerTypedef *resp)
{
USBH_StatusTypeDef status = USBH_OK;
MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
resp->Code = MTP_Handle->ptp.resp_container.code;
resp->SessionID = MTP_Handle->ptp.session_id;
resp->Transaction_ID = MTP_Handle->ptp.resp_container.trans_id;
resp->Param1 = MTP_Handle->ptp.resp_container.param1;
resp->Param2 = MTP_Handle->ptp.resp_container.param2;
resp->Param3 = MTP_Handle->ptp.resp_container.param3;
resp->Param4 = MTP_Handle->ptp.resp_container.param4;
resp->Param5 = MTP_Handle->ptp.resp_container.param5;
return status;
}{ ... }
/* ... */
static void PTP_BufferFullCallback(USBH_HandleTypeDef *phost)
{
MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
switch (MTP_Handle->ptp.data_container.code)
{
case PTP_OC_GetDeviceInfo:
PTP_DecodeDeviceInfo(phost, &(MTP_Handle->info.devinfo));
break;
case PTP_OC_GetDeviceInfo:
case PTP_OC_GetPartialObject:
case PTP_OC_GetObject:
if (MTP_Handle->ptp.iteration == 0U)
{
(void)USBH_memcpy(MTP_Handle->ptp.object_ptr, MTP_Handle->ptp.data_container.payload.data,
PTP_USB_BULK_PAYLOAD_LEN_READ);
MTP_Handle->ptp.data_ptr = (MTP_Handle->ptp.object_ptr + PTP_USB_BULK_PAYLOAD_LEN_READ);
}if (MTP_Handle->ptp.iteration == 0U) { ... }
break;
case PTP_OC_GetObject:
case PTP_OC_SendObject:
if (MTP_Handle->ptp.iteration == 0U)
{
MTP_Handle->ptp.data_ptr = (MTP_Handle->ptp.object_ptr + PTP_USB_BULK_PAYLOAD_LEN_READ);
}if (MTP_Handle->ptp.iteration == 0U) { ... }
break;
case PTP_OC_SendObject:
default:
break;
default
}switch (MTP_Handle->ptp.data_container.code) { ... }
}{ ... }
/* ... */
static void PTP_DecodeDeviceInfo(USBH_HandleTypeDef *phost, PTP_DeviceInfoTypedef *dev_info)
{
MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
uint8_t *data = MTP_Handle->ptp.data_container.payload.data;
uint32_t totallen;
uint16_t len;
USBH_DbgLog(" MTP device info size exceeds internal buffer size.\
only available data are decoded.");
if (MTP_Handle->ptp.iteration == 0U)
{
dev_info->StandardVersion = LE16(&data[PTP_di_StandardVersion]);
dev_info->VendorExtensionID = LE32(&data[PTP_di_VendorExtensionID]);
dev_info->VendorExtensionVersion = LE16(&data[PTP_di_VendorExtensionVersion]);
PTP_GetString(dev_info->VendorExtensionDesc, &data[PTP_di_VendorExtensionDesc], &len);
totallen = (uint32_t)(len * 2U) + 1U;
dev_info->FunctionalMode = LE16(&data[PTP_di_FunctionalMode + totallen]);
dev_info->OperationsSupported_len = PTP_GetArray16((uint16_t *)(void *)&dev_info->OperationsSupported,
data, PTP_di_OperationsSupported + totallen);
totallen = totallen + (dev_info->OperationsSupported_len * sizeof(uint16_t)) + sizeof(uint32_t);
dev_info->EventsSupported_len = PTP_GetArray16((uint16_t *)(void *)&dev_info->EventsSupported,
data, PTP_di_OperationsSupported + totallen);
totallen = totallen + (dev_info->EventsSupported_len * sizeof(uint16_t)) + sizeof(uint32_t);
dev_info->DevicePropertiesSupported_len = PTP_GetArray16((uint16_t *)(void *)&dev_info->DevicePropertiesSupported,
data, PTP_di_OperationsSupported + totallen);
totallen = totallen + (dev_info->DevicePropertiesSupported_len * sizeof(uint16_t)) + sizeof(uint32_t);
dev_info->CaptureFormats_len = PTP_GetArray16((uint16_t *)(void *)&dev_info->CaptureFormats,
data, PTP_di_OperationsSupported + totallen);
totallen = totallen + (dev_info->CaptureFormats_len * sizeof(uint16_t)) + sizeof(uint32_t);
dev_info->ImageFormats_len = PTP_GetArray16((uint16_t *)(void *)&dev_info->ImageFormats,
data, PTP_di_OperationsSupported + totallen);
totallen = totallen + (dev_info->ImageFormats_len * sizeof(uint16_t)) + sizeof(uint32_t);
PTP_GetString(dev_info->Manufacturer, &data[PTP_di_OperationsSupported + totallen], &len);
totallen += (uint32_t)(len * 2U) + 1U;
PTP_GetString(dev_info->Model, &data[PTP_di_OperationsSupported + totallen], &len);
totallen += (uint32_t)(len * 2U) + 1U;
PTP_GetString(dev_info->DeviceVersion, &data[PTP_di_OperationsSupported + totallen], &len);
totallen += (uint32_t)(len * 2U) + 1U;
PTP_GetString(dev_info->SerialNumber, &data[PTP_di_OperationsSupported + totallen], &len);
}if (MTP_Handle->ptp.iteration == 0U) { ... }
}{ ... }
/* ... */
static void PTP_GetStorageIDs(USBH_HandleTypeDef *phost, PTP_StorageIDsTypedef *stor_ids)
{
MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
uint8_t *data = MTP_Handle->ptp.data_container.payload.data;
stor_ids->n = PTP_GetArray32(stor_ids->Storage, data, 0U);
}{ ... }
/* ... */
static void PTP_GetStorageInfo(USBH_HandleTypeDef *phost, uint32_t storage_id, PTP_StorageInfoTypedef *stor_info)
{
UNUSED(storage_id);
MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
uint8_t *data = MTP_Handle->ptp.data_container.payload.data;
uint16_t len;
stor_info->StorageType = LE16(&data[PTP_si_StorageType]);
stor_info->FilesystemType = LE16(&data[PTP_si_FilesystemType]);
stor_info->AccessCapability = LE16(&data[PTP_si_AccessCapability]);
stor_info->MaxCapability = LE64(&data[PTP_si_MaxCapability]);
stor_info->FreeSpaceInBytes = LE64(&data[PTP_si_FreeSpaceInBytes]);
stor_info->FreeSpaceInImages = LE32(&data[PTP_si_FreeSpaceInImages]);
PTP_GetString(stor_info->StorageDescription, &data[PTP_si_StorageDescription], &len);
PTP_GetString(stor_info->VolumeLabel, &data[PTP_si_StorageDescription + (len * 2U) + 1U], &len);
}{ ... }
/* ... */
static void PTP_GetObjectInfo(USBH_HandleTypeDef *phost, PTP_ObjectInfoTypedef *object_info)
{
MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
uint8_t *data = MTP_Handle->ptp.data_container.payload.data;
uint16_t filenamelen;
object_info->StorageID = LE32(&data[PTP_oi_StorageID]);
object_info->ObjectFormat = LE16(&data[PTP_oi_ObjectFormat]);
object_info->ProtectionStatus = LE16(&data[PTP_oi_ProtectionStatus]);
object_info->ObjectCompressedSize = LE64(&data[PTP_oi_ObjectCompressedSize]);
if ((data[PTP_oi_filenamelen] == 0U) && (data[PTP_oi_filenamelen + 4U] != 0U))
{
data += 4;
}if ((data[PTP_oi_filenamelen] == 0U) && (data[PTP_oi_filenamelen + 4U] != 0U)) { ... }
object_info->ThumbFormat = LE16(&data[PTP_oi_ThumbFormat]);
object_info->ThumbCompressedSize = LE32(&data[PTP_oi_ThumbCompressedSize]);
object_info->ThumbPixWidth = LE32(&data[PTP_oi_ThumbPixWidth]);
object_info->ThumbPixHeight = LE32(&data[PTP_oi_ThumbPixHeight]);
object_info->ImagePixWidth = LE32(&data[PTP_oi_ImagePixWidth]);
object_info->ImagePixHeight = LE32(&data[PTP_oi_ImagePixHeight]);
object_info->ImageBitDepth = LE32(&data[PTP_oi_ImageBitDepth]);
object_info->ParentObject = LE32(&data[PTP_oi_ParentObject]);
object_info->AssociationType = LE16(&data[PTP_oi_AssociationType]);
object_info->AssociationDesc = LE32(&data[PTP_oi_AssociationDesc]);
object_info->SequenceNumber = LE32(&data[PTP_oi_SequenceNumber]);
PTP_GetString(object_info->Filename, &data[PTP_oi_filenamelen], &filenamelen);
}{ ... }
/* ... */
static void PTP_GetObjectPropDesc(USBH_HandleTypeDef *phost, PTP_ObjectPropDescTypeDef *opd, uint32_t opdlen)
{
MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
uint8_t *data = MTP_Handle->ptp.data_container.payload.data;
uint32_t offset = 0U, i;
opd->ObjectPropertyCode = LE16(&data[PTP_opd_ObjectPropertyCode]);
opd->DataType = LE16(&data[PTP_opd_DataType]);
opd->GetSet = *(uint8_t *)(&data[PTP_opd_GetSet]);
offset = PTP_opd_FactoryDefaultValue;
PTP_GetDevicePropValue(phost, &offset, opdlen, &opd->FactoryDefaultValue, opd->DataType);
opd->GroupCode = LE32(&data[offset]);
offset += sizeof(uint32_t);
opd->FormFlag = *(uint8_t *)(&data[offset]);
offset += sizeof(uint8_t);
switch (opd->FormFlag)
{
case PTP_OPFF_Range:
PTP_GetDevicePropValue(phost, &offset, opdlen, &opd->FORM.Range.MinimumValue, opd->DataType);
PTP_GetDevicePropValue(phost, &offset, opdlen, &opd->FORM.Range.MaximumValue, opd->DataType);
PTP_GetDevicePropValue(phost, &offset, opdlen, &opd->FORM.Range.StepSize, opd->DataType);
break;
case PTP_OPFF_Range:
case PTP_OPFF_Enumeration:
opd->FORM.Enum.NumberOfValues = LE16(&data[offset]);
offset += sizeof(uint16_t);
for (i = 0U; i < opd->FORM.Enum.NumberOfValues; i++)
{
PTP_GetDevicePropValue(phost, &offset, opdlen, &opd->FORM.Enum.SupportedValue[i], opd->DataType);
}for (i = 0U; i < opd->FORM.Enum.NumberOfValues; i++) { ... }
break;case PTP_OPFF_Enumeration:
default:
break;default
}switch (opd->FormFlag) { ... }
}{ ... }
/* ... */
static void PTP_GetDevicePropValue(USBH_HandleTypeDef *phost,
uint32_t *offset,
uint32_t total,
PTP_PropertyValueTypedef *value,
uint16_t datatype)
{
UNUSED(total);
MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
uint8_t *data = MTP_Handle->ptp.data_container.payload.data;
uint16_t len;
switch (datatype)
{
case PTP_DTC_INT8:
value->i8 = *(int8_t *)(void *) & (data[*offset]);
*offset += 1U;
break;case PTP_DTC_INT8:
case PTP_DTC_UINT8:
value->u8 = *(uint8_t *) & (data[*offset]);
*offset += 1U;
break;case PTP_DTC_UINT8:
case PTP_DTC_INT16:
value->i16 = *(int16_t *)(void *) & (data[*offset]);
*offset += 2U;
break;case PTP_DTC_INT16:
case PTP_DTC_UINT16:
value->u16 = LE16(&(data[*offset]));
*offset += 2U;
break;case PTP_DTC_UINT16:
case PTP_DTC_INT32:
value->i32 = *(int32_t *)(void *)(&(data[*offset]));
*offset += 4U;
break;case PTP_DTC_INT32:
case PTP_DTC_UINT32:
value->u32 = LE32(&(data[*offset]));
*offset += 4U;
break;case PTP_DTC_UINT32:
case PTP_DTC_INT64:
value->i64 = *(int64_t *)(void *)(&(data[*offset]));
*offset += 8U;
break;case PTP_DTC_INT64:
case PTP_DTC_UINT64:
value->u64 = LE64(&(data[*offset]));
*offset += 8U;
break;
case PTP_DTC_UINT64:
case PTP_DTC_UINT128:
*offset += 16U;
break;case PTP_DTC_UINT128:
case PTP_DTC_INT128:
*offset += 16U;
break;
case PTP_DTC_INT128:
case PTP_DTC_STR:
PTP_GetString((uint8_t *)(void *)value->str, (uint8_t *) & (data[*offset]), &len);
*offset += (uint32_t)(len * 2U) + 1U;
break;case PTP_DTC_STR:
default:
break;default
}switch (datatype) { ... }
}{ ... }
/* ... */
static uint32_t PTP_GetObjectPropList(USBH_HandleTypeDef *phost,
MTP_PropertiesTypedef *props,
uint32_t len)
{
MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
uint8_t *data = MTP_Handle->ptp.data_container.payload.data;
uint32_t prop_count;
uint32_t offset = 0U, i;
prop_count = LE32(data);
if (prop_count == 0U)
{
return 0U;
}if (prop_count == 0U) { ... }
data += sizeof(uint32_t);
len -= sizeof(uint32_t);
for (i = 0U; i < prop_count; i++)
{
if (len <= 0U)
{
return 0U;
}if (len <= 0U) { ... }
props[i].ObjectHandle = LE32(data);
data += sizeof(uint32_t);
len -= sizeof(uint32_t);
props[i].property = LE16(data);
data += sizeof(uint16_t);
len -= sizeof(uint16_t);
props[i].datatype = LE16(data);
data += sizeof(uint16_t);
len -= sizeof(uint16_t);
offset = 0U;
PTP_GetDevicePropValue(phost, &offset, len, &props[i].propval, props[i].datatype);
data += offset;
len -= offset;
}for (i = 0U; i < prop_count; i++) { ... }
return prop_count;
}{ ... }
/* ... */
static void PTP_GetString(uint8_t *str, uint8_t *data, uint16_t *len)
{
uint16_t strlength;
uint16_t idx;
*len = data[0];
strlength = (uint16_t)(2U * (uint32_t)data[0]);
data ++;
for (idx = 0U; idx < strlength; idx += 2U)
{
*str = data[idx];
str++;
}for (idx = 0U; idx < strlength; idx += 2U) { ... }
*str = 0U;
}{ ... }
/* ... */
static uint32_t PTP_GetArray16(uint16_t *array, uint8_t *data, uint32_t offset)
{
uint32_t size, idx = 0U;
size = LE32(&data[offset]);
while (size > idx)
{
array[idx] = (uint16_t)data[offset + (sizeof(uint16_t) * (idx + 2U))];
idx++;
}while (size > idx) { ... }
return size;
}{ ... }
/* ... */
static uint32_t PTP_GetArray32(uint32_t *array, uint8_t *data, uint32_t offset)
{
uint32_t size, idx = 0U;
size = LE32(&data[offset]);
while (size > idx)
{
array[idx] = LE32(&data[offset + (sizeof(uint32_t) * (idx + 1U))]);
idx++;
}while (size > idx) { ... }
return size;
}{ ... }
/* ... */
/* ... */
USBH_StatusTypeDef USBH_PTP_OpenSession(USBH_HandleTypeDef *phost, uint32_t session)
{
USBH_StatusTypeDef status = USBH_BUSY;
MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
PTP_ContainerTypedef ptp_container;
switch (MTP_Handle->ptp.req_state)
{
case PTP_REQ_SEND:
MTP_Handle->ptp.transaction_id = 0x00000000U;
MTP_Handle->ptp.session_id = session;
MTP_Handle->ptp.flags = PTP_DP_NODATA;
ptp_container.Code = PTP_OC_OpenSession;
ptp_container.SessionID = session;
ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++;
ptp_container.Param1 = session;
ptp_container.Nparam = 1U;
(void)USBH_PTP_SendRequest(phost, &ptp_container);
MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
status = USBH_BUSY;
#if (USBH_USE_OS == 1U)
phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT;
#if (osCMSIS < 0x20000U)
(void)osMessagePut(phost->os_event, phost->os_msg, 0U);
#else
(void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, 0U);
#endif/* ... */
#endif
break;
case PTP_REQ_SEND:
case PTP_REQ_WAIT:
status = USBH_PTP_Process(phost);
break;
case PTP_REQ_WAIT:
default:
break;default
}switch (MTP_Handle->ptp.req_state) { ... }
return status;
}{ ... }
/* ... */
USBH_StatusTypeDef USBH_PTP_GetDevicePropDesc(USBH_HandleTypeDef *phost,
uint16_t propcode,
PTP_DevicePropDescTypdef *devicepropertydesc)
{
USBH_StatusTypeDef status = USBH_BUSY;
MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
PTP_ContainerTypedef ptp_container;
uint8_t *data = MTP_Handle->ptp.data_container.payload.data;
switch (MTP_Handle->ptp.req_state)
{
case PTP_REQ_SEND:
MTP_Handle->ptp.flags = PTP_DP_GETDATA;
MTP_Handle->ptp.data_ptr = (uint8_t *)(void *) & (MTP_Handle->ptp.data_container);
MTP_Handle->ptp.data_length = 0U;
MTP_Handle->ptp.data_packet_counter = 0U;
MTP_Handle->ptp.data_packet = 0U;
ptp_container.Code = PTP_OC_GetDevicePropDesc;
ptp_container.SessionID = MTP_Handle->ptp.session_id;
ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++;
ptp_container.Param1 = propcode;
ptp_container.Nparam = 1U;
(void)USBH_PTP_SendRequest(phost, &ptp_container);
MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
status = USBH_BUSY;
#if (USBH_USE_OS == 1U)
phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT;
#if (osCMSIS < 0x20000U)
(void)osMessagePut(phost->os_event, phost->os_msg, 0U);
#else
(void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, 0U);
#endif/* ... */
#endif
break;
case PTP_REQ_SEND:
case PTP_REQ_WAIT:
status = USBH_PTP_Process(phost);
if (status == USBH_OK)
{
devicepropertydesc->DevicePropertyCode = LE16(&data[PTP_dpd_DevicePropertyCode]);
devicepropertydesc->DataType = LE16(&data[PTP_dpd_DataType]);
devicepropertydesc->GetSet = *(uint8_t *)(&data[PTP_dpd_GetSet]);
devicepropertydesc->FormFlag = PTP_DPFF_None;
}if (status == USBH_OK) { ... }
break;
case PTP_REQ_WAIT:
default:
break;default
}switch (MTP_Handle->ptp.req_state) { ... }
return status;
}{ ... }
/* ... */
USBH_StatusTypeDef USBH_PTP_GetDeviceInfo(USBH_HandleTypeDef *phost, PTP_DeviceInfoTypedef *dev_info)
{
USBH_StatusTypeDef status = USBH_BUSY;
MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
PTP_ContainerTypedef ptp_container;
switch (MTP_Handle->ptp.req_state)
{
case PTP_REQ_SEND:
MTP_Handle->ptp.flags = PTP_DP_GETDATA;
MTP_Handle->ptp.data_ptr = (uint8_t *)(void *) & (MTP_Handle->ptp.data_container);
MTP_Handle->ptp.data_length = 0U;
MTP_Handle->ptp.data_packet_counter = 0U;
MTP_Handle->ptp.data_packet = 0U;
ptp_container.Code = PTP_OC_GetDeviceInfo;
ptp_container.SessionID = MTP_Handle->ptp.session_id;
ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id++;
ptp_container.Nparam = 0U;
(void)USBH_PTP_SendRequest(phost, &ptp_container);
MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
status = USBH_BUSY;
#if (USBH_USE_OS == 1U)
phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT;
#if (osCMSIS < 0x20000U)
(void)osMessagePut(phost->os_event, phost->os_msg, 0U);
#else
(void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, 0U);
#endif/* ... */
#endif
break;
case PTP_REQ_SEND:
case PTP_REQ_WAIT:
status = USBH_PTP_Process(phost);
if (status == USBH_OK)
{
PTP_DecodeDeviceInfo(phost, dev_info);
}if (status == USBH_OK) { ... }
break;
case PTP_REQ_WAIT:
default:
break;default
}switch (MTP_Handle->ptp.req_state) { ... }
return status;
}{ ... }
/* ... */
USBH_StatusTypeDef USBH_PTP_GetStorageIds(USBH_HandleTypeDef *phost, PTP_StorageIDsTypedef *storage_ids)
{
USBH_StatusTypeDef status = USBH_BUSY;
MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
PTP_ContainerTypedef ptp_container;
switch (MTP_Handle->ptp.req_state)
{
case PTP_REQ_SEND:
MTP_Handle->ptp.flags = PTP_DP_GETDATA;
MTP_Handle->ptp.data_ptr = (uint8_t *)(void *) & (MTP_Handle->ptp.data_container);
MTP_Handle->ptp.data_length = 0U;
MTP_Handle->ptp.data_packet_counter = 0U;
MTP_Handle->ptp.data_packet = 0U;
ptp_container.Code = PTP_OC_GetStorageIDs;
ptp_container.SessionID = MTP_Handle->ptp.session_id;
ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id++;
ptp_container.Nparam = 0U;
(void)USBH_PTP_SendRequest(phost, &ptp_container);
MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
status = USBH_BUSY;
#if (USBH_USE_OS == 1U)
phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT;
#if (osCMSIS < 0x20000U)
(void)osMessagePut(phost->os_event, phost->os_msg, 0U);
#else
(void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, 0U);
#endif/* ... */
#endif
break;
case PTP_REQ_SEND:
case PTP_REQ_WAIT:
status = USBH_PTP_Process(phost);
if (status == USBH_OK)
{
PTP_GetStorageIDs(phost, storage_ids);
}if (status == USBH_OK) { ... }
break;
case PTP_REQ_WAIT:
default:
break;default
}switch (MTP_Handle->ptp.req_state) { ... }
return status;
}{ ... }
/* ... */
USBH_StatusTypeDef USBH_PTP_GetStorageInfo(USBH_HandleTypeDef *phost,
uint32_t storage_id,
PTP_StorageInfoTypedef *storage_info)
{
USBH_StatusTypeDef status = USBH_BUSY;
MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
PTP_ContainerTypedef ptp_container;
switch (MTP_Handle->ptp.req_state)
{
case PTP_REQ_SEND:
MTP_Handle->ptp.flags = PTP_DP_GETDATA;
MTP_Handle->ptp.data_ptr = (uint8_t *)(void *) & (MTP_Handle->ptp.data_container);
MTP_Handle->ptp.data_length = 0U;
MTP_Handle->ptp.data_packet_counter = 0U;
MTP_Handle->ptp.data_packet = 0U;
ptp_container.Code = PTP_OC_GetStorageInfo;
ptp_container.SessionID = MTP_Handle->ptp.session_id;
ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id++;
ptp_container.Param1 = storage_id;
ptp_container.Nparam = 1U;
(void)USBH_PTP_SendRequest(phost, &ptp_container);
MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
status = USBH_BUSY;
#if (USBH_USE_OS == 1U)
phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT;
#if (osCMSIS < 0x20000U)
(void)osMessagePut(phost->os_event, phost->os_msg, 0U);
#else
(void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, 0U);
#endif/* ... */
#endif
break;
case PTP_REQ_SEND:
case PTP_REQ_WAIT:
status = USBH_PTP_Process(phost);
if (status == USBH_OK)
{
PTP_GetStorageInfo(phost, storage_id, storage_info);
}if (status == USBH_OK) { ... }
break;
case PTP_REQ_WAIT:
default:
break;default
}switch (MTP_Handle->ptp.req_state) { ... }
return status;
}{ ... }
/* ... */
USBH_StatusTypeDef USBH_PTP_GetNumObjects(USBH_HandleTypeDef *phost,
uint32_t storage_id,
uint32_t objectformatcode,
uint32_t associationOH,
uint32_t *numobs)
{
USBH_StatusTypeDef status = USBH_BUSY;
MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
PTP_ContainerTypedef ptp_container;
switch (MTP_Handle->ptp.req_state)
{
case PTP_REQ_SEND:
MTP_Handle->ptp.flags = PTP_DP_NODATA;
ptp_container.Code = PTP_OC_GetNumObjects;
ptp_container.SessionID = MTP_Handle->ptp.session_id;
ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id++;
ptp_container.Param1 = storage_id;
ptp_container.Param2 = objectformatcode;
ptp_container.Param3 = associationOH;
ptp_container.Nparam = 3U;
(void)USBH_PTP_SendRequest(phost, &ptp_container);
MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
status = USBH_BUSY;
#if (USBH_USE_OS == 1U)
phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT;
#if (osCMSIS < 0x20000U)
(void)osMessagePut(phost->os_event, phost->os_msg, 0U);
#else
(void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, 0U);
#endif/* ... */
#endif
break;
case PTP_REQ_SEND:
case PTP_REQ_WAIT:
status = USBH_PTP_Process(phost);
if (status == USBH_OK)
{
*numobs = MTP_Handle->ptp.resp_container.param1;
}if (status == USBH_OK) { ... }
break;
case PTP_REQ_WAIT:
default:
break;default
}switch (MTP_Handle->ptp.req_state) { ... }
return status;
}{ ... }
/* ... */
USBH_StatusTypeDef USBH_PTP_GetObjectHandles(USBH_HandleTypeDef *phost,
uint32_t storage_id,
uint32_t objectformatcode,
uint32_t associationOH,
PTP_ObjectHandlesTypedef *objecthandles)
{
USBH_StatusTypeDef status = USBH_BUSY;
MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
PTP_ContainerTypedef ptp_container;
switch (MTP_Handle->ptp.req_state)
{
case PTP_REQ_SEND:
MTP_Handle->ptp.flags = PTP_DP_GETDATA;
MTP_Handle->ptp.data_ptr = (uint8_t *)(void *) & (MTP_Handle->ptp.data_container);
MTP_Handle->ptp.data_length = 0U;
MTP_Handle->ptp.data_packet_counter = 0U;
MTP_Handle->ptp.data_packet = 0U;
ptp_container.Code = PTP_OC_GetObjectHandles;
ptp_container.SessionID = MTP_Handle->ptp.session_id;
ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id++;
ptp_container.Param1 = storage_id;
ptp_container.Param2 = objectformatcode;
ptp_container.Param3 = associationOH;
ptp_container.Nparam = 3U;
(void)USBH_PTP_SendRequest(phost, &ptp_container);
MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
status = USBH_BUSY;
#if (USBH_USE_OS == 1U)
phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT;
#if (osCMSIS < 0x20000U)
(void)osMessagePut(phost->os_event, phost->os_msg, 0U);
#else
(void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, 0U);
#endif/* ... */
#endif
break;
case PTP_REQ_SEND:
case PTP_REQ_WAIT:
status = USBH_PTP_Process(phost);
if (status == USBH_OK)
{
objecthandles->n = PTP_GetArray32(objecthandles->Handler,
MTP_Handle->ptp.data_container.payload.data,
0U);
}if (status == USBH_OK) { ... }
break;
case PTP_REQ_WAIT:
default:
break;default
}switch (MTP_Handle->ptp.req_state) { ... }
return status;
}{ ... }
/* ... */
USBH_StatusTypeDef USBH_PTP_GetObjectInfo(USBH_HandleTypeDef *phost,
uint32_t handle,
PTP_ObjectInfoTypedef *object_info)
{
USBH_StatusTypeDef status = USBH_BUSY;
MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
PTP_ContainerTypedef ptp_container;
switch (MTP_Handle->ptp.req_state)
{
case PTP_REQ_SEND:
MTP_Handle->ptp.flags = PTP_DP_GETDATA;
MTP_Handle->ptp.data_ptr = (uint8_t *)(void *) & (MTP_Handle->ptp.data_container);
MTP_Handle->ptp.data_length = 0U;
MTP_Handle->ptp.data_packet_counter = 0U;
MTP_Handle->ptp.data_packet = 0U;
ptp_container.Code = PTP_OC_GetObjectInfo;
ptp_container.SessionID = MTP_Handle->ptp.session_id;
ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id++;
ptp_container.Param1 = handle;
ptp_container.Nparam = 1U;
(void)USBH_PTP_SendRequest(phost, &ptp_container);
MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
status = USBH_BUSY;
#if (USBH_USE_OS == 1U)
phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT;
#if (osCMSIS < 0x20000U)
(void)osMessagePut(phost->os_event, phost->os_msg, 0U);
#else
(void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, 0U);
#endif/* ... */
#endif
break;
case PTP_REQ_SEND:
case PTP_REQ_WAIT:
status = USBH_PTP_Process(phost);
if (status == USBH_OK)
{
PTP_GetObjectInfo(phost, object_info);
}if (status == USBH_OK) { ... }
break;
case PTP_REQ_WAIT:
default:
break;default
}switch (MTP_Handle->ptp.req_state) { ... }
return status;
}{ ... }
/* ... */
USBH_StatusTypeDef USBH_PTP_DeleteObject(USBH_HandleTypeDef *phost,
uint32_t handle,
uint32_t objectformatcode)
{
USBH_StatusTypeDef status = USBH_BUSY;
MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
PTP_ContainerTypedef ptp_container;
switch (MTP_Handle->ptp.req_state)
{
case PTP_REQ_SEND:
MTP_Handle->ptp.flags = PTP_DP_NODATA;
ptp_container.Code = PTP_OC_DeleteObject;
ptp_container.SessionID = MTP_Handle->ptp.session_id;
ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id++;
ptp_container.Param1 = handle;
ptp_container.Param2 = objectformatcode;
ptp_container.Nparam = 2U;
(void)USBH_PTP_SendRequest(phost, &ptp_container);
MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
status = USBH_BUSY;
#if (USBH_USE_OS == 1U)
phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT;
#if (osCMSIS < 0x20000U)
(void)osMessagePut(phost->os_event, phost->os_msg, 0U);
#else
(void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, 0U);
#endif/* ... */
#endif
break;
case PTP_REQ_SEND:
case PTP_REQ_WAIT:
status = USBH_PTP_Process(phost);
break;
case PTP_REQ_WAIT:
default:
break;default
}switch (MTP_Handle->ptp.req_state) { ... }
return status;
}{ ... }
/* ... */
USBH_StatusTypeDef USBH_PTP_GetObject(USBH_HandleTypeDef *phost,
uint32_t handle,
uint8_t *object)
{
USBH_StatusTypeDef status = USBH_BUSY;
MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
PTP_ContainerTypedef ptp_container;
switch (MTP_Handle->ptp.req_state)
{
case PTP_REQ_SEND:
MTP_Handle->ptp.flags = PTP_DP_GETDATA;
MTP_Handle->ptp.data_ptr = (uint8_t *)(void *) & (MTP_Handle->ptp.data_container);
MTP_Handle->ptp.data_length = 0U;
MTP_Handle->ptp.data_packet_counter = 0U;
MTP_Handle->ptp.data_packet = 0U;
MTP_Handle->ptp.object_ptr = object;
ptp_container.Code = PTP_OC_GetObject;
ptp_container.SessionID = MTP_Handle->ptp.session_id;
ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id++;
ptp_container.Param1 = handle;
ptp_container.Nparam = 1U;
(void)USBH_PTP_SendRequest(phost, &ptp_container);
MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
status = USBH_BUSY;
#if (USBH_USE_OS == 1U)
phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT;
#if (osCMSIS < 0x20000U)
(void)osMessagePut(phost->os_event, phost->os_msg, 0U);
#else
(void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, 0U);
#endif/* ... */
#endif
break;
case PTP_REQ_SEND:
case PTP_REQ_WAIT:
status = USBH_PTP_Process(phost);
if (status == USBH_OK)
{
if (MTP_Handle->ptp.iteration == 0U)
{
(void)USBH_memcpy(MTP_Handle->ptp.object_ptr,
MTP_Handle->ptp.data_container.payload.data,
PTP_USB_BULK_PAYLOAD_LEN_READ);
}if (MTP_Handle->ptp.iteration == 0U) { ... }
}if (status == USBH_OK) { ... }
break;
case PTP_REQ_WAIT:
default:
break;default
}switch (MTP_Handle->ptp.req_state) { ... }
return status;
}{ ... }
/* ... */
USBH_StatusTypeDef USBH_PTP_GetPartialObject(USBH_HandleTypeDef *phost,
uint32_t handle,
uint32_t offset,
uint32_t maxbytes,
uint8_t *object,
uint32_t *len)
{
USBH_StatusTypeDef status = USBH_BUSY;
MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
PTP_ContainerTypedef ptp_container;
switch (MTP_Handle->ptp.req_state)
{
case PTP_REQ_SEND:
MTP_Handle->ptp.flags = PTP_DP_GETDATA;
MTP_Handle->ptp.data_ptr = (uint8_t *)(void *) & (MTP_Handle->ptp.data_container);
MTP_Handle->ptp.data_length = 0U;
MTP_Handle->ptp.data_packet_counter = 0U;
MTP_Handle->ptp.data_packet = 0U;
MTP_Handle->ptp.object_ptr = object;
ptp_container.Code = PTP_OC_GetPartialObject;
ptp_container.SessionID = MTP_Handle->ptp.session_id;
ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id++;
ptp_container.Param1 = handle;
ptp_container.Param2 = offset;
ptp_container.Param3 = maxbytes;
ptp_container.Nparam = 3U;
(void)USBH_PTP_SendRequest(phost, &ptp_container);
MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
status = USBH_BUSY;
#if (USBH_USE_OS == 1U)
phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT;
#if (osCMSIS < 0x20000U)
(void)osMessagePut(phost->os_event, phost->os_msg, 0U);
#else
(void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, 0U);
#endif/* ... */
#endif
break;
case PTP_REQ_SEND:
case PTP_REQ_WAIT:
status = USBH_PTP_Process(phost);
if (status == USBH_OK)
{
*len = MTP_Handle->ptp.resp_container.param1;
if (MTP_Handle->ptp.iteration == 0U)
{
(void)USBH_memcpy(MTP_Handle->ptp.object_ptr,
MTP_Handle->ptp.data_container.payload.data, *len);
}if (MTP_Handle->ptp.iteration == 0U) { ... }
}if (status == USBH_OK) { ... }
break;
case PTP_REQ_WAIT:
default:
break;default
}switch (MTP_Handle->ptp.req_state) { ... }
return status;
}{ ... }
/* ... */
USBH_StatusTypeDef USBH_PTP_GetObjectPropsSupported(USBH_HandleTypeDef *phost,
uint16_t ofc,
uint32_t *propnum,
uint16_t *props)
{
USBH_StatusTypeDef status = USBH_BUSY;
MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
PTP_ContainerTypedef ptp_container;
switch (MTP_Handle->ptp.req_state)
{
case PTP_REQ_SEND:
MTP_Handle->ptp.flags = PTP_DP_GETDATA;
MTP_Handle->ptp.data_ptr = (uint8_t *)(void *) & (MTP_Handle->ptp.data_container);
MTP_Handle->ptp.data_length = 0U;
MTP_Handle->ptp.data_packet_counter = 0U;
MTP_Handle->ptp.data_packet = 0U;
ptp_container.Code = PTP_OC_GetObjectPropsSupported;
ptp_container.SessionID = MTP_Handle->ptp.session_id;
ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id++;
ptp_container.Param1 = ofc;
ptp_container.Nparam = 1U;
(void)USBH_PTP_SendRequest(phost, &ptp_container);
MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
status = USBH_BUSY;
#if (USBH_USE_OS == 1U)
phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT;
#if (osCMSIS < 0x20000U)
(void)osMessagePut(phost->os_event, phost->os_msg, 0U);
#else
(void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, 0U);
#endif/* ... */
#endif
break;
case PTP_REQ_SEND:
case PTP_REQ_WAIT:
status = USBH_PTP_Process(phost);
if (status == USBH_OK)
{
*propnum = PTP_GetArray16(props, MTP_Handle->ptp.data_container.payload.data, 0U);
}if (status == USBH_OK) { ... }
break;
case PTP_REQ_WAIT:
default:
break;default
}switch (MTP_Handle->ptp.req_state) { ... }
return status;
}{ ... }
/* ... */
USBH_StatusTypeDef USBH_PTP_GetObjectPropDesc(USBH_HandleTypeDef *phost,
uint16_t opc,
uint16_t ofc,
PTP_ObjectPropDescTypeDef *opd)
{
USBH_StatusTypeDef status = USBH_BUSY;
MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
PTP_ContainerTypedef ptp_container;
switch (MTP_Handle->ptp.req_state)
{
case PTP_REQ_SEND:
MTP_Handle->ptp.flags = PTP_DP_GETDATA;
MTP_Handle->ptp.data_ptr = (uint8_t *)(void *) & (MTP_Handle->ptp.data_container);
MTP_Handle->ptp.data_length = 0U;
MTP_Handle->ptp.data_packet_counter = 0U;
MTP_Handle->ptp.data_packet = 0U;
ptp_container.Code = PTP_OC_GetObjectPropDesc;
ptp_container.SessionID = MTP_Handle->ptp.session_id;
ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id++;
ptp_container.Param1 = opc;
ptp_container.Param2 = ofc;
ptp_container.Nparam = 2U;
(void)USBH_PTP_SendRequest(phost, &ptp_container);
MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
status = USBH_BUSY;
#if (USBH_USE_OS == 1U)
phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT;
#if (osCMSIS < 0x20000U)
(void)osMessagePut(phost->os_event, phost->os_msg, 0U);
#else
(void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, 0U);
#endif/* ... */
#endif
break;
case PTP_REQ_SEND:
case PTP_REQ_WAIT:
status = USBH_PTP_Process(phost);
if (status == USBH_OK)
{
PTP_GetObjectPropDesc(phost, opd, MTP_Handle->ptp.data_length);
}if (status == USBH_OK) { ... }
break;
case PTP_REQ_WAIT:
default:
break;default
}switch (MTP_Handle->ptp.req_state) { ... }
return status;
}{ ... }
/* ... */
USBH_StatusTypeDef USBH_PTP_GetObjectPropList(USBH_HandleTypeDef *phost,
uint32_t handle,
MTP_PropertiesTypedef *pprops,
uint32_t *nrofprops)
{
UNUSED(nrofprops);
USBH_StatusTypeDef status = USBH_BUSY;
MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
PTP_ContainerTypedef ptp_container;
switch (MTP_Handle->ptp.req_state)
{
case PTP_REQ_SEND:
MTP_Handle->ptp.flags = PTP_DP_GETDATA;
MTP_Handle->ptp.data_ptr = (uint8_t *)(void *) & (MTP_Handle->ptp.data_container);
MTP_Handle->ptp.data_length = 0U;
MTP_Handle->ptp.data_packet_counter = 0U;
MTP_Handle->ptp.data_packet = 0U;
(void)USBH_memcpy(MTP_Handle->ptp.data_container.payload.data,
MTP_Handle->ptp.object_ptr, PTP_USB_BULK_PAYLOAD_LEN_READ);
ptp_container.Code = PTP_OC_GetObjPropList;
ptp_container.SessionID = MTP_Handle->ptp.session_id;
ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id++;
ptp_container.Param1 = handle;
ptp_container.Param2 = 0x00000000U;
ptp_container.Param3 = 0xFFFFFFFFU;
ptp_container.Param4 = 0x00000000U;
ptp_container.Param5 = 0xFFFFFFFFU;
ptp_container.Nparam = 5U;
(void)USBH_PTP_SendRequest(phost, &ptp_container);
MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
status = USBH_BUSY;
#if (USBH_USE_OS == 1U)
phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT;
#if (osCMSIS < 0x20000U)
(void)osMessagePut(phost->os_event, phost->os_msg, 0U);
#else
(void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, 0U);
#endif/* ... */
#endif
break;
case PTP_REQ_SEND:
case PTP_REQ_WAIT:
status = USBH_PTP_Process(phost);
if (status == USBH_OK)
{
(void)PTP_GetObjectPropList(phost, pprops, MTP_Handle->ptp.data_length);
}if (status == USBH_OK) { ... }
break;
case PTP_REQ_WAIT:
default:
break;default
}switch (MTP_Handle->ptp.req_state) { ... }
return status;
}{ ... }
/* ... */
USBH_StatusTypeDef USBH_PTP_SendObject(USBH_HandleTypeDef *phost,
uint32_t handle,
uint8_t *object,
uint32_t size)
{
UNUSED(handle);
USBH_StatusTypeDef status = USBH_BUSY;
MTP_HandleTypeDef *MTP_Handle = (MTP_HandleTypeDef *)phost->pActiveClass->pData;
PTP_ContainerTypedef ptp_container;
switch (MTP_Handle->ptp.req_state)
{
case PTP_REQ_SEND:
MTP_Handle->ptp.flags = PTP_DP_SENDDATA;
MTP_Handle->ptp.data_ptr = (uint8_t *)(void *) & (MTP_Handle->ptp.data_container);
MTP_Handle->ptp.data_packet_counter = 0U;
MTP_Handle->ptp.data_packet = 0U;
MTP_Handle->ptp.iteration = 0U;
MTP_Handle->ptp.object_ptr = object;
MTP_Handle->ptp.data_length = size;
ptp_container.Code = PTP_OC_SendObject;
ptp_container.SessionID = MTP_Handle->ptp.session_id;
ptp_container.Transaction_ID = MTP_Handle->ptp.transaction_id ++;
ptp_container.Nparam = 0U;
(void)USBH_PTP_SendRequest(phost, &ptp_container);
MTP_Handle->ptp.state = PTP_OP_REQUEST_STATE;
MTP_Handle->ptp.req_state = PTP_REQ_WAIT;
status = USBH_BUSY;
#if (USBH_USE_OS == 1U)
phost->os_msg = (uint32_t)USBH_STATE_CHANGED_EVENT;
#if (osCMSIS < 0x20000U)
(void)osMessagePut(phost->os_event, phost->os_msg, 0U);
#else
(void)osMessageQueuePut(phost->os_event, &phost->os_msg, 0U, 0U);
#endif/* ... */
#endif
break;
case PTP_REQ_SEND:
case PTP_REQ_WAIT:
status = USBH_PTP_Process(phost);
break;
case PTP_REQ_WAIT:
default:
break;default
}switch (MTP_Handle->ptp.req_state) { ... }
return status;
}{ ... }
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
Includes