Ejemplo n.º 1
0
/* 
	==========================================================================
	Description:
		This routine is called at initialization. It returns a channel number
		that complies to regulation domain and less interference with current
		enviornment.
	Return:
		ch -  channel number that
	NOTE:
		The retruned channel number is guaranteed to comply to current regulation
		domain that recorded in pAd->CommonCfg.CountryRegion
        Usage: 
               1.) iwpriv ra0 set AutoChannelSel=1
                   Ues the number of AP and inference status to choose
               2.) iwpriv ra0 set AutoChannelSel=2
                   Ues the False CCA count and Rssi to choose
	==========================================================================
 */
UCHAR APAutoSelectChannel(
	IN PRTMP_ADAPTER pAd,
	IN ChannelSel_Alg Alg)
{
	UCHAR ch = 0, i;

	/* passive scan channel 1-14. collect statistics */
	
	/*
		In the autochannel select case. AP didn't get channel yet.
		So have no way to determine which Band AP used by channel number.
	*/

	/* Init some structures before doing AutoChannelSelect() */
	APAutoChannelInit(pAd);

	if (( Alg == ChannelAlgRandom ) && (pAd->pChannelInfo->IsABand == TRUE))
	{   /*for Dfs */
		ch = SelectClearChannelRandom(pAd);
	}
	else
	{
#ifdef MICROWAVE_OVEN_SUPPORT
		pAd->CommonCfg.MO_Cfg.bEnable = FALSE;
		AsicMeasureFalseCCA(pAd);
#endif
		/*find RSSI in each channel */
		for (i=0; i<pAd->ChannelListNum; i++)
		{

			AsicSwitchChannel(pAd, pAd->ChannelList[i].Channel, TRUE);
			AsicLockChannel(pAd, pAd->ChannelList[i].Channel);/*do nothing */
			pAd->ApCfg.current_channel_index = i;


			pAd->ApCfg.AutoChannel_Channel = pAd->ChannelList[i].Channel;
			
#ifdef AP_QLOAD_SUPPORT
			if (QLOAD_DOES_ALARM_OCCUR(pAd))
			{   /* QLOAD ALARM, ever alarm from QLOAD module */
				OS_WAIT(400); /* wait for 400 ms at each channel. */
			}
			else
#endif /* AP_QLOAD_SUPPORT */
			{
				OS_WAIT(200); /* wait for 200 ms at each channel. */
			}

			UpdateChannelInfo(pAd, i,Alg);
		}

		ch = SelectBestChannel(pAd, Alg);
	}
		
	return ch;
}
Ejemplo n.º 2
0
/* 
	==========================================================================
	Description:
		This routine is called at initialization. It returns a channel number
		that complies to regulation domain and less interference with current
		enviornment.
	Return:
		ch -  channel number that
	NOTE:
		The retruned channel number is guaranteed to comply to current regulation
		domain that recorded in pAd->CommonCfg.CountryRegion
        Usage: 
               1.) iwpriv ra0 set AutoChannelSel=1
                   Ues the number of AP and inference status to choose
               2.) iwpriv ra0 set AutoChannelSel=2
                   Ues the False CCA count and Rssi to choose
	==========================================================================
 */
UCHAR APAutoSelectChannel(
	IN PRTMP_ADAPTER pAd,
	IN ChannelSel_Alg Alg)
{
	UCHAR ch = 0, i;

	// passive scan channel 1-14. collect statistics
	
	// In the autochannel select case. AP didn't get channel yet.
	// So have no way to determine which Band AP used by channel number.

	//
	// Init some structures before doing AutoChannelSelect()
	//
	APAutoChannelInit(pAd);

	if (( Alg == ChannelAlgRandom ) && (pAd->pChannelInfo->IsABand == TRUE))
	{   //for Dfs
		ch = SelectClearChannelRandom(pAd);
	}
	else
	{

		//find RSSI in each channel //
		for (i=0; i<pAd->ChannelListNum; i++)
		{

			AsicSwitchChannel(pAd, pAd->ChannelList[i].Channel, TRUE);
			AsicLockChannel(pAd, pAd->ChannelList[i].Channel);//do nothing
			pAd->ApCfg.current_channel_index = i;


			pAd->ApCfg.AutoChannel_Channel = pAd->ChannelList[i].Channel;
			
#ifdef AP_QLOAD_SUPPORT
			if (QLOAD_DOES_ALARM_OCCUR(pAd))
			{   /* QLOAD ALARM, ever alarm from QLOAD module */
				OS_WAIT(400); // wait for 400 ms at each channel.
			}
			else
#endif
			{
				OS_WAIT(200); // wait for 200 ms at each channel.
			}

			UpdateChannelInfo(pAd, i,Alg);
		}

		ch = SelectBestChannel(pAd, Alg);
	}
		
	return ch;
}
Ejemplo n.º 3
0
*/	REBINT Wait_Ports(REBSER *ports, REBCNT timeout, REBINT only)
/*
**	Inputs:
**		Ports: a block of ports or zero (on stack to avoid GC).
**		Timeout: milliseconds to wait
**
**	Returns:
**		TRUE when port action happened, or FALSE for timeout.
**
***********************************************************************/
{
	REBI64 base = OS_DELTA_TIME(0, 0);
	REBCNT time;
	REBINT result;
	REBCNT wt = 1;
	REBCNT res = (timeout >= 1000) ? 0 : 16;  // OS dependent?

	while (wt) {
		if (GET_SIGNAL(SIG_ESCAPE)) {
			CLR_SIGNAL(SIG_ESCAPE);
			raise Error_Is(TASK_HALT_ERROR);
		}

		// Process any waiting events:
		if ((result = Awake_System(ports, only)) > 0) return TRUE;

		// If activity, use low wait time, otherwise increase it:
		if (result == 0) wt = 1;
		else {
			wt *= 2;
			if (wt > MAX_WAIT_MS) wt = MAX_WAIT_MS;
		}

		if (timeout != ALL_BITS) {
			// Figure out how long that (and OS_WAIT) took:
			time = (REBCNT)(OS_DELTA_TIME(base, 0)/1000);
			if (time >= timeout) break;	  // done (was dt = 0 before)
			else if (wt > timeout - time) // use smaller residual time
				wt = timeout - time;
		}

		//printf("%d %d %d\n", dt, time, timeout);

		// Wait for events or time to expire:
		//Debug_Num("OSW", wt);
		OS_WAIT(wt, res);
	}

	//time = (REBCNT)OS_DELTA_TIME(base, 0);
	//Print("dt: %d", time);

	return FALSE; // timeout
}
Ejemplo n.º 4
0
/* 
	==========================================================================
	Description:
		This routine is called at initialization. It returns a channel number
		that complies to regulation domain and less interference with current
		enviornment.
	Return:
		ch -  channel number that
	NOTE:
		The retruned channel number is guaranteed to comply to current regulation
		domain that recorded in pAd->CommonCfg.CountryRegion
        Usage: 
               1.) iwpriv ra0 set AutoChannelSel=1
                   Ues the number of AP and inference status to choose
               2.) iwpriv ra0 set AutoChannelSel=2
                   Ues the False CCA count and Rssi to choose
	==========================================================================
 */
