Ath5k: unify resets
[safe/jmp/linux-2.6] / drivers / net / wireless / mac80211_hwsim.c
index 3e33b29..248d31a 100644 (file)
@@ -121,13 +121,12 @@ static void mac80211_hwsim_monitor_rx(struct ieee80211_hw *hw,
        hdr->hdr.it_version = PKTHDR_RADIOTAP_VERSION;
        hdr->hdr.it_pad = 0;
        hdr->hdr.it_len = cpu_to_le16(sizeof(*hdr));
-       hdr->hdr.it_present = __constant_cpu_to_le32(
-            (1 << IEEE80211_RADIOTAP_FLAGS) |
-            (1 << IEEE80211_RADIOTAP_RATE) |
-            (1 << IEEE80211_RADIOTAP_CHANNEL));
+       hdr->hdr.it_present = cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
+                                         (1 << IEEE80211_RADIOTAP_RATE) |
+                                         (1 << IEEE80211_RADIOTAP_CHANNEL));
        hdr->rt_flags = 0;
        hdr->rt_rate = txrate->bitrate / 5;
-       hdr->rt_channel = data->channel->center_freq;
+       hdr->rt_channel = cpu_to_le16(data->channel->center_freq);
        flags = IEEE80211_CHAN_2GHZ;
        if (txrate->flags & IEEE80211_RATE_ERP_G)
                flags |= IEEE80211_CHAN_OFDM;
@@ -139,37 +138,20 @@ static void mac80211_hwsim_monitor_rx(struct ieee80211_hw *hw,
        skb_set_mac_header(skb, 0);
        skb->ip_summed = CHECKSUM_UNNECESSARY;
        skb->pkt_type = PACKET_OTHERHOST;
-       skb->protocol = __constant_htons(ETH_P_802_2);
+       skb->protocol = htons(ETH_P_802_2);
        memset(skb->cb, 0, sizeof(skb->cb));
        netif_rx(skb);
 }
 
 
-static int mac80211_hwsim_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
+static int mac80211_hwsim_tx_frame(struct ieee80211_hw *hw,
+                                  struct sk_buff *skb)
 {
        struct mac80211_hwsim_data *data = hw->priv;
-       struct ieee80211_rx_status rx_status;
        int i, ack = 0;
-       struct ieee80211_hdr *hdr;
+       struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
        struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
-       struct ieee80211_tx_info *txi;
-
-       mac80211_hwsim_monitor_rx(hw, skb);
-
-       if (skb->len < 10) {
-               /* Should not happen; just a sanity check for addr1 use */
-               dev_kfree_skb(skb);
-               return NETDEV_TX_OK;
-       }
-
-       if (!data->radio_enabled) {
-               printk(KERN_DEBUG "%s: dropped TX frame since radio "
-                      "disabled\n", wiphy_name(hw->wiphy));
-               dev_kfree_skb(skb);
-               return NETDEV_TX_OK;
-       }
-
-       hdr = (struct ieee80211_hdr *) skb->data;
+       struct ieee80211_rx_status rx_status;
 
        memset(&rx_status, 0, sizeof(rx_status));
        /* TODO: set mactime */
@@ -200,6 +182,33 @@ static int mac80211_hwsim_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
                ieee80211_rx_irqsafe(hwsim_radios[i], nskb, &rx_status);
        }
 
