1/*
2 * connInfra.c
3 *
4 * Copyright(c) 1998 - 2009 Texas Instruments. All rights reserved.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 *  * Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 *  * Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in
15 *    the documentation and/or other materials provided with the
16 *    distribution.
17 *  * Neither the name Texas Instruments nor the names of its
18 *    contributors may be used to endorse or promote products derived
19 *    from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/** \file connInfra.c
35 *  \brief Infra connection implementation
36 *
37 *  \see connInfra.h
38 */
39
40/***************************************************************************/
41/*                                                                         */
42/*      MODULE: connInfra.c                                                */
43/*    PURPOSE:  Infra connection implementation                            */
44/*                                                                         */
45/***************************************************************************/
46
47#define __FILE_ID__  FILE_ID_27
48#include "tidef.h"
49#include "report.h"
50#include "osApi.h"
51#include "conn.h"
52#include "connInfra.h"
53#include "timer.h"
54#include "fsm.h"
55#include "siteMgrApi.h"
56#include "sme.h"
57#include "rsnApi.h"
58#include "DataCtrl_Api.h"
59#include "paramOut.h"
60#include "siteHash.h"
61#include "smeSm.h"
62#include "PowerMgr_API.h"
63#include "measurementMgrApi.h"
64#include "TrafficMonitorAPI.h"
65#include "qosMngr_API.h"
66#include "EvHandler.h"
67#include "SwitchChannelApi.h"
68#include "ScanCncn.h"
69#include "currBss.h"
70#include "healthMonitor.h"
71#include "regulatoryDomainApi.h"
72#include "txCtrl.h"
73#include "TWDriver.h"
74#include "SoftGeminiApi.h"
75#include "RxQueue_api.h"
76
77#ifdef XCC_MODULE_INCLUDED
78#include "XCCMngr.h"
79#include "XCCTSMngr.h"
80#endif
81
82#define DISCONNECT_TIMEOUT_MSEC      800
83
84/* Local functions prototypes */
85
86static TI_STATUS actionUnexpected(void *pData);
87
88static TI_STATUS actionNop(void *pData);
89
90static TI_STATUS connInfra_ScrWait(void *pData);
91
92static TI_STATUS Idle_to_Idle(void *pData);
93
94static TI_STATUS ScrWait_to_idle(void *pData);
95
96static TI_STATUS ScrWait_to_JoinWait(void *pData);
97
98static TI_STATUS JoinWait_to_mlmeWait(void *pData);
99
100static TI_STATUS JoinWait_to_WaitDisconnect(void *pData);
101
102static TI_STATUS mlmeWait_to_WaitDisconnect(void *pData);
103
104static TI_STATUS mlmeWait_to_rsnWait(void *pData);
105
106static TI_STATUS rsnWait_to_disconnect(void *pData);
107
108static TI_STATUS rsnWait_to_configHW(void *pData);
109
110static TI_STATUS configHW_to_connected(void *pData);
111
112static TI_STATUS configHW_to_disconnect(void *pData);
113
114static TI_STATUS connInfra_ScrWaitDisconn_to_disconnect(void *pData);
115
116static TI_STATUS connect_to_ScrWait(void *pData);
117
118static TI_STATUS prepare_send_disconnect(void *pData);
119
120static TI_STATUS connInfra_WaitDisconnectToIdle (void *pData);
121
122
123static TI_STATUS stopModules( conn_t *pConn, TI_BOOL bDisconnect );
124
125void InfraConnSM_ScrCB( TI_HANDLE hConn, EScrClientRequestStatus requestStatus,
126                        EScrResourceId eResource, EScePendReason pendReason );
127
128int conn_ConfigHwFinishCb(TI_HANDLE pData);
129
130/********************************************/
131/*      Functions Implementations           */
132/********************************************/
133
134
135/***********************************************************************
136 *                        conn_infraConfig
137 ***********************************************************************
138DESCRIPTION: Infra Connection configuration function, called by the conection set param function
139                in the selection phase. Configures the connection state machine to Infra connection mode
140
141INPUT:      hConn   -   Connection handle.
142
143OUTPUT:
144
145RETURN:     TI_OK on success, TI_NOK otherwise
146
147************************************************************************/
148TI_STATUS conn_infraConfig(conn_t *pConn)
149{
150    static fsm_actionCell_t    smMatrix[CONN_INFRA_NUM_STATES][CONN_INFRA_NUM_EVENTS] =
151    {
152        /* next state and actions for IDLE state */
153        {   {STATE_CONN_INFRA_SCR_WAIT_CONN, connInfra_ScrWait},        /* "EVENT_CONNECT"  */
154            {STATE_CONN_INFRA_IDLE, actionNop       },                  /* "EVENT_SCR_SUCC"*/
155            {STATE_CONN_INFRA_IDLE, actionNop       },                  /* "EVENT_JOIN_CMD_CMPLT */
156            {STATE_CONN_INFRA_IDLE, Idle_to_Idle    },                  /* "EVENT_DISCONNECT"       */
157            {STATE_CONN_INFRA_IDLE, actionUnexpected},                  /* "EVENT_MLME_SUCC"*/
158            {STATE_CONN_INFRA_IDLE, actionUnexpected},                  /* "EVENT_RSN_SUCC" */
159            {STATE_CONN_INFRA_IDLE, actionNop},                         /* "EVENT_CONFIG_HW" */
160            {STATE_CONN_INFRA_IDLE, actionUnexpected}                   /* "EVENT_DISCONN_COMPLETE" */
161        },
162
163        /* next state and actions for SCR_WAIT_CONN state */
164        {   {STATE_CONN_INFRA_SCR_WAIT_CONN     , actionUnexpected},    /* "EVENT_CONNECT"  */
165            {STATE_CONN_INFRA_WAIT_JOIN_CMPLT, ScrWait_to_JoinWait},    /* "EVENT_SCR_SUCC"*/
166            {STATE_CONN_INFRA_SCR_WAIT_CONN     , actionUnexpected},    /* "EVENT_JOIN_CMD_CMPLT */
167            {STATE_CONN_INFRA_IDLE,     ScrWait_to_idle},               /* "EVENT_DISCONNECT"       */
168            {STATE_CONN_INFRA_SCR_WAIT_CONN     , actionUnexpected},    /* "EVENT_MLME_SUCC"*/
169            {STATE_CONN_INFRA_SCR_WAIT_CONN     , actionUnexpected},    /* "EVENT_RSN_SUCC" */
170            {STATE_CONN_INFRA_SCR_WAIT_CONN     , actionNop},           /* "EVENT_CONFIG_HW "*/
171            {STATE_CONN_INFRA_SCR_WAIT_CONN     , actionNop}            /* "EVENT_DISCONN_COMPLETE" */
172        },
173
174        /* next state and actions for WAIT_JOIN_CMPLT */
175        {   {STATE_CONN_INFRA_WAIT_JOIN_CMPLT, actionUnexpected},       /* "EVENT_CONNECT"    */
176            {STATE_CONN_INFRA_WAIT_JOIN_CMPLT, actionUnexpected},       /* "EVENT_SCR_SUCC"*/
177            {STATE_CONN_INFRA_MLME_WAIT,       JoinWait_to_mlmeWait},   /* "EVENT_JOIN_CMD_CMPLT"   */
178            {STATE_CONN_INFRA_WAIT_DISCONNECT, JoinWait_to_WaitDisconnect},/* "EVENT_DISCONNECT"       */
179            {STATE_CONN_INFRA_WAIT_JOIN_CMPLT, actionUnexpected},       /* "EVENT_MLME_SUCC"*/
180            {STATE_CONN_INFRA_WAIT_JOIN_CMPLT, actionUnexpected},       /* "EVENT_RSN_SUCC" */
181            {STATE_CONN_INFRA_WAIT_JOIN_CMPLT, actionNop},              /* "EVENT_CONFIG_HW"        */
182            {STATE_CONN_INFRA_WAIT_JOIN_CMPLT, actionUnexpected}        /* "EVENT_DISCONN_COMPLETE" */
183
184        },
185
186        /* next state and actions for MLME_WAIT state */
187        {   {STATE_CONN_INFRA_MLME_WAIT, actionUnexpected},             /* "EVENT_CONNECT"  */
188            {STATE_CONN_INFRA_MLME_WAIT, actionUnexpected},             /* "EVENT_SCR_SUCC" */
189            {STATE_CONN_INFRA_MLME_WAIT, actionUnexpected},             /* "EVENT_JOIN_CMD_CMPLT"*/
190            {STATE_CONN_INFRA_WAIT_DISCONNECT, mlmeWait_to_WaitDisconnect}, /* "EVENT_DISCONNECT"       */
191            {STATE_CONN_INFRA_RSN_WAIT,  mlmeWait_to_rsnWait},          /* "EVENT_MLME_SUCC"*/
192            {STATE_CONN_INFRA_MLME_WAIT, actionUnexpected},             /* "EVENT_RSN_SUCC" */
193            {STATE_CONN_INFRA_MLME_WAIT, actionUnexpected},             /* "EVENT_CONFIG_HW" */
194            {STATE_CONN_INFRA_MLME_WAIT, actionUnexpected}              /* "EVENT_DISCONN_COMPLETE" */
195        },
196
197        /* next state and actions for RSN_WAIT state */
198        {   {STATE_CONN_INFRA_RSN_WAIT,     actionUnexpected},          /* "EVENT_CONNECT"  */
199            {STATE_CONN_INFRA_RSN_WAIT,     actionUnexpected},          /* "EVENT_SCR_SUCC" */
200            {STATE_CONN_INFRA_RSN_WAIT,     actionUnexpected},          /* "EVENT_JOIN_CMD_CMPLT"*/
201            {STATE_CONN_INFRA_WAIT_DISCONNECT,    rsnWait_to_disconnect},   /* "EVENT_DISCONNECT" */
202            {STATE_CONN_INFRA_RSN_WAIT,     actionUnexpected},          /* "EVENT_MLME_SUCC"*/
203            {STATE_CONN_INFRA_CONFIG_HW,    rsnWait_to_configHW},       /* "EVENT_RSN_SUCC" */
204            {STATE_CONN_INFRA_RSN_WAIT,     actionUnexpected},          /* "EVENT_CONFIG_HW"        */
205            {STATE_CONN_INFRA_RSN_WAIT,     actionUnexpected}           /* "EVENT_DISCONN_COMPLETE" */
206        },
207
208        /* next state and actions for CONFIG_HW state */
209        {   {STATE_CONN_INFRA_CONFIG_HW, actionUnexpected},             /* "EVENT_CONNECT"  */
210            {STATE_CONN_INFRA_CONFIG_HW, actionUnexpected},             /* "EVENT_SCR_SUCC" */
211            {STATE_CONN_INFRA_CONFIG_HW, actionUnexpected},             /* "EVENT_JOIN_CMD_CMPLT"*/
212            {STATE_CONN_INFRA_WAIT_DISCONNECT, configHW_to_disconnect},     /* "EVENT_DISCONNECT"       */
213            {STATE_CONN_INFRA_CONFIG_HW, actionUnexpected},             /* "EVENT_MLME_SUCC"*/
214            {STATE_CONN_INFRA_CONFIG_HW, actionUnexpected},             /* "EVENT_RSN_SUCC" */
215            {STATE_CONN_INFRA_CONNECTED, configHW_to_connected},        /* "EVENT_CONFIG_HW"        */
216            {STATE_CONN_INFRA_CONFIG_HW, actionUnexpected}              /* "EVENT_DISCONN_COMPLETE" */
217        },
218
219        /* next state and actions for CONNECTED state */
220        {   {STATE_CONN_INFRA_SCR_WAIT_CONN, connect_to_ScrWait},   /* "EVENT_CONNECT"  */
221            {STATE_CONN_INFRA_CONNECTED, actionUnexpected},         /* "EVENT_SCR_SUCC"*/
222            {STATE_CONN_INFRA_CONNECTED, actionUnexpected},         /* "EVENT_JOIN_CMD_CMPLT" */
223            {STATE_CONN_INFRA_SCR_WAIT_DISCONN, connInfra_ScrWait}, /* "EVENT_DISCONNECT"       */
224            {STATE_CONN_INFRA_CONNECTED, actionUnexpected},         /* "EVENT_MLME_SUCC"*/
225            {STATE_CONN_INFRA_CONNECTED, actionUnexpected},         /* "EVENT_RSN_SUCC" */
226            {STATE_CONN_INFRA_CONNECTED, actionUnexpected},         /* "STATE_CONN_INFRA_CONFIG_HW" */
227            {STATE_CONN_INFRA_CONNECTED, actionUnexpected}          /* "EVENT_DISCONN_COMPLETE" */
228        },
229
230        /* next state and actions for SCR_WAIT_DISCONN state */
231        {   {STATE_CONN_INFRA_SCR_WAIT_DISCONN, actionUnexpected},     /* "EVENT_CONNECT"  */
232            {STATE_CONN_INFRA_WAIT_DISCONNECT       , connInfra_ScrWaitDisconn_to_disconnect},  /* "EVENT_SCR_SUCC"*/
233            {STATE_CONN_INFRA_SCR_WAIT_DISCONN, actionUnexpected},     /* "EVENT_JOIN_CMD_CMPLT */
234            {STATE_CONN_INFRA_SCR_WAIT_DISCONN, ScrWait_to_idle},      /* "EVENT_DISCONNECT"       */
235            {STATE_CONN_INFRA_SCR_WAIT_DISCONN, actionUnexpected},     /* "EVENT_MLME_SUCC"*/
236            {STATE_CONN_INFRA_SCR_WAIT_DISCONN, actionUnexpected},     /* "EVENT_RSN_SUCC" */
237            {STATE_CONN_INFRA_SCR_WAIT_DISCONN, actionNop},            /* "EVENT_CONFIG_HW "*/
238            {STATE_CONN_INFRA_SCR_WAIT_DISCONN, actionNop}             /* "EVENT_DISCONN_COMPLETE" */
239        },
240
241        /* next state and actions for STATE_CONN_INFRA_WAIT_DISCONNECT state */
242        {   {STATE_CONN_INFRA_WAIT_DISCONNECT, actionUnexpected},               /* "EVENT_CONNECT"  */
243            {STATE_CONN_INFRA_WAIT_DISCONNECT, actionUnexpected},               /* "STATE_CONN_INFRA_SCR_WAIT_CONN"*/
244            {STATE_CONN_INFRA_WAIT_DISCONNECT, actionUnexpected},               /* "EVENT_JOIN_CMD_CMPLT" */
245            {STATE_CONN_INFRA_WAIT_DISCONNECT, actionUnexpected},               /* "EVENT_DISCONNECT" */
246            {STATE_CONN_INFRA_WAIT_DISCONNECT, actionUnexpected},               /* "EVENT_MLME_SUCC"*/
247            {STATE_CONN_INFRA_WAIT_DISCONNECT, actionUnexpected},               /* "EVENT_RSN_SUCC" */
248            {STATE_CONN_INFRA_WAIT_DISCONNECT, actionUnexpected},               /* "STATE_CONN_INFRA_CONFIG_HW"  */
249            {STATE_CONN_INFRA_IDLE           , connInfra_WaitDisconnectToIdle}  /* "EVENT_DISCONN_COMPLETE" */
250        }
251
252    };
253
254    scr_registerClientCB( pConn->hScr, SCR_CID_CONNECT, InfraConnSM_ScrCB, pConn );
255
256    return fsm_Config(pConn->infra_pFsm, (fsm_Matrix_t)smMatrix, CONN_INFRA_NUM_STATES, CONN_INFRA_NUM_EVENTS, conn_infraSMEvent, pConn->hOs);
257}
258
259/***********************************************************************
260 *                        conn_infraSMEvent
261 ***********************************************************************
262DESCRIPTION: Infra Connection SM event processing function, called by the connection API
263                Perform the following:
264                -   Print the state movement as a result from the event
265                -   Calls the generic state machine event processing function which preform the following:
266                    -   Calls the correspoding callback function
267                    -   Move to next state
268
269INPUT:      currentState    -   Pointer to the connection current state.
270            event   -   Received event
271            pConn   -   Connection handle
272
273OUTPUT:
274
275RETURN:     TI_OK on success, TI_NOK otherwise
276
277************************************************************************/
278TI_STATUS conn_infraSMEvent(TI_UINT8 *currentState, TI_UINT8 event, TI_HANDLE hConn)
279{
280   conn_t *pConn = (conn_t *)hConn;
281    TI_STATUS       status;
282    TI_UINT8       nextState;
283
284    status = fsm_GetNextState(pConn->infra_pFsm, *currentState, event, &nextState);
285    if (status != TI_OK)
286    {
287        TRACE0(pConn->hReport, REPORT_SEVERITY_SM, "State machine error, failed getting next state\n");
288        return(TI_NOK);
289    }
290
291	TRACE3( pConn->hReport, REPORT_SEVERITY_INFORMATION, "conn_ibssSMEvent: <currentState = %d, event = %d> --> nextState = %d\n", *currentState, event, nextState);
292
293    status = fsm_Event(pConn->infra_pFsm, currentState, event, (void *)pConn);
294
295    return status;
296}
297
298/************************************************************************************************************/
299/*      In the following section are listed the callback function used by the Infra connection state machine    */
300/************************************************************************************************************/
301
302/* JOIN, SET_DATA_PORT_NOTIFY, START_MLME */
303static TI_STATUS ScrWait_to_JoinWait(void *pData)
304{
305    TI_STATUS status;
306    conn_t *pConn = (conn_t *)pData;
307
308    status = siteMgr_join(((conn_t *)pData)->hSiteMgr );
309    /* If the Join command was failed we report the SME that connection failure so it could exit connecting state */
310    if (status != TI_OK)
311    {
312       TRACE0(pConn->hReport, REPORT_SEVERITY_ERROR, "Join command has failed!\n");
313    }
314    return status;
315}
316
317
318static TI_STATUS JoinWait_to_mlmeWait(void *pData)
319{
320    TI_STATUS status;
321    paramInfo_t *pParam;
322    conn_t *pConn = (conn_t *)pData;
323
324    pParam = (paramInfo_t *)os_memoryAlloc(pConn->hOs, sizeof(paramInfo_t));
325    if (!pParam)
326        return TI_NOK;
327
328    /* Set the BA session policies to the FW */
329    qosMngr_SetBaPolicies(pConn->hQosMngr);
330
331    pParam->paramType = SITE_MGR_CURRENT_CHANNEL_PARAM;
332    siteMgr_getParam(pConn->hSiteMgr, pParam);
333
334    pParam->paramType = REGULATORY_DOMAIN_TX_POWER_AFTER_SELECTION_PARAM;
335    pParam->content.channel = pParam->content.siteMgrCurrentChannel;
336    regulatoryDomain_setParam(pConn->hRegulatoryDomain, pParam);
337
338    pParam->paramType = RX_DATA_PORT_STATUS_PARAM;
339    pParam->content.rxDataPortStatus = OPEN_NOTIFY;
340    status = rxData_setParam(pConn->hRxData, pParam);
341    if (status != TI_OK)
342    {
343        TRACE1( pConn->hReport, REPORT_SEVERITY_FATAL_ERROR, "JoinWait_to_mlmeWait: rxData_setParam return 0x%x.\n", status);
344        os_memoryFree(pConn->hOs, pParam, sizeof(paramInfo_t));
345        return status;
346    }
347
348    /* Update TxMgmtQueue SM to open Tx path only for Mgmt packets. */
349    txMgmtQ_SetConnState (((conn_t *)pData)->hTxMgmtQ, TX_CONN_STATE_MGMT);
350
351    /*
352     * Set the reassociation flag in the association logic.
353     */
354    pParam->paramType = MLME_RE_ASSOC_PARAM;
355
356    if( pConn->connType == CONN_TYPE_ROAM )
357        pParam->content.mlmeReAssoc = TI_TRUE;
358    else
359        pParam->content.mlmeReAssoc = TI_FALSE;
360
361    status = mlme_setParam(pConn->hMlmeSm, pParam);
362
363    if (status != TI_OK)
364    {
365        TRACE1( pConn->hReport, REPORT_SEVERITY_FATAL_ERROR, "JoinWait_to_mlmeWait: mlme_setParam return 0x%x.\n", status);
366    }
367    os_memoryFree(pConn->hOs, pParam, sizeof(paramInfo_t));
368    return mlme_start(pConn->hMlmeSm);
369}
370
371
372/* STOP_MLME, SET_DATA_PORT_CLOSE, DIS_JOIN */
373static TI_STATUS mlmeWait_to_WaitDisconnect(void *pData)
374{
375    TI_STATUS   status;
376    paramInfo_t *pParam;
377    conn_t      *pConn = (conn_t *)pData;
378
379    status = mlme_stop( pConn->hMlmeSm, DISCONNECT_IMMEDIATE, pConn->disConnReasonToAP );
380    if (status != TI_OK)
381        return status;
382
383    pParam = (paramInfo_t *)os_memoryAlloc(pConn->hOs, sizeof(paramInfo_t));
384    if (!pParam)
385        return TI_NOK;
386
387    pParam->paramType = RX_DATA_PORT_STATUS_PARAM;
388    pParam->content.rxDataPortStatus = CLOSE;
389    rxData_setParam(pConn->hRxData, pParam);
390
391    /* Update TxMgmtQueue SM to close Tx path. */
392    txMgmtQ_SetConnState (pConn->hTxMgmtQ, TX_CONN_STATE_CLOSE);
393
394    /* Start the disconnect complete time out timer.
395       Disconect Complete event, which stops the timer. */
396    tmr_StartTimer (pConn->hConnTimer, conn_timeout, (TI_HANDLE)pConn, DISCONNECT_TIMEOUT_MSEC, TI_FALSE);
397
398    /* FW will send the disconn frame according to disConnType */
399    TWD_CmdFwDisconnect (pConn->hTWD, pConn->disConnType, pConn->disConnReasonToAP);
400
401#ifdef XCC_MODULE_INCLUDED
402    XCCMngr_updateIappInformation(pConn->hXCCMngr, XCC_DISASSOC);
403#endif
404    os_memoryFree(pConn->hOs, pParam, sizeof(paramInfo_t));
405    return TI_OK;
406}
407
408/* This function is called from the WAIT_FOR_JOIN_CB_CMPLT state (before mlme_start)
409  - all we need to do is call siteMgr_disJoin */
410static TI_STATUS JoinWait_to_WaitDisconnect(void *pData)
411{
412    conn_t *pConn = (conn_t *)pData;
413
414    /* Start the disconnect complete time out timer.
415       Disconect Complete event, which stops the timer. */
416    tmr_StartTimer (pConn->hConnTimer, conn_timeout, (TI_HANDLE)pConn, DISCONNECT_TIMEOUT_MSEC, TI_FALSE);
417
418    /* FW will send the disconn frame according to disConnType */
419    TWD_CmdFwDisconnect (pConn->hTWD, pConn->disConnType, pConn->disConnReasonToAP);
420
421   return TI_OK;
422}
423
424/* SET_DATA_PORT_EAPOL, START_RSN */
425static TI_STATUS mlmeWait_to_rsnWait(void *pData)
426{
427    TI_STATUS status;
428    paramInfo_t *pParam;
429    conn_t *pConn = (conn_t *)pData;
430
431    pParam = (paramInfo_t *)os_memoryAlloc(pConn->hOs, sizeof(paramInfo_t));
432    if (!pParam)
433        return TI_NOK;
434
435    pParam->paramType = RX_DATA_PORT_STATUS_PARAM;
436    pParam->content.rxDataPortStatus = OPEN_EAPOL;
437    status = rxData_setParam(pConn->hRxData, pParam);
438    os_memoryFree(pConn->hOs, pParam, sizeof(paramInfo_t));
439    if (status != TI_OK)
440        return status;
441    /* Update TxMgmtQueue SM to enable EAPOL packets. */
442    txMgmtQ_SetConnState (((conn_t *)pData)->hTxMgmtQ, TX_CONN_STATE_EAPOL);
443
444    /*
445     *  Notify that the driver is associated to the supplicant\IP stack.
446     */
447    EvHandlerSendEvent(pConn->hEvHandler, IPC_EVENT_ASSOCIATED, NULL,0);
448    status = rsn_start(pConn->hRsn);
449    return status;
450}
451
452
453
454/* STOP_RSN, SET_DATA_PORT_CLOSE, STOP_MLME, DIS_JOIN */
455static TI_STATUS rsnWait_to_disconnect(void *pData)
456{
457    TI_STATUS status;
458    paramInfo_t *pParam;
459    conn_t *pConn = (conn_t *)pData;
460
461    status = rsn_stop(pConn->hRsn, pConn->disConEraseKeys);
462    if (status != TI_OK)
463        return status;
464
465    pParam = (paramInfo_t *)os_memoryAlloc(pConn->hOs, sizeof(paramInfo_t));
466    if (!pParam)
467        return TI_NOK;
468
469    pParam->paramType = RX_DATA_PORT_STATUS_PARAM;
470    pParam->content.rxDataPortStatus = CLOSE;
471    status = rxData_setParam(pConn->hRxData, pParam);
472    os_memoryFree(pConn->hOs, pParam, sizeof(paramInfo_t));
473    if (status != TI_OK)
474        return status;
475
476    /* Update TxMgmtQueue SM to close Tx path for all except Mgmt packets. */
477    txMgmtQ_SetConnState (pConn->hTxMgmtQ, TX_CONN_STATE_MGMT);
478
479    status = mlme_stop( pConn->hMlmeSm, DISCONNECT_IMMEDIATE, pConn->disConnReasonToAP );
480
481    if (status != TI_OK)
482        return status;
483
484    /* send disconnect command to firmware */
485    prepare_send_disconnect(pData);
486
487    return TI_OK;
488}
489
490
491/* STOP_RSN, SET_DATA_PORT_CLOSE, STOP_MLME, DIS_JOIN */
492static TI_STATUS configHW_to_disconnect(void *pData)
493{
494    TI_STATUS status;
495    paramInfo_t *pParam;
496    conn_t *pConn = (conn_t *)pData;
497
498    status = rsn_stop(pConn->hRsn, pConn->disConEraseKeys );
499    if (status != TI_OK)
500        return status;
501
502    pParam = (paramInfo_t *)os_memoryAlloc(pConn->hOs, sizeof(paramInfo_t));
503    if (!pParam)
504        return TI_NOK;
505
506    pParam->paramType = RX_DATA_PORT_STATUS_PARAM;
507    pParam->content.rxDataPortStatus = CLOSE;
508    status = rxData_setParam(pConn->hRxData, pParam);
509    if (status == TI_OK) {
510        /* Update TxMgmtQueue SM to close Tx path for all except Mgmt packets. */
511        txMgmtQ_SetConnState(pConn->hTxMgmtQ, TX_CONN_STATE_MGMT);
512
513        status = mlme_stop(pConn->hMlmeSm, DISCONNECT_IMMEDIATE, pConn->disConnReasonToAP);
514        if (status == TI_OK) {
515            pParam->paramType = REGULATORY_DOMAIN_DISCONNECT_PARAM;
516            regulatoryDomain_setParam(pConn->hRegulatoryDomain, pParam);
517
518            /* Must be called AFTER mlme_stop. since De-Auth packet should be sent with the
519                supported rates, and stopModules clears all rates. */
520            stopModules(pConn, TI_TRUE);
521
522            /* send disconnect command to firmware */
523            prepare_send_disconnect(pData);
524        }
525    }
526    os_memoryFree(pConn->hOs, pParam, sizeof(paramInfo_t));
527    return status;
528}
529
530static TI_STATUS connInfra_ScrWaitDisconn_to_disconnect(void *pData)
531{
532    TI_STATUS status;
533    paramInfo_t *pParam;
534    conn_t *pConn = (conn_t *)pData;
535
536    status = rsn_stop(pConn->hRsn, pConn->disConEraseKeys);
537    if (status != TI_OK)
538        return status;
539
540    pParam = (paramInfo_t *)os_memoryAlloc(pConn->hOs, sizeof(paramInfo_t));
541    if (!pParam)
542        return TI_NOK;
543
544    pParam->paramType = RX_DATA_PORT_STATUS_PARAM;
545    pParam->content.rxDataPortStatus = CLOSE;
546    status = rxData_setParam(pConn->hRxData, pParam);
547    if (status == TI_OK) {
548        /* Update TxMgmtQueue SM to close Tx path for all except Mgmt packets. */
549        txMgmtQ_SetConnState(pConn->hTxMgmtQ, TX_CONN_STATE_MGMT);
550
551        pParam->paramType = REGULATORY_DOMAIN_DISCONNECT_PARAM;
552        regulatoryDomain_setParam(pConn->hRegulatoryDomain, pParam);
553
554        status = mlme_stop(pConn->hMlmeSm, DISCONNECT_IMMEDIATE, pConn->disConnReasonToAP);
555        if (status == TI_OK) {
556            /* Must be called AFTER mlme_stop. since De-Auth packet should be sent with the
557                supported rates, and stopModules clears all rates. */
558            stopModules(pConn, TI_TRUE);
559
560            /* send disconnect command to firmware */
561            prepare_send_disconnect(pData);
562        }
563    }
564    os_memoryFree(pConn->hOs, pParam, sizeof(paramInfo_t));
565    return status;
566
567}
568
569
570static TI_STATUS rsnWait_to_configHW(void *pData)
571{
572    conn_t *pConn=(conn_t *)pData;
573    TI_STATUS status;
574    paramInfo_t *pParam;
575
576    pParam = (paramInfo_t *)os_memoryAlloc(pConn->hOs, sizeof(paramInfo_t));
577    if (!pParam)
578        return TI_NOK;
579
580    /* Open the RX to DATA */
581    pParam->paramType = RX_DATA_PORT_STATUS_PARAM;
582    pParam->content.rxDataPortStatus = OPEN;
583    status = rxData_setParam(pConn->hRxData, pParam);
584    os_memoryFree(pConn->hOs, pParam, sizeof(paramInfo_t));
585    if (status != TI_OK)
586         return status;
587
588    status = qosMngr_connect(pConn->hQosMngr);
589    if (status != TI_OK)
590    {
591         TRACE2(pConn->hReport, REPORT_SEVERITY_ERROR, "Infra Conn status=%d, have to return (%d)\n",status,__LINE__);
592         return status;
593    }
594
595    status = measurementMgr_connected(pConn->hMeasurementMgr);
596    if (status != TI_OK)
597    {
598         TRACE2(pConn->hReport, REPORT_SEVERITY_ERROR, "Infra Conn status=%d, have to return (%d)\n",status,__LINE__);
599         return status;
600    }
601
602    status = TrafficMonitor_Start(pConn->hTrafficMonitor);
603    if (status != TI_OK)
604    {
605         TRACE2(pConn->hReport, REPORT_SEVERITY_ERROR, "Infra Conn status=%d, have to return (%d)\n",status,__LINE__);
606         return status;
607    }
608
609    healthMonitor_setState(pConn->hHealthMonitor, HEALTH_MONITOR_STATE_CONNECTED);
610
611    switchChannel_start(pConn->hSwitchChannel);
612
613    scanCncn_SwitchToConnected (pConn->hScanCncn);
614
615    PowerMgr_startPS(pConn->hPwrMngr);
616
617    TRACE1(pConn->hReport, REPORT_SEVERITY_INFORMATION, "rsnWait_to_configHW: setStaStatus %d\n",STA_STATE_CONNECTED);
618    TWD_CmdSetStaState(pConn->hTWD, STA_STATE_CONNECTED, conn_ConfigHwFinishCb, pData);
619
620    return TI_OK;
621}
622
623/* last command of rsnWait_to_configHW callback */
624int conn_ConfigHwFinishCb(TI_HANDLE pData)
625{
626    conn_t *pConn = (conn_t *)pData;
627
628    TRACE0(pConn->hReport, REPORT_SEVERITY_INFORMATION, "conn_MboxFlushFinishCb: called \n");
629    return conn_infraSMEvent(&pConn->state, CONN_INFRA_HW_CONFIGURED, pConn);
630}
631
632static TI_STATUS configHW_to_connected(void *pData)
633{
634    conn_t          *pConn=(conn_t *)pData;
635    EScrResourceId  uResourceIndex;
636
637    /* Update TxMgmtQueue SM to open Tx path to all packets. */
638    txMgmtQ_SetConnState (((conn_t *)pData)->hTxMgmtQ, TX_CONN_STATE_OPEN);
639
640#ifdef XCC_MODULE_INCLUDED
641    XCCMngr_updateIappInformation(pConn->hXCCMngr, XCC_ASSOC_OK);
642#endif
643
644    /* Start keep alive process */
645    siteMgr_start(pConn->hSiteMgr);
646
647    /* free both SCR resources */
648    for (uResourceIndex = SCR_RESOURCE_SERVING_CHANNEL;
649         uResourceIndex < SCR_RESOURCE_NUM_OF_RESOURCES;
650         uResourceIndex++)
651    {
652        scr_clientComplete(pConn->hScr, SCR_CID_CONNECT, uResourceIndex );
653        pConn->scrRequested[ uResourceIndex ] = TI_FALSE;
654    }
655
656    /* Update current BSS connection type and mode */
657    currBSS_updateConnectedState(pConn->hCurrBss, TI_TRUE, BSS_INFRASTRUCTURE);
658
659    pConn->pConnStatusCB( pConn->connStatCbObj, STATUS_SUCCESSFUL, 0);
660
661    SoftGemini_SetPSmode(pConn->hSoftGemini);
662#ifdef REPORT_LOG
663    TRACE0(pConn->hReport, REPORT_SEVERITY_CONSOLE, "************ NEW CONNECTION ************\n");
664    WLAN_OS_REPORT(("************ NEW CONNECTION ************\n"));
665    siteMgr_printPrimarySiteDesc(pConn->hSiteMgr);
666    TRACE0(pConn->hReport, REPORT_SEVERITY_CONSOLE, "****************************************\n");
667    WLAN_OS_REPORT(("****************************************\n"));
668#else
669    os_printf("%s: *** NEW CONNECTION ***\n", __func__);
670#endif
671
672    return TI_OK;
673}
674
675
676static TI_STATUS actionUnexpected(void *pData)
677{
678#ifdef TI_DBG
679    conn_t *pConn = (conn_t *)pData;
680
681    TRACE0(pConn->hReport, REPORT_SEVERITY_SM, "State machine error, unexpected Event\n\n");
682#endif /*TI_DBG*/
683
684    return TI_OK;
685}
686
687static TI_STATUS actionNop(void *pData)
688{
689    return TI_OK;
690}
691
692
693static TI_STATUS connInfra_ScrWait(void *pData)
694{
695    conn_t *pConn = (conn_t *)pData;
696    EScrClientRequestStatus scrReplyStatus[ SCR_RESOURCE_NUM_OF_RESOURCES ];
697    EScePendReason          scrPendReason[ SCR_RESOURCE_NUM_OF_RESOURCES ];
698    EScrResourceId          uResourceIndex;
699
700    TRACE0( pConn->hReport, REPORT_SEVERITY_INFORMATION, "Infra Connnect SM: Requesting SCR.\n");
701
702    /* request the SCR for both resources, and act according to return status */
703    for (uResourceIndex = SCR_RESOURCE_SERVING_CHANNEL;
704         uResourceIndex < SCR_RESOURCE_NUM_OF_RESOURCES;
705         uResourceIndex++)
706    {
707        scrReplyStatus[ uResourceIndex ] = scr_clientRequest( pConn->hScr, SCR_CID_CONNECT,
708                                                              uResourceIndex,
709                                                              &(scrPendReason[ uResourceIndex ]));
710        pConn->scrRequested[ uResourceIndex ] = TI_TRUE;
711
712        /* sanity check */
713        if ((scrReplyStatus[ uResourceIndex ] > SCR_CRS_PEND) ||
714            (scrReplyStatus[ uResourceIndex ] < SCR_CRS_RUN))
715        {
716            TRACE2(pConn->hReport, REPORT_SEVERITY_ERROR , "Idle_to_ScrWait: SCR for resource %d returned status %d\n", uResourceIndex, scrReplyStatus[ uResourceIndex ]);
717            return TI_NOK;
718        }
719    }
720
721    /* analyze SCR results: */
722    /* both returned run - continue to next stage */
723    if ((SCR_CRS_RUN == scrReplyStatus[ SCR_RESOURCE_SERVING_CHANNEL ]) &&
724        (SCR_CRS_RUN == scrReplyStatus[ SCR_RESOURCE_PERIODIC_SCAN ]))
725    {
726        /* send an SCR SUCCESS event to the SM */
727        TRACE0( pConn->hReport, REPORT_SEVERITY_INFORMATION, "Infra Conn: SCR acquired.\n");
728        conn_infraSMEvent(&pConn->state, CONN_INFRA_SCR_SUCC, (TI_HANDLE) pConn);
729    }
730    else
731    {
732        /* mark which resource is pending (or both) */
733        for (uResourceIndex = SCR_RESOURCE_PERIODIC_SCAN;
734             uResourceIndex < SCR_RESOURCE_NUM_OF_RESOURCES;
735             uResourceIndex++)
736        {
737            if (SCR_CRS_PEND == scrReplyStatus[ uResourceIndex ])
738            {
739                TRACE2( pConn->hReport, REPORT_SEVERITY_INFORMATION, "Infra Conn: SCR pending for resource %d with pend reason: %d, stay in wait SCR state.\n", uResourceIndex, scrPendReason);
740                pConn->bScrAcquired[ uResourceIndex ] = TI_FALSE;
741            }
742            else
743            {
744                pConn->bScrAcquired[ uResourceIndex ] = TI_TRUE;
745            }
746        }
747    }
748    return TI_OK;
749}
750
751
752
753void InfraConnSM_ScrCB( TI_HANDLE hConn, EScrClientRequestStatus requestStatus,
754                        EScrResourceId eResource, EScePendReason pendReason )
755{
756    conn_t *pConn = (conn_t *)hConn;
757
758    TRACE2( pConn->hReport, REPORT_SEVERITY_INFORMATION, "InfraConnSM_ScrCB called by SCR for resource %d. Status is: %d.\n", eResource, requestStatus);
759
760    /* act according to the request staus */
761    switch ( requestStatus )
762    {
763    case SCR_CRS_RUN:
764        TRACE0( pConn->hReport, REPORT_SEVERITY_INFORMATION, "Infra Conn: SCR acquired.\n");
765        /* mark that the SCR was acquired for this resource */
766        pConn->bScrAcquired[ eResource ] = TI_TRUE;
767
768        /* if both resources had now been acquired */
769        if ((TI_TRUE == pConn->bScrAcquired[ SCR_RESOURCE_SERVING_CHANNEL ]) &&
770            (TI_TRUE == pConn->bScrAcquired[ SCR_RESOURCE_PERIODIC_SCAN ]))
771        {
772            /* send an SCR SUCCESS event to the SM */
773            conn_infraSMEvent(&pConn->state, CONN_INFRA_SCR_SUCC, (TI_HANDLE) pConn);
774        }
775        break;
776
777    case SCR_CRS_FW_RESET:
778        /* Ignore FW reset, the MLME SM will handle re-try of the conn */
779        TRACE0( pConn->hReport, REPORT_SEVERITY_INFORMATION, "Infra Conn: Recovery occured.\n");
780        break;
781
782    default:
783        TRACE3( pConn->hReport, REPORT_SEVERITY_ERROR, "Illegal SCR request status:%d, pend reason:%d, resource: %d.\n", requestStatus, pendReason, eResource);
784        break;
785    }
786}
787
788
789
790static TI_STATUS ScrWait_to_idle(void *pData)
791{
792    conn_t          *pConn = (conn_t *)pData;
793    EScrResourceId  uResourceIndex;
794
795    TRACE0( pConn->hReport, REPORT_SEVERITY_INFORMATION, "Infra Connnect SM: Stop event while in SCR wait, moving to IDLE.\n");
796
797    /* free both SCR resources */
798    for (uResourceIndex = SCR_RESOURCE_SERVING_CHANNEL;
799         uResourceIndex < SCR_RESOURCE_NUM_OF_RESOURCES;
800         uResourceIndex++)
801    {
802        scr_clientComplete(pConn->hScr, SCR_CID_CONNECT, uResourceIndex );
803        pConn->scrRequested[ uResourceIndex ] = TI_FALSE;
804    }
805
806    /*
807     * Call the connection lost callback set by the SME or AP_CONN.
808     */
809    pConn->pConnStatusCB( pConn->connStatCbObj, pConn->smContext.disAssocEventReason, pConn->smContext.disAssocEventStatusCode);
810
811    return TI_OK;
812}
813
814
815static TI_STATUS stopModules( conn_t *pConn, TI_BOOL bDisconnect )
816{
817
818    measurementMgr_disconnected(pConn->hMeasurementMgr);
819
820    rxData_stop(pConn->hRxData);
821
822    ctrlData_stop(pConn->hCtrlData);
823
824    TrafficMonitor_Stop(pConn->hTrafficMonitor);
825
826    switchChannel_stop(pConn->hSwitchChannel);
827
828    healthMonitor_setState(pConn->hHealthMonitor, HEALTH_MONITOR_STATE_DISCONNECTED);
829
830    siteMgr_stop(pConn->hSiteMgr);
831
832    /* stopping power save */
833    PowerMgr_stopPS(pConn->hPwrMngr, bDisconnect);
834
835    scanCncn_SwitchToNotConnected (pConn->hScanCncn);
836
837    /* Set Current BSS Module to stop triggerring roaming events */
838    currBSS_updateConnectedState(pConn->hCurrBss, TI_FALSE, BSS_INFRASTRUCTURE);
839
840    SoftGemini_unSetPSmode(pConn->hSoftGemini);
841
842    return TI_OK;
843}
844
845
846static TI_STATUS prepare_send_disconnect(void *pData)
847{
848    conn_t          *pConn = (conn_t *)pData;
849
850    txCtrlParams_setEapolEncryptionStatus(pConn->hTxCtrl, DEF_EAPOL_ENCRYPTION_STATUS);
851    qosMngr_disconnect (pConn->hQosMngr, TI_TRUE);
852
853#ifdef XCC_MODULE_INCLUDED
854    measurementMgr_disableTsMetrics(pConn->hMeasurementMgr, MAX_NUM_OF_AC);
855#endif
856
857    /* Start the disconnect complete time out timer.
858       Disconect Complete event, which stops the timer. */
859    tmr_StartTimer (pConn->hConnTimer, conn_timeout, (TI_HANDLE)pConn, DISCONNECT_TIMEOUT_MSEC, TI_FALSE);
860
861    /* FW will send the disconn frame according to disConnType */
862    TWD_CmdFwDisconnect (pConn->hTWD, pConn->disConnType, pConn->disConnReasonToAP);
863
864#ifdef XCC_MODULE_INCLUDED
865    XCCMngr_updateIappInformation(pConn->hXCCMngr, XCC_DISASSOC);
866#endif
867
868    return TI_OK;
869}
870
871static TI_STATUS connInfra_WaitDisconnectToIdle(void *pData)
872{
873    conn_t          *pConn = (conn_t *)pData;
874    EScrResourceId  uResourceIndex;
875
876    /* close all BA sessions */
877    TWD_CloseAllBaSessions(pConn->hTWD);
878
879    /* Stop the disconnect timeout timer. */
880    tmr_StopTimer (pConn->hConnTimer);
881
882    /*
883     * In case of connection failuer we might get here without freeing the SCR.
884     */
885    for (uResourceIndex = SCR_RESOURCE_SERVING_CHANNEL;
886         uResourceIndex < SCR_RESOURCE_NUM_OF_RESOURCES;
887         uResourceIndex++)
888    {
889        if (pConn->scrRequested[ uResourceIndex ] == TI_TRUE)
890        {
891            scr_clientComplete(pConn->hScr, SCR_CID_CONNECT, uResourceIndex );
892            pConn->scrRequested[ uResourceIndex ] = TI_FALSE;
893        }
894    }
895
896    /*
897     * Call the connection lost callback set by the SME or AP_CONN.
898     */
899    pConn->pConnStatusCB( pConn->connStatCbObj, pConn->smContext.disAssocEventReason, pConn->smContext.disAssocEventStatusCode);
900
901    return TI_OK;
902}
903
904static TI_STATUS connect_to_ScrWait(void *pData)
905{
906    TI_STATUS   status;
907    paramInfo_t param;
908    conn_t      *pConn = (conn_t *)pData;
909
910    /*
911     * This function performs roaming by two steps:
912     * First - close the current connection without notify the SME.
913     * Second - start new connection in reassociation mode.
914     */
915
916    /* close all BA sessions */
917    TWD_CloseAllBaSessions(pConn->hTWD);
918
919    status = rsn_stop(pConn->hRsn, pConn->disConEraseKeys);
920    if (status != TI_OK)
921        return status;
922
923    param.paramType = RX_DATA_PORT_STATUS_PARAM;
924    param.content.rxDataPortStatus = CLOSE;
925    status = rxData_setParam(pConn->hRxData, &param);
926    if (status != TI_OK)
927        return status;
928
929    /* Update TxMgmtQueue SM to close Tx path. */
930    txMgmtQ_SetConnState (((conn_t *)pData)->hTxMgmtQ, TX_CONN_STATE_CLOSE);
931
932    status = mlme_stop(pConn->hMlmeSm, DISCONNECT_IMMEDIATE, pConn->disConnReasonToAP);
933    if (status != TI_OK)
934        return status;
935
936    param.paramType = REGULATORY_DOMAIN_DISCONNECT_PARAM;
937    regulatoryDomain_setParam(pConn->hRegulatoryDomain, &param);
938
939#ifdef XCC_MODULE_INCLUDED
940    XCCMngr_updateIappInformation(pConn->hXCCMngr, XCC_DISASSOC);
941#endif
942    /* Must be called AFTER mlme_stop. since De-Auth packet should be sent with the
943        supported rates, and stopModules clears all rates. */
944    stopModules(pConn, TI_FALSE);
945
946    txCtrlParams_setEapolEncryptionStatus(pConn->hTxCtrl, DEF_EAPOL_ENCRYPTION_STATUS);
947    qosMngr_disconnect (pConn->hQosMngr, TI_FALSE);
948
949    /*
950     * Start new connection.
951     */
952    connInfra_ScrWait(pConn);
953
954    return TI_OK;
955}
956
957static TI_STATUS Idle_to_Idle(void *pData)
958{
959    conn_t *pConn = (conn_t *)pData;
960
961    /*
962     * In case we are in IDLE and getting DISCONNECT event, we need to inform
963     * the SME\AP_connection that we are disconnected.
964     * Call the connection lost callback set by the SME or AP_CONN.
965     */
966    pConn->pConnStatusCB( pConn->connStatCbObj, pConn->smContext.disAssocEventReason, pConn->smContext.disAssocEventStatusCode);
967
968    return TI_OK;
969}
970
971/***********************************************************************
972                connInfra_JoinCmpltNotification
973 ***********************************************************************
974DESCRIPTION: Call back upon receving Join Event Complete.
975
976INPUT:      hSiteMgr    -   site mgr handle.
977
978OUTPUT:
979
980RETURN:
981************************************************************************/
982TI_STATUS connInfra_JoinCmpltNotification(TI_HANDLE hconn)
983{
984    conn_t *pConn = (conn_t *)hconn;
985
986    TRACE0(pConn->hReport, REPORT_SEVERITY_INFORMATION, "connInfra_JoinCmpltNotification: has been called\n");
987
988   if (pConn->currentConnType == CONNECTION_INFRA ) {
989       conn_infraSMEvent(&pConn->state, CONN_INFRA_JOIN_CMD_CMPLT, pConn);
990   }
991
992   return TI_OK;
993}
994
995void connInfra_DisconnectComplete (conn_t *pConn, TI_UINT8  *data, TI_UINT8   dataLength)
996{
997    /* send an DISCONNECT COMPLETE event to the SM */
998    conn_infraSMEvent(&pConn->state, CONN_INFRA_DISCONN_COMPLETE, (TI_HANDLE) pConn);
999}
1000