Home | History | Annotate | Download | only in Sta_Management
      1 /*
      2  * templates.c
      3  *
      4  * Copyright(c) 1998 - 2010 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 reportReplvl.c
     35  *  \brief Report level implementation
     36  *
     37  *  \see reportReplvl.h
     38  */
     39 
     40 /***************************************************************************/
     41 /*																		   */
     42 /*		MODULE:	reportReplvl.c											   */
     43 /*    PURPOSE:	Report level implementation	 							   */
     44 /*																		   */
     45 /***************************************************************************/
     46 
     47 #define __FILE_ID__  FILE_ID_88
     48 #include "tidef.h"
     49 #include "report.h"
     50 #include "osApi.h"
     51 #include "siteHash.h"
     52 #include "rate.h"
     53 #include "rsnApi.h"
     54 #include "regulatoryDomainApi.h"
     55 #include "siteMgrApi.h"
     56 #include "TWDriver.h"
     57 #include "StaCap.h"
     58 #include "qosMngr_API.h"
     59 
     60 /********************************************/
     61 /*		Functions Implementation 			*/
     62 /********************************************/
     63 
     64 /************************************************************************
     65  *                        buildNullTemplate								*
     66  ************************************************************************
     67 DESCRIPTION: This function build a NULL data template to set to the HAL
     68 				when joining an infrastructure network
     69 				performs the following:
     70 				-	Build a template & set the template len, the template type is set in the site mgr
     71 
     72 INPUT:      pSiteMgr	-	Handle to site manager
     73 			pTemplate	-	Pointer to the template structure
     74 
     75 
     76 OUTPUT:
     77 
     78 
     79 RETURN:     TI_OK
     80 
     81 ************************************************************************/
     82 TI_STATUS buildNullTemplate(siteMgr_t *pSiteMgr, TSetTemplate *pTemplate)
     83 {
     84 	paramInfo_t			param;
     85 	nullDataTemplate_t	*pBuffer = (nullDataTemplate_t	*)pTemplate->ptr;
     86 	siteEntry_t			*pPrimarySite = pSiteMgr->pSitesMgmtParams->pPrimarySite;
     87 	TI_UINT16				fc;
     88 
     89 	os_memoryZero(pSiteMgr->hOs, pBuffer, sizeof(nullDataTemplate_t));
     90 
     91 	/*
     92 	 * Header First
     93 	 */
     94 	/* Set destination address */
     95 	MAC_COPY (pBuffer->hdr.DA, pPrimarySite->bssid);
     96 
     97 	/* Set BSSID address */
     98 	MAC_COPY (pBuffer->hdr.BSSID, pPrimarySite->bssid);
     99 
    100 	/* Build Source address */
    101 	param.paramType = CTRL_DATA_MAC_ADDRESS;
    102 	ctrlData_getParam(pSiteMgr->hCtrlData, &param);
    103 	MAC_COPY (pBuffer->hdr.SA, param.content.ctrlDataDeviceMacAddress);
    104 
    105 	fc = DOT11_FC_DATA_NULL_FUNCTION;
    106 	fc |= (TI_TRUE << DOT11_FC_TO_DS_SHIFT);
    107 
    108 	COPY_WLAN_WORD(&pBuffer->hdr.fc, &fc); /* copy with endianess handling. */
    109 
    110 	pTemplate->len = sizeof(dot11_mgmtHeader_t);
    111 	return TI_OK;
    112 }
    113 
    114 /************************************************************************
    115  *                        buildDisconnTemplate								*
    116  ************************************************************************
    117 DESCRIPTION: This function build a Death/Disassoc template to set to the HAL
    118 				when joining an infrastructure network
    119 				performs the following:
    120 				-	Build a template & set the template len, the template type is set in the site mgr
    121 
    122 INPUT:      pSiteMgr	-	Handle to site manager
    123 			pTemplate	-	Pointer to the template structure
    124 
    125 
    126 OUTPUT:
    127 
    128 
    129 RETURN:     TI_OK
    130 
    131 ************************************************************************/
    132 TI_STATUS buildDisconnTemplate(siteMgr_t *pSiteMgr, TSetTemplate *pTemplate)
    133 {
    134 	paramInfo_t			param;
    135 	TI_UINT32				size;
    136 	disconnTemplate_t	*pBuffer = (disconnTemplate_t	*)pTemplate->ptr;
    137 	siteEntry_t			*pPrimarySite = pSiteMgr->pSitesMgmtParams->pPrimarySite;
    138 	TI_UINT16				fc;
    139 
    140 	os_memoryZero(pSiteMgr->hOs, pBuffer, sizeof(disconnTemplate_t));
    141 
    142 	/*
    143 	 * Header First
    144 	 */
    145 	/* Set destination address */
    146 	MAC_COPY (pBuffer->hdr.DA, pPrimarySite->bssid);
    147 
    148 	/* Set BSSID address */
    149 	MAC_COPY (pBuffer->hdr.BSSID, pPrimarySite->bssid);
    150 
    151 	/* Build Source address */
    152 	param.paramType = CTRL_DATA_MAC_ADDRESS;
    153 	ctrlData_getParam(pSiteMgr->hCtrlData, &param);
    154 	MAC_COPY (pBuffer->hdr.SA, param.content.ctrlDataDeviceMacAddress);
    155 
    156 	fc = DOT11_FC_DISASSOC; /* will be change by firmware to DOT11_FC_DEAUTH if needed */
    157 
    158 	COPY_WLAN_WORD(&pBuffer->hdr.fc, &fc); /* copy with endianess handling. */
    159 
    160 	pBuffer->disconnReason = 0; /* filled by firmware */
    161 
    162 	size = sizeof(disconnTemplate_t);
    163 
    164 	pTemplate->len = size;
    165 
    166 	return TI_OK;
    167 }
    168 
    169 /**
    170  * \fn     setDefaultProbeReqTemplate
    171  * \brief  set Default Probe Req Template tp the FW.
    172  *
    173  * set Default Probe Req Template tp the FW.
    174  *
    175  * \param  hSiteMgr	-	Handle to site manager
    176  * \return None
    177  * \sa
    178  */
    179 void setDefaultProbeReqTemplate (TI_HANDLE	hSiteMgr)
    180 {
    181     siteMgr_t	*pSiteMgr = (siteMgr_t *)hSiteMgr;
    182     TSetTemplate        tTemplateStruct;
    183     probeReqTemplate_t  tProbeReqTemplate;
    184     TSsid               tBroadcastSSID;
    185 
    186     /*
    187      * Setting probe request temapltes for both bands.
    188      * allocating EMPTY 32 bytes for the SSID IE, to reserve space for different SSIDs the FW will set
    189      */
    190     tBroadcastSSID.len = MAX_SSID_LEN;
    191     os_memorySet (pSiteMgr->hOs, &(tBroadcastSSID.str[ 0 ]), 0, MAX_SSID_LEN);
    192     tTemplateStruct.ptr = (TI_UINT8 *)&tProbeReqTemplate;
    193     tTemplateStruct.type = PROBE_REQUEST_TEMPLATE;
    194     tTemplateStruct.eBand = RADIO_BAND_2_4_GHZ;
    195     tTemplateStruct.uRateMask = RATE_MASK_UNSPECIFIED;
    196     buildProbeReqTemplate (hSiteMgr, &tTemplateStruct, &tBroadcastSSID, RADIO_BAND_2_4_GHZ);
    197     TWD_CmdTemplate (pSiteMgr->hTWD, &tTemplateStruct, NULL, NULL);
    198     tTemplateStruct.eBand = RADIO_BAND_5_0_GHZ;
    199     buildProbeReqTemplate (hSiteMgr, &tTemplateStruct, &tBroadcastSSID, RADIO_BAND_5_0_GHZ);
    200     TWD_CmdTemplate (pSiteMgr->hTWD, &tTemplateStruct, NULL, NULL);
    201 }
    202 
    203 /************************************************************************
    204  *                        buildProbeReqTemplate							*
    205  ************************************************************************
    206 DESCRIPTION: This function build a probe request template to set to the HAL in the scan process.
    207 				performs the following:
    208 				-	Build a template & set the template len, the template type is set in the site mgr
    209 
    210 INPUT:      pSiteMgr	-	Handle to site manager
    211 			pTemplate	-	Pointer to the template structure
    212 			pSsid		-	Desired SSID
    213 
    214 
    215 OUTPUT:
    216 
    217 
    218 RETURN:     TI_OK
    219 
    220 ************************************************************************/
    221 TI_STATUS buildProbeReqTemplate(siteMgr_t *pSiteMgr, TSetTemplate *pTemplate, TSsid *pSsid, ERadioBand radioBand)
    222 {
    223 	paramInfo_t			param;
    224 	char				*pBuf;
    225 	int i;
    226 	probeReqTemplate_t	*pBuffer = (probeReqTemplate_t	*)pTemplate->ptr;
    227 	TI_UINT32			 size;
    228 	dot11_RATES_t		*pDot11Rates;
    229 	TI_UINT32			 len = 0, ofdmIndex = 0;
    230 	TI_UINT32			 suppRatesLen, extSuppRatesLen;
    231 	TI_UINT8			 ratesBuf[DOT11_MAX_SUPPORTED_RATES];
    232 	TI_UINT8             WSCOuiIe[DOT11_OUI_LEN] = { 0x00, 0x50, 0xf2, 0x04};
    233 	TI_UINT32			 supportedRateMask,basicRateMask;
    234 	TI_UINT16			 fc = DOT11_FC_PROBE_REQ;
    235 
    236 	os_memoryZero(pSiteMgr->hOs, pBuffer, sizeof(probeReqTemplate_t));
    237 
    238 	/*
    239 	 * Header First
    240 	 */
    241 	/* Set destination address */
    242 	for (i = 0; i < MAC_ADDR_LEN; i++)
    243 		pBuffer->hdr.DA[i] = 0xFF;
    244 
    245 	/* Set BSSID address */
    246 
    247 	for (i = 0; i < MAC_ADDR_LEN; i++)
    248 		pBuffer->hdr.BSSID[i] = 0xFF;
    249 
    250 
    251 	/* Build Source address */
    252 	param.paramType = CTRL_DATA_MAC_ADDRESS;
    253 	ctrlData_getParam(pSiteMgr->hCtrlData, &param);
    254 	MAC_COPY (pBuffer->hdr.SA, param.content.ctrlDataDeviceMacAddress);
    255 
    256 	COPY_WLAN_WORD(&pBuffer->hdr.fc, &fc); /* copy with endianess handling. */
    257 
    258 	size = sizeof(dot11_mgmtHeader_t);
    259 	pBuf = (char *)&(pBuffer->infoElements);
    260 
    261    /*
    262 	* Informataion elements
    263 	*/
    264 	/* SSID */
    265     /* It looks like it never happens. Anyway decided to check */
    266     if ( pSsid->len > MAX_SSID_LEN )
    267     {
    268         TRACE2( pSiteMgr->hReport, REPORT_SEVERITY_ERROR,
    269                "buildProbeReqTemplate. pSsid->len=%d exceeds the limit %d\n",
    270                pSsid->len, MAX_SSID_LEN);
    271         handleRunProblem(PROBLEM_BUF_SIZE_VIOLATION);
    272         return TI_NOK;
    273     }
    274 	((dot11_SSID_t *)(pBuf))->hdr[0] = DOT11_SSID_ELE_ID;
    275 	((dot11_SSID_t *)(pBuf))->hdr[1] = pSsid->len;
    276 	os_memoryCopy(pSiteMgr->hOs, pBuf + sizeof(dot11_eleHdr_t), (void *)pSsid->str, pSsid->len);
    277 	size += sizeof(dot11_eleHdr_t) + pSsid->len;
    278 	pBuf += sizeof(dot11_eleHdr_t) + pSsid->len;
    279 
    280 	/* Rates */
    281 	pDot11Rates = (dot11_RATES_t *) pBuf;
    282 
    283     /*
    284      * Supported rates in probe request will always use the default rates for BG or A bands,
    285      * regardless of the STA desired rates.
    286      */
    287     if (radioBand == RADIO_BAND_2_4_GHZ)
    288 	{
    289         /* Basic rates: 1,2,5.5,11 */
    290 		basicRateMask = rate_BasicToDrvBitmap((EBasicRateSet)(pSiteMgr->pDesiredParams->siteMgrRegstryBasicRate[DOT11_G_MODE]), TI_FALSE);
    291         /* Extended: 6,9,12,18,24,36,48,54 */
    292         supportedRateMask = rate_SupportedToDrvBitmap((ESupportedRateSet)(pSiteMgr->pDesiredParams->siteMgrRegstrySuppRate[DOT11_G_MODE]), TI_FALSE);
    293     }
    294     else if (radioBand == RADIO_BAND_5_0_GHZ)
    295     {   /* Basic rates: 6,12,24 */
    296         basicRateMask = rate_BasicToDrvBitmap((EBasicRateSet)(pSiteMgr->pDesiredParams->siteMgrRegstryBasicRate[DOT11_A_MODE]), TI_TRUE);
    297          /* Extended: 9,18,24,36,48,54 */
    298         supportedRateMask = rate_SupportedToDrvBitmap((ESupportedRateSet)(pSiteMgr->pDesiredParams->siteMgrRegstrySuppRate[DOT11_A_MODE]), TI_TRUE);
    299 	}
    300 	else
    301 	{
    302         TRACE1(pSiteMgr->hReport, REPORT_SEVERITY_ERROR, "buildProbeReqTemplate, radioBand =%d ???\n",radioBand);
    303         /* Use default and pray for the best */
    304         /* Basic rates: 1,2,5.5,11 */
    305         basicRateMask = rate_BasicToDrvBitmap(BASIC_RATE_SET_1_2_5_5_11, TI_FALSE);
    306         /* Extended: 6,9,12,18,24,36,48,54 */
    307         supportedRateMask = rate_SupportedToDrvBitmap(SUPPORTED_RATE_SET_UP_TO_54, TI_FALSE);
    308 	}
    309 
    310 	rate_DrvBitmapToNetStr (supportedRateMask, basicRateMask, ratesBuf, &len, &ofdmIndex);
    311 
    312     TRACE5(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "buildProbeReqTemplate, supportedRateMask=0x%x, basicRateMask=0x%x, len=%d, ofdmIndex=%d, radioBand =%d\n",							 supportedRateMask,basicRateMask,len, ofdmIndex, radioBand);
    313 
    314     /* It looks like it never happens. Anyway decided to check */
    315     if ( len > DOT11_MAX_SUPPORTED_RATES )
    316     {
    317         TRACE2( pSiteMgr->hReport, REPORT_SEVERITY_ERROR,
    318            "buildProbeReqTemplate. len=%d exceeds the limit %d\n",
    319                len, DOT11_MAX_SUPPORTED_RATES);
    320         handleRunProblem(PROBLEM_BUF_SIZE_VIOLATION);
    321         return TI_NOK;
    322     }
    323     if(radioBand == RADIO_BAND_5_0_GHZ ||
    324        pSiteMgr->pDesiredParams->siteMgrUseDraftNum == DRAFT_5_AND_EARLIER ||
    325 	   ofdmIndex == len)
    326 	{
    327 		pDot11Rates->hdr[0] = DOT11_SUPPORTED_RATES_ELE_ID;
    328 		pDot11Rates->hdr[1] = len;
    329 		os_memoryCopy(pSiteMgr->hOs, (void *)pDot11Rates->rates, ratesBuf, pDot11Rates->hdr[1]);
    330 		size += pDot11Rates->hdr[1] + sizeof(dot11_eleHdr_t);
    331 		pBuf += pDot11Rates->hdr[1] + sizeof(dot11_eleHdr_t);
    332 	}
    333 	else
    334 	{
    335 		pDot11Rates->hdr[0] = DOT11_SUPPORTED_RATES_ELE_ID;
    336 		pDot11Rates->hdr[1] = ofdmIndex;
    337 		os_memoryCopy(pSiteMgr->hOs, (void *)pDot11Rates->rates, ratesBuf, pDot11Rates->hdr[1]);
    338 		suppRatesLen = pDot11Rates->hdr[1] + sizeof(dot11_eleHdr_t);
    339 		pDot11Rates = (dot11_RATES_t *) (pBuf + suppRatesLen);
    340 		pDot11Rates->hdr[0] = DOT11_EXT_SUPPORTED_RATES_ELE_ID;
    341 		pDot11Rates->hdr[1] = len - ofdmIndex;
    342 		os_memoryCopy(pSiteMgr->hOs, (void *)pDot11Rates->rates, &ratesBuf[ofdmIndex], pDot11Rates->hdr[1]);
    343 		extSuppRatesLen = pDot11Rates->hdr[1] + sizeof(dot11_eleHdr_t);
    344 		size += suppRatesLen + extSuppRatesLen;
    345 		pBuf += suppRatesLen + extSuppRatesLen;
    346 	}
    347 
    348 
    349     /* add HT capabilities IE */
    350     StaCap_GetHtCapabilitiesIe (pSiteMgr->hStaCap, (TI_UINT8 *)pBuf, &len);
    351     size += len;
    352     pBuf += len;
    353 
    354     /* WiFi Simple Config */
    355     if (pSiteMgr->includeWSCinProbeReq && (pSiteMgr->siteMgrWSCCurrMode != TIWLN_SIMPLE_CONFIG_OFF))
    356     {
    357         ((dot11_WSC_t *)pBuf)->hdr[0] = DOT11_WSC_PARAM_ELE_ID;
    358         ((dot11_WSC_t *)pBuf)->hdr[1] = pSiteMgr->uWscIeSize + DOT11_OUI_LEN;
    359         pBuf += sizeof(dot11_eleHdr_t);
    360         os_memoryCopy(pSiteMgr->hOs, pBuf, &WSCOuiIe, DOT11_OUI_LEN);
    361         os_memoryCopy(pSiteMgr->hOs,
    362                       pBuf + DOT11_OUI_LEN,
    363                       &pSiteMgr->siteMgrWSCProbeReqParams,
    364                       pSiteMgr->uWscIeSize);
    365         size += sizeof(dot11_eleHdr_t) + pSiteMgr->uWscIeSize + DOT11_OUI_LEN;
    366         pBuf += sizeof(dot11_eleHdr_t) + pSiteMgr->uWscIeSize + DOT11_OUI_LEN;
    367     }
    368 
    369 	pTemplate->len = size;
    370 
    371 	return TI_OK;
    372 }
    373 
    374 /************************************************************************
    375  *                        buildProbeRspTemplate							*
    376  ************************************************************************
    377 DESCRIPTION: This function build a probe response template to set to the HAL
    378 				when joining an IBSS network.
    379 				performs the following:
    380 				-	Build a template & set the template len, the template type is set in the site mgr
    381 				-	The template is built based on the chosen site attributes
    382 
    383 			NOTE: This function is used to build beacon template too.
    384 			The site manager set the template type (after thos function returns) to beacon or probe response accordingly.
    385 
    386 INPUT:      pSiteMgr	-	Handle to site manager
    387 			pTemplate	-	Pointer to the template structure
    388 
    389 
    390 OUTPUT:
    391 
    392 
    393 RETURN:     TI_OK
    394 
    395 ************************************************************************/
    396 TI_STATUS buildProbeRspTemplate(siteMgr_t *pSiteMgr, TSetTemplate *pTemplate)
    397 {
    398 	paramInfo_t			param;
    399 	TI_UINT8			*pBuf;
    400 	probeRspTemplate_t	*pBuffer = (probeRspTemplate_t	*)pTemplate->ptr;
    401 	siteEntry_t			*pPrimarySite = pSiteMgr->pSitesMgmtParams->pPrimarySite;
    402 	TI_INT32			i, j;
    403 	TI_UINT32			size;
    404 	dot11_RATES_t		*pDot11Rates;
    405 	dot11_ERP_t         *pdot11Erp;
    406 	TI_UINT32			len = 0, ofdmIndex = 0;
    407 	TI_BOOL				extRates = TI_FALSE;
    408 	TI_BOOL             useProtection,NonErpPresent,barkerPreambleType;
    409 	TCountry			*pCountry = NULL;
    410 	TI_UINT8			ratesBuf[DOT11_MAX_SUPPORTED_RATES];
    411 	TI_UINT32			supportedRateMask,basicRateMask;
    412 	TI_UINT16			headerFC = DOT11_FC_PROBE_RESP;
    413 
    414 	os_memoryZero(pSiteMgr->hOs, pBuffer, sizeof(probeRspTemplate_t));
    415 
    416 
    417 	/*
    418 	 * Build WLAN Header:
    419 	 * ==================
    420 	 */
    421 
    422 	/* Set destination address */
    423 	for (i = 0; i < MAC_ADDR_LEN; i++)
    424 		pBuffer->hdr.DA[i] = 0xFF;
    425 
    426 	/* Set BSSID address */
    427 	MAC_COPY (pBuffer->hdr.BSSID, pPrimarySite->bssid);
    428 
    429 	/* Build Source address */
    430 	param.paramType = CTRL_DATA_MAC_ADDRESS;
    431 	ctrlData_getParam(pSiteMgr->hCtrlData, &param);
    432 	MAC_COPY (pBuffer->hdr.SA, param.content.ctrlDataDeviceMacAddress);
    433 
    434     COPY_WLAN_WORD(&pBuffer->hdr.fc, &headerFC);
    435 
    436 	size = sizeof(dot11_mgmtHeader_t);
    437 	pBuf = (TI_UINT8 *)pBuffer->timeStamp;
    438    /*
    439 	* Fixed Fields
    440 	*/
    441 	/* we skip the timestamp field */
    442 	size += TIME_STAMP_LEN;
    443 	pBuf += TIME_STAMP_LEN;
    444 
    445 	/* Beacon interval */
    446     COPY_WLAN_WORD(pBuf, &pPrimarySite->beaconInterval);
    447 	size += FIX_FIELD_LEN;
    448 	pBuf += FIX_FIELD_LEN;
    449 
    450 	/* capabilities */
    451     COPY_WLAN_WORD(pBuf, &pPrimarySite->capabilities);
    452 	size += FIX_FIELD_LEN;
    453 	pBuf += FIX_FIELD_LEN;
    454 
    455 	/*
    456 	 * Build Informataion Elements:
    457 	 * ============================
    458 	 */
    459 
    460 	/* SSID IE */
    461     /* It looks like it never happens. Anyway decided to check */
    462     if ( pPrimarySite->ssid.len > MAX_SSID_LEN )
    463     {
    464         TRACE2( pSiteMgr->hReport, REPORT_SEVERITY_ERROR,
    465                "buildProbeRspTemplate. pPrimarySite->ssid.len=%d exceeds the limit %d\n",
    466                pPrimarySite->ssid.len, MAX_SSID_LEN);
    467         handleRunProblem(PROBLEM_BUF_SIZE_VIOLATION);
    468         return TI_NOK;
    469     }
    470 	((dot11_SSID_t *)(pBuf))->hdr[0] = DOT11_SSID_ELE_ID;
    471 	((dot11_SSID_t *)(pBuf))->hdr[1] = pPrimarySite->ssid.len;
    472 	os_memoryCopy(pSiteMgr->hOs, pBuf + sizeof(dot11_eleHdr_t), (void *)pPrimarySite->ssid.str, pPrimarySite->ssid.len);
    473 	size += sizeof(dot11_eleHdr_t) + pPrimarySite->ssid.len;
    474 	pBuf += sizeof(dot11_eleHdr_t) + pPrimarySite->ssid.len;
    475 
    476 
    477 	/* Rates IE */
    478 
    479 	pDot11Rates = (dot11_RATES_t *) pBuf;
    480 
    481 	if (pPrimarySite->channel == SPECIAL_BG_CHANNEL)
    482 	{
    483 		supportedRateMask = rate_GetDrvBitmapForDefaultSupporteSet ();
    484 		basicRateMask	  = rate_GetDrvBitmapForDefaultBasicSet ();
    485 	}
    486 	else
    487 	{
    488 		supportedRateMask = pSiteMgr->pDesiredParams->siteMgrMatchedSuppRateMask;
    489 		basicRateMask     = pSiteMgr->pDesiredParams->siteMgrMatchedBasicRateMask;
    490 	}
    491 
    492 	rate_DrvBitmapToNetStr (supportedRateMask, basicRateMask, ratesBuf, &len, &ofdmIndex);
    493 
    494     if(pSiteMgr->siteMgrOperationalMode != DOT11_G_MODE ||
    495        pSiteMgr->pDesiredParams->siteMgrUseDraftNum == DRAFT_5_AND_EARLIER ||
    496 	   ofdmIndex == len)
    497 	{
    498 		pDot11Rates->hdr[0] = DOT11_SUPPORTED_RATES_ELE_ID;
    499 		pDot11Rates->hdr[1] = len;
    500 		os_memoryCopy(pSiteMgr->hOs, (void *)pDot11Rates->rates, ratesBuf, pDot11Rates->hdr[1]);
    501 		size += pDot11Rates->hdr[1] + sizeof(dot11_eleHdr_t);
    502 		pBuf += pDot11Rates->hdr[1] + sizeof(dot11_eleHdr_t);
    503 	}
    504 	else
    505 	{
    506 		pDot11Rates->hdr[0] = DOT11_SUPPORTED_RATES_ELE_ID;
    507 		pDot11Rates->hdr[1] = ofdmIndex;
    508 		os_memoryCopy(pSiteMgr->hOs, (void *)pDot11Rates->rates, ratesBuf, pDot11Rates->hdr[1]);
    509 		size += pDot11Rates->hdr[1] + sizeof(dot11_eleHdr_t);
    510 		pBuf += pDot11Rates->hdr[1] + sizeof(dot11_eleHdr_t);
    511 		extRates = TI_TRUE;
    512 	}
    513 
    514 	/* DS IE */
    515 	((dot11_DS_PARAMS_t *)(pBuf))->hdr[0] = DOT11_DS_PARAMS_ELE_ID;
    516 	((dot11_DS_PARAMS_t *)(pBuf))->hdr[1] = DOT11_DS_PARAMS_ELE_LEN;
    517 	((dot11_DS_PARAMS_t *)(pBuf))->currChannel = pPrimarySite->channel;
    518 	size += sizeof(dot11_eleHdr_t) + DOT11_DS_PARAMS_ELE_LEN;
    519 	pBuf += sizeof(dot11_eleHdr_t) + DOT11_DS_PARAMS_ELE_LEN;
    520 
    521 	/* IBSS IE */
    522 	((dot11_IBSS_PARAMS_t *)(pBuf))->hdr[0] = DOT11_IBSS_PARAMS_ELE_ID;
    523 	((dot11_IBSS_PARAMS_t *)(pBuf))->hdr[1] = DOT11_IBSS_PARAMS_ELE_LEN;
    524 	COPY_WLAN_WORD(&((dot11_IBSS_PARAMS_t *)(pBuf))->atimWindow, &pPrimarySite->atimWindow);
    525 	size += sizeof(dot11_eleHdr_t) + DOT11_IBSS_PARAMS_ELE_LEN;
    526 	pBuf += sizeof(dot11_eleHdr_t) + DOT11_IBSS_PARAMS_ELE_LEN;
    527 
    528 	/* Country IE */
    529 	param.paramType = REGULATORY_DOMAIN_ENABLED_PARAM;
    530 	regulatoryDomain_getParam(pSiteMgr->hRegulatoryDomain,&param);
    531 
    532 	if(	param.content.regulatoryDomainEnabled == TI_TRUE )
    533 	{
    534         /* get country IE */
    535         param.paramType = REGULATORY_DOMAIN_COUNTRY_PARAM;
    536 		regulatoryDomain_getParam(pSiteMgr->hRegulatoryDomain, &param);
    537 		pCountry = param.content.pCountry;
    538 
    539         /* Check if a country IE was found */
    540 		if(pCountry != NULL)
    541 		{
    542 			*pBuf = DOT11_COUNTRY_ELE_ID;
    543 			pBuf++;
    544 			size++;
    545 			*pBuf = (TI_UINT8)(pCountry->len);
    546 			pBuf++;
    547 			size++;
    548 
    549 			/* Note: The country structure is not byte-aligned so it is copied as follows to ensure
    550 			           that there are no gaps in the output structure (pBuf). */
    551 
    552 			os_memoryCopy(pSiteMgr->hOs, pBuf , &pCountry->countryIE.CountryString, DOT11_COUNTRY_STRING_LEN);
    553 			pBuf += DOT11_COUNTRY_STRING_LEN;
    554 			size += DOT11_COUNTRY_STRING_LEN;
    555 
    556 			/* Loop on all tripletChannels. Each item has three fields ('i' counts rows and 'j' counts bytes). */
    557 			for (i = 0, j = 0;  j < (pCountry->len - DOT11_COUNTRY_STRING_LEN);  i++, j+=3)
    558 			{
    559 				*(pBuf + j    ) = pCountry->countryIE.tripletChannels[i].firstChannelNumber;
    560 				*(pBuf + j + 1) = pCountry->countryIE.tripletChannels[i].maxTxPowerLevel;
    561 				*(pBuf + j + 2) = pCountry->countryIE.tripletChannels[i].numberOfChannels;
    562 			}
    563 
    564 			pBuf += (pCountry->len - DOT11_COUNTRY_STRING_LEN);
    565 			size += (pCountry->len - DOT11_COUNTRY_STRING_LEN);
    566 		}
    567 	}
    568 
    569 	/*ERP IE*/
    570 	siteMgr_IsERP_Needed(pSiteMgr,&useProtection,&NonErpPresent,&barkerPreambleType);
    571 	if (useProtection || NonErpPresent || barkerPreambleType)
    572 	{
    573 		pdot11Erp = (dot11_ERP_t *) pBuf;
    574 		pdot11Erp->hdr[0] = DOT11_ERP_IE_ID;
    575 		pdot11Erp->hdr[1] = 1;
    576 		pdot11Erp->ctrl = 0;
    577 		if (NonErpPresent)
    578 			pdot11Erp->ctrl |= ERP_IE_NON_ERP_PRESENT_MASK;
    579 		if (useProtection)
    580 			pdot11Erp->ctrl |= ERP_IE_USE_PROTECTION_MASK;
    581 		if (barkerPreambleType)
    582 			pdot11Erp->ctrl |= ERP_IE_BARKER_PREAMBLE_MODE_MASK;
    583 		size += pdot11Erp->hdr[1] + sizeof(dot11_eleHdr_t);
    584 		pBuf += pdot11Erp->hdr[1] + sizeof(dot11_eleHdr_t);
    585 
    586 	}
    587 
    588 
    589 	/* Extended supported rates IE */
    590 	if(extRates)
    591 	{
    592 		pDot11Rates = (dot11_RATES_t *) pBuf;
    593 		pDot11Rates->hdr[0] = DOT11_EXT_SUPPORTED_RATES_ELE_ID;
    594 		pDot11Rates->hdr[1] = len - ofdmIndex;
    595 		os_memoryCopy(pSiteMgr->hOs, (void *)pDot11Rates->rates, &ratesBuf[ofdmIndex], pDot11Rates->hdr[1]);
    596 		size += pDot11Rates->hdr[1] + sizeof(dot11_eleHdr_t);
    597 		pBuf += pDot11Rates->hdr[1] + sizeof(dot11_eleHdr_t);
    598 	}
    599 
    600     /* no need to insert RSN information elements */
    601 
    602 	pTemplate->len = size;
    603 TRACE1(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "Probe response template len = %d\n",size);
    604 
    605 	return TI_OK;
    606 }
    607 
    608 /************************************************************************
    609  *                        buildPsPollTemplate							*
    610  ************************************************************************
    611 DESCRIPTION: This function build a ps poll template
    612 				performs the following:
    613 				-	Build a template & set the template len, the template type is set in the site mgr
    614 
    615 INPUT:      pSiteMgr	-	Handle to site manager
    616 			pTemplate	-	Pointer to the template structure
    617 			pSsid		-	Desired SSID
    618 
    619 OUTPUT:
    620 
    621 RETURN:     TI_OK
    622 ************************************************************************/
    623 TI_STATUS buildPsPollTemplate(siteMgr_t *pSiteMgr, TSetTemplate *pTemplate)
    624 {
    625     paramInfo_t			param;
    626     TTwdParamInfo       tTwdParam;
    627 	TI_UINT32				size;
    628 	psPollTemplate_t	*pBuffer = (psPollTemplate_t *)pTemplate->ptr;
    629 	siteEntry_t			*pPrimarySite = pSiteMgr->pSitesMgmtParams->pPrimarySite;
    630 	TI_UINT16				fc;
    631 
    632 	os_memoryZero(pSiteMgr->hOs, pBuffer, sizeof(psPollTemplate_t));
    633 
    634 	/*
    635 	 * Header First
    636 	 */
    637 
    638 	/* Set BSSID address */
    639 	MAC_COPY (pBuffer->hdr.BSSID, pPrimarySite->bssid);
    640 
    641 	/* Build Source address */
    642 	param.paramType = CTRL_DATA_MAC_ADDRESS;
    643 	ctrlData_getParam(pSiteMgr->hCtrlData, &param);
    644 	MAC_COPY (pBuffer->hdr.TA, param.content.ctrlDataDeviceMacAddress);
    645 
    646     /*
    647     **   Building the Frame Control word (16 bits)
    648     ** ---------------------------------------------
    649     ** Type = Control
    650     ** SubType = Power Save (PS) POLL,  */
    651     fc = DOT11_FC_PS_POLL;
    652     /*
    653     ** setting the Power Management bit in the Frame control field
    654     ** to be "Power Save mode"
    655     */
    656     fc |= (0x1 << DOT11_FC_PWR_MGMT_SHIFT);
    657 
    658 	COPY_WLAN_WORD(&pBuffer->hdr.fc, &fc); /* copy with endianess handling. */
    659 
    660     /*
    661     **   Association ID
    662     ** -----------------
    663     */
    664     tTwdParam.paramType = TWD_AID_PARAM_ID;
    665     TWD_GetParam (pSiteMgr->hTWD, &tTwdParam);
    666 
    667     /* AID should have its two MSB bit Set to "1"*/
    668     pBuffer->hdr.AID = tTwdParam.content.halCtrlAid | 0xC000;
    669 
    670 	size = sizeof(dot11_PsPollFrameHeader_t);
    671 
    672 	pTemplate->len = size;
    673 
    674 	return TI_OK;
    675 }
    676 
    677 
    678 /************************************************************************
    679  *                        buildQosNullDataTemplate							*
    680  ************************************************************************
    681 DESCRIPTION: This function build a qos null data template
    682 				performs the following:
    683 				-	Build a template & set the template len, the template type is set in the site mgr
    684 
    685 INPUT:      pSiteMgr	-	Handle to site manager
    686 			pTemplate	-	Pointer to the template structure
    687 			pSsid		-	Desired SSID
    688 
    689 OUTPUT:
    690 
    691 RETURN:     TI_OK
    692 ************************************************************************/
    693 TI_STATUS buildQosNullDataTemplate(siteMgr_t *pSiteMgr, TSetTemplate *pTemplate, TI_UINT8 userPriority)
    694 {
    695 	paramInfo_t			param;
    696 	TI_UINT32				size;
    697 	QosNullDataTemplate_t	*pBuffer = (QosNullDataTemplate_t	*)pTemplate->ptr;
    698 	siteEntry_t			*pPrimarySite = pSiteMgr->pSitesMgmtParams->pPrimarySite;
    699 	TI_UINT16				fc;
    700 	TI_UINT16				qosControl;
    701 
    702 	os_memoryZero(pSiteMgr->hOs, pBuffer, sizeof(QosNullDataTemplate_t));
    703 
    704 	/*
    705 	 * Header First
    706 	 */
    707 	/* Set destination address */
    708     if (pPrimarySite)
    709     {
    710 	  MAC_COPY (pBuffer->hdr.address1, pPrimarySite->bssid);
    711 
    712 	  /* Set BSSID address */
    713 	  MAC_COPY (pBuffer->hdr.address3, pPrimarySite->bssid);
    714     }
    715     else
    716     {
    717 TRACE0(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "No Primary site so cannot fill QosNullData template\n");
    718     }
    719 
    720 	/* Build Source address */
    721 	param.paramType = CTRL_DATA_MAC_ADDRESS;
    722 	ctrlData_getParam(pSiteMgr->hCtrlData, &param);
    723 	MAC_COPY (pBuffer->hdr.address2, param.content.ctrlDataDeviceMacAddress);
    724 
    725 	fc = DOT11_FC_DATA_NULL_QOS | (1 << DOT11_FC_TO_DS_SHIFT);
    726 	COPY_WLAN_WORD(&pBuffer->hdr.fc, &fc); /* copy with endianess handling. */
    727 
    728     qosControl = (TI_UINT16)userPriority;
    729 	qosControl <<= QOS_CONTROL_UP_SHIFT;
    730 	COPY_WLAN_WORD(&pBuffer->hdr.qosControl, &qosControl); /* copy with endianess handling. */
    731 
    732 	size = WLAN_QOS_HDR_LEN;
    733 
    734 	pTemplate->len = size;
    735 
    736 	return TI_OK;
    737 }
    738 
    739 
    740 /************************************************************************
    741  *                        buildArpRspTemplate							*
    742  ************************************************************************
    743 DESCRIPTION: This function builds an ARP Response template to set to
    744 			 the HAL when joining an infrastructure network.
    745 
    746              The function's steps:
    747              - It builds the template & set the template len.
    748              - If QoS is inactive, it discards the QoS Control Field.
    749              ** The template type is set in the site mgr.
    750 
    751 INPUT:       pSiteMgr  - Handle to site manager.
    752 			 pTemplate - Pointer to the template structure.
    753 
    754 
    755 OUTPUT:
    756 
    757 
    758 RETURN:     TI_OK
    759 
    760 ************************************************************************/
    761 TI_STATUS buildArpRspTemplate(siteMgr_t *pSiteMgr, TSetTemplate *pTemplate, TIpAddr staIp)
    762 {
    763 	siteEntry_t		   *pPrimarySite = pSiteMgr->pSitesMgmtParams->pPrimarySite;
    764 	ArpRspTemplate_t   *pBuffer      = (ArpRspTemplate_t *)pTemplate->ptr;
    765 	TI_UINT8           *ptr          = (TI_UINT8 *)pBuffer;
    766 
    767 	paramInfo_t         param;          /* To get Site and QoS params */
    768 	TI_UINT16           fc;             /* Frame Control field in MAC header */
    769 	TI_UINT16           macAddrItr;
    770 	TI_BOOL   			privacyInvoked;
    771 	TI_UINT8  			encryptionFieldSize, copyPayloadOffset, lenToCopy;
    772 
    773 
    774 
    775 	/* Reset the buffer */
    776 	os_memoryZero(pSiteMgr->hOs, pBuffer, sizeof(ArpRspTemplate_t));
    777 
    778 
    779 	/* Turn on the To_DS bit in the Frame Control field */
    780 	fc = (1 << DOT11_FC_TO_DS_SHIFT);
    781 
    782     /* Set MAC header address fields:
    783 		-----------------------------
    784 		Since To_DS is on and From_DS is off the address meaning is as follows:
    785 		Address1 - BSSID
    786 		Address2 - Source Address
    787 		Address3 - Destination Address
    788 		Address4 - Not present */
    789 
    790 	/* - Set BSSID */
    791     if (pPrimarySite)
    792 	{
    793 		MAC_COPY (pBuffer->hdr.address1, pPrimarySite->bssid);
    794 	}
    795 	else
    796 	{
    797 		TRACE0(pSiteMgr->hReport, REPORT_SEVERITY_INFORMATION, "No Primary site so cannot fill QosNullData template.\n");
    798 	}
    799     /* - Set Source Address */
    800     param.paramType = CTRL_DATA_MAC_ADDRESS;
    801     ctrlData_getParam(pSiteMgr->hCtrlData, &param);
    802 	MAC_COPY (pBuffer->hdr.address2, param.content.ctrlDataDeviceMacAddress);
    803 	/* - Set Destination Address: ARP response should be sent with broadcast DA - Set accordingly */
    804 	for (macAddrItr = 0; macAddrItr < MAC_ADDR_LEN; macAddrItr++)
    805     {
    806         pBuffer->hdr.address3[macAddrItr] = 0xFF;
    807     }
    808 
    809     pBuffer->LLC.DSAP    = 0xaa;
    810     pBuffer->LLC.SSAP    = 0xaa;
    811     pBuffer->LLC.Control = 0x03;
    812 
    813 	/* pBuffer->LLC.Control.OUI these 3 bytes are zeroed already */
    814     pBuffer->LLC.Type = WLANTOHS((TI_UINT16)0x806);
    815     pBuffer->hardType = WLANTOHS((TI_UINT16)1);
    816     pBuffer->protType = WLANTOHS((TI_UINT16)0x800);
    817     pBuffer->hardSize = 6;
    818     pBuffer->protSize = 4;
    819     pBuffer->op       = WLANTOHS((TI_UINT16)2); /*filled as for ARP-RSP, not for RARP_RSP */
    820 
    821 	MAC_COPY(pBuffer->StaMac, pBuffer->hdr.address2);
    822     IP_COPY(pBuffer->StaIp, staIp);
    823 
    824     pTemplate->len = sizeof(ArpRspTemplate_t);
    825 
    826 
    827 	/* Get encryption status */
    828     txCtrlParams_getCurrentEncryptionInfo (pSiteMgr->hTxCtrl,  &privacyInvoked, &encryptionFieldSize);
    829 
    830     /* If no encryption is used, encryptionFieldSize has garbage value */
    831     encryptionFieldSize = privacyInvoked ? encryptionFieldSize : 0;
    832 
    833 	/* Set the subtype field of fc with WEP_BIT */
    834 	fc |= (privacyInvoked << DOT11_FC_WEP_SHIFT);
    835 
    836 
    837     /* Get QoS type to check if QoS is active */
    838     param.paramType = QOS_MNGR_ACTIVE_PROTOCOL;
    839     qosMngr_getParams(pSiteMgr->hQosMngr, &param);
    840 
    841 
    842     if(param.content.qosSiteProtocol == QOS_NONE)   /* QoS is not active */
    843     {
    844 		copyPayloadOffset = sizeof(pBuffer->hdr.qosControl) + AES_AFTER_HEADER_FIELD_SIZE - encryptionFieldSize;
    845         /* Set the subtype field of fc with DATA value (non Qos) */
    846         fc |= DOT11_FC_DATA;
    847     }
    848     else    /* QoS is active */
    849     {
    850 		copyPayloadOffset = AES_AFTER_HEADER_FIELD_SIZE - encryptionFieldSize;
    851         /* Set the subtype field of fc with DATA_QOS */
    852         fc |= DOT11_FC_DATA_QOS;
    853     }
    854 
    855 
    856     /* Need to copy backward to overwrite security or QoS offset */
    857     if (copyPayloadOffset > 0)
    858     {
    859 		ptr = (TI_UINT8 *)&pBuffer->LLC.DSAP;
    860         /* Copy back the actual payload without header & security */
    861         lenToCopy = sizeof(ArpRspTemplate_t) - sizeof(dot11_header_t) - AES_AFTER_HEADER_FIELD_SIZE;
    862 
    863         os_memoryCopy(pSiteMgr->hOs, ptr - copyPayloadOffset, ptr, lenToCopy);
    864         pTemplate->len -= copyPayloadOffset;
    865     }
    866 
    867 
    868     COPY_WLAN_WORD(&pBuffer->hdr.fc, &fc); /* copy with endianess handling. */
    869 
    870 	return TI_OK;
    871 }
    872 
    873 
    874 
    875 
    876