UCHAR APAutoSelectChannel(RTMP_ADAPTER *pAd, ChannelSel_Alg Alg)
{
    UCHAR ch = 0;
#ifndef SUPPORT_ACS_BY_SCAN	
	UCHAR i = 0;
#endif
    /* passive scan channel 1-14. collect statistics */
    
    DBGPRINT(RT_DEBUG_TRACE, ("Entering ACS (Alg=%d)...\n", Alg));
    /*
        In the autochannel select case. AP didn't get channel yet.
        So have no way to determine which Band AP used by channel number.
    */
    /* Init some structures before doing AutoChannelSelect() */
    APAutoChannelInit(pAd);

    if (( Alg == ChannelAlgRandom ) && (pAd->pChannelInfo->IsABand == TRUE))
    {   /*for Dfs */
        DBGPRINT(RT_DEBUG_TRACE, ("ACS: Select from random\n"));
        ch = SelectClearChannelRandom(pAd);
    }
    else
    {
#ifndef SUPPORT_ACS_BY_SCAN    
        /*find RSSI in each channel */
        DBGPRINT(RT_DEBUG_TRACE, ("Start ACS scan (total channel = %d, stay_time = %dms)\n", pAd->ChannelListNum, AUTO_CHANNEL_SEL_TIMEOUT));
        for (i=0; i<pAd->ChannelListNum; i++)
        {
            AsicSwitchChannel(pAd, pAd->ChannelList[i].Channel, TRUE);
            AsicLockChannel(pAd, pAd->ChannelList[i].Channel); /*do nothing */
            pAd->ApCfg.current_channel_index = i;
            pAd->ApCfg.AutoChannel_Channel = pAd->ChannelList[i].Channel;
            OS_WAIT(AUTO_CHANNEL_SEL_TIMEOUT); /* wait for 200 ms at each channel. */
            UpdateChannelInfo(pAd, i, Alg);
        }        
        DBGPRINT(RT_DEBUG_TRACE, ("ACS scan complete)\n"));
#ifdef SUPPORT_ACS_ALL_CHANNEL_RANK
        if ((ch = ACS_PerformAlgorithm(pAd, Alg)) <= 0)
        {
            /* return ch is the total number of channels in the rank list */
            DBGPRINT(RT_DEBUG_ERROR, ("ACS: Error perform algorithm!\n"));
        }
        else
            DBGPRINT(RT_DEBUG_ERROR, ("ACS: Perform algorithm OK (ch_count=%d)!\n", ch));
#else
        ch = SelectBestChannel(pAd, Alg);
#endif /* SUPPORT_ACS_ALL_CHANNEL_RANK */
#endif /* SUPPORT_ACS_BY_SCAN */
    }

    return ch;

}
Ejemplo n.º 5
0
static INT __devinit   rt2860_probe(
    IN  struct pci_dev              *pci_dev, 
    IN  const struct pci_device_id  *pci_id)
{
	PRTMP_ADAPTER 		pAd = (PRTMP_ADAPTER)NULL;
	struct  net_device		*net_dev;
	PVOID				handle;
	PSTRING				print_name;
	ULONG				csr_addr;
	INT rv = 0;
	RTMP_OS_NETDEV_OP_HOOK	netDevHook;
#ifdef RT30xx
	static UCHAR MemReset=0;
#endif // RT3090 //
	DBGPRINT(RT_DEBUG_TRACE, ("===> rt2860_probe\n"));

//PCIDevInit==============================================
	// wake up and enable device
	if ((rv = pci_enable_device(pci_dev))!= 0)
	{
		DBGPRINT(RT_DEBUG_ERROR, ("Enable PCI device failed, errno=%d!\n", rv));
		return rv;
	}

#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
	print_name = pci_dev ? (PSTRING)pci_name(pci_dev) : "rt2860";
#else
	print_name = pci_dev ? pci_dev->slot_name : "rt2860";
#endif // LINUX_VERSION_CODE //

	if ((rv = pci_request_regions(pci_dev, print_name)) != 0)
	{
		DBGPRINT(RT_DEBUG_ERROR, ("Request PCI resource failed, errno=%d!\n", rv));
		goto err_out;
	}
	
	// map physical address to virtual address for accessing register
	csr_addr = (unsigned long) ioremap(pci_resource_start(pci_dev, 0), pci_resource_len(pci_dev, 0));
	if (!csr_addr)
	{
		DBGPRINT(RT_DEBUG_ERROR, ("ioremap failed for device %s, region 0x%lX @ 0x%lX\n",
					print_name, (ULONG)pci_resource_len(pci_dev, 0), (ULONG)pci_resource_start(pci_dev, 0)));
		goto err_out_free_res;
	}
	else
	{
		DBGPRINT(RT_DEBUG_TRACE, ("%s: at 0x%lx, VA 0x%lx, IRQ %d. \n",  print_name, 
					(ULONG)pci_resource_start(pci_dev, 0), (ULONG)csr_addr, pci_dev->irq));
	}

	// Set DMA master
	pci_set_master(pci_dev);


//RtmpDevInit==============================================
	// Allocate RTMP_ADAPTER adapter structure
	handle = kmalloc(sizeof(struct os_cookie), GFP_KERNEL);
	if (handle == NULL)
	{
		DBGPRINT(RT_DEBUG_ERROR, ("%s(): Allocate memory for os handle failed!\n", __FUNCTION__));
		goto err_out_iounmap;
	}

	memset(handle, 0, sizeof(struct os_cookie));

	((POS_COOKIE)handle)->pci_dev = pci_dev;
	
	rv = RTMPAllocAdapterBlock(handle, &pAd);	//shiang: we may need the pci_dev for allocate structure of "RTMP_ADAPTER"
	if (rv != NDIS_STATUS_SUCCESS) 
		goto err_out_iounmap;
	// Here are the RTMP_ADAPTER structure with pci-bus specific parameters.
	pAd->CSRBaseAddress = (PUCHAR)csr_addr;
	DBGPRINT(RT_DEBUG_ERROR, ("pAd->CSRBaseAddress =0x%lx, csr_addr=0x%lx!\n", (ULONG)pAd->CSRBaseAddress, csr_addr));
#ifdef RT30xx
	if (MemReset==0)
	{
		UINT32 MacCsr0 = 0;
		UCHAR Index = 0;
		BOOLEAN NeedResetChips=FALSE;
		MemReset=1;
		do 
		{
			RTMP_IO_READ32(pAd, MAC_CSR0, &MacCsr0);

			if ((MacCsr0 != 0x00) && (MacCsr0 != 0xFFFFFFFF))
				break;
		
			RTMPusecDelay(10);
		} while (Index++ < 100);
		if (((MacCsr0&0xFFFF0000)==0x3090) ||((MacCsr0&0xFFFF0000)==0x3390))
		{
			if ((MacCsr0&0x0000FFFF) < 0x3213)
			NeedResetChips=TRUE;
		}
		
		if (((MacCsr0&0xFFFF0000)==0x3071) )
		{
			if ((MacCsr0&0x0000FFFF) < 0x21C)
			NeedResetChips=TRUE;
		}
		
		if (NeedResetChips==TRUE)
		{
	  		struct proc_dir_entry *tsarm_proc;
	  		
			RTMP_IO_READ32(pAd, 0x5C0,&MacCsr0);
			MacCsr0|=0x400000;
			RTMP_IO_WRITE32(pAd, 0x5C0,MacCsr0);
			OS_WAIT(1000);
		
	  		/* Send reset PCI device event */
	  		//RTMPSendWirelessEvent(pAd, IW_RESETPCI_EVENT_FLAG, NULL, BSS0, 0);
	  
	  		RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST);
			tsarm_proc = create_proc_entry("TwoM", 0, NULL);
			if (tsarm_proc) {
				tsarm_proc->read_proc = twoPortM_read_proc;
				tsarm_proc->write_proc = twoPortM_write_proc;
			}
	  		goto err_out_free_radev;
		}
	}
