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