"How To" Series: Configuring Network Adapters with Compact Framework

There was a question in the forums, if there is a way to configure a network adapter automatically - without an user interaction. Using the UI, the user may select "My network card connects to" value for every adapter in the adapters list. It may be changed to point one of the available network destinations like "The Internet" , "Work", etc. So, is there a way to this automatically?

In short the answer is YES! There is a way. We may prepare an OMA Client Provisioning File and pass it to the appropriate configuration provider in Windows Mobile.

 

 

 

An appropriate configuration file would be like this:

<wap-provisioningdoc>
    <characteristic type="CM_NetEntries"> 
        <characteristic type="Adapter Name"> 
           <parm name="DestId" value="{A1182988-0D73-439e-87AD-2A5B369F808B}"/>              
           <parm name="Adapter" value="Qualified Name"/>   
        </characteristic> 
    </characteristic>
</wap-provisioningdoc>


This file will bind a network adapter named "Adapter Name" to the "Work" destination. We have to change the "Adapter Name" value with the name of the adapter as it is seen in the adapters list. The "Qualified Name" should be changed with the fully qualified name of the adapter - it may be obtained by using the GetAdaptersAddresses routine.
If we want to change the destination to "The Internet" , we have to supply different GUID for the DestId parameter.
Following network identifiers as configured by default on Windows Mobile:

The Internet: {436EF144-B4FB-4863-A041-8F905A62C572}
Work: {A1182988-0D73-439e-87AD-2A5B369F808B}
WAP Network: {7022E968-5A97-4051-BC1C-C578E2FBA5D9}
Secure WAP Network:{F28D1F74-72BE-4394-A4A7-4E296219390C}
CurrentDTPTNetwork:{A1182988-0D73-439e-87AD-2A5B369F808B}

What we have to do in order to apply this configuration setting? We have the following options:
1. Preparing the provisioning Xml file , save it as _setup.xml, and place it inside a CAB file. We may "execute" the file on the device, then. Check out this post for details about deploying provisioning files with CABs.
2. We may apply these settings through code(Compact Framework) by using the managed Microsoft.WindowsMobile.Configuration.ConfigurationManager class from Windows Mobile 5 SDK:

            string configurationXml = "<wap-provisioningdoc><characteristic type=\"CM_NetEntries\">"+
           "<characteristic type=\"Adapter Name\"><parm name=\"DestId\" "+
           "value=\"{A1182988-0D73-439e-87AD-2A5B369F808B}\"/><parm name=\"Adapter\" value=\"Qualified Name\" /> "+ 
        "</characteristic></characteristic></wap-provisioningdoc>";
            // Load XML
            XmlDocument configurationXmlDoc = new XmlDocument();
            configurationXmlDoc.LoadXml(configurationXml);
            // Send to Configuration Manager
            ConfigurationManager.ProcessConfiguration(configurationXmlDoc, false);
Also the unmanaged version DMProcessConfigXML may be used Check out this post for unmanaged wrapper of DMProcessConfigXML

Links
CM_NetEntries Configuration Service Provider Examples for OMA Client Provisioning
Injecting Provisioning XML into a cab using VS 2005 on the Windows Mobile Blog
DMProcessConfigXML on the Marcus Perryman's WebLog
Windows Mobile Device Management for more configuration options

Comments

# re: "How To" Series: Configuring Network Adapters with Compact Framework

Wednesday, August 08, 2007 3:04 AM by Ilya

Hi Ruslan

I have a question regarding the alike issue : I need to change GRPS connection from the C# application. This GRPS connection has 2 "numbers"/access points to dial and I want to be able to disconnect from the connected and to reconnect to the other one.

Do you know if it is possible ?

Thanks in advance

# re: "How To" Series: Configuring Network Adapters with Compact Framework

Wednesday, August 08, 2007 6:44 AM by xman892

Pleace see if the following provisioning xml examples may help:

http://msdn2.microsoft.com/en-us/library/aa456106.aspx

http://msdn2.microsoft.com/en-us/library/aa456094.aspx

You may find  descriptions of the parameters here:

http://msdn2.microsoft.com/en-us/library/aa455849.aspx

there is a DevSpecificCellular/GPRSInfoAccessPointName param, which may be used to modify the gprs access point

you may deploy the xml file by one of the methods described in the post.

You may also use rapiconfig.exe  to provision devices from the PC (while testing your xml file)

# re: "How To" Series: Configuring Network Adapters with Compact Framework

Wednesday, August 08, 2007 8:22 AM by Ilya

2 xman892 :

First of all thanks for the fast reply !!!

I reviewed the links you posted and came up with something like this :

String regularXML = "<characteristic type=\"CM_GPRSEntries\"><characteristic type=\"GPRS1\">" +

               "<parm name=\"DestId\" value=\"{18AD9FBD-F716-ACB6-FD8A-1965DB95B814}\" />" +

               "<parm name=\"UserName\" value=\"\"/><parm name=\"Password\" value=\"\" />" +

               "<parm name=\"Domain\" value=\"\" /><characteristic type=\"DevSpecificCellular\">" +

               "<parm name=\"GPRSInfoValid\" value=\"1\" /><parm name=\"GPRSInfoAccessPointName\" value=\"regular\" />" +

               "</characteristic></characteristic></characteristic>";

           // Load XML

           XmlDocument regularXMLDoc = new XmlDocument();

           regularXMLDoc.LoadXml(regularXML);

           // Send to Configuration Manager

           ConfigurationManager.ProcessConfiguration(regularXMLDoc, false);

The only question's left - in case there are two possible connections in the same DestID ( Lets say My ISP ), how do I make him to connect to the connection specified by me and not default ? Or may be I can change the default ? I did not find answers to this questions ...

Thanks again

# re: "How To" Series: Configuring Network Adapters with Compact Framework

Wednesday, August 08, 2007 9:36 AM by xman892

As far as I know there is no direct API to control which connection to use.

The only way around (which I know) is to provision the Connection manager Planner - the component which calculates the "cheaper" connection.  You should pass the right xml to the configuration manager just before establishing the connection.

check out this link:

http://msdn2.microsoft.com/en-us/library/aa455853.aspx

http://msdn2.microsoft.com/en-us/library/aa456089.aspx

.. try playing with the PreferredConnections tag

See if this short overview of the ConnectionManager may be of use

http://blogs.msdn.com/cenet/archive/2006/06/06/620360.aspx

Ruslan

# re: "How To" Series: Configuring Network Adapters with Compact Framework

Wednesday, August 08, 2007 11:19 AM by Ilya

Ruslan

Thanks a lot !!!

I'm checking this out now and I'll reply back with the results !!!!

Ilya

# re: "How To" Series: Configuring Network Adapters with Compact Framework

Wednesday, August 08, 2007 6:50 PM by Ilya

OK !!!

It is working as expected !!!

Thanks a lot again !!!

Ilya