#endif // RT3090 //
	RTMPInitPCIeDevice(pci_dev, pAd);
	
//NetDevInit==============================================
	net_dev = RtmpPhyNetDevInit(pAd, &netDevHook);
	if (net_dev == NULL)
		goto err_out_free_radev;
	
	// Here are the net_device structure with pci-bus specific parameters.
	net_dev->irq = pci_dev->irq;		// Interrupt IRQ number
	net_dev->base_addr = csr_addr;		// Save CSR virtual address and irq to device structure
	pci_set_drvdata(pci_dev, net_dev);	// Set driver data
	

//All done, it's time to register the net device to linux kernel.
	// Register this device
#ifdef RT_CFG80211_SUPPORT
	pAd->pCfgDev = &(pci_dev->dev);
	pAd->CFG80211_Register = CFG80211_Register;
#endif // RT_CFG80211_SUPPORT //

	rv = RtmpOSNetDevAttach(net_dev, &netDevHook);
	if (rv)
		goto err_out_free_netdev;


#ifdef KTHREAD_SUPPORT
	init_waitqueue_head(&pAd->cmdQTask.kthread_q);
#ifdef WSC_INCLUDED
	init_waitqueue_head(&pAd->wscTask.kthread_q);
#endif
#endif // KTHREAD_SUPPORT //

	DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2860_probe\n"));

	return 0; // probe ok


	/* --------------------------- ERROR HANDLE --------------------------- */
err_out_free_netdev:
	RtmpOSNetDevFree(net_dev);
	
err_out_free_radev:
	/* free RTMP_ADAPTER strcuture and os_cookie*/
	RTMPFreeAdapter(pAd);

err_out_iounmap:
	iounmap((void *)(csr_addr));
	release_mem_region(pci_resource_start(pci_dev, 0), pci_resource_len(pci_dev, 0)); 
	
err_out_free_res:
	pci_release_regions(pci_dev);
	
