in reply to Re: Adding WlanConnect() to Win32::Wlan::API
in thread Adding WlanConnect() to Win32::Wlan::API

@corion Hey, thanks for the reply and suggesting pack(). Dunno about the "easy" bit but failing me getting a solution in perl, as at last resort one could outsource this to a native implementation and start an external process. Pure perl would be nicer though.

The IPPI signature is correct as is my GUID. However, the return value of the $API{ WlanConnect }->Call() is 87. Would this be need to be massaged into something meaningful?

Replies are listed 'Best First'.
Re^3: Adding WlanConnect() to Win32::Wlan::API (87)
by tye (Sage) on Jun 26, 2012 at 20:06 UTC

      I have a feeling that there's nothing obvious wrong with the values as such set in the perl application code. Under XP, it's mostly defaults that are available. Passing them on to the DLL seems to be the problem.

        So, I'd likely next look at the guts of whatever that *Struct module ends up generating (probably via 'perl -d').

        - tye        

Re^3: Adding WlanConnect() to Win32::Wlan::API
by bulk88 (Priest) on Jun 26, 2012 at 23:47 UTC
    How are you sure your GUID is correct? Win32::API doesn't have any built in understanding of GUIDs. If you got your GUIDs by dropping the '-'s, you did it wrong. Also there might be a bug in your using of Encode. Encode won't put a wide null unless you explicitly have a "\x00" in the scalar that you can see. Encode WONT see the secret null that perl keeps after the end of the visible string. Win32::API uses the letter S, not P for structs. P is for a scalar string (or self packed integer "\x01\x02\x03\x04" or self packed struct). An API::Struct is a object, if you print it, you'll probably get the reference in hex. So whoever is using the the IPPI prototype is very wrong.

    Post the code where you created the API object and the prototype you used. Your code isn't runnable currently.

    update, I just noticed the part where you mentioned "Win32::Wlan::API", the previous 2 paragraphs were written without me realizing your using a CPAN mod. After looking at Wlan::API, I see Wlan::API never uses API::Struct. Using P instead of S is probably your error.

      The GUID is obtained the same way the stock Wlan::API does it and it is used all over the place, e.g in the (added by me) WlanSetProfile(), which creates a new profile from the required XML structures like thus:

      sub WlanSetProfile { croak "Wlan functions are not available" unless $wlan_available; my ($handle, $guuid, $xmlref) = @_; my $reason = Zero; $API{ WlanSetProfile }->Call($handle, $guuid, 0, $$xmlref, 0, 1, 0 +, $reason) == 0 or die "$^E"; };

      Background: I want to automate establishing an ad-hoc network. On XP, insecure WEP is the only available encryption method. So, in order to make things a bit more secure, before connecting I create a new profile with a new WEP key, effectively creating a session key.

      WlanSetProfile() succeeds and I can use the new profile to connect manually. So, the GUID is good. Also, the UTF16LE profilename is good, because before creating a new profile, I do some housekeeping and delete the previously used profile with the (added by me) WlanDeleteProfile()

      sub WlanDeleteProfile { croak "Wlan functions are not available" unless $wlan_available; my ($handle, $guuid, $profilename) = @_; $API{ WlanDeleteProfile }->Call($handle, $guuid, $profilename, 0) +== 0 or die "$^E"; };

      Deleting a profile works by supplying its name in the required fashion. WlanDeleteProfile() succeeds.

      Unfortunately, using S for P in the signature

      ['WlanConnect' => 'IPSI' => 'I']

      makes no difference.

      I think my best bet is to follow Corion's suggestion and investigate pack()ing some string.

        Can you post your whole modified Win32 Wlan module, or atleast api.pm, wlan.pm, and something that uses your WlanConnect? I'll obviously have to slightly modify it to work with my SSID. If its a bug with Win32::API I'm willing to fix it. Since the GUIDs are known to work, and aren't hard coded, I know they are fine.

        Update: I decided to try and see if its a Win32::API or user problem in using Win32::API or a MS API problem. The following code, with the IPPI signature. generated
        hClientHandle 0x00000001 void * + pInterfaceGuid 0x00a55324 {04030201-0605-0807-0910-11121314151 +6} const _GUID * - pConnectionParameters 0x00a21594 {wlanConnectionMode=862873943 + strProfile=0x413a3a32 <Bad Ptr> pDot11Ssid=0x3a3a4950 {uSSIDLength=? +?? ucSSID=0x3a3a4954 <Bad Ptr> } ...} _WLAN_CONNECTION_PARAMETERS +* const wlanConnectionMode 862873943 _WLAN_CONNECTION_MODE - strProfile 0x413a3a32 <Bad Ptr> const unsigned short * CXX0030: Error: expression cannot be evaluated const unsign +ed short - pDot11Ssid 0x3a3a4950 {uSSIDLength=??? ucSSID=0x3a3a4954 <Bad +Ptr> } _DOT11_SSID * uSSIDLength CXX0030: Error: expression cannot be evaluated u +nsigned long + ucSSID 0x3a3a4954 <Bad Ptr> unsigned char [32] - pDesiredBssidList 0x75727453 {Header={Type=??? Revision=??? Si +ze=??? } uNumOfEntries=??? uTotalNumOfEntries=??? ...} DOT11_BSSID +_LIST * + Header {Type=??? Revision=??? Size=??? } _NDIS_OBJECT_HEADE +R uNumOfEntries CXX0030: Error: expression cannot be evaluated + unsigned long uTotalNumOfEntries CXX0030: Error: expression cannot be evaluat +ed unsigned long + BSSIDs 0x7572745f unsigned char [1][6] dot11BssType 1211987043 _DOT11_BSS_TYPE dwFlags 675828545 unsigned long pReserved 0x00000000 void *
        in C. pConnectionParameters is gibberish, and its exactly what I thought it would be.
        0x00A21594 57 69 6e 33 32 3a 3a 41 50 49 3a 3a 53 74 72 75 63 74 3d 4 +8 41 53 48 28 30 78 61 34 64 Win32::API::Struct=HASH(0xa4d 0x00A215B1 61 62 63 29 00 00 00 00 26 94 22 14 0d 02 00 00 00 ad ba a +b ab ab ab ab ab ab ab ee 04 abc)....&&#148;"......н║ллллллллю.
        Now I changed the signature to IPSI, and, I don't know how you ran it, but Win32::API errored out and died on me.
        Use of uninitialized value $type in string eq at C:/perl512/site/lib/W +in32/API/S truct.pm line 205. Use of uninitialized value $type in pattern match (m//) at C:/perl512/ +site/lib/W in32/API/Struct.pm line 216. Use of uninitialized value $type in concatenation (.) or string at C:/ +perl512/si te/lib/Win32/API/Struct.pm line 221. Use of uninitialized value $type in string eq at C:/perl512/site/lib/W +in32/API/S truct.pm line 223. Use of uninitialized value $name in hash element at C:/perl512/site/li +b/Win32/AP I/Struct.pm line 228. Use of uninitialized value $self in string eq at C:/perl512/site/lib/W +in32/API/T ype.pm line 161. Use of uninitialized value $type in exists at C:/perl512/site/lib/Win3 +2/API/Type .pm line 167. Use of uninitialized value $type in pattern match (m//) at C:/perl512/ +site/lib/W in32/API/Type.pm line 173. Use of uninitialized value $type in substitution (s///) at C:/perl512/ +site/lib/W in32/API/Type.pm line 180. Use of uninitialized value $type in exists at C:/perl512/site/lib/Win3 +2/API/Type .pm line 182. Use of uninitialized value $packing in pattern match (m//) at C:/perl5 +12/site/li b/Win32/API/Type.pm line 142. Use of uninitialized value $packing in hash element at C:/perl512/site +/lib/Win32 /API/Type.pm line 146. Use of uninitialized value $type_size in addition (+) at C:/perl512/si +te/lib/Win 32/API/Struct.pm line 232. Use of uninitialized value $type_size in modulus (%) at C:/perl512/sit +e/lib/Win3 2/API/Struct.pm line 232. Illegal modulus zero at C:/perl512/site/lib/Win32/API/Struct.pm line 2 +32.