2 * Copyright 2007-2008, Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * Michael Lotz <mmlr@mlotz.ch>
16 BUSBConfiguration::BUSBConfiguration(BUSBDevice
*device
, uint32 index
, int rawFD
)
21 fConfigurationString(NULL
)
23 usb_raw_command command
;
24 command
.config
.descriptor
= &fDescriptor
;
25 command
.config
.config_index
= fIndex
;
26 if (ioctl(fRawFD
, B_USB_RAW_COMMAND_GET_CONFIGURATION_DESCRIPTOR
, &command
,
27 sizeof(command
)) || command
.config
.status
!= B_USB_RAW_STATUS_SUCCESS
)
28 memset(&fDescriptor
, 0, sizeof(fDescriptor
));
30 fInterfaces
= new(std::nothrow
) BUSBInterface
*[
31 fDescriptor
.number_interfaces
];
32 if (fInterfaces
== NULL
)
35 for (uint32 i
= 0; i
< fDescriptor
.number_interfaces
; i
++) {
36 fInterfaces
[i
] = new(std::nothrow
) BUSBInterface(this, i
,
37 B_USB_RAW_ACTIVE_ALTERNATE
, fRawFD
);
42 BUSBConfiguration::~BUSBConfiguration()
44 delete[] fConfigurationString
;
45 if (fInterfaces
!= NULL
) {
46 for (int32 i
= 0; i
< fDescriptor
.number_interfaces
; i
++)
47 delete fInterfaces
[i
];
54 BUSBConfiguration::Index() const
61 BUSBConfiguration::Device() const
68 BUSBConfiguration::ConfigurationString() const
70 if (fDescriptor
.configuration
== 0)
73 if (fConfigurationString
)
74 return fConfigurationString
;
76 fConfigurationString
= Device()->DecodeStringDescriptor(
77 fDescriptor
.configuration
);
78 if (fConfigurationString
== NULL
)
81 return fConfigurationString
;
85 const usb_configuration_descriptor
*
86 BUSBConfiguration::Descriptor() const
93 BUSBConfiguration::CountInterfaces() const
95 return fDescriptor
.number_interfaces
;
100 BUSBConfiguration::InterfaceAt(uint32 index
) const
102 if (index
>= fDescriptor
.number_interfaces
|| fInterfaces
== NULL
)
105 return fInterfaces
[index
];