err_out:
	pci_disable_device(pci_dev);

	DBGPRINT(RT_DEBUG_ERROR, ("<=== rt2860_probe failed with rv = %d!\n", rv));

	return -ENODEV; /* probe fail */
}
Ejemplo n.º 6
0
BOOLEAN CFG80211DRV_ApKeyAdd(
	VOID                                            *pAdOrg,
	VOID                                            *pData)
{
#ifdef CONFIG_AP_SUPPORT
	PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pAdOrg;
	CMD_RTPRIV_IOCTL_80211_KEY *pKeyInfo;
	MAC_TABLE_ENTRY *pEntry=NULL;
	UINT Wcid = 0;
#ifdef RT_CFG80211_P2P_SUPPORT
	UINT apidx = CFG_GO_BSSID_IDX;
#else
	UINT apidx = MAIN_MBSSID;
#endif /*RT_CFG80211_P2P_SUPPORT*/
	BSS_STRUCT *pMbss = &pAd->ApCfg.MBSSID[apidx];
    struct wifi_dev *pWdev = &pMbss->wdev;
	
	DBGPRINT(RT_DEBUG_TRACE,("%s =====> \n", __FUNCTION__));
	pKeyInfo = (CMD_RTPRIV_IOCTL_80211_KEY *)pData;


	if (pKeyInfo->KeyType == RT_CMD_80211_KEY_WEP40 || pKeyInfo->KeyType == RT_CMD_80211_KEY_WEP104)
	{
		pWdev->WepStatus = Ndis802_11WEPEnabled;
		{
				//UCHAR CipherAlg;
				CIPHER_KEY	*pSharedKey;
				POS_COOKIE pObj;
				
				pObj = (POS_COOKIE) pAd->OS_Cookie;
				
				pSharedKey = &pAd->SharedKey[apidx][pKeyInfo->KeyId];
				pSharedKey->KeyLen = pKeyInfo->KeyLen;
				NdisMoveMemory(pSharedKey->Key, pKeyInfo->KeyBuf, pKeyInfo->KeyLen);


				if (pKeyInfo->KeyType == RT_CMD_80211_KEY_WEP40)
					pAd->SharedKey[apidx][pKeyInfo->KeyId].CipherAlg = CIPHER_WEP64;
				else
					pAd->SharedKey[apidx][pKeyInfo->KeyId].CipherAlg = CIPHER_WEP128;

				AsicAddSharedKeyEntry(pAd, apidx, pKeyInfo->KeyId, pSharedKey);
		}		
	}
	else if(pKeyInfo->KeyType == RT_CMD_80211_KEY_WPA)
	{

	if (pKeyInfo->cipher == Ndis802_11AESEnable)
	{
		/* AES */
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))
        if (pKeyInfo->bPairwise == FALSE )
#else
        if (pKeyInfo->KeyId > 0)
#endif	/* LINUX_VERSION_CODE 2.6.37 */	
		{
			if (pWdev->GroupKeyWepStatus == Ndis802_11Encryption3Enabled)
			{
				DBGPRINT(RT_DEBUG_TRACE, ("CFG: Set AES Security Set. (GROUP) %d\n", pKeyInfo->KeyLen));
				pAd->SharedKey[apidx][pKeyInfo->KeyId].KeyLen= LEN_TK;
				NdisMoveMemory(pAd->SharedKey[apidx][pKeyInfo->KeyId].Key, pKeyInfo->KeyBuf, pKeyInfo->KeyLen);
				
				pAd->SharedKey[apidx][pKeyInfo->KeyId].CipherAlg = CIPHER_AES;

				AsicAddSharedKeyEntry(pAd, apidx, pKeyInfo->KeyId, 
						&pAd->SharedKey[apidx][pKeyInfo->KeyId]);

				GET_GroupKey_WCID(pAd, Wcid, apidx);
				RTMPSetWcidSecurityInfo(pAd, apidx, (UINT8)(pKeyInfo->KeyId), 
				pAd->SharedKey[apidx][pKeyInfo->KeyId].CipherAlg, Wcid, SHAREDKEYTABLE);

#ifdef MT_MAC
                if (pAd->chipCap.hif_type == HIF_MT)
                        CmdProcAddRemoveKey(pAd, 0, apidx, pKeyInfo->KeyId, Wcid, SHAREDKEYTABLE,
                                        	&pAd->SharedKey[apidx][pKeyInfo->KeyId], BROADCAST_ADDR);
#endif /* MT_MAC */
				
			}
		}
		else
		{
			if (pKeyInfo->MAC)
				pEntry = MacTableLookup(pAd, pKeyInfo->MAC);
				
			if(pEntry)
			{
				DBGPRINT(RT_DEBUG_TRACE, ("CFG: Set AES Security Set. (PAIRWISE) %d\n", pKeyInfo->KeyLen));
				pEntry->PairwiseKey.KeyLen = LEN_TK;
				NdisCopyMemory(&pEntry->PTK[OFFSET_OF_PTK_TK], pKeyInfo->KeyBuf, OFFSET_OF_PTK_TK);
				NdisMoveMemory(pEntry->PairwiseKey.Key, &pEntry->PTK[OFFSET_OF_PTK_TK], pKeyInfo->KeyLen);
				pEntry->PairwiseKey.CipherAlg = CIPHER_AES;
				
				AsicAddPairwiseKeyEntry(pAd, (UCHAR)pEntry->Aid, &pEntry->PairwiseKey);
				RTMPSetWcidSecurityInfo(pAd, pEntry->func_tb_idx, (UINT8)(pKeyInfo->KeyId & 0x0fff),
				pEntry->PairwiseKey.CipherAlg, pEntry->Aid, PAIRWISEKEYTABLE);

#ifdef MT_MAC
                if (pAd->chipCap.hif_type == HIF_MT)
                    	CmdProcAddRemoveKey(pAd, 0, apidx, pKeyInfo->KeyId, pEntry->wcid, PAIRWISEKEYTABLE,
                                            &pEntry->PairwiseKey, pEntry->Addr);
#endif /* MT_MAC */
#ifdef RT_CFG80211_P2P_MULTI_CHAN_SUPPORT

				MTWF_LOG(DBG_CAT_ALL, DBG_SUBCAT_ALL, DBG_LVL_ERROR, ("%s: InfraCh=%d, pWdev->channel=%d\n", __FUNCTION__, pAd->MlmeAux.InfraChannel, pWdev->channel));
				if (INFRA_ON(pAd) && 
					( ((pAd->StaCfg.wdev.bw == pWdev->bw) && (pAd->StaCfg.wdev.channel != pWdev->channel )) 
					||!((pAd->StaCfg.wdev.bw == pWdev->bw) && ((pAd->StaCfg.wdev.channel == pWdev->channel)))))
					{
					/*wait 1 s  DHCP  for P2P CLI */
					OS_WAIT(1000);	
					DBGPRINT(RT_DEBUG_TRACE, ("OS WAIT 1000 FOR DHCP\n"));
//					pAd->MCC_GOConnect_Protect = FALSE;
//					pAd->MCC_GOConnect_Count = 0;
					Start_MCC(pAd);					
					MTWF_LOG(DBG_CAT_ALL, DBG_SUBCAT_ALL, DBG_LVL_ERROR, ("infra => GO test\n"));
				}
				else if((pAd->StaCfg.wdev.bw != pWdev->bw) && ((pAd->StaCfg.wdev.channel == pWdev->channel)))
				{
					MTWF_LOG(DBG_CAT_ALL, DBG_SUBCAT_ALL, DBG_LVL_ERROR, ("start bw !=  && SCC\n"));
					pAd->Mlme.bStartScc = TRUE;
				}
/*after p2p cli connect , neet to change to default configure*/
				//DBGPRINT(RT_DEBUG_TRACE, ("iversontest pWdev->bw %d  \n",pWdev->bw));
				if (pWdev->bw == 0)
				{
					pAd->CommonCfg.RegTransmitSetting.field.EXTCHA  = EXTCHA_BELOW;
					pAd->CommonCfg.RegTransmitSetting.field.BW = BW_40;
					pAd->CommonCfg.HT_Disable = 0;
					SetCommonHT(pAd);
				}

#endif /* RT_CFG80211_P2P_MULTI_CHAN_SUPPORT */

				
			}
			else	
			{
				DBGPRINT(RT_DEBUG_ERROR,("CFG: Set AES Security Set. (PAIRWISE) But pEntry NULL\n"));
			}
		
		}
		}else if (pKeyInfo->cipher == Ndis802_11TKIPEnable){
		/* TKIP */
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))
        if (pKeyInfo->bPairwise == FALSE )
