Home | History | Annotate | Download | only in scanCncn
      1 /****************************************************************************
      2 **+-----------------------------------------------------------------------+**
      3 **|                                                                       |**
      4 **| Copyright(c) 1998 - 2008 Texas Instruments. All rights reserved.      |**
      5 **| All rights reserved.                                                  |**
      6 **|                                                                       |**
      7 **| Redistribution and use in source and binary forms, with or without    |**
      8 **| modification, are permitted provided that the following conditions    |**
      9 **| are met:                                                              |**
     10 **|                                                                       |**
     11 **|  * Redistributions of source code must retain the above copyright     |**
     12 **|    notice, this list of conditions and the following disclaimer.      |**
     13 **|  * Redistributions in binary form must reproduce the above copyright  |**
     14 **|    notice, this list of conditions and the following disclaimer in    |**
     15 **|    the documentation and/or other materials provided with the         |**
     16 **|    distribution.                                                      |**
     17 **|  * Neither the name Texas Instruments nor the names of its            |**
     18 **|    contributors may be used to endorse or promote products derived    |**
     19 **|    from this software without specific prior written permission.      |**
     20 **|                                                                       |**
     21 **| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS   |**
     22 **| "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT     |**
     23 **| LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |**
     24 **| A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  |**
     25 **| OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |**
     26 **| SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT      |**
     27 **| LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |**
     28 **| DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |**
     29 **| THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT   |**
     30 **| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |**
     31 **| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  |**
     32 **|                                                                       |**
     33 **+-----------------------------------------------------------------------+**
     34 ****************************************************************************/
     35 
     36 /** \file ScanCncnAppApi.c
     37  *  \brief This file include implementation of application scan requests adapter.\n
     38  *  \author Ronen Kalish
     39  *  \date 30-Jan-2005
     40  */
     41 
     42 #include "ScanCncnAppApi.h"
     43 #include "ScanCncn.h"
     44 #include "EvHandler.h"
     45 #include "report.h"
     46 #include "smeApi.h"
     47 #include "siteMgrApi.h"
     48 #include "ScanCncnOidSM.h"
     49 
     50 /**
     51  * \author Ronen Kalish\n
     52  * \date 30-Jan-2005\n
     53  * \brief Parses and executes a set param command.\n
     54  *
     55  * Function Scope \e Public.\n
     56  * \param hScanCncn - handle to the scan concentrator object.\n
     57  * \param pParam - the param to set.\n
     58  * \return OK if the scan started successfully, NOK otherwise.\n
     59  */
     60 TI_STATUS scanConcentrator_setParam( TI_HANDLE hScanCncn, paramInfo_t *pParam )
     61 {
     62     scanConcentrator_t* pScanConcentrator = (scanConcentrator_t *)hScanCncn;
     63 	scan_Params_t* pScanParam;
     64 	UINT32 currentTimeStamp;
     65 
     66     switch ( pParam->paramType )
     67     {
     68 	case SCAN_CNCN_START_APP_SCAN:
     69 		pScanParam = pParam->content.pScanParams;
     70 		/*
     71 		 * Prepare scan complete's aging, by increasing the scanned sites
     72 		 * scan attemps counter. The counter will be checked upon scan complete,
     73 		 * and the sites with no update scan results will be dropped.
     74 		 */
     75 		siteMgr_setNotReceivedParameter( pScanConcentrator->hSiteManager, &(pScanParam->desiredSsid), pScanParam->band );
     76 
     77 		if ( SCAN_CRS_SCAN_RUNNING !=
     78                 scanConcentrator_scan( hScanCncn, SCAN_SCC_APP, pScanParam ) )
     79         {
     80             /* Scan was not started successfully, send a scan complete event to the user */
     81             EvHandlerSendEvent( pScanConcentrator->hEventSrv, IPC_EVENT_SCAN_COMPLETE, NULL, 0 );
     82             return NOK;
     83         }
     84         break;
     85 
     86     case SCAN_CNCN_STOP_APP_SCAN:
     87         scanConcentrator_stopScan( hScanCncn, SCAN_SCC_APP );
     88         break;
     89 	case SCAN_CNCN_BSSID_LIST_SCAN_PARAM:
     90 		/* check if OID scans are enabled in the registry */
     91 		if ( 0 == pScanConcentrator->initParams.minimumDurationBetweenOidScans )
     92 		{
     93 			WLAN_REPORT_INFORMATION( pScanConcentrator->hReport, SCAN_CNCN_MODULE_LOG,
     94 									 ("Received OID scan request when OID scans are disabled, quitting...\n") );
     95 			return OK; /* TODO ronen: return correct Windows value */
     96 		}
     97 
     98 		/* check if the last OID scan didn't start at a shorter duration than the configured minimum */
     99 		currentTimeStamp = os_timeStampMs( pScanConcentrator->hOS );
    100 		if ( (currentTimeStamp - pScanConcentrator->oidScanLastTimeStamp) <
    101 			 (pScanConcentrator->initParams.minimumDurationBetweenOidScans * 1000) ) /*converted to ms */
    102 		{
    103 			WLAN_REPORT_INFORMATION( pScanConcentrator->hReport, SCAN_CNCN_MODULE_LOG,
    104 									 ("Last OID scan performed at:%d, now is:%d, min duration is %d, too early for another scan!\n", \
    105 									  pScanConcentrator->oidScanLastTimeStamp, currentTimeStamp, pScanConcentrator->initParams.minimumDurationBetweenOidScans) );
    106 			return OK; /* TODO ronen: return correct Windows value */
    107 		}
    108 
    109 		/* mark that an OID scan process has started */
    110 		pScanConcentrator->bOidScanRunning = TRUE;
    111 		pScanConcentrator->oidScanLastTimeStamp = currentTimeStamp;
    112 		WLAN_REPORT_INFORMATION( pScanConcentrator->hReport, SCAN_CNCN_MODULE_LOG,
    113    								 ("Starting OID scan process...\n") );
    114 
    115 		/* and actually start the scan */
    116 		scanConcentratorOidSM_SMEvent( hScanCncn, (scan_oidSMStates_e*)&(pScanConcentrator->oidSMState), OID_SCAN_EVENT_START_SCAN );
    117 		break;
    118 
    119     default:
    120 	    WLAN_REPORT_ERROR( pScanConcentrator->hReport, SCAN_CNCN_MODULE_LOG,
    121                            ("Set param, Params is not supported:%d\n\n", pParam->paramType) );
    122 	    return PARAM_NOT_SUPPORTED;
    123     }
    124 
    125     return OK;
    126 }
    127 
    128 /**
    129  * \author Ronen Kalish\n
    130  * \date 30-Jan-2005\n
    131  * \brief Parses and executes a get param command.\n
    132  *
    133  * Function Scope \e Public.\n
    134  * \param hScanCncn - handle to the scan concentrator object.\n
    135  * \param pParam - the param to get.\n
    136  * \return always PARAM_NOT_SUPPORTED (not supposed to be called).\n
    137  */
    138 TI_STATUS scanConcentrator_getParam( TI_HANDLE hScanCncn, paramInfo_t *pParam )
    139 {
    140     return PARAM_NOT_SUPPORTED;
    141 }
    142 
    143 /**
    144  * \author Ronen Kalish\n
    145  * \date 30-Jan-2005\n
    146  * \brief Scan result callback for application scan.\n
    147  *
    148  * Function Scope \e Public.\n
    149  * \param hScanCncn - handle to the scan concentrator object.\n
    150  * \param status - the scan result status (scan complete, result received etc.).\n
    151  * \param frameInfo - a pointer to the structure holding all frame related info (in case a frame was received).\n
    152  * \prama SPSStatus - a bitmap indicating on which channels scan was attempted (valid for SPS scan only!).\n
    153  */
    154 void scanConcentrator_appScanResultCB( TI_HANDLE hScanCncn, scan_cncnResultStatus_e status,
    155                                        scan_frameInfo_t* frameInfo, UINT16 SPSStatus )
    156 {
    157     scanConcentrator_t* pScanConcentrator = (scanConcentrator_t*)hScanCncn;
    158 
    159     switch ( status )
    160 	{
    161 	case SCAN_CRS_RECEIVED_FRAME:
    162         /* forward scan results to site manager, like in the good old days... */
    163         siteMgr_updateSite( pScanConcentrator->hSiteManager, frameInfo->bssId,
    164                             frameInfo->parsedIEs, frameInfo->channel, frameInfo->band, FALSE );
    165         if ( BEACON == frameInfo->parsedIEs->subType )
    166         {
    167             siteMgr_saveBeaconBuffer( pScanConcentrator->hSiteManager, frameInfo->bssId,
    168                                       frameInfo->buffer, frameInfo->bufferLength );
    169         }
    170         else
    171         {
    172             siteMgr_saveProbeRespBuffer( pScanConcentrator->hSiteManager, frameInfo->bssId,
    173                                          frameInfo->buffer, frameInfo->bufferLength );
    174         }
    175 		break;
    176 
    177 	case SCAN_CRS_SCAN_COMPLETE_OK:
    178 		siteMgr_removeNotReceivedSites( pScanConcentrator->hSiteManager );
    179 
    180 	/* There's no break on purpose! */
    181 		/* if the current running app scan is an OID scan, send a scan complete event to its state machine */
    182 		if ( TRUE == pScanConcentrator->bOidScanRunning )
    183 		{
    184 			scanConcentratorOidSM_SMEvent(hScanCncn, (scan_oidSMStates_e*)&(pScanConcentrator->oidSMState), OID_SCAN_EVENT_SCAN_COMPLETE );
    185 		}
    186 		else
    187 		{
    188 			/* send a scan complete event to the user */
    189 			EvHandlerSendEvent( pScanConcentrator->hEventSrv, IPC_EVENT_SCAN_COMPLETE, NULL, 0 );
    190 		}
    191 		break;
    192 	case SCAN_CRS_TSF_ERROR:
    193 	case SCAN_CRS_SCAN_STOPPED:
    194 	case SCAN_CRS_SCAN_RUNNING:
    195 	case SCAN_CRS_SCAN_FAILED:
    196 	case SCAN_CRS_SCAN_ABORTED_HIGHER_PRIORITY:
    197 	case SCAN_CRS_SCAN_ABORTED_FW_RESET:
    198 	case SCAN_CRS_NUM_OF_RES_STATUS:
    199 	default:
    200         /* The scan was finished, send a scan complete event to the user
    201 		   (regardless of why the scan was completed) */
    202 		if ( TRUE == pScanConcentrator->bOidScanRunning )
    203 		{
    204 			scanConcentratorOidSM_SMEvent(hScanCncn, (scan_oidSMStates_e*)&(pScanConcentrator->oidSMState), OID_SCAN_EVENT_SCAN_FAILED );
    205 		}
    206 		else
    207 		{
    208         EvHandlerSendEvent( pScanConcentrator->hEventSrv, IPC_EVENT_SCAN_COMPLETE, NULL, 0 );
    209 		}
    210 		break;
    211 	}
    212 }
    213 
    214