|
@@ -843,12 +843,40 @@ int usb_control ( struct usb_device *usb, unsigned int request,
|
843
|
843
|
return rc;
|
844
|
844
|
}
|
845
|
845
|
|
|
846
|
+/**
|
|
847
|
+ * Get default language ID
|
|
848
|
+ *
|
|
849
|
+ * @v usb USB device
|
|
850
|
+ * @ret language Language ID
|
|
851
|
+ */
|
|
852
|
+static unsigned int usb_get_default_language ( struct usb_device *usb ) {
|
|
853
|
+ struct {
|
|
854
|
+ struct usb_descriptor_header header;
|
|
855
|
+ uint16_t language[1];
|
|
856
|
+ } __attribute__ (( packed )) desc;
|
|
857
|
+ unsigned int language;
|
|
858
|
+ int rc;
|
|
859
|
+
|
|
860
|
+ /* Get descriptor */
|
|
861
|
+ if ( ( rc = usb_get_descriptor ( usb, 0, USB_STRING_DESCRIPTOR, 0, 0,
|
|
862
|
+ &desc.header, sizeof ( desc ) ) ) !=0){
|
|
863
|
+ DBGC ( usb, "USB %s has no default language: %s\n",
|
|
864
|
+ usb->name, strerror ( rc ) );
|
|
865
|
+ return USB_LANG_ENGLISH;
|
|
866
|
+ }
|
|
867
|
+
|
|
868
|
+ /* Use first language ID */
|
|
869
|
+ language = le16_to_cpu ( desc.language[0] );
|
|
870
|
+ DBGC2 ( usb, "USB %s default language %#04x\n", usb->name, language );
|
|
871
|
+ return language;
|
|
872
|
+}
|
|
873
|
+
|
846
|
874
|
/**
|
847
|
875
|
* Get USB string descriptor
|
848
|
876
|
*
|
849
|
877
|
* @v usb USB device
|
850
|
878
|
* @v index String index
|
851
|
|
- * @v language Language ID
|
|
879
|
+ * @v language Language ID, or 0 to use default
|
852
|
880
|
* @v buf Data buffer
|
853
|
881
|
* @v len Length of buffer
|
854
|
882
|
* @ret len String length (excluding NUL), or negative error
|
|
@@ -864,6 +892,13 @@ int usb_get_string_descriptor ( struct usb_device *usb, unsigned int index,
|
864
|
892
|
unsigned int i;
|
865
|
893
|
int rc;
|
866
|
894
|
|
|
895
|
+ /* Use default language ID, if applicable */
|
|
896
|
+ if ( ( language == 0 ) && ( index != 0 ) ) {
|
|
897
|
+ if ( ! usb->language )
|
|
898
|
+ usb->language = usb_get_default_language ( usb );
|
|
899
|
+ language = usb->language;
|
|
900
|
+ }
|
|
901
|
+
|
867
|
902
|
/* Allocate buffer for string */
|
868
|
903
|
desc = malloc ( sizeof ( *desc ) );
|
869
|
904
|
if ( ! desc ) {
|