summaryrefslogtreecommitdiff
path: root/wl1271/stad/src/Sta_Management/ScanCncnApp.c
blob: 0e20066478aa12276afd41c41cc1cba1540434b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
/*
 * ScanCncnApp.c
 *
 * Copyright(c) 1998 - 2009 Texas Instruments. All rights reserved.      
 * All rights reserved.                                                  
 *                                                                       
 * Redistribution and use in source and binary forms, with or without    
 * modification, are permitted provided that the following conditions    
 * are met:                                                              
 *                                                                       
 *  * Redistributions of source code must retain the above copyright     
 *    notice, this list of conditions and the following disclaimer.      
 *  * Redistributions in binary form must reproduce the above copyright  
 *    notice, this list of conditions and the following disclaimer in    
 *    the documentation and/or other materials provided with the         
 *    distribution.                                                      
 *  * Neither the name Texas Instruments nor the names of its            
 *    contributors may be used to endorse or promote products derived    
 *    from this software without specific prior written permission.      
 *                                                                       
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS   
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT     
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT      
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT   
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/** \file  ScanCncnApp.c
 *  \brief Scan concentrator application scan module implementation
 *
 *  \see   ScanCncn.h, ScanCncn.c
 */


#define __FILE_ID__  FILE_ID_77
#include "ScanCncnPrivate.h"
#include "ScanCncn.h"
#include "ScanCncnOsSm.h"
#include "EvHandler.h"
#include "report.h"
#include "GenSM.h"
#include "scanResultTable.h"
#include "sme.h"
#include "smeApi.h"

/** 
 * \fn     scanCncnApp_SetParam
 * \brief  Parses and executes a set param command
 * 
 * Parses and executes a set param command (start/stop one-shot/periodic/OS scan)
 * 
 * \param  hScanCncn - handle to the scan concentrator object
 * \param  pParam - the param to set
 * \return operation status (OK / NOK / PARAM_NOT_SUPPORTED)
 * \sa     scanCncnApp_GetParam 
 */ 
