Resources | developer.brewmp.com Resources | developer.brewmp.com

Developer

resources

Connecting to a WLAN

Base version:

Brew® MP 1.0.2

Tested version:

Brew MP 1.0.2

Phone tested:

Yes

Objective

This document describes how to connect to a wireless access point using wlan_IConnMgr.

Requirements

To create an application, you must:

  • install the Brew MP Multi-Platform SDK - see the Brew MP Developer's website for installation instructions.
  • have a WLAN enabled device.

To test on a device, you must install a RealView Development suite (RVCT) or ARM Development Suite (ADS) compiler.

To connect to a WLAN:

  • Create an instance of wlan_IConnMgr.
  • Scan for networks, if you know the connect information, you do not need to do a scan.
  • Call wlan_IConnMgr_Connect() to connect to the network.

To search for WLANs:

  1. Create an instance of wlan_IConnMgr.
  2. Create a signal object.
  3. Setup the signal by calling wlan_IConnMgr_OnScanEnd().
  4. Start the scan by calling wlan_IConnMgr_StartScan().
  5. When the callback is triggered, call wlan_IConnMgr_GetNetworks() to get the list of available networks returned by the scan.

Sample code location

ZIP filename

Location

Run app

c_wlanconnmgrapp_1.0.0.zip

Brew MP Library

  • Download and extract the ZIP file.

  • Compile the app.

  • Run it on a device.

Example - Creating an instance of wlan_IConnMgr

Use the IShell create instance function to create a wlan_IConnMgr object.

nResult = ISHELL_CreateInstance(pMe->piShell, wlan_AEECLSID_ConnMgr,
                               (void**)(&pMe->piConnMgr));
if( SUCCESS != nResult) 
{
   DBGPRINTF("Create instance of wlan_IConnMgr failed Return Value %d",
              nResult);
   pMe->piConnMgr = NULL;
}

Example - Starting a scan

Before starting a scan, you must create a signal and set up the signal with the wlan_IConnMgr object. Then you call wlan_IConnMgr_StartScan() to start the scan.

nErr = WCM_CreateSignal(pMe->piShell, WCM_StartScanCB, pMe,
   &pMe->piSignal, &pMe->piSignalCtl);
if (AEE_SUCCESS != nErr) 
{
   goto bail;
}

nErr = wlan_IConnMgr_OnScanEnd(pMe->piConnMgr, pMe->piSignal);
if (AEE_SUCCESS != nErr) 
{
   goto bail;
}

nErr = wlan_IConnMgr_StartScan(pMe->piConnMgr);
if (AEE_SUCCESS != nErr) 
{
   goto bail;
}

Example - Retrieving the network list

When the wlan_IConnMgr is done finding the available networks, it generates the callback signal. In the callback function, you must call wlan_IConnMgr_GetNetworks() to determine if any networks were found and the buffer size needed.

nErr = wlan_IConnMgr_GetNetworks(pMe->piConnMgr, 
                               &bScanInProgress, 
                               pMe->pNet, pMe->nNetCount, 
                               &nNetworksLenReq);

After allocating the space defined in nNetworksLenReq, call wlan_IConnMgr_GetNetworks() to get the network list.

// allocate space
pMe->pNet = REALLOC(pMe->pNet, sizeof(wlan_Network) 
                            * nNetworksLenReq);
// Get the network string
nErr = wlan_IConnMgr_GetNetworks(pMe->piConnMgr, &bScanInProgress, 
                                       pMe->pNet, pMe->nNetCount, 
                                       NULL);

Example - Connecting to an access point

To connect to a WLAN access point, you must create and set up a callback function, and then try to connect.

nErr = WCM_CreateSignal(pMe->piShell, WCM_ConnectCB, pMe,
                       &pMe->piSignal, &pMe->piSignalCtl);
if (AEE_SUCCESS != nErr) 
{
   goto bail;
}

nErr = wlan_IConnMgr_OnConnectStatusChange(pMe->piConnMgr, 
                         pMe->piSignal);
if (AEE_SUCCESS != nErr) 
{
   goto bail;
}
     
nErr = wlan_IConnMgr_Connect(pMe->piConnMgr, pNet, 
                         wlan_SCAN_AUTO, enc, pAuthInfo);
if (AEE_SUCCESS != nErr) 
{
   WCM_DisplayMsg(pMe, "Connect failed %d \n", nErr );
   goto bail;
}

Example - Retrieving network information

To get the status of the network connection, you call wlan_IConnMgr_GetConnectStatus(). This function can be used at any time.

wlan_IConnMgr_GetConnectStatus( pMe->piConnMgr,&status, &reason, 
                                &bInfoAvail, &net);

Example - Disconnecting from an access point

To disconnect from a WLAN access point, you must create and set up a callback function, and then try and disconnect.

nErr = WCM_CreateSignal(pMe->piShell, WCM_DisconnectCB, pMe,
                       &pMe->piSignal, &pMe->piSignalCtl);
if (AEE_SUCCESS != nErr) 
{
    goto bail;
}

nErr = wlan_IConnMgr_OnConnectStatusChange(pMe->piConnMgr, pMe->piSignal);
if (AEE_SUCCESS != nErr) 
{
    goto bail;
}

nErr = wlan_IConnMgr_Disconnect(pMe->piConnMgr);
if (AEE_SUCCESS != nErr) 
{
   goto bail;
}