Example #1
0
File: iwctl.c Project: 7799/linux
/*
 * Wireless Handler: set scan
 */
int iwctl_siwscan(struct net_device *dev, struct iw_request_info *info,
		union iwreq_data *wrqu, char *extra)
{
	struct vnt_private *pDevice = netdev_priv(dev);
	struct iw_point *wrq = &wrqu->data;
	struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
	struct iw_scan_req *req = (struct iw_scan_req *)extra;
	u8 abyScanSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
	PWLAN_IE_SSID pItemSSID = NULL;

	if (!(pDevice->flags & DEVICE_FLAGS_OPENED))
		return -EINVAL;

	PRINT_K(" SIOCSIWSCAN\n");

	if (pMgmt == NULL)
		return -EFAULT;

	if (pMgmt->eScanState ==  WMAC_IS_SCANNING) {
		// In scanning..
		PRINT_K("SIOCSIWSCAN(overlap??)-->In scanning...\n");
		return -EAGAIN;
	}

	if (pDevice->byReAssocCount > 0) { // reject scan when re-associating!
		// send scan event to wpa_Supplicant
		union iwreq_data wrqu;
		PRINT_K("wireless_send_event--->SIOCGIWSCAN(scan done)\n");
		memset(&wrqu, 0, sizeof(wrqu));
		wireless_send_event(pDevice->dev, SIOCGIWSCAN, &wrqu, NULL);
		return 0;
	}

	spin_lock_irq(&pDevice->lock);

	BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);

	// mike add: active scan OR passive scan OR desire_ssid scan
	if (wrq->length == sizeof(struct iw_scan_req)) {
		if (wrq->flags & IW_SCAN_THIS_ESSID) { // desire_ssid scan
			memset(abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
			pItemSSID = (PWLAN_IE_SSID)abyScanSSID;
			pItemSSID->byElementID = WLAN_EID_SSID;
			memcpy(pItemSSID->abySSID, req->essid, (int)req->essid_len);
			if (pItemSSID->abySSID[req->essid_len] == '\0') {
				if (req->essid_len > 0)
					pItemSSID->len = req->essid_len;
			} else {
				pItemSSID->len = req->essid_len;
			}
			pMgmt->eScanType = WMAC_SCAN_PASSIVE;
			PRINT_K("SIOCSIWSCAN:[desired_ssid=%s,len=%d]\n", ((PWLAN_IE_SSID)abyScanSSID)->abySSID,
				((PWLAN_IE_SSID)abyScanSSID)->len);
			bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, abyScanSSID);
			spin_unlock_irq(&pDevice->lock);

			return 0;
		} else if (req->scan_type == IW_SCAN_TYPE_PASSIVE) { // passive scan
			pMgmt->eScanType = WMAC_SCAN_PASSIVE;
		}
	} else { // active scan
		pMgmt->eScanType = WMAC_SCAN_ACTIVE;
	}

	pMgmt->eScanType = WMAC_SCAN_PASSIVE;
	bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
	spin_unlock_irq(&pDevice->lock);

	return 0;
}
Example #2
0
File: iwctl.c Project: 7799/linux
/*
 * Wireless Handler: set operation mode
 */
int iwctl_siwmode(struct net_device *dev, struct iw_request_info *info,
		union iwreq_data *wrqu, char *extra)
{
	struct vnt_private *pDevice = netdev_priv(dev);
	__u32 *wmode = &wrqu->mode;
	struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
	int rc = 0;

	DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWMODE\n");

	if (pMgmt == NULL)
		return -EFAULT;

	if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP && pDevice->bEnableHostapd) {
		DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
			"Can't set operation mode, hostapd is running\n");
		return rc;
	}

	switch (*wmode) {
	case IW_MODE_ADHOC:
		if (pMgmt->eConfigMode != WMAC_CONFIG_IBSS_STA) {
			pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA;
			if (pDevice->flags & DEVICE_FLAGS_OPENED)
				pDevice->bCommit = true;
		}
		DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to ad-hoc\n");
		break;
	case IW_MODE_AUTO:
	case IW_MODE_INFRA:
		if (pMgmt->eConfigMode != WMAC_CONFIG_ESS_STA) {
			pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
			if (pDevice->flags & DEVICE_FLAGS_OPENED)
				pDevice->bCommit = true;
		}
		DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to infrastructure\n");
		break;
	case IW_MODE_MASTER:

		pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
		rc = -EOPNOTSUPP;
		break;

		if (pMgmt->eConfigMode != WMAC_CONFIG_AP) {
			pMgmt->eConfigMode = WMAC_CONFIG_AP;
			if (pDevice->flags & DEVICE_FLAGS_OPENED)
				pDevice->bCommit = true;
		}
		DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to Access Point\n");
		break;

	case IW_MODE_REPEAT:
		pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
		rc = -EOPNOTSUPP;
		break;
	default:
		rc = -EINVAL;
	}

	if (pDevice->bCommit) {
		if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
			netif_stop_queue(pDevice->dev);
			spin_lock_irq(&pDevice->lock);
			bScheduleCommand((void *) pDevice,
				WLAN_CMD_RUN_AP, NULL);
			spin_unlock_irq(&pDevice->lock);
		} else {
			DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
				"Commit the settings\n");

			spin_lock_irq(&pDevice->lock);

			if (pDevice->bLinkPass &&
				memcmp(pMgmt->abyCurrSSID,
					pMgmt->abyDesireSSID,
					WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN)) {
				bScheduleCommand((void *) pDevice,
					WLAN_CMD_DISASSOCIATE, NULL);
			} else {
				pDevice->bLinkPass = false;
				pMgmt->eCurrState = WMAC_STATE_IDLE;
				memset(pMgmt->abyCurrBSSID, 0, 6);
			}

			ControlvMaskByte(pDevice,
				MESSAGE_REQUEST_MACREG,	MAC_REG_PAPEDELAY,
					LEDSTS_STS, LEDSTS_SLOW);

			netif_stop_queue(pDevice->dev);

			pMgmt->eScanType = WMAC_SCAN_ACTIVE;

			if (!pDevice->bWPASuppWextEnabled)
				bScheduleCommand((void *) pDevice,
					 WLAN_CMD_BSSID_SCAN,
					 pMgmt->abyDesireSSID);

			bScheduleCommand((void *) pDevice,
				 WLAN_CMD_SSID,
				 NULL);

			spin_unlock_irq(&pDevice->lock);
		}
		pDevice->bCommit = false;
	}

	return rc;
}
Example #3
0
File: iwctl.c Project: 7799/linux
/*
 * Wireless Handler: set essid
 */
int iwctl_siwessid(struct net_device *dev, struct iw_request_info *info,
		union iwreq_data *wrqu, char *extra)
{
	struct vnt_private *pDevice = netdev_priv(dev);
	struct iw_point	*wrq = &wrqu->essid;
	struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
	PWLAN_IE_SSID pItemSSID;

	if (pMgmt == NULL)
		return -EFAULT;

	if (!(pDevice->flags & DEVICE_FLAGS_OPENED))
		return -EINVAL;

	DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWESSID :\n");

	pDevice->fWPA_Authened = false;
	// Check if we asked for `any'
	if (wrq->flags == 0) {
		// Just send an empty SSID list
		memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
		memset(pMgmt->abyDesireBSSID, 0xFF, 6);
		PRINT_K("set essid to 'any'\n");
		// Unknown desired AP, so here need not associate??
		return 0;
	} else {
		// Set the SSID
		memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
		pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
		pItemSSID->byElementID = WLAN_EID_SSID;

		memcpy(pItemSSID->abySSID, extra, wrq->length);
		if (pItemSSID->abySSID[wrq->length] == '\0') {
			if (wrq->length > 0)
				pItemSSID->len = wrq->length;
		} else {
			pItemSSID->len = wrq->length;
		}
		PRINT_K("set essid to %s\n", pItemSSID->abySSID);

		// mike: need clear desiredBSSID
		if (pItemSSID->len == 0) {
			memset(pMgmt->abyDesireBSSID, 0xFF, 6);
			return 0;
		}

		// Wext wil order another command of siwap to link
		// with desired AP, so here need not associate??
		if (pDevice->bWPASuppWextEnabled == true)  {
			/*******search if  in hidden ssid mode ****/
			PKnownBSS pCurr = NULL;
			u8 abyTmpDesireSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
			unsigned ii;
			unsigned uSameBssidNum = 0;

			memcpy(abyTmpDesireSSID, pMgmt->abyDesireSSID, sizeof(abyTmpDesireSSID));
			pCurr = BSSpSearchBSSList(pDevice, NULL,
						abyTmpDesireSSID,
						pDevice->eConfigPHYMode);

			if (pCurr == NULL) {
				PRINT_K("SIOCSIWESSID:hidden ssid site survey before associate.......\n");
				vResetCommandTimer((void *)pDevice);
				pMgmt->eScanType = WMAC_SCAN_ACTIVE;
				bScheduleCommand((void *)pDevice,
						WLAN_CMD_BSSID_SCAN,
						pMgmt->abyDesireSSID);
				bScheduleCommand((void *)pDevice,
						WLAN_CMD_SSID,
						pMgmt->abyDesireSSID);
			} else {  // mike: to find out if that desired SSID is a
				// hidden-ssid AP, by means of judging if there
				// are two same BSSID exist in list ?
				for (ii = 0; ii < MAX_BSS_NUM; ii++) {
					if (pMgmt->sBSSList[ii].bActive &&
						ether_addr_equal(pMgmt->sBSSList[ii].abyBSSID,
								 pCurr->abyBSSID)) {
						uSameBssidNum++;
					}
				}
				if (uSameBssidNum >= 2) { // hit: desired AP is in hidden ssid mode!!!
					PRINT_K("SIOCSIWESSID:hidden ssid directly associate.......\n");
					vResetCommandTimer((void *)pDevice);
					pMgmt->eScanType = WMAC_SCAN_PASSIVE; // this scan type, you'll submit scan result!
					bScheduleCommand((void *)pDevice,
							WLAN_CMD_BSSID_SCAN,
							pMgmt->abyDesireSSID);
					bScheduleCommand((void *)pDevice,
							WLAN_CMD_SSID,
							pMgmt->abyDesireSSID);
				}
			}
			return 0;
		}

		DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set essid = %s\n", pItemSSID->abySSID);
	}

	if (pDevice->flags & DEVICE_FLAGS_OPENED)
		pDevice->bCommit = true;