TI_STATUS scanCncnApp_SetParam (TI_HANDLE hScanCncn, paramInfo_t *pParam)
{
    TScanCncn   *pScanCncn = (TScanCncn*)hScanCncn;
    TI_UINT32   uCurrentTimeStamp;

    TRACE1(pScanCncn->hReport, REPORT_SEVERITY_INFORMATION , "scanCncnApp_SetParam: recevived request of type 0x%x\n", pParam->paramType);

    switch (pParam->paramType)
    {
    case SCAN_CNCN_START_APP_SCAN:

        /* verify that scan is not currently running */
        if (pScanCncn->eCurrentRunningAppScanClient != SCAN_SCC_NO_CLIENT)
        {
            TRACE1(pScanCncn->hReport, REPORT_SEVERITY_WARNING, "scanCncnApp_SetParam: trying to start app one-shot scan when client %d is currently running!\n", pScanCncn->eCurrentRunningAppScanClient);
            /* Scan was not started successfully, send a scan complete event to the user */
            return TI_NOK;
        }

        /* set one-shot scan as running app scan client */
        pScanCncn->eCurrentRunningAppScanClient = SCAN_SCC_APP_ONE_SHOT;

        /* start the scan */
        if (SCAN_CRS_SCAN_RUNNING != 
            scanCncn_Start1ShotScan (hScanCncn, SCAN_SCC_APP_ONE_SHOT, pParam->content.pScanParams))
        {
            /* Scan was not started successfully, mark that no app scan is running */
            pScanCncn->eCurrentRunningAppScanClient = SCAN_SCC_NO_CLIENT;
            return TI_NOK;
        }
        break;

    case SCAN_CNCN_STOP_APP_SCAN:
        /* verify that scan is currently running */
        if (pScanCncn->eCurrentRunningAppScanClient != SCAN_SCC_NO_CLIENT)
        {
            scanCncn_StopScan (hScanCncn, SCAN_SCC_APP_ONE_SHOT);
        }
        break;

    case SCAN_CNCN_START_PERIODIC_SCAN:
        /* verify that scan is not currently running */
        if (SCAN_SCC_NO_CLIENT != pScanCncn->eCurrentRunningAppScanClient)
        {
            TRACE1(pScanCncn->hReport, REPORT_SEVERITY_WARNING, "scanCncnApp_SetParam: trying to start app periodic scan when client %d is currently running!\n", pScanCncn->eCurrentRunningAppScanClient);
            /* Scan was not started successfully, send a scan complete event to the user */
            return TI_NOK;
        }

        /* set one-shot scan as running app scan client */
        pScanCncn->eCurrentRunningAppScanClient = SCAN_SCC_APP_PERIODIC;

        /* start the scan */
        if (SCAN_CRS_SCAN_RUNNING !=
            scanCncn_StartPeriodicScan (hScanCncn, SCAN_SCC_APP_PERIODIC, pParam->content.pPeriodicScanParams))
        {
            TRACE0(pScanCncn->hReport, REPORT_SEVERITY_CONSOLE , "Scan was not started. Verify scan parametrs or SME mode\n");
            WLAN_OS_REPORT (("Scan was not started. Verify scan parametrs or SME mode\n"));
                             
            /* Scan was not started successfully, mark that no app scan is running */
            pScanCncn->eCurrentRunningAppScanClient = SCAN_SCC_NO_CLIENT;
            return TI_NOK;
        }
        break;

    case SCAN_CNCN_STOP_PERIODIC_SCAN:
        /* verify that scan is currently running */
        if (pScanCncn->eCurrentRunningAppScanClient != SCAN_SCC_NO_CLIENT)
        {
            scanCncn_StopPeriodicScan (hScanCncn, SCAN_SCC_APP_PERIODIC);
        }
        break;

    case SCAN_CNCN_BSSID_LIST_SCAN_PARAM:
        /* check if OID scans are enabled in the registry */
        if (0 == pScanCncn->tInitParams.uMinimumDurationBetweenOsScans)
        {
            TRACE0(pScanCncn->hReport, REPORT_SEVERITY_INFORMATION , "scanCncnApp_SetParam: received OS scan request when OS scans are disabled, quitting...\n");
            return TI_NOK;
        }

        /* check if the last OID scan didn't start at a shorter duration than the configured minimum */
        uCurrentTimeStamp = os_timeStampMs (pScanCncn->hOS);
        if ( (uCurrentTimeStamp - pScanCncn->uOSScanLastTimeStamp) < 
             (pScanCncn->tInitParams.uMinimumDurationBetweenOsScans * 1000) ) /*converted to ms */
        {
            TRACE3(pScanCncn->hReport, REPORT_SEVERITY_INFORMATION , "scanCncnApp_SetParam: last OID scan performed at: %d, now is: %d, min duration is: %d, too early for another scan!\n", pScanCncn->uOSScanLastTimeStamp, uCurrentTimeStamp, pScanCncn->tInitParams.uMinimumDurationBetweenOsScans);
            return TI_NOK;
        }

        /* check that no other scan is currently running */
        if (SCAN_SCC_NO_CLIENT != pScanCncn->eCurrentRunningAppScanClient)
        {
            TRACE1(pScanCncn->hReport, REPORT_SEVERITY_ERROR , "scanCncnApp_SetParam: received OS scan request when client %d is currently running!\n", pScanCncn->eCurrentRunningAppScanClient);
            return TI_NOK;
        }

        /* set one-shot scan as running app scan client */
        pScanCncn->eCurrentRunningAppScanClient = SCAN_SCC_APP_ONE_SHOT;

        /* mark that an OID scan process has started */
        pScanCncn->bOSScanRunning = TI_TRUE;
        pScanCncn->uOSScanLastTimeStamp = uCurrentTimeStamp;
        TRACE0(pScanCncn->hReport, REPORT_SEVERITY_INFORMATION , "scanCncnApp_SetParam: starting OID scan process...\n");

		if(0 != pParam->content.pScanParams->desiredSsid.len)
        {
			pScanCncn->tOsScanParams.desiredSsid.len = pParam->content.pScanParams->desiredSsid.len;
            os_memoryCopy(pScanCncn->hOS, pScanCncn->tOsScanParams.desiredSsid.str, pParam->content.pScanParams->desiredSsid.str, pParam->content.pScanParams->desiredSsid.len);
        }
        else
        {
            pScanCncn->tOsScanParams.desiredSsid.len = 0;
            pScanCncn->tOsScanParams.desiredSsid.str[ 0 ] = '\0'; /* broadcast scan */
        }

		pScanCncn->tOsScanParams.scanType = pParam->content.pScanParams->scanType;

        /* and actually start the scan */
        genSM_Event (pScanCncn->hOSScanSm, SCAN_CNCN_OS_SM_EVENT_START_SCAN, hScanCncn);

        break;

    default:
        TRACE1(pScanCncn->hReport, REPORT_SEVERITY_ERROR , "scanCncnApp_SetParam: unrecognized param type :%d\n", pParam->paramType);
        return PARAM_NOT_SUPPORTED;
    }

    return TI_OK;
}

