2 *************************************************************************
4 * 5F., No.36, Taiyuan St., Jhubei City,
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
25 *************************************************************************
31 Miniport generic portion header file
35 -------- ---------- ----------------------------------------------
36 Fonchi 2007-06-25 Extend original mlme APIs to support multi-entries
39 #include "../rt_config.h"
40 #include "../mlme_ex_def.h"
44 // ===========================================================================================
46 // ===========================================================================================
48 /*! \brief Initialize the state machine.
49 * \param *S pointer to the state machine
50 * \param Trans State machine transition function
51 * \param StNr number of states
52 * \param MsgNr number of messages
53 * \param DefFunc default function, when there is invalid state/message combination
54 * \param InitState initial state of the state machine
55 * \param Base StateMachine base, internal use only
56 * \pre p_sm should be a legal pointer
59 VOID StateMachineInitEx(
60 IN STATE_MACHINE_EX *S,
61 IN STATE_MACHINE_FUNC_EX Trans[],
64 IN STATE_MACHINE_FUNC_EX DefFunc,
70 // set number of states and messages
77 // init all state transition to default function
78 for (i = 0; i < StNr; i++)
80 for (j = 0; j < MsgNr; j++)
82 S->TransFunc[i * MsgNr + j] = DefFunc;
86 // set the starting state
87 S->CurrState = InitState;
92 /*! \brief This function fills in the function pointer into the cell in the state machine
93 * \param *S pointer to the state machine
95 * \param Msg incoming message
96 * \param f the function to be executed when (state, message) combination occurs at the state machine
97 * \pre *S should be a legal pointer to the state machine, st, msg, should be all within the range, Base should be set in the initial state
100 VOID StateMachineSetActionEx(
101 IN STATE_MACHINE_EX *S,
104 IN STATE_MACHINE_FUNC_EX Func)
108 MsgIdx = Msg - S->Base;
110 if (St < S->NrState && MsgIdx < S->NrMsg)
112 // boundary checking before setting the action
113 S->TransFunc[St * S->NrMsg + MsgIdx] = Func;
119 /*! \brief This function does the state transition
120 * \param *Adapter the NIC adapter pointer
121 * \param *S the state machine
122 * \param *Elem the message to be executed
125 VOID StateMachinePerformActionEx(
126 IN PRTMP_ADAPTER pAd,
127 IN STATE_MACHINE_EX *S,
128 IN MLME_QUEUE_ELEM *Elem,
132 if (S->TransFunc[(*pCurrState) * S->NrMsg + Elem->MsgType - S->Base])
133 (*(S->TransFunc[(*pCurrState) * S->NrMsg + Elem->MsgType - S->Base]))(pAd, Elem, pCurrState, Idx);
138 /*! \brief Enqueue a message for other threads, if they want to send messages to MLME thread
139 * \param *Queue The MLME Queue
140 * \param Machine The State Machine Id
141 * \param MsgType The Message Type
142 * \param MsgLen The Message length
143 * \param *Msg The message pointer
144 * \return TRUE if enqueue is successful, FALSE if the queue is full
147 * \note The message has to be initialized
149 BOOLEAN MlmeEnqueueEx(
150 IN PRTMP_ADAPTER pAd,
158 MLME_QUEUE *Queue = (MLME_QUEUE *)&pAd->Mlme.Queue;
160 // Do nothing if the driver is starting halt state.
161 // This might happen when timer already been fired before cancel timer with mlmehalt
162 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS))
166 // First check the size, it MUST not exceed the mlme queue size
167 if (MsgLen > MAX_LEN_OF_MLME_BUFFER)
169 DBGPRINT_ERR(("MlmeEnqueueEx: msg too large, size = %ld \n", MsgLen));
173 if (MlmeQueueFull(Queue))
179 RTMP_SEM_LOCK(&Queue->Lock);
183 if (Queue->Tail == MAX_LEN_OF_MLME_QUEUE)
187 Queue->Entry[Tail].Occupied = TRUE;
188 Queue->Entry[Tail].Machine = Machine;
189 Queue->Entry[Tail].MsgType = MsgType;
190 Queue->Entry[Tail].MsgLen = MsgLen;
191 Queue->Entry[Tail].Idx = Idx;
193 NdisMoveMemory(Queue->Entry[Tail].Msg, Msg, MsgLen);
195 RTMP_SEM_UNLOCK(&Queue->Lock);
201 ==========================================================================
203 The drop function, when machine executes this, the message is simply
204 ignored. This function does nothing, the message is freed in
205 StateMachinePerformAction()
206 ==========================================================================
209 IN PRTMP_ADAPTER pAd,
210 IN MLME_QUEUE_ELEM *Elem,