static HRESULT RunScenario(CONFIGURATION_PARAMETERS configParams) { //common declarations HRESULT hr = HRESULT.S_OK; int pinLen = (int)Pin_Length_8; //pin needs to be a null terminated ascii byte[] for the IWCNDevice::SetPassword function var pin = new StringBuilder(pinLen + 1); //Wlan variable declarations StringBuilder profileBuffer = null; WCN_DEVICE_INFO_PARAMETERS WCNDeviceInformation = new WCN_DEVICE_INFO_PARAMETERS(); //The following wlan profile xml is used to configure an unconfigured WCN enabled Router or device. //See http://msdn.microsoft.com/en-us/library/bb525370(VS.85).aspx on how to generate a wlan profile. //Alternatively, you can read an existing network profile by calling WlanGetProfile. const string WCNConnectionProfileTemplate = "<?xml version=\"1.0\" ?>" + "" + "<WLANProfile xmlns=\"http://www.microsoft.com/networking/WLAN/profile/v1\">" + " <name>{0}</name>" + "" + " <SSIDConfig>" + " <SSID>" + " <name>{1}</name>" + " </SSID>" + " </SSIDConfig>" + " " + " <connectionType>ESS</connectionType>" + " <connectionMode>auto</connectionMode>" + "" + " <MSM>" + " <security>" + " <authEncryption>" + " <authentication>WPA2PSK</authentication>" + " <encryption>AES</encryption>" + " </authEncryption>" + "" + "" + " <sharedKey>" + " <keyType>passPhrase</keyType>" + " <protected>false</protected>" + " <keyMaterial>{2}</keyMaterial>" + " </sharedKey>" + "" + " </security>" + " </MSM>" + "</WLANProfile>"; //open a wlan handle - this will be used later for saving the profile to the system var status = WlanOpenHandle(WLAN_API_VERSION_2_0, default, out var negVersion, out var wlanHandle);
static HRESULT GetWCNDeviceInformation(IWCNDevice pDevice, WCN_DEVICE_INFO_PARAMETERS pWCNDeviceInformation) { HRESULT hr = Win32Error.ERROR_SUCCESS; //A WCN device can have a variety of attributes. (These attributes generally correspond //to TLVs in the WPS specification, although not all WPS TLVs are available as WCN attributes). //You can use the IWCNDevice::Get*Attribute to read these attributes. Not all devices send //all attributes -- if the device did not send a particular attribute, the Get*Attribute API //will return HRESULT _FROM_WIN32(ERROR_NOT_FOUND). // //This sample demonstrates how to get the most common attributes that would be useful for //displaying in a user interface. // // WCN_TYPE_DEVICE_NAME // //The IWCNDevice::GetStringAttribute method gets a cached attribute from the device as a string. hr = GetStringAttribute(WCN_ATTRIBUTE_TYPE.WCN_TYPE_DEVICE_NAME, out pWCNDeviceInformation.wszDeviceName); if (hr != Win32Error.ERROR_SUCCESS) { Console.Write("\nERROR: Failed to get the Device Name from the IWCNDevice instance. hr=[0x{0:X}]", (uint)hr); goto cleanup; } Console.Write("\nINFO: Device Name: [{0}]", pWCNDeviceInformation.wszDeviceName); // // WCN_TYPE_MANUFACTURER // hr = GetStringAttribute(WCN_ATTRIBUTE_TYPE.WCN_TYPE_MANUFACTURER, out pWCNDeviceInformation.wszManufacturerName); if (hr != Win32Error.ERROR_SUCCESS) { Console.Write("\nERROR: Failed to get the device manufacturer from the ICWNDevice instance, hr=[0x{0:X}]", (uint)hr); goto cleanup; } Console.Write("\nINFO: Manufacturer Name: [{0}]", pWCNDeviceInformation.wszManufacturerName); HRESULT GetStringAttribute(WCN_ATTRIBUTE_TYPE at, out string str) => FunctionHelper.CallMethodWithStrBuf((StringBuilder sb, ref uint s) => pDevice.GetStringAttribute(at, s, sb), out str); // // WCN_TYPE_MODEL_NAME // hr = GetStringAttribute(WCN_ATTRIBUTE_TYPE.WCN_TYPE_MODEL_NAME, out pWCNDeviceInformation.wszModelName); if (hr != Win32Error.ERROR_SUCCESS) { Console.Write("\nERROR: Failed to get the device model name from the ICWNDevice instance, hr=[0x{0:X}]", (uint)hr); goto cleanup; } Console.Write("\nINFO: Model Name: [{0}]", pWCNDeviceInformation.wszModelName); // // WCN_TYPE_MODEL_NUMBER // Note that the Model Number is actually a string. Most devices have alpha-numeric // model numbers, like "AB1234CD". hr = GetStringAttribute(WCN_ATTRIBUTE_TYPE.WCN_TYPE_MODEL_NUMBER, out pWCNDeviceInformation.wszModelNumber); if (hr != Win32Error.ERROR_SUCCESS) { Console.Write("\nERROR: Failed to get the device model name from the ICWNDevice instance, hr=[0x{0:X}]", (uint)hr); goto cleanup; } Console.Write("\nINFO: Model Number: [{0}]", pWCNDeviceInformation.wszModelNumber); // // WCN_TYPE_SERIAL_NUMBER // Note that the Serial Number is actually a string. Some devices send strings that // aren't meaningful, like "(none)" or just the empty string. hr = GetStringAttribute(WCN_ATTRIBUTE_TYPE.WCN_TYPE_SERIAL_NUMBER, out pWCNDeviceInformation.wszSerialNumber); if (hr != Win32Error.ERROR_SUCCESS) { Console.Write("\nERROR: Failed to get the device model name from the ICWNDevice instance, hr=[0x{0:X}]", (uint)hr); goto cleanup; } Console.Write("\nINFO: Serial Number: [{0}]", pWCNDeviceInformation.wszSerialNumber); // // WCN_TYPE_CONFIG_METHODS // This is a bit mask of the values from WCN_VALUE_TYPE_CONFIG_METHODS. // For example, a devices indicates support for pushbutton if its Config // Methods value includes the WCN_VALUE_CM_PUSHBUTTON flag. //The GetIntegerAttribute method gets a cached attribute from the device as an integer. hr = pDevice.GetIntegerAttribute(WCN_ATTRIBUTE_TYPE.WCN_TYPE_CONFIG_METHODS, out pWCNDeviceInformation.uConfigMethods); if (hr != Win32Error.ERROR_SUCCESS) { Console.Write("\nERROR: Failed to get the device model name from the ICWNDevice instance, hr=[0x{0:X}]", (uint)hr); goto cleanup; } cleanup: return(hr); }