/** 
 * \fn     scanCncnApp_GetParam
 * \brief  Parses and executes a get param command
 * 
 * Parses and executes a get param command (get BSSID list)
 * 
 * \param  hScanCncn - handle to the scan concentrator object
 * \param  pParam - the param to get
 * \return operation status (OK / NOK / PARAM_NOT_SUPPORTED)
 * \sa     scanCncnApp_SetParam
 */ 
TI_STATUS scanCncnApp_GetParam (TI_HANDLE hScanCncn, paramInfo_t *pParam)
{
    TScanCncn   *pScanCncn = (TScanCncn*)hScanCncn;

    TRACE1(pScanCncn->hReport, REPORT_SEVERITY_INFORMATION , "scanCncnApp_GetParam: received request of type %d\n", pParam->paramType);

    switch (pParam->paramType)
    {
    case SCAN_CNCN_BSSID_LIST_SIZE_PARAM:
        /* retrieves the size to allocate for the app scan result taBle BBSID list (see next code) */
        pParam->paramLength = sizeof(TI_UINT32);
		pParam->content.uBssidListSize = scanResultTable_CalculateBssidListSize (pScanCncn->hScanResultTable, TI_TRUE);
        break;

    case SCAN_CNCN_BSSID_LIST_PARAM:
        /* retrieve the app scan result table */
        return scanResultTable_GetBssidList (pScanCncn->hScanResultTable, pParam->content.pBssidList, 
                                             &pParam->paramLength, TI_TRUE);
        break;

    default:
        TRACE1(pScanCncn->hReport, REPORT_SEVERITY_ERROR , "scanCncnApp_GetParam: unrecognized param type :%d\n", pParam->paramType);
        return PARAM_NOT_SUPPORTED;
    }

    return TI_OK;
}

/** 
 * \fn     scanCncn_AppScanResultCB
 * \brief  Scan result callback for application scan
 * 
 * Scan result callback for application scan
 * 
 * \param  hScanCncn - handle to the scan concentrator object
 * \param  status - the scan result status (scan complete, result received etc.)
 * \param  frameInfo - a pointer to the structure holding all frame related info (in case a frame was received)
 * \param  SPSStatus - a bitmap indicating on which channels scan was attempted (valid for SPS scan only!)
 * \return None
 */ 
