Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1509 lines
45 KiB

  1. #pragma hdrstop
  2. #include <stdio.h>
  3. #include "debug.h"
  4. #include "upnp.h"
  5. HRESULT PrintVariantBool(LPWSTR pszVariable, VARIANT* pVariant)
  6. {
  7. HRESULT hr = S_OK;
  8. if(V_VT(pVariant) == VT_BOOL)
  9. {
  10. wprintf(L"%s is %s\n", pszVariable, VARIANT_TRUE == V_BOOL(pVariant) ? L"TRUE" : L"FALSE");
  11. }
  12. return hr;
  13. }
  14. HRESULT PrintVariableBool(IUPnPService* pService, LPWSTR pszVariable)
  15. {
  16. HRESULT hr = S_OK;
  17. BSTR VariableName;
  18. VARIANT Variant;
  19. VariantInit(&Variant);
  20. VariableName = SysAllocString(pszVariable);
  21. hr = pService->QueryStateVariable(VariableName, &Variant);
  22. if(SUCCEEDED(hr))
  23. {
  24. hr = PrintVariantBool(pszVariable, &Variant);
  25. }
  26. else
  27. {
  28. wprintf(L"error %x\n", hr);
  29. }
  30. SysFreeString(VariableName);
  31. VariantClear(&Variant);
  32. return hr;
  33. }
  34. HRESULT PrintVariantShort(LPWSTR pszVariable, VARIANT* pVariant)
  35. {
  36. HRESULT hr = S_OK;
  37. if(V_VT(pVariant) == VT_UI2)
  38. {
  39. wprintf(L"%s is %d\n", pszVariable, V_UI2(pVariant));
  40. }
  41. return hr;
  42. }
  43. HRESULT PrintVariableShort(IUPnPService* pService, LPWSTR pszVariable)
  44. {
  45. HRESULT hr = S_OK;
  46. BSTR VariableName;
  47. VARIANT Variant;
  48. VariantInit(&Variant);
  49. VariableName = SysAllocString(pszVariable);
  50. hr = pService->QueryStateVariable(VariableName, &Variant);
  51. if(SUCCEEDED(hr))
  52. {
  53. hr = PrintVariantShort(pszVariable, &Variant);
  54. }
  55. else
  56. {
  57. wprintf(L"error %x\n", hr);
  58. }
  59. SysFreeString(VariableName);
  60. VariantClear(&Variant);
  61. return hr;
  62. }
  63. HRESULT PrintVariantLong(LPWSTR pszVariable, VARIANT* pVariant)
  64. {
  65. HRESULT hr = S_OK;
  66. if(V_VT(pVariant) == VT_UI4)
  67. {
  68. wprintf(L"%s is %d\n", pszVariable, V_UI4(pVariant));
  69. }
  70. return hr;
  71. }
  72. HRESULT PrintVariableLong(IUPnPService* pService, LPWSTR pszVariable)
  73. {
  74. HRESULT hr = S_OK;
  75. BSTR VariableName;
  76. VARIANT Variant;
  77. VariantInit(&Variant);
  78. VariableName = SysAllocString(pszVariable);
  79. hr = pService->QueryStateVariable(VariableName, &Variant);
  80. if(SUCCEEDED(hr))
  81. {
  82. hr = PrintVariantLong(pszVariable, &Variant);
  83. }
  84. else
  85. {
  86. wprintf(L"error %x\n", hr);
  87. }
  88. SysFreeString(VariableName);
  89. VariantClear(&Variant);
  90. return hr;
  91. }
  92. HRESULT PrintVariantString(LPWSTR pszVariable, VARIANT* pVariant)
  93. {
  94. HRESULT hr = S_OK;
  95. if(V_VT(pVariant) == VT_BSTR)
  96. {
  97. wprintf(L"%s is %s\n", pszVariable, V_BSTR(pVariant));
  98. }
  99. return hr;
  100. }
  101. HRESULT PrintVariableString(IUPnPService* pService, LPWSTR pszVariable)
  102. {
  103. HRESULT hr = S_OK;
  104. BSTR VariableName;
  105. VARIANT Variant;
  106. VariantInit(&Variant);
  107. VariableName = SysAllocString(pszVariable);
  108. hr = pService->QueryStateVariable(VariableName, &Variant);
  109. if(SUCCEEDED(hr))
  110. {
  111. hr = PrintVariantString(pszVariable, &Variant);
  112. }
  113. else
  114. {
  115. wprintf(L"error %x\n", hr);
  116. }
  117. SysFreeString(VariableName);
  118. VariantClear(&Variant);
  119. return hr;
  120. }
  121. HRESULT PrintOutParams(VARIANT* pOutParams)
  122. {
  123. HRESULT hr = S_OK;
  124. SAFEARRAY* pArray = V_ARRAY(pOutParams);
  125. LONG lIndex = 0;
  126. VARIANT Param;
  127. while(SUCCEEDED(hr))
  128. {
  129. hr = SafeArrayGetElement(pArray, &lIndex, &Param);
  130. if(SUCCEEDED(hr))
  131. {
  132. switch(V_VT(&Param))
  133. {
  134. case VT_BOOL:
  135. PrintVariantBool(L"B ", &Param);
  136. break;
  137. case VT_UI4:
  138. PrintVariantLong(L"D ", &Param);
  139. break;
  140. case VT_UI2:
  141. PrintVariantShort(L"W ", &Param);
  142. break;
  143. case VT_BSTR:
  144. PrintVariantString(L"S ", &Param);
  145. break;
  146. }
  147. }
  148. lIndex++;
  149. }
  150. return hr;
  151. }
  152. HRESULT FindFirstDevice(IUPnPDevices* pDevices, IUPnPDevice** ppDevice)
  153. {
  154. HRESULT hr = S_OK;
  155. IUnknown* pEnumerator;
  156. hr = pDevices->get__NewEnum(&pEnumerator);
  157. if (SUCCEEDED(hr))
  158. {
  159. IEnumVARIANT* pVariantEnumerator;
  160. hr = pEnumerator->QueryInterface(IID_IEnumVARIANT, reinterpret_cast<void**>(&pVariantEnumerator));
  161. if (SUCCEEDED(hr))
  162. {
  163. VARIANT DeviceVariant;
  164. VariantInit(&DeviceVariant);
  165. pVariantEnumerator->Reset();
  166. // Traverse the collection.
  167. while (S_OK == pVariantEnumerator->Next(1, &DeviceVariant, NULL))
  168. {
  169. IDispatch * pDeviceDispatch = NULL;
  170. IUPnPDevice * pDevice = NULL;
  171. pDeviceDispatch = V_DISPATCH(&DeviceVariant);
  172. hr = pDeviceDispatch->QueryInterface(IID_IUPnPDevice, reinterpret_cast<void **>(&pDevice));
  173. if (SUCCEEDED(hr))
  174. {
  175. // Do something interesting with pDevice.
  176. *ppDevice = pDevice;
  177. BSTR FriendlyName;
  178. hr = pDevice->get_FriendlyName(&FriendlyName);
  179. if(SUCCEEDED(hr))
  180. {
  181. wprintf(L"Friendly Name %s\n", FriendlyName);
  182. SysFreeString(FriendlyName);
  183. }
  184. // pDevice->Release();
  185. break; // BUGBUG
  186. }
  187. VariantClear(&DeviceVariant);
  188. };
  189. if(NULL == *ppDevice)
  190. {
  191. hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
  192. }
  193. pVariantEnumerator->Release();
  194. }
  195. pEnumerator->Release();
  196. }
  197. return hr;
  198. }
  199. HRESULT FindGatewayDevice(IUPnPDevice** ppGatewayDevice)
  200. {
  201. HRESULT hr;
  202. *ppGatewayDevice = NULL;
  203. IUPnPDeviceFinder *pDeviceFinder;
  204. hr = CoCreateInstance(CLSID_UPnPDeviceFinder, NULL, CLSCTX_INPROC_SERVER, IID_IUPnPDeviceFinder, reinterpret_cast<void **>(&pDeviceFinder));
  205. if(SUCCEEDED(hr))
  206. {
  207. BSTR bstrTypeURI;
  208. bstrTypeURI = SysAllocString(L"urn:schemas-upnp-org:device:InternetGatewayDevice:0.3");
  209. if (NULL != bstrTypeURI)
  210. {
  211. IUPnPDevices* pFoundDevices;
  212. hr = pDeviceFinder->FindByType(bstrTypeURI, 0, &pFoundDevices);
  213. if (SUCCEEDED(hr))
  214. {
  215. hr = FindFirstDevice(pFoundDevices, ppGatewayDevice);
  216. pFoundDevices->Release();
  217. }
  218. SysFreeString(bstrTypeURI);
  219. }
  220. pDeviceFinder->Release();
  221. }
  222. else
  223. {
  224. printf("Couldn't create device finder %x\n", hr);
  225. }
  226. return hr;
  227. }
  228. HRESULT FindChildDevice(IUPnPDevice* pDevice, IUPnPDevice** ppChildDevice)
  229. {
  230. HRESULT hr = S_OK;
  231. IUPnPDevices* pDevices;
  232. hr = pDevice->get_Children(&pDevices);
  233. if(SUCCEEDED(hr))
  234. {
  235. hr = FindFirstDevice(pDevices, ppChildDevice);
  236. }
  237. return hr;
  238. }
  239. HRESULT FindService(IUPnPDevice* pDevice, LPWSTR pszServiceName, IUPnPService** ppICSService)
  240. {
  241. HRESULT hr;
  242. IUPnPServices* pServices;
  243. hr = pDevice->get_Services(&pServices);
  244. if (SUCCEEDED(hr))
  245. {
  246. // IUnknown* pEnumerator;
  247. // hr = pServices->get__NewEnum(&pEnumerator);
  248. // if (SUCCEEDED(hr))
  249. // {
  250. // IEnumVARIANT* pVariantEnumerator;
  251. // hr = pEnumerator->QueryInterface(IID_IEnumVARIANT, reinterpret_cast<void**>(&pVariantEnumerator));
  252. // if (SUCCEEDED(hr))
  253. // {
  254. // VARIANT ServiceVariant;
  255. //
  256. // VariantInit(&ServiceVariant);
  257. //
  258. // pVariantEnumerator->Reset();
  259. //
  260. // // Traverse the collection.
  261. //
  262. // while (S_OK == pVariantEnumerator->Next(1, &ServiceVariant, NULL))
  263. // {
  264. // wprintf(L"getting i1d\n");
  265. // IDispatch * pServiceDispatch = NULL;
  266. // IUPnPService * pService = NULL;
  267. //
  268. // pServiceDispatch = V_DISPATCH(&ServiceVariant);
  269. // hr = pServiceDispatch->QueryInterface(IID_IUPnPService, reinterpret_cast<void **>(&pService));
  270. // if (SUCCEEDED(hr))
  271. // {
  272. // wprintf(L"getting id\n");
  273. //
  274. // BSTR ServiceId;
  275. // hr = pService->get_Id(&ServiceId);
  276. // if(SUCCEEDED(hr))
  277. // {
  278. // wprintf(L"service %s\n", ServiceId);
  279. // SysFreeString(ServiceId);
  280. // }
  281. // pService->Release();
  282. // }
  283. //
  284. // VariantClear(&ServiceVariant);
  285. // };
  286. // wprintf(L"done enum\n");
  287. // pVariantEnumerator->Release();
  288. // }
  289. // pEnumerator->Release();
  290. // }
  291. BSTR ServiceId = SysAllocString(pszServiceName);
  292. if (NULL != ServiceId)
  293. {
  294. IUPnPService* pICSService;
  295. hr = pServices->get_Item(ServiceId, &pICSService);
  296. if(SUCCEEDED(hr))
  297. {
  298. wprintf(L"found service\n");
  299. *ppICSService = pICSService;
  300. }
  301. SysFreeString(ServiceId);
  302. }
  303. pServices->Release();
  304. }
  305. if(FAILED(hr))
  306. {
  307. wprintf(L"find ICS Service %x\n", hr);
  308. }
  309. return hr;
  310. }
  311. HRESULT CreateParamArray(LONG lElements, VARIANT* pInParams)
  312. {
  313. HRESULT hr = S_OK;
  314. VariantInit(pInParams);
  315. SAFEARRAYBOUND rgsaBound[1];
  316. SAFEARRAY * psa = NULL;
  317. rgsaBound[0].lLbound = 0;
  318. rgsaBound[0].cElements = lElements;
  319. psa = SafeArrayCreate(VT_VARIANT, 1, rgsaBound);
  320. if(NULL != psa)
  321. {
  322. pInParams->vt = VT_VARIANT | VT_ARRAY;
  323. V_ARRAY(pInParams) = psa;
  324. }
  325. else
  326. {
  327. hr = E_OUTOFMEMORY;
  328. }
  329. return hr;
  330. }
  331. HRESULT InvokeAction(IUPnPService * pService, LPTSTR pszCommand, VARIANT* pInParams, VARIANT* pOutParams)
  332. {
  333. HRESULT hr = S_OK;
  334. BSTR bstrActionName;
  335. bstrActionName = SysAllocString(pszCommand);
  336. if (NULL != bstrActionName)
  337. {
  338. VARIANT varReturnVal;
  339. VariantInit(pOutParams);
  340. VariantInit(&varReturnVal);
  341. hr = pService->InvokeAction(bstrActionName, *pInParams, pOutParams, &varReturnVal);
  342. if(SUCCEEDED(hr))
  343. {
  344. VariantClear(&varReturnVal);
  345. }
  346. SysFreeString(bstrActionName);
  347. }
  348. else
  349. {
  350. hr = E_OUTOFMEMORY;
  351. }
  352. return hr;
  353. }
  354. HRESULT InvokeVoidAction(IUPnPService * pService, LPTSTR pszCommand, VARIANT* pOutParams)
  355. {
  356. HRESULT hr = S_OK;
  357. VARIANT varInArgs;
  358. hr = CreateParamArray(0, &varInArgs);
  359. if (SUCCEEDED(hr))
  360. {
  361. hr = InvokeAction(pService, pszCommand, &varInArgs, pOutParams);
  362. VariantClear(&varInArgs);
  363. }
  364. else
  365. {
  366. hr = E_OUTOFMEMORY;
  367. }
  368. return hr;
  369. }
  370. HRESULT TestInternetGatewayDevice_OSInfo(IUPnPDevice* pGatewayDevice)
  371. {
  372. HRESULT hr;
  373. wprintf(L"TestInternetGatewayDevice_OSInfo\n");
  374. IUPnPService* pICSService;
  375. hr = FindService(pGatewayDevice, L"upnp:id:OSInfo", &pICSService);
  376. if(SUCCEEDED(hr))
  377. {
  378. do
  379. {
  380. BSTR VariableName;
  381. VARIANT Variant;
  382. VariantInit(&Variant);
  383. VariableName = SysAllocString(L"OSMajorVersion");
  384. hr = pICSService->QueryStateVariable(VariableName, &Variant);
  385. if(SUCCEEDED(hr))
  386. {
  387. if(V_VT(&Variant) == VT_I4)
  388. {
  389. wprintf(L"OSMajorVersion is %d\n", V_I4(&Variant));
  390. }
  391. }
  392. else
  393. {
  394. wprintf(L"error %x\n", hr);
  395. }
  396. SysFreeString(VariableName);
  397. VariantClear(&Variant);
  398. if(SUCCEEDED(hr))
  399. {
  400. VariableName = SysAllocString(L"OSMinorVersion");
  401. hr = pICSService->QueryStateVariable(VariableName, &Variant);
  402. if(SUCCEEDED(hr))
  403. {
  404. if(V_VT(&Variant) == VT_I4)
  405. {
  406. wprintf(L"OSMinorVersion is %d\n", V_I4(&Variant));
  407. }
  408. }
  409. else
  410. {
  411. wprintf(L"error %x\n", hr);
  412. }
  413. SysFreeString(VariableName);
  414. VariantClear(&Variant);
  415. }
  416. if(SUCCEEDED(hr))
  417. {
  418. VariableName = SysAllocString(L"OSBuildNumber");
  419. hr = pICSService->QueryStateVariable(VariableName, &Variant);
  420. if(SUCCEEDED(hr))
  421. {
  422. if(V_VT(&Variant) == VT_I4)
  423. {
  424. wprintf(L"OSBuildNumber is %d\n", V_I4(&Variant));
  425. }
  426. }
  427. else
  428. {
  429. wprintf(L"error %x\n", hr);
  430. }
  431. SysFreeString(VariableName);
  432. VariantClear(&Variant);
  433. }
  434. // if(SUCCEEDED(hr))
  435. // {
  436. // MessageBox(NULL, L"click to disconnect", L"debug", MB_OK);
  437. // wprintf(L"disconnect\n");
  438. // hr = InvokePlay(pICSService, L"Disconnect");
  439. // wprintf(L"invoke failed %x\n", hr);
  440. // MessageBox(NULL, L"click to connect", L"debug", MB_OK);
  441. // wprintf(L"connect\n");
  442. // hr = InvokePlay(pICSService, L"Connect");
  443. // wprintf(L"invoke failed %x\n", hr);
  444. // }
  445. //
  446. //
  447. } while (UPNP_E_VARIABLE_VALUE_UNKNOWN == hr);
  448. pICSService->Release();
  449. }
  450. return hr;
  451. }
  452. HRESULT TestWANDevice_WANCommonInterfaceConfig(IUPnPDevice* pGatewayDevice)
  453. {
  454. HRESULT hr;
  455. wprintf(L"TestWANDevice_WANCommonInterfaceConfig\n");
  456. IUPnPService* pICSService;
  457. hr = FindService(pGatewayDevice, L"upnp:id:WANCommonInterfaceConfig", &pICSService);
  458. if(SUCCEEDED(hr))
  459. {
  460. do
  461. {
  462. if(SUCCEEDED(hr))
  463. {
  464. hr = PrintVariableString(pICSService, L"WANAccessType");
  465. }
  466. if(SUCCEEDED(hr))
  467. {
  468. hr = PrintVariableLong(pICSService, L"Layer1UpstreamMaxBitRate");
  469. }
  470. if(SUCCEEDED(hr))
  471. {
  472. hr = PrintVariableLong(pICSService, L"Layer1DownstreamMaxBitRate");
  473. }
  474. if(SUCCEEDED(hr))
  475. {
  476. hr = PrintVariableString(pICSService, L"PhysicalLinkStatus");
  477. }
  478. if(SUCCEEDED(hr))
  479. {
  480. hr = PrintVariableString(pICSService, L"WANAccessProvider");
  481. }
  482. if(SUCCEEDED(hr))
  483. {
  484. hr = PrintVariableLong(pICSService, L"TotalBytesSent");
  485. }
  486. if(SUCCEEDED(hr))
  487. {
  488. hr = PrintVariableLong(pICSService, L"TotalBytesReceived");
  489. }
  490. if(SUCCEEDED(hr))
  491. {
  492. hr = PrintVariableLong(pICSService, L"TotalPacketsSent");
  493. }
  494. if(SUCCEEDED(hr))
  495. {
  496. hr = PrintVariableLong(pICSService, L"TotalPacketsReceived");
  497. }
  498. if(SUCCEEDED(hr))
  499. {
  500. hr = PrintVariableShort(pICSService, L"MaximumActiveConnections");
  501. }
  502. if(SUCCEEDED(hr))
  503. {
  504. hr = PrintVariableBool(pICSService, L"PersonalFirewallEnabled");
  505. }
  506. if(SUCCEEDED(hr))
  507. {
  508. wprintf(L"GetCommonLinkProperties\n");
  509. VARIANT OutArgs;
  510. hr = InvokeVoidAction(pICSService, L"GetCommonLinkProperties", &OutArgs);
  511. if(SUCCEEDED(hr))
  512. {
  513. SAFEARRAY* pArray = V_ARRAY(&OutArgs);
  514. LONG lIndex = 0;
  515. VARIANT Param;
  516. lIndex = 0;
  517. hr = SafeArrayGetElement(pArray, &lIndex, &Param);
  518. if(SUCCEEDED(hr))
  519. {
  520. PrintVariantString(L" WANAccessType", &Param);
  521. VariantClear(&Param);
  522. }
  523. lIndex = 1;
  524. hr = SafeArrayGetElement(pArray, &lIndex, &Param);
  525. if(SUCCEEDED(hr))
  526. {
  527. PrintVariantLong(L" Layer1UpstreamMaxBitRate", &Param);
  528. VariantClear(&Param);
  529. }
  530. lIndex = 2;
  531. hr = SafeArrayGetElement(pArray, &lIndex, &Param);
  532. if(SUCCEEDED(hr))
  533. {
  534. PrintVariantLong(L" Layer1DownstreamMaxBitRate", &Param);
  535. VariantClear(&Param);
  536. }
  537. lIndex = 3;
  538. hr = SafeArrayGetElement(pArray, &lIndex, &Param);
  539. if(SUCCEEDED(hr))
  540. {
  541. PrintVariantLong(L" PhysicalLinkStatus", &Param);
  542. VariantClear(&Param);
  543. }
  544. VariantClear(&OutArgs);
  545. }
  546. else
  547. {
  548. printf("no action %x\n", hr);
  549. }
  550. }
  551. if(SUCCEEDED(hr))
  552. {
  553. wprintf(L"GetCommonConnectionProperties\n");
  554. VARIANT OutArgs;
  555. hr = InvokeVoidAction(pICSService, L"GetCommonConnectionProperties", &OutArgs);
  556. if(SUCCEEDED(hr))
  557. {
  558. SAFEARRAY* pArray = V_ARRAY(&OutArgs);
  559. LONG lIndex = 0;
  560. VARIANT Param;
  561. lIndex = 0;
  562. hr = SafeArrayGetElement(pArray, &lIndex, &Param);
  563. if(SUCCEEDED(hr))
  564. {
  565. PrintVariantString(L" WANAccessProvider", &Param);
  566. VariantClear(&Param);
  567. }
  568. lIndex = 1;
  569. hr = SafeArrayGetElement(pArray, &lIndex, &Param);
  570. if(SUCCEEDED(hr))
  571. {
  572. PrintVariantShort(L" MaximumActiveConnections", &Param);
  573. VariantClear(&Param);
  574. }
  575. lIndex = 2;
  576. hr = SafeArrayGetElement(pArray, &lIndex, &Param);
  577. if(SUCCEEDED(hr))
  578. {
  579. PrintVariantLong(L" TotalBytesSent", &Param);
  580. VariantClear(&Param);
  581. }
  582. lIndex = 3;
  583. hr = SafeArrayGetElement(pArray, &lIndex, &Param);
  584. if(SUCCEEDED(hr))
  585. {
  586. PrintVariantLong(L" TotalBytesReceived", &Param);
  587. VariantClear(&Param);
  588. }
  589. lIndex = 4;
  590. hr = SafeArrayGetElement(pArray, &lIndex, &Param);
  591. if(SUCCEEDED(hr))
  592. {
  593. PrintVariantLong(L" TotalPacketsSent", &Param);
  594. VariantClear(&Param);
  595. }
  596. lIndex = 5;
  597. hr = SafeArrayGetElement(pArray, &lIndex, &Param);
  598. if(SUCCEEDED(hr))
  599. {
  600. PrintVariantLong(L" TotalPacketsReceived", &Param);
  601. VariantClear(&Param);
  602. }
  603. VariantClear(&OutArgs);
  604. }
  605. else
  606. {
  607. printf("no action %x\n", hr);
  608. }
  609. }
  610. } while (UPNP_E_VARIABLE_VALUE_UNKNOWN == hr);
  611. pICSService->Release();
  612. }
  613. return hr;
  614. }
  615. HRESULT TestWANCommonDevice_WANPOTSLinkConfig(IUPnPDevice* pGatewayDevice)
  616. {
  617. HRESULT hr;
  618. wprintf(L"TestWANCommonDevice_WANPOTSLinkConfig\n");
  619. IUPnPService* pICSService;
  620. hr = FindService(pGatewayDevice, L"upnp:id:WANPOTSLinkConfig", &pICSService);
  621. if(SUCCEEDED(hr))
  622. {
  623. do
  624. {
  625. if(SUCCEEDED(hr))
  626. {
  627. hr = PrintVariableString(pICSService, L"ISPPhoneNumber");
  628. }
  629. if(SUCCEEDED(hr))
  630. {
  631. hr = PrintVariableString(pICSService, L"ISPInfo");
  632. }
  633. if(SUCCEEDED(hr))
  634. {
  635. hr = PrintVariableString(pICSService, L"LinkType");
  636. }
  637. if(SUCCEEDED(hr))
  638. {
  639. hr = PrintVariableLong(pICSService, L"NumberOfRetries");
  640. }
  641. if(SUCCEEDED(hr))
  642. {
  643. hr = PrintVariableLong(pICSService, L"DelayBetweenRetries");
  644. }
  645. } while (UPNP_E_VARIABLE_VALUE_UNKNOWN == hr);
  646. pICSService->Release();
  647. }
  648. return hr;
  649. }
  650. HRESULT TestWANCommonDevice_WANPPPConnection(IUPnPDevice* pGatewayDevice)
  651. {
  652. HRESULT hr;
  653. wprintf(L"TestWANCommonDevice_WANPPPConnection\n");
  654. IUPnPService* pICSService;
  655. hr = FindService(pGatewayDevice, L"upnp:id:WANPPPConnection", &pICSService);
  656. if(SUCCEEDED(hr))
  657. {
  658. do
  659. {
  660. if(SUCCEEDED(hr))
  661. {
  662. hr = PrintVariableString(pICSService, L"ConnectionType");
  663. }
  664. if(SUCCEEDED(hr))
  665. {
  666. hr = PrintVariableString(pICSService, L"PossibleConnectionTypes");
  667. }
  668. if(SUCCEEDED(hr))
  669. {
  670. hr = PrintVariableString(pICSService, L"ConnectionStatus");
  671. }
  672. if(SUCCEEDED(hr))
  673. {
  674. hr = PrintVariableLong(pICSService, L"Uptime");
  675. }
  676. if(SUCCEEDED(hr))
  677. {
  678. hr = PrintVariableLong(pICSService, L"UpstreamMaxBitRate");
  679. }
  680. if(SUCCEEDED(hr))
  681. {
  682. hr = PrintVariableLong(pICSService, L"DownstreamMaxBitRate");
  683. }
  684. if(SUCCEEDED(hr))
  685. {
  686. hr = PrintVariableString(pICSService, L"LastConnectionError");
  687. }
  688. if(SUCCEEDED(hr))
  689. {
  690. hr = PrintVariableBool(pICSService, L"RSIPAvailable");
  691. }
  692. if(SUCCEEDED(hr))
  693. {
  694. hr = PrintVariableBool(pICSService, L"NATEnabled");
  695. }
  696. if(SUCCEEDED(hr))
  697. {
  698. hr = PrintVariableLong(pICSService, L"AutoDisconnectTime");
  699. }
  700. if(SUCCEEDED(hr))
  701. {
  702. hr = PrintVariableLong(pICSService, L"IdleDisconnectTime");
  703. }
  704. if(SUCCEEDED(hr))
  705. {
  706. hr = PrintVariableLong(pICSService, L"WarnDisconnectDelay");
  707. }
  708. if(SUCCEEDED(hr))
  709. {
  710. hr = PrintVariableString(pICSService, L"PPPEncryptionProtocol");
  711. }
  712. if(SUCCEEDED(hr))
  713. {
  714. hr = PrintVariableString(pICSService, L"PPPCompressionProtocol");
  715. }
  716. if(SUCCEEDED(hr))
  717. {
  718. hr = PrintVariableString(pICSService, L"PPPAuthenticationProtocol");
  719. }
  720. if(SUCCEEDED(hr))
  721. {
  722. hr = PrintVariableShort(pICSService, L"ServiceMapNumberOfEntries");
  723. }
  724. if(SUCCEEDED(hr))
  725. {
  726. wprintf(L"GetConnectionTypeInfo\n");
  727. VARIANT OutArgs;
  728. hr = InvokeVoidAction(pICSService, L"GetConnectionTypeInfo", &OutArgs);
  729. if(SUCCEEDED(hr))
  730. {
  731. SAFEARRAY* pArray = V_ARRAY(&OutArgs);
  732. LONG lIndex = 0;
  733. VARIANT Param;
  734. lIndex = 0;
  735. hr = SafeArrayGetElement(pArray, &lIndex, &Param);
  736. if(SUCCEEDED(hr))
  737. {
  738. PrintVariantString(L" NewConnectionType", &Param);
  739. VariantClear(&Param);
  740. }
  741. lIndex = 1;
  742. hr = SafeArrayGetElement(pArray, &lIndex, &Param);
  743. if(SUCCEEDED(hr))
  744. {
  745. PrintVariantString(L" NewPossibleConnectionTypes", &Param);
  746. VariantClear(&Param);
  747. }
  748. VariantClear(&OutArgs);
  749. }
  750. else
  751. {
  752. printf("no action %x\n", hr);
  753. }
  754. }
  755. if(SUCCEEDED(hr))
  756. {
  757. wprintf(L"GetStatusInfo\n");
  758. VARIANT OutArgs;
  759. hr = InvokeVoidAction(pICSService, L"GetStatusInfo", &OutArgs);
  760. if(SUCCEEDED(hr))
  761. {
  762. SAFEARRAY* pArray = V_ARRAY(&OutArgs);
  763. LONG lIndex = 0;
  764. VARIANT Param;
  765. lIndex = 0;
  766. hr = SafeArrayGetElement(pArray, &lIndex, &Param);
  767. if(SUCCEEDED(hr))
  768. {
  769. PrintVariantString(L" NewConnectionStatus", &Param);
  770. VariantClear(&Param);
  771. }
  772. lIndex = 1;
  773. hr = SafeArrayGetElement(pArray, &lIndex, &Param);
  774. if(SUCCEEDED(hr))
  775. {
  776. PrintVariantString(L" NewLastConnectionError", &Param);
  777. VariantClear(&Param);
  778. }
  779. lIndex = 2;
  780. hr = SafeArrayGetElement(pArray, &lIndex, &Param);
  781. if(SUCCEEDED(hr))
  782. {
  783. PrintVariantLong(L" NewUptime", &Param);
  784. VariantClear(&Param);
  785. }
  786. VariantClear(&OutArgs);
  787. }
  788. else
  789. {
  790. printf("no action %x\n", hr);
  791. }
  792. }
  793. if(SUCCEEDED(hr))
  794. {
  795. wprintf(L"GetNATInfo\n");
  796. VARIANT OutArgs;
  797. hr = InvokeVoidAction(pICSService, L"GetNATInfo", &OutArgs);
  798. if(SUCCEEDED(hr))
  799. {
  800. SAFEARRAY* pArray = V_ARRAY(&OutArgs);
  801. LONG lIndex = 0;
  802. VARIANT Param;
  803. lIndex = 0;
  804. hr = SafeArrayGetElement(pArray, &lIndex, &Param);
  805. if(SUCCEEDED(hr))
  806. {
  807. PrintVariantBool(L" NewRSIPAvailable", &Param);
  808. VariantClear(&Param);
  809. }
  810. lIndex = 1;
  811. hr = SafeArrayGetElement(pArray, &lIndex, &Param);
  812. if(SUCCEEDED(hr))
  813. {
  814. PrintVariantBool(L" NewNATEnabled", &Param);
  815. VariantClear(&Param);
  816. }
  817. lIndex = 2;
  818. hr = SafeArrayGetElement(pArray, &lIndex, &Param);
  819. if(SUCCEEDED(hr))
  820. {
  821. PrintVariantShort(L" NewServiceMapNumberOfEntries", &Param);
  822. VariantClear(&Param);
  823. }
  824. VariantClear(&OutArgs);
  825. }
  826. else
  827. {
  828. printf("no action %x\n", hr);
  829. }
  830. }
  831. if(SUCCEEDED(hr))
  832. {
  833. wprintf(L"GetLinkLayerInfo\n");
  834. VARIANT OutArgs;
  835. hr = InvokeVoidAction(pICSService, L"GetLinkLayerInfo", &OutArgs);
  836. if(SUCCEEDED(hr))
  837. {
  838. SAFEARRAY* pArray = V_ARRAY(&OutArgs);
  839. LONG lIndex = 0;
  840. VARIANT Param;
  841. lIndex = 0;
  842. hr = SafeArrayGetElement(pArray, &lIndex, &Param);
  843. if(SUCCEEDED(hr))
  844. {
  845. PrintVariantLong(L" NewUpstreamMaxBitRate", &Param);
  846. VariantClear(&Param);
  847. }
  848. lIndex = 1;
  849. hr = SafeArrayGetElement(pArray, &lIndex, &Param);
  850. if(SUCCEEDED(hr))
  851. {
  852. PrintVariantLong(L" NewDownstreamMaxBitRate", &Param);
  853. VariantClear(&Param);
  854. }
  855. lIndex = 2;
  856. hr = SafeArrayGetElement(pArray, &lIndex, &Param);
  857. if(SUCCEEDED(hr))
  858. {
  859. PrintVariantString(L" NewPPPEncryptionProtocol", &Param);
  860. VariantClear(&Param);
  861. }
  862. lIndex = 3;
  863. hr = SafeArrayGetElement(pArray, &lIndex, &Param);
  864. if(SUCCEEDED(hr))
  865. {
  866. PrintVariantString(L" NewPPPCompressionProtocol", &Param);
  867. VariantClear(&Param);
  868. }
  869. lIndex = 4;
  870. hr = SafeArrayGetElement(pArray, &lIndex, &Param);
  871. if(SUCCEEDED(hr))
  872. {
  873. PrintVariantString(L" NewPPPAuthenticationProtocol", &Param);
  874. VariantClear(&Param);
  875. }
  876. VariantClear(&OutArgs);
  877. }
  878. else
  879. {
  880. printf("no action %x\n", hr);
  881. }
  882. }
  883. if(SUCCEEDED(hr))
  884. {
  885. wprintf(L"GetTerminationInfo\n");
  886. VARIANT OutArgs;
  887. hr = InvokeVoidAction(pICSService, L"GetTerminationInfo", &OutArgs);
  888. if(SUCCEEDED(hr))
  889. {
  890. SAFEARRAY* pArray = V_ARRAY(&OutArgs);
  891. LONG lIndex = 0;
  892. VARIANT Param;
  893. lIndex = 0;
  894. hr = SafeArrayGetElement(pArray, &lIndex, &Param);
  895. if(SUCCEEDED(hr))
  896. {
  897. PrintVariantLong(L" AutoDisconnectTime", &Param);
  898. VariantClear(&Param);
  899. }
  900. lIndex = 1;
  901. hr = SafeArrayGetElement(pArray, &lIndex, &Param);
  902. if(SUCCEEDED(hr))
  903. {
  904. PrintVariantLong(L" IdleDisconnectTime", &Param);
  905. VariantClear(&Param);
  906. }
  907. lIndex = 2;
  908. hr = SafeArrayGetElement(pArray, &lIndex, &Param);
  909. if(SUCCEEDED(hr))
  910. {
  911. PrintVariantLong(L" WarnDisconnectDelay", &Param);
  912. VariantClear(&Param);
  913. }
  914. VariantClear(&OutArgs);
  915. }
  916. else
  917. {
  918. printf("no action %x\n", hr);
  919. }
  920. }
  921. } while (UPNP_E_VARIABLE_VALUE_UNKNOWN == hr);
  922. pICSService->Release();
  923. }
  924. return hr;
  925. }
  926. HRESULT TestWANCommonDevice_WANIPConnection(IUPnPDevice* pGatewayDevice)
  927. {
  928. HRESULT hr;
  929. wprintf(L"TestWANCommonDevice_WANIPConnection\n");
  930. IUPnPService* pICSService;
  931. hr = FindService(pGatewayDevice, L"upnp:id:WANIPConnection", &pICSService);
  932. if(SUCCEEDED(hr))
  933. {
  934. do
  935. {
  936. if(SUCCEEDED(hr))
  937. {
  938. hr = PrintVariableString(pICSService, L"ConnectionType");
  939. }
  940. if(SUCCEEDED(hr))
  941. {
  942. hr = PrintVariableString(pICSService, L"PossibleConnectionTypes");
  943. }
  944. if(SUCCEEDED(hr))
  945. {
  946. hr = PrintVariableString(pICSService, L"ConnectionStatus");
  947. }
  948. if(SUCCEEDED(hr))
  949. {
  950. hr = PrintVariableLong(pICSService, L"Uptime");
  951. }
  952. if(SUCCEEDED(hr))
  953. {
  954. hr = PrintVariableBool(pICSService, L"RSIPAvailable");
  955. }
  956. if(SUCCEEDED(hr))
  957. {
  958. hr = PrintVariableBool(pICSService, L"NATEnabled");
  959. }
  960. if(SUCCEEDED(hr))
  961. {
  962. hr = PrintVariableLong(pICSService, L"AutoDisconnectTime");
  963. }
  964. if(SUCCEEDED(hr))
  965. {
  966. hr = PrintVariableLong(pICSService, L"IdleDisconnectTime");
  967. }
  968. if(SUCCEEDED(hr))
  969. {
  970. hr = PrintVariableLong(pICSService, L"WarnDisconnectDelay");
  971. }
  972. if(SUCCEEDED(hr))
  973. {
  974. hr = PrintVariableShort(pICSService, L"ServiceMapNumberOfEntries");
  975. }
  976. if(SUCCEEDED(hr))
  977. {
  978. wprintf(L"GetConnectionTypeInfo\n");
  979. VARIANT OutArgs;
  980. hr = InvokeVoidAction(pICSService, L"GetConnectionTypeInfo", &OutArgs);
  981. if(SUCCEEDED(hr))
  982. {
  983. SAFEARRAY* pArray = V_ARRAY(&OutArgs);
  984. LONG lIndex = 0;
  985. VARIANT Param;
  986. lIndex = 0;
  987. hr = SafeArrayGetElement(pArray, &lIndex, &Param);
  988. if(SUCCEEDED(hr))
  989. {
  990. PrintVariantString(L" NewConnectionType", &Param);
  991. VariantClear(&Param);
  992. }
  993. lIndex = 1;
  994. hr = SafeArrayGetElement(pArray, &lIndex, &Param);
  995. if(SUCCEEDED(hr))
  996. {
  997. PrintVariantString(L" NewPossibleConnectionTypes", &Param);
  998. VariantClear(&Param);
  999. }
  1000. VariantClear(&OutArgs);
  1001. }
  1002. else
  1003. {
  1004. printf("no action %x\n", hr);
  1005. }
  1006. }
  1007. if(SUCCEEDED(hr))
  1008. {
  1009. wprintf(L"GetStatusInfo\n");
  1010. VARIANT OutArgs;
  1011. hr = InvokeVoidAction(pICSService, L"GetStatusInfo", &OutArgs);
  1012. if(SUCCEEDED(hr))
  1013. {
  1014. SAFEARRAY* pArray = V_ARRAY(&OutArgs);
  1015. LONG lIndex = 0;
  1016. VARIANT Param;
  1017. lIndex = 0;
  1018. hr = SafeArrayGetElement(pArray, &lIndex, &Param);
  1019. if(SUCCEEDED(hr))
  1020. {
  1021. PrintVariantString(L" NewConnectionStatus", &Param);
  1022. VariantClear(&Param);
  1023. }
  1024. lIndex = 1;
  1025. hr = SafeArrayGetElement(pArray, &lIndex, &Param);
  1026. if(SUCCEEDED(hr))
  1027. {
  1028. PrintVariantString(L" NewLastConnectionError", &Param);
  1029. VariantClear(&Param);
  1030. }
  1031. lIndex = 2;
  1032. hr = SafeArrayGetElement(pArray, &lIndex, &Param);
  1033. if(SUCCEEDED(hr))
  1034. {
  1035. PrintVariantLong(L" NewUptime", &Param);
  1036. VariantClear(&Param);
  1037. }
  1038. VariantClear(&OutArgs);
  1039. }
  1040. else
  1041. {
  1042. printf("no action %x\n", hr);
  1043. }
  1044. }
  1045. if(SUCCEEDED(hr))
  1046. {
  1047. wprintf(L"GetNATInfo\n");
  1048. VARIANT OutArgs;
  1049. hr = InvokeVoidAction(pICSService, L"GetNATInfo", &OutArgs);
  1050. if(SUCCEEDED(hr))
  1051. {
  1052. SAFEARRAY* pArray = V_ARRAY(&OutArgs);
  1053. LONG lIndex = 0;
  1054. VARIANT Param;
  1055. lIndex = 0;
  1056. hr = SafeArrayGetElement(pArray, &lIndex, &Param);
  1057. if(SUCCEEDED(hr))
  1058. {
  1059. PrintVariantBool(L" NewRSIPAvailable", &Param);
  1060. VariantClear(&Param);
  1061. }
  1062. lIndex = 1;
  1063. hr = SafeArrayGetElement(pArray, &lIndex, &Param);
  1064. if(SUCCEEDED(hr))
  1065. {
  1066. PrintVariantBool(L" NewNATEnabled", &Param);
  1067. VariantClear(&Param);
  1068. }
  1069. lIndex = 2;
  1070. hr = SafeArrayGetElement(pArray, &lIndex, &Param);
  1071. if(SUCCEEDED(hr))
  1072. {
  1073. PrintVariantShort(L" NewServiceMapNumberOfEntries", &Param);
  1074. VariantClear(&Param);
  1075. }
  1076. VariantClear(&OutArgs);
  1077. }
  1078. else
  1079. {
  1080. printf("no action %x\n", hr);
  1081. }
  1082. }
  1083. if(SUCCEEDED(hr))
  1084. {
  1085. wprintf(L"GetTerminationInfo\n");
  1086. VARIANT OutArgs;
  1087. hr = InvokeVoidAction(pICSService, L"GetTerminationInfo", &OutArgs);
  1088. if(SUCCEEDED(hr))
  1089. {
  1090. SAFEARRAY* pArray = V_ARRAY(&OutArgs);
  1091. LONG lIndex = 0;
  1092. VARIANT Param;
  1093. lIndex = 0;
  1094. hr = SafeArrayGetElement(pArray, &lIndex, &Param);
  1095. if(SUCCEEDED(hr))
  1096. {
  1097. PrintVariantLong(L" AutoDisconnectTime", &Param);
  1098. VariantClear(&Param);
  1099. }
  1100. lIndex = 1;
  1101. hr = SafeArrayGetElement(pArray, &lIndex, &Param);
  1102. if(SUCCEEDED(hr))
  1103. {
  1104. PrintVariantLong(L" IdleDisconnectTime", &Param);
  1105. VariantClear(&Param);
  1106. }
  1107. lIndex = 2;
  1108. hr = SafeArrayGetElement(pArray, &lIndex, &Param);
  1109. if(SUCCEEDED(hr))
  1110. {
  1111. PrintVariantLong(L" WarnDisconnectDelay", &Param);
  1112. VariantClear(&Param);
  1113. }
  1114. VariantClear(&OutArgs);
  1115. }
  1116. else
  1117. {
  1118. printf("no action %x\n", hr);
  1119. }
  1120. }
  1121. } while (UPNP_E_VARIABLE_VALUE_UNKNOWN == hr);
  1122. pICSService->Release();
  1123. }
  1124. return hr;
  1125. }
  1126. HRESULT TestWANCommonDevice_NATStaticPortMapping(IUPnPDevice* pGatewayDevice)
  1127. {
  1128. HRESULT hr;
  1129. wprintf(L"TestWANCommonDevice_NATStaticPortMapping\n");
  1130. IUPnPService* pICSService;
  1131. hr = FindService(pGatewayDevice, L"upnp:id:NATStaticPortMapping", &pICSService);
  1132. if(SUCCEEDED(hr))
  1133. {
  1134. do
  1135. {
  1136. if(SUCCEEDED(hr))
  1137. {
  1138. hr = PrintVariableString(pICSService, L"StaticPortDescriptionList");
  1139. }
  1140. if(SUCCEEDED(hr))
  1141. {
  1142. wprintf(L"GetStaticPortMappingList\n");
  1143. VARIANT OutArgs;
  1144. hr = InvokeVoidAction(pICSService, L"GetStaticPortMappingList", &OutArgs);
  1145. if(SUCCEEDED(hr))
  1146. {
  1147. PrintOutParams(&OutArgs);
  1148. VariantClear(&OutArgs);
  1149. }
  1150. else
  1151. {
  1152. printf("no action %x\n", hr);
  1153. }
  1154. }
  1155. if(SUCCEEDED(hr))
  1156. {
  1157. wprintf(L"GetStaticPortMapping\n");
  1158. VARIANT InArgs;
  1159. VARIANT OutArgs;
  1160. hr = CreateParamArray(1, &InArgs);
  1161. if(SUCCEEDED(hr))
  1162. {
  1163. SAFEARRAY* pArray = V_ARRAY(&InArgs);
  1164. long lIndex = 0;
  1165. VARIANT Param0;
  1166. Param0.vt = VT_BSTR;
  1167. V_BSTR(&Param0) = SysAllocString(L"tester");
  1168. SafeArrayPutElement(pArray, &lIndex, &Param0);
  1169. hr = InvokeAction(pICSService, L"GetStaticPortMapping", &InArgs, &OutArgs);
  1170. if(SUCCEEDED(hr))
  1171. {
  1172. PrintOutParams(&OutArgs);
  1173. VariantClear(&OutArgs);
  1174. }
  1175. else
  1176. {
  1177. printf("no action %x\n", hr);
  1178. }
  1179. }
  1180. }
  1181. } while (UPNP_E_VARIABLE_VALUE_UNKNOWN == hr);
  1182. pICSService->Release();
  1183. }
  1184. return hr;
  1185. }
  1186. HRESULT TestWANCommonDevice_NATDynamicPortMapping(IUPnPDevice* pGatewayDevice)
  1187. {
  1188. HRESULT hr;
  1189. wprintf(L"TestWANCommonDevice_NATDynamicPortMapping\n");
  1190. IUPnPService* pICSService;
  1191. hr = FindService(pGatewayDevice, L"upnp:id:NATDynamicPortMapping", &pICSService);
  1192. if(SUCCEEDED(hr))
  1193. {
  1194. do
  1195. {
  1196. } while (UPNP_E_VARIABLE_VALUE_UNKNOWN == hr);
  1197. pICSService->Release();
  1198. }
  1199. return hr;
  1200. }
  1201. HRESULT TestWANCommonDevice_NATInfo(IUPnPDevice* pGatewayDevice)
  1202. {
  1203. HRESULT hr;
  1204. wprintf(L"TestWANCommonDevice_NATInfo\n");
  1205. IUPnPService* pICSService;
  1206. hr = FindService(pGatewayDevice, L"upnp:id:NATInfo", &pICSService);
  1207. if(SUCCEEDED(hr))
  1208. {
  1209. do
  1210. {
  1211. } while (UPNP_E_VARIABLE_VALUE_UNKNOWN == hr);
  1212. pICSService->Release();
  1213. }
  1214. return hr;
  1215. }
  1216. int __cdecl main(int argc, char* argv[])
  1217. {
  1218. HRESULT hr;
  1219. hr = CoInitialize(NULL);
  1220. if(SUCCEEDED(hr))
  1221. {
  1222. IUPnPDevice* pGatewayDevice;
  1223. hr = FindGatewayDevice(&pGatewayDevice);
  1224. if(SUCCEEDED(hr))
  1225. {
  1226. // TestInternetGatewayDevice_OSInfo(pGatewayDevice);
  1227. IUPnPDevice* pWANDevice;
  1228. hr = FindChildDevice(pGatewayDevice, &pWANDevice);
  1229. if(SUCCEEDED(hr))
  1230. {
  1231. //TestWANDevice_WANCommonInterfaceConfig(pWANDevice);
  1232. IUPnPDevice* pWANConnectionDevice;
  1233. hr = FindChildDevice(pWANDevice, &pWANConnectionDevice);
  1234. if(SUCCEEDED(hr))
  1235. {
  1236. // TestWANCommonDevice_WANPOTSLinkConfig(pWANConnectionDevice);
  1237. // TestWANCommonDevice_WANPPPConnection(pWANConnectionDevice);
  1238. // TestWANCommonDevice_WANIPConnection(pWANConnectionDevice);
  1239. TestWANCommonDevice_NATStaticPortMapping(pWANConnectionDevice);
  1240. TestWANCommonDevice_NATDynamicPortMapping(pWANConnectionDevice);
  1241. TestWANCommonDevice_NATInfo(pWANConnectionDevice);
  1242. pWANConnectionDevice->Release();
  1243. }
  1244. pWANDevice->Release();
  1245. }
  1246. pGatewayDevice->Release();
  1247. }
  1248. CoUninitialize();
  1249. }
  1250. return 0;
  1251. }