tools/usb_gadget/gadget.py
def GetStringDescriptor(self, index, lang, length):
    """Handle a GET_DESCRIPTOR(String) request from the host.

    Descriptor index 0 returns the set of languages supported by the device.
    All other indices return the string descriptors registered with those
    indices.

    See Universal Serial Bus Specification Revision 2.0 section 9.6.7.

    Args:
      index: Descriptor index.
      lang: Descriptor language code.
      length: Maximum amount of data the host expects the device to return.

    Returns:
      The string descriptor or None to stall the pipe if the descriptor is not
      found.
    """
    if index == 0:
      length = 2 + len(self._strings) * 2
      header = struct.pack('<BB', length, usb_constants.DescriptorType.STRING)
      lang_codes = [struct.pack('<H', lang)
                    for lang in self._strings.iterkeys()]
      buf = header + ''.join(lang_codes)
      assert len(buf) == length
      return buf[:length]
    if index == 0xEE and lang == 0 and self._ms_vendor_code_v1 is not None:
      # See https://msdn.microsoft.com/en-us/windows/hardware/gg463179 for the
      # definition of this special string descriptor.
      buf = (struct.pack('<BB', 18, usb_constants.DescriptorType.STRING) +
             'MSFT100'.encode('UTF-16LE') +
             struct.pack('<BB', self._ms_vendor_code_v1, 0))
      assert len(buf) == 18
      return buf[:length]
    elif lang not in self._strings:
      return None
    elif index not in self._strings[lang]:
      return None
    else:
      descriptor = usb_descriptors.StringDescriptor(
          bString=self._strings[lang][index])
      return descriptor.Encode()[:length]
Handle a GET_DESCRIPTOR(String) request from the host.

    Descriptor index 0 returns the set of languages supported by the device.
    All other indices return the string descriptors registered with those
    indices.

    See Universal Serial Bus Specification Revision 2.0 section 9.6.7.

    Args:
      index: Descriptor index.
      lang: Descriptor language code.
      length: Maximum amount of data the host expects the device to return.

    Returns:
      The string descriptor or None to stall the pipe if the descriptor is not
      found.
    
Handle a GET_DESCRIPTOR(String) request from the host.
Descriptor index 0 returns the set of languages supported by the device.
All other indices return the string descriptors registered with those
indices.


Handle a GET_DESCRIPTOR ( String ) request from the host . Descriptor index 0 returns the set of languages supported by the device . All other indices return the string descriptors registered with those indices .
def GetStringDescriptor(self, index, lang, length):
    if index == 0:
      length = 2 + len(self._strings) * 2
      header = struct.pack('<BB', length, usb_constants.DescriptorType.STRING)
      lang_codes = [struct.pack('<H', lang)
                    for lang in self._strings.iterkeys()]
      buf = header + ''.join(lang_codes)
      assert len(buf) == length
      return buf[:length]
    if index == 0xEE and lang == 0 and self._ms_vendor_code_v1 is not None:
      buf = (struct.pack('<BB', 18, usb_constants.DescriptorType.STRING) +
             'MSFT100'.encode('UTF-16LE') +
             struct.pack('<BB', self._ms_vendor_code_v1, 0))
      assert len(buf) == 18
      return buf[:length]
    elif lang not in self._strings:
      return None
    elif index not in self._strings[lang]:
      return None
    else:
      descriptor = usb_descriptors.StringDescriptor(
          bString=self._strings[lang][index])
      return descriptor.Encode()[:length]
def GetStringDescriptor ( self , index , lang , length ) : if index == 0 : length = 2 + len ( self . _strings ) * 2 header = struct . pack ( '<BB' , length , usb_constants . DescriptorType . STRING ) lang_codes = [ struct . pack ( '<H' , lang ) for lang in self . _strings . iterkeys ( ) ] buf = header + '' . join ( lang_codes ) assert len ( buf ) == length return buf [ : length ] if index == 0xEE and lang == 0 and self . _ms_vendor_code_v1 is not None : buf = ( struct . pack ( '<BB' , 18 , usb_constants . DescriptorType . STRING ) + 'MSFT100' . encode ( 'UTF-16LE' ) + struct . pack ( '<BB' , self . _ms_vendor_code_v1 , 0 ) ) assert len ( buf ) == 18 return buf [ : length ] elif lang not in self . _strings : return None elif index not in self . _strings [ lang ] : return None else : descriptor = usb_descriptors . StringDescriptor ( bString = self . _strings [ lang ] [ index ] ) return descriptor . Encode ( ) [ : length ]
Handle a GET_DESCRIPTOR(String) request from the host.
Handle a GET_DESCRIPTOR ( String ) request from the host .
"""Handle a GET_DESCRIPTOR(String) request from the host.

    Descriptor index 0 returns the set of languages supported by the device.
    All other indices return the string descriptors registered with those
    indices.

    See Universal Serial Bus Specification Revision 2.0 section 9.6.7.

    Args:
      index: Descriptor index.
      lang: Descriptor language code.
      length: Maximum amount of data the host expects the device to return.

    Returns:
      The string descriptor or None to stall the pipe if the descriptor is not
      found.
    """ # See https://msdn.microsoft.com/en-us/windows/hardware/gg463179 for the # definition of this special string descriptor.
The string descriptor or None to stall the pipe if the descriptor is not
found.
The string descriptor or None to stall the pipe if the descriptor is not found .
self
index
None
lang
Descriptor language code.
Descriptor language code .
length
Maximum amount of data the host expects the device to return.
Maximum amount of data the host expects the device to return .