/// <summary>
        /// Gets the <see cref="Microsoft.MixedReality.Toolkit.WindowsDevicePortal.AvailableWiFiNetworks"/> of the target device.
        /// </summary>
        /// <param name="interfaceInfo">The GUID for the network interface to use to search for wireless networks, without brackets.</param>
        /// <returns><see cref="Microsoft.MixedReality.Toolkit.WindowsDevicePortal.AvailableWiFiNetworks"/></returns>
        public static async Task <AvailableWiFiNetworks> GetAvailableWiFiNetworksAsync(DeviceInfo targetDevice, InterfaceInfo interfaceInfo)
        {
            var isAuth = await EnsureAuthenticationAsync(targetDevice);

            if (!isAuth)
            {
                return(null);
            }

            string query    = string.Format(WiFiNetworkQuery, FinalizeUrl(targetDevice.IP), $"s?interface={interfaceInfo.GUID}");
            var    response = await Rest.GetAsync(query, targetDevice.Authorization);

            if (!response.Successful)
            {
                if (response.ResponseCode == 403 && await RefreshCsrfTokenAsync(targetDevice))
                {
                    return(await GetAvailableWiFiNetworksAsync(targetDevice, interfaceInfo));
                }

                Debug.LogError(response.ResponseBody);
                return(null);
            }

            return(JsonUtility.FromJson <AvailableWiFiNetworks>(response.ResponseBody));
        }
        /// <summary>
        /// Connects to the specified WiFi Network.
        /// </summary>
        /// <param name="interfaceInfo">The interface to use to connect.</param>
        /// <param name="wifiNetwork">The network to connect to.</param>
        /// <param name="password">Password for network access.</param>
        /// <returns>True, if connection successful.</returns>
        public static async Task <Response> ConnectToWiFiNetworkAsync(DeviceInfo targetDevice, InterfaceInfo interfaceInfo, WirelessNetworkInfo wifiNetwork, string password)
        {
            var isAuth = await EnsureAuthenticationAsync(targetDevice);

            if (!isAuth)
            {
                return(new Response(false, "Unable to authenticate with device", null, 403));
            }

            string query = string.Format(
                WiFiNetworkQuery,
                FinalizeUrl(targetDevice.IP),
                $"?interface={interfaceInfo.GUID}&ssid={wifiNetwork.SSID.EncodeTo64()}&op=connect&createprofile=yes&key={password}");

            return(await Rest.PostAsync(query, targetDevice.Authorization));
        }
示例#3
0
        /// <summary>
        /// Gets the <see cref="Microsoft.MixedReality.Toolkit.WindowsDevicePortal.AvailableWiFiNetworks"/> of the target device.
        /// </summary>
        /// <param name="interfaceInfo">The GUID for the network interface to use to search for wireless networks, without brackets.</param>
        /// <returns><see cref="Microsoft.MixedReality.Toolkit.WindowsDevicePortal.AvailableWiFiNetworks"/></returns>
        public static async Task <AvailableWiFiNetworks> GetAvailableWiFiNetworksAsync(DeviceInfo targetDevice, InterfaceInfo interfaceInfo)
        {
            var isAuth = await EnsureAuthenticationAsync(targetDevice);

            if (!isAuth)
            {
                return(null);
            }

            string query    = string.Format(WiFiNetworkQuery, FinalizeUrl(targetDevice.IP), $"s?interface={interfaceInfo.GUID}");
            var    response = await RestHelpers.Rest.GetAsync(query, targetDevice.Authorization, readResponseData : true, certificateHandler : DevicePortalCertificateHandler, disposeCertificateHandlerOnDispose : false);

            if (!response.Successful)
            {
                if (response.ResponseCode == 403 && await RefreshCsrfTokenAsync(targetDevice))
                {
                    return(await GetAvailableWiFiNetworksAsync(targetDevice, interfaceInfo));
                }

                Debug.LogError(await response.GetResponseBody());
                return(null);
            }

            return(JsonUtility.FromJson <AvailableWiFiNetworks>(await response.GetResponseBody()));
        }