	return 0;
}
Example #4
0
int private_ioctl(PSDevice pDevice, struct ifreq *rq) {

	PSCmdRequest        pReq = (PSCmdRequest)rq;
    PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
	int 		        result = 0;
    PWLAN_IE_SSID       pItemSSID;
    SCmdBSSJoin         sJoinCmd;
    SCmdZoneTypeSet sZoneTypeCmd;
    SCmdScan            sScanCmd;
    SCmdStartAP         sStartAPCmd;
    SCmdSetWEP          sWEPCmd;
    SCmdValue           sValue;
    SBSSIDList          sList;
    SNodeList           sNodeList;
    PSBSSIDList         pList;
    PSNodeList          pNodeList;
    unsigned int                cbListCount;
    PKnownBSS           pBSS;
    PKnownNodeDB        pNode;
    unsigned int                ii, jj;
    SCmdLinkStatus      sLinkStatus;
    BYTE                abySuppRates[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16};
    BYTE                abyNullAddr[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
    DWORD               dwKeyIndex= 0;
    BYTE                abyScanSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
    signed long                ldBm;

    pReq->wResult = 0;

    switch(pReq->wCmdCode) {

    case WLAN_CMD_BSS_SCAN:

        if (copy_from_user(&sScanCmd, pReq->data, sizeof(SCmdScan))) {
			result = -EFAULT;
			break;
		}

        pItemSSID = (PWLAN_IE_SSID)sScanCmd.ssid;
        if (pItemSSID->len != 0) {
            memset(abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
            memcpy(abyScanSSID, pItemSSID, pItemSSID->len + WLAN_IEHDR_LEN);
        }
        spin_lock_irq(&pDevice->lock);

	if (memcmp(pMgmt->abyCurrBSSID, &abyNullAddr[0], 6) == 0)
		BSSvClearBSSList((void *) pDevice, FALSE);
	else
		BSSvClearBSSList((void *) pDevice, pDevice->bLinkPass);

	DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_BSS_SCAN..begin\n");

	if (pItemSSID->len != 0)
		bScheduleCommand((void *) pDevice,
				 WLAN_CMD_BSSID_SCAN,
				 abyScanSSID);
	else
		bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, NULL);

        spin_unlock_irq(&pDevice->lock);
        break;

    case WLAN_CMD_ZONETYPE_SET:
	//mike add :cann't support.
           result=-EOPNOTSUPP;
	  break;

        if (copy_from_user(&sZoneTypeCmd, pReq->data, sizeof(SCmdZoneTypeSet))) {
			result = -EFAULT;
			break;
		}

          if(sZoneTypeCmd.bWrite==TRUE) {
	  //////write zonetype
                if(sZoneTypeCmd.ZoneType == ZoneType_USA) {
                  //set to USA
                   printk("set_ZoneType:USA\n");
		}
                else if(sZoneTypeCmd.ZoneType == ZoneType_Japan) {
                  //set to Japan
                  printk("set_ZoneType:Japan\n");
		}
	       else if(sZoneTypeCmd.ZoneType == ZoneType_Europe) {
                  //set to Europe
                  printk("set_ZoneType:Europe\n");
		}
            }
	else {
          ///////read zonetype
	  BYTE                       zonetype=0;

           if(zonetype == 0x00)  { //USA
             sZoneTypeCmd.ZoneType = ZoneType_USA;
           }
	 else if(zonetype == 0x01) { //Japan
             sZoneTypeCmd.ZoneType = ZoneType_Japan;
	  }
	 else if(zonetype == 0x02) { //Europe
             sZoneTypeCmd.ZoneType = ZoneType_Europe;
	 }
	 else { //Unknown ZoneType
	        printk("Error:ZoneType[%x] Unknown ???\n",zonetype);
	         result = -EFAULT;
		break;
	 }
	   if (copy_to_user(pReq->data, &sZoneTypeCmd, sizeof(SCmdZoneTypeSet))) {
			result = -EFAULT;
			break;
		}
	}

	     break;

    case WLAN_CMD_BSS_JOIN:

        if (copy_from_user(&sJoinCmd, pReq->data, sizeof(SCmdBSSJoin))) {
			result = -EFAULT;
			break;
		}

        pItemSSID = (PWLAN_IE_SSID)sJoinCmd.ssid;
        memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
		memcpy(pMgmt->abyDesireSSID, pItemSSID, pItemSSID->len + WLAN_IEHDR_LEN);
	    if (sJoinCmd.wBSSType == ADHOC) {
	        pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA;
	        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ioct set to adhoc mode\n");
	    }
	    else {
	        pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
	        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ioct set to STA mode\n");
	    }
	    if (sJoinCmd.bPSEnable == TRUE) {
            pDevice->ePSMode = WMAC_POWER_FAST;
//            pDevice->ePSMode = WMAC_POWER_MAX;
            pMgmt->wListenInterval = 2;
            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Power Saving On\n");
        }
        else {
            pDevice->ePSMode = WMAC_POWER_CAM;
            pMgmt->wListenInterval = 1;
            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Power Saving Off \n");
        }

        if (sJoinCmd.bShareKeyAuth == TRUE){
            pMgmt->bShareKeyAlgorithm = TRUE;
            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Share Key \n");
        }
        else {
            pMgmt->bShareKeyAlgorithm = FALSE;
            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Open System \n");
        }
	    pDevice->uChannel = sJoinCmd.uChannel;
        netif_stop_queue(pDevice->dev);
        spin_lock_irq(&pDevice->lock);
        pMgmt->eCurrState = WMAC_STATE_IDLE;
	bScheduleCommand((void *) pDevice,
			 WLAN_CMD_BSSID_SCAN,
			 pMgmt->abyDesireSSID);
	bScheduleCommand((void *) pDevice, WLAN_CMD_SSID, NULL);
        spin_unlock_irq(&pDevice->lock);
        break;

    case WLAN_CMD_SET_WEP:
        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_SET_WEP Key. \n");
        memset(&sWEPCmd, 0 ,sizeof(SCmdSetWEP));
        if (copy_from_user(&sWEPCmd, pReq->data, sizeof(SCmdSetWEP))) {
			result = -EFAULT;
			break;
		}
	    if (sWEPCmd.bEnableWep != TRUE) {
	        int uu;

            pDevice->bEncryptionEnable = FALSE;
            pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
            spin_lock_irq(&pDevice->lock);
	    for (uu = 0; uu < MAX_KEY_TABLE; uu++)
		MACvDisableKeyEntry(pDevice, uu);
            spin_unlock_irq(&pDevice->lock);
	    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WEP function disable.\n");
            break;
        }

        for (ii = 0; ii < WLAN_WEP_NKEYS; ii ++) {
            if (sWEPCmd.bWepKeyAvailable[ii]) {
                if (ii == sWEPCmd.byKeyIndex)
//2006-1207-01<Modify>by Einsn Liu
//		    dwKeyIndex|= (1 << 31);
                    dwKeyIndex=ii|(1 << 31);
                else
                    dwKeyIndex = ii;
                spin_lock_irq(&pDevice->lock);
                KeybSetDefaultKey(  pDevice,
                                    &(pDevice->sKey),
                                    dwKeyIndex,
                                    sWEPCmd.auWepKeyLength[ii],
                                    NULL,
                                    (PBYTE)&sWEPCmd.abyWepKey[ii][0],
                                    KEY_CTL_WEP
                                  );
               spin_unlock_irq(&pDevice->lock);

            }
        }
        pDevice->byKeyIndex = sWEPCmd.byKeyIndex;
        pDevice->bTransmitKey = TRUE;
        pDevice->bEncryptionEnable = TRUE;
        pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;

        break;

    case WLAN_CMD_GET_LINK:
        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_GET_LINK status. \n");

        memset(sLinkStatus.abySSID, 0 , WLAN_SSID_MAXLEN + 1);

        if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)
            sLinkStatus.wBSSType = ADHOC;
        else
            sLinkStatus.wBSSType = INFRA;

        if (pMgmt->eCurrState == WMAC_STATE_JOINTED)
            sLinkStatus.byState = ADHOC_JOINTED;
        else
            sLinkStatus.byState = ADHOC_STARTED;

        sLinkStatus.uChannel = pMgmt->uCurrChannel;
        if (pDevice->bLinkPass == TRUE) {
            sLinkStatus.bLink = TRUE;
 		    pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
		    memcpy(sLinkStatus.abySSID, pItemSSID->abySSID, pItemSSID->len);
		    memcpy(sLinkStatus.abyBSSID, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
		    sLinkStatus.uLinkRate = pMgmt->sNodeDBTable[0].wTxDataRate;
            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Link Success ! \n");
        }
        else {
            sLinkStatus.bLink = FALSE;
        }
        if (copy_to_user(pReq->data, &sLinkStatus, sizeof(SCmdLinkStatus))) {
			result = -EFAULT;
			break;
		}

        break;

    case WLAN_CMD_GET_LISTLEN:
		cbListCount = 0;
		pBSS = &(pMgmt->sBSSList[0]);
        for (ii = 0; ii < MAX_BSS_NUM; ii++) {
            pBSS = &(pMgmt->sBSSList[ii]);
            if (!pBSS->bActive)
                continue;
            cbListCount++;
        }
        sList.uItem = cbListCount;
        if (copy_to_user(pReq->data, &sList, sizeof(SBSSIDList))) {
			result = -EFAULT;
			break;
		}
        pReq->wResult = 0;
        break;

    case WLAN_CMD_GET_LIST:
        if (copy_from_user(&sList, pReq->data, sizeof(SBSSIDList))) {
			result = -EFAULT;
			break;
		}
        pList = (PSBSSIDList)kmalloc(sizeof(SBSSIDList) + (sList.uItem * sizeof(SBSSIDItem)), (int)GFP_ATOMIC);
        if (pList == NULL) {
            result = -ENOMEM;
            break;
        }
		pList->uItem = sList.uItem;
		pBSS = &(pMgmt->sBSSList[0]);
        for (ii = 0, jj = 0; jj < MAX_BSS_NUM ; jj++) {
            pBSS = &(pMgmt->sBSSList[jj]);
            if (pBSS->bActive) {
    		    pList->sBSSIDList[ii].uChannel = pBSS->uChannel;
    		    pList->sBSSIDList[ii].wBeaconInterval = pBSS->wBeaconInterval;
    		    pList->sBSSIDList[ii].wCapInfo = pBSS->wCapInfo;
    		    RFvRSSITodBm(pDevice, (BYTE)(pBSS->uRSSI), &ldBm);
		    pList->sBSSIDList[ii].uRSSI = (unsigned int) ldBm;
//    		    pList->sBSSIDList[ii].uRSSI = pBSS->uRSSI;
    		    memcpy(pList->sBSSIDList[ii].abyBSSID, pBSS->abyBSSID, WLAN_BSSID_LEN);
    		    pItemSSID = (PWLAN_IE_SSID)pBSS->abySSID;
    		    memset(pList->sBSSIDList[ii].abySSID, 0, WLAN_SSID_MAXLEN + 1);
    		    memcpy(pList->sBSSIDList[ii].abySSID, pItemSSID->abySSID, pItemSSID->len);
                if (WLAN_GET_CAP_INFO_ESS(pBSS->wCapInfo)) {
    		        pList->sBSSIDList[ii].byNetType = INFRA;
                }
                else {
    		        pList->sBSSIDList[ii].byNetType = ADHOC;
    		    }
    		    if (WLAN_GET_CAP_INFO_PRIVACY(pBSS->wCapInfo)) {
    		        pList->sBSSIDList[ii].bWEPOn = TRUE;
                }
                else {
    		        pList->sBSSIDList[ii].bWEPOn = FALSE;
    		    }
    		    ii ++;
    		    if (ii >= pList->uItem)
    		        break;
            }
        }

        if (copy_to_user(pReq->data, pList, sizeof(SBSSIDList) + (sList.uItem * sizeof(SBSSIDItem)))) {
			result = -EFAULT;
			break;
		}
        kfree(pList);
        pReq->wResult = 0;
        break;

    case WLAN_CMD_GET_MIB:
        if (copy_to_user(pReq->data, &(pDevice->s802_11Counter), sizeof(SDot11MIBCount))) {
			result = -EFAULT;
			break;
		}
        break;

    case WLAN_CMD_GET_STAT:
        if (copy_to_user(pReq->data, &(pDevice->scStatistic), sizeof(SStatCounter))) {
			result = -EFAULT;
			break;
		}
        break;
    case WLAN_CMD_STOP_MAC:

        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_STOP_MAC\n");
        // Todo xxxxxx
        netif_stop_queue(pDevice->dev);
        spin_lock_irq(&pDevice->lock);
        if (pDevice->bRadioOff == FALSE) {
            CARDbRadioPowerOff(pDevice);
        }
        pDevice->bLinkPass = FALSE;
        ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
        memset(pMgmt->abyCurrBSSID, 0, 6);
        pMgmt->eCurrState = WMAC_STATE_IDLE;
//        del_timer(&pDevice->sTimerCommand);
//        del_timer(&pMgmt->sTimerSecondCallback);
        pDevice->bCmdRunning = FALSE;
        spin_unlock_irq(&pDevice->lock);

        break;

    case WLAN_CMD_START_MAC:

        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_START_MAC\n");
        // Todo xxxxxxx
        if (pDevice->bRadioOff == TRUE)
            CARDbRadioPowerOn(pDevice);
        break;

    case WLAN_CMD_SET_HOSTAPD:

        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_SET_HOSTAPD\n");

        if (copy_from_user(&sValue, pReq->data, sizeof(SCmdValue))) {
			result = -EFAULT;
			break;
		}
		if (sValue.dwValue == 1) {
            if (vt6656_hostap_set_hostapd(pDevice, 1, 1) == 0){
                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable HOSTAP\n");
            }
            else {
			    result = -EFAULT;
			    break;
			}
        }
        else {
            vt6656_hostap_set_hostapd(pDevice, 0, 1);
            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable HOSTAP\n");
        }

        break;

    case WLAN_CMD_SET_HOSTAPD_STA:

        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_SET_HOSTAPD_STA\n");

        break;
    case WLAN_CMD_SET_802_1X:

        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_SET_802_1X\n");
        if (copy_from_user(&sValue, pReq->data, sizeof(SCmdValue))) {
			result = -EFAULT;
			break;
		}

		if (sValue.dwValue == 1) {
            pDevice->bEnable8021x = TRUE;
            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable 802.1x\n");
        }
        else {
            pDevice->bEnable8021x = FALSE;
            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable 802.1x\n");
        }

        break;

    case WLAN_CMD_SET_HOST_WEP:

        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_SET_HOST_WEP\n");
        if (copy_from_user(&sValue, pReq->data, sizeof(SCmdValue))) {
			result = -EFAULT;
			break;
		}

		if (sValue.dwValue == 1) {
            pDevice->bEnableHostWEP = TRUE;
            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable HostWEP\n");
        }
        else {
            pDevice->bEnableHostWEP = FALSE;
            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable HostWEP\n");
        }

        break;

    case WLAN_CMD_SET_WPA:
         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_SET_WPA\n");

        if (copy_from_user(&sValue, pReq->data, sizeof(SCmdValue))) {
			result = -EFAULT;
			break;
		}
		if (sValue.dwValue == 1) {
                     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "up wpadev\n");
		   memcpy(pDevice->wpadev->dev_addr,
			  pDevice->dev->dev_addr,
			  ETH_ALEN);
		   pDevice->bWPADEVUp = TRUE;
        }
        else {
            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "close wpadev\n");
	   pDevice->bWPADEVUp = FALSE;
        }

        break;

    case WLAN_CMD_AP_START:

        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_AP_START\n");
        if (pDevice->bRadioOff == TRUE) {
            CARDbRadioPowerOn(pDevice);
            add_timer(&pMgmt->sTimerSecondCallback);
        }
        if (copy_from_user(&sStartAPCmd, pReq->data, sizeof(SCmdStartAP))) {
			result = -EFAULT;
			break;
		}

	    if (sStartAPCmd.wBSSType == AP) {
	        pMgmt->eConfigMode = WMAC_CONFIG_AP;
	        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ioct set to AP mode\n");
	    }
	    else {
	        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ioct BSS type not set to AP mode\n");
			result = -EFAULT;
			break;
	    }

	    if (sStartAPCmd.wBBPType == PHY80211g) {
            pMgmt->byAPBBType = PHY_TYPE_11G;
        }
        else if (sStartAPCmd.wBBPType == PHY80211a) {
                 pMgmt->byAPBBType = PHY_TYPE_11A;
        }
        else {
            pMgmt->byAPBBType = PHY_TYPE_11B;
        }

        pItemSSID = (PWLAN_IE_SSID)sStartAPCmd.ssid;
        memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
		memcpy(pMgmt->abyDesireSSID, pItemSSID, pItemSSID->len + WLAN_IEHDR_LEN);

	    if ((sStartAPCmd.uChannel > 0)&&(sStartAPCmd.uChannel <= 14))
	        pDevice->uChannel = sStartAPCmd.uChannel;

	    if ((sStartAPCmd.uBeaconInt >= 20) && (sStartAPCmd.uBeaconInt <= 1000))
            pMgmt->wIBSSBeaconPeriod = sStartAPCmd.uBeaconInt;
        else
            pMgmt->wIBSSBeaconPeriod = 100;

        if (sStartAPCmd.bShareKeyAuth == TRUE){
            pMgmt->bShareKeyAlgorithm = TRUE;
            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Share Key \n");
        }
        else {
            pMgmt->bShareKeyAlgorithm = FALSE;
            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Open System \n");
        }
        memcpy(pMgmt->abyIBSSSuppRates, abySuppRates, 6);

        if (sStartAPCmd.byBasicRate & BIT3) {
            pMgmt->abyIBSSSuppRates[2] |= BIT7;
            pMgmt->abyIBSSSuppRates[3] |= BIT7;
            pMgmt->abyIBSSSuppRates[4] |= BIT7;
            pMgmt->abyIBSSSuppRates[5] |= BIT7;
        }else if (sStartAPCmd.byBasicRate & BIT2) {
             pMgmt->abyIBSSSuppRates[2] |= BIT7;
             pMgmt->abyIBSSSuppRates[3] |= BIT7;
             pMgmt->abyIBSSSuppRates[4] |= BIT7;
        }else if (sStartAPCmd.byBasicRate & BIT1) {
             pMgmt->abyIBSSSuppRates[2] |= BIT7;
             pMgmt->abyIBSSSuppRates[3] |= BIT7;
        }else if (sStartAPCmd.byBasicRate & BIT1) {
             pMgmt->abyIBSSSuppRates[2] |= BIT7;
        }else {
            //default 1,2M
             pMgmt->abyIBSSSuppRates[2] |= BIT7;
             pMgmt->abyIBSSSuppRates[3] |= BIT7;
        }

        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Support Rate= %x %x %x %x\n",
                pMgmt->abyIBSSSuppRates[2],
                pMgmt->abyIBSSSuppRates[3],
                pMgmt->abyIBSSSuppRates[4],
                pMgmt->abyIBSSSuppRates[5]
                );

        netif_stop_queue(pDevice->dev);
        spin_lock_irq(&pDevice->lock);
	bScheduleCommand((void *) pDevice, WLAN_CMD_RUN_AP, NULL);
        spin_unlock_irq(&pDevice->lock);
        break;

    case WLAN_CMD_GET_NODE_CNT:

		cbListCount = 0;
		pNode = &(pMgmt->sNodeDBTable[0]);
        for (ii = 0; ii < (MAX_NODE_NUM + 1); ii++) {
            pNode = &(pMgmt->sNodeDBTable[ii]);
            if (!pNode->bActive)
                continue;
            cbListCount++;
        }

        sNodeList.uItem = cbListCount;
        if (copy_to_user(pReq->data, &sNodeList, sizeof(SNodeList))) {
			result = -EFAULT;
			break;
		}
        pReq->wResult = 0;
        break;

    case WLAN_CMD_GET_NODE_LIST:

        if (copy_from_user(&sNodeList, pReq->data, sizeof(SNodeList))) {
			result = -EFAULT;
			break;
		}
        pNodeList = (PSNodeList)kmalloc(sizeof(SNodeList) + (sNodeList.uItem * sizeof(SNodeItem)), (int)GFP_ATOMIC);
        if (pNodeList == NULL) {
            result = -ENOMEM;
            break;
        }
		pNodeList->uItem = sNodeList.uItem;
		pNode = &(pMgmt->sNodeDBTable[0]);
        for (ii = 0, jj = 0; ii < (MAX_NODE_NUM + 1); ii++) {
            pNode = &(pMgmt->sNodeDBTable[ii]);
            if (pNode->bActive) {
    		    pNodeList->sNodeList[jj].wAID = pNode->wAID;
    		    memcpy(pNodeList->sNodeList[jj].abyMACAddr, pNode->abyMACAddr, WLAN_ADDR_LEN);
    		    pNodeList->sNodeList[jj].wTxDataRate = pNode->wTxDataRate;
    		    pNodeList->sNodeList[jj].wInActiveCount = (WORD)pNode->uInActiveCount;
    		    pNodeList->sNodeList[jj].wEnQueueCnt = (WORD)pNode->wEnQueueCnt;
    		    pNodeList->sNodeList[jj].wFlags = (WORD)pNode->dwFlags;
    		    pNodeList->sNodeList[jj].bPWBitOn = pNode->bPSEnable;
    		    pNodeList->sNodeList[jj].byKeyIndex = pNode->byKeyIndex;
    		    pNodeList->sNodeList[jj].wWepKeyLength = pNode->uWepKeyLength;
    		    memcpy(&(pNodeList->sNodeList[jj].abyWepKey[0]), &(pNode->abyWepKey[0]), WEP_KEYMAXLEN);
                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "key= %2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
                            pNodeList->sNodeList[jj].abyWepKey[0],
                            pNodeList->sNodeList[jj].abyWepKey[1],
                            pNodeList->sNodeList[jj].abyWepKey[2],
                            pNodeList->sNodeList[jj].abyWepKey[3],
                            pNodeList->sNodeList[jj].abyWepKey[4]
                           );
    		    pNodeList->sNodeList[jj].bIsInFallback = pNode->bIsInFallback;
    		    pNodeList->sNodeList[jj].uTxFailures = pNode->uTxFailures;
    		    pNodeList->sNodeList[jj].uTxAttempts = pNode->uTxAttempts;
    		    pNodeList->sNodeList[jj].wFailureRatio = (WORD)pNode->uFailureRatio;
    		    jj ++;
    		    if (jj >= pNodeList->uItem)
    		        break;
    		}
		}
        if (copy_to_user(pReq->data, pNodeList, sizeof(SNodeList) + (sNodeList.uItem * sizeof(SNodeItem)))) {
			result = -EFAULT;
			break;
		}
        kfree(pNodeList);
        pReq->wResult = 0;
        break;

    case 0xFF:
        memset(wpa_Result.ifname,0,sizeof(wpa_Result.ifname));
	    wpa_Result.proto = 0;
	    wpa_Result.key_mgmt = 0;
	    wpa_Result.eap_type = 0;
	    wpa_Result.authenticated = FALSE;
	      pDevice->fWPA_Authened = FALSE;
        if (copy_from_user(&wpa_Result, pReq->data, sizeof(wpa_Result))) {
            result = -EFAULT;
			break;
		}
