• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * mlmeBuilder.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 mlmeBuilder.c
35  *  \brief 802.11 MLME Builder
36  *
37  *  \see mlmeBuilder.h
38  */
39 
40 
41 /***************************************************************************/
42 /*																		   */
43 /*		MODULE:	mlmeBuilder.c											   */
44 /*    PURPOSE:	802.11 MLME Builder										   */
45 /*																	 	   */
46 /***************************************************************************/
47 
48 #define __FILE_ID__  FILE_ID_67
49 #include "tidef.h"
50 #include "osApi.h"
51 #include "paramOut.h"
52 #include "report.h"
53 #include "802_11Defs.h"
54 #include "DataCtrl_Api.h"
55 #include "mlmeApi.h"
56 #include "mlmeSm.h"
57 #include "mlmeBuilder.h"
58 #include "TWDriver.h"
59 #include "connApi.h"
60 /* Constants */
61 
62 /* Enumerations */
63 
64 /* Typedefs */
65 
66 /* Structures */
67 
68 /* External data definitions */
69 
70 /* External functions definitions */
71 
72 /* Local function prototypes */
73 
74 /* Functions */
75 
mlmeBuilder_sendFrame(TI_HANDLE hMlme,dot11MgmtSubType_e type,TI_UINT8 * pDataBuff,TI_UINT32 dataLen,TI_UINT8 setWepOpt)76 TI_STATUS mlmeBuilder_sendFrame(TI_HANDLE hMlme,
77 							 dot11MgmtSubType_e type,
78 							 TI_UINT8   *pDataBuff,
79 							 TI_UINT32  dataLen,
80 							 TI_UINT8	setWepOpt)
81 {
82 	mlme_t			*pHandle = (mlme_t*)hMlme;
83 	TI_STATUS		status;
84     TTxCtrlBlk      *pPktCtrlBlk;
85     TI_UINT8        *pPktBuffer;
86 	TMacAddr		daBssid, saBssid;
87 	dot11_mgmtHeader_t	*pDot11Header;
88 
89 	/* Allocate a TxCtrlBlk and data buffer (large enough for the max management packet) */
90     pPktCtrlBlk = TWD_txCtrlBlk_Alloc (pHandle->hTWD);
91     pPktBuffer  = txCtrl_AllocPacketBuffer (pHandle->hTxCtrl,
92                                             pPktCtrlBlk,
93                                             MAX_MANAGEMENT_FRAME_BODY_LEN + WLAN_HDR_LEN);
94     if (pPktBuffer == NULL)
95     {
96         TRACE0(pHandle->hReport, REPORT_SEVERITY_ERROR , ": No memory\n");
97         TWD_txCtrlBlk_Free (pHandle->hTWD, pPktCtrlBlk);
98         return TI_NOK;
99     }
100 
101 	pDot11Header = (dot11_mgmtHeader_t *)(pPktCtrlBlk->aPktHdr);
102 
103 	status = mlmeBuilder_buildFrameCtrl (pHandle, type, (TI_UINT16 *)&pDot11Header->fc, setWepOpt);
104 	if (status != TI_OK)
105 	{
106         txCtrl_FreePacket (pHandle->hTxCtrl, pPktCtrlBlk, TI_NOK);
107 		return TI_NOK;
108 	}
109 
110     status = ctrlData_getParamBssid(pHandle->hCtrlData, CTRL_DATA_CURRENT_BSSID_PARAM, daBssid);
111 	if (status != TI_OK)
112 	{
113         txCtrl_FreePacket (pHandle->hTxCtrl, pPktCtrlBlk, TI_NOK);
114 		return TI_NOK;
115 	}
116 
117 	/* copy destination mac address */
118 	MAC_COPY (pDot11Header->DA, daBssid);
119 
120     status = ctrlData_getParamBssid(pHandle->hCtrlData, CTRL_DATA_MAC_ADDRESS, saBssid);
121 	if (status != TI_OK)
122 	{
123         txCtrl_FreePacket (pHandle->hTxCtrl, pPktCtrlBlk, TI_NOK);
124 		return TI_NOK;
125 	}
126 
127 	/* copy source mac address */
128 	MAC_COPY (pDot11Header->SA, saBssid);
129 
130 	/* copy BSSID (destination mac address) */
131 	MAC_COPY (pDot11Header->BSSID, daBssid);
132 
133 	if (pDataBuff != NULL)
134 	{
135 		os_memoryCopy (pHandle->hOs, pPktBuffer, pDataBuff, dataLen);
136 	}
137 
138     /* Update packet parameters (start-time, length, pkt-type) */
139     pPktCtrlBlk->tTxDescriptor.startTime = os_timeStampMs (pHandle->hOs);
140     pPktCtrlBlk->tTxPktParams.uPktType   = TX_PKT_TYPE_MGMT;
141     BUILD_TX_TWO_BUF_PKT_BDL (pPktCtrlBlk, (TI_UINT8 *)pDot11Header, WLAN_HDR_LEN, pPktBuffer, dataLen)
142 
143 	/* Enqueue packet in the mgmt-queues and run the scheduler. */
144 	status = txMgmtQ_Xmit (pHandle->hTxMgmtQ, pPktCtrlBlk, TI_FALSE);
145 
146 	return status;
147 }
148 
149 
mlmeBuilder_buildFrameCtrl(mlme_t * pMlme,dot11MgmtSubType_e type,TI_UINT16 * pFctrl,TI_UINT8 setWepOpt)150 TI_STATUS mlmeBuilder_buildFrameCtrl(mlme_t* pMlme, dot11MgmtSubType_e type, TI_UINT16* pFctrl, TI_UINT8 setWepOpt)
151 {
152 	TI_UINT16	fc = 0;
153 
154 	switch (type)
155 	{
156 	case ASSOC_REQUEST:
157 		fc |= DOT11_FC_ASSOC_REQ;
158 		break;
159 	case ASSOC_RESPONSE:
160 		fc |= DOT11_FC_ASSOC_RESP;
161 		break;
162 	case RE_ASSOC_REQUEST:
163 		fc |= DOT11_FC_REASSOC_REQ;
164 		break;
165 	case RE_ASSOC_RESPONSE:
166 		fc |= DOT11_FC_REASSOC_RESP;
167 		break;
168 	case DIS_ASSOC:
169 		fc |= DOT11_FC_DISASSOC;
170 		break;
171 	case AUTH:
172 		fc |= DOT11_FC_AUTH;
173 		break;
174 	case DE_AUTH:
175 		fc |= DOT11_FC_DEAUTH;
176 		break;
177 	case ACTION:
178 		fc |= DOT11_FC_ACTION;
179 		break;
180 	default:
181 		*pFctrl = 0;
182 		return TI_NOK;
183 	}
184 
185 	if (setWepOpt)
186 	{
187 		fc |= DOT11_FC_WEP;
188 	}
189 
190 	COPY_WLAN_WORD(pFctrl, &fc); /* copy with endianess handling. */
191 
192 	return TI_OK;
193 }
194 
195