Exception in WlanOpenHandle if called to soon after reboot

We have a crash (unhandled exception 0x6ba) when calling WlanOpenHandle in our application after rebooting. It does not happen when we add a delay of about 3 seconds when starting the application. We are working with LM007 Wifi dongle (https://www.lm-technologies.com/product/wifi-usb-adapter-150mbps-lm007/).

Here is the debug output:

ÿToradex Bootloader 1.5b4 Built on Apr 17 2019
Splash screen is enabled.
Colibri iMX6S 256MB 1.1A Serial: 05193410
SPL enabled version.
Using 8MB of IPU memory and 16MB of GPU memory.
CPU is running at 984MHz.
Using eMMC boot partition (size: 4096 sectors).
Initializing L2 Cache.
Configuring pin 30
Press [SPACE] to enter Bootloader Menu

Initiating image launch in 2 seconds. <BS><BS><BS><BS><BS><BS><BS><BS><BS><BS><BS>1 seconds. <BS><BS><BS><BS><BS><BS><BS><BS><BS><BS><BS>0 seconds. 
System ready!
Preparing for download...
Loading compressed image...
Reading image from sector 40962.
Extracting 45858080 bytes from compressed image of 25154476 bytes
.......................
Done.
Launching image at 10200000.
Toradex Windows CE 7.0 1.5b4
 for iMX6 Built on Apr 17 2019
Colibri iMX6 Solo 256MB
Wait mode Disabled
SMP support disabled
RTC origin set to: 2006/01/01.
Registry - loading version 68 from 16386.
Registry loaded.
Loading Clock...
GPU enabled.
DVFS not enabled.
Done Loading Clock (14 ms)
Loading GPIO Multiplexer...
Failed(0) Loading GPIO Multiplexer (1 ms)
Loading SD Bus...
Done Loading SD Bus (0 ms)
Loading eMMC...
Loading I2C2...
Done Loading I2C2 (1 ms)
Done Loading eMMC (9 ms)
Waiting for flash disk \Flashdisk for 30 seconds
Loading I2C1...
Done Loading I2C1 (1 ms)
Folder mounted
Loading external SD interface...
SD clock always on on slot 2
SD slot 2 is using custom multiplexing.
Loading iMX6 PCIE driver...
Failed(0) Loading iMX6 PCIE driver (0 ms)
Loading PMIC...
Loading USB Host Controller...
Loading USB OTG...
Done Loading USB OTG (2 ms)
Loading SD card...
Loading 2D/3D Graphic Accelerator...
Loading Image Processing Unit...
Done Loading Image Processing Unit (1 ms)
Loading SPI2...
Multiplexing must be specified for non standard SPI port.
Failed(0) Loading SPI2 (5 ms)
Loading SPI1...
Done Loading SPI1 (0 ms)
Loading UARTC...
Done Loading UARTC (1 ms)
Done Loading 2D/3D Graphic Accelerator (84 ms)
Loading UARTB...
Done Loading UARTB (0 ms)
Loading UARTA...
Port is used for OS debug! 
Failed(0) Loading UARTA (3 ms)
Loading Audio...
Loading Ethernet...
Loading Display...
Initializing display using splash screen settings.
GPU2D enabled.
Done Loading Display.
Ethernet: Disconnected 
Done Loading Ethernet (250 ms)
Done Loading SD card (394 ms)
Turning display ON.
Done Loading PMIC (404 ms)
USB HOST: Forcing Full Speed
Loading DHCP v4...
Done Loading DHCP v4 (0 ms)
Done Loading USB Host Controller (480 ms)
Loading HDCP v6...
Done Loading HDCP v6 (0 ms)
Done Loading external SD interface (533 ms)
Load TouchButton: PosX 4,PosY 495,width 132,height 45,vkKey 58 <LF><CR>Load TouchButton: PosX 136,PosY 495,width 132,height 45,vkKey 59 <LF><CR>Load TouchButton: PosX 268,PosY 495,width 264,height 45,vkKey 60 <LF><CR>Load TouchButton: PosX 532,PosY 495,width 132,height 45,vkKey 62 <LF><CR>Load TouchButton: PosX 664,PosY 495,width 132,height 45,vkKey 63 <LF><CR>Loading Touch...
Maximum Allowed Error 5:
Done Loading Touch.
Done Loading Audio (1546 ms)
Reading RTC failed.
No external RTC found
RTCSync: Completed.
Loading USB OTG Host...
Done Loading USB OTG Host (65 ms)
Unloading USB OTG Host...
Done Unloading USB OTG Host (52 ms)
USB Device: Forcing Full Speed
Warning: you are requesting IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMTYPE, which has been deprecated.  Use IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMNAME instead.
Warning: you are requesting IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMTYPE, which has been deprecated.  Use IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMNAME instead.
Warning: you are requesting IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMTYPE, which has been deprecated.  Use IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMNAME instead.
Warning: you are requesting IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMTYPE, which has been deprecated.  Use IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMNAME instead.
Warning: you are requesting IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMTYPE, which has been deprecated.  Use IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMNAME instead.
Warning: you are requesting IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMTYPE, which has been deprecated.  Use IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMNAME instead.
Warning: you are requesting IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMTYPE, which has been deprecated.  Use IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMNAME instead.
Warning: you are requesting IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMTYPE, which has been deprecated.  Use IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMNAME instead.
Warning: you are requesting IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMTYPE, which has been deprecated.  Use IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMNAME instead.
Warning: you are requesting IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMTYPE, which has been deprecated.  Use IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMNAME instead.
Warning: you are requesting IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMTYPE, which has been deprecated.  Use IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMNAME instead.
Warning: you are requesting IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMTYPE, which has been deprecated.  Use IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMNAME instead.
Warning: you are requesting IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMTYPE, which has been deprecated.  Use IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMNAME instead.
Warning: you are requesting IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMTYPE, which has been deprecated.  Use IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMNAME instead.
Display: 800x480@60Hz PCLK: 29000000
Loading PP...
Done Loading PP (1 ms)
Turning display ON.
Warning: you are requesting IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMTYPE, which has been deprecated.  Use IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMNAME instead.
Warning: you are requesting IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMTYPE, which has been deprecated.  Use IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMNAME instead.
Warning: you are requesting IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMTYPE, which has been deprecated.  Use IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMNAME instead.
Warning: you are requesting IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMTYPE, which has been deprecated.  Use IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMNAME instead.
Warning: you are requesting IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMTYPE, which has been deprecated.  Use IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMNAME instead.
Warning: you are requesting IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMTYPE, which has been deprecated.  Use IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMNAME instead.
Warning: you are requesting IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMTYPE, which has been deprecated.  Use IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMNAME instead.
Warning: you are requesting IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMTYPE, which has been deprecated.  Use IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMNAME instead.
Warning: you are requesting IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMTYPE, which has been deprecated.  Use IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMNAME instead.
Warning: you are requesting IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMTYPE, which has been deprecated.  Use IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMNAME instead.
Warning: you are requesting IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMTYPE, which has been deprecated.  Use IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMNAME instead.
Warning: you are requesting IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMTYPE, which has been deprecated.  Use IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMNAME instead.
Warning: you are requesting IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMTYPE, which has been deprecated.  Use IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMNAME instead.
Warning: you are requesting IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMTYPE, which has been deprecated.  Use IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMNAME instead.
Warning: you are requesting IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMTYPE, which has been deprecated.  Use IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMNAME instead.
Warning: you are requesting IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMTYPE, which has been deprecated.  Use IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMNAME instead.
Warning: you are requesting IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMTYPE, which has been deprecated.  Use IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMNAME instead.
Warning: you are requesting IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMTYPE, which has been deprecated.  Use IOCTL_HAL_GET_DEVICE_INFO::SPI_GETPLATFORMNAME instead.
Exception 'Raised Exception' (0x6ba): Thread-Id=044b006e(pth=af840000), Proc-Id=05270062(pprc=af89ba44) 'FireFox.exe', VM-active=05270062(pprc=af89ba44) 'FireFox.exe'
PC=4002b484(coredll.dll+0x0001b484) RA=80232648(kernel.dll+0x0000e648) SP=0159eb48, BVA=00000000
Exception 'Data Abort' (0x4): Thread-Id=044b006e(pth=af840000), Proc-Id=05270062(pprc=af89ba44) 'FireFox.exe', VM-active=05270062(pprc=af89ba44) 'FireFox.exe'
PC=0097f3f4(FireFox.exe+0x0096f3f4) RA=4002fa5c(coredll.dll+0x0001fa5c) SP=0159e3f0, BVA=00000000

Is there a way to access the WLANAPI earlier?

Dear widtmann,

You may need to wait for Shell ready API before using WlanOpenHandle and displaying the contents, refer example code below

// Wait for the shell to be ready
while (WAIT_OBJECT_0 != WaitForAPIReady(SH_SHELL, 500))
;

For more information, please go through this code : C:\WINCE700\public\common\oak\drivers\netui\quickconfigui.c. You need to install the Windows Embedded Compact platform builder to access the code.

Let us know if it doesn’t solve the problem.

We’ve added the recommended line before opening the handle but we still have the same exception:

#include "kfuncs.h"
extern "C" DWORD WaitForAPIReady(DWORD, DWORD);

WifiNativeWrapper::WifiNativeWrapper() : PMT::ItfCommunication::IWiFiWrapper(), m_clientHandle(0) {

                while (WAIT_OBJECT_0 != WaitForAPIReady(SH_SHELL, 500)); 

                DWORD negotiatedVersion = NULL;
                DWORD dwReturn = WlanOpenHandle(WLAN_API_VERSION_1_0, NULL, &negotiatedVersion, &m_clientHandle);
                if (dwReturn != ERROR_SUCCESS) 
                {
                    TRACE_TEXT_FORMAT( TRACE_ERROR, "WifiNativeWrapper: Error code %d, could not create Handle!", dwReturn );
                }
           }

I have to correct myself, we actually don’t run explorer.exe in our configuration (https://developer.toradex.com/knowledge-base/disable-and-enable-the-explorer). The while loop is actually not leaving without explorer.exe running. We are using USB sticks to run explorer.exe for development purposes and this USB stick was connected during the tests. However, in this case the exception happens as mentioned in the previous comment.

Dear @widtmann,

We are glad to know that you found a solution. We would like to ask a few questions related to this topic

  • Are you using Connection Manager APIs or WLAN APIs in your application?

  • What was the purpose did you disable the connection manager previously.

  • Is your application starting by HKLM\Init registry feature or through Autorun or starting batch file through and lunching the application using command.

  • We use WLAN API in our application. I think Connection Manager API is not used.
  • We disabled Connection Manager since we had problems getting our LM007 Wifi dongle working in the beginning (trial and error). At that time explorer.exe was not yet disabled so popup windows with Wifi networks showed up over our application.
  • Our application starts through the AutoRun mechanism on /FlashDisk

We just realized that our application cannot connect to a wireless network anymore when Connection Manager is enabled. Enumerating wireless networks is working but the connection fails. So, we have to disable the Connection Manager again in order to get WLAN API working correctly.
That means we are back to our original problem with the exception in WlanOpenHandle.

We have implemented a small executable which just calls WlanOpenHandle and placed it in /FlashDisk/AutoRun/. WlanOpenHandle does always return error code 1722 (RPC server unavailable) immediately after boot up. As already mentioned, we don’t have explorer.exe running and Connection Manager is disabled. A delay of about 4 seconds helps to avoid the error but it is kind of an ugly workaround.
Any ideas how to improve the behavior?

Dear @widtmann,

I tested the issue with WlanOpenHandle() called early in boot with connection manager disabled. I could reproduce the exception, but it looks like the exception is handled inside wlanapi.dll and the call to WlanOpenHandle() cleanly returns with an error (1722).
Here is the output i get from my test application:

WiFiTest
Exception 'Raised Exception' (0x6ba): Thread-Id=0552000a(pth=a2873a58), Proc-Id=054e000a(pprc=a2873708) 'sandbox.exe', VM-active=054e000a(pprc=a2873708) 'sandbox.exe'
PC=4002b4a4(coredll.dll+0x0001b4a4) RA=80071648(kernel.dll+0x0000e648) SP=0002f930, BVA=00000000
[WLANAPI] RPC exception, error 1722
[WLANAPI] Failed to open handle at the server side, error 1722
Failed

The last “Failed” is coming from my test application checking the return value from WlanOpenHandle().
So a possible workaround for you if you don’t want to want a fixed amount of time would be to call WlanOpenHandle() in a loop until it returns ERROR_SUCCESS.

The reason why we see the exception is because we add an exception handler for unhandled exceptions in the very beginning of our application (AddVectoredExceptionHandler). With that in place the exception inside WLAN API is caught immediately and the application exits.
I added the loop over WlanOpenHandle just before hooking in the exception handler and that works as expected. However, this is still a workaround for us since we would expect the WLAN API ready when our application is starting.

We’ve finally found the solution for our problem. The Connection Manager was disabled at an early stage of development (https://developer.toradex.com/knowledge-base/wifi-configuration-from-program#Windows_CE_7 / https://docs.toradex.com/104147-connectionmanagerremove.zip). Obviously this part is needed to get the Wifi Framework up and running faster. Using the original registry settings fixes our issue.

Dear @widtmann,
The reason why WLANAPI is not ready yet when starting your application comes from the fact that we now do parallel loading of all drivers / services. You could disable this behavior, but boot time would increase 1-2 seconds. See this:
https://developer.toradex.com/software/windows-embedded-compact/t20-t30-wec-software/release-details?view=all&issue=39671

BTW: is that really a port of FireFox (web browser) that you are running? Would it be possible to share it?

Ok, I see the point now. Probably we would end up with the same boot time if we would disable the parallel driver loading. We might consider it after the upcoming release of our application but for now the current solution works for us.

BTW: Our application is not related to the web browser, the name is a little confusing.