//DavidWang  for some AP maybe good authenticate
   if(wpa_Result.key_mgmt==0x20)
      pMgmt->Cisco_cckm =1;
    else
    pMgmt->Cisco_cckm =0;

if(wpa_Result.authenticated==TRUE) {
   {
     union iwreq_data      wrqu;

     pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;

     memset(&wrqu, 0, sizeof(wrqu));
     wrqu.data.flags = RT_WPACONNECTED_EVENT_FLAG;
     wrqu.data.length =pItemSSID->len;
     wireless_send_event(pDevice->dev, IWEVCUSTOM, &wrqu, pItemSSID->abySSID);
   }
         pDevice->fWPA_Authened = TRUE;           //is successful peer to wpa_Result.authenticated?
}

        //printk("get private wpa_supplicant announce WPA SM\n");
	//printk("wpa-->ifname=%s\n",wpa_Result.ifname);
	//printk("wpa-->proto=%d\n",wpa_Result.proto);
	//printk("wpa-->key-mgmt=%d\n",wpa_Result.key_mgmt);
	//printk("wpa-->eap_type=%d\n",wpa_Result.eap_type);
	//printk("wpa-->authenticated is %s\n",(wpa_Result.authenticated==TRUE)?"TRUE":"FALSE");

	pReq->wResult = 0;
        break;

    default:
        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Private command not support..\n");
    }

    return result;
}
static int wpa_set_associate(PSDevice pDevice,
			     struct viawget_wpa_param *param)
{
	PSMgmtObject    pMgmt = pDevice->pMgmt;
	PWLAN_IE_SSID   pItemSSID;
	unsigned char abyNullAddr[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
	unsigned char abyWPAIE[64];
	int ret = 0;
	bool bWepEnabled = false;

	// set key type & algorithm
	DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pairwise_suite = %d\n", param->u.wpa_associate.pairwise_suite);
	DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "group_suite = %d\n", param->u.wpa_associate.group_suite);
	DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "key_mgmt_suite = %d\n", param->u.wpa_associate.key_mgmt_suite);
	DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "auth_alg = %d\n", param->u.wpa_associate.auth_alg);
	DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "mode = %d\n", param->u.wpa_associate.mode);
	DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wpa_ie_len = %d\n", param->u.wpa_associate.wpa_ie_len);

	if (param->u.wpa_associate.wpa_ie_len) {
		if (!param->u.wpa_associate.wpa_ie)
			return -EINVAL;
		if (param->u.wpa_associate.wpa_ie_len > sizeof(abyWPAIE))
			return -EINVAL;
		if (copy_from_user(&abyWPAIE[0], param->u.wpa_associate.wpa_ie, param->u.wpa_associate.wpa_ie_len))
			return -EFAULT;
	}

	if (param->u.wpa_associate.mode == 1)
		pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA;
	else
		pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
	// set ssid
	memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
	pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
	pItemSSID->byElementID = WLAN_EID_SSID;
	pItemSSID->len = param->u.wpa_associate.ssid_len;
	memcpy(pItemSSID->abySSID, param->u.wpa_associate.ssid, pItemSSID->len);
	// set bssid
	if (memcmp(param->u.wpa_associate.bssid, &abyNullAddr[0], 6) != 0)
		memcpy(pMgmt->abyDesireBSSID, param->u.wpa_associate.bssid, 6);
	else {
		bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pItemSSID->abySSID);
	}

	if (param->u.wpa_associate.wpa_ie_len == 0) {
		if (param->u.wpa_associate.auth_alg & AUTH_ALG_SHARED_KEY)
			pMgmt->eAuthenMode = WMAC_AUTH_SHAREKEY;
		else
			pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
	} else if (abyWPAIE[0] == RSN_INFO_ELEM) {
		if (param->u.wpa_associate.key_mgmt_suite == KEY_MGMT_PSK)
			pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK;
		else
			pMgmt->eAuthenMode = WMAC_AUTH_WPA2;
	} else {
		if (param->u.wpa_associate.key_mgmt_suite == KEY_MGMT_WPA_NONE)
			pMgmt->eAuthenMode = WMAC_AUTH_WPANONE;
		else if (param->u.wpa_associate.key_mgmt_suite == KEY_MGMT_PSK)
			pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK;
		else
			pMgmt->eAuthenMode = WMAC_AUTH_WPA;
	}

	switch (param->u.wpa_associate.pairwise_suite) {
	case CIPHER_CCMP:
		pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
		break;
	case CIPHER_TKIP:
		pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
		break;
	case CIPHER_WEP40:
	case CIPHER_WEP104:
		pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
		bWepEnabled = true;
		break;
	case CIPHER_NONE:
		if (param->u.wpa_associate.group_suite == CIPHER_CCMP)
			pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
		else
			pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
		break;
	default:
		pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
	}