#else
        if (pKeyInfo->KeyId > 0)
#endif	/* LINUX_VERSION_CODE 2.6.37 */	
		{
			if (pWdev->GroupKeyWepStatus == Ndis802_11Encryption2Enabled)
			{
				DBGPRINT(RT_DEBUG_TRACE, ("CFG: Set TKIP Security Set. (GROUP) %d\n", pKeyInfo->KeyLen));
				pAd->SharedKey[apidx][pKeyInfo->KeyId].KeyLen= LEN_TK;
				NdisMoveMemory(pAd->SharedKey[apidx][pKeyInfo->KeyId].Key, pKeyInfo->KeyBuf, pKeyInfo->KeyLen);
				
				pAd->SharedKey[apidx][pKeyInfo->KeyId].CipherAlg = CIPHER_TKIP;

				AsicAddSharedKeyEntry(pAd, apidx, pKeyInfo->KeyId, 
						&pAd->SharedKey[apidx][pKeyInfo->KeyId]);

				GET_GroupKey_WCID(pAd, Wcid, apidx);
				RTMPSetWcidSecurityInfo(pAd, apidx, (UINT8)(pKeyInfo->KeyId), 
				pAd->SharedKey[apidx][pKeyInfo->KeyId].CipherAlg, Wcid, SHAREDKEYTABLE);

#ifdef MT_MAC
                if (pAd->chipCap.hif_type == HIF_MT)
                        CmdProcAddRemoveKey(pAd, 0, apidx, pKeyInfo->KeyId, Wcid, SHAREDKEYTABLE,
                                        	&pAd->SharedKey[apidx][pKeyInfo->KeyId], BROADCAST_ADDR);
#endif /* MT_MAC */
				
			}
		}
		else
		{
			if (pKeyInfo->MAC)
				pEntry = MacTableLookup(pAd, pKeyInfo->MAC);
				
			if(pEntry)
			{
				DBGPRINT(RT_DEBUG_TRACE, ("CFG: Set TKIP Security Set. (PAIRWISE) %d\n", pKeyInfo->KeyLen));
				pEntry->PairwiseKey.KeyLen = LEN_TK;
				NdisCopyMemory(&pEntry->PTK[OFFSET_OF_PTK_TK], pKeyInfo->KeyBuf, OFFSET_OF_PTK_TK);
				NdisMoveMemory(pEntry->PairwiseKey.Key, &pEntry->PTK[OFFSET_OF_PTK_TK], pKeyInfo->KeyLen);
				pEntry->PairwiseKey.CipherAlg = CIPHER_TKIP;
				
				AsicAddPairwiseKeyEntry(pAd, (UCHAR)pEntry->Aid, &pEntry->PairwiseKey);
				RTMPSetWcidSecurityInfo(pAd, pEntry->func_tb_idx, (UINT8)(pKeyInfo->KeyId & 0x0fff),
				pEntry->PairwiseKey.CipherAlg, pEntry->Aid, PAIRWISEKEYTABLE);

#ifdef MT_MAC
                if (pAd->chipCap.hif_type == HIF_MT)
                    	CmdProcAddRemoveKey(pAd, 0, apidx, pKeyInfo->KeyId, pEntry->wcid, PAIRWISEKEYTABLE,
                                            &pEntry->PairwiseKey, pEntry->Addr);
#endif /* MT_MAC */
				
			}
			else	
			{
				DBGPRINT(RT_DEBUG_ERROR,("CFG: Set TKIP Security Set. (PAIRWISE) But pEntry NULL\n"));
			}
		
		}
	}
	}
#endif /* CONFIG_AP_SUPPORT */
	return TRUE;

}
Ejemplo n.º 7
0
BOOLEAN CFG80211DRV_OpsBeaconAdd(VOID *pAdOrg, VOID *pData)
{
	PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)pAdOrg;
	CMD_RTPRIV_IOCTL_80211_BEACON *pBeacon;
//	BOOLEAN Cancelled;
	UINT i = 0;
#ifdef RT_CFG80211_P2P_SUPPORT
	UINT apidx = CFG_GO_BSSID_IDX;
#else
	UINT apidx = MAIN_MBSSID;
