PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
report_descriptor_init.c
1/*
2# _____ ___ ____ ___ ____
3# ____| | ____| | | |____|
4# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5#-----------------------------------------------------------------------
6# Copyright ps2dev - http://www.ps2dev.org
7# Licenced under Academic Free License version 2.0
8# Review ps2sdk README & LICENSE files for further details.
9*/
10
11#include "usbdpriv.h"
12
13int handleStaticDeviceDescriptor(UsbdDevice_t *dev, UsbDeviceDescriptor *devDescStart, UsbDeviceDescriptor *devDescEnd)
14{
15 UsbDeviceDescriptor *devDescCur;
16 u32 ifNum;
17 unsigned int bLength;
18 int i;
19 u32 wItemLength;
20 UsbdReportDescriptor_t *hidDescriptor;
21 int state;
22 u32 cfgNum;
23 UsbHidDescriptor *usbHidDescriptor;
24 const UsbConfigDescriptor *usbConfigDescriptor;
25 const UsbInterfaceDescriptor *usbInterfaceDescriptor;
26
27 dev->m_reportDescriptorStart = NULL;
28 dev->m_reportDescriptorEnd = NULL;
29 cfgNum = 0;
30 ifNum = 0;
31 for ( devDescCur = devDescStart; devDescCur < devDescEnd;
32 devDescCur = (UsbDeviceDescriptor *)((u8 *)devDescCur + bLength) )
33 {
34 bLength = devDescCur->bLength;
35 if ( bLength < 2 )
36 break;
37 if ( (u8 *)devDescEnd - (u8 *)devDescCur < (int)bLength )
38 break;
39 switch ( devDescCur->bDescriptorType )
40 {
41 case 1u:
42 case 3u:
43 case 5u:
44 case 6u:
45 case 7u:
46 case 8u:
47 case 9u:
48 case 0xAu:
49 case 0xBu:
50 case 0xCu:
51 case 0xDu:
52 case 0xEu:
53 case 0xFu:
54 case 0x10u:
55 case 0x11u:
56 case 0x12u:
57 case 0x13u:
58 case 0x14u:
59 case 0x15u:
60 case 0x16u:
61 case 0x17u:
62 case 0x18u:
63 case 0x19u:
64 case 0x1Au:
65 case 0x1Bu:
66 case 0x1Cu:
67 case 0x1Du:
68 case 0x1Eu:
69 case 0x1Fu:
70 case 0x20u:
71 break;
72 case 2u:
73 if ( (int)bLength >= 9 )
74 {
75 usbConfigDescriptor = (UsbConfigDescriptor *)devDescCur;
76 cfgNum = usbConfigDescriptor->bConfigurationValue;
77 }
78 break;
79 case 4u:
80 if ( (int)bLength >= 9 )
81 {
82 usbInterfaceDescriptor = (UsbInterfaceDescriptor *)devDescCur;
83 ifNum = usbInterfaceDescriptor->bInterfaceNumber;
84 }
85 break;
86 case 0x21u:
87 usbHidDescriptor = (UsbHidDescriptor *)devDescCur;
88 for ( i = 0; i < usbHidDescriptor->bNumDescriptors; i += 1 )
89 {
90 if ( usbHidDescriptor->items[i].bDescriptorType == 0x22 )
91 {
92 wItemLength =
93 usbHidDescriptor->items[i].wDescriptorLengthLb + (usbHidDescriptor->items[i].wDescriptorLengthHb << 8);
94 CpuSuspendIntr(&state);
95 hidDescriptor =
96 (UsbdReportDescriptor_t *)AllocSysMemory(ALLOC_FIRST, wItemLength + sizeof(UsbdReportDescriptor_t), NULL);
97 CpuResumeIntr(state);
98 hidDescriptor->m_ifNum = ifNum;
99 hidDescriptor->m_length = wItemLength;
100 hidDescriptor->m_cfgNum = cfgNum;
101 hidDescriptor->m_prev = dev->m_reportDescriptorEnd;
102 if ( dev->m_reportDescriptorEnd )
103 dev->m_reportDescriptorEnd->m_next = hidDescriptor;
104 else
105 dev->m_reportDescriptorStart = hidDescriptor;
106 hidDescriptor->m_next = NULL;
107 dev->m_reportDescriptorEnd = hidDescriptor;
108 }
109 }
110 break;
111 default:
112 break;
113 }
114 }
115 return 0;
116}
int CpuResumeIntr(int state)
Definition intrman.c:227
int CpuSuspendIntr(int *state)
Definition intrman.c:205