//DavidWang add for WPA_supplicant support open/share mode

	if (pMgmt->eAuthenMode == WMAC_AUTH_SHAREKEY) {
		pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
		//pMgmt->eAuthenMode = WMAC_AUTH_SHAREKEY;
		pMgmt->bShareKeyAlgorithm = true;
	} else if (pMgmt->eAuthenMode == WMAC_AUTH_OPEN) {
		if (!bWepEnabled)  pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
		else pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
		//pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
	}
//mike save old encryption status
	pDevice->eOldEncryptionStatus = pDevice->eEncryptionStatus;

	if (pDevice->eEncryptionStatus !=  Ndis802_11EncryptionDisabled)
		pDevice->bEncryptionEnable = true;
	else
		pDevice->bEncryptionEnable = false;
	if (!((pMgmt->eAuthenMode == WMAC_AUTH_SHAREKEY) ||
	      ((pMgmt->eAuthenMode == WMAC_AUTH_OPEN) && (bWepEnabled == true))))
		KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
	spin_lock_irq(&pDevice->lock);
	pDevice->bLinkPass = false;
	memset(pMgmt->abyCurrBSSID, 0, 6);
	pMgmt->eCurrState = WMAC_STATE_IDLE;
	netif_stop_queue(pDevice->dev);
/*******search if ap_scan=2 ,which is associating request in hidden ssid mode ****/
	{
		PKnownBSS       pCurr = NULL;
		pCurr = BSSpSearchBSSList(pDevice,
					  pMgmt->abyDesireBSSID,
					  pMgmt->abyDesireSSID,
					  pMgmt->eConfigPHYMode
);

		if (pCurr == NULL) {
			printk("wpa_set_associate---->hidden mode site survey before associate.......\n");
			bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
		}
	}
/****************************************************************/
	bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
	spin_unlock_irq(&pDevice->lock);

	return ret;
}
static int device_close(struct net_device *dev)
{
	struct vnt_private *pDevice = netdev_priv(dev);
	struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
	int uu;

	DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_close1\n");
    if (pDevice == NULL)
        return -ENODEV;

    if (pDevice->bLinkPass) {
	bScheduleCommand((void *) pDevice, WLAN_CMD_DISASSOCIATE, NULL);
        mdelay(30);
    }

        memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
        pMgmt->bShareKeyAlgorithm = false;
        pDevice->bEncryptionEnable = false;
        pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
	spin_lock_irq(&pDevice->lock);
	for (uu = 0; uu < MAX_KEY_TABLE; uu++)
                MACvDisableKeyEntry(pDevice,uu);
	spin_unlock_irq(&pDevice->lock);

    if ((pDevice->flags & DEVICE_FLAGS_UNPLUG) == false) {
        MACbShutdown(pDevice);
    }
    netif_stop_queue(pDevice->dev);
    MP_SET_FLAG(pDevice, fMP_DISCONNECTED);
    MP_CLEAR_FLAG(pDevice, fMP_POST_WRITES);
    MP_CLEAR_FLAG(pDevice, fMP_POST_READS);
    pDevice->fKillEventPollingThread = true;

	cancel_delayed_work_sync(&pDevice->run_command_work);
	cancel_delayed_work_sync(&pDevice->second_callback_work);

    if (pDevice->bDiversityRegCtlON) {
        del_timer(&pDevice->TimerSQ3Tmax1);
        del_timer(&pDevice->TimerSQ3Tmax2);
        del_timer(&pDevice->TimerSQ3Tmax3);
    }

	cancel_work_sync(&pDevice->rx_mng_work_item);
	cancel_work_sync(&pDevice->read_work_item);

    tasklet_kill(&pDevice->EventWorkItem);

   pDevice->bRoaming = false;
   pDevice->bIsRoaming = false;
   pDevice->bEnableRoaming = false;
    pDevice->bCmdRunning = false;
    pDevice->bLinkPass = false;
    memset(pMgmt->abyCurrBSSID, 0, 6);
    pMgmt->eCurrState = WMAC_STATE_IDLE;

	pDevice->flags &= ~DEVICE_FLAGS_OPENED;

    device_free_tx_bufs(pDevice);
    device_free_rx_bufs(pDevice);
    device_free_int_bufs(pDevice);
    device_free_frag_bufs(pDevice);

	usb_kill_urb(pDevice->pInterruptURB);
    usb_free_urb(pDevice->pInterruptURB);

    BSSvClearNodeDBTable(pDevice, 0);

    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_close2 \n");

    return 0;
}
static int  device_open(struct net_device *dev)
{
	struct vnt_private *pDevice = netdev_priv(dev);

     pDevice->fWPA_Authened = false;

    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " device_open...\n");

    pDevice->rx_buf_sz = MAX_TOTAL_SIZE_WITH_ALL_HEADERS;

    if (device_alloc_bufs(pDevice) == false) {
        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " device_alloc_bufs fail... \n");
        return -ENOMEM;
    }

    if (device_init_defrag_cb(pDevice)== false) {
        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Initial defragment cb fail \n");
        goto free_rx_tx;
    }

    MP_CLEAR_FLAG(pDevice, fMP_DISCONNECTED);
    MP_CLEAR_FLAG(pDevice, fMP_CONTROL_READS);
    MP_CLEAR_FLAG(pDevice, fMP_CONTROL_WRITES);
    MP_SET_FLAG(pDevice, fMP_POST_READS);
    MP_SET_FLAG(pDevice, fMP_POST_WRITES);

    /* read config file */
    Read_config_file(pDevice);

    if (device_init_registers(pDevice, DEVICE_INIT_COLD) == false) {
        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " init register fail\n");
        goto free_all;
    }

    device_set_multi(pDevice->dev);

    /* init for key management */
    KeyvInitTable(pDevice,&pDevice->sKey);
	memcpy(pDevice->vnt_mgmt.abyMACAddr,
		pDevice->abyCurrentNetAddr, ETH_ALEN);
    memcpy(pDevice->dev->dev_addr, pDevice->abyCurrentNetAddr, ETH_ALEN);
    pDevice->bStopTx0Pkt = false;
    pDevice->bStopDataPkt = false;
    pDevice->bRoaming = false;
    pDevice->bIsRoaming = false;
    pDevice->bEnableRoaming = false;
    if (pDevice->bDiversityRegCtlON) {
        device_init_diversity_timer(pDevice);
    }

    vMgrObjectInit(pDevice);

    tasklet_init(&pDevice->EventWorkItem, (void *)INTvWorkItem, (unsigned long)pDevice);

	schedule_delayed_work(&pDevice->second_callback_work, HZ);

	pDevice->int_interval = 100;  /* max 100 microframes */
    pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;

    pDevice->bIsRxWorkItemQueued = true;
    pDevice->fKillEventPollingThread = false;
    pDevice->bEventAvailable = false;

   pDevice->bWPADEVUp = false;
     pDevice->bwextstep0 = false;
     pDevice->bwextstep1 = false;
     pDevice->bwextstep2 = false;
     pDevice->bwextstep3 = false;
     pDevice->bWPASuppWextEnabled = false;
    pDevice->byReAssocCount = 0;

	schedule_work(&pDevice->read_work_item);
    INTvWorkItem(pDevice);

    /* if WEP key already set by iwconfig but device not yet open */
    if ((pDevice->bEncryptionEnable == true) && (pDevice->bTransmitKey == true)) {
         spin_lock_irq(&pDevice->lock);
         KeybSetDefaultKey( pDevice,
                            &(pDevice->sKey),
                            pDevice->byKeyIndex | (1 << 31),
                            pDevice->uKeyLength,
                            NULL,
                            pDevice->abyKey,
                            KEY_CTL_WEP
                          );
         spin_unlock_irq(&pDevice->lock);
         pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
    }

	if (pDevice->vnt_mgmt.eConfigMode == WMAC_CONFIG_AP)
		bScheduleCommand((void *) pDevice, WLAN_CMD_RUN_AP, NULL);
	else
		bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, NULL);

    netif_stop_queue(pDevice->dev);
    pDevice->flags |= DEVICE_FLAGS_OPENED;

	DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_open success..\n");
	return 0;

