wlanutilities/wlanwizard/src/wlanwizardscanlist.cpp
changeset 50 d4198dcb9983
parent 46 2fbd1d709fe7
equal deleted inserted replaced
46:2fbd1d709fe7 50:d4198dcb9983
    24 #include <wlanqtutilsap.h>
    24 #include <wlanqtutilsap.h>
    25 
    25 
    26 // User includes
    26 // User includes
    27 #include "wlanwizardscanlist.h"
    27 #include "wlanwizardscanlist.h"
    28 #include "wlanwizardpageinternal.h"
    28 #include "wlanwizardpageinternal.h"
       
    29 #include "OstTraceDefinitions.h"
       
    30 #ifdef OST_TRACE_COMPILER_IN_USE
       
    31 #include "wlanwizardscanlistTraces.h"
       
    32 #endif
       
    33 
    29 
    34 
    30 /*!
    35 /*!
    31  * Constructor for WlanWizardScanList object.
    36  * Constructor for WlanWizardScanList object.
    32  */
    37  */
    33 WlanWizardScanList::WlanWizardScanList()
    38 WlanWizardScanList::WlanWizardScanList(): mWpsSelected(false)
    34 {
    39 {
       
    40     OstTraceFunctionEntry0( WLANWIZARDSCANLIST_WLANWIZARDSCANLIST_ENTRY );
    35 
    41 
       
    42     OstTraceFunctionExit0( WLANWIZARDSCANLIST_WLANWIZARDSCANLIST_EXIT );
    36 }
    43 }
    37 
    44 
    38 /*!
    45 /*!
    39  * Copy Constructor for WlanWizardScanList object.
    46  * Copy Constructor for WlanWizardScanList object.
    40  * @param [in] scanList is the object to be copied.
    47  * @param [in] scanList is the object to be copied.
    41  */
    48  */
    42 WlanWizardScanList::WlanWizardScanList(const WlanWizardScanList &scanList):
    49 WlanWizardScanList::WlanWizardScanList(const WlanWizardScanList &scanList):
    43     mOpenOptions(scanList.mOpenOptions)
    50 mOpenOptions(scanList.mOpenOptions), mWpsSelected(false)
    44 {
    51 {
       
    52     OstTraceFunctionEntry0( DUP1_WLANWIZARDSCANLIST_WLANWIZARDSCANLIST_ENTRY );
    45 
    53 
       
    54     OstTraceFunctionExit0( DUP1_WLANWIZARDSCANLIST_WLANWIZARDSCANLIST_EXIT );
    46 }
    55 }
    47 
    56 
    48 /*!
    57 /*!
    49  * Destructor for WlanWizardScanList object.
    58  * Destructor for WlanWizardScanList object.
    50  */
    59  */
    51 WlanWizardScanList::~WlanWizardScanList()
    60 WlanWizardScanList::~WlanWizardScanList()
    52 {
    61 {
       
    62     OstTraceFunctionEntry0( DUP2_WLANWIZARDSCANLIST_WLANWIZARDSCANLIST_ENTRY );
    53 
    63 
       
    64     OstTraceFunctionExit0( DUP2_WLANWIZARDSCANLIST_WLANWIZARDSCANLIST_EXIT );
    54 }
    65 }
    55 
    66 
    56 /*!
    67 /*!
    57  * This function builds a hash list of scan results. Key value in a hash item
    68  * This function builds a hash list of scan results. Key value in a hash item
    58  * is the network mode and the associated value is a list of security modes.
    69  * is the network mode and the associated value is a list of security modes.
    60  * to one or more security modes.
    71  * to one or more security modes.
    61  * @param [in] results contains a list of scan results.
    72  * @param [in] results contains a list of scan results.
    62  */
    73  */
    63 void WlanWizardScanList::build(const QList<WlanScanResult> &results)
    74 void WlanWizardScanList::build(const QList<WlanScanResult> &results)
    64 {
    75 {
       
    76     OstTraceFunctionEntry0( WLANWIZARDSCANLIST_BUILD_ENTRY );
       
    77     
       
    78     mWpsSelected = true;
       
    79     
    65     for (int i = 0; i < results.size(); i++) {
    80     for (int i = 0; i < results.size(); i++) {
    66         WlanNetworkSetting netMode;
    81         WlanNetworkSetting netMode;
    67         WlanSecuritySetting secMode;
    82         WlanSecuritySetting secMode;
    68         WlanScanResult item = results.at(i);
    83         WlanScanResult item = results.at(i);
    69         
    84 
    70         netMode.wpsSupported = item.scanResult->value(WlanQtUtilsAp::ConfIdWpsSupported).toBool();
    85         netMode.wpsSupported = item.scanResult->value(WlanQtUtilsAp::ConfIdWpsSupported).toBool();
    71         netMode.mode = item.scanResult->value(WlanQtUtilsAp::ConfIdConnectionMode).toInt();
    86         netMode.mode = item.scanResult->value(WlanQtUtilsAp::ConfIdConnectionMode).toInt();
    72         netMode.hidden = (netMode.mode == CMManagerShim::Adhoc) ? false : item.networkHidden;
    87         netMode.hidden = (netMode.mode == CMManagerShim::Adhoc) ? false : item.networkHidden;
    73         
    88 
    74         secMode.mode = item.scanResult->value(WlanQtUtilsAp::ConfIdSecurityMode).toInt();
    89         secMode.mode = item.scanResult->value(WlanQtUtilsAp::ConfIdSecurityMode).toInt();
    75         secMode.usePsk = (secMode.mode == CMManagerShim::WlanSecModeWep) ? true
    90         secMode.usePsk = (secMode.mode == CMManagerShim::WlanSecModeWep) ? true
    76             : item.scanResult->value(WlanQtUtilsAp::ConfIdWpaPskUse).toBool();
    91             : item.scanResult->value(WlanQtUtilsAp::ConfIdWpaPskUse).toBool();
    77 
    92 
    78         switch (secMode.mode) {
    93         switch (secMode.mode) {
    79         case CMManagerShim::WlanSecMode802_1x:
    94         case CMManagerShim::WlanSecMode802_1x:
    80             secMode.nextPageId = WlanWizardPage::PageEapStart;
    95             secMode.nextPageId = WlanWizardPage::PageEapStart;
    81             break;
    96             break;
    82             
    97 
    83         case CMManagerShim::WlanSecModeWep:
    98         case CMManagerShim::WlanSecModeWep:
    84             secMode.nextPageId = WlanWizardPageInternal::PageKeyQuery;
    99             secMode.nextPageId = WlanWizardPageInternal::PageKeyQuery;
    85             break;
   100             break;
    86             
   101 
    87         case CMManagerShim::WlanSecModeWpa:
   102         case CMManagerShim::WlanSecModeWpa:
    88         case CMManagerShim::WlanSecModeWpa2:
   103         case CMManagerShim::WlanSecModeWpa2:
    89             if (secMode.usePsk) {
   104             if (secMode.usePsk) {
    90                 secMode.nextPageId = WlanWizardPageInternal::PageKeyQuery;
   105                 secMode.nextPageId = WlanWizardPageInternal::PageKeyQuery;
    91             }
   106             }
    97         default:
   112         default:
    98             Q_ASSERT(CMManagerShim::WlanSecModeOpen == secMode.mode ||
   113             Q_ASSERT(CMManagerShim::WlanSecModeOpen == secMode.mode ||
    99                 CMManagerShim::WlanSecModeWapi == secMode.mode);
   114                 CMManagerShim::WlanSecModeWapi == secMode.mode);
   100             secMode.nextPageId = WlanWizardPage::PageProcessSettings;
   115             secMode.nextPageId = WlanWizardPage::PageProcessSettings;
   101             break;
   116             break;
   102             
   117 
   103         }
   118         }
   104         
   119 
   105         // prevent duplicate settings.
   120         // prevent duplicate settings.
   106         if (!mOpenOptions.contains(netMode)) {
   121         if (!mOpenOptions.contains(netMode)) {
       
   122             mWpsSelected = (mWpsSelected && netMode.wpsSupported);
   107             QList<WlanSecuritySetting> secList;
   123             QList<WlanSecuritySetting> secList;
   108             secList.append(secMode);
   124             secList.append(secMode);
   109             mOpenOptions.insert(netMode, secList);
   125             mOpenOptions.insert(netMode, secList);
   110         }
   126         }
   111         else if (!(mOpenOptions.find(netMode)->contains(secMode))) {
   127         else if (!(mOpenOptions.find(netMode)->contains(secMode))) {
   112             mOpenOptions.find(netMode)->append(secMode);  
   128             mOpenOptions.find(netMode)->append(secMode);  
   113         }
   129         }
   114         // else an identical key-value pair is already in the list -> not added.
   130         // else an identical key-value pair is already in the list -> not added.
   115     }
   131     }
       
   132     OstTraceFunctionExit0( WLANWIZARDSCANLIST_BUILD_EXIT );
   116 }
   133 }
   117 
   134 
   118 /*!
   135 /*!
   119  * This function returns a security mode setting at the requested location.
   136  * This function returns a security mode setting at the requested location.
   120  * This function does not do any validity checks for the lists, so the user
   137  * This function does not do any validity checks for the lists, so the user
   125  */
   142  */
   126 const WlanSecuritySetting &WlanWizardScanList::getSecMode(
   143 const WlanSecuritySetting &WlanWizardScanList::getSecMode(
   127     WlanNetworkSetting netMode,
   144     WlanNetworkSetting netMode,
   128     int index) const
   145     int index) const
   129 {
   146 {
       
   147     OstTraceFunctionEntry0( WLANWIZARDSCANLIST_GETSECMODE_ENTRY );
   130     return mOpenOptions.value(netMode).at(index);
   148     return mOpenOptions.value(netMode).at(index);
   131 }
   149 }
   132 
   150 
   133 /*!
   151 /*!
   134  * The number of key values available in the hash list.
   152  * The number of key values available in the hash list.
   135  * @return the number of keys.
   153  * @return the number of keys.
   136  */
   154  */
   137 int WlanWizardScanList::netModes() const
   155 int WlanWizardScanList::netModes() const
   138 {
   156 {
       
   157     OstTraceFunctionEntry0( WLANWIZARDSCANLIST_NETMODES_ENTRY );
   139     return mOpenOptions.size();
   158     return mOpenOptions.size();
   140 }
   159 }
   141 
   160 
   142 /*!
   161 /*!
   143  * The size of the security mode list associated to a network mode.
   162  * The size of the security mode list associated to a network mode.
   144  * @param [in] netMode key value for the hash list.
   163  * @param [in] netMode key value for the hash list.
   145  * @return the size of the list associated with the key.
   164  * @return the size of the list associated with the key.
   146  */
   165  */
   147 int WlanWizardScanList::secModes(WlanNetworkSetting netMode) const
   166 int WlanWizardScanList::secModes(WlanNetworkSetting netMode) const
   148 {
   167 {
       
   168     OstTraceFunctionEntry0( WLANWIZARDSCANLIST_SECMODES_ENTRY );
       
   169     Q_ASSERT(mOpenOptions.contains(netMode));
   149     return mOpenOptions.find(netMode)->size();
   170     return mOpenOptions.find(netMode)->size();
   150 }
   171 }
   151 
   172 
   152 /*!
   173 /*!
   153  * This function returns the list of keys in the hash.
   174  * This function returns the list of keys in the hash.
   154  * @return a list of keys.
   175  * @return a list of keys.
   155  */
   176  */
   156 QList<WlanNetworkSetting> WlanWizardScanList::getNetModes() const
   177 QList<WlanNetworkSetting> WlanWizardScanList::getNetModes() const
   157 {
   178 {
       
   179     OstTraceFunctionEntry0( WLANWIZARDSCANLIST_GETNETMODES_ENTRY );
   158     return mOpenOptions.keys();
   180     return mOpenOptions.keys();
   159 }
   181 }
   160 
   182 
       
   183 /*!
       
   184  * This function indicates whether the list of scan results supports
       
   185  * Wi-Fi Protected Setup.
       
   186  * @return true, if all result network modes support wps, false if even
       
   187  * a single result does not.
       
   188  */
       
   189 bool WlanWizardScanList::wpsSelected() const
       
   190 {
       
   191     OstTraceFunctionEntry0( WLANWIZARDSCANLIST_WPSSELECTED_ENTRY );
       
   192     return mWpsSelected;
       
   193 }