#endif /*RT_CFG80211_P2P_SUPPORT*/
	BSS_STRUCT *pMbss = &pAd->ApCfg.MBSSID[apidx];
	struct wifi_dev *wdev = &pMbss->wdev;
	CHAR tr_tb_idx = MAX_LEN_OF_MAC_TABLE + apidx;

	/* for Concurrent, AP/P2P GO use HW_BSSID 1 */
	//wdev->hw_bssid_idx = CFG_GO_BSSID_IDX;
	wdev->hw_bssid_idx = apidx;
#ifdef RT_CFG80211_SUPPORT
#ifdef RT_CFG80211_P2P_SUPPORT
	if (!RTMP_CFG80211_VIF_P2P_GO_ON(pAd)) 
#endif /* RT_CFG80211_P2P_SUPPORT */		
		wdev->Hostapd=Hostapd_CFG;
#endif /* RT_CFG80211_SUPPORT */

	CFG80211DBG(RT_DEBUG_TRACE, ("80211> %s ==>\n", __FUNCTION__));

#ifdef CONFIG_AP_SUPPORT
#endif /* CONFIG_AP_SUPPORT */	

	pBeacon = (CMD_RTPRIV_IOCTL_80211_BEACON *)pData;

#ifdef UAPSD_SUPPORT
        wdev->UapsdInfo.bAPSDCapable = TRUE;
        pMbss->CapabilityInfo |= 0x0800;
#endif /* UAPSD_SUPPORT */

	CFG80211DRV_UpdateApSettingFromBeacon(pAd, apidx, pBeacon);
	
	AsicSetRxFilter(pAd);
	
	/* Start from 0 & MT_MAC using HW_BSSID 1, TODO */
#ifdef RT_CFG80211_P2P_SUPPORT
	pAd->ApCfg.BssidNum = (CFG_GO_BSSID_IDX + 1); 
#else
	pAd->ApCfg.BssidNum = (MAIN_MBSSID + 1); 
#endif /*RT_CFG80211_P2P_SUPPORT*/

	pAd->MacTab.MsduLifeTime = 20; /* pEntry's UAPSD Q Idle Threshold */
	/* CFG_TODO */
	pAd->ApCfg.MBSSID[apidx].bcn_buf.BcnBufIdx = 0 ;
	for(i = 0; i < WLAN_MAX_NUM_OF_TIM; i++)
                pAd->ApCfg.MBSSID[apidx].TimBitmaps[i] = 0;

	pMbss->bcn_buf.bBcnSntReq = TRUE;

	/* For GO Timeout */
#ifdef RT_CFG80211_P2P_MULTI_CHAN_SUPPORT
	pAd->ApCfg.StaIdleTimeout = 300;
	pMbss->StationKeepAliveTime = 60;
#else
	pAd->ApCfg.StaIdleTimeout = 300;
	pMbss->StationKeepAliveTime = 0;
#endif /* RT_CFG80211_P2P_MULTI_CHAN_SUPPORT */
	
	AsicDisableSync(pAd);

	if (pAd->CommonCfg.Channel > 14)
		pAd->CommonCfg.PhyMode = (WMODE_A | WMODE_AN);
	else
		pAd->CommonCfg.PhyMode = (WMODE_B | WMODE_G |WMODE_GN);

	/* cfg_todo */
	wdev->bWmmCapable = TRUE;

	wdev->wdev_type = WDEV_TYPE_AP;
	wdev->func_dev = (void *)&pAd->ApCfg.MBSSID[apidx];
	wdev->sys_handle = (void *)pAd;
	wdev->func_idx = apidx; //NEW
	


#ifdef RT_CFG80211_P2P_CONCURRENT_DEVICE
	/* Using netDev ptr from VifList if VifDevList Exist */
	PNET_DEV pNetDev = NULL;
	if ((pAd->cfg80211_ctrl.Cfg80211VifDevSet.vifDevList.size > 0) &&
	   ((pNetDev = RTMP_CFG80211_FindVifEntry_ByType(pAd, RT_CMD_80211_IFTYPE_P2P_GO)) != NULL))	
	{
		wdev->if_dev = pNetDev;
		COPY_MAC_ADDR(wdev->bssid, pNetDev->dev_addr);
		COPY_MAC_ADDR(wdev->if_addr, pNetDev->dev_addr);	
		
		RTMP_OS_NETDEV_SET_WDEV(pNetDev, wdev);
		RTMP_OS_NETDEV_SET_PRIV(pNetDev, pAd);
	}
	else
#endif /* RT_CFG80211_P2P_CONCURRENT_DEVICE */			
	{	
		wdev->if_dev = pAd->net_dev;
		COPY_MAC_ADDR(wdev->bssid, pAd->CurrentAddress);
		COPY_MAC_ADDR(wdev->if_addr, pAd->CurrentAddress);		

		/* assoc to MBSSID's wdev */
		RTMP_OS_NETDEV_SET_WDEV(pAd->net_dev, wdev);
		RTMP_OS_NETDEV_SET_PRIV(pAd->net_dev, pAd);
		//reset to INT_MAIN , because SET_PRIV would clear priv_flag
		RT_DEV_PRIV_FLAGS_SET(pAd->net_dev,INT_MAIN);
	}

	/* BC/MC Handling */
    wdev->tr_tb_idx = tr_tb_idx;
    tr_tb_set_mcast_entry(pAd, tr_tb_idx, wdev);

	/* TX */
    wdev->tx_pkt_allowed = ApAllowToSendPacket;
    wdev->wdev_hard_tx = APHardTransmit;
    wdev->tx_pkt_handle = APSendPacket;

	/* RX */
    wdev->rx_pkt_allowed = ap_rx_pkt_allow;
    wdev->rx_pkt_foward = ap_rx_foward_handle;
    wdev->rx_ps_handle = ap_rx_ps_handle;

	wdev_bcn_buf_init(pAd, &pAd->ApCfg.MBSSID[apidx].bcn_buf);
	if (rtmp_wdev_idx_reg(pAd, wdev) < 0)
    {
		DBGPRINT(RT_DEBUG_TRACE, ("%s(): register wdev fail\n", __FUNCTION__));
	}                
	wdev->allow_data_tx = TRUE;

    AsicSetBssid(pAd, wdev->if_addr, 0x1);
    AsicSetDevMac(pAd, wdev->if_addr, 0x1);

	DBGPRINT(RT_DEBUG_TRACE, ("New AP BSSID %02x:%02x:%02x:%02x:%02x:%02x (%d)\n", 
		PRINT_MAC(wdev->bssid), pAd->CommonCfg.PhyMode));

	RTMPSetPhyMode(pAd, pAd->CommonCfg.PhyMode);

#ifdef DOT11_N_SUPPORT
	if (WMODE_CAP_N(pAd->CommonCfg.PhyMode) && (pAd->Antenna.field.TxPath == 2))
		bbp_set_txdac(pAd, 2);
	else
#endif /* DOT11_N_SUPPORT */
		bbp_set_txdac(pAd, 0);
	
	/* Receiver Antenna selection */
	bbp_set_rxpath(pAd, pAd->Antenna.field.RxPath);

	if(!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED))
	{
		if (WMODE_CAP_N(pAd->CommonCfg.PhyMode) || wdev->bWmmCapable)
		{
			/* EDCA parameters used for AP's own transmission */
			if (pAd->CommonCfg.APEdcaParm.bValid == FALSE)
				set_default_ap_edca_param(pAd);

			/* EDCA parameters to be annouced in outgoing BEACON, used by WMM STA */
			if (pAd->ApCfg.BssEdcaParm.bValid == FALSE)
				set_default_sta_edca_param(pAd);

			AsicSetEdcaParm(pAd, &pAd->CommonCfg.APEdcaParm);
		}
		else
			AsicSetEdcaParm(pAd, NULL);
	}

#ifdef DOT11_N_SUPPORT
#ifndef RT_CFG80211_P2P_MULTI_CHAN_SUPPORT
	if (WMODE_CAP_N(pAd->CommonCfg.PhyMode))
		pAd->CommonCfg.HtCapability.HtCapInfo.ChannelWidth = BW_20; /* Patch UI */
#endif /* RT_CFG80211_P2P_MULTI_CHAN_SUPPORT */

	AsicSetRDG(pAd, pAd->CommonCfg.bRdg);

	AsicSetRalinkBurstMode(pAd, pAd->CommonCfg.bRalinkBurstMode);
#endif /* DOT11_N_SUPPORT */

	//AsicSetBssid(pAd, pAd->CurrentAddress, 0x0); 
		
	MTWF_LOG(DBG_CAT_ALL, DBG_SUBCAT_ALL, DBG_LVL_TRACE, ("%s():Reset WCID Table\n", __FUNCTION__));
	AsicDelWcidTab(pAd, WCID_ALL);
	
	pAd->MacTab.Content[0].Addr[0] = 0x01;
	pAd->MacTab.Content[0].HTPhyMode.field.MODE = MODE_OFDM;
	pAd->MacTab.Content[0].HTPhyMode.field.MCS = 3;

#ifdef DOT11_N_SUPPORT
	SetCommonHT(pAd);
#endif /* DOT11_N_SUPPORT */

	/*In MCC  & p2p GO not support VHT now, */
	/*change here for support P2P GO 40 BW*/
	/*	pAd->CommonCfg.vht_bw = 0;*/
	if(pAd->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_BELOW)
		pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel - 2;
	else if (pAd->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_ABOVE)
		pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel + 2;
	else
		pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel;
	
	AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel,FALSE); 
    AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel);
#ifdef RT_CFG80211_P2P_MULTI_CHAN_SUPPORT
	bbp_set_bw(pAd, wdev->bw);
#else
	bbp_set_bw(pAd, pAd->CommonCfg.RegTransmitSetting.field.BW);
#endif /* RT_CFG80211_P2P_MULTI_CHAN_SUPPORT */

	

	
	AsicBBPAdjust(pAd);
	//MlmeSetTxPreamble(pAd, (USHORT)pAd->CommonCfg.TxPreamble);	
	//MlmeUpdateTxRates(pAd, FALSE, MIN_NET_DEVICE_FOR_MBSSID);
#ifdef RT_CFG80211_P2P_SUPPORT
	MlmeUpdateTxRates(pAd, FALSE, MIN_NET_DEVICE_FOR_CFG80211_VIF_P2P_GO + apidx);
#else
	MlmeUpdateTxRates(pAd, FALSE, apidx);
#endif /*RT_CFG80211_P2P_SUPPORT*/
		
#ifdef DOT11_N_SUPPORT 
	if (WMODE_CAP_N(pAd->CommonCfg.PhyMode))		
		MlmeUpdateHtTxRates(pAd, MIN_NET_DEVICE_FOR_MBSSID);
#endif /* DOT11_N_SUPPORT */

	/* Disable Protection first. */		
	if (!INFRA_ON(pAd))		
		AsicUpdateProtect(pAd, 0, (ALLN_SETPROTECT|CCKSETPROTECT|OFDMSETPROTECT), TRUE, FALSE);		

	APUpdateCapabilityAndErpIe(pAd);		
#ifdef DOT11_N_SUPPORT	
	APUpdateOperationMode(pAd);
#endif /* DOT11_N_SUPPORT */		
	CFG80211_UpdateBeacon(pAd, pBeacon->beacon_head, pBeacon->beacon_head_len,
	                       pBeacon->beacon_tail, pBeacon->beacon_tail_len, TRUE);
		
							   
#ifdef RT_CFG80211_P2P_MULTI_CHAN_SUPPORT
	if (INFRA_ON(pAd))
	{
		ULONG BPtoJiffies;
		LONG timeDiff;
		INT starttime= pAd->Mlme.channel_1st_staytime;
		NdisGetSystemUpTime(&pAd->Mlme.BeaconNow32);

		timeDiff = (pAd->Mlme.BeaconNow32 - pAd->StaCfg.LastBeaconRxTime) % (pAd->CommonCfg.BeaconPeriod);
		DBGPRINT(RT_DEBUG_TRACE, ("#####pAd->Mlme.Now32 %d pAd->StaCfg.LastBeaconRxTime %d \n",pAd->Mlme.BeaconNow32,pAd->StaCfg.LastBeaconRxTime));
		DBGPRINT(RT_DEBUG_TRACE, ("####    timeDiff %d \n",timeDiff));	
		if (starttime > timeDiff)
		{
			OS_WAIT((starttime - timeDiff));
		}
		else{
			OS_WAIT((starttime + (pAd->CommonCfg.BeaconPeriod - timeDiff)));
		}	
	}

#endif /* RT_CFG80211_P2P_MULTI_CHAN_SUPPORT */


	/* Enable BSS Sync*/
#ifdef RT_CFG80211_P2P_MULTI_CHAN_SUPPORT
	if (INFRA_ON(pAd))
	{
		ULONG BPtoJiffies;
		LONG timeDiff;
		INT starttime= pAd->Mlme.channel_1st_staytime;
		NdisGetSystemUpTime(&pAd->Mlme.BeaconNow32);
		timeDiff = (pAd->Mlme.BeaconNow32 - pAd->StaCfg.LastBeaconRxTime) % (pAd->CommonCfg.BeaconPeriod);
		DBGPRINT(RT_DEBUG_TRACE, ("#####pAd->Mlme.Now32 %d pAd->StaCfg.LastBeaconRxTime %d \n",pAd->Mlme.BeaconNow32,pAd->StaCfg.LastBeaconRxTime));
		DBGPRINT(RT_DEBUG_TRACE, ("####    timeDiff %d \n",timeDiff));	
		if (starttime > timeDiff)
		{
			OS_WAIT((starttime - timeDiff));
		}
		else{
			OS_WAIT((starttime + (pAd->CommonCfg.BeaconPeriod - timeDiff)));
		}	
	}

#endif /* RT_CFG80211_P2P_MULTI_CHAN_SUPPORT */


	AsicEnableApBssSync(pAd, pAd->CommonCfg.BeaconPeriod);
	//pAd->P2pCfg.bSentProbeRSP = TRUE;

	AsicSetPreTbtt(pAd, TRUE);


	OPSTATUS_SET_FLAG(pAd, fOP_AP_STATUS_MEDIA_STATE_CONNECTED);	
	RTMP_IndicateMediaState(pAd, NdisMediaStateConnected);
	return TRUE;
}
Ejemplo n.º 8
0
INT Set_P2P_Provision_Dev_Addr_Proc(
	IN	PRTMP_ADAPTER	pAd, 
	IN	PSTRING			arg)
{
	POS_COOKIE			pObj;
	UCHAR		p2pindex = P2P_NOT_FOUND;
	PUCHAR	pAddr;
	UCHAR ConnAddr[6];
	UINT32	i;
	UINT16 retry_cnt = 0;
	extern UCHAR ZERO_MAC_ADDR[MAC_ADDR_LEN];
	extern UCHAR BROADCAST_ADDR[MAC_ADDR_LEN];

	pObj = (POS_COOKIE) pAd->OS_Cookie;
	if (pObj->ioctl_if_type != INT_P2P)
		return 0;

	DBGPRINT(RT_DEBUG_ERROR, ("%s::  Connect to DevAddr[%s]\n", __FUNCTION__, arg));


	/*
		If the input is the zero mac address, it means use our default(from EEPROM) MAC address as out-going 
		   MAC address.
		If the input is the broadcast MAC address, it means use the source MAC of first packet forwarded by
		   our device as the out-going MAC address.
		If the input is any other specific valid MAC address, use it as the out-going MAC address.
	*/

	if( pAd->P2pTable.ClientNumber == 0)
	{
		DBGPRINT( RT_DEBUG_ERROR, ("P2P Table is Empty! Scan First!\n"));
		P2pScan(pAd);
		OS_WAIT(2000);
	}

	NdisMoveMemory(&ConnAddr[0], &ZERO_MAC_ADDR[0], MAC_ADDR_LEN);
	if (rtstrmactohex(arg, (PSTRING) &ConnAddr[0]) == FALSE)
		return FALSE;

	DBGPRINT(RT_DEBUG_ERROR, ("%s:: DevMac = %02x:%02x:%02x:%02x:%02x:%02x\n",	__FUNCTION__, PRINT_MAC(ConnAddr)));
	
	if (MAC_ADDR_EQUAL(ConnAddr, ZERO_MAC_ADDR))
	{
		P2pLinkDown(pAd, P2P_CONNECT_FAIL);
		return TRUE;
	}

retry:
	
	for (i=0; i < pAd->P2pTable.ClientNumber; i++)
	{
		if (MAC_ADDR_EQUAL(pAd->P2pTable.Client[i].addr, ConnAddr) ||
			MAC_ADDR_EQUAL(pAd->P2pTable.Client[i].bssid, ConnAddr) ||
			MAC_ADDR_EQUAL(pAd->P2pTable.Client[i].InterfaceAddr, ConnAddr))
		{
			p2pindex = i;
			break;
		}
	}

	DBGPRINT(RT_DEBUG_TRACE,("pAd->P2pTable.ClientNumber = %d, p2pindex = %d\n", pAd->P2pTable.ClientNumber, p2pindex));
	if ((p2pindex < pAd->P2pTable.ClientNumber) && (p2pindex != P2P_NOT_FOUND))
	{
		pAddr = &pAd->P2pTable.Client[p2pindex].addr[0];
			P2pConnectPrepare(pAd, pAddr, P2PSTATE_PROVISION_COMMAND);
	}
	else
	{
		retry_cnt ++;
		if ( retry_cnt < 5 )
		{
			OS_WAIT(2000);
			goto retry;
		}
		DBGPRINT(RT_DEBUG_ERROR, ("Table Idx out of range!\n"));
#ifdef RT_P2P_SPECIFIC_WIRELESS_EVENT
		P2pSendWirelessEvent(pAd, RT_P2P_CONNECT_FAIL, NULL, NULL);
#endif /* RT_P2P_SPECIFIC_WIRELESS_EVENT */
	}

	return TRUE;
}