free_all:
    device_free_frag_bufs(pDevice);
free_rx_tx:
    device_free_rx_bufs(pDevice);
    device_free_tx_bufs(pDevice);
    device_free_int_bufs(pDevice);
	usb_kill_urb(pDevice->pInterruptURB);
    usb_free_urb(pDevice->pInterruptURB);

    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_open fail.. \n");
    return -ENOMEM;
}
Example #8
0
int private_ioctl(PSDevice pDevice, struct ifreq *rq)
{
	PSCmdRequest	pReq = (PSCmdRequest)rq;
	PSMgmtObject	pMgmt = pDevice->pMgmt;
	int		result = 0;
	PWLAN_IE_SSID	pItemSSID;
	SCmdBSSJoin	sJoinCmd;
	SCmdZoneTypeSet	sZoneTypeCmd;
	SCmdScan	sScanCmd;
	SCmdStartAP	sStartAPCmd;
	SCmdSetWEP	sWEPCmd;
	SCmdValue	sValue;
	SBSSIDList	sList;
	SNodeList	sNodeList;
	PSBSSIDList	pList;
	PSNodeList	pNodeList;
	unsigned int	cbListCount;
	PKnownBSS	pBSS;
	PKnownNodeDB	pNode;
	unsigned int	ii, jj;
	unsigned char	abySuppRates[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16};
	unsigned char	abyNullAddr[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
	unsigned long	dwKeyIndex = 0;
	unsigned char	abyScanSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
	long		ldBm;

	pReq->wResult = 0;

	switch (pReq->wCmdCode) {
	case WLAN_CMD_BSS_SCAN:
		DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_BSS_SCAN..begin\n");
		if (copy_from_user(&sScanCmd, pReq->data, sizeof(SCmdScan))) {
			result = -EFAULT;
			break;
		}

		pItemSSID = (PWLAN_IE_SSID)sScanCmd.ssid;
		if (pItemSSID->len > WLAN_SSID_MAXLEN + 1)
			return -EINVAL;
		if (pItemSSID->len != 0) {
			memset(abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
			memcpy(abyScanSSID, pItemSSID, pItemSSID->len + WLAN_IEHDR_LEN);
		}

		if (pDevice->bMACSuspend == true) {
			if (pDevice->bRadioOff == true)
				CARDbRadioPowerOn(pDevice);
			vMgrTimerInit(pDevice);
			MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
			add_timer(&pMgmt->sTimerSecondCallback);
			pDevice->bMACSuspend = false;
		}
		spin_lock_irq(&pDevice->lock);
		if (memcmp(pMgmt->abyCurrBSSID, &abyNullAddr[0], 6) == 0)
			BSSvClearBSSList((void *)pDevice, false);
		else
			BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);

		if (pItemSSID->len != 0)
			bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, abyScanSSID);
		else
			bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
		spin_unlock_irq(&pDevice->lock);
		break;

	case WLAN_CMD_ZONETYPE_SET:
		/* mike add :can't support. */
		result = -EOPNOTSUPP;
		break;

		if (copy_from_user(&sZoneTypeCmd, pReq->data, sizeof(SCmdZoneTypeSet))) {
			result = -EFAULT;
			break;
		}

		if (sZoneTypeCmd.bWrite == true) {
			/* write zonetype */
			if (sZoneTypeCmd.ZoneType == ZoneType_USA) {
				/* set to USA */
				pr_debug("set_ZoneType:USA\n");
			} else if (sZoneTypeCmd.ZoneType == ZoneType_Japan) {
				/* set to Japan */
				pr_debug("set_ZoneType:Japan\n");
			} else if (sZoneTypeCmd.ZoneType == ZoneType_Europe) {
				/* set to Europe */
				pr_debug("set_ZoneType:Europe\n");
			}
		} else {
			/* read zonetype */
			unsigned char zonetype = 0;

			if (zonetype == 0x00) {		/* USA */
				sZoneTypeCmd.ZoneType = ZoneType_USA;
			} else if (zonetype == 0x01) {	/* Japan */
				sZoneTypeCmd.ZoneType = ZoneType_Japan;
			} else if (zonetype == 0x02) {	/* Europe */
				sZoneTypeCmd.ZoneType = ZoneType_Europe;
			} else {			/* Unknown ZoneType */
				pr_err("Error:ZoneType[%x] Unknown ???\n", zonetype);
				result = -EFAULT;
				break;
			}
			if (copy_to_user(pReq->data, &sZoneTypeCmd, sizeof(SCmdZoneTypeSet))) {
				result = -EFAULT;
				break;
			}
		}
		break;

	case WLAN_CMD_BSS_JOIN:
		if (pDevice->bMACSuspend == true) {
			if (pDevice->bRadioOff == true)
				CARDbRadioPowerOn(pDevice);
			vMgrTimerInit(pDevice);
			MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
			add_timer(&pMgmt->sTimerSecondCallback);
			pDevice->bMACSuspend = false;
		}

		if (copy_from_user(&sJoinCmd, pReq->data, sizeof(SCmdBSSJoin))) {
			result = -EFAULT;
			break;
		}

		pItemSSID = (PWLAN_IE_SSID)sJoinCmd.ssid;
		if (pItemSSID->len > WLAN_SSID_MAXLEN + 1)
			return -EINVAL;
		memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
		memcpy(pMgmt->abyDesireSSID, pItemSSID, pItemSSID->len + WLAN_IEHDR_LEN);
		if (sJoinCmd.wBSSType == ADHOC) {
			pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA;
			DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ioct set to adhoc mode\n");
		} else {
			pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
			DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ioct set to STA mode\n");
		}
		if (sJoinCmd.bPSEnable == true) {
			pDevice->ePSMode = WMAC_POWER_FAST;
			pMgmt->wListenInterval = 2;
			DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Power Saving On\n");
		} else {
			pDevice->ePSMode = WMAC_POWER_CAM;
			pMgmt->wListenInterval = 1;
			DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Power Saving Off\n");
		}

		if (sJoinCmd.bShareKeyAuth == true) {
			pMgmt->bShareKeyAlgorithm = true;
			DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Share Key\n");
		} else {
			pMgmt->bShareKeyAlgorithm = false;
			DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Open System\n");
		}
		pDevice->uChannel = sJoinCmd.uChannel;
		netif_stop_queue(pDevice->dev);
		spin_lock_irq(&pDevice->lock);
		pMgmt->eCurrState = WMAC_STATE_IDLE;
		bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
		bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
		spin_unlock_irq(&pDevice->lock);
		break;

	case WLAN_CMD_SET_WEP:
		DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_SET_WEP Key.\n");
		memset(&sWEPCmd, 0, sizeof(SCmdSetWEP));
		if (copy_from_user(&sWEPCmd, pReq->data, sizeof(SCmdSetWEP))) {
			result = -EFAULT;
			break;
		}
		if (sWEPCmd.bEnableWep != true) {
			pDevice->bEncryptionEnable = false;
			pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
			MACvDisableDefaultKey(pDevice->PortOffset);
			DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WEP function disable.\n");
			break;
		}

		for (ii = 0; ii < WLAN_WEP_NKEYS; ii++) {
			if (sWEPCmd.bWepKeyAvailable[ii]) {
				if (ii == sWEPCmd.byKeyIndex)
					dwKeyIndex = ii | (1 << 31);
				else
					dwKeyIndex = ii;

				KeybSetDefaultKey(&(pDevice->sKey),
						  dwKeyIndex,
						  sWEPCmd.auWepKeyLength[ii],
						  NULL,
						  (unsigned char *)&sWEPCmd.abyWepKey[ii][0],
						  KEY_CTL_WEP,
						  pDevice->PortOffset,
						  pDevice->byLocalID);
			}
		}
		pDevice->byKeyIndex = sWEPCmd.byKeyIndex;
		pDevice->bTransmitKey = true;
		pDevice->bEncryptionEnable = true;
		pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
		break;

	case WLAN_CMD_GET_LINK: {
		SCmdLinkStatus sLinkStatus;

		DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_GET_LINK status.\n");

		memset(&sLinkStatus, 0, sizeof(sLinkStatus));

		if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)
			sLinkStatus.wBSSType = ADHOC;
		else
			sLinkStatus.wBSSType = INFRA;

		if (pMgmt->eCurrState == WMAC_STATE_JOINTED)
			sLinkStatus.byState = ADHOC_JOINTED;
		else
			sLinkStatus.byState = ADHOC_STARTED;

		sLinkStatus.uChannel = pMgmt->uCurrChannel;
		if (pDevice->bLinkPass == true) {
			sLinkStatus.bLink = true;
			pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
			memcpy(sLinkStatus.abySSID, pItemSSID->abySSID, pItemSSID->len);
			memcpy(sLinkStatus.abyBSSID, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
			sLinkStatus.uLinkRate = pMgmt->sNodeDBTable[0].wTxDataRate;
			DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Link Success!\n");
		} else {
			sLinkStatus.bLink = false;
			sLinkStatus.uLinkRate = 0;
		}
		if (copy_to_user(pReq->data, &sLinkStatus, sizeof(SCmdLinkStatus))) {
			result = -EFAULT;
			break;
		}
		break;
	}
	case WLAN_CMD_GET_LISTLEN:
		cbListCount = 0;
		pBSS = &(pMgmt->sBSSList[0]);
		for (ii = 0; ii < MAX_BSS_NUM; ii++) {
			pBSS = &(pMgmt->sBSSList[ii]);
			if (!pBSS->bActive)
				continue;
			cbListCount++;
		}
		sList.uItem = cbListCount;
		if (copy_to_user(pReq->data, &sList, sizeof(SBSSIDList))) {
			result = -EFAULT;
			break;
		}
		pReq->wResult = 0;
		break;

	case WLAN_CMD_GET_LIST:
		if (copy_from_user(&sList, pReq->data, sizeof(SBSSIDList))) {
			result = -EFAULT;
			break;
		}
		if (sList.uItem > (ULONG_MAX - sizeof(SBSSIDList)) / sizeof(SBSSIDItem)) {
			result = -EINVAL;
			break;
		}
		pList = (PSBSSIDList)kmalloc(sizeof(SBSSIDList) + (sList.uItem * sizeof(SBSSIDItem)),
					     GFP_ATOMIC);
		if (pList == NULL) {
			result = -ENOMEM;
			break;
		}
		pList->uItem = sList.uItem;
		pBSS = &(pMgmt->sBSSList[0]);
		for (ii = 0, jj = 0; jj < MAX_BSS_NUM; jj++) {
			pBSS = &(pMgmt->sBSSList[jj]);
			if (pBSS->bActive) {
				pList->sBSSIDList[ii].uChannel = pBSS->uChannel;
				pList->sBSSIDList[ii].wBeaconInterval = pBSS->wBeaconInterval;
				pList->sBSSIDList[ii].wCapInfo = pBSS->wCapInfo;
				RFvRSSITodBm(pDevice, (unsigned char)(pBSS->uRSSI), &ldBm);
				pList->sBSSIDList[ii].uRSSI = (unsigned int)ldBm;
				memcpy(pList->sBSSIDList[ii].abyBSSID, pBSS->abyBSSID, WLAN_BSSID_LEN);
				pItemSSID = (PWLAN_IE_SSID)pBSS->abySSID;
				memset(pList->sBSSIDList[ii].abySSID, 0, WLAN_SSID_MAXLEN + 1);
				memcpy(pList->sBSSIDList[ii].abySSID, pItemSSID->abySSID, pItemSSID->len);
				if (WLAN_GET_CAP_INFO_ESS(pBSS->wCapInfo))
					pList->sBSSIDList[ii].byNetType = INFRA;
				else
					pList->sBSSIDList[ii].byNetType = ADHOC;

				if (WLAN_GET_CAP_INFO_PRIVACY(pBSS->wCapInfo))
					pList->sBSSIDList[ii].bWEPOn = true;
				else
					pList->sBSSIDList[ii].bWEPOn = false;

				ii++;
				if (ii >= pList->uItem)
					break;
			}
		}

		if (copy_to_user(pReq->data, pList, sizeof(SBSSIDList) + (sList.uItem * sizeof(SBSSIDItem)))) {
			result = -EFAULT;
			break;
		}
		kfree(pList);
		pReq->wResult = 0;
		break;

	case WLAN_CMD_GET_MIB:
		if (copy_to_user(pReq->data, &(pDevice->s802_11Counter), sizeof(SDot11MIBCount))) {
			result = -EFAULT;
			break;
		}
		break;

	case WLAN_CMD_GET_STAT:
		if (copy_to_user(pReq->data, &(pDevice->scStatistic), sizeof(SStatCounter))) {
			result = -EFAULT;
			break;
		}
		break;

	case WLAN_CMD_STOP_MAC:
		DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_STOP_MAC\n");
		netif_stop_queue(pDevice->dev);

		spin_lock_irq(&pDevice->lock);
		if (pDevice->bRadioOff == false)
			CARDbRadioPowerOff(pDevice);

		pDevice->bLinkPass = false;
		memset(pMgmt->abyCurrBSSID, 0, 6);
		pMgmt->eCurrState = WMAC_STATE_IDLE;
		del_timer(&pDevice->sTimerCommand);
		del_timer(&pMgmt->sTimerSecondCallback);
		pDevice->bCmdRunning = false;
		pDevice->bMACSuspend = true;
		MACvIntDisable(pDevice->PortOffset);
		spin_unlock_irq(&pDevice->lock);
		break;

	case WLAN_CMD_START_MAC:
		DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_START_MAC\n");

		if (pDevice->bMACSuspend == true) {
			if (pDevice->bRadioOff == true)
				CARDbRadioPowerOn(pDevice);
			vMgrTimerInit(pDevice);
			MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
			add_timer(&pMgmt->sTimerSecondCallback);
			pDevice->bMACSuspend = false;
		}
		break;

	case WLAN_CMD_SET_HOSTAPD:
		DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_SET_HOSTAPD\n");

		if (copy_from_user(&sValue, pReq->data, sizeof(SCmdValue))) {
			result = -EFAULT;
			break;
		}
		if (sValue.dwValue == 1) {
			if (vt6655_hostap_set_hostapd(pDevice, 1, 1) == 0) {
				DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable HOSTAP\n");
			} else {
				result = -EFAULT;
				break;
			}
		} else {
			vt6655_hostap_set_hostapd(pDevice, 0, 1);
			DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable HOSTAP\n");
		}
		break;

	case WLAN_CMD_SET_HOSTAPD_STA:
		DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_SET_HOSTAPD_STA\n");
		break;

	case WLAN_CMD_SET_802_1X:
		DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_SET_802_1X\n");
		if (copy_from_user(&sValue, pReq->data, sizeof(SCmdValue))) {
			result = -EFAULT;
			break;
		}

		if (sValue.dwValue == 1) {
			pDevice->bEnable8021x = true;
			DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable 802.1x\n");
		} else {
			pDevice->bEnable8021x = false;
			DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable 802.1x\n");
		}
		break;

	case WLAN_CMD_SET_HOST_WEP:
		DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_SET_HOST_WEP\n");
		if (copy_from_user(&sValue, pReq->data, sizeof(SCmdValue))) {
			result = -EFAULT;
			break;
		}

		if (sValue.dwValue == 1) {
			pDevice->bEnableHostWEP = true;
			DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable HostWEP\n");
		} else {
			pDevice->bEnableHostWEP = false;
			DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable HostWEP\n");
		}
		break;

	case WLAN_CMD_SET_WPA:
		DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_SET_WPA\n");

		if (copy_from_user(&sValue, pReq->data, sizeof(SCmdValue))) {
			result = -EFAULT;
			break;
		}
		if (sValue.dwValue == 1) {
			DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "up wpadev\n");
			eth_hw_addr_inherit(pDevice->wpadev, pDevice->dev);
			pDevice->bWPADEVUp = true;
		} else {
			DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "close wpadev\n");
			pDevice->bWPADEVUp = false;
		}
		break;

	case WLAN_CMD_AP_START:
		DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_AP_START\n");
		if (pDevice->bRadioOff == true) {
			CARDbRadioPowerOn(pDevice);
			vMgrTimerInit(pDevice);
			MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
			add_timer(&pMgmt->sTimerSecondCallback);
		}
		if (copy_from_user(&sStartAPCmd, pReq->data, sizeof(SCmdStartAP))) {
			result = -EFAULT;
			break;
		}

		if (sStartAPCmd.wBSSType == AP) {
			pMgmt->eConfigMode = WMAC_CONFIG_AP;
			DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ioct set to AP mode\n");
		} else {
			DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ioct BSS type not set to AP mode\n");
			result = -EFAULT;
			break;
		}

		if (sStartAPCmd.wBBPType == PHY80211g)
			pMgmt->byAPBBType = PHY_TYPE_11G;
		else if (sStartAPCmd.wBBPType == PHY80211a)
			pMgmt->byAPBBType = PHY_TYPE_11A;
		else
			pMgmt->byAPBBType = PHY_TYPE_11B;

		pItemSSID = (PWLAN_IE_SSID)sStartAPCmd.ssid;
		if (pItemSSID->len > WLAN_SSID_MAXLEN + 1)
			return -EINVAL;
		memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
		memcpy(pMgmt->abyDesireSSID, pItemSSID, pItemSSID->len + WLAN_IEHDR_LEN);

		if ((sStartAPCmd.uChannel > 0) && (sStartAPCmd.uChannel <= 14))
			pDevice->uChannel = sStartAPCmd.uChannel;

		if ((sStartAPCmd.uBeaconInt >= 20) && (sStartAPCmd.uBeaconInt <= 1000))
			pMgmt->wIBSSBeaconPeriod = sStartAPCmd.uBeaconInt;
		else
			pMgmt->wIBSSBeaconPeriod = 100;

		if (sStartAPCmd.bShareKeyAuth == true) {
			pMgmt->bShareKeyAlgorithm = true;
			DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Share Key\n");
		} else {
			pMgmt->bShareKeyAlgorithm = false;
			DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Open System\n");
		}
		memcpy(pMgmt->abyIBSSSuppRates, abySuppRates, 6);

		if (sStartAPCmd.byBasicRate & BIT3) {
			pMgmt->abyIBSSSuppRates[2] |= BIT7;
			pMgmt->abyIBSSSuppRates[3] |= BIT7;
			pMgmt->abyIBSSSuppRates[4] |= BIT7;
			pMgmt->abyIBSSSuppRates[5] |= BIT7;
		} else if (sStartAPCmd.byBasicRate & BIT2) {
			pMgmt->abyIBSSSuppRates[2] |= BIT7;
			pMgmt->abyIBSSSuppRates[3] |= BIT7;
			pMgmt->abyIBSSSuppRates[4] |= BIT7;
		} else if (sStartAPCmd.byBasicRate & BIT1) {
			pMgmt->abyIBSSSuppRates[2] |= BIT7;
			pMgmt->abyIBSSSuppRates[3] |= BIT7;
		} else if (sStartAPCmd.byBasicRate & BIT1) {
			pMgmt->abyIBSSSuppRates[2] |= BIT7;
		} else {
			/* default 1,2M */
			pMgmt->abyIBSSSuppRates[2] |= BIT7;
			pMgmt->abyIBSSSuppRates[3] |= BIT7;
		}

		DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Support Rate= %*ph\n",
			4, pMgmt->abyIBSSSuppRates + 2);

		netif_stop_queue(pDevice->dev);
		spin_lock_irq(&pDevice->lock);
		bScheduleCommand((void *)pDevice, WLAN_CMD_RUN_AP, NULL);
		spin_unlock_irq(&pDevice->lock);
		break;

	case WLAN_CMD_GET_NODE_CNT:
		cbListCount = 0;
		pNode = &(pMgmt->sNodeDBTable[0]);
		for (ii = 0; ii < (MAX_NODE_NUM + 1); ii++) {
			pNode = &(pMgmt->sNodeDBTable[ii]);
			if (!pNode->bActive)
				continue;
			cbListCount++;
		}

		sNodeList.uItem = cbListCount;
		if (copy_to_user(pReq->data, &sNodeList, sizeof(SNodeList))) {
			result = -EFAULT;
			break;
		}
		pReq->wResult = 0;
		break;

	case WLAN_CMD_GET_NODE_LIST:
		if (copy_from_user(&sNodeList, pReq->data, sizeof(SNodeList))) {
			result = -EFAULT;
			break;
		}
		if (sNodeList.uItem > (ULONG_MAX - sizeof(SNodeList)) / sizeof(SNodeItem)) {
			result = -EINVAL;
			break;
		}
		pNodeList = (PSNodeList)kmalloc(sizeof(SNodeList) + (sNodeList.uItem * sizeof(SNodeItem)),
						GFP_ATOMIC);
		if (pNodeList == NULL) {
			result = -ENOMEM;
			break;
		}
		pNodeList->uItem = sNodeList.uItem;
		pNode = &(pMgmt->sNodeDBTable[0]);
		for (ii = 0, jj = 0; ii < (MAX_NODE_NUM + 1); ii++) {
			pNode = &(pMgmt->sNodeDBTable[ii]);
			if (pNode->bActive) {
				pNodeList->sNodeList[jj].wAID = pNode->wAID;
				memcpy(pNodeList->sNodeList[jj].abyMACAddr, pNode->abyMACAddr, WLAN_ADDR_LEN);
				pNodeList->sNodeList[jj].wTxDataRate = pNode->wTxDataRate;
				pNodeList->sNodeList[jj].wInActiveCount = (unsigned short)pNode->uInActiveCount;
				pNodeList->sNodeList[jj].wEnQueueCnt = (unsigned short)pNode->wEnQueueCnt;
				pNodeList->sNodeList[jj].wFlags = (unsigned short)pNode->dwFlags;
				pNodeList->sNodeList[jj].bPWBitOn = pNode->bPSEnable;
				pNodeList->sNodeList[jj].byKeyIndex = pNode->byKeyIndex;
				pNodeList->sNodeList[jj].wWepKeyLength = pNode->uWepKeyLength;
				memcpy(&(pNodeList->sNodeList[jj].abyWepKey[0]), &(pNode->abyWepKey[0]), WEP_KEYMAXLEN);
				DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "key= %2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
					pNodeList->sNodeList[jj].abyWepKey[0],
					pNodeList->sNodeList[jj].abyWepKey[1],
					pNodeList->sNodeList[jj].abyWepKey[2],
					pNodeList->sNodeList[jj].abyWepKey[3],
					pNodeList->sNodeList[jj].abyWepKey[4]);
				pNodeList->sNodeList[jj].bIsInFallback = pNode->bIsInFallback;
				pNodeList->sNodeList[jj].uTxFailures = pNode->uTxFailures;
				pNodeList->sNodeList[jj].uTxAttempts = pNode->uTxAttempts;
				pNodeList->sNodeList[jj].wFailureRatio = (unsigned short)pNode->uFailureRatio;
				jj++;
				if (jj >= pNodeList->uItem)
					break;
			}
		}
		if (copy_to_user(pReq->data, pNodeList, sizeof(SNodeList) + (sNodeList.uItem * sizeof(SNodeItem)))) {
			result = -EFAULT;
			break;
		}
		kfree(pNodeList);
		pReq->wResult = 0;
		break;

