Jump to content
Sign in to follow this  
MattyD

Native Wifi Functions

Recommended Posts

Hi,

I hope I'm right here.

I also want to add a new WLAN profile and connect to it afterwards.

I tried the code Cartoondragon posted.

The profile gets added, but it seems that the usercredentials are not getting stored, because everytime I try to

connect to the Wlan Windows asks me for the username and password...

Can anyone help?

Share this post


Link to post
Share on other sites

Hi all

Obviously I have been on hiatus for quite some time now - and as much as this project means to me, I'm having a little trouble getting motivated to pour in the hours that is needed to bring it up to speed.  Just considering support for Windows 8 both means both some core project changes (for Wifi Direct support) and  much mundane coding to keep the profile objects up to date (Introduction of quite a few new EAP methods).  I'm also a little worried that by myself I'll be Windows 8 ready way too late for it to be of any use to anyone.

so I reckon I have a few options

1. Wait for a change of heart, suck it up and just power on coding 

2. Round it off at Windows 7 and retire the project

3. Lessen the scope of the project and focus on parts of the API that people actually care about (I'll definitely need some guidance here!)

4. GIT the project, steer it, and hope someone else will chip in code (they'll to put up with me and my "creative" coding environment :) )

5. Sign off on the current project and put it into the wild

6. Leave it in Limbo I guess

Just want to say if I do round off the project I'd hate to leave anyone hanging.  Theres a wide enough base I think for offshoot projects, and I'd be happy enough to provide custom code for other (real) projects for a credit.

Any thoughts are of course welcome - honestly at this stage I think I'll probably bite the bullet, code for a week and get sick of it. Then defer making a decision again.

Thanks as always,

Matt

Share this post


Link to post
Share on other sites

As far as I have been able to ascertain, this is the only comprehensive UDF of its kind. I certainly hope you don't give up on it, and in fact bring it up-to-date for Win 8. In any case, you have my thanks for keeping it going as long as you did.
 
TAC
 

Any thoughts are of course welcome - honestly at this stage I think I'll probably bite the bullet, code for a week and get sick of it. Then defer making a decision again.
 
Thanks as always,
Matt

Share this post


Link to post
Share on other sites

Hi, in these days I took a look at the script and MattyD did a really good job!

But I didn't understand the need of an external compiled WlanNotify.exe script... I've searched on the repository for WlanNotify.au3 and I tried it only in "Full Backup 2012-09-20.zip" archive (on sourceforge.net)..

Substantially it just starts wlan notifications calling WlanRegisterNotification with a callback function ("_WLAN_NOTIFICATION_CALLBACK") and it writes the output to a named pipe (".pipeNWifi").

Can't be written directly in the main script NativeWifi.au3?

Share this post


Link to post
Share on other sites

As far as I have been able to ascertain, this is the only comprehensive UDF of its kind. I certainly hope you don't give up on it, and in fact bring it up-to-date for Win 8. In any case, you have my thanks for keeping it going as long as you did.

 

TAC

 

 

Thanks TAC, it is appreciated. (really).

 

Given that theres still a steady flow of hits coming through on Sourceforge, I'll probably open up git and see what happens. To be realistic though, I doubt it'll take.

 

Hi, in these days I took a look at the script and MattyD did a really good job!

But I didn't understand the need of an external compiled WlanNotify.exe script... I've searched on the repository for WlanNotify.au3 and I tried it only in "Full Backup 2012-09-20.zip" archive (on sourceforge.net)..

Substantially it just starts wlan notifications calling WlanRegisterNotification with a callback function ("_WLAN_NOTIFICATION_CALLBACK") and it writes the output to a named pipe (".pipeNWifi").

Can't be written directly in the main script NativeWifi.au3?

 
Unfortunately its not that easy - believe me I wish it were!. A new thread is kicked off when a callback occurs which causes AutoIt to freakout if it is in the middle of another operation.
 
If you examine the source code closely, you'll see that the WlanNotify module actually pauses its own thread. This allows it to handle the notifications from the API without interruption. We are just lucky those notifications are queued by the API so only one can come through at a time :)
 
Cheers,
Matt

Share this post


Link to post
Share on other sites

Unfortunately its not that easy - believe me I wish it were!. A new thread is kicked off when a callback occurs which causes AutoIt to freakout if it is in the middle of another operation.

 

Are you sure? I think the main loop is just suspended...

I've modified NativeWifi.au3 a little to include WlanNotify.au3, but I receive 536 error (ERROR_PIPE_LISTENING: Waiting for a process to open the other end of the pipe) with GetLastError in _Wlan_CacheNotification() because Autoit thread can't read both pipe ends. I think if I can substitute Pipes use with memory implementation the script can run!

scripts.zip

Share this post


Link to post
Share on other sites

Hey J0kky,

I think if I can substitute Pipes use with memory implementation the script can run!

 

FYI If you're having a play, I have an array in a global scope called $asNotificationCache which you should be able to directly write to.

Its not documented - but the structure of that array is as follows:

$asNotificationCache[$i][0] holds the timestamp (so it can be discarded after a period of time)

$asNotificationCache[$i][1] holds the comma separated notification data in the following format:

source (int), code (int), guid (string - human readable), notification (string - human readable), raw data of elements returned in the notification struct

 

Most of the hard work is already done for you done in the _WLAN_NOTIFICATION_CALLBACK function - you'll just need to modify it a bit.

 

Are you sure? I think the main loop is just suspended...

 

Try giving this a spin dude, and you'll see what I mean.  If the script is idling you'll be fine for the most part - not so much when things get busy! 

Global $hWLANAPI = DllOpen("WlanAPI.dll")
Local $hClientHandle = _WinAPI_WlanOpenHandle(2)

Local $tCallback = DllCallbackRegister("_WLAN_NOTIFICATION_CALLBACK", "none", "ptr;ptr")
_WinAPI_WlanRegisterNotification($hClientHandle, 0XFFFF, True, DllCallbackGetPtr($tCallback))

Local $iTimer = TimerInit(), $iDoSomething
While TimerDiff($iTimer) < 120000
   $iDoSomething +=1
   ;Sleep(10) ;Comment out this line and generate notifications! (connect to a network for example)
WEnd

_WinAPI_WlanCloseHandle($hClientHandle)
DllClose($hWLANAPI)

Func _WLAN_NOTIFICATION_CALLBACK($pNotificationData, $pVoid)
    Local $tNotifData, $iNotifSource, $iNotifCode
    $tNotifData = DllStructCreate("dword NotificationSource; dword NotificationCode; byte GUID[16]; dword DataSize; ptr Data", $pNotificationData)
    $iNotifSource = DllStructGetData($tNotifData, "NotificationSource")
    $iNotifCode = DllStructGetData($tNotifData, "NotificationCode")

    ConsoleWrite("Notification! Source:" & $iNotifSource & " Code:" & $iNotifCode & @CRLF)
EndFunc

Func _WinAPI_WlanOpenHandle($iClientVersion, $pReserved = 0)
    Local $aResult = DllCall($hWLANAPI, "dword", "WlanOpenHandle", "dword", $iClientVersion, "ptr", $pReserved, "dword*", 0, "hwnd*", 0)
    If @error Then Return SetError(1, @error, False)
    If $aResult[0] Then Return SetError(2, $aResult[0], False)
    Return SetExtended($aResult[3], $aResult[4])
EndFunc

Func _WinAPI_WlanRegisterNotification($hClientHandle, $iNotifSource, $fIgnoreDuplicate, $pNotificationCallback = 0, $pCallbackContext = 0, $pReserved = 0)
    Local $aResult = DllCall($hWLANAPI, "dword", "WlanRegisterNotification", "hwnd", $hClientHandle, "dword", $iNotifSource, "int", $fIgnoreDuplicate, "ptr", $pNotificationCallback, "ptr", $pCallbackContext, "ptr", $pReserved, "ptr*", 0)
    If @error Then Return SetError(1, @error, False)
    If $aResult[0] Then Return SetError(2, $aResult[0], False)
    Return SetExtended($aResult[7], True)
EndFunc

Func _WinAPI_WlanCloseHandle($hClientHandle, $pReserved = 0)
    Local $aResult = DllCall($hWLANAPI, "dword", "WlanCloseHandle", "ptr", $hClientHandle, "ptr", $pReserved)
    If @error Then Return SetError(1, @error, False)
    If $aResult[0] Then Return SetError(2, $aResult[0], False)
    Return True
EndFunc

Cheers,

Matt

Share this post


Link to post
Share on other sites

You're right, your loop fails, but I think it is a problem regarding Timers.

Instead of :

Local $iTimer = TimerInit(), $iDoSomething
While TimerDiff($iTimer) < 120000
   $iDoSomething +=1
   ;Sleep(10) ;Comment out this line and generate notifications! (connect to a network for example)
WEnd

Try this one:

$handle = WinGetHandle(GUICreate("TEST"))
$label1 = GUICtrlCreateLabel("0", 150, 150, 70)
$label2 = GUICtrlCreateLabel("0", 150, 180, 70)
GUISetState(@SW_SHOW)
$counter = 0
$timer = TimerInit()
Sleep(500)
While 1
    $counter += 1
    Beep(500, 500)
    GUICtrlSetData($label1, $counter)
    GUICtrlSetData($label2, TimerDiff($timer))
    Sleep(500)
    If $counter = 10 Then ExitLoop
WEnd

Share this post


Link to post
Share on other sites

midvalley,

I had a quick play with this over the weekend, and didn't make much progress.

I'm thinking the profile is OK. You can set that profile generated by windows by doing this:

_Wlan_SetProfile(FileRead("My Profile.xml"), $sReason)
It didn't make any difference for me though.

I've double checked the back end of the _Wlan_SetProfileUserData function and all looks OK there too. I'm starting to think there may be a bug in the API (wouldn't be the first). Googling the WLAN_SET_EAPHOST_DATA_ALL_USERS flag returns jack all - which is always helpful.

That being said I couldn't get the creds in the HKLM hive even through the GUI - so it could be me. Perhaps I'll try another more up-to-date machine...

Cheers,

Matt

 

 

I just came across this script (it's great!) but I'm having the same issue as above. I take it you never managed to figure this one out? 

I got all excited when I found the WlanSetProfileEapXmlUserData function on MSDN, got turned away that it was only C++ as the example, then found this and got excited again, only to be let down :(

Has anyone figured out how to get credentials to save to HKLM instead of HKCU? I tried simply copying the registry key over but that didn't work. 

Share this post


Link to post
Share on other sites

Hi MattyD

I noticed a problem with the USB wifi app and left this here for you. This is the section for showing the wifi profiles and returns all the ssid profile names to an array
There was a problem with building the dll stucture so I removed it and just ran a small loop to build it.

; ///////////////////////////////////////////////////////////////////////////////////////////
; ------------------------------------------------------------
; SHOW ALL SET USER WIFI PROFILES
; -----------------------------------------------------------
Func _GetProfileALL($hClientHandle, $pGUID)
Local $pProfileList, $PROFILE_LIST, $NumberOfItems, $ii = 0, $StructString1 = "", $StructString, $index = 0, $WLAN_PROFILE_INFO_LIST = "dword dwNumberOfItems; dword dwIndex; "
local $a_iCall = DllCall($hDLL, "dword", "WlanGetProfileList", "hwnd", $hClientHandle, "ptr", $pGUID, "ptr", 0, "ptr*", 0)
$pProfileList = $a_iCall[4]
$PROFILE_LIST = DllStructCreate($WLAN_PROFILE_INFO_LIST, $pProfileList)
$NumberOfItems = DllStructGetData($PROFILE_LIST, "dwNumberOfItems")
;-----------------------------------------------------------------------------------
;-----------------------------------------------------------------------------------
; THIS CREATES THE DLL STRUCTURE PER PROFILE
Do
$StructString1 = $StructString1 & "wchar strProfileName" & $ii & "[256]; dword dwFlags" & $ii & "; "
$ii = $ii + 1
Until $ii = $NumberOfItems
;-----------------------------------------------------------------------------------
;-----------------------------------------------------------------------------------
$StructString = $WLAN_PROFILE_INFO_LIST & $StructString1
$PROFILE_LIST = DllStructCreate($StructString, $pProfileList)
Dim $ProfileArray[$NumberOfItems]
For $i = 0 To $NumberOfItems - 1
$ProfileArray[$i] = DllStructGetData($PROFILE_LIST, "strProfileName" & $index)
;;;ConsoleWrite("DEBUG 3:" & $ProfileArray[$i] & @CRLF)
$index += 1
Next
DllCall($hDLL, "dword", "WlanFreeMemory", "ptr", $pProfileList) ;Free memory
Return $ProfileArray
EndFunc
; ///////////////////////////////////////////////////////////////////////////////////////////

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...