ath9k_common: move the rate status setting into ath9k_process_rate()
[safe/jmp/linux-2.6] / drivers / net / wireless / ath / ath9k / common.c
1 /*
2  * Copyright (c) 2009 Atheros Communications Inc.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16
17 /*
18  * Module for common driver code between ath9k and ath9k_htc
19  */
20
21 #include <linux/kernel.h>
22 #include <linux/module.h>
23
24 #include "common.h"
25
26 MODULE_AUTHOR("Atheros Communications");
27 MODULE_DESCRIPTION("Shared library for Atheros wireless 802.11n LAN cards.");
28 MODULE_LICENSE("Dual BSD/GPL");
29
30 /* Common RX processing */
31
32 /* Assumes you've already done the endian to CPU conversion */
33 static bool ath9k_rx_accept(struct ath_common *common,
34                             struct sk_buff *skb,
35                             struct ieee80211_rx_status *rxs,
36                             struct ath_rx_status *rx_stats,
37                             bool *decrypt_error)
38 {
39         struct ath_hw *ah = common->ah;
40         struct ieee80211_hdr *hdr;
41         __le16 fc;
42
43         hdr = (struct ieee80211_hdr *) skb->data;
44         fc = hdr->frame_control;
45
46         if (!rx_stats->rs_datalen)
47                 return false;
48         /*
49          * rs_status follows rs_datalen so if rs_datalen is too large
50          * we can take a hint that hardware corrupted it, so ignore
51          * those frames.
52          */
53         if (rx_stats->rs_datalen > common->rx_bufsize)
54                 return false;
55
56         /*
57          * rs_more indicates chained descriptors which can be used
58          * to link buffers together for a sort of scatter-gather
59          * operation.
60          * reject the frame, we don't support scatter-gather yet and
61          * the frame is probably corrupt anyway
62          */
63         if (rx_stats->rs_more)
64                 return false;
65
66         /*
67          * The rx_stats->rs_status will not be set until the end of the
68          * chained descriptors so it can be ignored if rs_more is set. The
69          * rs_more will be false at the last element of the chained
70          * descriptors.
71          */
72         if (rx_stats->rs_status != 0) {
73                 if (rx_stats->rs_status & ATH9K_RXERR_CRC)
74                         rxs->flag |= RX_FLAG_FAILED_FCS_CRC;
75                 if (rx_stats->rs_status & ATH9K_RXERR_PHY)
76                         return false;
77
78                 if (rx_stats->rs_status & ATH9K_RXERR_DECRYPT) {
79                         *decrypt_error = true;
80                 } else if (rx_stats->rs_status & ATH9K_RXERR_MIC) {
81                         if (ieee80211_is_ctl(fc))
82                                 /*
83                                  * Sometimes, we get invalid
84                                  * MIC failures on valid control frames.
85                                  * Remove these mic errors.
86                                  */
87                                 rx_stats->rs_status &= ~ATH9K_RXERR_MIC;
88                         else
89                                 rxs->flag |= RX_FLAG_MMIC_ERROR;
90                 }
91                 /*
92                  * Reject error frames with the exception of
93                  * decryption and MIC failures. For monitor mode,
94                  * we also ignore the CRC error.
95                  */
96                 if (ah->opmode == NL80211_IFTYPE_MONITOR) {
97                         if (rx_stats->rs_status &
98                             ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC |
99                               ATH9K_RXERR_CRC))
100                                 return false;
101                 } else {
102                         if (rx_stats->rs_status &
103                             ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC)) {
104                                 return false;
105                         }
106                 }
107         }
108         return true;
109 }
110
111 static int ath9k_process_rate(struct ath_common *common,
112                               struct ieee80211_hw *hw,
113                               struct ath_rx_status *rx_stats,
114                               struct ieee80211_rx_status *rxs,
115                               struct sk_buff *skb)
116 {
117         struct ieee80211_supported_band *sband;
118         enum ieee80211_band band;
119         unsigned int i = 0;
120
121         band = hw->conf.channel->band;
122         sband = hw->wiphy->bands[band];
123
124         if (rx_stats->rs_rate & 0x80) {
125                 /* HT rate */
126                 rxs->flag |= RX_FLAG_HT;
127                 if (rx_stats->rs_flags & ATH9K_RX_2040)
128                         rxs->flag |= RX_FLAG_40MHZ;
129                 if (rx_stats->rs_flags & ATH9K_RX_GI)
130                         rxs->flag |= RX_FLAG_SHORT_GI;
131                 rxs->rate_idx = rx_stats->rs_rate & 0x7f;
132                 return 0;
133         }
134
135         for (i = 0; i < sband->n_bitrates; i++) {
136                 if (sband->bitrates[i].hw_value == rx_stats->rs_rate) {
137                         rxs->rate_idx = i;
138                         return 0;
139                 }
140                 if (sband->bitrates[i].hw_value_short == rx_stats->rs_rate) {
141                         rxs->flag |= RX_FLAG_SHORTPRE;
142                         rxs->rate_idx = i;
143                         return 0;
144                 }
145         }
146
147         /*
148          * No valid hardware bitrate found -- we should not get here
149          * because hardware has already validated this frame as OK.
150          */
151         ath_print(common, ATH_DBG_XMIT, "unsupported hw bitrate detected "
152                   "0x%02x using 1 Mbit\n", rx_stats->rs_rate);
153         if ((common->debug_mask & ATH_DBG_XMIT))
154                 print_hex_dump_bytes("", DUMP_PREFIX_NONE, skb->data, skb->len);
155
156         rxs->rate_idx = 0;
157         return 0;
158 }
159
160 static void ath9k_process_rssi(struct ath_common *common,
161                                struct ieee80211_hw *hw,
162                                struct sk_buff *skb,
163                                struct ath_rx_status *rx_stats)
164 {
165         struct ath_hw *ah = common->ah;
166         struct ieee80211_sta *sta;
167         struct ieee80211_hdr *hdr;
168         struct ath_node *an;
169         int last_rssi = ATH_RSSI_DUMMY_MARKER;
170         __le16 fc;
171
172         hdr = (struct ieee80211_hdr *)skb->data;
173         fc = hdr->frame_control;
174
175         rcu_read_lock();
176         /*
177          * XXX: use ieee80211_find_sta! This requires quite a bit of work
178          * under the current ath9k virtual wiphy implementation as we have
179          * no way of tying a vif to wiphy. Typically vifs are attached to
180          * at least one sdata of a wiphy on mac80211 but with ath9k virtual
181          * wiphy you'd have to iterate over every wiphy and each sdata.
182          */
183         sta = ieee80211_find_sta_by_hw(hw, hdr->addr2);
184         if (sta) {
185                 an = (struct ath_node *) sta->drv_priv;
186                 if (rx_stats->rs_rssi != ATH9K_RSSI_BAD &&
187                    !rx_stats->rs_moreaggr)
188                         ATH_RSSI_LPF(an->last_rssi, rx_stats->rs_rssi);
189                 last_rssi = an->last_rssi;
190         }
191         rcu_read_unlock();
192
193         if (likely(last_rssi != ATH_RSSI_DUMMY_MARKER))
194                 rx_stats->rs_rssi = ATH_EP_RND(last_rssi,
195                                               ATH_RSSI_EP_MULTIPLIER);
196         if (rx_stats->rs_rssi < 0)
197                 rx_stats->rs_rssi = 0;
198
199         /* Update Beacon RSSI, this is used by ANI. */
200         if (ieee80211_is_beacon(fc))
201                 ah->stats.avgbrssi = rx_stats->rs_rssi;
202 }
203
204 /*
205  * For Decrypt or Demic errors, we only mark packet status here and always push
206  * up the frame up to let mac80211 handle the actual error case, be it no
207  * decryption key or real decryption error. This let us keep statistics there.
208  */
209 int ath9k_cmn_rx_skb_preprocess(struct ath_common *common,
210                                 struct ieee80211_hw *hw,
211                                 struct sk_buff *skb,
212                                 struct ath_rx_status *rx_stats,
213                                 struct ieee80211_rx_status *rx_status,
214                                 bool *decrypt_error)
215 {
216         struct ath_hw *ah = common->ah;
217
218         memset(rx_status, 0, sizeof(struct ieee80211_rx_status));
219
220         /*
221          * everything but the rate is checked here, the rate check is done
222          * separately to avoid doing two lookups for a rate for each frame.
223          */
224         if (!ath9k_rx_accept(common, skb, rx_status, rx_stats, decrypt_error))
225                 return -EINVAL;
226
227         ath9k_process_rssi(common, hw, skb, rx_stats);
228
229         if (ath9k_process_rate(common, hw, rx_stats, rx_status, skb))
230                 return -EINVAL;
231
232         rx_status->mactime = ath9k_hw_extend_tsf(ah, rx_stats->rs_tstamp);
233         rx_status->band = hw->conf.channel->band;
234         rx_status->freq = hw->conf.channel->center_freq;
235         rx_status->signal = ATH_DEFAULT_NOISE_FLOOR + rx_stats->rs_rssi;
236         rx_status->antenna = rx_stats->rs_antenna;
237         rx_status->flag |= RX_FLAG_TSFT;
238
239         return 0;
240 }
241 EXPORT_SYMBOL(ath9k_cmn_rx_skb_preprocess);
242
243 void ath9k_cmn_rx_skb_postprocess(struct ath_common *common,
244                                   struct sk_buff *skb,
245                                   struct ath_rx_status *rx_stats,
246                                   struct ieee80211_rx_status *rxs,
247                                   bool decrypt_error)
248 {
249         struct ath_hw *ah = common->ah;
250         struct ieee80211_hdr *hdr;
251         int hdrlen, padpos, padsize;
252         u8 keyix;
253         __le16 fc;
254
255         /* see if any padding is done by the hw and remove it */
256         hdr = (struct ieee80211_hdr *) skb->data;
257         hdrlen = ieee80211_get_hdrlen_from_skb(skb);
258         fc = hdr->frame_control;
259         padpos = ath9k_cmn_padpos(hdr->frame_control);
260
261         /* The MAC header is padded to have 32-bit boundary if the
262          * packet payload is non-zero. The general calculation for
263          * padsize would take into account odd header lengths:
264          * padsize = (4 - padpos % 4) % 4; However, since only
265          * even-length headers are used, padding can only be 0 or 2
266          * bytes and we can optimize this a bit. In addition, we must
267          * not try to remove padding from short control frames that do
268          * not have payload. */
269         padsize = padpos & 3;
270         if (padsize && skb->len>=padpos+padsize+FCS_LEN) {
271                 memmove(skb->data + padsize, skb->data, padpos);
272                 skb_pull(skb, padsize);
273         }
274
275         keyix = rx_stats->rs_keyix;
276
277         if (!(keyix == ATH9K_RXKEYIX_INVALID) && !decrypt_error &&
278             ieee80211_has_protected(fc)) {
279                 rxs->flag |= RX_FLAG_DECRYPTED;
280         } else if (ieee80211_has_protected(fc)
281                    && !decrypt_error && skb->len >= hdrlen + 4) {
282                 keyix = skb->data[hdrlen + 3] >> 6;
283
284                 if (test_bit(keyix, common->keymap))
285                         rxs->flag |= RX_FLAG_DECRYPTED;
286         }
287         if (ah->sw_mgmt_crypto &&
288             (rxs->flag & RX_FLAG_DECRYPTED) &&
289             ieee80211_is_mgmt(fc))
290                 /* Use software decrypt for management frames. */
291                 rxs->flag &= ~RX_FLAG_DECRYPTED;
292 }
293 EXPORT_SYMBOL(ath9k_cmn_rx_skb_postprocess);
294
295 int ath9k_cmn_padpos(__le16 frame_control)
296 {
297         int padpos = 24;
298         if (ieee80211_has_a4(frame_control)) {
299                 padpos += ETH_ALEN;
300         }
301         if (ieee80211_is_data_qos(frame_control)) {
302                 padpos += IEEE80211_QOS_CTL_LEN;
303         }
304
305         return padpos;
306 }
307 EXPORT_SYMBOL(ath9k_cmn_padpos);
308
309 int ath9k_cmn_get_hw_crypto_keytype(struct sk_buff *skb)
310 {
311         struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
312
313         if (tx_info->control.hw_key) {
314                 if (tx_info->control.hw_key->alg == ALG_WEP)
315                         return ATH9K_KEY_TYPE_WEP;
316                 else if (tx_info->control.hw_key->alg == ALG_TKIP)
317                         return ATH9K_KEY_TYPE_TKIP;
318                 else if (tx_info->control.hw_key->alg == ALG_CCMP)
319                         return ATH9K_KEY_TYPE_AES;
320         }
321
322         return ATH9K_KEY_TYPE_CLEAR;
323 }
324 EXPORT_SYMBOL(ath9k_cmn_get_hw_crypto_keytype);
325
326 static u32 ath9k_get_extchanmode(struct ieee80211_channel *chan,
327                                  enum nl80211_channel_type channel_type)
328 {
329         u32 chanmode = 0;
330
331         switch (chan->band) {
332         case IEEE80211_BAND_2GHZ:
333                 switch (channel_type) {
334                 case NL80211_CHAN_NO_HT:
335                 case NL80211_CHAN_HT20:
336                         chanmode = CHANNEL_G_HT20;
337                         break;
338                 case NL80211_CHAN_HT40PLUS:
339                         chanmode = CHANNEL_G_HT40PLUS;
340                         break;
341                 case NL80211_CHAN_HT40MINUS:
342                         chanmode = CHANNEL_G_HT40MINUS;
343                         break;
344                 }
345                 break;
346         case IEEE80211_BAND_5GHZ:
347                 switch (channel_type) {
348                 case NL80211_CHAN_NO_HT:
349                 case NL80211_CHAN_HT20:
350                         chanmode = CHANNEL_A_HT20;
351                         break;
352                 case NL80211_CHAN_HT40PLUS:
353                         chanmode = CHANNEL_A_HT40PLUS;
354                         break;
355                 case NL80211_CHAN_HT40MINUS:
356                         chanmode = CHANNEL_A_HT40MINUS;
357                         break;
358                 }
359                 break;
360         default:
361                 break;
362         }
363
364         return chanmode;
365 }
366
367 /*
368  * Update internal channel flags.
369  */
370 void ath9k_cmn_update_ichannel(struct ieee80211_hw *hw,
371                                struct ath9k_channel *ichan)
372 {
373         struct ieee80211_channel *chan = hw->conf.channel;
374         struct ieee80211_conf *conf = &hw->conf;
375
376         ichan->channel = chan->center_freq;
377         ichan->chan = chan;
378
379         if (chan->band == IEEE80211_BAND_2GHZ) {
380                 ichan->chanmode = CHANNEL_G;
381                 ichan->channelFlags = CHANNEL_2GHZ | CHANNEL_OFDM | CHANNEL_G;
382         } else {
383                 ichan->chanmode = CHANNEL_A;
384                 ichan->channelFlags = CHANNEL_5GHZ | CHANNEL_OFDM;
385         }
386
387         if (conf_is_ht(conf))
388                 ichan->chanmode = ath9k_get_extchanmode(chan,
389                                                         conf->channel_type);
390 }
391 EXPORT_SYMBOL(ath9k_cmn_update_ichannel);
392
393 /*
394  * Get the internal channel reference.
395  */
396 struct ath9k_channel *ath9k_cmn_get_curchannel(struct ieee80211_hw *hw,
397                                                struct ath_hw *ah)
398 {
399         struct ieee80211_channel *curchan = hw->conf.channel;
400         struct ath9k_channel *channel;
401         u8 chan_idx;
402
403         chan_idx = curchan->hw_value;
404         channel = &ah->channels[chan_idx];
405         ath9k_cmn_update_ichannel(hw, channel);
406
407         return channel;
408 }
409 EXPORT_SYMBOL(ath9k_cmn_get_curchannel);
410
411 static int ath_setkey_tkip(struct ath_common *common, u16 keyix, const u8 *key,
412                            struct ath9k_keyval *hk, const u8 *addr,
413                            bool authenticator)
414 {
415         struct ath_hw *ah = common->ah;
416         const u8 *key_rxmic;
417         const u8 *key_txmic;
418
419         key_txmic = key + NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY;
420         key_rxmic = key + NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY;
421
422         if (addr == NULL) {
423                 /*
424                  * Group key installation - only two key cache entries are used
425                  * regardless of splitmic capability since group key is only
426                  * used either for TX or RX.
427                  */
428                 if (authenticator) {
429                         memcpy(hk->kv_mic, key_txmic, sizeof(hk->kv_mic));
430                         memcpy(hk->kv_txmic, key_txmic, sizeof(hk->kv_mic));
431                 } else {
432                         memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
433                         memcpy(hk->kv_txmic, key_rxmic, sizeof(hk->kv_mic));
434                 }
435                 return ath9k_hw_set_keycache_entry(ah, keyix, hk, addr);
436         }
437         if (!common->splitmic) {
438                 /* TX and RX keys share the same key cache entry. */
439                 memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
440                 memcpy(hk->kv_txmic, key_txmic, sizeof(hk->kv_txmic));
441                 return ath9k_hw_set_keycache_entry(ah, keyix, hk, addr);
442         }
443
444         /* Separate key cache entries for TX and RX */
445
446         /* TX key goes at first index, RX key at +32. */
447         memcpy(hk->kv_mic, key_txmic, sizeof(hk->kv_mic));
448         if (!ath9k_hw_set_keycache_entry(ah, keyix, hk, NULL)) {
449                 /* TX MIC entry failed. No need to proceed further */
450                 ath_print(common, ATH_DBG_FATAL,
451                           "Setting TX MIC Key Failed\n");
452                 return 0;
453         }
454
455         memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
456         /* XXX delete tx key on failure? */
457         return ath9k_hw_set_keycache_entry(ah, keyix + 32, hk, addr);
458 }
459
460 static int ath_reserve_key_cache_slot_tkip(struct ath_common *common)
461 {
462         int i;
463
464         for (i = IEEE80211_WEP_NKID; i < common->keymax / 2; i++) {
465                 if (test_bit(i, common->keymap) ||
466                     test_bit(i + 64, common->keymap))
467                         continue; /* At least one part of TKIP key allocated */
468                 if (common->splitmic &&
469                     (test_bit(i + 32, common->keymap) ||
470                      test_bit(i + 64 + 32, common->keymap)))
471                         continue; /* At least one part of TKIP key allocated */
472
473                 /* Found a free slot for a TKIP key */
474                 return i;
475         }
476         return -1;
477 }
478
479 static int ath_reserve_key_cache_slot(struct ath_common *common)
480 {
481         int i;
482
483         /* First, try to find slots that would not be available for TKIP. */
484         if (common->splitmic) {
485                 for (i = IEEE80211_WEP_NKID; i < common->keymax / 4; i++) {
486                         if (!test_bit(i, common->keymap) &&
487                             (test_bit(i + 32, common->keymap) ||
488                              test_bit(i + 64, common->keymap) ||
489                              test_bit(i + 64 + 32, common->keymap)))
490                                 return i;
491                         if (!test_bit(i + 32, common->keymap) &&
492                             (test_bit(i, common->keymap) ||
493                              test_bit(i + 64, common->keymap) ||
494                              test_bit(i + 64 + 32, common->keymap)))
495                                 return i + 32;
496                         if (!test_bit(i + 64, common->keymap) &&
497                             (test_bit(i , common->keymap) ||
498                              test_bit(i + 32, common->keymap) ||
499                              test_bit(i + 64 + 32, common->keymap)))
500                                 return i + 64;
501                         if (!test_bit(i + 64 + 32, common->keymap) &&
502                             (test_bit(i, common->keymap) ||
503                              test_bit(i + 32, common->keymap) ||
504                              test_bit(i + 64, common->keymap)))
505                                 return i + 64 + 32;
506                 }
507         } else {
508                 for (i = IEEE80211_WEP_NKID; i < common->keymax / 2; i++) {
509                         if (!test_bit(i, common->keymap) &&
510                             test_bit(i + 64, common->keymap))
511                                 return i;
512                         if (test_bit(i, common->keymap) &&
513                             !test_bit(i + 64, common->keymap))
514                                 return i + 64;
515                 }
516         }
517
518         /* No partially used TKIP slots, pick any available slot */
519         for (i = IEEE80211_WEP_NKID; i < common->keymax; i++) {
520                 /* Do not allow slots that could be needed for TKIP group keys
521                  * to be used. This limitation could be removed if we know that
522                  * TKIP will not be used. */
523                 if (i >= 64 && i < 64 + IEEE80211_WEP_NKID)
524                         continue;
525                 if (common->splitmic) {
526                         if (i >= 32 && i < 32 + IEEE80211_WEP_NKID)
527                                 continue;
528                         if (i >= 64 + 32 && i < 64 + 32 + IEEE80211_WEP_NKID)
529                                 continue;
530                 }
531
532                 if (!test_bit(i, common->keymap))
533                         return i; /* Found a free slot for a key */
534         }
535
536         /* No free slot found */
537         return -1;
538 }
539
540 /*
541  * Configure encryption in the HW.
542  */
543 int ath9k_cmn_key_config(struct ath_common *common,
544                          struct ieee80211_vif *vif,
545                          struct ieee80211_sta *sta,
546                          struct ieee80211_key_conf *key)
547 {
548         struct ath_hw *ah = common->ah;
549         struct ath9k_keyval hk;
550         const u8 *mac = NULL;
551         int ret = 0;
552         int idx;
553
554         memset(&hk, 0, sizeof(hk));
555
556         switch (key->alg) {
557         case ALG_WEP:
558                 hk.kv_type = ATH9K_CIPHER_WEP;
559                 break;
560         case ALG_TKIP:
561                 hk.kv_type = ATH9K_CIPHER_TKIP;
562                 break;
563         case ALG_CCMP:
564                 hk.kv_type = ATH9K_CIPHER_AES_CCM;
565                 break;
566         default:
567                 return -EOPNOTSUPP;
568         }
569
570         hk.kv_len = key->keylen;
571         memcpy(hk.kv_val, key->key, key->keylen);
572
573         if (!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
574                 /* For now, use the default keys for broadcast keys. This may
575                  * need to change with virtual interfaces. */
576                 idx = key->keyidx;
577         } else if (key->keyidx) {
578                 if (WARN_ON(!sta))
579                         return -EOPNOTSUPP;
580                 mac = sta->addr;
581
582                 if (vif->type != NL80211_IFTYPE_AP) {
583                         /* Only keyidx 0 should be used with unicast key, but
584                          * allow this for client mode for now. */
585                         idx = key->keyidx;
586                 } else
587                         return -EIO;
588         } else {
589                 if (WARN_ON(!sta))
590                         return -EOPNOTSUPP;
591                 mac = sta->addr;
592
593                 if (key->alg == ALG_TKIP)
594                         idx = ath_reserve_key_cache_slot_tkip(common);
595                 else
596                         idx = ath_reserve_key_cache_slot(common);
597                 if (idx < 0)
598                         return -ENOSPC; /* no free key cache entries */
599         }
600
601         if (key->alg == ALG_TKIP)
602                 ret = ath_setkey_tkip(common, idx, key->key, &hk, mac,
603                                       vif->type == NL80211_IFTYPE_AP);
604         else
605                 ret = ath9k_hw_set_keycache_entry(ah, idx, &hk, mac);
606
607         if (!ret)
608                 return -EIO;
609
610         set_bit(idx, common->keymap);
611         if (key->alg == ALG_TKIP) {
612                 set_bit(idx + 64, common->keymap);
613                 if (common->splitmic) {
614                         set_bit(idx + 32, common->keymap);
615                         set_bit(idx + 64 + 32, common->keymap);
616                 }
617         }
618
619         return idx;
620 }
621 EXPORT_SYMBOL(ath9k_cmn_key_config);
622
623 /*
624  * Delete Key.
625  */
626 void ath9k_cmn_key_delete(struct ath_common *common,
627                           struct ieee80211_key_conf *key)
628 {
629         struct ath_hw *ah = common->ah;
630
631         ath9k_hw_keyreset(ah, key->hw_key_idx);
632         if (key->hw_key_idx < IEEE80211_WEP_NKID)
633                 return;
634
635         clear_bit(key->hw_key_idx, common->keymap);
636         if (key->alg != ALG_TKIP)
637                 return;
638
639         clear_bit(key->hw_key_idx + 64, common->keymap);
640         if (common->splitmic) {
641                 ath9k_hw_keyreset(ah, key->hw_key_idx + 32);
642                 clear_bit(key->hw_key_idx + 32, common->keymap);
643                 clear_bit(key->hw_key_idx + 64 + 32, common->keymap);
644         }
645 }
646 EXPORT_SYMBOL(ath9k_cmn_key_delete);
647
648 static int __init ath9k_cmn_init(void)
649 {
650         return 0;
651 }
652 module_init(ath9k_cmn_init);
653
654 static void __exit ath9k_cmn_exit(void)
655 {
656         return;
657 }
658 module_exit(ath9k_cmn_exit);