#ifdef WPA_SM_Transtatus
	case 0xFF:
		memset(wpa_Result.ifname, 0, sizeof(wpa_Result.ifname));
		wpa_Result.proto = 0;
		wpa_Result.key_mgmt = 0;
		wpa_Result.eap_type = 0;
		wpa_Result.authenticated = false;
		pDevice->fWPA_Authened = false;
		if (copy_from_user(&wpa_Result, pReq->data, sizeof(wpa_Result))) {
			result = -EFAULT;
			break;
		}

		if (wpa_Result.authenticated == true) {
#ifdef SndEvt_ToAPI
			{
				union iwreq_data wrqu;

				pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;

				memset(&wrqu, 0, sizeof(wrqu));
				wrqu.data.flags = RT_WPACONNECTED_EVENT_FLAG;
				wrqu.data.length = pItemSSID->len;
				wireless_send_event(pDevice->dev, IWEVCUSTOM, &wrqu, pItemSSID->abySSID);
			}
#endif
			pDevice->fWPA_Authened = true; /* is successful peer to wpa_Result.authenticated? */
		}
		pReq->wResult = 0;
		break;
#endif

	default:
		DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Private command not support..\n");
	}

	return result;
}
Example #9
0
static int wpa_set_associate(PSDevice pDevice,
				     struct viawget_wpa_param *param)
{
    PSMgmtObject    pMgmt = &(pDevice->sMgmtObj);
    PWLAN_IE_SSID   pItemSSID;
    BYTE    abyNullAddr[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
    BYTE    abyWPAIE[64];
    int ret = 0;
    BOOL   bwepEnabled=FALSE;

	// set key type & algorithm
    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pairwise_suite = %d\n", param->u.wpa_associate.pairwise_suite);
    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "group_suite = %d\n", param->u.wpa_associate.group_suite);
    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "key_mgmt_suite = %d\n", param->u.wpa_associate.key_mgmt_suite);
    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "auth_alg = %d\n", param->u.wpa_associate.auth_alg);
    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "mode = %d\n", param->u.wpa_associate.mode);
    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wpa_ie_len = %d\n", param->u.wpa_associate.wpa_ie_len);
    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Roaming dBm = %d\n", param->u.wpa_associate.roam_dbm);  //Davidwang

	if (param->u.wpa_associate.wpa_ie &&
	    copy_from_user(&abyWPAIE[0], param->u.wpa_associate.wpa_ie, param->u.wpa_associate.wpa_ie_len))
	    return -EINVAL;

	if (param->u.wpa_associate.mode == 1)
	    pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA;
	else
	    pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;

	// set bssid
    if (memcmp(param->u.wpa_associate.bssid, &abyNullAddr[0], 6) != 0)
        memcpy(pMgmt->abyDesireBSSID, param->u.wpa_associate.bssid, 6);
    // set ssid
	memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
    pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
    pItemSSID->byElementID = WLAN_EID_SSID;
	pItemSSID->len = param->u.wpa_associate.ssid_len;
	memcpy(pItemSSID->abySSID, param->u.wpa_associate.ssid, pItemSSID->len);

    if (param->u.wpa_associate.wpa_ie_len == 0) {
	    if (param->u.wpa_associate.auth_alg & AUTH_ALG_SHARED_KEY)
            pMgmt->eAuthenMode = WMAC_AUTH_SHAREKEY;
	    else
            pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
	} else if (abyWPAIE[0] == RSN_INFO_ELEM) {
		if (param->u.wpa_associate.key_mgmt_suite == KEY_MGMT_PSK)
			pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK;
		else
			pMgmt->eAuthenMode = WMAC_AUTH_WPA2;
	} else {
		if (param->u.wpa_associate.key_mgmt_suite == KEY_MGMT_WPA_NONE)
			pMgmt->eAuthenMode = WMAC_AUTH_WPANONE;
		else if (param->u.wpa_associate.key_mgmt_suite == KEY_MGMT_PSK)
		    pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK;
		else
		    pMgmt->eAuthenMode = WMAC_AUTH_WPA;
	}

	switch (param->u.wpa_associate.pairwise_suite) {
	case CIPHER_CCMP:
		pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
		break;
	case CIPHER_TKIP:
		pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
		break;
	case CIPHER_WEP40:
	case CIPHER_WEP104:
		pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
		bwepEnabled = TRUE;
	//	printk("****************wpa_set_associate:set CIPHER_WEP40_104\n");
		break;
	case CIPHER_NONE:
		if (param->u.wpa_associate.group_suite == CIPHER_CCMP)
			pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
		else
			pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
		break;
	default:
		pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
	};

           pMgmt->Roam_dbm = param->u.wpa_associate.roam_dbm;
         // if ((pMgmt->Roam_dbm > 40)&&(pMgmt->Roam_dbm<80))
         //    pDevice->bEnableRoaming = TRUE;

	    if (pMgmt->eAuthenMode == WMAC_AUTH_SHAREKEY) {   //@wep-sharekey
            pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
            pMgmt->bShareKeyAlgorithm = TRUE;
             }
	    else if (pMgmt->eAuthenMode == WMAC_AUTH_OPEN) {
	       if(bwepEnabled==TRUE) {                                                         //@open-wep
                       pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
	   	}
	      else {                                                                                                 //@only open
            pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
	   	}
           }
//mike save old encryption status
	pDevice->eOldEncryptionStatus = pDevice->eEncryptionStatus;

    if (pDevice->eEncryptionStatus !=  Ndis802_11EncryptionDisabled)
        pDevice->bEncryptionEnable = TRUE;
    else
        pDevice->bEncryptionEnable = FALSE;

 if ((pMgmt->eAuthenMode == WMAC_AUTH_SHAREKEY) ||
      ((pMgmt->eAuthenMode == WMAC_AUTH_OPEN) && (bwepEnabled==TRUE)))  {
 //mike re-comment:open-wep && sharekey-wep needn't do initial key!!

     }
 else
    KeyvInitTable(pDevice,&pDevice->sKey);

    spin_lock_irq(&pDevice->lock);
    pDevice->bLinkPass = FALSE;
    ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
    memset(pMgmt->abyCurrBSSID, 0, 6);
    pMgmt->eCurrState = WMAC_STATE_IDLE;
    netif_stop_queue(pDevice->dev);

/*******search if ap_scan=2 ,which is associating request in hidden ssid mode ****/
{
   PKnownBSS       pCurr = NULL;
    pCurr = BSSpSearchBSSList(pDevice,
                              pMgmt->abyDesireBSSID,
                              pMgmt->abyDesireSSID,
                              pDevice->eConfigPHYMode
                              );

    if (pCurr == NULL){
    printk("wpa_set_associate---->hidden mode site survey before associate.......\n");
    bScheduleCommand((void *) pDevice,
		     WLAN_CMD_BSSID_SCAN,
		     pMgmt->abyDesireSSID);
  };
}
/****************************************************************/

    bScheduleCommand((void *) pDevice, WLAN_CMD_SSID, NULL);
    spin_unlock_irq(&pDevice->lock);

    return ret;
}
int iwctl_siwscan(struct net_device *dev,
             struct iw_request_info *info,
			 struct iw_point *wrq,
             char *extra)
{
	PSDevice	        pDevice = (PSDevice)netdev_priv(dev);
	 PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
	struct iw_scan_req  *req = (struct iw_scan_req *)extra;
	BYTE                abyScanSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
	PWLAN_IE_SSID       pItemSSID=NULL;

  if (!(pDevice->flags & DEVICE_FLAGS_OPENED))
        return -EINVAL;

    PRINT_K(" SIOCSIWSCAN \n");

if (pMgmt->eScanState ==  WMAC_IS_SCANNING) {
        
     PRINT_K("SIOCSIWSCAN(overlap??)-->In scanning...\n");
     return -EAGAIN;
  }

if(pDevice->byReAssocCount > 0) {   
  union iwreq_data wrqu;
 PRINT_K("wireless_send_event--->SIOCGIWSCAN(scan done)\n");
 memset(&wrqu, 0, sizeof(wrqu));
 wireless_send_event(pDevice->dev, SIOCGIWSCAN, &wrqu, NULL);
  return 0;
}

	spin_lock_irq(&pDevice->lock);

	BSSvClearBSSList((void *) pDevice, pDevice->bLinkPass);

 if(wrq->length == sizeof(struct iw_scan_req)) {
   if (wrq->flags & IW_SCAN_THIS_ESSID)  {                               
       memset(abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
       pItemSSID = (PWLAN_IE_SSID)abyScanSSID;
       pItemSSID->byElementID = WLAN_EID_SSID;
       memcpy(pItemSSID->abySSID, req->essid, (int)req->essid_len);
         if (pItemSSID->abySSID[req->essid_len - 1] == '\0') {
           if(req->essid_len>0)
		pItemSSID->len = req->essid_len - 1;
         }
	else
	  pItemSSID->len = req->essid_len;
	  pMgmt->eScanType = WMAC_SCAN_PASSIVE;
         PRINT_K("SIOCSIWSCAN:[desired_ssid=%s,len=%d]\n",((PWLAN_IE_SSID)abyScanSSID)->abySSID,
		 	                                                                                ((PWLAN_IE_SSID)abyScanSSID)->len);
	bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, abyScanSSID);
	spin_unlock_irq(&pDevice->lock);

	return 0;
   }
   else if(req->scan_type == IW_SCAN_TYPE_PASSIVE) {          
       pMgmt->eScanType = WMAC_SCAN_PASSIVE;
   }
 }
 else {           
     pMgmt->eScanType = WMAC_SCAN_ACTIVE;
 }

	 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
	bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
	spin_unlock_irq(&pDevice->lock);

	return 0;
}
int iwctl_siwessid(struct net_device *dev,
             struct iw_request_info *info,
             struct iw_point *wrq,
             char *extra)
{
	PSDevice	        pDevice = (PSDevice)netdev_priv(dev);
    PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
    PWLAN_IE_SSID       pItemSSID;

  if (!(pDevice->flags & DEVICE_FLAGS_OPENED))
        return -EINVAL;

    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWESSID :\n");

         pDevice->fWPA_Authened = FALSE;
	
	if(wrq->flags == 0) {
		
		memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
                  memset(pMgmt->abyDesireBSSID, 0xFF,6);
	    PRINT_K("set essid to 'any' \n");
           #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
             
                  return 0;
            #endif
	} else {
		
		memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
        pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
        pItemSSID->byElementID = WLAN_EID_SSID;

		memcpy(pItemSSID->abySSID, extra, wrq->length);
         if (pItemSSID->abySSID[wrq->length - 1] == '\0') {
           if(wrq->length>0)
		pItemSSID->len = wrq->length - 1;
         }
	else
	  pItemSSID->len = wrq->length;
	PRINT_K("set essid to %s \n",pItemSSID->abySSID);

     
     if(pItemSSID->len==0) {
        memset(pMgmt->abyDesireBSSID, 0xFF,6);
        return 0;
     }

#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
 
 
  if(pDevice->bWPASuppWextEnabled == TRUE)  {
        
        {
           PKnownBSS       pCurr = NULL;
           BYTE                   abyTmpDesireSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
	  unsigned int ii, uSameBssidNum = 0;

	  memcpy(abyTmpDesireSSID,pMgmt->abyDesireSSID,sizeof(abyTmpDesireSSID));
            pCurr = BSSpSearchBSSList(pDevice,
                                      NULL,
                                      abyTmpDesireSSID,
                                      pDevice->eConfigPHYMode
                                      );

            if (pCurr == NULL){
               PRINT_K("SIOCSIWESSID:hidden ssid site survey before associate.......\n");
	      vResetCommandTimer((void *) pDevice);
	      pMgmt->eScanType = WMAC_SCAN_ACTIVE;
	      bScheduleCommand((void *) pDevice,
			       WLAN_CMD_BSSID_SCAN,
			       pMgmt->abyDesireSSID);
	      bScheduleCommand((void *) pDevice,
			       WLAN_CMD_SSID,
			       pMgmt->abyDesireSSID);
          }
	 else {  
                     
                  for (ii = 0; ii < MAX_BSS_NUM; ii++) {
                     if (pMgmt->sBSSList[ii].bActive &&
			 !compare_ether_addr(pMgmt->sBSSList[ii].abyBSSID,
					     pCurr->abyBSSID)) {
                        uSameBssidNum++;
                     }
                  }
	     if(uSameBssidNum >= 2) {  
                 PRINT_K("SIOCSIWESSID:hidden ssid directly associate.......\n");
		 vResetCommandTimer((void *) pDevice);
	        pMgmt->eScanType = WMAC_SCAN_PASSIVE;          
		bScheduleCommand((void *) pDevice,
				 WLAN_CMD_BSSID_SCAN,
				 pMgmt->abyDesireSSID);
		bScheduleCommand((void *) pDevice,
				 WLAN_CMD_SSID,
				 pMgmt->abyDesireSSID);
	     }
	 }
        }
     return 0;
  }
	     #endif

	    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set essid = %s \n", pItemSSID->abySSID);
	}

    if (pDevice->flags & DEVICE_FLAGS_OPENED) {
	    pDevice->bCommit = TRUE;
	}


	return 0;
}
Example #12
0
static int wpa_set_associate(PSDevice pDevice,
				     struct viawget_wpa_param *param)
{
    PSMgmtObject    pMgmt = pDevice->pMgmt;
    PWLAN_IE_SSID   pItemSSID;
    BYTE    abyNullAddr[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
    BYTE    abyWPAIE[64];
    int ret = 0;
    BOOL bWepEnabled=FALSE;

	
    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pairwise_suite = %d\n", param->u.wpa_associate.pairwise_suite);
    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "group_suite = %d\n", param->u.wpa_associate.group_suite);
    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "key_mgmt_suite = %d\n", param->u.wpa_associate.key_mgmt_suite);
    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "auth_alg = %d\n", param->u.wpa_associate.auth_alg);
    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "mode = %d\n", param->u.wpa_associate.mode);
    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wpa_ie_len = %d\n", param->u.wpa_associate.wpa_ie_len);


	if (param->u.wpa_associate.wpa_ie &&
	    copy_from_user(&abyWPAIE[0], param->u.wpa_associate.wpa_ie, param->u.wpa_associate.wpa_ie_len))
	    return -EINVAL;

	if (param->u.wpa_associate.mode == 1)
	    pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA;
	else
	    pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
    
	memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
    pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
    pItemSSID->byElementID = WLAN_EID_SSID;
	pItemSSID->len = param->u.wpa_associate.ssid_len;
	memcpy(pItemSSID->abySSID, param->u.wpa_associate.ssid, pItemSSID->len);
	
    if (memcmp(param->u.wpa_associate.bssid, &abyNullAddr[0], 6) != 0)
        memcpy(pMgmt->abyDesireBSSID, param->u.wpa_associate.bssid, 6);
