VirtualBox

Ignore:
Timestamp:
May 2, 2016 4:13:57 PM (9 years ago)
Author:
vboxsync
Message:

ValidationKit/usb: Add client support for passing extended confiugration for the gadget create request

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/tests/usb/usbgadget.py

    r60571 r60794  
    6262## @{
    6363g_kiGadgetAccessUsbIp          = 1;
     64## @}
     65
     66## @name USB gadget config types.
     67## @{
     68g_kiGadgetCfgTypeBool          = 1;
     69g_kiGadgetCfgTypeString        = 2;
     70g_kiGadgetCfgTypeUInt8         = 3;
     71g_kiGadgetCfgTypeUInt16        = 4;
     72g_kiGadgetCfgTypeUInt32        = 5;
     73g_kiGadgetCfgTypeUInt64        = 6;
     74g_kiGadgetCfgTypeInt8          = 7;
     75g_kiGadgetCfgTypeInt16         = 8;
     76g_kiGadgetCfgTypeInt32         = 9;
     77g_kiGadgetCfgTypeInt64         = 10;
    6478## @}
    6579
     
    176190    for i in range(cb): # pylint: disable=W0612
    177191        abArray.append(0);
     192    return abArray;
     193
     194def strToByteArry(sStr):
     195    """Encodes the string as a little endian byte (B) array including the terminator."""
     196    abArray = array.array('B');
     197    sUtf8 = sStr.encode('utf_8');
     198    for i in range(0, len(sUtf8)):
     199        abArray.append(ord(sUtf8[i]))
     200    abArray.append(0);
     201    return abArray;
     202
     203def cfgListToByteArray(lst):
     204    """Encodes the given config list as a little endian byte (B) array."""
     205    abArray = array.array('B');
     206    if lst is not None:
     207        for t3Item in lst:
     208            # Encode they key size
     209            abArray.extend(u32ToByteArray(len(t3Item[0]) + 1)); # Include terminator
     210            abArray.extend(u32ToByteArray(t3Item[1]))           # Config type
     211            abArray.extend(u32ToByteArray(len(t3Item[2]) + 1)); # Value size including temrinator.
     212            abArray.extend(u32ToByteArray(0));                  # Reserved field.
     213
     214            abArray.extend(strToByteArry(t3Item[0]));
     215            abArray.extend(strToByteArry(t3Item[2]));
     216
    178217    return abArray;
    179218
     
    750789    #
    751790
    752     def taskGadgetCreate(self, iGadgetType, iGadgetAccess):
     791    def taskGadgetCreate(self, iGadgetType, iGadgetAccess, lstCfg = None):
    753792        """Creates a new gadget on UTS"""
    754         fRc = self.sendMsg("GDGTCRT", (iGadgetType, iGadgetAccess, 0, 0));
     793        cCfgItems = 0;
     794        if lstCfg is not None:
     795            cCfgItems = len(lstCfg);
     796        fRc = self.sendMsg("GDGTCRT", (iGadgetType, iGadgetAccess, cCfgItems, 0, cfgListToByteArray(lstCfg)));
    755797        if fRc is True:
    756798            fRc = self.recvAckLogged("GDGTCRT");
     
    839881    #
    840882
    841     def asyncGadgetCreate(self, iGadgetType, iGadgetAccess, cMsTimeout = 30000, fIgnoreErrors = False):
     883    def asyncGadgetCreate(self, iGadgetType, iGadgetAccess, lstCfg = None, cMsTimeout = 30000, fIgnoreErrors = False):
    842884        """
    843885        Initiates a gadget create task.
     
    848890        """
    849891        return self.startTask(cMsTimeout, fIgnoreErrors, "GadgetCreate", self.taskGadgetCreate, \
    850                               (iGadgetType, iGadgetAccess));
    851 
    852     def syncGadgetCreate(self, iGadgetType, iGadgetAccess, cMsTimeout = 30000, fIgnoreErrors = False):
     892                              (iGadgetType, iGadgetAccess, lstCfg));
     893
     894    def syncGadgetCreate(self, iGadgetType, iGadgetAccess, lstCfg = None, cMsTimeout = 30000, fIgnoreErrors = False):
    853895        """Synchronous version."""
    854         return self.asyncToSync(self.asyncGadgetCreate, iGadgetType, iGadgetAccess, cMsTimeout, fIgnoreErrors);
     896        return self.asyncToSync(self.asyncGadgetCreate, iGadgetType, iGadgetAccess, lstCfg, cMsTimeout, fIgnoreErrors);
    855897
    856898    def asyncGadgetDestroy(self, iGadgetId, cMsTimeout = 30000, fIgnoreErrors = False):
     
    13271369        return self.oUtsSession.syncGadgetConnect(self.idGadget);
    13281370
    1329     def impersonate(self, sImpersonation):
     1371    def impersonate(self, sImpersonation, fSuperSpeed = False):
    13301372        """
    13311373        Impersonate a given device.
     
    13381380        fRc = False;
    13391381        if sImpersonation == g_ksGadgetImpersonationTest:
    1340             fDone = self.oUtsSession.syncGadgetCreate(g_kiGadgetTypeTest, g_kiGadgetAccessUsbIp);
     1382            lstCfg = [];
     1383            if fSuperSpeed is True:
     1384                lstCfg.append( ('Gadget/SuperSpeed', g_kiGadgetCfgTypeBool, 'true') );
     1385            fDone = self.oUtsSession.syncGadgetCreate(g_kiGadgetTypeTest, g_kiGadgetAccessUsbIp, lstCfg);
    13411386            if fDone is True and self.oUtsSession.isSuccess():
    13421387                # Get the gadget ID.
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette