staging: wilc1000: add ops tx power in cfg80211
[linux-2.6-microblaze.git] / drivers / staging / wilc1000 / wilc_wfi_cfgoperations.c
index d2b7a8b..14e1f14 100644 (file)
@@ -524,7 +524,8 @@ static void CfgConnectResult(enum conn_event enuConnDisconnEvent,
                if ((u8MacStatus == MAC_DISCONNECTED) &&
                    (pstrConnectInfo->u16ConnectStatus == SUCCESSFUL_STATUSCODE)) {
                        u16ConnectStatus = WLAN_STATUS_UNSPECIFIED_FAILURE;
-                       wilc_wlan_set_bssid(priv->dev, NullBssid);
+                       wilc_wlan_set_bssid(priv->dev, NullBssid,
+                                           STATION_MODE);
                        eth_zero_addr(wilc_connected_ssid);
 
                        if (!pstrWFIDrv->p2p_connect)
@@ -577,7 +578,7 @@ static void CfgConnectResult(enum conn_event enuConnDisconnEvent,
                p2p_recv_random = 0x00;
                wilc_ie = false;
                eth_zero_addr(priv->au8AssociatedBss);
-               wilc_wlan_set_bssid(priv->dev, NullBssid);
+               wilc_wlan_set_bssid(priv->dev, NullBssid, STATION_MODE);
                eth_zero_addr(wilc_connected_ssid);
 
                if (!pstrWFIDrv->p2p_connect)
@@ -632,7 +633,6 @@ static int scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
 
        priv->u32RcvdChCount = 0;
 
-       wilc_set_wfi_drv_handler(vif, wilc_get_vif_idx(vif));
        reset_shadow_found();
 
        priv->bCfgScanning = true;
@@ -713,8 +713,6 @@ static int connect(struct wiphy *wiphy, struct net_device *dev,
        vif = netdev_priv(priv->dev);
        pstrWFIDrv = (struct host_if_drv *)(priv->hWILCWFIDrv);
 
-       wilc_set_wfi_drv_handler(vif, wilc_get_vif_idx(vif));
-
        PRINT_D(CFG80211_DBG, "Connecting to SSID [%s] on netdev [%p] host if [%p]\n", sme->ssid, dev, priv->hWILCWFIDrv);
        if (!(strncmp(sme->ssid, "DIRECT-", 7))) {
                PRINT_D(CFG80211_DBG, "Connected to Direct network,OBSS disabled\n");
@@ -759,8 +757,8 @@ static int connect(struct wiphy *wiphy, struct net_device *dev,
                        PRINT_D(CFG80211_DBG, "No Scan results yet\n");
                else
                        PRINT_D(CFG80211_DBG, "Required bss not in scan results: Error(%d)\n", s32Error);
-
-               goto done;
+               wilc_connecting = 0;
+               return s32Error;
        }
 
        priv->WILC_WFI_wep_default = 0;
@@ -847,8 +845,8 @@ static int connect(struct wiphy *wiphy, struct net_device *dev,
                } else {
                        s32Error = -ENOTSUPP;
                        PRINT_ER("Not supported cipher: Error(%d)\n", s32Error);
-
-                       goto done;
+                       wilc_connecting = 0;
+                       return s32Error;
                }
        }
 
@@ -903,7 +901,7 @@ static int connect(struct wiphy *wiphy, struct net_device *dev,
        if (!pstrWFIDrv->p2p_connect)
                wlan_channel = pstrNetworkInfo->u8channel;
 
-       wilc_wlan_set_bssid(dev, pstrNetworkInfo->au8bssid);
+       wilc_wlan_set_bssid(dev, pstrNetworkInfo->au8bssid, STATION_MODE);
 
        s32Error = wilc_set_join_req(vif, pstrNetworkInfo->au8bssid, sme->ssid,
                                     sme->ssid_len, sme->ie, sme->ie_len,
@@ -914,11 +912,10 @@ static int connect(struct wiphy *wiphy, struct net_device *dev,
        if (s32Error != 0) {
                PRINT_ER("wilc_set_join_req(): Error(%d)\n", s32Error);
                s32Error = -ENOENT;
-               goto done;
+               wilc_connecting = 0;
+               return s32Error;
        }
 
-done:
-
        return s32Error;
 }
 
@@ -937,7 +934,7 @@ static int disconnect(struct wiphy *wiphy, struct net_device *dev, u16 reason_co
        pstrWFIDrv = (struct host_if_drv *)priv->hWILCWFIDrv;
        if (!pstrWFIDrv->p2p_connect)
                wlan_channel = INVALID_CHANNEL;
-       wilc_wlan_set_bssid(priv->dev, NullBssid);
+       wilc_wlan_set_bssid(priv->dev, NullBssid, STATION_MODE);
 
        PRINT_D(CFG80211_DBG, "Disconnecting with reason code(%d)\n", reason_code);
 
@@ -1731,7 +1728,7 @@ void WILC_WFI_p2p_rx (struct net_device *dev, u8 *buff, u32 size)
                        }
                }
 
-               cfg80211_rx_mgmt(priv->wdev, s32Freq, 0, buff, size - 7, 0);
+               cfg80211_rx_mgmt(priv->wdev, s32Freq, 0, buff, size, 0);
        }
 }
 
@@ -2097,9 +2094,6 @@ static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev,
 {
        struct wilc_priv *priv;
        struct wilc_vif *vif;
-       u8 interface_type;
-       u16 TID = 0;
-       u8 i;
        struct wilc *wl;
 
        vif = netdev_priv(dev);
@@ -2124,149 +2118,26 @@ static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev,
                priv->wdev->iftype = type;
                vif->monitor_flag = 0;
                vif->iftype = STATION_MODE;
+               wilc_set_operation_mode(vif, STATION_MODE);
 
                memset(priv->assoc_stainfo.au8Sta_AssociatedBss, 0, MAX_NUM_STA * ETH_ALEN);
-               interface_type = vif->iftype;
-               vif->iftype = STATION_MODE;
 
-               if (wl->initialized) {
-                       wilc_del_all_rx_ba_session(vif, wl->vif[0]->bssid,
-                                                  TID);
-                       wilc_wait_msg_queue_idle();
-
-                       up(&wl->cfg_event);
-
-                       wilc1000_wlan_deinit(dev);
-                       wilc1000_wlan_init(dev, vif);
-                       wilc_initialized = 1;
-                       vif->iftype = interface_type;
-
-                       wilc_set_wfi_drv_handler(vif,
-                                                wilc_get_vif_idx(wl->vif[0]));
-                       wilc_set_mac_address(wl->vif[0], wl->vif[0]->src_addr);
-                       wilc_set_operation_mode(vif, STATION_MODE);
-
-                       if (g_wep_keys_saved) {
-                               wilc_set_wep_default_keyid(wl->vif[0],
-                                               g_key_wep_params.key_idx);
-                               wilc_add_wep_key_bss_sta(wl->vif[0],
-                                               g_key_wep_params.key,
-                                               g_key_wep_params.key_len,
-                                               g_key_wep_params.key_idx);
-                       }
-
-                       wilc_flush_join_req(vif);
-
-                       if (g_ptk_keys_saved && g_gtk_keys_saved) {
-                               PRINT_D(CFG80211_DBG, "ptk %x %x %x\n", g_key_ptk_params.key[0],
-                                       g_key_ptk_params.key[1],
-                                       g_key_ptk_params.key[2]);
-                               PRINT_D(CFG80211_DBG, "gtk %x %x %x\n", g_key_gtk_params.key[0],
-                                       g_key_gtk_params.key[1],
-                                       g_key_gtk_params.key[2]);
-                               add_key(wl->vif[0]->ndev->ieee80211_ptr->wiphy,
-                                       wl->vif[0]->ndev,
-                                       g_add_ptk_key_params.key_idx,
-                                       g_add_ptk_key_params.pairwise,
-                                       g_add_ptk_key_params.mac_addr,
-                                       (struct key_params *)(&g_key_ptk_params));
-
-                               add_key(wl->vif[0]->ndev->ieee80211_ptr->wiphy,
-                                       wl->vif[0]->ndev,
-                                       g_add_gtk_key_params.key_idx,
-                                       g_add_gtk_key_params.pairwise,
-                                       g_add_gtk_key_params.mac_addr,
-                                       (struct key_params *)(&g_key_gtk_params));
-                       }
-
-                       if (wl->initialized)    {
-                               for (i = 0; i < num_reg_frame; i++) {
-                                       PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", vif->g_struct_frame_reg[i].frame_type,
-                                               vif->g_struct_frame_reg[i].reg);
-                                       wilc_frame_register(vif,
-                                                               vif->g_struct_frame_reg[i].frame_type,
-                                                               vif->g_struct_frame_reg[i].reg);
-                               }
-                       }
-
-                       wilc_enable_ps = true;
-                       wilc_set_power_mgmt(vif, 1, 0);
-               }
+               wilc_enable_ps = true;
+               wilc_set_power_mgmt(vif, 1, 0);
                break;
 
        case NL80211_IFTYPE_P2P_CLIENT:
-               wilc_enable_ps = false;
-               wilc_set_power_mgmt(vif, 0, 0);
                wilc_connecting = 0;
                PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_P2P_CLIENT\n");
 
-               wilc_del_all_rx_ba_session(vif, wl->vif[0]->bssid, TID);
-
                dev->ieee80211_ptr->iftype = type;
                priv->wdev->iftype = type;
                vif->monitor_flag = 0;
-
-               PRINT_D(HOSTAPD_DBG, "Downloading P2P_CONCURRENCY_FIRMWARE\n");
                vif->iftype = CLIENT_MODE;
+               wilc_set_operation_mode(vif, STATION_MODE);
 
-
-               if (wl->initialized)    {
-                       wilc_wait_msg_queue_idle();
-
-                       wilc1000_wlan_deinit(dev);
-                       wilc1000_wlan_init(dev, vif);
-                       wilc_initialized = 1;
-
-                       wilc_set_wfi_drv_handler(vif,
-                                                wilc_get_vif_idx(wl->vif[0]));
-                       wilc_set_mac_address(wl->vif[0], wl->vif[0]->src_addr);
-                       wilc_set_operation_mode(vif, STATION_MODE);
-
-                       if (g_wep_keys_saved) {
-                               wilc_set_wep_default_keyid(wl->vif[0],
-                                               g_key_wep_params.key_idx);
-                               wilc_add_wep_key_bss_sta(wl->vif[0],
-                                               g_key_wep_params.key,
-                                               g_key_wep_params.key_len,
-                                               g_key_wep_params.key_idx);
-                       }
-
-                       wilc_flush_join_req(vif);
-
-                       if (g_ptk_keys_saved && g_gtk_keys_saved) {
-                               PRINT_D(CFG80211_DBG, "ptk %x %x %x\n", g_key_ptk_params.key[0],
-                                       g_key_ptk_params.key[1],
-                                       g_key_ptk_params.key[2]);
-                               PRINT_D(CFG80211_DBG, "gtk %x %x %x\n", g_key_gtk_params.key[0],
-                                       g_key_gtk_params.key[1],
-                                       g_key_gtk_params.key[2]);
-                               add_key(wl->vif[0]->ndev->ieee80211_ptr->wiphy,
-                                       wl->vif[0]->ndev,
-                                       g_add_ptk_key_params.key_idx,
-                                       g_add_ptk_key_params.pairwise,
-                                       g_add_ptk_key_params.mac_addr,
-                                       (struct key_params *)(&g_key_ptk_params));
-
-                               add_key(wl->vif[0]->ndev->ieee80211_ptr->wiphy,
-                                       wl->vif[0]->ndev,
-                                       g_add_gtk_key_params.key_idx,
-                                       g_add_gtk_key_params.pairwise,
-                                       g_add_gtk_key_params.mac_addr,
-                                       (struct key_params *)(&g_key_gtk_params));
-                       }
-
-                       refresh_scan(priv, 1, true);
-
-                       if (wl->initialized)    {
-                               for (i = 0; i < num_reg_frame; i++) {
-                                       PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", vif->g_struct_frame_reg[i].frame_type,
-                                               vif->g_struct_frame_reg[i].reg);
-                                       wilc_frame_register(vif,
-                                                               vif->g_struct_frame_reg[i].frame_type,
-                                                               vif->g_struct_frame_reg[i].reg);
-                               }
-                       }
-               }
+               wilc_enable_ps = false;
+               wilc_set_power_mgmt(vif, 0, 0);
                break;
 
        case NL80211_IFTYPE_AP:
@@ -2275,23 +2146,12 @@ static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev,
                dev->ieee80211_ptr->iftype = type;
                priv->wdev->iftype = type;
                vif->iftype = AP_MODE;
-               PRINT_D(CORECONFIG_DBG, "priv->hWILCWFIDrv[%p]\n", priv->hWILCWFIDrv);
-
-               PRINT_D(HOSTAPD_DBG, "Downloading AP firmware\n");
-               wilc_wlan_get_firmware(dev);
-
-               if (wl->initialized)    {
-                       vif->iftype = AP_MODE;
-                       wilc_mac_close(dev);
-                       wilc_mac_open(dev);
-
-                       for (i = 0; i < num_reg_frame; i++) {
-                               PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", vif->g_struct_frame_reg[i].frame_type,
-                                       vif->g_struct_frame_reg[i].reg);
-                               wilc_frame_register(vif,
-                                                       vif->g_struct_frame_reg[i].frame_type,
-                                                       vif->g_struct_frame_reg[i].reg);
-                       }
+
+               if (wl->initialized) {
+                       wilc_set_wfi_drv_handler(vif, wilc_get_vif_idx(vif),
+                                                0);
+                       wilc_set_operation_mode(vif, AP_MODE);
+                       wilc_set_power_mgmt(vif, 0, 0);
                }
                break;
 
@@ -2301,73 +2161,15 @@ static int change_virtual_intf(struct wiphy *wiphy, struct net_device *dev,
                wilc_optaining_ip = true;
                mod_timer(&wilc_during_ip_timer,
                          jiffies + msecs_to_jiffies(during_ip_time));
-               wilc_set_power_mgmt(vif, 0, 0);
-               wilc_del_all_rx_ba_session(vif, wl->vif[0]->bssid, TID);
-               wilc_enable_ps = false;
                PRINT_D(HOSTAPD_DBG, "Interface type = NL80211_IFTYPE_GO\n");
+
+               wilc_set_operation_mode(vif, AP_MODE);
                dev->ieee80211_ptr->iftype = type;
                priv->wdev->iftype = type;
-
-               PRINT_D(CORECONFIG_DBG, "priv->hWILCWFIDrv[%p]\n", priv->hWILCWFIDrv);
-
-               PRINT_D(HOSTAPD_DBG, "Downloading P2P_CONCURRENCY_FIRMWARE\n");
-
-
                vif->iftype = GO_MODE;
 
-               wilc_wait_msg_queue_idle();
-               wilc1000_wlan_deinit(dev);
-               wilc1000_wlan_init(dev, vif);
-               wilc_initialized = 1;
-
-               wilc_set_wfi_drv_handler(vif, wilc_get_vif_idx(wl->vif[0]));
-               wilc_set_mac_address(wl->vif[0], wl->vif[0]->src_addr);
-               wilc_set_operation_mode(vif, AP_MODE);
-
-               if (g_wep_keys_saved) {
-                       wilc_set_wep_default_keyid(wl->vif[0],
-                                                  g_key_wep_params.key_idx);
-                       wilc_add_wep_key_bss_sta(wl->vif[0],
-                                                g_key_wep_params.key,
-                                                g_key_wep_params.key_len,
-                                                g_key_wep_params.key_idx);
-               }
-
-               wilc_flush_join_req(vif);
-
-               if (g_ptk_keys_saved && g_gtk_keys_saved) {
-                       PRINT_D(CFG80211_DBG, "ptk %x %x %x cipher %x\n", g_key_ptk_params.key[0],
-                               g_key_ptk_params.key[1],
-                               g_key_ptk_params.key[2],
-                               g_key_ptk_params.cipher);
-                       PRINT_D(CFG80211_DBG, "gtk %x %x %x cipher %x\n", g_key_gtk_params.key[0],
-                               g_key_gtk_params.key[1],
-                               g_key_gtk_params.key[2],
-                               g_key_gtk_params.cipher);
-                       add_key(wl->vif[0]->ndev->ieee80211_ptr->wiphy,
-                               wl->vif[0]->ndev,
-                               g_add_ptk_key_params.key_idx,
-                               g_add_ptk_key_params.pairwise,
-                               g_add_ptk_key_params.mac_addr,
-                               (struct key_params *)(&g_key_ptk_params));
-
-                       add_key(wl->vif[0]->ndev->ieee80211_ptr->wiphy,
-                               wl->vif[0]->ndev,
-                               g_add_gtk_key_params.key_idx,
-                               g_add_gtk_key_params.pairwise,
-                               g_add_gtk_key_params.mac_addr,
-                               (struct key_params *)(&g_key_gtk_params));
-               }
-
-               if (wl->initialized)    {
-                       for (i = 0; i < num_reg_frame; i++) {
-                               PRINT_D(INIT_DBG, "Frame registering Type: %x - Reg: %d\n", vif->g_struct_frame_reg[i].frame_type,
-                                       vif->g_struct_frame_reg[i].reg);
-                               wilc_frame_register(vif,
-                                                       vif->g_struct_frame_reg[i].frame_type,
-                                                       vif->g_struct_frame_reg[i].reg);
-                       }
-               }
+               wilc_enable_ps = false;
+               wilc_set_power_mgmt(vif, 0, 0);
                break;
 
        default:
@@ -2400,7 +2202,8 @@ static int start_ap(struct wiphy *wiphy, struct net_device *dev,
        if (s32Error != 0)
                PRINT_ER("Error in setting channel\n");
 
-       wilc_wlan_set_bssid(dev, wl->vif[0]->src_addr);
+       wilc_wlan_set_bssid(dev, wl->vif[vif->u8IfIdx]->src_addr, AP_MODE);
+       wilc_set_power_mgmt(vif, 0, 0);
 
        s32Error = wilc_add_beacon(vif, settings->beacon_interval,
                                   settings->dtim_period, beacon->head_len,
@@ -2444,7 +2247,7 @@ static int stop_ap(struct wiphy *wiphy, struct net_device *dev)
 
        PRINT_D(HOSTAPD_DBG, "Deleting beacon\n");
 
-       wilc_wlan_set_bssid(dev, NullBssid);
+       wilc_wlan_set_bssid(dev, NullBssid, AP_MODE);
 
        s32Error = wilc_del_beacon(vif);
 
@@ -2701,6 +2504,39 @@ static void wilc_set_wakeup(struct wiphy *wiphy, bool enabled)
        netdev_info(vif->ndev, "cfg set wake up = %d\n", enabled);
 }
 
+static int set_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
+                       enum nl80211_tx_power_setting type, int mbm)
+{
+       int ret;
+       s32 tx_power = MBM_TO_DBM(mbm);
+       struct wilc_priv *priv = wiphy_priv(wiphy);
+       struct wilc_vif *vif = netdev_priv(priv->dev);
+
+       if (tx_power < 0)
+               tx_power = 0;
+       else if (tx_power > 18)
+               tx_power = 18;
+       ret = wilc_set_tx_power(vif, tx_power);
+       if (ret)
+               netdev_err(vif->ndev, "Failed to set tx power\n");
+
+       return ret;
+}
+
+static int get_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
+                       int *dbm)
+{
+       int ret;
+       struct wilc_priv *priv = wiphy_priv(wiphy);
+       struct wilc_vif *vif = netdev_priv(priv->dev);
+
+       ret = wilc_get_tx_power(vif, (u8 *)dbm);
+       if (ret)
+               netdev_err(vif->ndev, "Failed to get tx power\n");
+
+       return ret;
+}
+
 static struct cfg80211_ops wilc_cfg80211_ops = {
        .set_monitor_channel = set_channel,
        .scan = scan,
@@ -2739,6 +2575,8 @@ static struct cfg80211_ops wilc_cfg80211_ops = {
        .suspend = wilc_suspend,
        .resume = wilc_resume,
        .set_wakeup = wilc_set_wakeup,
+       .set_tx_power = set_tx_power,
+       .get_tx_power = get_tx_power,
 
 };
 
@@ -2824,7 +2662,9 @@ struct wireless_dev *wilc_create_wiphy(struct net_device *net, struct device *de
        sema_init(&(priv->SemHandleUpdateStats), 1);
        priv->wdev = wdev;
        wdev->wiphy->max_scan_ssids = MAX_NUM_PROBED_SSID;
+#ifdef CONFIG_PM
        wdev->wiphy->wowlan = &wowlan_support;
+#endif
        wdev->wiphy->max_num_pmkids = WILC_MAX_NUM_PMKIDS;
        PRINT_INFO(CFG80211_DBG, "Max number of PMKIDs = %d\n", wdev->wiphy->max_num_pmkids);