else
{
   bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, pItemSSID->abySSID);
}

    if (param->u.wpa_associate.wpa_ie_len == 0) {
	    if (param->u.wpa_associate.auth_alg & AUTH_ALG_SHARED_KEY)
            pMgmt->eAuthenMode = WMAC_AUTH_SHAREKEY;
	    else
            pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
	} else if (abyWPAIE[0] == RSN_INFO_ELEM) {
		if (param->u.wpa_associate.key_mgmt_suite == KEY_MGMT_PSK)
			pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK;
		else
			pMgmt->eAuthenMode = WMAC_AUTH_WPA2;
	} else {
		if (param->u.wpa_associate.key_mgmt_suite == KEY_MGMT_WPA_NONE)
			pMgmt->eAuthenMode = WMAC_AUTH_WPANONE;
		else if (param->u.wpa_associate.key_mgmt_suite == KEY_MGMT_PSK)
		    pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK;
		else
		    pMgmt->eAuthenMode = WMAC_AUTH_WPA;
	}

	switch (param->u.wpa_associate.pairwise_suite) {
	case CIPHER_CCMP:
		pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
		break;
	case CIPHER_TKIP:
		pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
		break;
	case CIPHER_WEP40:
	case CIPHER_WEP104:
		pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
		bWepEnabled=TRUE;
		break;
	case CIPHER_NONE:
		if (param->u.wpa_associate.group_suite == CIPHER_CCMP)
			pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
		else
			pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
		break;
	default:
		pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
	};



      if (pMgmt->eAuthenMode == WMAC_AUTH_SHAREKEY) {
            pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
            
            pMgmt->bShareKeyAlgorithm = TRUE;
             }
     else if (pMgmt->eAuthenMode == WMAC_AUTH_OPEN) {
          if(!bWepEnabled)  pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
	else pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
            
            
           }

	pDevice->eOldEncryptionStatus = pDevice->eEncryptionStatus;

    if (pDevice->eEncryptionStatus !=  Ndis802_11EncryptionDisabled)
        pDevice->bEncryptionEnable = TRUE;
    else
        pDevice->bEncryptionEnable = FALSE;
if (!((pMgmt->eAuthenMode == WMAC_AUTH_SHAREKEY) ||
      ((pMgmt->eAuthenMode == WMAC_AUTH_OPEN) && (bWepEnabled==TRUE))) )  
    KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
    spin_lock_irq(&pDevice->lock);
    pDevice->bLinkPass = FALSE;
    memset(pMgmt->abyCurrBSSID, 0, 6);
    pMgmt->eCurrState = WMAC_STATE_IDLE;
    netif_stop_queue(pDevice->dev);
	

{
   PKnownBSS       pCurr = NULL;
    pCurr = BSSpSearchBSSList(pDevice,
                              pMgmt->abyDesireBSSID,
                              pMgmt->abyDesireSSID,
                              pMgmt->eConfigPHYMode
                              );

    if (pCurr == NULL){
    printk("wpa_set_associate---->hidden mode site survey before associate.......\n");
    bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
  };
}

    bScheduleCommand((HANDLE) pDevice, WLAN_CMD_SSID, NULL);
    spin_unlock_irq(&pDevice->lock);

    return ret;
}