0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <linux/delay.h>
0013 #include <linux/if_ether.h>
0014 #include <linux/skbuff.h>
0015 #include <linux/if_arp.h>
0016 #include <linux/etherdevice.h>
0017 #include <linux/rtnetlink.h>
0018 #include <net/mac80211.h>
0019 #include <asm/unaligned.h>
0020
0021 #include "ieee80211_i.h"
0022 #include "driver-ops.h"
0023 #include "rate.h"
0024
0025 #define IEEE80211_OCB_HOUSEKEEPING_INTERVAL (60 * HZ)
0026 #define IEEE80211_OCB_PEER_INACTIVITY_LIMIT (240 * HZ)
0027 #define IEEE80211_OCB_MAX_STA_ENTRIES 128
0028
0029
0030
0031
0032
0033
0034
0035 enum ocb_deferred_task_flags {
0036 OCB_WORK_HOUSEKEEPING,
0037 };
0038
0039 void ieee80211_ocb_rx_no_sta(struct ieee80211_sub_if_data *sdata,
0040 const u8 *bssid, const u8 *addr,
0041 u32 supp_rates)
0042 {
0043 struct ieee80211_if_ocb *ifocb = &sdata->u.ocb;
0044 struct ieee80211_local *local = sdata->local;
0045 struct ieee80211_chanctx_conf *chanctx_conf;
0046 struct ieee80211_supported_band *sband;
0047 enum nl80211_bss_scan_width scan_width;
0048 struct sta_info *sta;
0049 int band;
0050
0051
0052
0053
0054 if (local->num_sta >= IEEE80211_OCB_MAX_STA_ENTRIES) {
0055 net_info_ratelimited("%s: No room for a new OCB STA entry %pM\n",
0056 sdata->name, addr);
0057 return;
0058 }
0059
0060 ocb_dbg(sdata, "Adding new OCB station %pM\n", addr);
0061
0062 rcu_read_lock();
0063 chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf);
0064 if (WARN_ON_ONCE(!chanctx_conf)) {
0065 rcu_read_unlock();
0066 return;
0067 }
0068 band = chanctx_conf->def.chan->band;
0069 scan_width = cfg80211_chandef_to_scan_width(&chanctx_conf->def);
0070 rcu_read_unlock();
0071
0072 sta = sta_info_alloc(sdata, addr, GFP_ATOMIC);
0073 if (!sta)
0074 return;
0075
0076
0077 sband = local->hw.wiphy->bands[band];
0078 sta->sta.deflink.supp_rates[band] =
0079 ieee80211_mandatory_rates(sband, scan_width);
0080
0081 spin_lock(&ifocb->incomplete_lock);
0082 list_add(&sta->list, &ifocb->incomplete_stations);
0083 spin_unlock(&ifocb->incomplete_lock);
0084 ieee80211_queue_work(&local->hw, &sdata->work);
0085 }
0086
0087 static struct sta_info *ieee80211_ocb_finish_sta(struct sta_info *sta)
0088 __acquires(RCU)
0089 {
0090 struct ieee80211_sub_if_data *sdata = sta->sdata;
0091 u8 addr[ETH_ALEN];
0092
0093 memcpy(addr, sta->sta.addr, ETH_ALEN);
0094
0095 ocb_dbg(sdata, "Adding new IBSS station %pM (dev=%s)\n",
0096 addr, sdata->name);
0097
0098 sta_info_move_state(sta, IEEE80211_STA_AUTH);
0099 sta_info_move_state(sta, IEEE80211_STA_ASSOC);
0100 sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
0101
0102 rate_control_rate_init(sta);
0103
0104
0105 if (sta_info_insert_rcu(sta))
0106 return sta_info_get(sdata, addr);
0107 return sta;
0108 }
0109
0110 static void ieee80211_ocb_housekeeping(struct ieee80211_sub_if_data *sdata)
0111 {
0112 struct ieee80211_if_ocb *ifocb = &sdata->u.ocb;
0113
0114 ocb_dbg(sdata, "Running ocb housekeeping\n");
0115
0116 ieee80211_sta_expire(sdata, IEEE80211_OCB_PEER_INACTIVITY_LIMIT);
0117
0118 mod_timer(&ifocb->housekeeping_timer,
0119 round_jiffies(jiffies + IEEE80211_OCB_HOUSEKEEPING_INTERVAL));
0120 }
0121
0122 void ieee80211_ocb_work(struct ieee80211_sub_if_data *sdata)
0123 {
0124 struct ieee80211_if_ocb *ifocb = &sdata->u.ocb;
0125 struct sta_info *sta;
0126
0127 if (ifocb->joined != true)
0128 return;
0129
0130 sdata_lock(sdata);
0131
0132 spin_lock_bh(&ifocb->incomplete_lock);
0133 while (!list_empty(&ifocb->incomplete_stations)) {
0134 sta = list_first_entry(&ifocb->incomplete_stations,
0135 struct sta_info, list);
0136 list_del(&sta->list);
0137 spin_unlock_bh(&ifocb->incomplete_lock);
0138
0139 ieee80211_ocb_finish_sta(sta);
0140 rcu_read_unlock();
0141 spin_lock_bh(&ifocb->incomplete_lock);
0142 }
0143 spin_unlock_bh(&ifocb->incomplete_lock);
0144
0145 if (test_and_clear_bit(OCB_WORK_HOUSEKEEPING, &ifocb->wrkq_flags))
0146 ieee80211_ocb_housekeeping(sdata);
0147
0148 sdata_unlock(sdata);
0149 }
0150
0151 static void ieee80211_ocb_housekeeping_timer(struct timer_list *t)
0152 {
0153 struct ieee80211_sub_if_data *sdata =
0154 from_timer(sdata, t, u.ocb.housekeeping_timer);
0155 struct ieee80211_local *local = sdata->local;
0156 struct ieee80211_if_ocb *ifocb = &sdata->u.ocb;
0157
0158 set_bit(OCB_WORK_HOUSEKEEPING, &ifocb->wrkq_flags);
0159
0160 ieee80211_queue_work(&local->hw, &sdata->work);
0161 }
0162
0163 void ieee80211_ocb_setup_sdata(struct ieee80211_sub_if_data *sdata)
0164 {
0165 struct ieee80211_if_ocb *ifocb = &sdata->u.ocb;
0166
0167 timer_setup(&ifocb->housekeeping_timer,
0168 ieee80211_ocb_housekeeping_timer, 0);
0169 INIT_LIST_HEAD(&ifocb->incomplete_stations);
0170 spin_lock_init(&ifocb->incomplete_lock);
0171 }
0172
0173 int ieee80211_ocb_join(struct ieee80211_sub_if_data *sdata,
0174 struct ocb_setup *setup)
0175 {
0176 struct ieee80211_local *local = sdata->local;
0177 struct ieee80211_if_ocb *ifocb = &sdata->u.ocb;
0178 u32 changed = BSS_CHANGED_OCB | BSS_CHANGED_BSSID;
0179 int err;
0180
0181 if (ifocb->joined == true)
0182 return -EINVAL;
0183
0184 sdata->deflink.operating_11g_mode = true;
0185 sdata->deflink.smps_mode = IEEE80211_SMPS_OFF;
0186 sdata->deflink.needed_rx_chains = sdata->local->rx_chains;
0187
0188 mutex_lock(&sdata->local->mtx);
0189 err = ieee80211_link_use_channel(&sdata->deflink, &setup->chandef,
0190 IEEE80211_CHANCTX_SHARED);
0191 mutex_unlock(&sdata->local->mtx);
0192 if (err)
0193 return err;
0194
0195 ieee80211_bss_info_change_notify(sdata, changed);
0196
0197 ifocb->joined = true;
0198
0199 set_bit(OCB_WORK_HOUSEKEEPING, &ifocb->wrkq_flags);
0200 ieee80211_queue_work(&local->hw, &sdata->work);
0201
0202 netif_carrier_on(sdata->dev);
0203 return 0;
0204 }
0205
0206 int ieee80211_ocb_leave(struct ieee80211_sub_if_data *sdata)
0207 {
0208 struct ieee80211_if_ocb *ifocb = &sdata->u.ocb;
0209 struct ieee80211_local *local = sdata->local;
0210 struct sta_info *sta;
0211
0212 ifocb->joined = false;
0213 sta_info_flush(sdata);
0214
0215 spin_lock_bh(&ifocb->incomplete_lock);
0216 while (!list_empty(&ifocb->incomplete_stations)) {
0217 sta = list_first_entry(&ifocb->incomplete_stations,
0218 struct sta_info, list);
0219 list_del(&sta->list);
0220 spin_unlock_bh(&ifocb->incomplete_lock);
0221
0222 sta_info_free(local, sta);
0223 spin_lock_bh(&ifocb->incomplete_lock);
0224 }
0225 spin_unlock_bh(&ifocb->incomplete_lock);
0226
0227 netif_carrier_off(sdata->dev);
0228 clear_bit(SDATA_STATE_OFFCHANNEL, &sdata->state);
0229 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_OCB);
0230
0231 mutex_lock(&sdata->local->mtx);
0232 ieee80211_link_release_channel(&sdata->deflink);
0233 mutex_unlock(&sdata->local->mtx);
0234
0235 skb_queue_purge(&sdata->skb_queue);
0236
0237 del_timer_sync(&sdata->u.ocb.housekeeping_timer);
0238
0239
0240
0241
0242
0243
0244
0245 return 0;
0246 }