void scanCncn_AppScanResultCB (TI_HANDLE hScanCncn, EScanCncnResultStatus status,
                               TScanFrameInfo* frameInfo, TI_UINT16 SPSStatus)
{
    TScanCncn   *pScanCncn = (TScanCncn*)hScanCncn;
    TI_UINT32	statusData;

    /* forward all data to SME */
    sme_AppScanResult (pScanCncn->hSme, status, frameInfo);

    switch (status)
    {
    case SCAN_CRS_RECEIVED_FRAME:
        /* Save the result in the app scan result table */
        if (TI_OK != scanResultTable_UpdateEntry (pScanCncn->hScanResultTable, frameInfo->bssId, frameInfo))
		{
	        TRACE0(pScanCncn->hReport, REPORT_SEVERITY_WARNING , "scanCncn_AppScanResultCB, scanResultTable_UpdateEntry() failed\n");
		}
		break;

    case SCAN_CRS_SCAN_COMPLETE_OK:

        TRACE1(pScanCncn->hReport, REPORT_SEVERITY_INFORMATION , "scanCncn_AppScanResultCB, received scan complete with status :%d\n", status);

        /* if OS scan is running */
        if (TI_TRUE == pScanCncn->bOSScanRunning)
        {
            /* send a scan complete event to the OS scan SM. It will stabliza the table when needed */
            genSM_Event (pScanCncn->hOSScanSm, SCAN_CNCN_OS_SM_EVENT_SCAN_COMPLETE, hScanCncn);
        }
        else
        {
            /* move the scan result table to stable state, clear it if no results were received */
            scanResultTable_SetStableState (pScanCncn->hScanResultTable);

            /* mark that no app scan is running */
            pScanCncn->eCurrentRunningAppScanClient = SCAN_SCC_NO_CLIENT;
            /*
             * The scan was finished, send a scan complete event to the user
             * (regardless of why the scan was completed)
             */
            statusData = SCAN_STATUS_COMPLETE;	/* Completed status */
			EvHandlerSendEvent (pScanCncn->hEvHandler, IPC_EVENT_SCAN_COMPLETE, (TI_UINT8 *)&statusData, sizeof(TI_UINT32));
        }
        break;

    case SCAN_CRS_SCAN_STOPPED:

        TRACE1(pScanCncn->hReport, REPORT_SEVERITY_INFORMATION , "scanCncn_AppScanResultCB, received scan complete with status :%d\n", status);

        /* if OS scan is running */
        if (TI_TRUE == pScanCncn->bOSScanRunning)
        {
            /* send a scan complete event to the OS scan SM. It will stabliza the table when needed */
            genSM_Event (pScanCncn->hOSScanSm, SCAN_CNCN_OS_SM_EVENT_SCAN_COMPLETE, hScanCncn);
        }
        else
        {
            /* move the scan result table to stable state, clear it if no results were received */
            scanResultTable_SetStableState (pScanCncn->hScanResultTable);

            /* mark that no app scan is running */
            pScanCncn->eCurrentRunningAppScanClient = SCAN_SCC_NO_CLIENT;
            /*
             * The scan was finished, send a scan complete event to the user
             * (regardless of why the scan was completed)
             */
            statusData = SCAN_STATUS_STOPPED;	/* Stopped status */
            EvHandlerSendEvent (pScanCncn->hEvHandler, IPC_EVENT_SCAN_COMPLETE, (TI_UINT8 *)&statusData, sizeof(TI_UINT32));
        }
        break;

    case SCAN_CRS_TSF_ERROR:
    case SCAN_CRS_SCAN_RUNNING:
    case SCAN_CRS_SCAN_FAILED:
    case SCAN_CRS_SCAN_ABORTED_HIGHER_PRIORITY:
    case SCAN_CRS_SCAN_ABORTED_FW_RESET:

        TRACE1(pScanCncn->hReport, REPORT_SEVERITY_INFORMATION , "scanCncn_AppScanResultCB, received scan complete with status :%d\n", status);

        /* if OS scan is running */
        if (TI_TRUE == pScanCncn->bOSScanRunning)
        {
            /* send a scan complete event to the OS scan SM. It will stabliza the table when needed */
            genSM_Event (pScanCncn->hOSScanSm, SCAN_CNCN_OS_SM_EVENT_SCAN_COMPLETE, hScanCncn);
        }
        else
        {
            /* move the scan result table to stable state, clear it if no results were received */
            scanResultTable_SetStableState (pScanCncn->hScanResultTable);

            /* mark that no app scan is running */
            pScanCncn->eCurrentRunningAppScanClient = SCAN_SCC_NO_CLIENT;
            /* 
             * The scan was finished, send a scan complete event to the user
             * (regardless of why the scan was completed)
             */
            statusData = SCAN_STATUS_FAILED;		/* Failed status */
            EvHandlerSendEvent (pScanCncn->hEvHandler, IPC_EVENT_SCAN_COMPLETE, (TI_UINT8 *)&statusData, sizeof(TI_UINT32));
        }
        break;

    case SCAN_CRS_NUM_OF_RES_STATUS:
    default:
        TRACE1(pScanCncn->hReport, REPORT_SEVERITY_ERROR , "scanCncn_AppScanResultCB, received erroneuos scan result with status :%d\n", status);
        break;
    }
}