+       return ack;
+}
+
+
+static int mac80211_hwsim_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
+{
+       struct mac80211_hwsim_data *data = hw->priv;
+       int ack;
+       struct ieee80211_tx_info *txi;
+
+       mac80211_hwsim_monitor_rx(hw, skb);
+
+       if (skb->len < 10) {
+               /* Should not happen; just a sanity check for addr1 use */
+               dev_kfree_skb(skb);
+               return NETDEV_TX_OK;
+       }
+
+       if (!data->radio_enabled) {
+               printk(KERN_DEBUG "%s: dropped TX frame since radio "
+                      "disabled\n", wiphy_name(hw->wiphy));
+               dev_kfree_skb(skb);
+               return NETDEV_TX_OK;
+       }
+
+       ack = mac80211_hwsim_tx_frame(hw, skb);
+
        txi = IEEE80211_SKB_CB(skb);
        memset(&txi->status, 0, sizeof(txi->status));
        if (!(txi->flags & IEEE80211_TX_CTL_NO_ACK)) {
@@ -255,10 +264,7 @@ static void mac80211_hwsim_beacon_tx(void *arg, u8 *mac,
                                     struct ieee80211_vif *vif)
 {
        struct ieee80211_hw *hw = arg;
-       struct mac80211_hwsim_data *data = hw->priv;
        struct sk_buff *skb;
-       struct ieee80211_rx_status rx_status;
-       int i;
        struct ieee80211_tx_info *info;
 
        if (vif->type != IEEE80211_IF_TYPE_AP)
@@ -270,33 +276,7 @@ static void mac80211_hwsim_beacon_tx(void *arg, u8 *mac,
        info = IEEE80211_SKB_CB(skb);
 
        mac80211_hwsim_monitor_rx(hw, skb);
-
-       memset(&rx_status, 0, sizeof(rx_status));
-       /* TODO: set mactime */
-       rx_status.freq = data->channel->center_freq;
-       rx_status.band = data->channel->band;
-       rx_status.rate_idx = info->tx_rate_idx;
-       /* TODO: simulate signal strength (and optional packet drop) */
-
-       /* Copy skb to all enabled radios that are on the current frequency */
-       for (i = 0; i < hwsim_radio_count; i++) {
-               struct mac80211_hwsim_data *data2;
-               struct sk_buff *nskb;
-
-               if (hwsim_radios[i] == NULL || hwsim_radios[i] == hw)
-                       continue;
-               data2 = hwsim_radios[i]->priv;
-               if (!data2->started || !data2->radio_enabled ||
-                   data->channel->center_freq != data2->channel->center_freq)
-                       continue;
-
-               nskb = skb_copy(skb, GFP_ATOMIC);
-               if (nskb == NULL)
-                       continue;
-
-               ieee80211_rx_irqsafe(hwsim_radios[i], nskb, &rx_status);
-       }
-
+       mac80211_hwsim_tx_frame(hw, skb);
        dev_kfree_skb(skb);
 }
 
@@ -309,7 +289,8 @@ static void mac80211_hwsim_beacon(unsigned long arg)
        if (!data->started || !data->radio_enabled)
                return;
 
-       ieee80211_iterate_active_interfaces(hw, mac80211_hwsim_beacon_tx, hw);
+       ieee80211_iterate_active_interfaces_atomic(
+               hw, mac80211_hwsim_beacon_tx, hw);
 
        data->beacon_timer.expires = jiffies + data->beacon_int;
        add_timer(&data->beacon_timer);
@@ -383,8 +364,7 @@ static void mac80211_hwsim_free(void)
                        struct mac80211_hwsim_data *data;
                        data = hwsim_radios[i]->priv;
                        ieee80211_unregister_hw(hwsim_radios[i]);
-                       if (!IS_ERR(data->dev))
-                               device_unregister(data->dev);
+                       device_unregister(data->dev);
                        ieee80211_free_hw(hwsim_radios[i]);
                }
        }
@@ -449,15 +429,16 @@ static int __init init_mac80211_hwsim(void)
                hwsim_radios[i] = hw;
 
                data = hw->priv;
-               data->dev = device_create(hwsim_class, NULL, 0, "hwsim%d", i);
+               data->dev = device_create_drvdata(hwsim_class, NULL, 0, hw,
+                                               "hwsim%d", i);
                if (IS_ERR(data->dev)) {
-                       printk(KERN_DEBUG "mac80211_hwsim: device_create "
+                       printk(KERN_DEBUG
+                              "mac80211_hwsim: device_create_drvdata "
                               "failed (%ld)\n", PTR_ERR(data->dev));
                        err = -ENOMEM;
-                       goto failed;
+                       goto failed_drvdata;
                }
                data->dev->driver = &mac80211_hwsim_driver;
-               dev_set_drvdata(data->dev, hw);
 
                SET_IEEE80211_DEV(hw, data->dev);
                addr[3] = i >> 8;
@@ -479,7 +460,7 @@ static int __init init_mac80211_hwsim(void)
                if (err < 0) {
                        printk(KERN_DEBUG "mac80211_hwsim: "
                               "ieee80211_register_hw failed (%d)\n", err);
-                       goto failed;
+                       goto failed_hw;
                }
 
                printk(KERN_DEBUG "%s: hwaddr %s registered\n",
@@ -497,9 +478,9 @@ static int __init init_mac80211_hwsim(void)
        rtnl_lock();
 
        err = dev_alloc_name(hwsim_mon, hwsim_mon->name);
-       if (err < 0) {
+       if (err < 0)
                goto failed_mon;
-       }
+
 
        err = register_netdevice(hwsim_mon);
        if (err < 0)
@@ -512,7 +493,14 @@ static int __init init_mac80211_hwsim(void)
 failed_mon:
        rtnl_unlock();
        free_netdev(hwsim_mon);
+       mac80211_hwsim_free();
+       return err;
 
+failed_hw:
+       device_unregister(data->dev);
+failed_drvdata:
+       ieee80211_free_hw(hw);
+       hwsim_radios[i] = NULL;
 failed:
        mac80211_hwsim_free();
        return err;