Changeset 60793 in vbox for trunk/src/VBox/ValidationKit/utils/usb/UsbTestServicePlatform-linux.cpp
- Timestamp:
- May 2, 2016 4:12:43 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/utils/usb/UsbTestServicePlatform-linux.cpp
r60522 r60793 45 45 46 46 /** 47 * A dummy UDC descriptor. 48 */ 49 typedef struct UTSPLATFORMLNXDUMMYHCD 50 { 51 /* Index of the dummy hcd entry. */ 52 uint32_t idxDummyHcd; 47 * A USB bus provided by the dummy HCD. 48 */ 49 typedef struct UTSPLATFORMLNXDUMMYHCDBUS 50 { 53 51 /** The bus ID on the host the dummy HCD is serving. */ 54 52 uint32_t uBusId; 53 /** Flag whether this is a super speed bus. */ 54 bool fSuperSpeed; 55 } UTSPLATFORMLNXDUMMYHCDBUS; 56 /** Pointer to a Dummy HCD bus. */ 57 typedef UTSPLATFORMLNXDUMMYHCDBUS *PUTSPLATFORMLNXDUMMYHCDBUS; 58 59 /** 60 * A dummy UDC descriptor. 61 */ 62 typedef struct UTSPLATFORMLNXDUMMYHCD 63 { 64 /** Index of the dummy hcd entry. */ 65 uint32_t idxDummyHcd; 55 66 /** Flag whether this HCD is free for use. */ 56 bool fAvailable; 67 bool fAvailable; 68 /** Number of busses this HCD instance serves. */ 69 unsigned cBusses; 70 /** Bus structures the HCD serves.*/ 71 PUTSPLATFORMLNXDUMMYHCDBUS paBusses; 57 72 } UTSPLATFORMLNXDUMMYHCD; 58 73 /** Pointer to a dummy HCD entry. */ … … 75 90 76 91 /** 77 * Queries the assigned bus ID for the given dummy HCD index.92 * Queries the assigned busses for the given dummy HCD instance. 78 93 * 79 94 * @returns IPRT status code. 80 * @param idxHcd The HCD index to query the bus number for. 81 * @param puBusId Where to store the bus number on success. 82 */ 83 static int utsPlatformLnxDummyHcdQueryBusId(uint32_t idxHcd, uint32_t *puBusId) 95 * @param pHcd The dummy HCD bus instance. 96 */ 97 static int utsPlatformLnxDummyHcdQueryBusses(PUTSPLATFORMLNXDUMMYHCD pHcd) 84 98 { 85 99 int rc = VINF_SUCCESS; 86 100 char aszPath[RTPATH_MAX + 1]; 87 88 size_t cchPath = RTStrPrintf(&aszPath[0], RT_ELEMENTS(aszPath), UTS_PLATFORM_LNX_DUMMY_HCD_PATH "/dummy_hcd.%u/usb*", idxHcd); 101 unsigned idxBusCur = 0; 102 unsigned idxBusMax = 0; 103 104 size_t cchPath = RTStrPrintf(&aszPath[0], RT_ELEMENTS(aszPath), UTS_PLATFORM_LNX_DUMMY_HCD_PATH "/dummy_hcd.%u/usb*", pHcd->idxDummyHcd); 89 105 if (cchPath == RT_ELEMENTS(aszPath)) 90 106 return VERR_BUFFER_OVERFLOW; … … 94 110 if (RT_SUCCESS(rc)) 95 111 { 96 RTDIRENTRY DirFolderContent; 97 rc = RTDirRead(pDir, &DirFolderContent, NULL); 98 if (RT_SUCCESS(rc)) 99 { 100 /* Extract the bus number - it is after "usb", i.e. "usb9" indicates a bus ID of 9. */ 101 rc = RTStrToUInt32Ex(&DirFolderContent.szName[3], NULL, 10, puBusId); 112 do 113 { 114 RTDIRENTRY DirFolderContent; 115 rc = RTDirRead(pDir, &DirFolderContent, NULL); 102 116 if (RT_SUCCESS(rc)) 103 117 { 104 /* Make sure there is no other entry or something screwed us up. */ 105 rc = RTDirRead(pDir, &DirFolderContent, NULL); 118 uint32_t uBusId = 0; 119 120 /* Extract the bus number - it is after "usb", i.e. "usb9" indicates a bus ID of 9. */ 121 rc = RTStrToUInt32Ex(&DirFolderContent.szName[3], NULL, 10, &uBusId); 106 122 if (RT_SUCCESS(rc)) 107 rc = VERR_INVALID_STATE; 108 else if (rc == VERR_NO_MORE_FILES) 109 rc = VINF_SUCCESS; 123 { 124 /* Check whether this is a super speed bus. */ 125 int64_t iSpeed = 0; 126 bool fSuperSpeed = false; 127 rc = RTLinuxSysFsReadIntFile(10, &iSpeed, UTS_PLATFORM_LNX_DUMMY_HCD_PATH "/dummy_hcd.%u/%s/speed", 128 pHcd->idxDummyHcd, DirFolderContent.szName); 129 if ( RT_SUCCESS(rc) 130 && (iSpeed == 5000 || iSpeed == 10000)) 131 fSuperSpeed = true; 132 133 /* Add to array of available busses for this HCD. */ 134 if (idxBusCur == idxBusMax) 135 { 136 size_t cbNew = (idxBusMax + 10) * sizeof(UTSPLATFORMLNXDUMMYHCDBUS); 137 PUTSPLATFORMLNXDUMMYHCDBUS pNew = (PUTSPLATFORMLNXDUMMYHCDBUS)RTMemRealloc(pHcd->paBusses, cbNew); 138 if (pNew) 139 { 140 idxBusMax += 10; 141 pHcd->paBusses = pNew; 142 } 143 } 144 145 if (idxBusCur < idxBusMax) 146 { 147 pHcd->paBusses[idxBusCur].uBusId = uBusId; 148 pHcd->paBusses[idxBusCur].fSuperSpeed = fSuperSpeed; 149 idxBusCur++; 150 } 151 else 152 rc = VERR_NO_MEMORY; 153 } 110 154 } 111 } 155 } while (RT_SUCCESS(rc)); 156 157 pHcd->cBusses = idxBusCur; 158 159 if (rc == VERR_NO_MORE_FILES) 160 rc = VINF_SUCCESS; 112 161 113 162 RTDirClose(pDir); … … 124 173 if (RT_SUCCESS(rc)) 125 174 { 126 const char * pszArg = "num=2"; /** @todo: Make configurable from config. */127 rc = utsPlatformModuleLoad("dummy_hcd", & pszArg, 1);175 const char *apszArg[] = { "num=2", "is_super_speed=1" }; /** @todo: Make configurable from config. */ 176 rc = utsPlatformModuleLoad("dummy_hcd", &apszArg[0], RT_ELEMENTS(apszArg)); 128 177 if (RT_SUCCESS(rc)) 129 178 { … … 157 206 if (RT_SUCCESS(rc)) 158 207 { 159 uint32_t uBusId = 0; 160 rc = utsPlatformLnxDummyHcdQueryBusId(idxHcd, &uBusId); 161 if (RT_SUCCESS(rc)) 208 /* Add to array of available HCDs. */ 209 if (idxHcdCur == idxHcdMax) 162 210 { 163 /* Add to array of available HCDs. */ 164 if (idxHcdCur == idxHcdMax) 211 size_t cbNew = (idxHcdMax + 10) * sizeof(UTSPLATFORMLNXDUMMYHCD); 212 PUTSPLATFORMLNXDUMMYHCD pNew = (PUTSPLATFORMLNXDUMMYHCD)RTMemRealloc(g_paDummyHcd, cbNew); 213 if (pNew) 165 214 { 166 size_t cbNew = (idxHcdMax + 10) * sizeof(UTSPLATFORMLNXDUMMYHCD); 167 PUTSPLATFORMLNXDUMMYHCD pNew = (PUTSPLATFORMLNXDUMMYHCD)RTMemRealloc(g_paDummyHcd, cbNew); 168 if (pNew) 169 { 170 idxHcdMax += 10; 171 g_paDummyHcd = pNew; 172 } 173 } 174 175 if (idxHcdCur < idxHcdMax) 176 { 177 g_paDummyHcd[idxHcdCur].idxDummyHcd = idxHcd; 178 g_paDummyHcd[idxHcdCur].uBusId = uBusId; 179 g_paDummyHcd[idxHcdCur].fAvailable = true; 180 idxHcdCur++; 215 idxHcdMax += 10; 216 g_paDummyHcd = pNew; 181 217 } 182 218 } 219 220 if (idxHcdCur < idxHcdMax) 221 { 222 g_paDummyHcd[idxHcdCur].idxDummyHcd = idxHcd; 223 g_paDummyHcd[idxHcdCur].fAvailable = true; 224 g_paDummyHcd[idxHcdCur].cBusses = 0; 225 g_paDummyHcd[idxHcdCur].paBusses = NULL; 226 rc = utsPlatformLnxDummyHcdQueryBusses(&g_paDummyHcd[idxHcdCur]); 227 if (RT_SUCCESS(rc)) 228 idxHcdCur++; 229 } 230 else 231 rc = VERR_NO_MEMORY; 183 232 } 184 233 } … … 222 271 unsigned idx; 223 272 for (idx = 0; idx < cArgv; idx++) 224 papszArgs[2+idx] = papszArg s[idx];273 papszArgs[2+idx] = papszArgv[idx]; 225 274 papszArgs[2+idx] = NULL; 226 275 … … 271 320 272 321 273 DECLHIDDEN(int) utsPlatformLnxAcquireUDC( char **ppszUdc, uint32_t *puBusId)322 DECLHIDDEN(int) utsPlatformLnxAcquireUDC(bool fSuperSpeed, char **ppszUdc, uint32_t *puBusId) 274 323 { 275 324 int rc = VERR_NOT_FOUND; … … 277 326 for (unsigned i = 0; i < g_cDummyHcd; i++) 278 327 { 279 if (g_paDummyHcd[i].fAvailable) 280 { 281 rc = VINF_SUCCESS; 282 int cbRet = RTStrAPrintf(ppszUdc, "dummy_udc.%u", g_paDummyHcd[i].idxDummyHcd); 283 if (cbRet == -1) 284 rc = VERR_NO_STR_MEMORY; 285 *puBusId = g_paDummyHcd[i].uBusId; 286 g_paDummyHcd[i].fAvailable = false; 287 break; 328 PUTSPLATFORMLNXDUMMYHCD pHcd = &g_paDummyHcd[i]; 329 330 if (pHcd->fAvailable) 331 { 332 /* Check all assigned busses for a speed match. */ 333 for (unsigned idxBus = 0; idxBus < pHcd->cBusses; idxBus++) 334 { 335 if (pHcd->paBusses[idxBus].fSuperSpeed == fSuperSpeed) 336 { 337 rc = VINF_SUCCESS; 338 int cbRet = RTStrAPrintf(ppszUdc, "dummy_udc.%u", pHcd->idxDummyHcd); 339 if (cbRet == -1) 340 rc = VERR_NO_STR_MEMORY; 341 *puBusId = pHcd->paBusses[idxBus].uBusId; 342 pHcd->fAvailable = false; 343 break; 344 } 345 } 346 347 if (rc != VERR_NOT_FOUND) 348 break; 288 349 } 289 350 }
Note:
See TracChangeset
for help on using the changeset viewer.