static int hostap_disable_hostapd(PSDevice pDevice, int rtnl_locked) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: disabling hostapd mode\n", pDevice->dev->name); if (pDevice->apdev && pDevice->apdev->name && pDevice->apdev->name[0]) { if (rtnl_locked) unregister_netdevice(pDevice->apdev); else unregister_netdev(pDevice->apdev); DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Netdevice %s unregistered\n", pDevice->dev->name, pDevice->apdev->name); } kfree(pDevice->apdev); pDevice->apdev = NULL; pDevice->bEnable8021x = false; pDevice->bEnableHostWEP = false; pDevice->bEncryptionEnable = false; //4.2007-0118-03,<Add> by EinsnLiu //execute some clear work pDevice->pMgmt->byCSSPK=KEY_CTL_NONE; pDevice->pMgmt->byCSSGK=KEY_CTL_NONE; KeyvInitTable(&pDevice->sKey,pDevice->PortOffset); return 0; }
static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked) { PSDevice apdev_priv; struct net_device *dev = pDevice->dev; int ret; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name); pDevice->apdev = kzalloc(sizeof(struct net_device), GFP_KERNEL); if (pDevice->apdev == NULL) return -ENOMEM; apdev_priv = netdev_priv(pDevice->apdev); *apdev_priv = *pDevice; memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN); /* only half broken now */ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211; pDevice->apdev->netdev_ops = &apdev_netdev_ops; pDevice->apdev->type = ARPHRD_IEEE80211; pDevice->apdev->base_addr = dev->base_addr; pDevice->apdev->irq = dev->irq; pDevice->apdev->mem_start = dev->mem_start; pDevice->apdev->mem_end = dev->mem_end; sprintf(pDevice->apdev->name, "%sap", dev->name); if (rtnl_locked) ret = register_netdevice(pDevice->apdev); else ret = register_netdev(pDevice->apdev); if (ret) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: register_netdevice(AP) failed!\n", dev->name); return -1; } DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Registered netdevice %s for AP management\n", dev->name, pDevice->apdev->name); KeyvInitTable(&pDevice->sKey, pDevice->PortOffset); return 0; }
int iwctl_siwmlme(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_mlme *mlme = (struct iw_mlme *)extra; int ret = 0; if(memcmp(pMgmt->abyCurrBSSID, mlme->addr.sa_data, ETH_ALEN)){ ret = -EINVAL; return ret; } switch(mlme->cmd){ case IW_MLME_DEAUTH: break; case IW_MLME_DISASSOC: if(pDevice->bLinkPass == TRUE){ printk("iwctl_siwmlme--->send DISASSOCIATE\n"); memset(pMgmt->abyDesireBSSID, 0xFF,6); KeyvInitTable(&pDevice->sKey, pDevice->PortOffset); bScheduleCommand((HANDLE)pDevice, WLAN_CMD_DISASSOCIATE, NULL); } break; default: ret = -EOPNOTSUPP; } return ret; }
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) == 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; }
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; //pMgmt->bShareKeyAlgorithm = false; //20080717-06,<Modify> by chester//Fix Open mode, WEP encrytion } //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))) ) //DavidWang //20080717-06,<Modify> by chester//Not to initial WEP 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); //20080701-02,<Add> by Mike Liu /*******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; }
int iwctl_siwencodeext(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra) { struct vnt_private *pDevice = netdev_priv(dev); struct vnt_manager *pMgmt = &pDevice->vnt_mgmt; struct iw_point *wrq = &wrqu->encoding; struct iw_encode_ext *ext = (struct iw_encode_ext*)extra; struct viawget_wpa_param *param = NULL; // original member wpa_alg alg_name; u8 addr[6]; int key_idx; int set_tx = 0; u8 seq[IW_ENCODE_SEQ_MAX_SIZE]; u8 key[64]; size_t seq_len = 0; size_t key_len = 0; u8 *buf; u8 key_array[64]; int ret = 0; PRINT_K("SIOCSIWENCODEEXT......\n"); if (pMgmt == NULL) return -EFAULT; if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) return -ENODEV; buf = kzalloc(sizeof(struct viawget_wpa_param), GFP_KERNEL); if (buf == NULL) return -ENOMEM; param = (struct viawget_wpa_param *)buf; // recover alg_name switch (ext->alg) { case IW_ENCODE_ALG_NONE: alg_name = WPA_ALG_NONE; break; case IW_ENCODE_ALG_WEP: alg_name = WPA_ALG_WEP; break; case IW_ENCODE_ALG_TKIP: alg_name = WPA_ALG_TKIP; break; case IW_ENCODE_ALG_CCMP: alg_name = WPA_ALG_CCMP; break; default: PRINT_K("Unknown alg = %d\n", ext->alg); ret = -ENOMEM; goto error; } // recover addr memcpy(addr, ext->addr.sa_data, ETH_ALEN); // recover key_idx key_idx = (wrq->flags&IW_ENCODE_INDEX) - 1; // recover set_tx if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) set_tx = 1; // recover seq,seq_len if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) { seq_len = IW_ENCODE_SEQ_MAX_SIZE; memcpy(seq, ext->rx_seq, seq_len); } // recover key,key_len if (ext->key_len) { key_len = ext->key_len; memcpy(key, &ext->key[0], key_len); } memset(key_array, 0, 64); if (key_len > 0) { memcpy(key_array, key, key_len); if (key_len == 32) { // notice ! the oder memcpy(&key_array[16], &key[24], 8); memcpy(&key_array[24], &key[16], 8); } } /**************Translate iw_encode_ext to viawget_wpa_param****************/ memcpy(param->addr, addr, ETH_ALEN); param->u.wpa_key.alg_name = (int)alg_name; param->u.wpa_key.set_tx = set_tx; param->u.wpa_key.key_index = key_idx; param->u.wpa_key.key_len = key_len; param->u.wpa_key.key = (u8 *)key_array; param->u.wpa_key.seq = (u8 *)seq; param->u.wpa_key.seq_len = seq_len; /****set if current action is Network Manager count?? */ /****this method is so foolish,but there is no other way??? */ if (param->u.wpa_key.alg_name == WPA_ALG_NONE) { if (param->u.wpa_key.key_index == 0) { pDevice->bwextstep0 = true; } if ((pDevice->bwextstep0 == true) && (param->u.wpa_key.key_index == 1)) { pDevice->bwextstep0 = false; pDevice->bwextstep1 = true; } if ((pDevice->bwextstep1 == true) && (param->u.wpa_key.key_index == 2)) { pDevice->bwextstep1 = false; pDevice->bwextstep2 = true; } if ((pDevice->bwextstep2 == true) && (param->u.wpa_key.key_index == 3)) { pDevice->bwextstep2 = false; pDevice->bwextstep3 = true; } } if (pDevice->bwextstep3 == true) { PRINT_K("SIOCSIWENCODEEXT:Enable WPA WEXT SUPPORT!!!!!\n"); pDevice->bwextstep0 = false; pDevice->bwextstep1 = false; pDevice->bwextstep2 = false; pDevice->bwextstep3 = false; pDevice->bWPASuppWextEnabled = true; memset(pMgmt->abyDesireBSSID, 0xFF, 6); KeyvInitTable(pDevice, &pDevice->sKey); } /*******/ spin_lock_irq(&pDevice->lock); ret = wpa_set_keys(pDevice, param); spin_unlock_irq(&pDevice->lock); error: kfree(buf); return ret; }
static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked) { PSDevice apdev_priv; struct net_device *dev = pDevice->dev; int ret; const struct net_device_ops apdev_netdev_ops = { .ndo_start_xmit = pDevice->tx_80211, }; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name); pDevice->apdev = kzalloc(sizeof(struct net_device), GFP_KERNEL); if (pDevice->apdev == NULL) return -ENOMEM; apdev_priv = netdev_priv(pDevice->apdev); *apdev_priv = *pDevice; memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN); pDevice->apdev->netdev_ops = &apdev_netdev_ops; pDevice->apdev->type = ARPHRD_IEEE80211; pDevice->apdev->base_addr = dev->base_addr; pDevice->apdev->irq = dev->irq; pDevice->apdev->mem_start = dev->mem_start; pDevice->apdev->mem_end = dev->mem_end; sprintf(pDevice->apdev->name, "%sap", dev->name); if (rtnl_locked) ret = register_netdevice(pDevice->apdev); else ret = register_netdev(pDevice->apdev); if (ret) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: register_netdevice(AP) failed!\n", dev->name); return -1; } DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Registered netdevice %s for AP management\n", dev->name, pDevice->apdev->name); KeyvInitTable(&pDevice->sKey, pDevice->PortOffset); return 0; } /* * Description: * unregister net_device(AP) * * Parameters: * In: * pDevice - * rtnl_locked - * Out: * * Return Value: * */ static int hostap_disable_hostapd(PSDevice pDevice, int rtnl_locked) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: disabling hostapd mode\n", pDevice->dev->name); if (pDevice->apdev && pDevice->apdev->name && pDevice->apdev->name[0]) { if (rtnl_locked) unregister_netdevice(pDevice->apdev); else unregister_netdev(pDevice->apdev); DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Netdevice %s unregistered\n", pDevice->dev->name, pDevice->apdev->name); } kfree(pDevice->apdev); pDevice->apdev = NULL; pDevice->bEnable8021x = false; pDevice->bEnableHostWEP = false; pDevice->bEncryptionEnable = false; //4.2007-0118-03,<Add> by EinsnLiu //execute some clear work pDevice->pMgmt->byCSSPK=KEY_CTL_NONE; pDevice->pMgmt->byCSSGK=KEY_CTL_NONE; KeyvInitTable(&pDevice->sKey,pDevice->PortOffset); return 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_siwencodeext(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_encode_ext *ext = (struct iw_encode_ext*)extra; struct viawget_wpa_param *param=NULL; wpa_alg alg_name; u8 addr[6]; int key_idx, set_tx=0; u8 seq[IW_ENCODE_SEQ_MAX_SIZE]; u8 key[64]; size_t seq_len=0,key_len=0; u8 *buf; size_t blen; u8 key_array[64]; int ret=0; PRINT_K("SIOCSIWENCODEEXT...... \n"); blen = sizeof(*param); buf = kmalloc((int)blen, (int)GFP_KERNEL); if (buf == NULL) return -ENOMEM; memset(buf, 0, blen); param = (struct viawget_wpa_param *) buf; switch (ext->alg) { case IW_ENCODE_ALG_NONE: alg_name = WPA_ALG_NONE; break; case IW_ENCODE_ALG_WEP: alg_name = WPA_ALG_WEP; break; case IW_ENCODE_ALG_TKIP: alg_name = WPA_ALG_TKIP; break; case IW_ENCODE_ALG_CCMP: alg_name = WPA_ALG_CCMP; break; default: PRINT_K("Unknown alg = %d\n",ext->alg); ret= -ENOMEM; goto error; } memcpy(addr, ext->addr.sa_data, ETH_ALEN); key_idx = (wrq->flags&IW_ENCODE_INDEX) - 1; if(ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) set_tx = 1; if(ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) { seq_len=IW_ENCODE_SEQ_MAX_SIZE; memcpy(seq, ext->rx_seq, seq_len); } if(ext->key_len) { key_len=ext->key_len; memcpy(key, &ext->key[0], key_len); } memset(key_array, 0, 64); if ( key_len > 0) { memcpy(key_array, key, key_len); if (key_len == 32) { memcpy(&key_array[16], &key[24], 8); memcpy(&key_array[24], &key[16], 8); } } memcpy(param->addr, addr, ETH_ALEN); param->u.wpa_key.alg_name = (int)alg_name; param->u.wpa_key.set_tx = set_tx; param->u.wpa_key.key_index = key_idx; param->u.wpa_key.key_len = key_len; param->u.wpa_key.key = (u8 *)key_array; param->u.wpa_key.seq = (u8 *)seq; param->u.wpa_key.seq_len = seq_len; if(param->u.wpa_key.alg_name == WPA_ALG_NONE) { if(param->u.wpa_key.key_index ==0) { pDevice->bwextstep0 = TRUE; } if((pDevice->bwextstep0 = TRUE)&&(param->u.wpa_key.key_index ==1)) { pDevice->bwextstep0 = FALSE; pDevice->bwextstep1 = TRUE; } if((pDevice->bwextstep1 = TRUE)&&(param->u.wpa_key.key_index ==2)) { pDevice->bwextstep1 = FALSE; pDevice->bwextstep2 = TRUE; } if((pDevice->bwextstep2 = TRUE)&&(param->u.wpa_key.key_index ==3)) { pDevice->bwextstep2 = FALSE; pDevice->bwextstep3 = TRUE; } } if(pDevice->bwextstep3 == TRUE) { PRINT_K("SIOCSIWENCODEEXT:Enable WPA WEXT SUPPORT!!!!!\n"); pDevice->bwextstep0 = FALSE; pDevice->bwextstep1 = FALSE; pDevice->bwextstep2 = FALSE; pDevice->bwextstep3 = FALSE; pDevice->bWPASuppWextEnabled = TRUE; memset(pMgmt->abyDesireBSSID, 0xFF,6); KeyvInitTable(pDevice,&pDevice->sKey); } spin_lock_irq(&pDevice->lock); ret = wpa_set_keys(pDevice, param, TRUE); spin_unlock_irq(&pDevice->lock); error: kfree(param); return ret; }
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; }
static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked) { PSDevice apdev_priv; struct net_device *dev = pDevice->dev; int ret; const struct net_device_ops apdev_netdev_ops = { .ndo_start_xmit = pDevice->tx_80211, }; DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name); pDevice->apdev = (struct net_device *)kmalloc(sizeof(struct net_device), GFP_KERNEL); if (pDevice->apdev == NULL) return -ENOMEM; memset(pDevice->apdev, 0, sizeof(struct net_device)); apdev_priv = netdev_priv(pDevice->apdev); *apdev_priv = *pDevice; memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN); pDevice->apdev->netdev_ops = &apdev_netdev_ops; pDevice->apdev->type = ARPHRD_IEEE80211; pDevice->apdev->base_addr = dev->base_addr; pDevice->apdev->irq = dev->irq; pDevice->apdev->mem_start = dev->mem_start; pDevice->apdev->mem_end = dev->mem_end; sprintf(pDevice->apdev->name, "%sap", dev->name); if (rtnl_locked) ret = register_netdevice(pDevice->apdev); else ret = register_netdev(pDevice->apdev); if (ret) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: register_netdevice(AP) failed!\n", dev->name); return -1; } DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Registered netdevice %s for AP management\n", dev->name, pDevice->apdev->name); KeyvInitTable(pDevice,&pDevice->sKey); return 0; } /* * Description: * unregister net_device(AP) * * Parameters: * In: * pDevice - * rtnl_locked - * Out: * * Return Value: * */ static int hostap_disable_hostapd(PSDevice pDevice, int rtnl_locked) { DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: disabling hostapd mode\n", pDevice->dev->name); if (pDevice->apdev && pDevice->apdev->name && pDevice->apdev->name[0]) { if (rtnl_locked) unregister_netdevice(pDevice->apdev); else unregister_netdev(pDevice->apdev); DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Netdevice %s unregistered\n", pDevice->dev->name, pDevice->apdev->name); } kfree(pDevice->apdev); pDevice->apdev = NULL; pDevice->bEnable8021x = FALSE; pDevice->bEnableHostWEP = FALSE; pDevice->bEncryptionEnable = FALSE; return 0; }