Revision 6e625fc7

b/hw/usb-desc.c
91 91
    dest[0x08] = conf->bMaxPower;
92 92
    wTotalLength += bLength;
93 93

  
94
    /* handle grouped interfaces if any*/
95
    for (i = 0; i < conf->nif_groups; i++) {
96
        rc = usb_desc_iface_group(&(conf->if_groups[i]),
97
                                  dest + wTotalLength,
98
                                  len - wTotalLength);
99
        if (rc < 0) {
100
            return rc;
101
        }
102
        wTotalLength += rc;
103
    }
104

  
105
    /* handle normal (ungrouped / no IAD) interfaces if any */
94 106
    for (i = 0; i < conf->nif; i++) {
95 107
        rc = usb_desc_iface(conf->ifs + i, dest + wTotalLength, len - wTotalLength);
96 108
        if (rc < 0) {
......
104 116
    return wTotalLength;
105 117
}
106 118

  
119
int usb_desc_iface_group(const USBDescIfaceAssoc *iad, uint8_t *dest,
120
                         size_t len)
121
{
122
    int pos = 0;
123
    int i = 0;
124

  
125
    /* handle interface association descriptor */
126
    uint8_t bLength = 0x08;
127

  
128
    if (len < bLength) {
129
        return -1;
130
    }
131

  
132
    dest[0x00] = bLength;
133
    dest[0x01] = USB_DT_INTERFACE_ASSOC;
134
    dest[0x02] = iad->bFirstInterface;
135
    dest[0x03] = iad->bInterfaceCount;
136
    dest[0x04] = iad->bFunctionClass;
137
    dest[0x05] = iad->bFunctionSubClass;
138
    dest[0x06] = iad->bFunctionProtocol;
139
    dest[0x07] = iad->iFunction;
140
    pos += bLength;
141

  
142
    /* handle associated interfaces in this group */
143
    for (i = 0; i < iad->nif; i++) {
144
        int rc = usb_desc_iface(&(iad->ifs[i]), dest + pos, len - pos);
145
        if (rc < 0) {
146
            return rc;
147
        }
148
        pos += rc;
149
    }
150

  
151
    return pos;
152
}
153

  
107 154
int usb_desc_iface(const USBDescIface *iface, uint8_t *dest, size_t len)
108 155
{
109 156
    uint8_t bLength = 0x09;
b/hw/usb-desc.h
30 30
    uint8_t                   bmAttributes;
31 31
    uint8_t                   bMaxPower;
32 32

  
33
    /* grouped interfaces */
34
    uint8_t                   nif_groups;
35
    const USBDescIfaceAssoc   *if_groups;
36

  
37
    /* "normal" interfaces */
38
    uint8_t                   nif;
39
    const USBDescIface        *ifs;
40
};
41

  
42
/* conceptually an Interface Association Descriptor, and releated interfaces */
43
struct USBDescIfaceAssoc {
44
    uint8_t                   bFirstInterface;
45
    uint8_t                   bInterfaceCount;
46
    uint8_t                   bFunctionClass;
47
    uint8_t                   bFunctionSubClass;
48
    uint8_t                   bFunctionProtocol;
49
    uint8_t                   iFunction;
50

  
33 51
    uint8_t                   nif;
34 52
    const USBDescIface        *ifs;
35 53
};
......
75 93
int usb_desc_device_qualifier(const USBDescDevice *dev,
76 94
                              uint8_t *dest, size_t len);
77 95
int usb_desc_config(const USBDescConfig *conf, uint8_t *dest, size_t len);
96
int usb_desc_iface_group(const USBDescIfaceAssoc *iad, uint8_t *dest,
97
                         size_t len);
78 98
int usb_desc_iface(const USBDescIface *iface, uint8_t *dest, size_t len);
79 99
int usb_desc_endpoint(const USBDescEndpoint *ep, uint8_t *dest, size_t len);
80 100
int usb_desc_other(const USBDescOther *desc, uint8_t *dest, size_t len);
b/hw/usb.h
141 141
typedef struct USBDescID USBDescID;
142 142
typedef struct USBDescDevice USBDescDevice;
143 143
typedef struct USBDescConfig USBDescConfig;
144
typedef struct USBDescIfaceAssoc USBDescIfaceAssoc;
144 145
typedef struct USBDescIface USBDescIface;
145 146
typedef struct USBDescEndpoint USBDescEndpoint;
146 147
typedef struct USBDescOther USBDescOther;

Also available in: Unified diff