1981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*
2981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * smeSm.c
3981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
4981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Copyright(c) 1998 - 2009 Texas Instruments. All rights reserved.
5981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * All rights reserved.
6981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
7981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Redistribution and use in source and binary forms, with or without
8981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * modification, are permitted provided that the following conditions
9981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * are met:
10981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
11981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *  * Redistributions of source code must retain the above copyright
12981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *    notice, this list of conditions and the following disclaimer.
13981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *  * Redistributions in binary form must reproduce the above copyright
14981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *    notice, this list of conditions and the following disclaimer in
15981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *    the documentation and/or other materials provided with the
16981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *    distribution.
17981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *  * Neither the name Texas Instruments nor the names of its
18981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *    contributors may be used to endorse or promote products derived
19981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *    from this software without specific prior written permission.
20981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
21981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
33981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
34981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/** \file  smeSm.c
35981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *  \brief SME state machine implementation
36981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
37981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *  \see   smeSm.h, sme.c, sme.h
38981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
39981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
40981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
41981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define __FILE_ID__  FILE_ID_43
42981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "GenSM.h"
43981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "smeSm.h"
44981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "smePrivate.h"
45981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "connApi.h"
46981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "apConn.h"
47981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "ScanCncn.h"
48981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "scanResultTable.h"
49981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "EvHandler.h"
50981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "regulatoryDomainApi.h"
51981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "siteMgrApi.h"
52981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "DrvMain.h"
53981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
54981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
55981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic OS_802_11_DISASSOCIATE_REASON_E eDisassocConvertTable[ MGMT_STATUS_MAX_NUM ] =
56981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
57981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    OS_DISASSOC_STATUS_UNSPECIFIED,
58981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    OS_DISASSOC_STATUS_UNSPECIFIED,
59981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    OS_DISASSOC_STATUS_AUTH_REJECT,
60981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    OS_DISASSOC_STATUS_ASSOC_REJECT,
61981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    OS_DISASSOC_STATUS_SECURITY_FAILURE,
62981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    OS_DISASSOC_STATUS_AP_DEAUTHENTICATE,
63981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    OS_DISASSOC_STATUS_AP_DISASSOCIATE,
64981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    OS_DISASSOC_STATUS_ROAMING_TRIGGER,
65981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    OS_DISASSOC_STATUS_UNSPECIFIED,
66981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    OS_DISASSOC_STATUS_UNSPECIFIED,
67981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    OS_DISASSOC_STATUS_UNSPECIFIED,
68981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    OS_DISASSOC_STATUS_UNSPECIFIED,
69981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    OS_DISASSOC_STATUS_UNSPECIFIED,
70981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    OS_DISASSOC_STATUS_UNSPECIFIED,
71981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    OS_DISASSOC_STATUS_UNSPECIFIED,
72981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt};
73981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
74981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#define SME_CONVERT_DISASSOC_CODES(disassocReason)     (eDisassocConvertTable[ (disassocReason) ])
75981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
76981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void smeSm_Start (TI_HANDLE hSme);
77981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void smeSm_Stop (TI_HANDLE hSme);
78981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void smeSm_PreConnect (TI_HANDLE hSme);
79981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void smeSm_Connect (TI_HANDLE hSme);
80981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void smeSm_ConnectSuccess (TI_HANDLE hSme);
81981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void smeSm_Disconnect (TI_HANDLE hSme);
82981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void smeSm_DisconnectDone (TI_HANDLE hSme);
83981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void smeSm_StopScan (TI_HANDLE hSme);
84981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void smeSm_StopConnect (TI_HANDLE hSme);
85981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void smeSm_ConnWhenConnecting (TI_HANDLE hSme);
86981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void smeSm_ActionUnexpected (TI_HANDLE hSme);
87981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void smeSm_NopAction (TI_HANDLE hSme);
88981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void smeSm_CheckStartConditions (TI_HANDLE hSme);
89981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
90981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic TI_STATUS sme_StartScan (TI_HANDLE hSme);
91981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void sme_updateScanCycles (TI_HANDLE hSme,
92981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                                  TI_BOOL bDEnabled,
93981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                                  TI_BOOL bCountryValid,
94981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                                  TI_BOOL bConstantScan);
95981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtstatic void sme_CalculateCyclesNumber (TI_HANDLE hSme, TI_UINT32 uTotalTimeMs);
96981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
97981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtTGenSM_actionCell tSmMatrix[ SME_SM_NUMBER_OF_STATES ][ SME_SM_NUMBER_OF_EVENTS ] =
98981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
99981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        { /* SME_SM_STATE_IDLE */
100981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            { SME_SM_STATE_WAIT_CONNECT, smeSm_Start },             /* SME_SM_EVENT_START */
101981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            { SME_SM_STATE_IDLE, smeSm_ActionUnexpected },          /* SME_SM_EVENT_STOP */
102981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            { SME_SM_STATE_IDLE, smeSm_ActionUnexpected },          /* SME_SM_EVENT_CONNECT */
103981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            { SME_SM_STATE_IDLE, smeSm_ActionUnexpected },          /* SME_SM_EVENT_CONNECT_SUCCESS */
104981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            { SME_SM_STATE_IDLE, smeSm_ActionUnexpected },          /* SME_SM_EVENT_CONNECT_FAILURE */
105981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            { SME_SM_STATE_IDLE, smeSm_CheckStartConditions },          /* SME_SM_EVENT_DISCONNECT */
106981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        },
107981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        { /* SME_SM_STATE_WAIT_CONNECT */
108981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            { SME_SM_STATE_WAIT_CONNECT, smeSm_ActionUnexpected },  /* SME_SM_EVENT_START */
109981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            { SME_SM_STATE_IDLE, smeSm_Stop },                      /* SME_SM_EVENT_STOP */
110981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            { SME_SM_STATE_SCANNING, smeSm_PreConnect },            /* SME_SM_EVENT_CONNECT */
111981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            { SME_SM_STATE_WAIT_CONNECT, smeSm_ActionUnexpected },  /* SME_SM_EVENT_CONNECT_SUCCESS */
112981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            { SME_SM_STATE_WAIT_CONNECT, smeSm_ActionUnexpected },  /* SME_SM_EVENT_CONNECT_FAILURE */
113981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            { SME_SM_STATE_WAIT_CONNECT, smeSm_Start },             /* SME_SM_EVENT_DISCONNECT */
114981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        },
115981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        { /* SME_SM_STATE_SCANNING */
116981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            { SME_SM_STATE_SCANNING, smeSm_ActionUnexpected },      /* SME_SM_EVENT_START */
117981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            { SME_SM_STATE_DISCONNECTING, smeSm_StopScan },         /* SME_SM_EVENT_STOP */
118981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            { SME_SM_STATE_CONNECTING, smeSm_Connect },             /* SME_SM_EVENT_CONNECT */
119981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            { SME_SM_STATE_SCANNING, smeSm_ActionUnexpected },      /* SME_SM_EVENT_CONNECT_SUCCESS */
120981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            { SME_SM_STATE_WAIT_CONNECT, smeSm_DisconnectDone },    /* SME_SM_EVENT_CONNECT_FAILURE */
121981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            { SME_SM_STATE_DISCONNECTING, smeSm_StopScan },         /* SME_SM_EVENT_DISCONNECT */
122981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        },
123981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        { /* SME_SM_STATE_CONNECTING */
124981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            { SME_SM_STATE_CONNECTING, smeSm_ActionUnexpected },    /* SME_SM_EVENT_START */
125981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            { SME_SM_STATE_DISCONNECTING, smeSm_StopConnect },      /* SME_SM_EVENT_STOP */
126981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            { SME_SM_STATE_CONNECTING, smeSm_ConnWhenConnecting },  /* SME_SM_EVENT_CONNECT */
127981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            { SME_SM_STATE_CONNECTED, smeSm_ConnectSuccess },       /* SME_SM_EVENT_CONNECT_SUCCESS */
128981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            { SME_SM_STATE_WAIT_CONNECT, smeSm_DisconnectDone },    /* SME_SM_EVENT_CONNECT_FAILURE */
129981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            { SME_SM_STATE_DISCONNECTING, smeSm_StopConnect },      /* SME_SM_EVENT_DISCONNECT */
130981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        },
131981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        { /* SME_SM_STATE_CONNECTED */
132981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            { SME_SM_STATE_CONNECTED, smeSm_ActionUnexpected },     /* SME_SM_EVENT_START */
133981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            { SME_SM_STATE_DISCONNECTING, smeSm_Disconnect },       /* SME_SM_EVENT_STOP */
134981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            { SME_SM_STATE_CONNECTED, smeSm_ActionUnexpected },     /* SME_SM_EVENT_CONNECT */
135981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            { SME_SM_STATE_CONNECTED, smeSm_ActionUnexpected },     /* SME_SM_EVENT_CONNECT_SUCCESS */
136981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            { SME_SM_STATE_WAIT_CONNECT, smeSm_DisconnectDone },    /* SME_SM_EVENT_CONNECT_FAILURE */
137981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            { SME_SM_STATE_DISCONNECTING, smeSm_Disconnect },       /* SME_SM_EVENT_DISCONNECT */
138981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        },
139981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        { /* SME_SM_STATE_DISCONNECTING */
140981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            { SME_SM_STATE_DISCONNECTING, smeSm_ActionUnexpected }, /* SME_SM_EVENT_START */
141981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            { SME_SM_STATE_DISCONNECTING, smeSm_ActionUnexpected }, /* SME_SM_EVENT_STOP */
142981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            { SME_SM_STATE_DISCONNECTING, smeSm_ActionUnexpected }, /* SME_SM_EVENT_CONNECT */
143981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            { SME_SM_STATE_DISCONNECTING, smeSm_ActionUnexpected }, /* SME_SM_EVENT_CONNECT_SUCCESS */
144981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            { SME_SM_STATE_WAIT_CONNECT, smeSm_DisconnectDone },    /* SME_SM_EVENT_CONNECT_FAILURE */
145981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            { SME_SM_STATE_DISCONNECTING, smeSm_NopAction }, /* SME_SM_EVENT_DISCONNECT */
146981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
147981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    };
148981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
149981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtTI_INT8*  uStateDescription[] =
150981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
151981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        "IDLE",
152981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        "WAIT_CONNECT",
153981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        "SCANNING",
154981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        "CONNECTING",
155981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        "CONNECTED",
156981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        "DISCONNECTING"
157981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    };
158981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
159981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtTI_INT8*  uEventDescription[] =
160981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
161981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        "START",
162981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        "STOP",
163981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        "CONNECT",
164981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        "CONNECT_SUCCESS",
165981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        "CONNECT_FAILURE",
166981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        "DISCONNECT"
167981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    };
168981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
169981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/**
170981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \fn     smeSm_Start
171981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \brief  Starts STA opeartion by moving SCR out of idle group and starting connection process
172981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
173981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Starts STA opeartion by moving SCR out of idle group and starting connection process
174981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
175981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  hSme - handle to the SME object
176981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \return None
177981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \sa     smeSm_Stop, sme_start
178981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
179981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtvoid smeSm_Start (TI_HANDLE hSme)
180981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
181981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TSme    *pSme = (TSme*)hSme;
182981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
183981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* set SCR group according to connection mode */
184981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (CONNECT_MODE_AUTO == pSme->eConnectMode)
185981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
186981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        TRACE0(pSme->hReport, REPORT_SEVERITY_INFORMATION , "smeSm_Start: changing SCR group to DRV scan\n");
187981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        scr_setGroup (pSme->hScr, SCR_GID_DRV_SCAN);
188981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
189981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    else
190981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
191981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        TRACE0(pSme->hReport, REPORT_SEVERITY_INFORMATION , "smeSm_Start: changing SCR group to APP scan\n");
192981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        scr_setGroup (pSme->hScr, SCR_GID_APP_SCAN);
193981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
194981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
195981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if ((TI_FALSE == pSme->bRadioOn) || (TI_FALSE == pSme->bRunning))
196981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
197981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* Radio is off so send stop event */
198981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        genSM_Event (pSme->hSmeSm, SME_SM_EVENT_STOP, hSme);
199981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
200981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    else if (TI_TRUE == pSme->bConnectRequired)
201981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
202981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* if connection was required, start the process */
203981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        genSM_Event (pSme->hSmeSm, SME_SM_EVENT_CONNECT, hSme);
204981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
205981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
206981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
207981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/**
208981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \fn     smeSm_Stop
209981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \brief  Turns off the STA
210981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
211981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Turns off the STA by moving the SCr to idle
212981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
213981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  hSme - handle to the SME object
214981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \return None
215981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \sa     smeSm_Start, sme_Stop
216981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
217981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtvoid smeSm_Stop (TI_HANDLE hSme)
218981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
219981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TSme    *pSme = (TSme*)hSme;
220981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
221981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* set SCR group to idle */
222981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    scr_setGroup (pSme->hScr, SCR_GID_IDLE);
223981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
224981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (TI_FALSE == pSme->bRunning)
225981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
226981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* call DrvMain */
227981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        drvMain_SmeStop (pSme->hDrvMain);
228981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
229981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
230981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
231981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/**
232981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \fn     smeSm_PreConnect
233981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \brief  Initiates the connection process
234981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
235981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Initiates the connection process - for automatic mode, start scan, for manual mode - triggers connection
236981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
237981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  hSme - handle to the SME object
238981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \return None
239981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \sa     smeSm_Connect, smeSm_ConnectSuccess
240981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
241981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtvoid smeSm_PreConnect (TI_HANDLE hSme)
242981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
243023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt    TSme *pSme = (TSme *)hSme;
244023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt    paramInfo_t	*pParam;
245981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
246981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* set the connection mode with which this connection attempt is starting */
247981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pSme->eLastConnectMode = pSme->eConnectMode;
248981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
249981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* mark that no authentication/assocaition was yet sent */
250981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pSme->bAuthSent = TI_FALSE;
251981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
252981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* try to find a connection candidate (manual mode have already performed scann */
253981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pSme->pCandidate = sme_Select (hSme);
254981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (NULL != pSme->pCandidate)
255981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
256981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* candidate is available - attempt connection */
257981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        genSM_Event (pSme->hSmeSm, SME_SM_EVENT_CONNECT, hSme);
258981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
259981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* no candidate */
260981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    else
261981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
262981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if (CONNECT_MODE_AUTO == pSme->eConnectMode)
263981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
264981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* automatic mode - start scanning */
265981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            if (TI_OK != sme_StartScan (hSme))
266981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
267981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                TRACE0(pSme->hReport, REPORT_SEVERITY_ERROR , "smeSm_PreConnect: unable to start scan, stopping the SME\n");
268981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pSme->bRadioOn = TI_FALSE;
269981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                genSM_Event (pSme->hSmeSm, SME_SM_EVENT_CONNECT_FAILURE, hSme);
270981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
271981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
272981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* update scan count counter */
273981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            if(pSme->uScanCount < PERIODIC_SCAN_MAX_INTERVAL_NUM)
274981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
275981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pSme->uScanCount++;
276981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
277981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
278981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
279653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        else		/* Manual mode */
280981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
281653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt			/* for IBSS or any, if no entries where found, add the self site */
282653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt			if (pSme->eBssType == BSS_INFRASTRUCTURE)
283653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt            {
284023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt                /* makr whether we need to stop the attempt connection in manual mode */
285023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt                pSme->bConnectRequired = TI_FALSE;
286981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
287653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt				TRACE0(pSme->hReport, REPORT_SEVERITY_INFORMATION , "smeSm_PreConnect: No candidate available, sending connect failure\n");
288023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt                /* manual mode and no connection candidate is available - connection failed */
289023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt                genSM_Event (pSme->hSmeSm, SME_SM_EVENT_CONNECT_FAILURE, hSme);
290653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt			}
291653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
292653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt			else		/* IBSS */
293653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt			{
294023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt				TI_UINT8    uDesiredChannel;
295023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt                TI_BOOL     channelValidity;
296023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt
297653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt		        pSme->bConnectRequired = TI_FALSE;
298653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
299023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt                pParam = (paramInfo_t *)os_memoryAlloc(pSme->hOS, sizeof(paramInfo_t));
300023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt                if (!pParam)
301023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt                    return;
302023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt
303023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt				pParam->paramType = SITE_MGR_DESIRED_CHANNEL_PARAM;
304023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt				siteMgr_getParam(pSme->hSiteMgr, pParam);
305023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt				uDesiredChannel = pParam->content.siteMgrDesiredChannel;
306653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
307653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt				if (uDesiredChannel >= SITE_MGR_CHANNEL_A_MIN)
308653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt				{
309023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt				   pParam->content.channelCapabilityReq.band = RADIO_BAND_5_0_GHZ;
310653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt				}
311653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt				else
312653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt				{
313023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt				   pParam->content.channelCapabilityReq.band = RADIO_BAND_2_4_GHZ;
314653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt				}
315653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
316653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt				/*
317653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt				update the regulatory domain with the selected band
318653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt				*/
319653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt				/* Check if the selected channel is valid according to regDomain */
320023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt				pParam->paramType = REGULATORY_DOMAIN_GET_SCAN_CAPABILITIES;
321023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt				pParam->content.channelCapabilityReq.scanOption = ACTIVE_SCANNING;
322023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt				pParam->content.channelCapabilityReq.channelNum = uDesiredChannel;
323023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt
324023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt				regulatoryDomain_getParam (pSme->hRegDomain, pParam);
325023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt                channelValidity = pParam->content.channelCapabilityRet.channelValidity;
326023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt                os_memoryFree(pSme->hOS, pParam, sizeof(paramInfo_t));
327023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt				if (!channelValidity)
328653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt				{
329653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt				   TRACE0(pSme->hReport, REPORT_SEVERITY_INFORMATION , "IBSS SELECT FAILURE  - No channel !!!\n\n");
330653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
331653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt				   genSM_Event (pSme->hSmeSm, SME_SM_EVENT_CONNECT_FAILURE, hSme);
332653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
333653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt				   return;
334653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt				}
335653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
336653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt				pSme->pCandidate = (TSiteEntry *)addSelfSite(pSme->hSiteMgr);
337653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
338653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt				if (pSme->pCandidate == NULL)
339653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt				{
340653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt				   TRACE0(pSme->hReport, REPORT_SEVERITY_ERROR , "IBSS SELECT FAILURE  - could not open self site !!!\n\n");
341653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
342653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt				   genSM_Event (pSme->hSmeSm, SME_SM_EVENT_CONNECT_FAILURE, hSme);
343653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
344653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt				   return;
345653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt				}
346653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt
347653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt#ifdef REPORT_LOG
348653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt				TRACE6(pSme->hReport, REPORT_SEVERITY_CONSOLE,"%%%%%%%%%%%%%%	SELF SELECT SUCCESS, bssid: %X-%X-%X-%X-%X-%X	%%%%%%%%%%%%%%\n\n", pSme->pCandidate->bssid[0], pSme->pCandidate->bssid[1], pSme->pCandidate->bssid[2], pSme->pCandidate->bssid[3], pSme->pCandidate->bssid[4], pSme->pCandidate->bssid[5]);
349653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt                WLAN_OS_REPORT (("%%%%%%%%%%%%%%	SELF SELECT SUCCESS, bssid: %02x.%02x.%02x.%02x.%02x.%02x %%%%%%%%%%%%%%\n\n", pSme->pCandidate->bssid[0], pSme->pCandidate->bssid[1], pSme->pCandidate->bssid[2], pSme->pCandidate->bssid[3], pSme->pCandidate->bssid[4], pSme->pCandidate->bssid[5]));
350653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt#endif
351653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt				/* a connection candidate is available, send a connect event */
352653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt				genSM_Event (pSme->hSmeSm, SME_SM_EVENT_CONNECT, hSme);
353653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt			}
354981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
355981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
356981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
357981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
358981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/**
359981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \fn     smeSm_Connect
360981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \brief  Starts a connection process with the selected network
361981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
362981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Starts a connection process with the selected network
363981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
364981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  hSme - handle to the SME object
365981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \return None
366981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \sa     smeSm_PreConnect, smeSm_ConnectSuccess
367981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
368981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtvoid smeSm_Connect (TI_HANDLE hSme)
369981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
370023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt    TSme            *pSme = (TSme*)hSme;
371981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_STATUS       tStatus;
372023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt    paramInfo_t     *pParam;
373981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
374981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Sanity check - if no connection candidate was found so far */
375981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (NULL == pSme->pCandidate)
376981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
377981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        TRACE0(pSme->hReport, REPORT_SEVERITY_ERROR , "smeSm_Connect: No candidate available, sending connect failure\n");
378981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        genSM_Event (pSme->hSmeSm, SME_SM_EVENT_CONNECT_FAILURE, hSme);
379981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
380981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    else
381981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
382023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt        pParam = (paramInfo_t *)os_memoryAlloc(pSme->hOS, sizeof(paramInfo_t));
383023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt        if (!pParam)
384023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt            return;
385023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt
386981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt       /* set SCR group */
387981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt       if (BSS_INFRASTRUCTURE == pSme->pCandidate->bssType)
388981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt       {
389981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt           scr_setGroup (pSme->hScr, SCR_GID_CONNECT);
390981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt       }
391981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
392981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt       /***************** Config Connection *************************/
393023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt       pParam->paramType = CONN_TYPE_PARAM;
394981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt       if (BSS_INDEPENDENT == pSme->pCandidate->bssType)
395981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt           if (SITE_SELF == pSme->pCandidate->siteType)
396981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt           {
397023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt               pParam->content.connType = CONNECTION_SELF;
398981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt           }
399981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt           else
400981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt           {
401023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt               pParam->content.connType = CONNECTION_IBSS;
402981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt           }
403981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt       else
404023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt           pParam->content.connType = CONNECTION_INFRA;
405023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt       conn_setParam(pSme->hConn, pParam);
406023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt       os_memoryFree(pSme->hOS, pParam, sizeof(paramInfo_t));
407981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
408981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt       /* start the connection process */
409981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt       tStatus = conn_start (pSme->hConn, CONN_TYPE_FIRST_CONN, sme_ReportConnStatus, hSme, TI_FALSE, TI_FALSE);
410981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt       if (TI_OK != tStatus)
411981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt       {
412981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt           TRACE1(pSme->hReport, REPORT_SEVERITY_ERROR , "smeSm_Connect: conn_start returned status %d\n", tStatus);
413981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt       }
414981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
415981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
416981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
417981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/**
418981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \fn     smeSm_ConnectSuccess
419981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \brief  Handles connection success indication
420981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
421981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Handles connection success indication - starts AP conn and set SCR group to connected
422981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
423981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  hSme - handle to the SME object
424981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \return None
425981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \sa     smeSm_PreConnect, smeSm_Connect
426981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
427981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtvoid smeSm_ConnectSuccess (TI_HANDLE hSme)
428981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
429981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TSme        *pSme = (TSme*)hSme;
430981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
431981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pSme->uScanCount = 0;
432981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
433981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* connection succedded to the connection candidate - start AP connection */
434981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (BSS_INFRASTRUCTURE == pSme->pCandidate->bssType)
435981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
436981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* Start the AP connection */
437981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        apConn_start (pSme->hApConn,
438981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                      (pSme->tSsid.len != 0) && !OS_802_11_SSID_JUNK (pSme->tSsid.str, pSme->tSsid.len));
439981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
440981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
441981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Set SCR group to connected */
442981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    scr_setGroup (pSme->hScr, SCR_GID_CONNECTED);
443981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
444981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
445981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/**
446981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \fn     smeSm_Disconnect
447981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \brief  Starts a disconnect by calling the AP connection or connect modules
448981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
449981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Starts a disconnect by calling the AP connection or connect modules
450981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
451981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  hSme - handle to the SME object
452981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \return None
453981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \sa     smeSm_DisconnectDone
454981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
455981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtvoid smeSm_Disconnect (TI_HANDLE hSme)
456981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
457981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TSme        *pSme = (TSme*)hSme;
458981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_STATUS   tStatus;
459981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
460981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* set the SCr group to connecting */
461981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    scr_setGroup (pSme->hScr, SCR_GID_CONNECT);
462981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
463981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (BSS_INFRASTRUCTURE == pSme->pCandidate->bssType)
464981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
465981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt		 /* Call the AP connection to perform disconnect */
466981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt		 tStatus = apConn_stop (pSme->hApConn, TI_TRUE);
467981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	}
468981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	else
469981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	{
470981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	    /* In IBSS disconnect is done directly with the connection SM */
471981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt		tStatus = conn_stop(pSme->hConn, DISCONNECT_DE_AUTH, STATUS_UNSPECIFIED,
472981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt						   TI_TRUE, sme_ReportConnStatus, hSme);
473981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt		if (tStatus != TI_OK)
474981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt		{
475981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtTRACE1(pSme->hReport, REPORT_SEVERITY_ERROR , "smeSm_Disconnect: conn_stop retruned %d\n", tStatus);
476981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt		}
477981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
478981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
479981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
480981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/**
481981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \fn     smeSm_DisconnectDone
482981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \brief  Finish a disconnect process
483981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
484981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Finish a disconnect process by sending the appropriate event and restarting the state-machine
485981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
486981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  hSme - handle to the SME object
487981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \return None
488981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \sa     smeSm_Disconnect
489981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
490981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtvoid smeSm_DisconnectDone (TI_HANDLE hSme)
491981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
492981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TSme        *pSme = (TSme*)hSme;
493981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    OS_802_11_DISASSOCIATE_REASON_T	    tEventReason;
494981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
495981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (TI_FALSE == pSme->bReselect)
496981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
497981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* send an event notifying the disassocation */
498981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if (TI_TRUE == pSme->bAuthSent)
499981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
500981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            tEventReason.eDisAssocType = SME_CONVERT_DISASSOC_CODES (pSme->tDisAssoc.eMgmtStatus);
501981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            tEventReason.uStatusCode = pSme->tDisAssoc.uStatusCode;
502981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            EvHandlerSendEvent (pSme->hEvHandler, IPC_EVENT_DISASSOCIATED, (TI_UINT8*)&tEventReason,
503981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                                sizeof(OS_802_11_DISASSOCIATE_REASON_T));
504981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
505981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        else if (CONNECT_MODE_AUTO != pSme->eLastConnectMode)
506981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
507981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            EvHandlerSendEvent (pSme->hEvHandler, IPC_EVENT_NOT_ASSOCIATED, NULL, 0);
508981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
509981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
510981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
511981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    siteMgr_disSelectSite (pSme->hSiteMgr);
512981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
513981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* try to reconnect */
514981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    smeSm_Start (hSme);
515981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
516981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
517981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/**
518981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \fn     smeSm_StopScan
519981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \brief  Stops the SME scan operation
520981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
521981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Stops the SME scan operation
522981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
523981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  hSme - handle to the SME object
524981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \return None
525981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \sa     smeSm_PreConnect, sme_StartScan
526981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
527981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtvoid smeSm_StopScan (TI_HANDLE hSme)
528981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
529981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TSme        *pSme = (TSme*)hSme;
530981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
531981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    scanCncn_StopPeriodicScan (pSme->hScanCncn, SCAN_SCC_DRIVER);
532981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
533981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
534981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/**
535981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \fn     smeSm_StopConnect
536981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \brief  Stops the connect module
537981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
538981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Stops the connect module (if the SME is stopped during a connect attempt
539981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
540981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  hSme - handle to the SME object
541981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \return None
542981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \sa     smeSm_Connect
543981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
544981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtvoid smeSm_StopConnect (TI_HANDLE hSme)
545981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
546981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TSme        *pSme = (TSme*)hSme;
547981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_STATUS   tStatus;
548981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
549981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    tStatus = conn_stop (pSme->hConn, DISCONNECT_DE_AUTH, STATUS_UNSPECIFIED,
550981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                         TI_TRUE, sme_ReportConnStatus, hSme);
551981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
552981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (TI_OK != tStatus)
553981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
554981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        TRACE1(pSme->hReport, REPORT_SEVERITY_ERROR , "smeSm_StopConnect: conn_stop returned status %d\n", tStatus);
555981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
556981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
557981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
558981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/**
559981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \fn     smeSm_ConnWhenConnecting
560981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \brief  Starts the connect process again
561981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
562981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Starts the connect process again
563981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
564981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  hSme - handle to the SME object
565981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \return None
566981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \sa     smeSm_Connect
567981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
568981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtvoid smeSm_ConnWhenConnecting (TI_HANDLE hSme)
569981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
570981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TSme        *pSme = (TSme*)hSme;
571981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_STATUS   tStatus;
572981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
573981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* start the connection process */
574981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    tStatus = conn_start (pSme->hConn, CONN_TYPE_FIRST_CONN, sme_ReportConnStatus, hSme, TI_FALSE, TI_FALSE);
575981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (TI_OK != tStatus)
576981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
577981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        TRACE1(pSme->hReport, REPORT_SEVERITY_ERROR , "smeSm_ConnWhenConnecting: conn_start returned status %d\n", tStatus);
578981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
579981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
580981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
581981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/**
582981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \fn     smeSm_ActionUnexpected
583981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \brief  Called when an unexpected event (for current state) is received
584981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
585981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Called when an unexpected event (for current state) is received
586981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
587981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  hSme - handle to the SME object
588981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \return None
589981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
590981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtvoid smeSm_ActionUnexpected (TI_HANDLE hSme)
591981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
592981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TSme        *pSme = (TSme*)hSme;
593981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
594981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TRACE0(pSme->hReport, REPORT_SEVERITY_ERROR , "smeSm_ActionUnexpected called\n");
595981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
596981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
597981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/**
598981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \fn     smeSm_NopAction
599981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \brief  Called when event call and don't need to do nothing.
600981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
601981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  hSme - handle to the SME object
602981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \return None
603981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
604981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtvoid smeSm_NopAction (TI_HANDLE hSme)
605981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
606981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TSme        *pSme = (TSme*)hSme;
607981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
608981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TRACE0(pSme->hReport, REPORT_SEVERITY_INFORMATION , "smeSm_NopAction called\n");
609981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
610981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
611981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtvoid smeSm_CheckStartConditions (TI_HANDLE hSme)
612981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
613981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TSme        *pSme = (TSme*)hSme;
614981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
615981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if ((TI_TRUE == pSme->bRunning) && (TI_TRUE == pSme->bRadioOn))
616981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
617981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* send a start event */
618981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        genSM_Event (pSme->hSmeSm, SME_SM_EVENT_START, hSme);
619981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
620981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
621981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
622981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
623981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/* do we need to verify G only / A only / dual-band with site mgr? or rely on channels only? */
624981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
625981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/**
626981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \fn     sme_StartScan
627981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \brief  Set scan parameters and calls scan concnetartor to start the scan operation.
628981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
629981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Set scan parameters and calls scan concnetartor to start the scan operation.
630981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
631981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Scan parameters are set according to scan target - find country IE, find desired SSID, or both
632981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * (one on each band). To find country IE we use passive scan forever, to find the desired SSID we
633981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * use active scan until the current country IE expires. In addition, we take into account the WSC PB
634981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * mode - scan constantly for two minutes (but under the country validity and expiry constraints)
635981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
636981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  hSme - handle to the SME object
637981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \return TI_OK if scan started successfully, TI_NOK otherwise
638981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \sa     smeSm_PreConnect
639981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
640981801b95b81e6d1c7a2085967406e86af0f08fcDmitry ShmidtTI_STATUS sme_StartScan (TI_HANDLE hSme)
641981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
642981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TSme            *pSme = (TSme*)hSme;
643023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt    paramInfo_t     *pParam;
644981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_BOOL         bDEnabled, bCountryValid;
645981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_BOOL         bBandChannelExist[ RADIO_BAND_NUM_OF_BANDS ];
646981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_BOOL         bBandCountryFound[ RADIO_BAND_NUM_OF_BANDS ];
647981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_STATUS       tStatus;
648981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32       uIndex;
649981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
650981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* get 802.11d enable state */
651023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt    pParam = (paramInfo_t *)os_memoryAlloc(pSme->hOS, sizeof(paramInfo_t));
652023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt    if (!pParam)
653023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt        return TI_NOK;
654023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt
655023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt    pParam->paramType = REGULATORY_DOMAIN_ENABLED_PARAM;
656023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt    regulatoryDomain_getParam (pSme->hRegDomain, pParam);
657023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt    bDEnabled = pParam->content.regulatoryDomainEnabled;
658981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
659023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt    pParam->paramType = REGULATORY_DOMAIN_IS_COUNTRY_FOUND;
660981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* get country validity for all bands */
661981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    for (uIndex = 0; uIndex < RADIO_BAND_NUM_OF_BANDS; uIndex++)
662981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
663023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt        pParam->content.eRadioBand = uIndex;
664023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt        regulatoryDomain_getParam (pSme->hRegDomain, pParam);
665023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt        bBandCountryFound[ uIndex ] = pParam->content.bIsCountryFound;
666981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* also nullify the channel exist indication for this band */
667981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        bBandChannelExist[ uIndex ] = TI_FALSE;
668981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
669023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt    os_memoryFree(pSme->hOS, pParam, sizeof(paramInfo_t));
670981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
671981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* First fill the channels */
672981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    for (uIndex = 0; uIndex < pSme->tInitParams.uChannelNum; uIndex++)
673981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
674981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* for each channel, if country is found, set active scan */
675981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pSme->tScanParams.tChannels[ uIndex ].eBand = pSme->tInitParams.tChannelList[ uIndex ].eBand;
676981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pSme->tScanParams.tChannels[ uIndex ].uChannel = pSme->tInitParams.tChannelList[ uIndex ].uChannel;
677981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pSme->tScanParams.tChannels[ uIndex ].uMaxDwellTimeMs = pSme->tInitParams.uMaxScanDuration;
678981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pSme->tScanParams.tChannels[ uIndex ].uMinDwellTimeMs = pSme->tInitParams.uMinScanDuration;
679981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pSme->tScanParams.tChannels[ uIndex ].uTxPowerLevelDbm = DEF_TX_POWER;
680981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
681981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* if 802.11d is disabled, or country is available for this band */
682981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if ((TI_FALSE == bDEnabled) ||
683981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            (TI_TRUE == bBandCountryFound[ pSme->tInitParams.tChannelList[ uIndex ].eBand ]))
684981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
685981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* set active scan */
686981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pSme->tScanParams.tChannels[ uIndex ].eScanType = SCAN_TYPE_NORMAL_ACTIVE;
687981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
688981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* 802.11d is enabled and no country available */
689981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        else
690981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
691981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* set passive scan */
692981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pSme->tScanParams.tChannels[ uIndex ].eScanType = SCAN_TYPE_NORMAL_PASSIVE;
693981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
694981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /*
695981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             * in order to fined country set uMaxDwellTimeMs ( that at passive scan set the passiveScanDuration )
696981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             * to significant value
697981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             */
698981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pSme->tScanParams.tChannels[ uIndex ].uMaxDwellTimeMs = SCAN_CNCN_REGULATORY_DOMAIN_PASSIVE_DWELL_TIME_DEF;
699981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
700981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* mark that a channel exists for this band */
701981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        bBandChannelExist[ pSme->tInitParams.tChannelList[ uIndex ].eBand ] = TI_TRUE;
702981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
703981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* set number of channels */
704981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pSme->tScanParams.uChannelNum = pSme->tInitParams.uChannelNum;
705981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
706981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* now, fill global parameters */
707981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pSme->tScanParams.uProbeRequestNum = pSme->tInitParams.uProbeReqNum;
708981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pSme->tScanParams.iRssiThreshold = pSme->tInitParams.iRssiThreshold;
709981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pSme->tScanParams.iSnrThreshold = pSme->tInitParams.iSnrThreshold;
710981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pSme->tScanParams.bTerminateOnReport = TI_TRUE;
711981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pSme->tScanParams.uFrameCountReportThreshold = 1;
712981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
713981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /*
714981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     * if for at least one band country is known and scan is performed on this band - means we need to
715981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     * take into consideration country expiry, plus we are scanning for the desired SSID
716981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     */
717981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    bCountryValid = ((TI_TRUE == bBandChannelExist[ RADIO_BAND_2_4_GHZ ]) && (TI_TRUE == bBandCountryFound[ RADIO_BAND_2_4_GHZ ])) ||
718981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                    ((TI_TRUE == bBandChannelExist[ RADIO_BAND_5_0_GHZ ]) && (TI_TRUE == bBandCountryFound[ RADIO_BAND_5_0_GHZ ]));
719981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
720981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* set SSID(s) and BSS type according to 802.11d status, and country availability */
721981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* if 802.11d is disabled */
722981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (TI_FALSE == bDEnabled)
723981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
724981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pSme->tScanParams.eBssType = pSme->eBssType;
725981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* set the deisred SSID, or any SSID if this is the desired SSID */
726981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if (SSID_TYPE_ANY == pSme->eSsidType)
727981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
728981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pSme->tScanParams.uSsidNum = 0;
729653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt            pSme->tScanParams.uSsidListFilterEnabled = 1;
730981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
731981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        else
732981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
733981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pSme->tScanParams.tDesiredSsid[ 0 ].eVisability = SCAN_SSID_VISABILITY_HIDDEN;
734981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            os_memoryCopy (pSme->hOS, &(pSme->tScanParams.tDesiredSsid[ 0 ].tSsid), &(pSme->tSsid), sizeof (TSsid));
735981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pSme->tScanParams.uSsidNum = 1;
736653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt            pSme->tScanParams.uSsidListFilterEnabled = 1;
737981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
738981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
739981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Country code exists and scan is performed on this band - take country expiry timr into account */
740981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    else if (TI_TRUE == bCountryValid)
741981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
742981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        TRACE0(pSme->hReport, REPORT_SEVERITY_INFORMATION , "sme_StartScan: performing active scan to find desired SSID\n");
743981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
744981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* we already know that at least on one band we know the country IE, so we scan for our SSID */
745981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pSme->tScanParams.tDesiredSsid[ 0 ].eVisability = SCAN_SSID_VISABILITY_HIDDEN;
746981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        os_memoryCopy (pSme->hOS, &(pSme->tScanParams.tDesiredSsid[ 0 ].tSsid), &(pSme->tSsid), sizeof (TSsid));
747981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /*
748981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * if, in addition, we scan the other band to find its country, and the desired SSDI is not any SSID,
749981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * add an empty SSID
750981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         */
751981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if ((SSID_TYPE_ANY != pSme->eSsidType) &&
752981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            (((TI_TRUE == bBandChannelExist[ RADIO_BAND_2_4_GHZ ]) && (TI_FALSE == bBandCountryFound[ RADIO_BAND_2_4_GHZ ])) ||
753981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             ((TI_TRUE == bBandChannelExist[ RADIO_BAND_5_0_GHZ ]) && (TI_FALSE == bBandCountryFound[ RADIO_BAND_5_0_GHZ ]))))
754981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
755981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pSme->tScanParams.tDesiredSsid[ 1 ].eVisability = SCAN_SSID_VISABILITY_PUBLIC;
756981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pSme->tScanParams.tDesiredSsid[ 1 ].tSsid.len = 0;
757981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pSme->tScanParams.uSsidNum = 2;
758653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt            pSme->tScanParams.uSsidListFilterEnabled = 1;
759981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /*
760981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             * since we are also looking for an AP with country IE (not include in IBSS), we need to make sure
761981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             * the desired BSS type include infrastructure BSSes.
762981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             */
763981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            if (BSS_INDEPENDENT == pSme->eBssType)
764981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
765981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                /* the desired is only IBSS - scan for any */
766981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pSme->tScanParams.eBssType = BSS_ANY;
767981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
768981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            else
769981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
770981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                /* the desired is either infrastructure or any - use it */
771981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pSme->tScanParams.eBssType = pSme->eBssType;
772981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
773981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
774981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        else
775981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
776981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pSme->tScanParams.uSsidNum = 1;
777653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt            pSme->tScanParams.uSsidListFilterEnabled = 1;
778981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* only looking for the desired SSID - set the desired BSS type */
779981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pSme->tScanParams.eBssType = pSme->eBssType;
780981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
781981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
782981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* no scanned band has a counrty code - meaning all scan is passive (to find country) */
783981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    else
784981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
785981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        TRACE0(pSme->hReport, REPORT_SEVERITY_INFORMATION , "sme_StartScan: performing passive scan to find country IE\n");
786981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pSme->tScanParams.eBssType = BSS_INFRASTRUCTURE; /* only an AP would transmit a country IE */
787981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pSme->tScanParams.uSsidNum = 0;
788653850f71f9caaa41af19cadbab24bb5e655daf4Dmitry Shmidt        pSme->tScanParams.uSsidListFilterEnabled = 1;
789981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
790981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
791981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* update scan cycle number and scan intervals according to 802.11d status and country availability  */
792981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    sme_updateScanCycles (hSme, bDEnabled, bCountryValid, pSme->bConstantScan);
793981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
794981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* Finally(!!!), start the scan */
795981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    tStatus = scanCncn_StartPeriodicScan (pSme->hScanCncn, SCAN_SCC_DRIVER, &(pSme->tScanParams));
796981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (SCAN_CRS_SCAN_RUNNING != tStatus)
797981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
798981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        TRACE1(pSme->hReport, REPORT_SEVERITY_ERROR , "sme_StartScan: scan concentrator returned status %d\n", tStatus);
799981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        return TI_NOK;
800981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
801981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
802981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    return TI_OK;
803981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
804981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
805981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/**
806981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \fn     sme_updateScanCycles
807981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \brief  Updates the scan intervals and cycle number according to 802.11d status, country availability and WSC PB mode
808981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
809981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Updates the scan intervals and cycle number according to 802.11d status, country availability and WSC PB mode.
810981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Possible scenarios - D disabled - WSC PB off - scan forever with supplied intervals
811981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *                    - D enabled - country unknown - WSC PB off - scan forever with supplied intervals
812981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *                    - D disabled - WSC PB on - scan for two minutes with zero intervals
813981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *                    - D enabled - country unknown - WSC PB on - scan for two minutes with zero intervals
814981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *                    - D enabled - country known - WSC PB off - scan until country expiry with supplied intervals
815981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *                    - D enabled - country known - WSC PB on - scan for the minimu of two minutes and country expiry with zero intervals
816981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
817981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  hSme - handle to the SME object
818981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  bDEnabled - TRUE if 802.11d is enabled
819981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  bCountryValid - TRUE if a country IE is valid for a band on which we scan
820981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  bConstantScan - TRUE if WSC PB mode is on
821981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \return None
822981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \sa     sme_CalculateCyclesNumber, sme_StartScan
823981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
824981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtvoid sme_updateScanCycles (TI_HANDLE hSme,
825981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                           TI_BOOL bDEnabled,
826981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                           TI_BOOL bCountryValid,
827981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                           TI_BOOL bConstantScan)
828981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
829981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TSme            *pSme = (TSme*)hSme;
830981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32       uIndex, uScanPeriodMs, uScanDurationMs;
831023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt    paramInfo_t     *pParam;
832981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
833981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* 802.11d is disabled, or no country is valid */
834981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if ((TI_FALSE == bDEnabled) || (TI_FALSE == bCountryValid))
835981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
836981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* WSC PB mode is disabled */
837981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if (TI_FALSE == bConstantScan)
838981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
839981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /*
840981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             * copy intervals
841981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             * In order to avoid tight loop of scan-select or scan-select-connecting operation,
842981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             * the prepare scan function takes into account the value of the scan_count when setting the 16 periods in the scan command
843981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             */
844981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            os_memoryCopy (pSme->hOS, &(pSme->tScanParams.uCycleIntervalMsec[ 0 ]),
845981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                           &(pSme->tInitParams.uScanIntervals[ pSme->uScanCount ]), sizeof (TI_UINT32) * (PERIODIC_SCAN_MAX_INTERVAL_NUM - pSme->uScanCount));
846981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
847981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            for(uIndex = (PERIODIC_SCAN_MAX_INTERVAL_NUM - pSme->uScanCount); uIndex < PERIODIC_SCAN_MAX_INTERVAL_NUM; uIndex++)
848981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
849981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pSme->tScanParams.uCycleIntervalMsec[ uIndex ] = pSme->tInitParams.uScanIntervals[ PERIODIC_SCAN_MAX_INTERVAL_NUM - 1 ];
850981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
851981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
852981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* scan for default number (until a result is found) */
853981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pSme->tScanParams.uCycleNum = pSme->tInitParams.uCycleNum;
854981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
855981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* WSC PB mode is enabled */
856981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        else
857981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
858981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* turn off WSC PB mode (for next scan) */
859981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pSme->bConstantScan = TI_FALSE;
860981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
861981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* nullify all intervals */
862981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            os_memoryZero (pSme->hOS, &(pSme->tScanParams.uCycleIntervalMsec[ 0 ]),
863981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                           sizeof (TI_UINT32) * PERIODIC_SCAN_MAX_INTERVAL_NUM);
864981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
865981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* calculate the duration of one scan cycle */
866981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            uScanDurationMs = 0;
867981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            for (uIndex = 0; uIndex < pSme->tScanParams.uChannelNum; uIndex++)
868981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
869981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                uScanDurationMs += pSme->tScanParams.tChannels[ uIndex ].uMaxDwellTimeMs;
870981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
871981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
872981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* set the number of cycles - 2 minutes divided by one cycle duration */
873981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pSme->tScanParams.uCycleNum = (120000 / uScanDurationMs) + 1;
874981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
875981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
876981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* 802.11d is enabled, and country is valid on at least one band */
877981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    else
878981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
879023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt        pParam = (paramInfo_t *)os_memoryAlloc(pSme->hOS, sizeof(paramInfo_t));
880023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt        if (!pParam)
881023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt            return;
882023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt
883981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* get country expiry time */
884023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt        pParam->paramType = REGULATORY_DOMAIN_TIME_TO_COUNTRY_EXPIRY;
885023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt        regulatoryDomain_getParam (pSme->hRegDomain, pParam);
886981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
887981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* WSC PB mode is disabled */
888981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        if (TI_FALSE == bConstantScan)
889981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
890981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /*
891981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             * copy intervals
892981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             * In order to avoid tight loop of scan-select or scan-select-connecting operation,
893981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             * the prepare scan function takes into account the value of the scan_count when setting the 16 periods in the scan command
894981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt             */
895981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            os_memoryCopy (pSme->hOS, &(pSme->tScanParams.uCycleIntervalMsec[ 0 ]),
896981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                           &(pSme->tInitParams.uScanIntervals[ pSme->uScanCount ]), sizeof (TI_UINT32) * (PERIODIC_SCAN_MAX_INTERVAL_NUM - pSme->uScanCount));
897981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
898981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            for(uIndex = (PERIODIC_SCAN_MAX_INTERVAL_NUM - pSme->uScanCount); uIndex < PERIODIC_SCAN_MAX_INTERVAL_NUM; uIndex++)
899981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
900981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pSme->tScanParams.uCycleIntervalMsec[ uIndex ] = pSme->tInitParams.uScanIntervals[ PERIODIC_SCAN_MAX_INTERVAL_NUM - 1 ];
901981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
902981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
903981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* set cycle number according to country expiry time */
904023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt            sme_CalculateCyclesNumber (hSme, pParam->content.uTimeToCountryExpiryMs);
905981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
906981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* WSC PB mode is enabled */
907981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        else
908981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        {
909981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* turn off WSC PB mode (for next scan) */
910981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            pSme->bConstantScan = TI_FALSE;
911981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
912981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* set scan period to minimum of WSC PB duration (2 minutes) and country expiry time */
913023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt            uScanPeriodMs = TI_MIN (120000, pParam->content.uTimeToCountryExpiryMs);
914981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
915981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* nullify all intervals */
916981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            os_memoryZero (pSme->hOS, &(pSme->tScanParams.uCycleIntervalMsec[ 0 ]),
917981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                           sizeof (TI_UINT32) * PERIODIC_SCAN_MAX_INTERVAL_NUM);
918981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
919981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            /* calculate the duration of one scan cycle */
920981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            uScanDurationMs = 0;
921981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            for (uIndex = 0; uIndex < pSme->tScanParams.uChannelNum; uIndex++)
922981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
923981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                uScanDurationMs += pSme->tScanParams.tChannels[ uIndex ].uMaxDwellTimeMs;
924981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
925981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
926981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            if (uScanDurationMs != 0)
927981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
928981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                /* set the number of cycles - scan period divided by one cycle duration */
929981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pSme->tScanParams.uCycleNum = (uScanPeriodMs / uScanDurationMs) + 1;
930981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
931981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            else
932981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            {
933981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                pSme->tScanParams.uCycleNum = pSme->tInitParams.uCycleNum;
934981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt            }
935981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        }
936023547f11f3d7c84ab64acaab9b9e821f8c528e7Dmitry Shmidt        os_memoryFree(pSme->hOS, pParam, sizeof(paramInfo_t));
937981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
938981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
939981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* in case independent mode and to avoid supplicant send disconnect event after 60s */
940981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (pSme->eBssType != BSS_INFRASTRUCTURE)
941981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
942981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pSme->tScanParams.uCycleNum = 1;
943981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
944981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
945981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
946981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/**
947981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \fn     sme_CalculateCyclesNumber
948981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \brief  Calculates the cycle number required for a gicen time, according to scan intervals
949981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
950981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Calculates the cycle number required for a gicen time, according to scan intervals. First check the 16
951981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * different intervals, and if more time is available, find how many cycles still fit. Write the result
952981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * to the SME scan command
953981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
954981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  hSme - handle to the SME object
955981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \param  uToTalTimeMs - the total periodic scan operation duartion
956981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \return None
957981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * \sa     sme_updateScanCycles, sme_StartScan
958981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
959981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidtvoid sme_CalculateCyclesNumber (TI_HANDLE hSme, TI_UINT32 uTotalTimeMs)
960981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
961981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TSme            *pSme = (TSme*)hSme;
962981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    TI_UINT32       uIndex, uCurrentTimeMs = 0;
963981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
964981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /*
965981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     * the total time should exceed country code expiration by one interval (so that next scan wouldn't
966981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     * have a valid country code)
967981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt     */
968981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
969981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* nullify cycle number */
970981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    pSme->tScanParams.uCycleNum = 0;
971981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* now find how many cycles fit within this time. First, check if all first 16 configured intervals fit */
972981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    for (uIndex = 0;
973981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         (uIndex < PERIODIC_SCAN_MAX_INTERVAL_NUM) && (uCurrentTimeMs < uTotalTimeMs);
974981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         uIndex++)
975981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
976981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pSme->tScanParams.uCycleNum++;
977981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        uCurrentTimeMs += pSme->tScanParams.uCycleIntervalMsec[ uIndex ];
978981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
979981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    /* now find out how many more cycles with the last interval still fits */
980981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    if (uCurrentTimeMs < uTotalTimeMs)
981981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    {
982981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /*
983981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * divide the reamining time (time until expiry minus the total time calculated so far)
984981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         * by the last interval time, to get how many more scans would fit after the first 16 intervals
985981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt         */
986981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pSme->tScanParams.uCycleNum += (uTotalTimeMs - uCurrentTimeMs) /
987981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt                                            pSme->tScanParams.uCycleIntervalMsec[ PERIODIC_SCAN_MAX_INTERVAL_NUM - 1];
988981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        /* and add one, to compensate for the reminder */
989981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt        pSme->tScanParams.uCycleNum++;
990981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt    }
991981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
992981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
993