Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1 | /* IEEE 802.11 SoftMAC layer |
Andrea Merello | 559a4c3 | 2013-08-26 13:53:30 +0200 | [diff] [blame] | 2 | * Copyright (c) 2005 Andrea Merello <andrea.merello@gmail.com> |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3 | * |
| 4 | * Mostly extracted from the rtl8180-sa2400 driver for the |
| 5 | * in-kernel generic ieee802.11 stack. |
| 6 | * |
| 7 | * Few lines might be stolen from other part of the rtllib |
| 8 | * stack. Copyright who own it's copyright |
| 9 | * |
| 10 | * WPA code stolen from the ipw2200 driver. |
| 11 | * Copyright who own it's copyright. |
| 12 | * |
| 13 | * released under the GPL |
| 14 | */ |
| 15 | |
| 16 | |
| 17 | #include "rtllib.h" |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 18 | |
| 19 | #include <linux/random.h> |
| 20 | #include <linux/delay.h> |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 21 | #include <linux/uaccess.h> |
Wei Yongjun | 0c43e56 | 2012-08-26 09:04:23 +0800 | [diff] [blame] | 22 | #include <linux/etherdevice.h> |
Paul Gortmaker | acd442d | 2015-04-27 01:25:41 -0400 | [diff] [blame] | 23 | #include <linux/ieee80211.h> |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 24 | #include "dot11d.h" |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 25 | |
Mateusz Kulikowski | 6957248 | 2015-07-14 22:04:26 +0200 | [diff] [blame] | 26 | static void rtllib_sta_wakeup(struct rtllib_device *ieee, short nl); |
| 27 | |
| 28 | |
| 29 | static short rtllib_is_54g(struct rtllib_network *net) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 30 | { |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 31 | return (net->rates_ex_len > 0) || (net->rates_len > 4); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 32 | } |
| 33 | |
Justin P. Mattock | cd01712 | 2012-04-23 07:36:52 -0700 | [diff] [blame] | 34 | /* returns the total length needed for placing the RATE MFIE |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 35 | * tag and the EXTENDED RATE MFIE tag if needed. |
| 36 | * It encludes two bytes per tag for the tag itself and its len |
| 37 | */ |
Larry Finger | ec0dc6be | 2011-08-25 14:07:04 -0500 | [diff] [blame] | 38 | static unsigned int rtllib_MFIE_rate_len(struct rtllib_device *ieee) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 39 | { |
| 40 | unsigned int rate_len = 0; |
| 41 | |
| 42 | if (ieee->modulation & RTLLIB_CCK_MODULATION) |
| 43 | rate_len = RTLLIB_CCK_RATE_LEN + 2; |
| 44 | |
| 45 | if (ieee->modulation & RTLLIB_OFDM_MODULATION) |
| 46 | |
| 47 | rate_len += RTLLIB_OFDM_RATE_LEN + 2; |
| 48 | |
| 49 | return rate_len; |
| 50 | } |
| 51 | |
Justin P. Mattock | cd01712 | 2012-04-23 07:36:52 -0700 | [diff] [blame] | 52 | /* place the MFIE rate, tag to the memory (double) pointed. |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 53 | * Then it updates the pointer so that |
| 54 | * it points after the new MFIE tag added. |
| 55 | */ |
Larry Finger | ec0dc6be | 2011-08-25 14:07:04 -0500 | [diff] [blame] | 56 | static void rtllib_MFIE_Brate(struct rtllib_device *ieee, u8 **tag_p) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 57 | { |
| 58 | u8 *tag = *tag_p; |
| 59 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 60 | if (ieee->modulation & RTLLIB_CCK_MODULATION) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 61 | *tag++ = MFIE_TYPE_RATES; |
| 62 | *tag++ = 4; |
| 63 | *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_1MB; |
| 64 | *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_2MB; |
| 65 | *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_5MB; |
| 66 | *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_11MB; |
| 67 | } |
| 68 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 69 | /* We may add an option for custom rates that specific HW |
Mateusz Kulikowski | 14b40d9 | 2015-04-01 00:24:37 +0200 | [diff] [blame] | 70 | * might support |
| 71 | */ |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 72 | *tag_p = tag; |
| 73 | } |
| 74 | |
Larry Finger | ec0dc6be | 2011-08-25 14:07:04 -0500 | [diff] [blame] | 75 | static void rtllib_MFIE_Grate(struct rtllib_device *ieee, u8 **tag_p) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 76 | { |
| 77 | u8 *tag = *tag_p; |
| 78 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 79 | if (ieee->modulation & RTLLIB_OFDM_MODULATION) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 80 | *tag++ = MFIE_TYPE_RATES_EX; |
| 81 | *tag++ = 8; |
| 82 | *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_6MB; |
| 83 | *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_9MB; |
| 84 | *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_12MB; |
| 85 | *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_18MB; |
| 86 | *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_24MB; |
| 87 | *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_36MB; |
| 88 | *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_48MB; |
| 89 | *tag++ = RTLLIB_BASIC_RATE_MASK | RTLLIB_OFDM_RATE_54MB; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 90 | } |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 91 | /* We may add an option for custom rates that specific HW might |
Mateusz Kulikowski | 14b40d9 | 2015-04-01 00:24:37 +0200 | [diff] [blame] | 92 | * support |
| 93 | */ |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 94 | *tag_p = tag; |
| 95 | } |
| 96 | |
Larry Finger | ec0dc6be | 2011-08-25 14:07:04 -0500 | [diff] [blame] | 97 | static void rtllib_WMM_Info(struct rtllib_device *ieee, u8 **tag_p) |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 98 | { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 99 | u8 *tag = *tag_p; |
| 100 | |
| 101 | *tag++ = MFIE_TYPE_GENERIC; |
| 102 | *tag++ = 7; |
| 103 | *tag++ = 0x00; |
| 104 | *tag++ = 0x50; |
| 105 | *tag++ = 0xf2; |
| 106 | *tag++ = 0x02; |
| 107 | *tag++ = 0x00; |
| 108 | *tag++ = 0x01; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 109 | *tag++ = MAX_SP_Len; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 110 | *tag_p = tag; |
| 111 | } |
| 112 | |
Mateusz Kulikowski | 6957248 | 2015-07-14 22:04:26 +0200 | [diff] [blame] | 113 | static void rtllib_TURBO_Info(struct rtllib_device *ieee, u8 **tag_p) |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 114 | { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 115 | u8 *tag = *tag_p; |
| 116 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 117 | *tag++ = MFIE_TYPE_GENERIC; |
| 118 | *tag++ = 7; |
| 119 | *tag++ = 0x00; |
| 120 | *tag++ = 0xe0; |
| 121 | *tag++ = 0x4c; |
| 122 | *tag++ = 0x01; |
| 123 | *tag++ = 0x02; |
| 124 | *tag++ = 0x11; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 125 | *tag++ = 0x00; |
| 126 | |
| 127 | *tag_p = tag; |
Mateusz Kulikowski | d69d205 | 2015-03-17 00:00:52 +0100 | [diff] [blame] | 128 | netdev_alert(ieee->dev, "This is enable turbo mode IE process\n"); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 129 | } |
| 130 | |
Larry Finger | ec0dc6be | 2011-08-25 14:07:04 -0500 | [diff] [blame] | 131 | static void enqueue_mgmt(struct rtllib_device *ieee, struct sk_buff *skb) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 132 | { |
| 133 | int nh; |
Matthew Casey | 3a6b70c | 2014-08-22 06:27:52 -0400 | [diff] [blame] | 134 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 135 | nh = (ieee->mgmt_queue_head + 1) % MGMT_QUEUE_NUM; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 136 | |
Mateusz Kulikowski | 14b40d9 | 2015-04-01 00:24:37 +0200 | [diff] [blame] | 137 | /* if the queue is full but we have newer frames then |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 138 | * just overwrites the oldest. |
| 139 | * |
| 140 | * if (nh == ieee->mgmt_queue_tail) |
| 141 | * return -1; |
| 142 | */ |
| 143 | ieee->mgmt_queue_head = nh; |
| 144 | ieee->mgmt_queue_ring[nh] = skb; |
| 145 | |
| 146 | } |
| 147 | |
Larry Finger | ec0dc6be | 2011-08-25 14:07:04 -0500 | [diff] [blame] | 148 | static void init_mgmt_queue(struct rtllib_device *ieee) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 149 | { |
| 150 | ieee->mgmt_queue_tail = ieee->mgmt_queue_head = 0; |
| 151 | } |
| 152 | |
| 153 | |
| 154 | u8 |
| 155 | MgntQuery_TxRateExcludeCCKRates(struct rtllib_device *ieee) |
| 156 | { |
| 157 | u16 i; |
| 158 | u8 QueryRate = 0; |
| 159 | u8 BasicRate; |
| 160 | |
| 161 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 162 | for (i = 0; i < ieee->current_network.rates_len; i++) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 163 | BasicRate = ieee->current_network.rates[i]&0x7F; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 164 | if (!rtllib_is_cck_rate(BasicRate)) { |
| 165 | if (QueryRate == 0) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 166 | QueryRate = BasicRate; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 167 | } else { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 168 | if (BasicRate < QueryRate) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 169 | QueryRate = BasicRate; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 170 | } |
| 171 | } |
| 172 | } |
| 173 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 174 | if (QueryRate == 0) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 175 | QueryRate = 12; |
Mateusz Kulikowski | d69d205 | 2015-03-17 00:00:52 +0100 | [diff] [blame] | 176 | netdev_info(ieee->dev, "No BasicRate found!!\n"); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 177 | } |
| 178 | return QueryRate; |
| 179 | } |
| 180 | |
Behan Webster | d82f002 | 2014-10-29 15:42:22 -0700 | [diff] [blame] | 181 | static u8 MgntQuery_MgntFrameTxRate(struct rtllib_device *ieee) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 182 | { |
Larry Finger | 7796d93 | 2011-07-18 20:22:19 -0500 | [diff] [blame] | 183 | struct rt_hi_throughput *pHTInfo = ieee->pHTInfo; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 184 | u8 rate; |
| 185 | |
| 186 | if (pHTInfo->IOTAction & HT_IOT_ACT_MGNT_USE_CCK_6M) |
| 187 | rate = 0x0c; |
| 188 | else |
| 189 | rate = ieee->basic_rate & 0x7f; |
| 190 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 191 | if (rate == 0) { |
| 192 | if (ieee->mode == IEEE_A || |
| 193 | ieee->mode == IEEE_N_5G || |
| 194 | (ieee->mode == IEEE_N_24G && !pHTInfo->bCurSuppCCK)) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 195 | rate = 0x0c; |
| 196 | else |
| 197 | rate = 0x02; |
| 198 | } |
| 199 | |
| 200 | return rate; |
| 201 | } |
| 202 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 203 | inline void softmac_mgmt_xmit(struct sk_buff *skb, struct rtllib_device *ieee) |
| 204 | { |
| 205 | unsigned long flags; |
| 206 | short single = ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 207 | struct rtllib_hdr_3addr *header = |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 208 | (struct rtllib_hdr_3addr *) skb->data; |
| 209 | |
Larry Finger | 3b83db4 | 2011-07-19 00:01:29 -0500 | [diff] [blame] | 210 | struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + 8); |
Matthew Casey | 3a6b70c | 2014-08-22 06:27:52 -0400 | [diff] [blame] | 211 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 212 | spin_lock_irqsave(&ieee->lock, flags); |
| 213 | |
| 214 | /* called with 2nd param 0, no mgmt lock required */ |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 215 | rtllib_sta_wakeup(ieee, 0); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 216 | |
Rashika Kheria | f7df191 | 2013-11-07 18:56:28 +0530 | [diff] [blame] | 217 | if (le16_to_cpu(header->frame_ctl) == RTLLIB_STYPE_BEACON) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 218 | tcb_desc->queue_index = BEACON_QUEUE; |
| 219 | else |
| 220 | tcb_desc->queue_index = MGNT_QUEUE; |
| 221 | |
| 222 | if (ieee->disable_mgnt_queue) |
| 223 | tcb_desc->queue_index = HIGH_QUEUE; |
| 224 | |
| 225 | tcb_desc->data_rate = MgntQuery_MgntFrameTxRate(ieee); |
| 226 | tcb_desc->RATRIndex = 7; |
| 227 | tcb_desc->bTxDisableRateFallBack = 1; |
| 228 | tcb_desc->bTxUseDriverAssingedRate = 1; |
| 229 | if (single) { |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 230 | if (ieee->queue_stop) { |
| 231 | enqueue_mgmt(ieee, skb); |
| 232 | } else { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 233 | header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0]<<4); |
| 234 | |
| 235 | if (ieee->seq_ctrl[0] == 0xFFF) |
| 236 | ieee->seq_ctrl[0] = 0; |
| 237 | else |
| 238 | ieee->seq_ctrl[0]++; |
| 239 | |
| 240 | /* avoid watchdog triggers */ |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 241 | ieee->softmac_data_hard_start_xmit(skb, ieee->dev, |
| 242 | ieee->basic_rate); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | spin_unlock_irqrestore(&ieee->lock, flags); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 246 | } else { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 247 | spin_unlock_irqrestore(&ieee->lock, flags); |
| 248 | spin_lock_irqsave(&ieee->mgmt_tx_lock, flags); |
| 249 | |
| 250 | header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4); |
| 251 | |
| 252 | if (ieee->seq_ctrl[0] == 0xFFF) |
| 253 | ieee->seq_ctrl[0] = 0; |
| 254 | else |
| 255 | ieee->seq_ctrl[0]++; |
| 256 | |
Adam Buchbinder | f263589 | 2012-09-19 21:51:07 -0400 | [diff] [blame] | 257 | /* check whether the managed packet queued greater than 5 */ |
Mateusz Kulikowski | 35e33b0 | 2015-05-31 20:19:40 +0200 | [diff] [blame] | 258 | if (!ieee->check_nic_enough_desc(ieee->dev, |
| 259 | tcb_desc->queue_index) || |
| 260 | skb_queue_len(&ieee->skb_waitQ[tcb_desc->queue_index]) || |
| 261 | ieee->queue_stop) { |
Mateusz Kulikowski | 14b40d9 | 2015-04-01 00:24:37 +0200 | [diff] [blame] | 262 | /* insert the skb packet to the management queue |
| 263 | * |
| 264 | * as for the completion function, it does not need |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 265 | * to check it any more. |
Mateusz Kulikowski | 14b40d9 | 2015-04-01 00:24:37 +0200 | [diff] [blame] | 266 | */ |
Mateusz Kulikowski | d69d205 | 2015-03-17 00:00:52 +0100 | [diff] [blame] | 267 | netdev_info(ieee->dev, |
Mateusz Kulikowski | 0822339 | 2015-03-17 00:00:48 +0100 | [diff] [blame] | 268 | "%s():insert to waitqueue, queue_index:%d!\n", |
| 269 | __func__, tcb_desc->queue_index); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 270 | skb_queue_tail(&ieee->skb_waitQ[tcb_desc->queue_index], |
| 271 | skb); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 272 | } else { |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 273 | ieee->softmac_hard_start_xmit(skb, ieee->dev); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 274 | } |
| 275 | spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags); |
| 276 | } |
| 277 | } |
| 278 | |
Baoyou Xie | ec65ef8 | 2016-09-04 14:33:35 +0800 | [diff] [blame] | 279 | static inline void |
| 280 | softmac_ps_mgmt_xmit(struct sk_buff *skb, |
| 281 | struct rtllib_device *ieee) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 282 | { |
| 283 | short single = ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE; |
| 284 | struct rtllib_hdr_3addr *header = |
| 285 | (struct rtllib_hdr_3addr *) skb->data; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 286 | u16 fc, type, stype; |
Larry Finger | 3b83db4 | 2011-07-19 00:01:29 -0500 | [diff] [blame] | 287 | struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + 8); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 288 | |
Rashika Kheria | 1830a6d | 2013-11-07 18:58:57 +0530 | [diff] [blame] | 289 | fc = le16_to_cpu(header->frame_ctl); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 290 | type = WLAN_FC_GET_TYPE(fc); |
| 291 | stype = WLAN_FC_GET_STYPE(fc); |
| 292 | |
| 293 | |
| 294 | if (stype != RTLLIB_STYPE_PSPOLL) |
| 295 | tcb_desc->queue_index = MGNT_QUEUE; |
| 296 | else |
| 297 | tcb_desc->queue_index = HIGH_QUEUE; |
| 298 | |
| 299 | if (ieee->disable_mgnt_queue) |
| 300 | tcb_desc->queue_index = HIGH_QUEUE; |
| 301 | |
| 302 | |
| 303 | tcb_desc->data_rate = MgntQuery_MgntFrameTxRate(ieee); |
| 304 | tcb_desc->RATRIndex = 7; |
| 305 | tcb_desc->bTxDisableRateFallBack = 1; |
| 306 | tcb_desc->bTxUseDriverAssingedRate = 1; |
| 307 | if (single) { |
| 308 | if (type != RTLLIB_FTYPE_CTL) { |
| 309 | header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4); |
| 310 | |
| 311 | if (ieee->seq_ctrl[0] == 0xFFF) |
| 312 | ieee->seq_ctrl[0] = 0; |
| 313 | else |
| 314 | ieee->seq_ctrl[0]++; |
| 315 | |
| 316 | } |
| 317 | /* avoid watchdog triggers */ |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 318 | ieee->softmac_data_hard_start_xmit(skb, ieee->dev, |
| 319 | ieee->basic_rate); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 320 | |
| 321 | } else { |
| 322 | if (type != RTLLIB_FTYPE_CTL) { |
| 323 | header->seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4); |
| 324 | |
| 325 | if (ieee->seq_ctrl[0] == 0xFFF) |
| 326 | ieee->seq_ctrl[0] = 0; |
| 327 | else |
| 328 | ieee->seq_ctrl[0]++; |
| 329 | } |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 330 | ieee->softmac_hard_start_xmit(skb, ieee->dev); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 331 | |
| 332 | } |
| 333 | } |
| 334 | |
Behan Webster | 6d91857 | 2014-10-29 15:42:20 -0700 | [diff] [blame] | 335 | static inline struct sk_buff *rtllib_probe_req(struct rtllib_device *ieee) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 336 | { |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 337 | unsigned int len, rate_len; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 338 | u8 *tag; |
| 339 | struct sk_buff *skb; |
| 340 | struct rtllib_probe_request *req; |
| 341 | |
| 342 | len = ieee->current_network.ssid_len; |
| 343 | |
| 344 | rate_len = rtllib_MFIE_rate_len(ieee); |
| 345 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 346 | skb = dev_alloc_skb(sizeof(struct rtllib_probe_request) + |
| 347 | 2 + len + rate_len + ieee->tx_headroom); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 348 | |
| 349 | if (!skb) |
| 350 | return NULL; |
| 351 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 352 | skb_reserve(skb, ieee->tx_headroom); |
| 353 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 354 | req = (struct rtllib_probe_request *) skb_put(skb, |
| 355 | sizeof(struct rtllib_probe_request)); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 356 | req->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_PROBE_REQ); |
| 357 | req->header.duration_id = 0; |
| 358 | |
Hari Prasath Gujulan Elango | 686f0c2 | 2016-02-08 04:44:13 +0000 | [diff] [blame] | 359 | eth_broadcast_addr(req->header.addr1); |
Mateusz Kulikowski | b57ceb1 | 2015-05-31 20:19:22 +0200 | [diff] [blame] | 360 | ether_addr_copy(req->header.addr2, ieee->dev->dev_addr); |
Hari Prasath Gujulan Elango | 686f0c2 | 2016-02-08 04:44:13 +0000 | [diff] [blame] | 361 | eth_broadcast_addr(req->header.addr3); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 362 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 363 | tag = (u8 *) skb_put(skb, len + 2 + rate_len); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 364 | |
| 365 | *tag++ = MFIE_TYPE_SSID; |
| 366 | *tag++ = len; |
| 367 | memcpy(tag, ieee->current_network.ssid, len); |
| 368 | tag += len; |
| 369 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 370 | rtllib_MFIE_Brate(ieee, &tag); |
| 371 | rtllib_MFIE_Grate(ieee, &tag); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 372 | |
| 373 | return skb; |
| 374 | } |
| 375 | |
Mateusz Kulikowski | 6957248 | 2015-07-14 22:04:26 +0200 | [diff] [blame] | 376 | static struct sk_buff *rtllib_get_beacon_(struct rtllib_device *ieee); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 377 | |
Larry Finger | ec0dc6be | 2011-08-25 14:07:04 -0500 | [diff] [blame] | 378 | static void rtllib_send_beacon(struct rtllib_device *ieee) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 379 | { |
| 380 | struct sk_buff *skb; |
Matthew Casey | 3a6b70c | 2014-08-22 06:27:52 -0400 | [diff] [blame] | 381 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 382 | if (!ieee->ieee_up) |
| 383 | return; |
| 384 | skb = rtllib_get_beacon_(ieee); |
| 385 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 386 | if (skb) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 387 | softmac_mgmt_xmit(skb, ieee); |
| 388 | ieee->softmac_stats.tx_beacons++; |
| 389 | } |
| 390 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 391 | if (ieee->beacon_txing && ieee->ieee_up) |
| 392 | mod_timer(&ieee->beacon_timer, jiffies + |
Vaishali Thakkar | 8b9733c | 2015-03-11 13:51:36 +0530 | [diff] [blame] | 393 | (msecs_to_jiffies(ieee->current_network.beacon_interval - 5))); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | |
Larry Finger | ec0dc6be | 2011-08-25 14:07:04 -0500 | [diff] [blame] | 397 | static void rtllib_send_beacon_cb(unsigned long _ieee) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 398 | { |
| 399 | struct rtllib_device *ieee = |
| 400 | (struct rtllib_device *) _ieee; |
| 401 | unsigned long flags; |
| 402 | |
| 403 | spin_lock_irqsave(&ieee->beacon_lock, flags); |
| 404 | rtllib_send_beacon(ieee); |
| 405 | spin_unlock_irqrestore(&ieee->beacon_lock, flags); |
| 406 | } |
| 407 | |
Mateusz Kulikowski | 14b40d9 | 2015-04-01 00:24:37 +0200 | [diff] [blame] | 408 | /* Enables network monitor mode, all rx packets will be received. */ |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 409 | void rtllib_EnableNetMonitorMode(struct net_device *dev, |
| 410 | bool bInitState) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 411 | { |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 412 | struct rtllib_device *ieee = netdev_priv_rsl(dev); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 413 | |
Mateusz Kulikowski | d69d205 | 2015-03-17 00:00:52 +0100 | [diff] [blame] | 414 | netdev_info(dev, "========>Enter Monitor Mode\n"); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 415 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 416 | ieee->AllowAllDestAddrHandler(dev, true, !bInitState); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | |
Mateusz Kulikowski | 14b40d9 | 2015-04-01 00:24:37 +0200 | [diff] [blame] | 420 | /* Disables network monitor mode. Only packets destinated to |
| 421 | * us will be received. |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 422 | */ |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 423 | void rtllib_DisableNetMonitorMode(struct net_device *dev, |
| 424 | bool bInitState) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 425 | { |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 426 | struct rtllib_device *ieee = netdev_priv_rsl(dev); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 427 | |
Mateusz Kulikowski | d69d205 | 2015-03-17 00:00:52 +0100 | [diff] [blame] | 428 | netdev_info(dev, "========>Exit Monitor Mode\n"); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 429 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 430 | ieee->AllowAllDestAddrHandler(dev, false, !bInitState); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | |
Mateusz Kulikowski | 14b40d9 | 2015-04-01 00:24:37 +0200 | [diff] [blame] | 434 | /* Enables the specialized promiscuous mode required by Intel. |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 435 | * In this mode, Intel intends to hear traffics from/to other STAs in the |
| 436 | * same BSS. Therefore we don't have to disable checking BSSID and we only need |
| 437 | * to allow all dest. BUT: if we enable checking BSSID then we can't recv |
| 438 | * packets from other STA. |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 439 | */ |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 440 | void rtllib_EnableIntelPromiscuousMode(struct net_device *dev, |
| 441 | bool bInitState) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 442 | { |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 443 | bool bFilterOutNonAssociatedBSSID = false; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 444 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 445 | struct rtllib_device *ieee = netdev_priv_rsl(dev); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 446 | |
Mateusz Kulikowski | d69d205 | 2015-03-17 00:00:52 +0100 | [diff] [blame] | 447 | netdev_info(dev, "========>Enter Intel Promiscuous Mode\n"); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 448 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 449 | ieee->AllowAllDestAddrHandler(dev, true, !bInitState); |
| 450 | ieee->SetHwRegHandler(dev, HW_VAR_CECHK_BSSID, |
| 451 | (u8 *)&bFilterOutNonAssociatedBSSID); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 452 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 453 | ieee->bNetPromiscuousMode = true; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 454 | } |
Sean MacLennan | 3b28499 | 2011-11-28 20:20:26 -0500 | [diff] [blame] | 455 | EXPORT_SYMBOL(rtllib_EnableIntelPromiscuousMode); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 456 | |
| 457 | |
Mateusz Kulikowski | 14b40d9 | 2015-04-01 00:24:37 +0200 | [diff] [blame] | 458 | /* Disables the specialized promiscuous mode required by Intel. |
| 459 | * See MgntEnableIntelPromiscuousMode for detail. |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 460 | */ |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 461 | void rtllib_DisableIntelPromiscuousMode(struct net_device *dev, |
| 462 | bool bInitState) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 463 | { |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 464 | bool bFilterOutNonAssociatedBSSID = true; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 465 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 466 | struct rtllib_device *ieee = netdev_priv_rsl(dev); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 467 | |
Mateusz Kulikowski | d69d205 | 2015-03-17 00:00:52 +0100 | [diff] [blame] | 468 | netdev_info(dev, "========>Exit Intel Promiscuous Mode\n"); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 469 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 470 | ieee->AllowAllDestAddrHandler(dev, false, !bInitState); |
| 471 | ieee->SetHwRegHandler(dev, HW_VAR_CECHK_BSSID, |
| 472 | (u8 *)&bFilterOutNonAssociatedBSSID); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 473 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 474 | ieee->bNetPromiscuousMode = false; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 475 | } |
Sean MacLennan | 3b28499 | 2011-11-28 20:20:26 -0500 | [diff] [blame] | 476 | EXPORT_SYMBOL(rtllib_DisableIntelPromiscuousMode); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 477 | |
Larry Finger | ec0dc6be | 2011-08-25 14:07:04 -0500 | [diff] [blame] | 478 | static void rtllib_send_probe(struct rtllib_device *ieee, u8 is_mesh) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 479 | { |
| 480 | struct sk_buff *skb; |
Matthew Casey | 3a6b70c | 2014-08-22 06:27:52 -0400 | [diff] [blame] | 481 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 482 | skb = rtllib_probe_req(ieee); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 483 | if (skb) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 484 | softmac_mgmt_xmit(skb, ieee); |
| 485 | ieee->softmac_stats.tx_probe_rq++; |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | |
Mateusz Kulikowski | 6957248 | 2015-07-14 22:04:26 +0200 | [diff] [blame] | 490 | static void rtllib_send_probe_requests(struct rtllib_device *ieee, u8 is_mesh) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 491 | { |
| 492 | if (ieee->active_scan && (ieee->softmac_features & |
| 493 | IEEE_SOFTMAC_PROBERQ)) { |
| 494 | rtllib_send_probe(ieee, 0); |
| 495 | rtllib_send_probe(ieee, 0); |
| 496 | } |
| 497 | } |
| 498 | |
Mateusz Kulikowski | 6957248 | 2015-07-14 22:04:26 +0200 | [diff] [blame] | 499 | static void rtllib_update_active_chan_map(struct rtllib_device *ieee) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 500 | { |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 501 | memcpy(ieee->active_channel_map, GET_DOT11D_INFO(ieee)->channel_map, |
| 502 | MAX_CHANNEL_NUMBER+1); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | /* this performs syncro scan blocking the caller until all channels |
| 506 | * in the allowed channel map has been checked. |
| 507 | */ |
Mateusz Kulikowski | 6957248 | 2015-07-14 22:04:26 +0200 | [diff] [blame] | 508 | static void rtllib_softmac_scan_syncro(struct rtllib_device *ieee, u8 is_mesh) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 509 | { |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 510 | union iwreq_data wrqu; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 511 | short ch = 0; |
| 512 | |
| 513 | rtllib_update_active_chan_map(ieee); |
| 514 | |
| 515 | ieee->be_scan_inprogress = true; |
| 516 | |
Binoy Jayan | be10cee | 2016-06-01 14:56:55 +0530 | [diff] [blame] | 517 | mutex_lock(&ieee->scan_mutex); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 518 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 519 | while (1) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 520 | do { |
| 521 | ch++; |
| 522 | if (ch > MAX_CHANNEL_NUMBER) |
| 523 | goto out; /* scan completed */ |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 524 | } while (!ieee->active_channel_map[ch]); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 525 | |
Masanari Iida | 430fb25 | 2014-04-25 01:48:41 +0900 | [diff] [blame] | 526 | /* this function can be called in two situations |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 527 | * 1- We have switched to ad-hoc mode and we are |
| 528 | * performing a complete syncro scan before conclude |
| 529 | * there are no interesting cell and to create a |
| 530 | * new one. In this case the link state is |
| 531 | * RTLLIB_NOLINK until we found an interesting cell. |
| 532 | * If so the ieee8021_new_net, called by the RX path |
| 533 | * will set the state to RTLLIB_LINKED, so we stop |
| 534 | * scanning |
| 535 | * 2- We are linked and the root uses run iwlist scan. |
| 536 | * So we switch to RTLLIB_LINKED_SCANNING to remember |
| 537 | * that we are still logically linked (not interested in |
| 538 | * new network events, despite for updating the net list, |
| 539 | * but we are temporarly 'unlinked' as the driver shall |
| 540 | * not filter RX frames and the channel is changing. |
Justin P. Mattock | cd01712 | 2012-04-23 07:36:52 -0700 | [diff] [blame] | 541 | * So the only situation in which are interested is to check |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 542 | * if the state become LINKED because of the #1 situation |
| 543 | */ |
| 544 | |
| 545 | if (ieee->state == RTLLIB_LINKED) |
| 546 | goto out; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 547 | if (ieee->sync_scan_hurryup) { |
Mateusz Kulikowski | d69d205 | 2015-03-17 00:00:52 +0100 | [diff] [blame] | 548 | netdev_info(ieee->dev, |
| 549 | "============>sync_scan_hurryup out\n"); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 550 | goto out; |
| 551 | } |
| 552 | |
| 553 | ieee->set_chan(ieee->dev, ch); |
| 554 | if (ieee->active_channel_map[ch] == 1) |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 555 | rtllib_send_probe_requests(ieee, 0); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 556 | |
| 557 | /* this prevent excessive time wait when we |
| 558 | * need to wait for a syncro scan to end.. |
| 559 | */ |
| 560 | msleep_interruptible_rsl(RTLLIB_SOFTMAC_SCAN_TIME); |
| 561 | } |
| 562 | out: |
| 563 | ieee->actscanning = false; |
| 564 | ieee->sync_scan_hurryup = 0; |
| 565 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 566 | if (ieee->state >= RTLLIB_LINKED) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 567 | if (IS_DOT11D_ENABLE(ieee)) |
| 568 | DOT11D_ScanComplete(ieee); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 569 | } |
Binoy Jayan | be10cee | 2016-06-01 14:56:55 +0530 | [diff] [blame] | 570 | mutex_unlock(&ieee->scan_mutex); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 571 | |
| 572 | ieee->be_scan_inprogress = false; |
| 573 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 574 | memset(&wrqu, 0, sizeof(wrqu)); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 575 | wireless_send_event(ieee->dev, SIOCGIWSCAN, &wrqu, NULL); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 576 | } |
| 577 | |
Larry Finger | ec0dc6be | 2011-08-25 14:07:04 -0500 | [diff] [blame] | 578 | static void rtllib_softmac_scan_wq(void *data) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 579 | { |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 580 | struct rtllib_device *ieee = container_of_dwork_rsl(data, |
| 581 | struct rtllib_device, softmac_scan_wq); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 582 | u8 last_channel = ieee->current_network.channel; |
| 583 | |
| 584 | rtllib_update_active_chan_map(ieee); |
| 585 | |
| 586 | if (!ieee->ieee_up) |
| 587 | return; |
Valentina Manea | 4bb0142 | 2013-10-25 11:28:10 +0300 | [diff] [blame] | 588 | if (rtllib_act_scanning(ieee, true)) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 589 | return; |
| 590 | |
Binoy Jayan | be10cee | 2016-06-01 14:56:55 +0530 | [diff] [blame] | 591 | mutex_lock(&ieee->scan_mutex); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 592 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 593 | if (ieee->eRFPowerState == eRfOff) { |
Mateusz Kulikowski | d69d205 | 2015-03-17 00:00:52 +0100 | [diff] [blame] | 594 | netdev_info(ieee->dev, |
| 595 | "======>%s():rf state is eRfOff, return\n", |
| 596 | __func__); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 597 | goto out1; |
| 598 | } |
| 599 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 600 | do { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 601 | ieee->current_network.channel = |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 602 | (ieee->current_network.channel + 1) % |
| 603 | MAX_CHANNEL_NUMBER; |
| 604 | if (ieee->scan_watch_dog++ > MAX_CHANNEL_NUMBER) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 605 | if (!ieee->active_channel_map[ieee->current_network.channel]) |
| 606 | ieee->current_network.channel = 6; |
| 607 | goto out; /* no good chans */ |
| 608 | } |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 609 | } while (!ieee->active_channel_map[ieee->current_network.channel]); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 610 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 611 | if (ieee->scanning_continue == 0) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 612 | goto out; |
| 613 | |
| 614 | ieee->set_chan(ieee->dev, ieee->current_network.channel); |
| 615 | |
| 616 | if (ieee->active_channel_map[ieee->current_network.channel] == 1) |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 617 | rtllib_send_probe_requests(ieee, 0); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 618 | |
Amitoj Kaur Chawla | 354605f | 2016-02-20 15:36:26 +0530 | [diff] [blame] | 619 | schedule_delayed_work(&ieee->softmac_scan_wq, |
| 620 | msecs_to_jiffies(RTLLIB_SOFTMAC_SCAN_TIME)); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 621 | |
Binoy Jayan | be10cee | 2016-06-01 14:56:55 +0530 | [diff] [blame] | 622 | mutex_unlock(&ieee->scan_mutex); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 623 | return; |
| 624 | |
| 625 | out: |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 626 | if (IS_DOT11D_ENABLE(ieee)) |
| 627 | DOT11D_ScanComplete(ieee); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 628 | ieee->current_network.channel = last_channel; |
| 629 | |
| 630 | out1: |
| 631 | ieee->actscanning = false; |
| 632 | ieee->scan_watch_dog = 0; |
| 633 | ieee->scanning_continue = 0; |
Binoy Jayan | be10cee | 2016-06-01 14:56:55 +0530 | [diff] [blame] | 634 | mutex_unlock(&ieee->scan_mutex); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | |
| 638 | |
Larry Finger | ec0dc6be | 2011-08-25 14:07:04 -0500 | [diff] [blame] | 639 | static void rtllib_beacons_start(struct rtllib_device *ieee) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 640 | { |
| 641 | unsigned long flags; |
Matthew Casey | 3a6b70c | 2014-08-22 06:27:52 -0400 | [diff] [blame] | 642 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 643 | spin_lock_irqsave(&ieee->beacon_lock, flags); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 644 | |
| 645 | ieee->beacon_txing = 1; |
| 646 | rtllib_send_beacon(ieee); |
| 647 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 648 | spin_unlock_irqrestore(&ieee->beacon_lock, flags); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 649 | } |
| 650 | |
Larry Finger | ec0dc6be | 2011-08-25 14:07:04 -0500 | [diff] [blame] | 651 | static void rtllib_beacons_stop(struct rtllib_device *ieee) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 652 | { |
| 653 | unsigned long flags; |
| 654 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 655 | spin_lock_irqsave(&ieee->beacon_lock, flags); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 656 | |
| 657 | ieee->beacon_txing = 0; |
| 658 | del_timer_sync(&ieee->beacon_timer); |
| 659 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 660 | spin_unlock_irqrestore(&ieee->beacon_lock, flags); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 661 | |
| 662 | } |
| 663 | |
| 664 | |
| 665 | void rtllib_stop_send_beacons(struct rtllib_device *ieee) |
| 666 | { |
| 667 | if (ieee->stop_send_beacons) |
| 668 | ieee->stop_send_beacons(ieee->dev); |
| 669 | if (ieee->softmac_features & IEEE_SOFTMAC_BEACONS) |
| 670 | rtllib_beacons_stop(ieee); |
| 671 | } |
Sean MacLennan | 3b28499 | 2011-11-28 20:20:26 -0500 | [diff] [blame] | 672 | EXPORT_SYMBOL(rtllib_stop_send_beacons); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 673 | |
| 674 | |
| 675 | void rtllib_start_send_beacons(struct rtllib_device *ieee) |
| 676 | { |
| 677 | if (ieee->start_send_beacons) |
| 678 | ieee->start_send_beacons(ieee->dev); |
| 679 | if (ieee->softmac_features & IEEE_SOFTMAC_BEACONS) |
| 680 | rtllib_beacons_start(ieee); |
| 681 | } |
Sean MacLennan | 3b28499 | 2011-11-28 20:20:26 -0500 | [diff] [blame] | 682 | EXPORT_SYMBOL(rtllib_start_send_beacons); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 683 | |
| 684 | |
Larry Finger | ec0dc6be | 2011-08-25 14:07:04 -0500 | [diff] [blame] | 685 | static void rtllib_softmac_stop_scan(struct rtllib_device *ieee) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 686 | { |
Binoy Jayan | be10cee | 2016-06-01 14:56:55 +0530 | [diff] [blame] | 687 | mutex_lock(&ieee->scan_mutex); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 688 | ieee->scan_watch_dog = 0; |
Mike McCormack | cb76215 | 2011-07-11 08:56:20 +0900 | [diff] [blame] | 689 | if (ieee->scanning_continue == 1) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 690 | ieee->scanning_continue = 0; |
Valentina Manea | 014e4c2 | 2013-10-29 20:58:48 +0200 | [diff] [blame] | 691 | ieee->actscanning = false; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 692 | |
Amitoj Kaur Chawla | 354605f | 2016-02-20 15:36:26 +0530 | [diff] [blame] | 693 | cancel_delayed_work_sync(&ieee->softmac_scan_wq); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 694 | } |
| 695 | |
Binoy Jayan | be10cee | 2016-06-01 14:56:55 +0530 | [diff] [blame] | 696 | mutex_unlock(&ieee->scan_mutex); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | void rtllib_stop_scan(struct rtllib_device *ieee) |
| 700 | { |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 701 | if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 702 | rtllib_softmac_stop_scan(ieee); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 703 | } else { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 704 | if (ieee->rtllib_stop_hw_scan) |
| 705 | ieee->rtllib_stop_hw_scan(ieee->dev); |
| 706 | } |
| 707 | } |
Sean MacLennan | 3b28499 | 2011-11-28 20:20:26 -0500 | [diff] [blame] | 708 | EXPORT_SYMBOL(rtllib_stop_scan); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 709 | |
| 710 | void rtllib_stop_scan_syncro(struct rtllib_device *ieee) |
| 711 | { |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 712 | if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) { |
Mateusz Kulikowski | fc00af0 | 2015-09-20 21:04:26 +0200 | [diff] [blame] | 713 | ieee->sync_scan_hurryup = 1; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 714 | } else { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 715 | if (ieee->rtllib_stop_hw_scan) |
| 716 | ieee->rtllib_stop_hw_scan(ieee->dev); |
| 717 | } |
| 718 | } |
Sean MacLennan | 3b28499 | 2011-11-28 20:20:26 -0500 | [diff] [blame] | 719 | EXPORT_SYMBOL(rtllib_stop_scan_syncro); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 720 | |
| 721 | bool rtllib_act_scanning(struct rtllib_device *ieee, bool sync_scan) |
| 722 | { |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 723 | if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) { |
| 724 | if (sync_scan) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 725 | return ieee->be_scan_inprogress; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 726 | else |
| 727 | return ieee->actscanning || ieee->be_scan_inprogress; |
| 728 | } else { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 729 | return test_bit(STATUS_SCANNING, &ieee->status); |
| 730 | } |
| 731 | } |
Sean MacLennan | 3b28499 | 2011-11-28 20:20:26 -0500 | [diff] [blame] | 732 | EXPORT_SYMBOL(rtllib_act_scanning); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 733 | |
| 734 | /* called with ieee->lock held */ |
Larry Finger | ec0dc6be | 2011-08-25 14:07:04 -0500 | [diff] [blame] | 735 | static void rtllib_start_scan(struct rtllib_device *ieee) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 736 | { |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 737 | RT_TRACE(COMP_DBG, "===>%s()\n", __func__); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 738 | if (ieee->rtllib_ips_leave_wq != NULL) |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 739 | ieee->rtllib_ips_leave_wq(ieee->dev); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 740 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 741 | if (IS_DOT11D_ENABLE(ieee)) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 742 | if (IS_COUNTRY_IE_VALID(ieee)) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 743 | RESET_CIE_WATCHDOG(ieee); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 744 | } |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 745 | if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) { |
| 746 | if (ieee->scanning_continue == 0) { |
| 747 | ieee->actscanning = true; |
| 748 | ieee->scanning_continue = 1; |
Amitoj Kaur Chawla | 354605f | 2016-02-20 15:36:26 +0530 | [diff] [blame] | 749 | schedule_delayed_work(&ieee->softmac_scan_wq, 0); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 750 | } |
| 751 | } else { |
| 752 | if (ieee->rtllib_start_hw_scan) |
| 753 | ieee->rtllib_start_hw_scan(ieee->dev); |
| 754 | } |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 755 | } |
| 756 | |
Binoy Jayan | 9afa937 | 2016-06-01 14:56:52 +0530 | [diff] [blame] | 757 | /* called with wx_mutex held */ |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 758 | void rtllib_start_scan_syncro(struct rtllib_device *ieee, u8 is_mesh) |
| 759 | { |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 760 | if (IS_DOT11D_ENABLE(ieee)) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 761 | if (IS_COUNTRY_IE_VALID(ieee)) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 762 | RESET_CIE_WATCHDOG(ieee); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 763 | } |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 764 | ieee->sync_scan_hurryup = 0; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 765 | if (ieee->softmac_features & IEEE_SOFTMAC_SCAN) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 766 | rtllib_softmac_scan_syncro(ieee, is_mesh); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 767 | } else { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 768 | if (ieee->rtllib_start_hw_scan) |
| 769 | ieee->rtllib_start_hw_scan(ieee->dev); |
| 770 | } |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 771 | } |
Sean MacLennan | 3b28499 | 2011-11-28 20:20:26 -0500 | [diff] [blame] | 772 | EXPORT_SYMBOL(rtllib_start_scan_syncro); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 773 | |
Baoyou Xie | ec65ef8 | 2016-09-04 14:33:35 +0800 | [diff] [blame] | 774 | static inline struct sk_buff * |
| 775 | rtllib_authentication_req(struct rtllib_network *beacon, |
| 776 | struct rtllib_device *ieee, |
| 777 | int challengelen, u8 *daddr) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 778 | { |
| 779 | struct sk_buff *skb; |
| 780 | struct rtllib_authentication *auth; |
Bhaktipriya Shridhar | 7949be6 | 2016-02-19 03:13:56 +0530 | [diff] [blame] | 781 | int len; |
Matthew Casey | 3a6b70c | 2014-08-22 06:27:52 -0400 | [diff] [blame] | 782 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 783 | len = sizeof(struct rtllib_authentication) + challengelen + |
| 784 | ieee->tx_headroom + 4; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 785 | skb = dev_alloc_skb(len); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 786 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 787 | if (!skb) |
| 788 | return NULL; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 789 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 790 | skb_reserve(skb, ieee->tx_headroom); |
| 791 | |
| 792 | auth = (struct rtllib_authentication *) |
| 793 | skb_put(skb, sizeof(struct rtllib_authentication)); |
| 794 | |
Rashika Kheria | 1830a6d | 2013-11-07 18:58:57 +0530 | [diff] [blame] | 795 | auth->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_AUTH); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 796 | if (challengelen) |
Rashika Kheria | 7fe30a7 | 2013-11-07 18:57:37 +0530 | [diff] [blame] | 797 | auth->header.frame_ctl |= cpu_to_le16(RTLLIB_FCTL_WEP); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 798 | |
Rashika Kheria | 1830a6d | 2013-11-07 18:58:57 +0530 | [diff] [blame] | 799 | auth->header.duration_id = cpu_to_le16(0x013a); |
Mateusz Kulikowski | b57ceb1 | 2015-05-31 20:19:22 +0200 | [diff] [blame] | 800 | ether_addr_copy(auth->header.addr1, beacon->bssid); |
| 801 | ether_addr_copy(auth->header.addr2, ieee->dev->dev_addr); |
| 802 | ether_addr_copy(auth->header.addr3, beacon->bssid); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 803 | if (ieee->auth_mode == 0) |
| 804 | auth->algorithm = WLAN_AUTH_OPEN; |
| 805 | else if (ieee->auth_mode == 1) |
Rashika Kheria | 1830a6d | 2013-11-07 18:58:57 +0530 | [diff] [blame] | 806 | auth->algorithm = cpu_to_le16(WLAN_AUTH_SHARED_KEY); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 807 | else if (ieee->auth_mode == 2) |
| 808 | auth->algorithm = WLAN_AUTH_OPEN; |
| 809 | auth->transaction = cpu_to_le16(ieee->associate_seq); |
| 810 | ieee->associate_seq++; |
| 811 | |
| 812 | auth->status = cpu_to_le16(WLAN_STATUS_SUCCESS); |
| 813 | |
| 814 | return skb; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 815 | } |
| 816 | |
Mateusz Kulikowski | c7ddc28 | 2015-05-31 20:19:20 +0200 | [diff] [blame] | 817 | static struct sk_buff *rtllib_probe_resp(struct rtllib_device *ieee, |
| 818 | const u8 *dest) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 819 | { |
| 820 | u8 *tag; |
| 821 | int beacon_size; |
| 822 | struct rtllib_probe_response *beacon_buf; |
| 823 | struct sk_buff *skb = NULL; |
| 824 | int encrypt; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 825 | int atim_len, erp_len; |
Sean MacLennan | 32c44cb | 2011-12-19 23:20:41 -0500 | [diff] [blame] | 826 | struct lib80211_crypt_data *crypt; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 827 | |
| 828 | char *ssid = ieee->current_network.ssid; |
| 829 | int ssid_len = ieee->current_network.ssid_len; |
| 830 | int rate_len = ieee->current_network.rates_len+2; |
| 831 | int rate_ex_len = ieee->current_network.rates_ex_len; |
| 832 | int wpa_ie_len = ieee->wpa_ie_len; |
| 833 | u8 erpinfo_content = 0; |
| 834 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 835 | u8 *tmp_ht_cap_buf = NULL; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 836 | u8 tmp_ht_cap_len = 0; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 837 | u8 *tmp_ht_info_buf = NULL; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 838 | u8 tmp_ht_info_len = 0; |
Larry Finger | 7796d93 | 2011-07-18 20:22:19 -0500 | [diff] [blame] | 839 | struct rt_hi_throughput *pHTInfo = ieee->pHTInfo; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 840 | u8 *tmp_generic_ie_buf = NULL; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 841 | u8 tmp_generic_ie_len = 0; |
| 842 | |
| 843 | if (rate_ex_len > 0) |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 844 | rate_ex_len += 2; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 845 | |
| 846 | if (ieee->current_network.capability & WLAN_CAPABILITY_IBSS) |
| 847 | atim_len = 4; |
| 848 | else |
| 849 | atim_len = 0; |
| 850 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 851 | if ((ieee->current_network.mode == IEEE_G) || |
| 852 | (ieee->current_network.mode == IEEE_N_24G && |
| 853 | ieee->pHTInfo->bCurSuppCCK)) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 854 | erp_len = 3; |
| 855 | erpinfo_content = 0; |
| 856 | if (ieee->current_network.buseprotection) |
| 857 | erpinfo_content |= ERP_UseProtection; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 858 | } else |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 859 | erp_len = 0; |
| 860 | |
Sean MacLennan | 0ddcf5f | 2011-12-19 23:21:41 -0500 | [diff] [blame] | 861 | crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx]; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 862 | encrypt = ieee->host_encrypt && crypt && crypt->ops && |
Mateusz Kulikowski | 4c29207 | 2015-09-20 21:04:27 +0200 | [diff] [blame] | 863 | ((strcmp(crypt->ops->name, "R-WEP") == 0 || wpa_ie_len)); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 864 | if (ieee->pHTInfo->bCurrentHTSupport) { |
| 865 | tmp_ht_cap_buf = (u8 *) &(ieee->pHTInfo->SelfHTCap); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 866 | tmp_ht_cap_len = sizeof(ieee->pHTInfo->SelfHTCap); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 867 | tmp_ht_info_buf = (u8 *) &(ieee->pHTInfo->SelfHTInfo); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 868 | tmp_ht_info_len = sizeof(ieee->pHTInfo->SelfHTInfo); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 869 | HTConstructCapabilityElement(ieee, tmp_ht_cap_buf, |
| 870 | &tmp_ht_cap_len, encrypt, false); |
| 871 | HTConstructInfoElement(ieee, tmp_ht_info_buf, &tmp_ht_info_len, |
| 872 | encrypt); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 873 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 874 | if (pHTInfo->bRegRT2RTAggregation) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 875 | tmp_generic_ie_buf = ieee->pHTInfo->szRT2RTAggBuffer; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 876 | tmp_generic_ie_len = |
| 877 | sizeof(ieee->pHTInfo->szRT2RTAggBuffer); |
| 878 | HTConstructRT2RTAggElement(ieee, tmp_generic_ie_buf, |
| 879 | &tmp_generic_ie_len); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 880 | } |
| 881 | } |
| 882 | |
| 883 | beacon_size = sizeof(struct rtllib_probe_response)+2+ |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 884 | ssid_len + 3 + rate_len + rate_ex_len + atim_len + erp_len |
| 885 | + wpa_ie_len + ieee->tx_headroom; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 886 | skb = dev_alloc_skb(beacon_size); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 887 | if (!skb) |
| 888 | return NULL; |
| 889 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 890 | skb_reserve(skb, ieee->tx_headroom); |
| 891 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 892 | beacon_buf = (struct rtllib_probe_response *) skb_put(skb, |
| 893 | (beacon_size - ieee->tx_headroom)); |
Mateusz Kulikowski | b57ceb1 | 2015-05-31 20:19:22 +0200 | [diff] [blame] | 894 | ether_addr_copy(beacon_buf->header.addr1, dest); |
| 895 | ether_addr_copy(beacon_buf->header.addr2, ieee->dev->dev_addr); |
| 896 | ether_addr_copy(beacon_buf->header.addr3, ieee->current_network.bssid); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 897 | |
| 898 | beacon_buf->header.duration_id = 0; |
| 899 | beacon_buf->beacon_interval = |
| 900 | cpu_to_le16(ieee->current_network.beacon_interval); |
| 901 | beacon_buf->capability = |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 902 | cpu_to_le16(ieee->current_network.capability & |
| 903 | WLAN_CAPABILITY_IBSS); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 904 | beacon_buf->capability |= |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 905 | cpu_to_le16(ieee->current_network.capability & |
| 906 | WLAN_CAPABILITY_SHORT_PREAMBLE); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 907 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 908 | if (ieee->short_slot && (ieee->current_network.capability & |
| 909 | WLAN_CAPABILITY_SHORT_SLOT_TIME)) |
Rashika Kheria | 7fe30a7 | 2013-11-07 18:57:37 +0530 | [diff] [blame] | 910 | beacon_buf->capability |= |
| 911 | cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 912 | |
Sean MacLennan | 0ddcf5f | 2011-12-19 23:21:41 -0500 | [diff] [blame] | 913 | crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx]; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 914 | if (encrypt) |
| 915 | beacon_buf->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY); |
| 916 | |
| 917 | |
| 918 | beacon_buf->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_PROBE_RESP); |
| 919 | beacon_buf->info_element[0].id = MFIE_TYPE_SSID; |
| 920 | beacon_buf->info_element[0].len = ssid_len; |
| 921 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 922 | tag = (u8 *) beacon_buf->info_element[0].data; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 923 | |
| 924 | memcpy(tag, ssid, ssid_len); |
| 925 | |
| 926 | tag += ssid_len; |
| 927 | |
| 928 | *(tag++) = MFIE_TYPE_RATES; |
| 929 | *(tag++) = rate_len-2; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 930 | memcpy(tag, ieee->current_network.rates, rate_len-2); |
| 931 | tag += rate_len-2; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 932 | |
| 933 | *(tag++) = MFIE_TYPE_DS_SET; |
| 934 | *(tag++) = 1; |
| 935 | *(tag++) = ieee->current_network.channel; |
| 936 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 937 | if (atim_len) { |
| 938 | u16 val16; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 939 | *(tag++) = MFIE_TYPE_IBSS_SET; |
| 940 | *(tag++) = 2; |
Rashika Kheria | 1830a6d | 2013-11-07 18:58:57 +0530 | [diff] [blame] | 941 | val16 = ieee->current_network.atim_window; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 942 | memcpy((u8 *)tag, (u8 *)&val16, 2); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 943 | tag += 2; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 944 | } |
| 945 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 946 | if (erp_len) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 947 | *(tag++) = MFIE_TYPE_ERP; |
| 948 | *(tag++) = 1; |
| 949 | *(tag++) = erpinfo_content; |
| 950 | } |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 951 | if (rate_ex_len) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 952 | *(tag++) = MFIE_TYPE_RATES_EX; |
| 953 | *(tag++) = rate_ex_len-2; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 954 | memcpy(tag, ieee->current_network.rates_ex, rate_ex_len-2); |
| 955 | tag += rate_ex_len-2; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 956 | } |
| 957 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 958 | if (wpa_ie_len) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 959 | if (ieee->iw_mode == IW_MODE_ADHOC) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 960 | memcpy(&ieee->wpa_ie[14], &ieee->wpa_ie[8], 4); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 961 | memcpy(tag, ieee->wpa_ie, ieee->wpa_ie_len); |
| 962 | tag += ieee->wpa_ie_len; |
| 963 | } |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 964 | return skb; |
| 965 | } |
| 966 | |
Larry Finger | ec0dc6be | 2011-08-25 14:07:04 -0500 | [diff] [blame] | 967 | static struct sk_buff *rtllib_assoc_resp(struct rtllib_device *ieee, u8 *dest) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 968 | { |
| 969 | struct sk_buff *skb; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 970 | u8 *tag; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 971 | |
Sean MacLennan | 32c44cb | 2011-12-19 23:20:41 -0500 | [diff] [blame] | 972 | struct lib80211_crypt_data *crypt; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 973 | struct rtllib_assoc_response_frame *assoc; |
| 974 | short encrypt; |
| 975 | |
| 976 | unsigned int rate_len = rtllib_MFIE_rate_len(ieee); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 977 | int len = sizeof(struct rtllib_assoc_response_frame) + rate_len + |
| 978 | ieee->tx_headroom; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 979 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 980 | skb = dev_alloc_skb(len); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 981 | |
| 982 | if (!skb) |
| 983 | return NULL; |
| 984 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 985 | skb_reserve(skb, ieee->tx_headroom); |
| 986 | |
| 987 | assoc = (struct rtllib_assoc_response_frame *) |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 988 | skb_put(skb, sizeof(struct rtllib_assoc_response_frame)); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 989 | |
| 990 | assoc->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_ASSOC_RESP); |
Mateusz Kulikowski | b57ceb1 | 2015-05-31 20:19:22 +0200 | [diff] [blame] | 991 | ether_addr_copy(assoc->header.addr1, dest); |
| 992 | ether_addr_copy(assoc->header.addr3, ieee->dev->dev_addr); |
| 993 | ether_addr_copy(assoc->header.addr2, ieee->dev->dev_addr); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 994 | assoc->capability = cpu_to_le16(ieee->iw_mode == IW_MODE_MASTER ? |
| 995 | WLAN_CAPABILITY_ESS : WLAN_CAPABILITY_IBSS); |
| 996 | |
| 997 | |
| 998 | if (ieee->short_slot) |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 999 | assoc->capability |= |
| 1000 | cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1001 | |
| 1002 | if (ieee->host_encrypt) |
Sean MacLennan | 0ddcf5f | 2011-12-19 23:21:41 -0500 | [diff] [blame] | 1003 | crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx]; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1004 | else |
| 1005 | crypt = NULL; |
| 1006 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1007 | encrypt = (crypt && crypt->ops); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1008 | |
| 1009 | if (encrypt) |
| 1010 | assoc->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY); |
| 1011 | |
| 1012 | assoc->status = 0; |
| 1013 | assoc->aid = cpu_to_le16(ieee->assoc_id); |
| 1014 | if (ieee->assoc_id == 0x2007) |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1015 | ieee->assoc_id = 0; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1016 | else |
| 1017 | ieee->assoc_id++; |
| 1018 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1019 | tag = (u8 *) skb_put(skb, rate_len); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1020 | rtllib_MFIE_Brate(ieee, &tag); |
| 1021 | rtllib_MFIE_Grate(ieee, &tag); |
| 1022 | |
| 1023 | return skb; |
| 1024 | } |
| 1025 | |
Larry Finger | ec0dc6be | 2011-08-25 14:07:04 -0500 | [diff] [blame] | 1026 | static struct sk_buff *rtllib_auth_resp(struct rtllib_device *ieee, int status, |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1027 | u8 *dest) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1028 | { |
| 1029 | struct sk_buff *skb = NULL; |
| 1030 | struct rtllib_authentication *auth; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1031 | int len = ieee->tx_headroom + sizeof(struct rtllib_authentication) + 1; |
Matthew Casey | 3a6b70c | 2014-08-22 06:27:52 -0400 | [diff] [blame] | 1032 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1033 | skb = dev_alloc_skb(len); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1034 | if (!skb) |
| 1035 | return NULL; |
| 1036 | |
| 1037 | skb->len = sizeof(struct rtllib_authentication); |
| 1038 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1039 | skb_reserve(skb, ieee->tx_headroom); |
| 1040 | |
| 1041 | auth = (struct rtllib_authentication *) |
| 1042 | skb_put(skb, sizeof(struct rtllib_authentication)); |
| 1043 | |
| 1044 | auth->status = cpu_to_le16(status); |
| 1045 | auth->transaction = cpu_to_le16(2); |
| 1046 | auth->algorithm = cpu_to_le16(WLAN_AUTH_OPEN); |
| 1047 | |
Mateusz Kulikowski | b57ceb1 | 2015-05-31 20:19:22 +0200 | [diff] [blame] | 1048 | ether_addr_copy(auth->header.addr3, ieee->dev->dev_addr); |
| 1049 | ether_addr_copy(auth->header.addr2, ieee->dev->dev_addr); |
| 1050 | ether_addr_copy(auth->header.addr1, dest); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1051 | auth->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_AUTH); |
| 1052 | return skb; |
| 1053 | |
| 1054 | |
| 1055 | } |
| 1056 | |
Larry Finger | ec0dc6be | 2011-08-25 14:07:04 -0500 | [diff] [blame] | 1057 | static struct sk_buff *rtllib_null_func(struct rtllib_device *ieee, short pwr) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1058 | { |
| 1059 | struct sk_buff *skb; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1060 | struct rtllib_hdr_3addr *hdr; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1061 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1062 | skb = dev_alloc_skb(sizeof(struct rtllib_hdr_3addr)+ieee->tx_headroom); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1063 | if (!skb) |
| 1064 | return NULL; |
| 1065 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1066 | skb_reserve(skb, ieee->tx_headroom); |
| 1067 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1068 | hdr = (struct rtllib_hdr_3addr *)skb_put(skb, |
| 1069 | sizeof(struct rtllib_hdr_3addr)); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1070 | |
Mateusz Kulikowski | b57ceb1 | 2015-05-31 20:19:22 +0200 | [diff] [blame] | 1071 | ether_addr_copy(hdr->addr1, ieee->current_network.bssid); |
| 1072 | ether_addr_copy(hdr->addr2, ieee->dev->dev_addr); |
| 1073 | ether_addr_copy(hdr->addr3, ieee->current_network.bssid); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1074 | |
| 1075 | hdr->frame_ctl = cpu_to_le16(RTLLIB_FTYPE_DATA | |
| 1076 | RTLLIB_STYPE_NULLFUNC | RTLLIB_FCTL_TODS | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1077 | (pwr ? RTLLIB_FCTL_PM : 0)); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1078 | |
| 1079 | return skb; |
| 1080 | |
| 1081 | |
| 1082 | } |
| 1083 | |
Larry Finger | ec0dc6be | 2011-08-25 14:07:04 -0500 | [diff] [blame] | 1084 | static struct sk_buff *rtllib_pspoll_func(struct rtllib_device *ieee) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1085 | { |
| 1086 | struct sk_buff *skb; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1087 | struct rtllib_pspoll_hdr *hdr; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1088 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1089 | skb = dev_alloc_skb(sizeof(struct rtllib_pspoll_hdr)+ieee->tx_headroom); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1090 | if (!skb) |
| 1091 | return NULL; |
| 1092 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1093 | skb_reserve(skb, ieee->tx_headroom); |
| 1094 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1095 | hdr = (struct rtllib_pspoll_hdr *)skb_put(skb, |
| 1096 | sizeof(struct rtllib_pspoll_hdr)); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1097 | |
Mateusz Kulikowski | b57ceb1 | 2015-05-31 20:19:22 +0200 | [diff] [blame] | 1098 | ether_addr_copy(hdr->bssid, ieee->current_network.bssid); |
| 1099 | ether_addr_copy(hdr->ta, ieee->dev->dev_addr); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1100 | |
| 1101 | hdr->aid = cpu_to_le16(ieee->assoc_id | 0xc000); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1102 | hdr->frame_ctl = cpu_to_le16(RTLLIB_FTYPE_CTL | RTLLIB_STYPE_PSPOLL | |
| 1103 | RTLLIB_FCTL_PM); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1104 | |
| 1105 | return skb; |
| 1106 | |
| 1107 | } |
| 1108 | |
Larry Finger | ec0dc6be | 2011-08-25 14:07:04 -0500 | [diff] [blame] | 1109 | static void rtllib_resp_to_assoc_rq(struct rtllib_device *ieee, u8 *dest) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1110 | { |
| 1111 | struct sk_buff *buf = rtllib_assoc_resp(ieee, dest); |
| 1112 | |
| 1113 | if (buf) |
| 1114 | softmac_mgmt_xmit(buf, ieee); |
| 1115 | } |
| 1116 | |
| 1117 | |
Larry Finger | ec0dc6be | 2011-08-25 14:07:04 -0500 | [diff] [blame] | 1118 | static void rtllib_resp_to_auth(struct rtllib_device *ieee, int s, u8 *dest) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1119 | { |
| 1120 | struct sk_buff *buf = rtllib_auth_resp(ieee, s, dest); |
| 1121 | |
| 1122 | if (buf) |
| 1123 | softmac_mgmt_xmit(buf, ieee); |
| 1124 | } |
| 1125 | |
| 1126 | |
Larry Finger | ec0dc6be | 2011-08-25 14:07:04 -0500 | [diff] [blame] | 1127 | static void rtllib_resp_to_probe(struct rtllib_device *ieee, u8 *dest) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1128 | { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1129 | struct sk_buff *buf = rtllib_probe_resp(ieee, dest); |
Matthew Casey | 3a6b70c | 2014-08-22 06:27:52 -0400 | [diff] [blame] | 1130 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1131 | if (buf) |
| 1132 | softmac_mgmt_xmit(buf, ieee); |
| 1133 | } |
| 1134 | |
| 1135 | |
Baoyou Xie | ec65ef8 | 2016-09-04 14:33:35 +0800 | [diff] [blame] | 1136 | static inline int SecIsInPMKIDList(struct rtllib_device *ieee, u8 *bssid) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1137 | { |
| 1138 | int i = 0; |
| 1139 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1140 | do { |
| 1141 | if ((ieee->PMKIDList[i].bUsed) && |
| 1142 | (memcmp(ieee->PMKIDList[i].Bssid, bssid, ETH_ALEN) == 0)) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1143 | break; |
Mahati Chamarthy | 92db2a2 | 2014-09-22 01:21:48 +0530 | [diff] [blame] | 1144 | i++; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1145 | } while (i < NUM_PMKID_CACHE); |
| 1146 | |
| 1147 | if (i == NUM_PMKID_CACHE) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1148 | i = -1; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1149 | return i; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1150 | } |
| 1151 | |
Baoyou Xie | ec65ef8 | 2016-09-04 14:33:35 +0800 | [diff] [blame] | 1152 | static inline struct sk_buff * |
| 1153 | rtllib_association_req(struct rtllib_network *beacon, |
| 1154 | struct rtllib_device *ieee) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1155 | { |
| 1156 | struct sk_buff *skb; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1157 | struct rtllib_assoc_request_frame *hdr; |
| 1158 | u8 *tag, *ies; |
| 1159 | int i; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1160 | u8 *ht_cap_buf = NULL; |
| 1161 | u8 ht_cap_len = 0; |
| 1162 | u8 *realtek_ie_buf = NULL; |
| 1163 | u8 realtek_ie_len = 0; |
| 1164 | int wpa_ie_len = ieee->wpa_ie_len; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1165 | int wps_ie_len = ieee->wps_ie_len; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1166 | unsigned int ckip_ie_len = 0; |
| 1167 | unsigned int ccxrm_ie_len = 0; |
| 1168 | unsigned int cxvernum_ie_len = 0; |
Sean MacLennan | 32c44cb | 2011-12-19 23:20:41 -0500 | [diff] [blame] | 1169 | struct lib80211_crypt_data *crypt; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1170 | int encrypt; |
| 1171 | int PMKCacheIdx; |
| 1172 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1173 | unsigned int rate_len = (beacon->rates_len ? |
| 1174 | (beacon->rates_len + 2) : 0) + |
| 1175 | (beacon->rates_ex_len ? (beacon->rates_ex_len) + |
| 1176 | 2 : 0); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1177 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1178 | unsigned int wmm_info_len = beacon->qos_data.supported ? 9 : 0; |
| 1179 | unsigned int turbo_info_len = beacon->Turbo_Enable ? 9 : 0; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1180 | |
| 1181 | int len = 0; |
Matthew Casey | 3a6b70c | 2014-08-22 06:27:52 -0400 | [diff] [blame] | 1182 | |
Sean MacLennan | 0ddcf5f | 2011-12-19 23:21:41 -0500 | [diff] [blame] | 1183 | crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx]; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1184 | if (crypt != NULL) |
| 1185 | encrypt = ieee->host_encrypt && crypt && crypt->ops && |
Mateusz Kulikowski | 4c29207 | 2015-09-20 21:04:27 +0200 | [diff] [blame] | 1186 | ((strcmp(crypt->ops->name, "R-WEP") == 0 || |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1187 | wpa_ie_len)); |
| 1188 | else |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1189 | encrypt = 0; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1190 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1191 | if ((ieee->rtllib_ap_sec_type && |
| 1192 | (ieee->rtllib_ap_sec_type(ieee) & SEC_ALG_TKIP)) || |
Valentina Manea | 4bb0142 | 2013-10-25 11:28:10 +0300 | [diff] [blame] | 1193 | ieee->bForcedBgMode) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1194 | ieee->pHTInfo->bEnableHT = 0; |
| 1195 | ieee->mode = WIRELESS_MODE_G; |
| 1196 | } |
| 1197 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1198 | if (ieee->pHTInfo->bCurrentHTSupport && ieee->pHTInfo->bEnableHT) { |
| 1199 | ht_cap_buf = (u8 *)&(ieee->pHTInfo->SelfHTCap); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1200 | ht_cap_len = sizeof(ieee->pHTInfo->SelfHTCap); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1201 | HTConstructCapabilityElement(ieee, ht_cap_buf, &ht_cap_len, |
| 1202 | encrypt, true); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1203 | if (ieee->pHTInfo->bCurrentRT2RTAggregation) { |
| 1204 | realtek_ie_buf = ieee->pHTInfo->szRT2RTAggBuffer; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1205 | realtek_ie_len = |
| 1206 | sizeof(ieee->pHTInfo->szRT2RTAggBuffer); |
| 1207 | HTConstructRT2RTAggElement(ieee, realtek_ie_buf, |
| 1208 | &realtek_ie_len); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1209 | } |
| 1210 | } |
| 1211 | |
| 1212 | if (beacon->bCkipSupported) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1213 | ckip_ie_len = 30+2; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1214 | if (beacon->bCcxRmEnable) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1215 | ccxrm_ie_len = 6+2; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1216 | if (beacon->BssCcxVerNumber >= 2) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1217 | cxvernum_ie_len = 5+2; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1218 | |
| 1219 | PMKCacheIdx = SecIsInPMKIDList(ieee, ieee->current_network.bssid); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1220 | if (PMKCacheIdx >= 0) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1221 | wpa_ie_len += 18; |
Mateusz Kulikowski | d69d205 | 2015-03-17 00:00:52 +0100 | [diff] [blame] | 1222 | netdev_info(ieee->dev, "[PMK cache]: WPA2 IE length: %x\n", |
| 1223 | wpa_ie_len); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1224 | } |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1225 | len = sizeof(struct rtllib_assoc_request_frame) + 2 |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1226 | + beacon->ssid_len |
| 1227 | + rate_len |
| 1228 | + wpa_ie_len |
| 1229 | + wps_ie_len |
| 1230 | + wmm_info_len |
| 1231 | + turbo_info_len |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1232 | + ht_cap_len |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1233 | + realtek_ie_len |
| 1234 | + ckip_ie_len |
| 1235 | + ccxrm_ie_len |
| 1236 | + cxvernum_ie_len |
| 1237 | + ieee->tx_headroom; |
| 1238 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1239 | skb = dev_alloc_skb(len); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1240 | |
| 1241 | if (!skb) |
| 1242 | return NULL; |
| 1243 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1244 | skb_reserve(skb, ieee->tx_headroom); |
| 1245 | |
| 1246 | hdr = (struct rtllib_assoc_request_frame *) |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1247 | skb_put(skb, sizeof(struct rtllib_assoc_request_frame) + 2); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1248 | |
| 1249 | |
Gnanachandran Dhanapal | fa70ae0 | 2015-06-09 14:47:49 +0000 | [diff] [blame] | 1250 | hdr->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_ASSOC_REQ); |
Rashika Kheria | 1830a6d | 2013-11-07 18:58:57 +0530 | [diff] [blame] | 1251 | hdr->header.duration_id = cpu_to_le16(37); |
Mateusz Kulikowski | b57ceb1 | 2015-05-31 20:19:22 +0200 | [diff] [blame] | 1252 | ether_addr_copy(hdr->header.addr1, beacon->bssid); |
| 1253 | ether_addr_copy(hdr->header.addr2, ieee->dev->dev_addr); |
| 1254 | ether_addr_copy(hdr->header.addr3, beacon->bssid); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1255 | |
Mateusz Kulikowski | b57ceb1 | 2015-05-31 20:19:22 +0200 | [diff] [blame] | 1256 | ether_addr_copy(ieee->ap_mac_addr, beacon->bssid); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1257 | |
| 1258 | hdr->capability = cpu_to_le16(WLAN_CAPABILITY_ESS); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1259 | if (beacon->capability & WLAN_CAPABILITY_PRIVACY) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1260 | hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY); |
| 1261 | |
| 1262 | if (beacon->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 1263 | hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_PREAMBLE); |
| 1264 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1265 | if (ieee->short_slot && |
| 1266 | (beacon->capability&WLAN_CAPABILITY_SHORT_SLOT_TIME)) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1267 | hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT_TIME); |
| 1268 | |
| 1269 | |
Rashika Kheria | 1830a6d | 2013-11-07 18:58:57 +0530 | [diff] [blame] | 1270 | hdr->listen_interval = cpu_to_le16(beacon->listen_interval); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1271 | |
| 1272 | hdr->info_element[0].id = MFIE_TYPE_SSID; |
| 1273 | |
| 1274 | hdr->info_element[0].len = beacon->ssid_len; |
| 1275 | tag = skb_put(skb, beacon->ssid_len); |
| 1276 | memcpy(tag, beacon->ssid, beacon->ssid_len); |
| 1277 | |
| 1278 | tag = skb_put(skb, rate_len); |
| 1279 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1280 | if (beacon->rates_len) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1281 | *tag++ = MFIE_TYPE_RATES; |
| 1282 | *tag++ = beacon->rates_len; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1283 | for (i = 0; i < beacon->rates_len; i++) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1284 | *tag++ = beacon->rates[i]; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1285 | } |
| 1286 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1287 | if (beacon->rates_ex_len) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1288 | *tag++ = MFIE_TYPE_RATES_EX; |
| 1289 | *tag++ = beacon->rates_ex_len; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1290 | for (i = 0; i < beacon->rates_ex_len; i++) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1291 | *tag++ = beacon->rates_ex[i]; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1292 | } |
| 1293 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1294 | if (beacon->bCkipSupported) { |
Behan Webster | 16fc54e | 2014-10-29 15:42:23 -0700 | [diff] [blame] | 1295 | static const u8 AironetIeOui[] = {0x00, 0x01, 0x66}; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1296 | u8 CcxAironetBuf[30]; |
Larry Finger | 8310b6c0 | 2011-07-18 21:57:13 -0500 | [diff] [blame] | 1297 | struct octet_string osCcxAironetIE; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1298 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1299 | memset(CcxAironetBuf, 0, 30); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1300 | osCcxAironetIE.Octet = CcxAironetBuf; |
| 1301 | osCcxAironetIE.Length = sizeof(CcxAironetBuf); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1302 | memcpy(osCcxAironetIE.Octet, AironetIeOui, |
| 1303 | sizeof(AironetIeOui)); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1304 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1305 | osCcxAironetIE.Octet[IE_CISCO_FLAG_POSITION] |= |
| 1306 | (SUPPORT_CKIP_PK|SUPPORT_CKIP_MIC); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1307 | tag = skb_put(skb, ckip_ie_len); |
| 1308 | *tag++ = MFIE_TYPE_AIRONET; |
| 1309 | *tag++ = osCcxAironetIE.Length; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1310 | memcpy(tag, osCcxAironetIE.Octet, osCcxAironetIE.Length); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1311 | tag += osCcxAironetIE.Length; |
| 1312 | } |
| 1313 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1314 | if (beacon->bCcxRmEnable) { |
Behan Webster | 16fc54e | 2014-10-29 15:42:23 -0700 | [diff] [blame] | 1315 | static const u8 CcxRmCapBuf[] = {0x00, 0x40, 0x96, 0x01, 0x01, |
| 1316 | 0x00}; |
Larry Finger | 8310b6c0 | 2011-07-18 21:57:13 -0500 | [diff] [blame] | 1317 | struct octet_string osCcxRmCap; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1318 | |
Behan Webster | 16fc54e | 2014-10-29 15:42:23 -0700 | [diff] [blame] | 1319 | osCcxRmCap.Octet = (u8 *) CcxRmCapBuf; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1320 | osCcxRmCap.Length = sizeof(CcxRmCapBuf); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1321 | tag = skb_put(skb, ccxrm_ie_len); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1322 | *tag++ = MFIE_TYPE_GENERIC; |
| 1323 | *tag++ = osCcxRmCap.Length; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1324 | memcpy(tag, osCcxRmCap.Octet, osCcxRmCap.Length); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1325 | tag += osCcxRmCap.Length; |
| 1326 | } |
| 1327 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1328 | if (beacon->BssCcxVerNumber >= 2) { |
| 1329 | u8 CcxVerNumBuf[] = {0x00, 0x40, 0x96, 0x03, 0x00}; |
Larry Finger | 8310b6c0 | 2011-07-18 21:57:13 -0500 | [diff] [blame] | 1330 | struct octet_string osCcxVerNum; |
Matthew Casey | 3a6b70c | 2014-08-22 06:27:52 -0400 | [diff] [blame] | 1331 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1332 | CcxVerNumBuf[4] = beacon->BssCcxVerNumber; |
| 1333 | osCcxVerNum.Octet = CcxVerNumBuf; |
| 1334 | osCcxVerNum.Length = sizeof(CcxVerNumBuf); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1335 | tag = skb_put(skb, cxvernum_ie_len); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1336 | *tag++ = MFIE_TYPE_GENERIC; |
| 1337 | *tag++ = osCcxVerNum.Length; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1338 | memcpy(tag, osCcxVerNum.Octet, osCcxVerNum.Length); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1339 | tag += osCcxVerNum.Length; |
| 1340 | } |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1341 | if (ieee->pHTInfo->bCurrentHTSupport && ieee->pHTInfo->bEnableHT) { |
| 1342 | if (ieee->pHTInfo->ePeerHTSpecVer != HT_SPEC_VER_EWC) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1343 | tag = skb_put(skb, ht_cap_len); |
| 1344 | *tag++ = MFIE_TYPE_HT_CAP; |
| 1345 | *tag++ = ht_cap_len - 2; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1346 | memcpy(tag, ht_cap_buf, ht_cap_len - 2); |
| 1347 | tag += ht_cap_len - 2; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1348 | } |
| 1349 | } |
| 1350 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1351 | if (wpa_ie_len) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1352 | tag = skb_put(skb, ieee->wpa_ie_len); |
| 1353 | memcpy(tag, ieee->wpa_ie, ieee->wpa_ie_len); |
| 1354 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1355 | if (PMKCacheIdx >= 0) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1356 | tag = skb_put(skb, 18); |
| 1357 | *tag = 1; |
| 1358 | *(tag + 1) = 0; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1359 | memcpy((tag + 2), &ieee->PMKIDList[PMKCacheIdx].PMKID, |
| 1360 | 16); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1361 | } |
| 1362 | } |
| 1363 | if (wmm_info_len) { |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1364 | tag = skb_put(skb, wmm_info_len); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1365 | rtllib_WMM_Info(ieee, &tag); |
| 1366 | } |
| 1367 | |
| 1368 | if (wps_ie_len && ieee->wps_ie) { |
| 1369 | tag = skb_put(skb, wps_ie_len); |
| 1370 | memcpy(tag, ieee->wps_ie, wps_ie_len); |
| 1371 | } |
| 1372 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1373 | tag = skb_put(skb, turbo_info_len); |
| 1374 | if (turbo_info_len) |
| 1375 | rtllib_TURBO_Info(ieee, &tag); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1376 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1377 | if (ieee->pHTInfo->bCurrentHTSupport && ieee->pHTInfo->bEnableHT) { |
| 1378 | if (ieee->pHTInfo->ePeerHTSpecVer == HT_SPEC_VER_EWC) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1379 | tag = skb_put(skb, ht_cap_len); |
| 1380 | *tag++ = MFIE_TYPE_GENERIC; |
| 1381 | *tag++ = ht_cap_len - 2; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1382 | memcpy(tag, ht_cap_buf, ht_cap_len - 2); |
| 1383 | tag += ht_cap_len - 2; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1384 | } |
| 1385 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1386 | if (ieee->pHTInfo->bCurrentRT2RTAggregation) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1387 | tag = skb_put(skb, realtek_ie_len); |
| 1388 | *tag++ = MFIE_TYPE_GENERIC; |
| 1389 | *tag++ = realtek_ie_len - 2; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1390 | memcpy(tag, realtek_ie_buf, realtek_ie_len - 2); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1391 | } |
| 1392 | } |
| 1393 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1394 | kfree(ieee->assocreq_ies); |
| 1395 | ieee->assocreq_ies = NULL; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1396 | ies = &(hdr->info_element[0].id); |
| 1397 | ieee->assocreq_ies_len = (skb->data + skb->len) - ies; |
| 1398 | ieee->assocreq_ies = kmalloc(ieee->assocreq_ies_len, GFP_ATOMIC); |
| 1399 | if (ieee->assocreq_ies) |
| 1400 | memcpy(ieee->assocreq_ies, ies, ieee->assocreq_ies_len); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1401 | else { |
Mateusz Kulikowski | d69d205 | 2015-03-17 00:00:52 +0100 | [diff] [blame] | 1402 | netdev_info(ieee->dev, |
| 1403 | "%s()Warning: can't alloc memory for assocreq_ies\n", |
| 1404 | __func__); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1405 | ieee->assocreq_ies_len = 0; |
| 1406 | } |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1407 | return skb; |
| 1408 | } |
| 1409 | |
Mateusz Kulikowski | 6957248 | 2015-07-14 22:04:26 +0200 | [diff] [blame] | 1410 | static void rtllib_associate_abort(struct rtllib_device *ieee) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1411 | { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1412 | unsigned long flags; |
Matthew Casey | 3a6b70c | 2014-08-22 06:27:52 -0400 | [diff] [blame] | 1413 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1414 | spin_lock_irqsave(&ieee->lock, flags); |
| 1415 | |
| 1416 | ieee->associate_seq++; |
| 1417 | |
| 1418 | /* don't scan, and avoid to have the RX path possibily |
| 1419 | * try again to associate. Even do not react to AUTH or |
| 1420 | * ASSOC response. Just wait for the retry wq to be scheduled. |
| 1421 | * Here we will check if there are good nets to associate |
| 1422 | * with, so we retry or just get back to NO_LINK and scanning |
| 1423 | */ |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1424 | if (ieee->state == RTLLIB_ASSOCIATING_AUTHENTICATING) { |
Mateusz Kulikowski | e9fea2e | 2015-05-31 20:19:33 +0200 | [diff] [blame] | 1425 | netdev_dbg(ieee->dev, "Authentication failed\n"); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1426 | ieee->softmac_stats.no_auth_rs++; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1427 | } else { |
Mateusz Kulikowski | e9fea2e | 2015-05-31 20:19:33 +0200 | [diff] [blame] | 1428 | netdev_dbg(ieee->dev, "Association failed\n"); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1429 | ieee->softmac_stats.no_ass_rs++; |
| 1430 | } |
| 1431 | |
| 1432 | ieee->state = RTLLIB_ASSOCIATING_RETRY; |
| 1433 | |
Amitoj Kaur Chawla | 354605f | 2016-02-20 15:36:26 +0530 | [diff] [blame] | 1434 | schedule_delayed_work(&ieee->associate_retry_wq, |
| 1435 | RTLLIB_SOFTMAC_ASSOC_RETRY_TIME); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1436 | |
| 1437 | spin_unlock_irqrestore(&ieee->lock, flags); |
| 1438 | } |
| 1439 | |
Larry Finger | ec0dc6be | 2011-08-25 14:07:04 -0500 | [diff] [blame] | 1440 | static void rtllib_associate_abort_cb(unsigned long dev) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1441 | { |
| 1442 | rtllib_associate_abort((struct rtllib_device *) dev); |
| 1443 | } |
| 1444 | |
Matthias Schoepe | a0711c4 | 2013-12-26 20:23:32 +0100 | [diff] [blame] | 1445 | static void rtllib_associate_step1(struct rtllib_device *ieee, u8 *daddr) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1446 | { |
| 1447 | struct rtllib_network *beacon = &ieee->current_network; |
| 1448 | struct sk_buff *skb; |
| 1449 | |
Mateusz Kulikowski | e9fea2e | 2015-05-31 20:19:33 +0200 | [diff] [blame] | 1450 | netdev_dbg(ieee->dev, "Stopping scan\n"); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1451 | |
| 1452 | ieee->softmac_stats.tx_auth_rq++; |
| 1453 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1454 | skb = rtllib_authentication_req(beacon, ieee, 0, daddr); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1455 | |
| 1456 | if (!skb) |
| 1457 | rtllib_associate_abort(ieee); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1458 | else { |
Mateusz Kulikowski | dc986e3 | 2015-03-17 00:00:49 +0100 | [diff] [blame] | 1459 | ieee->state = RTLLIB_ASSOCIATING_AUTHENTICATING; |
Mateusz Kulikowski | e9fea2e | 2015-05-31 20:19:33 +0200 | [diff] [blame] | 1460 | netdev_dbg(ieee->dev, "Sending authentication request\n"); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1461 | softmac_mgmt_xmit(skb, ieee); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1462 | if (!timer_pending(&ieee->associate_timer)) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1463 | ieee->associate_timer.expires = jiffies + (HZ / 2); |
| 1464 | add_timer(&ieee->associate_timer); |
| 1465 | } |
| 1466 | } |
| 1467 | } |
| 1468 | |
Mateusz Kulikowski | 35e33b0 | 2015-05-31 20:19:40 +0200 | [diff] [blame] | 1469 | static void rtllib_auth_challenge(struct rtllib_device *ieee, u8 *challenge, |
| 1470 | int chlen) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1471 | { |
| 1472 | u8 *c; |
| 1473 | struct sk_buff *skb; |
| 1474 | struct rtllib_network *beacon = &ieee->current_network; |
| 1475 | |
| 1476 | ieee->associate_seq++; |
| 1477 | ieee->softmac_stats.tx_auth_rq++; |
| 1478 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1479 | skb = rtllib_authentication_req(beacon, ieee, chlen + 2, beacon->bssid); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1480 | |
| 1481 | if (!skb) |
| 1482 | rtllib_associate_abort(ieee); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1483 | else { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1484 | c = skb_put(skb, chlen+2); |
| 1485 | *(c++) = MFIE_TYPE_CHALLENGE; |
| 1486 | *(c++) = chlen; |
| 1487 | memcpy(c, challenge, chlen); |
| 1488 | |
Mateusz Kulikowski | e9fea2e | 2015-05-31 20:19:33 +0200 | [diff] [blame] | 1489 | netdev_dbg(ieee->dev, |
| 1490 | "Sending authentication challenge response\n"); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1491 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1492 | rtllib_encrypt_fragment(ieee, skb, |
| 1493 | sizeof(struct rtllib_hdr_3addr)); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1494 | |
| 1495 | softmac_mgmt_xmit(skb, ieee); |
| 1496 | mod_timer(&ieee->associate_timer, jiffies + (HZ/2)); |
| 1497 | } |
| 1498 | kfree(challenge); |
| 1499 | } |
| 1500 | |
Larry Finger | ec0dc6be | 2011-08-25 14:07:04 -0500 | [diff] [blame] | 1501 | static void rtllib_associate_step2(struct rtllib_device *ieee) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1502 | { |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1503 | struct sk_buff *skb; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1504 | struct rtllib_network *beacon = &ieee->current_network; |
| 1505 | |
| 1506 | del_timer_sync(&ieee->associate_timer); |
| 1507 | |
Mateusz Kulikowski | e9fea2e | 2015-05-31 20:19:33 +0200 | [diff] [blame] | 1508 | netdev_dbg(ieee->dev, "Sending association request\n"); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1509 | |
| 1510 | ieee->softmac_stats.tx_ass_rq++; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1511 | skb = rtllib_association_req(beacon, ieee); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1512 | if (!skb) |
| 1513 | rtllib_associate_abort(ieee); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1514 | else { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1515 | softmac_mgmt_xmit(skb, ieee); |
| 1516 | mod_timer(&ieee->associate_timer, jiffies + (HZ/2)); |
| 1517 | } |
| 1518 | } |
| 1519 | |
Larry Finger | ec0dc6be | 2011-08-25 14:07:04 -0500 | [diff] [blame] | 1520 | static void rtllib_associate_complete_wq(void *data) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1521 | { |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1522 | struct rtllib_device *ieee = (struct rtllib_device *) |
| 1523 | container_of_work_rsl(data, |
| 1524 | struct rtllib_device, |
| 1525 | associate_complete_wq); |
Shivani Bhardwaj | bd60ac1 | 2015-10-14 23:46:05 +0530 | [diff] [blame] | 1526 | struct rt_pwr_save_ctrl *pPSC = &(ieee->PowerSaveControl); |
Mateusz Kulikowski | d69d205 | 2015-03-17 00:00:52 +0100 | [diff] [blame] | 1527 | netdev_info(ieee->dev, "Associated successfully\n"); |
Valentina Manea | 4bb0142 | 2013-10-25 11:28:10 +0300 | [diff] [blame] | 1528 | if (!ieee->is_silent_reset) { |
Mateusz Kulikowski | d69d205 | 2015-03-17 00:00:52 +0100 | [diff] [blame] | 1529 | netdev_info(ieee->dev, "normal associate\n"); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1530 | notify_wx_assoc_event(ieee); |
| 1531 | } |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1532 | |
| 1533 | netif_carrier_on(ieee->dev); |
| 1534 | ieee->is_roaming = false; |
| 1535 | if (rtllib_is_54g(&ieee->current_network) && |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1536 | (ieee->modulation & RTLLIB_OFDM_MODULATION)) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1537 | ieee->rate = 108; |
Mateusz Kulikowski | d69d205 | 2015-03-17 00:00:52 +0100 | [diff] [blame] | 1538 | netdev_info(ieee->dev, "Using G rates:%d\n", ieee->rate); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1539 | } else { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1540 | ieee->rate = 22; |
| 1541 | ieee->SetWirelessMode(ieee->dev, IEEE_B); |
Mateusz Kulikowski | d69d205 | 2015-03-17 00:00:52 +0100 | [diff] [blame] | 1542 | netdev_info(ieee->dev, "Using B rates:%d\n", ieee->rate); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1543 | } |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1544 | if (ieee->pHTInfo->bCurrentHTSupport && ieee->pHTInfo->bEnableHT) { |
Mateusz Kulikowski | d69d205 | 2015-03-17 00:00:52 +0100 | [diff] [blame] | 1545 | netdev_info(ieee->dev, "Successfully associated, ht enabled\n"); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1546 | HTOnAssocRsp(ieee); |
| 1547 | } else { |
Mateusz Kulikowski | d69d205 | 2015-03-17 00:00:52 +0100 | [diff] [blame] | 1548 | netdev_info(ieee->dev, |
| 1549 | "Successfully associated, ht not enabled(%d, %d)\n", |
| 1550 | ieee->pHTInfo->bCurrentHTSupport, |
| 1551 | ieee->pHTInfo->bEnableHT); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1552 | memset(ieee->dot11HTOperationalRateSet, 0, 16); |
| 1553 | } |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1554 | ieee->LinkDetectInfo.SlotNum = 2 * (1 + |
| 1555 | ieee->current_network.beacon_interval / |
| 1556 | 500); |
| 1557 | if (ieee->LinkDetectInfo.NumRecvBcnInPeriod == 0 || |
| 1558 | ieee->LinkDetectInfo.NumRecvDataInPeriod == 0) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1559 | ieee->LinkDetectInfo.NumRecvBcnInPeriod = 1; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1560 | ieee->LinkDetectInfo.NumRecvDataInPeriod = 1; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1561 | } |
| 1562 | pPSC->LpsIdleCount = 0; |
| 1563 | ieee->link_change(ieee->dev); |
| 1564 | |
Valentina Manea | 4bb0142 | 2013-10-25 11:28:10 +0300 | [diff] [blame] | 1565 | if (ieee->is_silent_reset) { |
Mateusz Kulikowski | d69d205 | 2015-03-17 00:00:52 +0100 | [diff] [blame] | 1566 | netdev_info(ieee->dev, "silent reset associate\n"); |
Valentina Manea | 014e4c2 | 2013-10-29 20:58:48 +0200 | [diff] [blame] | 1567 | ieee->is_silent_reset = false; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1568 | } |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1569 | |
| 1570 | if (ieee->data_hard_resume) |
| 1571 | ieee->data_hard_resume(ieee->dev); |
| 1572 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1573 | } |
| 1574 | |
| 1575 | static void rtllib_sta_send_associnfo(struct rtllib_device *ieee) |
| 1576 | { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1577 | } |
| 1578 | |
Larry Finger | ec0dc6be | 2011-08-25 14:07:04 -0500 | [diff] [blame] | 1579 | static void rtllib_associate_complete(struct rtllib_device *ieee) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1580 | { |
| 1581 | del_timer_sync(&ieee->associate_timer); |
| 1582 | |
| 1583 | ieee->state = RTLLIB_LINKED; |
| 1584 | rtllib_sta_send_associnfo(ieee); |
| 1585 | |
Amitoj Kaur Chawla | 354605f | 2016-02-20 15:36:26 +0530 | [diff] [blame] | 1586 | schedule_work(&ieee->associate_complete_wq); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1587 | } |
| 1588 | |
Larry Finger | ec0dc6be | 2011-08-25 14:07:04 -0500 | [diff] [blame] | 1589 | static void rtllib_associate_procedure_wq(void *data) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1590 | { |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1591 | struct rtllib_device *ieee = container_of_dwork_rsl(data, |
| 1592 | struct rtllib_device, |
| 1593 | associate_procedure_wq); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1594 | rtllib_stop_scan_syncro(ieee); |
| 1595 | if (ieee->rtllib_ips_leave != NULL) |
| 1596 | ieee->rtllib_ips_leave(ieee->dev); |
Binoy Jayan | 9afa937 | 2016-06-01 14:56:52 +0530 | [diff] [blame] | 1597 | mutex_lock(&ieee->wx_mutex); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1598 | |
| 1599 | if (ieee->data_hard_stop) |
| 1600 | ieee->data_hard_stop(ieee->dev); |
| 1601 | |
| 1602 | rtllib_stop_scan(ieee); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1603 | RT_TRACE(COMP_DBG, "===>%s(), chan:%d\n", __func__, |
| 1604 | ieee->current_network.channel); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1605 | HTSetConnectBwMode(ieee, HT_CHANNEL_WIDTH_20, HT_EXTCHNL_OFFSET_NO_EXT); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1606 | if (ieee->eRFPowerState == eRfOff) { |
Mateusz Kulikowski | 0822339 | 2015-03-17 00:00:48 +0100 | [diff] [blame] | 1607 | RT_TRACE(COMP_DBG, |
| 1608 | "=============>%s():Rf state is eRfOff, schedule ipsleave wq again,return\n", |
| 1609 | __func__); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1610 | if (ieee->rtllib_ips_leave_wq != NULL) |
| 1611 | ieee->rtllib_ips_leave_wq(ieee->dev); |
Binoy Jayan | 9afa937 | 2016-06-01 14:56:52 +0530 | [diff] [blame] | 1612 | mutex_unlock(&ieee->wx_mutex); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1613 | return; |
| 1614 | } |
| 1615 | ieee->associate_seq = 1; |
| 1616 | |
| 1617 | rtllib_associate_step1(ieee, ieee->current_network.bssid); |
| 1618 | |
Binoy Jayan | 9afa937 | 2016-06-01 14:56:52 +0530 | [diff] [blame] | 1619 | mutex_unlock(&ieee->wx_mutex); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1620 | } |
| 1621 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1622 | inline void rtllib_softmac_new_net(struct rtllib_device *ieee, |
| 1623 | struct rtllib_network *net) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1624 | { |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1625 | u8 tmp_ssid[IW_ESSID_MAX_SIZE + 1]; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1626 | int tmp_ssid_len = 0; |
| 1627 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1628 | short apset, ssidset, ssidbroad, apmatch, ssidmatch; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1629 | |
| 1630 | /* we are interested in new new only if we are not associated |
| 1631 | * and we are not associating / authenticating |
| 1632 | */ |
| 1633 | if (ieee->state != RTLLIB_NOLINK) |
| 1634 | return; |
| 1635 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1636 | if ((ieee->iw_mode == IW_MODE_INFRA) && !(net->capability & |
| 1637 | WLAN_CAPABILITY_ESS)) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1638 | return; |
| 1639 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1640 | if ((ieee->iw_mode == IW_MODE_ADHOC) && !(net->capability & |
| 1641 | WLAN_CAPABILITY_IBSS)) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1642 | return; |
| 1643 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1644 | if ((ieee->iw_mode == IW_MODE_ADHOC) && |
| 1645 | (net->channel > ieee->ibss_maxjoin_chal)) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1646 | return; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1647 | if (ieee->iw_mode == IW_MODE_INFRA || ieee->iw_mode == IW_MODE_ADHOC) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1648 | /* if the user specified the AP MAC, we need also the essid |
| 1649 | * This could be obtained by beacons or, if the network does not |
| 1650 | * broadcast it, it can be put manually. |
| 1651 | */ |
| 1652 | apset = ieee->wap_set; |
| 1653 | ssidset = ieee->ssid_set; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1654 | ssidbroad = !(net->ssid_len == 0 || net->ssid[0] == '\0'); |
| 1655 | apmatch = (memcmp(ieee->current_network.bssid, net->bssid, |
| 1656 | ETH_ALEN) == 0); |
| 1657 | if (!ssidbroad) { |
| 1658 | ssidmatch = (ieee->current_network.ssid_len == |
| 1659 | net->hidden_ssid_len) && |
| 1660 | (!strncmp(ieee->current_network.ssid, |
| 1661 | net->hidden_ssid, net->hidden_ssid_len)); |
| 1662 | if (net->hidden_ssid_len > 0) { |
| 1663 | strncpy(net->ssid, net->hidden_ssid, |
| 1664 | net->hidden_ssid_len); |
| 1665 | net->ssid_len = net->hidden_ssid_len; |
| 1666 | ssidbroad = 1; |
| 1667 | } |
| 1668 | } else |
| 1669 | ssidmatch = |
| 1670 | (ieee->current_network.ssid_len == net->ssid_len) && |
| 1671 | (!strncmp(ieee->current_network.ssid, net->ssid, |
| 1672 | net->ssid_len)); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1673 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1674 | /* if the user set the AP check if match. |
| 1675 | * if the network does not broadcast essid we check the |
Justin P. Mattock | cd01712 | 2012-04-23 07:36:52 -0700 | [diff] [blame] | 1676 | * user supplied ANY essid |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1677 | * if the network does broadcast and the user does not set |
| 1678 | * essid it is OK |
| 1679 | * if the network does broadcast and the user did set essid |
| 1680 | * check if essid match |
| 1681 | * if the ap is not set, check that the user set the bssid |
Masanari Iida | db2c8da | 2012-08-10 01:37:31 +0900 | [diff] [blame] | 1682 | * and the network does broadcast and that those two bssid match |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1683 | */ |
| 1684 | if ((apset && apmatch && |
| 1685 | ((ssidset && ssidbroad && ssidmatch) || |
| 1686 | (ssidbroad && !ssidset) || (!ssidbroad && ssidset))) || |
| 1687 | (!apset && ssidset && ssidbroad && ssidmatch) || |
| 1688 | (ieee->is_roaming && ssidset && ssidbroad && ssidmatch)) { |
| 1689 | /* if the essid is hidden replace it with the |
Mateusz Kulikowski | 14b40d9 | 2015-04-01 00:24:37 +0200 | [diff] [blame] | 1690 | * essid provided by the user. |
| 1691 | */ |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1692 | if (!ssidbroad) { |
| 1693 | strncpy(tmp_ssid, ieee->current_network.ssid, |
| 1694 | IW_ESSID_MAX_SIZE); |
| 1695 | tmp_ssid_len = ieee->current_network.ssid_len; |
| 1696 | } |
| 1697 | memcpy(&ieee->current_network, net, |
| 1698 | sizeof(struct rtllib_network)); |
| 1699 | if (!ssidbroad) { |
| 1700 | strncpy(ieee->current_network.ssid, tmp_ssid, |
| 1701 | IW_ESSID_MAX_SIZE); |
| 1702 | ieee->current_network.ssid_len = tmp_ssid_len; |
| 1703 | } |
Mateusz Kulikowski | d69d205 | 2015-03-17 00:00:52 +0100 | [diff] [blame] | 1704 | netdev_info(ieee->dev, |
| 1705 | "Linking with %s,channel:%d, qos:%d, myHT:%d, networkHT:%d, mode:%x cur_net.flags:0x%x\n", |
| 1706 | ieee->current_network.ssid, |
| 1707 | ieee->current_network.channel, |
| 1708 | ieee->current_network.qos_data.supported, |
| 1709 | ieee->pHTInfo->bEnableHT, |
| 1710 | ieee->current_network.bssht.bdSupportHT, |
| 1711 | ieee->current_network.mode, |
| 1712 | ieee->current_network.flags); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1713 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1714 | if ((rtllib_act_scanning(ieee, false)) && |
| 1715 | !(ieee->softmac_features & IEEE_SOFTMAC_SCAN)) |
| 1716 | rtllib_stop_scan_syncro(ieee); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1717 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1718 | HTResetIOTSetting(ieee->pHTInfo); |
| 1719 | ieee->wmm_acm = 0; |
| 1720 | if (ieee->iw_mode == IW_MODE_INFRA) { |
| 1721 | /* Join the network for the first time */ |
| 1722 | ieee->AsocRetryCount = 0; |
| 1723 | if ((ieee->current_network.qos_data.supported == 1) && |
Mateusz Kulikowski | 35e33b0 | 2015-05-31 20:19:40 +0200 | [diff] [blame] | 1724 | ieee->current_network.bssht.bdSupportHT) |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1725 | HTResetSelfAndSavePeerSetting(ieee, |
| 1726 | &(ieee->current_network)); |
| 1727 | else |
| 1728 | ieee->pHTInfo->bCurrentHTSupport = |
| 1729 | false; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1730 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1731 | ieee->state = RTLLIB_ASSOCIATING; |
| 1732 | if (ieee->LedControlHandler != NULL) |
| 1733 | ieee->LedControlHandler(ieee->dev, |
| 1734 | LED_CTL_START_TO_LINK); |
Amitoj Kaur Chawla | 354605f | 2016-02-20 15:36:26 +0530 | [diff] [blame] | 1735 | schedule_delayed_work( |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1736 | &ieee->associate_procedure_wq, 0); |
| 1737 | } else { |
| 1738 | if (rtllib_is_54g(&ieee->current_network) && |
Mateusz Kulikowski | 35e33b0 | 2015-05-31 20:19:40 +0200 | [diff] [blame] | 1739 | (ieee->modulation & |
| 1740 | RTLLIB_OFDM_MODULATION)) { |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1741 | ieee->rate = 108; |
Mateusz Kulikowski | 35e33b0 | 2015-05-31 20:19:40 +0200 | [diff] [blame] | 1742 | ieee->SetWirelessMode(ieee->dev, |
| 1743 | IEEE_G); |
| 1744 | netdev_info(ieee->dev, |
| 1745 | "Using G rates\n"); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1746 | } else { |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1747 | ieee->rate = 22; |
Mateusz Kulikowski | 35e33b0 | 2015-05-31 20:19:40 +0200 | [diff] [blame] | 1748 | ieee->SetWirelessMode(ieee->dev, |
| 1749 | IEEE_B); |
| 1750 | netdev_info(ieee->dev, |
| 1751 | "Using B rates\n"); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1752 | } |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1753 | memset(ieee->dot11HTOperationalRateSet, 0, 16); |
| 1754 | ieee->state = RTLLIB_LINKED; |
| 1755 | } |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1756 | } |
| 1757 | } |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1758 | } |
| 1759 | |
Mateusz Kulikowski | 6957248 | 2015-07-14 22:04:26 +0200 | [diff] [blame] | 1760 | static void rtllib_softmac_check_all_nets(struct rtllib_device *ieee) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1761 | { |
| 1762 | unsigned long flags; |
| 1763 | struct rtllib_network *target; |
| 1764 | |
| 1765 | spin_lock_irqsave(&ieee->lock, flags); |
| 1766 | |
| 1767 | list_for_each_entry(target, &ieee->network_list, list) { |
| 1768 | |
| 1769 | /* if the state become different that NOLINK means |
| 1770 | * we had found what we are searching for |
| 1771 | */ |
| 1772 | |
| 1773 | if (ieee->state != RTLLIB_NOLINK) |
| 1774 | break; |
| 1775 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1776 | if (ieee->scan_age == 0 || time_after(target->last_scanned + |
| 1777 | ieee->scan_age, jiffies)) |
| 1778 | rtllib_softmac_new_net(ieee, target); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1779 | } |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1780 | spin_unlock_irqrestore(&ieee->lock, flags); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1781 | } |
| 1782 | |
Mateusz Kulikowski | e9fea2e | 2015-05-31 20:19:33 +0200 | [diff] [blame] | 1783 | static inline u16 auth_parse(struct net_device *dev, struct sk_buff *skb, |
| 1784 | u8 **challenge, int *chlen) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1785 | { |
| 1786 | struct rtllib_authentication *a; |
| 1787 | u8 *t; |
Matthew Casey | 3a6b70c | 2014-08-22 06:27:52 -0400 | [diff] [blame] | 1788 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1789 | if (skb->len < (sizeof(struct rtllib_authentication) - |
| 1790 | sizeof(struct rtllib_info_element))) { |
Mateusz Kulikowski | e9fea2e | 2015-05-31 20:19:33 +0200 | [diff] [blame] | 1791 | netdev_dbg(dev, "invalid len in auth resp: %d\n", skb->len); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1792 | return 0xcafe; |
| 1793 | } |
| 1794 | *challenge = NULL; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1795 | a = (struct rtllib_authentication *) skb->data; |
| 1796 | if (skb->len > (sizeof(struct rtllib_authentication) + 3)) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1797 | t = skb->data + sizeof(struct rtllib_authentication); |
| 1798 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1799 | if (*(t++) == MFIE_TYPE_CHALLENGE) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1800 | *chlen = *(t++); |
Hema Prathaban | 6dea0da | 2013-05-14 21:01:22 +0530 | [diff] [blame] | 1801 | *challenge = kmemdup(t, *chlen, GFP_ATOMIC); |
Hema Prathaban | ae05325 | 2013-05-14 20:59:19 +0530 | [diff] [blame] | 1802 | if (!*challenge) |
| 1803 | return -ENOMEM; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1804 | } |
| 1805 | } |
Arno Tiemersma | 640f7d6 | 2015-05-09 22:27:16 +0200 | [diff] [blame] | 1806 | return le16_to_cpu(a->status); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1807 | } |
| 1808 | |
Mateusz Kulikowski | e9fea2e | 2015-05-31 20:19:33 +0200 | [diff] [blame] | 1809 | static int auth_rq_parse(struct net_device *dev, struct sk_buff *skb, u8 *dest) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1810 | { |
| 1811 | struct rtllib_authentication *a; |
| 1812 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1813 | if (skb->len < (sizeof(struct rtllib_authentication) - |
| 1814 | sizeof(struct rtllib_info_element))) { |
Mateusz Kulikowski | e9fea2e | 2015-05-31 20:19:33 +0200 | [diff] [blame] | 1815 | netdev_dbg(dev, "invalid len in auth request: %d\n", skb->len); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1816 | return -1; |
| 1817 | } |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1818 | a = (struct rtllib_authentication *) skb->data; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1819 | |
Mateusz Kulikowski | b57ceb1 | 2015-05-31 20:19:22 +0200 | [diff] [blame] | 1820 | ether_addr_copy(dest, a->header.addr2); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1821 | |
| 1822 | if (le16_to_cpu(a->algorithm) != WLAN_AUTH_OPEN) |
| 1823 | return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG; |
| 1824 | |
| 1825 | return WLAN_STATUS_SUCCESS; |
| 1826 | } |
| 1827 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1828 | static short probe_rq_parse(struct rtllib_device *ieee, struct sk_buff *skb, |
| 1829 | u8 *src) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1830 | { |
| 1831 | u8 *tag; |
| 1832 | u8 *skbend; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1833 | u8 *ssid = NULL; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1834 | u8 ssidlen = 0; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1835 | struct rtllib_hdr_3addr *header = |
| 1836 | (struct rtllib_hdr_3addr *) skb->data; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1837 | bool bssid_match; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1838 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1839 | if (skb->len < sizeof(struct rtllib_hdr_3addr)) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1840 | return -1; /* corrupted */ |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1841 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1842 | bssid_match = |
Mateusz Kulikowski | c2f8b4a | 2015-05-31 20:19:24 +0200 | [diff] [blame] | 1843 | (!ether_addr_equal(header->addr3, ieee->current_network.bssid)) && |
Wei Yongjun | 0c43e56 | 2012-08-26 09:04:23 +0800 | [diff] [blame] | 1844 | (!is_broadcast_ether_addr(header->addr3)); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1845 | if (bssid_match) |
| 1846 | return -1; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1847 | |
Mateusz Kulikowski | b57ceb1 | 2015-05-31 20:19:22 +0200 | [diff] [blame] | 1848 | ether_addr_copy(src, header->addr2); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1849 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1850 | skbend = (u8 *)skb->data + skb->len; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1851 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1852 | tag = skb->data + sizeof(struct rtllib_hdr_3addr); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1853 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1854 | while (tag + 1 < skbend) { |
| 1855 | if (*tag == 0) { |
| 1856 | ssid = tag + 2; |
| 1857 | ssidlen = *(tag + 1); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1858 | break; |
| 1859 | } |
| 1860 | tag++; /* point to the len field */ |
| 1861 | tag = tag + *(tag); /* point to the last data byte of the tag */ |
| 1862 | tag++; /* point to the next tag */ |
| 1863 | } |
| 1864 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1865 | if (ssidlen == 0) |
| 1866 | return 1; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1867 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1868 | if (!ssid) |
| 1869 | return 1; /* ssid not found in tagged param */ |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1870 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1871 | return !strncmp(ssid, ieee->current_network.ssid, ssidlen); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1872 | } |
| 1873 | |
Mateusz Kulikowski | e9fea2e | 2015-05-31 20:19:33 +0200 | [diff] [blame] | 1874 | static int assoc_rq_parse(struct net_device *dev, struct sk_buff *skb, u8 *dest) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1875 | { |
| 1876 | struct rtllib_assoc_request_frame *a; |
| 1877 | |
| 1878 | if (skb->len < (sizeof(struct rtllib_assoc_request_frame) - |
| 1879 | sizeof(struct rtllib_info_element))) { |
Mateusz Kulikowski | e9fea2e | 2015-05-31 20:19:33 +0200 | [diff] [blame] | 1880 | netdev_dbg(dev, "invalid len in auth request:%d\n", skb->len); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1881 | return -1; |
| 1882 | } |
| 1883 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1884 | a = (struct rtllib_assoc_request_frame *) skb->data; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1885 | |
Mateusz Kulikowski | b57ceb1 | 2015-05-31 20:19:22 +0200 | [diff] [blame] | 1886 | ether_addr_copy(dest, a->header.addr2); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1887 | |
| 1888 | return 0; |
| 1889 | } |
| 1890 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1891 | static inline u16 assoc_parse(struct rtllib_device *ieee, struct sk_buff *skb, |
| 1892 | int *aid) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1893 | { |
| 1894 | struct rtllib_assoc_response_frame *response_head; |
| 1895 | u16 status_code; |
| 1896 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1897 | if (skb->len < sizeof(struct rtllib_assoc_response_frame)) { |
Mateusz Kulikowski | e9fea2e | 2015-05-31 20:19:33 +0200 | [diff] [blame] | 1898 | netdev_dbg(ieee->dev, "Invalid len in auth resp: %d\n", |
| 1899 | skb->len); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1900 | return 0xcafe; |
| 1901 | } |
| 1902 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1903 | response_head = (struct rtllib_assoc_response_frame *) skb->data; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1904 | *aid = le16_to_cpu(response_head->aid) & 0x3fff; |
| 1905 | |
| 1906 | status_code = le16_to_cpu(response_head->status); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1907 | if ((status_code == WLAN_STATUS_ASSOC_DENIED_RATES || |
| 1908 | status_code == WLAN_STATUS_CAPS_UNSUPPORTED) && |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1909 | ((ieee->mode == IEEE_G) && |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1910 | (ieee->current_network.mode == IEEE_N_24G) && |
| 1911 | (ieee->AsocRetryCount++ < (RT_ASOC_RETRY_LIMIT-1)))) { |
| 1912 | ieee->pHTInfo->IOTAction |= HT_IOT_ACT_PURE_N_MODE; |
| 1913 | } else { |
| 1914 | ieee->AsocRetryCount = 0; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1915 | } |
| 1916 | |
| 1917 | return le16_to_cpu(response_head->status); |
| 1918 | } |
| 1919 | |
| 1920 | void rtllib_rx_probe_rq(struct rtllib_device *ieee, struct sk_buff *skb) |
| 1921 | { |
| 1922 | u8 dest[ETH_ALEN]; |
Matthew Casey | 3a6b70c | 2014-08-22 06:27:52 -0400 | [diff] [blame] | 1923 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1924 | ieee->softmac_stats.rx_probe_rq++; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1925 | if (probe_rq_parse(ieee, skb, dest) > 0) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1926 | ieee->softmac_stats.tx_probe_rs++; |
| 1927 | rtllib_resp_to_probe(ieee, dest); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1928 | } |
| 1929 | } |
| 1930 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1931 | static inline void rtllib_rx_auth_rq(struct rtllib_device *ieee, |
| 1932 | struct sk_buff *skb) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1933 | { |
| 1934 | u8 dest[ETH_ALEN]; |
| 1935 | int status; |
Matthew Casey | 3a6b70c | 2014-08-22 06:27:52 -0400 | [diff] [blame] | 1936 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1937 | ieee->softmac_stats.rx_auth_rq++; |
| 1938 | |
Mateusz Kulikowski | e9fea2e | 2015-05-31 20:19:33 +0200 | [diff] [blame] | 1939 | status = auth_rq_parse(ieee->dev, skb, dest); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1940 | if (status != -1) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1941 | rtllib_resp_to_auth(ieee, status, dest); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1942 | } |
| 1943 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1944 | static inline void rtllib_rx_assoc_rq(struct rtllib_device *ieee, |
| 1945 | struct sk_buff *skb) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1946 | { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1947 | u8 dest[ETH_ALEN]; |
| 1948 | |
Mateusz Kulikowski | 06c1110 | 2015-05-31 20:19:21 +0200 | [diff] [blame] | 1949 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1950 | ieee->softmac_stats.rx_ass_rq++; |
Mateusz Kulikowski | e9fea2e | 2015-05-31 20:19:33 +0200 | [diff] [blame] | 1951 | if (assoc_rq_parse(ieee->dev, skb, dest) != -1) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1952 | rtllib_resp_to_assoc_rq(ieee, dest); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1953 | |
Mateusz Kulikowski | d69d205 | 2015-03-17 00:00:52 +0100 | [diff] [blame] | 1954 | netdev_info(ieee->dev, "New client associated: %pM\n", dest); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1955 | } |
| 1956 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1957 | void rtllib_sta_ps_send_null_frame(struct rtllib_device *ieee, short pwr) |
| 1958 | { |
| 1959 | |
| 1960 | struct sk_buff *buf = rtllib_null_func(ieee, pwr); |
| 1961 | |
| 1962 | if (buf) |
| 1963 | softmac_ps_mgmt_xmit(buf, ieee); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1964 | } |
Sean MacLennan | 3b28499 | 2011-11-28 20:20:26 -0500 | [diff] [blame] | 1965 | EXPORT_SYMBOL(rtllib_sta_ps_send_null_frame); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1966 | |
| 1967 | void rtllib_sta_ps_send_pspoll_frame(struct rtllib_device *ieee) |
| 1968 | { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1969 | struct sk_buff *buf = rtllib_pspoll_func(ieee); |
| 1970 | |
| 1971 | if (buf) |
| 1972 | softmac_ps_mgmt_xmit(buf, ieee); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1973 | } |
| 1974 | |
Larry Finger | 0dd5650 | 2011-08-25 11:48:12 -0500 | [diff] [blame] | 1975 | static short rtllib_sta_ps_sleep(struct rtllib_device *ieee, u64 *time) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1976 | { |
| 1977 | int timeout = ieee->ps_timeout; |
| 1978 | u8 dtim; |
Shivani Bhardwaj | bd60ac1 | 2015-10-14 23:46:05 +0530 | [diff] [blame] | 1979 | struct rt_pwr_save_ctrl *pPSC = &(ieee->PowerSaveControl); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1980 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1981 | if (ieee->LPSDelayCnt) { |
| 1982 | ieee->LPSDelayCnt--; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1983 | return 0; |
| 1984 | } |
| 1985 | |
| 1986 | dtim = ieee->current_network.dtim_data; |
| 1987 | if (!(dtim & RTLLIB_DTIM_VALID)) |
| 1988 | return 0; |
| 1989 | timeout = ieee->current_network.beacon_interval; |
| 1990 | ieee->current_network.dtim_data = RTLLIB_DTIM_INVALID; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 1991 | /* there's no need to nofity AP that I find you buffered |
Mateusz Kulikowski | 14b40d9 | 2015-04-01 00:24:37 +0200 | [diff] [blame] | 1992 | * with broadcast packet |
| 1993 | */ |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1994 | if (dtim & (RTLLIB_DTIM_UCAST & ieee->ps)) |
| 1995 | return 2; |
| 1996 | |
Vaishali Thakkar | 8b9733c | 2015-03-11 13:51:36 +0530 | [diff] [blame] | 1997 | if (!time_after(jiffies, |
Florian Westphal | 4d0e965 | 2016-05-03 16:30:59 +0200 | [diff] [blame] | 1998 | dev_trans_start(ieee->dev) + msecs_to_jiffies(timeout))) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 1999 | return 0; |
Vaishali Thakkar | 8b9733c | 2015-03-11 13:51:36 +0530 | [diff] [blame] | 2000 | if (!time_after(jiffies, |
| 2001 | ieee->last_rx_ps_time + msecs_to_jiffies(timeout))) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2002 | return 0; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2003 | if ((ieee->softmac_features & IEEE_SOFTMAC_SINGLE_QUEUE) && |
| 2004 | (ieee->mgmt_queue_tail != ieee->mgmt_queue_head)) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2005 | return 0; |
| 2006 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2007 | if (time) { |
Valentina Manea | 4bb0142 | 2013-10-25 11:28:10 +0300 | [diff] [blame] | 2008 | if (ieee->bAwakePktSent) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2009 | pPSC->LPSAwakeIntvl = 1; |
| 2010 | } else { |
Mateusz Kulikowski | 35e33b0 | 2015-05-31 20:19:40 +0200 | [diff] [blame] | 2011 | u8 MaxPeriod = 1; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2012 | |
| 2013 | if (pPSC->LPSAwakeIntvl == 0) |
| 2014 | pPSC->LPSAwakeIntvl = 1; |
| 2015 | if (pPSC->RegMaxLPSAwakeIntvl == 0) |
| 2016 | MaxPeriod = 1; |
| 2017 | else if (pPSC->RegMaxLPSAwakeIntvl == 0xFF) |
| 2018 | MaxPeriod = ieee->current_network.dtim_period; |
| 2019 | else |
| 2020 | MaxPeriod = pPSC->RegMaxLPSAwakeIntvl; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2021 | pPSC->LPSAwakeIntvl = (pPSC->LPSAwakeIntvl >= |
| 2022 | MaxPeriod) ? MaxPeriod : |
| 2023 | (pPSC->LPSAwakeIntvl + 1); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2024 | } |
| 2025 | { |
| 2026 | u8 LPSAwakeIntvl_tmp = 0; |
| 2027 | u8 period = ieee->current_network.dtim_period; |
| 2028 | u8 count = ieee->current_network.tim.tim_count; |
Matthew Casey | 3a6b70c | 2014-08-22 06:27:52 -0400 | [diff] [blame] | 2029 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2030 | if (count == 0) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2031 | if (pPSC->LPSAwakeIntvl > period) |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2032 | LPSAwakeIntvl_tmp = period + |
| 2033 | (pPSC->LPSAwakeIntvl - |
| 2034 | period) - |
| 2035 | ((pPSC->LPSAwakeIntvl-period) % |
| 2036 | period); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2037 | else |
| 2038 | LPSAwakeIntvl_tmp = pPSC->LPSAwakeIntvl; |
| 2039 | |
| 2040 | } else { |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2041 | if (pPSC->LPSAwakeIntvl > |
| 2042 | ieee->current_network.tim.tim_count) |
| 2043 | LPSAwakeIntvl_tmp = count + |
| 2044 | (pPSC->LPSAwakeIntvl - count) - |
| 2045 | ((pPSC->LPSAwakeIntvl-count)%period); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2046 | else |
| 2047 | LPSAwakeIntvl_tmp = pPSC->LPSAwakeIntvl; |
| 2048 | } |
| 2049 | |
Larry Finger | 0dd5650 | 2011-08-25 11:48:12 -0500 | [diff] [blame] | 2050 | *time = ieee->current_network.last_dtim_sta_time |
Vaishali Thakkar | 8b9733c | 2015-03-11 13:51:36 +0530 | [diff] [blame] | 2051 | + msecs_to_jiffies(ieee->current_network.beacon_interval * |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2052 | LPSAwakeIntvl_tmp); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2053 | } |
| 2054 | } |
| 2055 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2056 | return 1; |
| 2057 | |
| 2058 | |
| 2059 | } |
| 2060 | |
Larry Finger | ec0dc6be | 2011-08-25 14:07:04 -0500 | [diff] [blame] | 2061 | static inline void rtllib_sta_ps(struct rtllib_device *ieee) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2062 | { |
Larry Finger | 0dd5650 | 2011-08-25 11:48:12 -0500 | [diff] [blame] | 2063 | u64 time; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2064 | short sleep; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2065 | unsigned long flags, flags2; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2066 | |
| 2067 | spin_lock_irqsave(&ieee->lock, flags); |
| 2068 | |
| 2069 | if ((ieee->ps == RTLLIB_PS_DISABLED || |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2070 | ieee->iw_mode != IW_MODE_INFRA || |
| 2071 | ieee->state != RTLLIB_LINKED)) { |
Mateusz Kulikowski | 0822339 | 2015-03-17 00:00:48 +0100 | [diff] [blame] | 2072 | RT_TRACE(COMP_DBG, |
| 2073 | "=====>%s(): no need to ps,wake up!! ieee->ps is %d, ieee->iw_mode is %d, ieee->state is %d\n", |
| 2074 | __func__, ieee->ps, ieee->iw_mode, ieee->state); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2075 | spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2076 | rtllib_sta_wakeup(ieee, 1); |
| 2077 | |
| 2078 | spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2); |
| 2079 | } |
Larry Finger | 0dd5650 | 2011-08-25 11:48:12 -0500 | [diff] [blame] | 2080 | sleep = rtllib_sta_ps_sleep(ieee, &time); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2081 | /* 2 wake, 1 sleep, 0 do nothing */ |
| 2082 | if (sleep == 0) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2083 | goto out; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2084 | if (sleep == 1) { |
| 2085 | if (ieee->sta_sleep == LPS_IS_SLEEP) { |
Larry Finger | 0dd5650 | 2011-08-25 11:48:12 -0500 | [diff] [blame] | 2086 | ieee->enter_sleep_state(ieee->dev, time); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2087 | } else if (ieee->sta_sleep == LPS_IS_WAKE) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2088 | spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2); |
| 2089 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2090 | if (ieee->ps_is_queue_empty(ieee->dev)) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2091 | ieee->sta_sleep = LPS_WAIT_NULL_DATA_SEND; |
| 2092 | ieee->ack_tx_to_ieee = 1; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2093 | rtllib_sta_ps_send_null_frame(ieee, 1); |
Larry Finger | 0dd5650 | 2011-08-25 11:48:12 -0500 | [diff] [blame] | 2094 | ieee->ps_time = time; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2095 | } |
| 2096 | spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2); |
| 2097 | |
| 2098 | } |
| 2099 | |
| 2100 | ieee->bAwakePktSent = false; |
| 2101 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2102 | } else if (sleep == 2) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2103 | spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2); |
| 2104 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2105 | rtllib_sta_wakeup(ieee, 1); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2106 | |
| 2107 | spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2); |
| 2108 | } |
| 2109 | |
| 2110 | out: |
| 2111 | spin_unlock_irqrestore(&ieee->lock, flags); |
| 2112 | |
| 2113 | } |
| 2114 | |
Mateusz Kulikowski | 6957248 | 2015-07-14 22:04:26 +0200 | [diff] [blame] | 2115 | static void rtllib_sta_wakeup(struct rtllib_device *ieee, short nl) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2116 | { |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2117 | if (ieee->sta_sleep == LPS_IS_WAKE) { |
| 2118 | if (nl) { |
| 2119 | if (ieee->pHTInfo->IOTAction & |
| 2120 | HT_IOT_ACT_NULL_DATA_POWER_SAVING) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2121 | ieee->ack_tx_to_ieee = 1; |
| 2122 | rtllib_sta_ps_send_null_frame(ieee, 0); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2123 | } else { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2124 | ieee->ack_tx_to_ieee = 1; |
| 2125 | rtllib_sta_ps_send_pspoll_frame(ieee); |
| 2126 | } |
| 2127 | } |
| 2128 | return; |
| 2129 | |
| 2130 | } |
| 2131 | |
| 2132 | if (ieee->sta_sleep == LPS_IS_SLEEP) |
| 2133 | ieee->sta_wake_up(ieee->dev); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2134 | if (nl) { |
| 2135 | if (ieee->pHTInfo->IOTAction & |
| 2136 | HT_IOT_ACT_NULL_DATA_POWER_SAVING) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2137 | ieee->ack_tx_to_ieee = 1; |
| 2138 | rtllib_sta_ps_send_null_frame(ieee, 0); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2139 | } else { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2140 | ieee->ack_tx_to_ieee = 1; |
| 2141 | ieee->polling = true; |
| 2142 | rtllib_sta_ps_send_pspoll_frame(ieee); |
| 2143 | } |
| 2144 | |
| 2145 | } else { |
| 2146 | ieee->sta_sleep = LPS_IS_WAKE; |
| 2147 | ieee->polling = false; |
| 2148 | } |
| 2149 | } |
| 2150 | |
| 2151 | void rtllib_ps_tx_ack(struct rtllib_device *ieee, short success) |
| 2152 | { |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2153 | unsigned long flags, flags2; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2154 | |
| 2155 | spin_lock_irqsave(&ieee->lock, flags); |
| 2156 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2157 | if (ieee->sta_sleep == LPS_WAIT_NULL_DATA_SEND) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2158 | /* Null frame with PS bit set */ |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2159 | if (success) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2160 | ieee->sta_sleep = LPS_IS_SLEEP; |
Larry Finger | 0dd5650 | 2011-08-25 11:48:12 -0500 | [diff] [blame] | 2161 | ieee->enter_sleep_state(ieee->dev, ieee->ps_time); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2162 | } |
| 2163 | /* if the card report not success we can't be sure the AP |
| 2164 | * has not RXed so we can't assume the AP believe us awake |
| 2165 | */ |
| 2166 | } else {/* 21112005 - tx again null without PS bit if lost */ |
| 2167 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2168 | if ((ieee->sta_sleep == LPS_IS_WAKE) && !success) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2169 | spin_lock_irqsave(&ieee->mgmt_tx_lock, flags2); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2170 | if (ieee->pHTInfo->IOTAction & |
| 2171 | HT_IOT_ACT_NULL_DATA_POWER_SAVING) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2172 | rtllib_sta_ps_send_null_frame(ieee, 0); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2173 | else |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2174 | rtllib_sta_ps_send_pspoll_frame(ieee); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2175 | spin_unlock_irqrestore(&ieee->mgmt_tx_lock, flags2); |
| 2176 | } |
| 2177 | } |
| 2178 | spin_unlock_irqrestore(&ieee->lock, flags); |
| 2179 | } |
Sean MacLennan | 3b28499 | 2011-11-28 20:20:26 -0500 | [diff] [blame] | 2180 | EXPORT_SYMBOL(rtllib_ps_tx_ack); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2181 | |
Mateusz Kulikowski | 35e33b0 | 2015-05-31 20:19:40 +0200 | [diff] [blame] | 2182 | static void rtllib_process_action(struct rtllib_device *ieee, |
| 2183 | struct sk_buff *skb) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2184 | { |
| 2185 | struct rtllib_hdr_3addr *header = (struct rtllib_hdr_3addr *) skb->data; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2186 | u8 *act = rtllib_get_payload((struct rtllib_hdr *)header); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2187 | u8 category = 0; |
| 2188 | |
| 2189 | if (act == NULL) { |
Mateusz Kulikowski | 11e672c | 2015-05-31 20:19:26 +0200 | [diff] [blame] | 2190 | netdev_warn(ieee->dev, |
| 2191 | "Error getting payload of action frame\n"); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2192 | return; |
| 2193 | } |
| 2194 | |
| 2195 | category = *act; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2196 | act++; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2197 | switch (category) { |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2198 | case ACT_CAT_BA: |
| 2199 | switch (*act) { |
| 2200 | case ACT_ADDBAREQ: |
| 2201 | rtllib_rx_ADDBAReq(ieee, skb); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2202 | break; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2203 | case ACT_ADDBARSP: |
| 2204 | rtllib_rx_ADDBARsp(ieee, skb); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2205 | break; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2206 | case ACT_DELBA: |
| 2207 | rtllib_rx_DELBA(ieee, skb); |
| 2208 | break; |
| 2209 | } |
| 2210 | break; |
| 2211 | default: |
| 2212 | break; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2213 | } |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2214 | } |
| 2215 | |
Baoyou Xie | ec65ef8 | 2016-09-04 14:33:35 +0800 | [diff] [blame] | 2216 | static inline int |
| 2217 | rtllib_rx_assoc_resp(struct rtllib_device *ieee, struct sk_buff *skb, |
| 2218 | struct rtllib_rx_stats *rx_stats) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2219 | { |
| 2220 | u16 errcode; |
| 2221 | int aid; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2222 | u8 *ies; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2223 | struct rtllib_assoc_response_frame *assoc_resp; |
| 2224 | struct rtllib_hdr_3addr *header = (struct rtllib_hdr_3addr *) skb->data; |
Gnanachandran Dhanapal | fa70ae0 | 2015-06-09 14:47:49 +0000 | [diff] [blame] | 2225 | u16 frame_ctl = le16_to_cpu(header->frame_ctl); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2226 | |
Mateusz Kulikowski | e9fea2e | 2015-05-31 20:19:33 +0200 | [diff] [blame] | 2227 | netdev_dbg(ieee->dev, "received [RE]ASSOCIATION RESPONSE (%d)\n", |
Gnanachandran Dhanapal | fa70ae0 | 2015-06-09 14:47:49 +0000 | [diff] [blame] | 2228 | WLAN_FC_GET_STYPE(frame_ctl)); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2229 | |
| 2230 | if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) && |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2231 | ieee->state == RTLLIB_ASSOCIATING_AUTHENTICATED && |
| 2232 | (ieee->iw_mode == IW_MODE_INFRA)) { |
| 2233 | errcode = assoc_parse(ieee, skb, &aid); |
Mateusz Kulikowski | 4c29207 | 2015-09-20 21:04:27 +0200 | [diff] [blame] | 2234 | if (!errcode) { |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2235 | struct rtllib_network *network = |
| 2236 | kzalloc(sizeof(struct rtllib_network), |
| 2237 | GFP_ATOMIC); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2238 | |
| 2239 | if (!network) |
| 2240 | return 1; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2241 | ieee->state = RTLLIB_LINKED; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2242 | ieee->assoc_id = aid; |
| 2243 | ieee->softmac_stats.rx_ass_ok++; |
| 2244 | /* station support qos */ |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2245 | /* Let the register setting default with Legacy station */ |
| 2246 | assoc_resp = (struct rtllib_assoc_response_frame *)skb->data; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2247 | if (ieee->current_network.qos_data.supported == 1) { |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2248 | if (rtllib_parse_info_param(ieee, assoc_resp->info_element, |
| 2249 | rx_stats->len - sizeof(*assoc_resp), |
| 2250 | network, rx_stats)) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2251 | kfree(network); |
| 2252 | return 1; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2253 | } |
Mahati Chamarthy | 92db2a2 | 2014-09-22 01:21:48 +0530 | [diff] [blame] | 2254 | memcpy(ieee->pHTInfo->PeerHTCapBuf, |
| 2255 | network->bssht.bdHTCapBuf, |
| 2256 | network->bssht.bdHTCapLen); |
| 2257 | memcpy(ieee->pHTInfo->PeerHTInfoBuf, |
| 2258 | network->bssht.bdHTInfoBuf, |
| 2259 | network->bssht.bdHTInfoLen); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2260 | if (ieee->handle_assoc_response != NULL) |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2261 | ieee->handle_assoc_response(ieee->dev, |
| 2262 | (struct rtllib_assoc_response_frame *)header, |
| 2263 | network); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2264 | } |
Jesper Juhl | 3375034 | 2012-02-13 00:15:02 +0100 | [diff] [blame] | 2265 | kfree(network); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2266 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2267 | kfree(ieee->assocresp_ies); |
| 2268 | ieee->assocresp_ies = NULL; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2269 | ies = &(assoc_resp->info_element[0].id); |
| 2270 | ieee->assocresp_ies_len = (skb->data + skb->len) - ies; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2271 | ieee->assocresp_ies = kmalloc(ieee->assocresp_ies_len, |
| 2272 | GFP_ATOMIC); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2273 | if (ieee->assocresp_ies) |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2274 | memcpy(ieee->assocresp_ies, ies, |
| 2275 | ieee->assocresp_ies_len); |
| 2276 | else { |
Mateusz Kulikowski | d69d205 | 2015-03-17 00:00:52 +0100 | [diff] [blame] | 2277 | netdev_info(ieee->dev, |
| 2278 | "%s()Warning: can't alloc memory for assocresp_ies\n", |
| 2279 | __func__); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2280 | ieee->assocresp_ies_len = 0; |
| 2281 | } |
| 2282 | rtllib_associate_complete(ieee); |
| 2283 | } else { |
| 2284 | /* aid could not been allocated */ |
| 2285 | ieee->softmac_stats.rx_ass_err++; |
Mateusz Kulikowski | d69d205 | 2015-03-17 00:00:52 +0100 | [diff] [blame] | 2286 | netdev_info(ieee->dev, |
| 2287 | "Association response status code 0x%x\n", |
| 2288 | errcode); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2289 | if (ieee->AsocRetryCount < RT_ASOC_RETRY_LIMIT) |
Amitoj Kaur Chawla | 354605f | 2016-02-20 15:36:26 +0530 | [diff] [blame] | 2290 | schedule_delayed_work( |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2291 | &ieee->associate_procedure_wq, 0); |
| 2292 | else |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2293 | rtllib_associate_abort(ieee); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2294 | } |
| 2295 | } |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2296 | return 0; |
| 2297 | } |
| 2298 | |
Mateusz Kulikowski | e8f05b0 | 2015-04-01 00:24:34 +0200 | [diff] [blame] | 2299 | static void rtllib_rx_auth_resp(struct rtllib_device *ieee, struct sk_buff *skb) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2300 | { |
| 2301 | u16 errcode; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2302 | u8 *challenge; |
| 2303 | int chlen = 0; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2304 | bool bSupportNmode = true, bHalfSupportNmode = false; |
| 2305 | |
Mateusz Kulikowski | e9fea2e | 2015-05-31 20:19:33 +0200 | [diff] [blame] | 2306 | errcode = auth_parse(ieee->dev, skb, &challenge, &chlen); |
Mateusz Kulikowski | e8f05b0 | 2015-04-01 00:24:34 +0200 | [diff] [blame] | 2307 | |
Mateusz Kulikowski | f7567e2 | 2015-04-01 00:24:35 +0200 | [diff] [blame] | 2308 | if (errcode) { |
Mateusz Kulikowski | e8f05b0 | 2015-04-01 00:24:34 +0200 | [diff] [blame] | 2309 | ieee->softmac_stats.rx_auth_rs_err++; |
Mateusz Kulikowski | e8f05b0 | 2015-04-01 00:24:34 +0200 | [diff] [blame] | 2310 | netdev_info(ieee->dev, |
Mateusz Kulikowski | e725fb6 | 2015-04-01 00:24:36 +0200 | [diff] [blame] | 2311 | "Authentication respose status code 0x%x", errcode); |
Mateusz Kulikowski | e8f05b0 | 2015-04-01 00:24:34 +0200 | [diff] [blame] | 2312 | rtllib_associate_abort(ieee); |
Mateusz Kulikowski | f7567e2 | 2015-04-01 00:24:35 +0200 | [diff] [blame] | 2313 | return; |
| 2314 | } |
| 2315 | |
| 2316 | if (ieee->open_wep || !challenge) { |
| 2317 | ieee->state = RTLLIB_ASSOCIATING_AUTHENTICATED; |
| 2318 | ieee->softmac_stats.rx_auth_rs_ok++; |
Mateusz Kulikowski | e725fb6 | 2015-04-01 00:24:36 +0200 | [diff] [blame] | 2319 | if (!(ieee->pHTInfo->IOTAction & HT_IOT_ACT_PURE_N_MODE)) { |
Mateusz Kulikowski | f7567e2 | 2015-04-01 00:24:35 +0200 | [diff] [blame] | 2320 | if (!ieee->GetNmodeSupportBySecCfg(ieee->dev)) { |
| 2321 | if (IsHTHalfNmodeAPs(ieee)) { |
| 2322 | bSupportNmode = true; |
| 2323 | bHalfSupportNmode = true; |
| 2324 | } else { |
| 2325 | bSupportNmode = false; |
| 2326 | bHalfSupportNmode = false; |
| 2327 | } |
| 2328 | } |
| 2329 | } |
Mateusz Kulikowski | 14b40d9 | 2015-04-01 00:24:37 +0200 | [diff] [blame] | 2330 | /* Dummy wirless mode setting to avoid encryption issue */ |
Mateusz Kulikowski | f7567e2 | 2015-04-01 00:24:35 +0200 | [diff] [blame] | 2331 | if (bSupportNmode) { |
| 2332 | ieee->SetWirelessMode(ieee->dev, |
Mateusz Kulikowski | e725fb6 | 2015-04-01 00:24:36 +0200 | [diff] [blame] | 2333 | ieee->current_network.mode); |
Mateusz Kulikowski | f7567e2 | 2015-04-01 00:24:35 +0200 | [diff] [blame] | 2334 | } else { |
| 2335 | /*TODO*/ |
Mateusz Kulikowski | e725fb6 | 2015-04-01 00:24:36 +0200 | [diff] [blame] | 2336 | ieee->SetWirelessMode(ieee->dev, IEEE_G); |
Mateusz Kulikowski | f7567e2 | 2015-04-01 00:24:35 +0200 | [diff] [blame] | 2337 | } |
| 2338 | |
Mateusz Kulikowski | e725fb6 | 2015-04-01 00:24:36 +0200 | [diff] [blame] | 2339 | if ((ieee->current_network.mode == IEEE_N_24G) && |
| 2340 | bHalfSupportNmode) { |
| 2341 | netdev_info(ieee->dev, "======>enter half N mode\n"); |
| 2342 | ieee->bHalfWirelessN24GMode = true; |
| 2343 | } else { |
| 2344 | ieee->bHalfWirelessN24GMode = false; |
| 2345 | } |
Mateusz Kulikowski | f7567e2 | 2015-04-01 00:24:35 +0200 | [diff] [blame] | 2346 | rtllib_associate_step2(ieee); |
| 2347 | } else { |
Mateusz Kulikowski | e725fb6 | 2015-04-01 00:24:36 +0200 | [diff] [blame] | 2348 | rtllib_auth_challenge(ieee, challenge, chlen); |
Mateusz Kulikowski | e8f05b0 | 2015-04-01 00:24:34 +0200 | [diff] [blame] | 2349 | } |
| 2350 | } |
| 2351 | |
Baoyou Xie | ec65ef8 | 2016-09-04 14:33:35 +0800 | [diff] [blame] | 2352 | static inline int |
| 2353 | rtllib_rx_auth(struct rtllib_device *ieee, struct sk_buff *skb, |
| 2354 | struct rtllib_rx_stats *rx_stats) |
Mateusz Kulikowski | e8f05b0 | 2015-04-01 00:24:34 +0200 | [diff] [blame] | 2355 | { |
| 2356 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2357 | if (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2358 | if (ieee->state == RTLLIB_ASSOCIATING_AUTHENTICATING && |
| 2359 | (ieee->iw_mode == IW_MODE_INFRA)) { |
Mateusz Kulikowski | e9fea2e | 2015-05-31 20:19:33 +0200 | [diff] [blame] | 2360 | netdev_dbg(ieee->dev, |
| 2361 | "Received authentication response"); |
Mateusz Kulikowski | e8f05b0 | 2015-04-01 00:24:34 +0200 | [diff] [blame] | 2362 | rtllib_rx_auth_resp(ieee, skb); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2363 | } else if (ieee->iw_mode == IW_MODE_MASTER) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2364 | rtllib_rx_auth_rq(ieee, skb); |
| 2365 | } |
| 2366 | } |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2367 | return 0; |
| 2368 | } |
| 2369 | |
Baoyou Xie | ec65ef8 | 2016-09-04 14:33:35 +0800 | [diff] [blame] | 2370 | static inline int |
| 2371 | rtllib_rx_deauth(struct rtllib_device *ieee, struct sk_buff *skb) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2372 | { |
| 2373 | struct rtllib_hdr_3addr *header = (struct rtllib_hdr_3addr *) skb->data; |
Gnanachandran Dhanapal | fa70ae0 | 2015-06-09 14:47:49 +0000 | [diff] [blame] | 2374 | u16 frame_ctl; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2375 | |
| 2376 | if (memcmp(header->addr3, ieee->current_network.bssid, ETH_ALEN) != 0) |
| 2377 | return 0; |
| 2378 | |
| 2379 | /* FIXME for now repeat all the association procedure |
Mateusz Kulikowski | 14b40d9 | 2015-04-01 00:24:37 +0200 | [diff] [blame] | 2380 | * both for disassociation and deauthentication |
| 2381 | */ |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2382 | if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) && |
| 2383 | ieee->state == RTLLIB_LINKED && |
| 2384 | (ieee->iw_mode == IW_MODE_INFRA)) { |
Gnanachandran Dhanapal | fa70ae0 | 2015-06-09 14:47:49 +0000 | [diff] [blame] | 2385 | frame_ctl = le16_to_cpu(header->frame_ctl); |
Mateusz Kulikowski | d69d205 | 2015-03-17 00:00:52 +0100 | [diff] [blame] | 2386 | netdev_info(ieee->dev, |
| 2387 | "==========>received disassoc/deauth(%x) frame, reason code:%x\n", |
Gnanachandran Dhanapal | fa70ae0 | 2015-06-09 14:47:49 +0000 | [diff] [blame] | 2388 | WLAN_FC_GET_STYPE(frame_ctl), |
Mateusz Kulikowski | d69d205 | 2015-03-17 00:00:52 +0100 | [diff] [blame] | 2389 | ((struct rtllib_disassoc *)skb->data)->reason); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2390 | ieee->state = RTLLIB_ASSOCIATING; |
| 2391 | ieee->softmac_stats.reassoc++; |
| 2392 | ieee->is_roaming = true; |
| 2393 | ieee->LinkDetectInfo.bBusyTraffic = false; |
| 2394 | rtllib_disassociate(ieee); |
| 2395 | RemovePeerTS(ieee, header->addr2); |
| 2396 | if (ieee->LedControlHandler != NULL) |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2397 | ieee->LedControlHandler(ieee->dev, |
| 2398 | LED_CTL_START_TO_LINK); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2399 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2400 | if (!(ieee->rtllib_ap_sec_type(ieee) & |
| 2401 | (SEC_ALG_CCMP|SEC_ALG_TKIP))) |
Amitoj Kaur Chawla | 354605f | 2016-02-20 15:36:26 +0530 | [diff] [blame] | 2402 | schedule_delayed_work( |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2403 | &ieee->associate_procedure_wq, 5); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2404 | } |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2405 | return 0; |
| 2406 | } |
| 2407 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2408 | inline int rtllib_rx_frame_softmac(struct rtllib_device *ieee, |
| 2409 | struct sk_buff *skb, |
| 2410 | struct rtllib_rx_stats *rx_stats, u16 type, |
| 2411 | u16 stype) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2412 | { |
| 2413 | struct rtllib_hdr_3addr *header = (struct rtllib_hdr_3addr *) skb->data; |
Gnanachandran Dhanapal | fa70ae0 | 2015-06-09 14:47:49 +0000 | [diff] [blame] | 2414 | u16 frame_ctl; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2415 | |
| 2416 | if (!ieee->proto_started) |
| 2417 | return 0; |
| 2418 | |
Gnanachandran Dhanapal | fa70ae0 | 2015-06-09 14:47:49 +0000 | [diff] [blame] | 2419 | frame_ctl = le16_to_cpu(header->frame_ctl); |
| 2420 | switch (WLAN_FC_GET_STYPE(frame_ctl)) { |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2421 | case RTLLIB_STYPE_ASSOC_RESP: |
| 2422 | case RTLLIB_STYPE_REASSOC_RESP: |
| 2423 | if (rtllib_rx_assoc_resp(ieee, skb, rx_stats) == 1) |
| 2424 | return 1; |
| 2425 | break; |
| 2426 | case RTLLIB_STYPE_ASSOC_REQ: |
| 2427 | case RTLLIB_STYPE_REASSOC_REQ: |
| 2428 | if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) && |
| 2429 | ieee->iw_mode == IW_MODE_MASTER) |
| 2430 | rtllib_rx_assoc_rq(ieee, skb); |
| 2431 | break; |
| 2432 | case RTLLIB_STYPE_AUTH: |
| 2433 | rtllib_rx_auth(ieee, skb, rx_stats); |
| 2434 | break; |
| 2435 | case RTLLIB_STYPE_DISASSOC: |
| 2436 | case RTLLIB_STYPE_DEAUTH: |
| 2437 | rtllib_rx_deauth(ieee, skb); |
| 2438 | break; |
| 2439 | case RTLLIB_STYPE_MANAGE_ACT: |
| 2440 | rtllib_process_action(ieee, skb); |
| 2441 | break; |
| 2442 | default: |
| 2443 | return -1; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2444 | } |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2445 | return 0; |
| 2446 | } |
| 2447 | |
Masanari Iida | db2c8da | 2012-08-10 01:37:31 +0900 | [diff] [blame] | 2448 | /* following are for a simpler TX queue management. |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2449 | * Instead of using netif_[stop/wake]_queue the driver |
Justin P. Mattock | cd01712 | 2012-04-23 07:36:52 -0700 | [diff] [blame] | 2450 | * will use these two functions (plus a reset one), that |
| 2451 | * will internally use the kernel netif_* and takes |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2452 | * care of the ieee802.11 fragmentation. |
| 2453 | * So the driver receives a fragment per time and might |
Justin P. Mattock | cd01712 | 2012-04-23 07:36:52 -0700 | [diff] [blame] | 2454 | * call the stop function when it wants to not |
| 2455 | * have enough room to TX an entire packet. |
| 2456 | * This might be useful if each fragment needs it's own |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2457 | * descriptor, thus just keep a total free memory > than |
Justin P. Mattock | cd01712 | 2012-04-23 07:36:52 -0700 | [diff] [blame] | 2458 | * the max fragmentation threshold is not enough.. If the |
| 2459 | * ieee802.11 stack passed a TXB struct then you need |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2460 | * to keep N free descriptors where |
| 2461 | * N = MAX_PACKET_SIZE / MIN_FRAG_TRESHOLD |
| 2462 | * In this way you need just one and the 802.11 stack |
| 2463 | * will take care of buffering fragments and pass them to |
| 2464 | * to the driver later, when it wakes the queue. |
| 2465 | */ |
| 2466 | void rtllib_softmac_xmit(struct rtllib_txb *txb, struct rtllib_device *ieee) |
| 2467 | { |
| 2468 | |
| 2469 | unsigned int queue_index = txb->queue_index; |
| 2470 | unsigned long flags; |
| 2471 | int i; |
Larry Finger | 3b83db4 | 2011-07-19 00:01:29 -0500 | [diff] [blame] | 2472 | struct cb_desc *tcb_desc = NULL; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2473 | unsigned long queue_len = 0; |
| 2474 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2475 | spin_lock_irqsave(&ieee->lock, flags); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2476 | |
| 2477 | /* called with 2nd parm 0, no tx mgmt lock required */ |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2478 | rtllib_sta_wakeup(ieee, 0); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2479 | |
| 2480 | /* update the tx status */ |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2481 | tcb_desc = (struct cb_desc *)(txb->fragments[0]->cb + |
| 2482 | MAX_DEV_ADDR_SIZE); |
| 2483 | if (tcb_desc->bMulticast) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2484 | ieee->stats.multicast++; |
Mike McCormack | 4f6807e | 2011-07-11 08:56:20 +0900 | [diff] [blame] | 2485 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2486 | /* if xmit available, just xmit it immediately, else just insert it to |
Mateusz Kulikowski | 14b40d9 | 2015-04-01 00:24:37 +0200 | [diff] [blame] | 2487 | * the wait queue |
| 2488 | */ |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2489 | for (i = 0; i < txb->nr_frags; i++) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2490 | queue_len = skb_queue_len(&ieee->skb_waitQ[queue_index]); |
Mateusz Kulikowski | e2ac043 | 2015-04-01 00:24:30 +0200 | [diff] [blame] | 2491 | if ((queue_len != 0) || |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2492 | (!ieee->check_nic_enough_desc(ieee->dev, queue_index)) || |
| 2493 | (ieee->queue_stop)) { |
Mateusz Kulikowski | 14b40d9 | 2015-04-01 00:24:37 +0200 | [diff] [blame] | 2494 | /* insert the skb packet to the wait queue |
| 2495 | * as for the completion function, it does not need |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2496 | * to check it any more. |
Mateusz Kulikowski | 14b40d9 | 2015-04-01 00:24:37 +0200 | [diff] [blame] | 2497 | */ |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2498 | if (queue_len < 200) |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2499 | skb_queue_tail(&ieee->skb_waitQ[queue_index], |
| 2500 | txb->fragments[i]); |
| 2501 | else |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2502 | kfree_skb(txb->fragments[i]); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2503 | } else { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2504 | ieee->softmac_data_hard_start_xmit( |
| 2505 | txb->fragments[i], |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2506 | ieee->dev, ieee->rate); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2507 | } |
| 2508 | } |
Mike McCormack | 4f6807e | 2011-07-11 08:56:20 +0900 | [diff] [blame] | 2509 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2510 | rtllib_txb_free(txb); |
| 2511 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2512 | spin_unlock_irqrestore(&ieee->lock, flags); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2513 | |
| 2514 | } |
| 2515 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2516 | void rtllib_reset_queue(struct rtllib_device *ieee) |
| 2517 | { |
| 2518 | unsigned long flags; |
| 2519 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2520 | spin_lock_irqsave(&ieee->lock, flags); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2521 | init_mgmt_queue(ieee); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2522 | if (ieee->tx_pending.txb) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2523 | rtllib_txb_free(ieee->tx_pending.txb); |
| 2524 | ieee->tx_pending.txb = NULL; |
| 2525 | } |
| 2526 | ieee->queue_stop = 0; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2527 | spin_unlock_irqrestore(&ieee->lock, flags); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2528 | |
| 2529 | } |
Sean MacLennan | 3b28499 | 2011-11-28 20:20:26 -0500 | [diff] [blame] | 2530 | EXPORT_SYMBOL(rtllib_reset_queue); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2531 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2532 | void rtllib_stop_all_queues(struct rtllib_device *ieee) |
| 2533 | { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2534 | unsigned int i; |
Matthew Casey | 3a6b70c | 2014-08-22 06:27:52 -0400 | [diff] [blame] | 2535 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2536 | for (i = 0; i < ieee->dev->num_tx_queues; i++) |
| 2537 | netdev_get_tx_queue(ieee->dev, i)->trans_start = jiffies; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2538 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2539 | netif_tx_stop_all_queues(ieee->dev); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2540 | } |
| 2541 | |
| 2542 | void rtllib_wake_all_queues(struct rtllib_device *ieee) |
| 2543 | { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2544 | netif_tx_wake_all_queues(ieee->dev); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2545 | } |
| 2546 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2547 | /* called in user context only */ |
Mateusz Kulikowski | 6957248 | 2015-07-14 22:04:26 +0200 | [diff] [blame] | 2548 | static void rtllib_start_master_bss(struct rtllib_device *ieee) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2549 | { |
| 2550 | ieee->assoc_id = 1; |
| 2551 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2552 | if (ieee->current_network.ssid_len == 0) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2553 | strncpy(ieee->current_network.ssid, |
| 2554 | RTLLIB_DEFAULT_TX_ESSID, |
| 2555 | IW_ESSID_MAX_SIZE); |
| 2556 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2557 | ieee->current_network.ssid_len = |
| 2558 | strlen(RTLLIB_DEFAULT_TX_ESSID); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2559 | ieee->ssid_set = 1; |
| 2560 | } |
| 2561 | |
Mateusz Kulikowski | b57ceb1 | 2015-05-31 20:19:22 +0200 | [diff] [blame] | 2562 | ether_addr_copy(ieee->current_network.bssid, ieee->dev->dev_addr); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2563 | |
| 2564 | ieee->set_chan(ieee->dev, ieee->current_network.channel); |
| 2565 | ieee->state = RTLLIB_LINKED; |
| 2566 | ieee->link_change(ieee->dev); |
| 2567 | notify_wx_assoc_event(ieee); |
| 2568 | |
| 2569 | if (ieee->data_hard_resume) |
| 2570 | ieee->data_hard_resume(ieee->dev); |
| 2571 | |
| 2572 | netif_carrier_on(ieee->dev); |
| 2573 | } |
| 2574 | |
Larry Finger | ec0dc6be | 2011-08-25 14:07:04 -0500 | [diff] [blame] | 2575 | static void rtllib_start_monitor_mode(struct rtllib_device *ieee) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2576 | { |
| 2577 | /* reset hardware status */ |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2578 | if (ieee->raw_tx) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2579 | if (ieee->data_hard_resume) |
| 2580 | ieee->data_hard_resume(ieee->dev); |
| 2581 | |
| 2582 | netif_carrier_on(ieee->dev); |
| 2583 | } |
| 2584 | } |
| 2585 | |
Larry Finger | ec0dc6be | 2011-08-25 14:07:04 -0500 | [diff] [blame] | 2586 | static void rtllib_start_ibss_wq(void *data) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2587 | { |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2588 | struct rtllib_device *ieee = container_of_dwork_rsl(data, |
| 2589 | struct rtllib_device, start_ibss_wq); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2590 | /* iwconfig mode ad-hoc will schedule this and return |
| 2591 | * on the other hand this will block further iwconfig SET |
Binoy Jayan | 9afa937 | 2016-06-01 14:56:52 +0530 | [diff] [blame] | 2592 | * operations because of the wx_mutex hold. |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2593 | * Anyway some most set operations set a flag to speed-up |
| 2594 | * (abort) this wq (when syncro scanning) before sleeping |
Binoy Jayan | 9afa937 | 2016-06-01 14:56:52 +0530 | [diff] [blame] | 2595 | * on the mutex |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2596 | */ |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2597 | if (!ieee->proto_started) { |
Mateusz Kulikowski | d69d205 | 2015-03-17 00:00:52 +0100 | [diff] [blame] | 2598 | netdev_info(ieee->dev, "==========oh driver down return\n"); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2599 | return; |
| 2600 | } |
Binoy Jayan | 9afa937 | 2016-06-01 14:56:52 +0530 | [diff] [blame] | 2601 | mutex_lock(&ieee->wx_mutex); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2602 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2603 | if (ieee->current_network.ssid_len == 0) { |
| 2604 | strcpy(ieee->current_network.ssid, RTLLIB_DEFAULT_TX_ESSID); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2605 | ieee->current_network.ssid_len = strlen(RTLLIB_DEFAULT_TX_ESSID); |
| 2606 | ieee->ssid_set = 1; |
| 2607 | } |
| 2608 | |
| 2609 | ieee->state = RTLLIB_NOLINK; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2610 | ieee->mode = IEEE_G; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2611 | /* check if we have this cell in our network list */ |
| 2612 | rtllib_softmac_check_all_nets(ieee); |
| 2613 | |
| 2614 | |
Justin P. Mattock | cd01712 | 2012-04-23 07:36:52 -0700 | [diff] [blame] | 2615 | /* if not then the state is not linked. Maybe the user switched to |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2616 | * ad-hoc mode just after being in monitor mode, or just after |
| 2617 | * being very few time in managed mode (so the card have had no |
| 2618 | * time to scan all the chans..) or we have just run up the iface |
| 2619 | * after setting ad-hoc mode. So we have to give another try.. |
| 2620 | * Here, in ibss mode, should be safe to do this without extra care |
Justin P. Mattock | cd01712 | 2012-04-23 07:36:52 -0700 | [diff] [blame] | 2621 | * (in bss mode we had to make sure no-one tried to associate when |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2622 | * we had just checked the ieee->state and we was going to start the |
Justin P. Mattock | cd01712 | 2012-04-23 07:36:52 -0700 | [diff] [blame] | 2623 | * scan) because in ibss mode the rtllib_new_net function, when |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2624 | * finds a good net, just set the ieee->state to RTLLIB_LINKED, |
| 2625 | * so, at worst, we waste a bit of time to initiate an unneeded syncro |
| 2626 | * scan, that will stop at the first round because it sees the state |
| 2627 | * associated. |
| 2628 | */ |
| 2629 | if (ieee->state == RTLLIB_NOLINK) |
| 2630 | rtllib_start_scan_syncro(ieee, 0); |
| 2631 | |
| 2632 | /* the network definitively is not here.. create a new cell */ |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2633 | if (ieee->state == RTLLIB_NOLINK) { |
Mateusz Kulikowski | d69d205 | 2015-03-17 00:00:52 +0100 | [diff] [blame] | 2634 | netdev_info(ieee->dev, "creating new IBSS cell\n"); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2635 | ieee->current_network.channel = ieee->IbssStartChnl; |
| 2636 | if (!ieee->wap_set) |
Bhumika Goyal | 3724197 | 2016-03-02 01:12:03 +0530 | [diff] [blame] | 2637 | eth_random_addr(ieee->current_network.bssid); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2638 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2639 | if (ieee->modulation & RTLLIB_CCK_MODULATION) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2640 | |
| 2641 | ieee->current_network.rates_len = 4; |
| 2642 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2643 | ieee->current_network.rates[0] = |
| 2644 | RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_1MB; |
| 2645 | ieee->current_network.rates[1] = |
| 2646 | RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_2MB; |
| 2647 | ieee->current_network.rates[2] = |
| 2648 | RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_5MB; |
| 2649 | ieee->current_network.rates[3] = |
| 2650 | RTLLIB_BASIC_RATE_MASK | RTLLIB_CCK_RATE_11MB; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2651 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2652 | } else |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2653 | ieee->current_network.rates_len = 0; |
| 2654 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2655 | if (ieee->modulation & RTLLIB_OFDM_MODULATION) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2656 | ieee->current_network.rates_ex_len = 8; |
| 2657 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2658 | ieee->current_network.rates_ex[0] = |
| 2659 | RTLLIB_OFDM_RATE_6MB; |
| 2660 | ieee->current_network.rates_ex[1] = |
| 2661 | RTLLIB_OFDM_RATE_9MB; |
| 2662 | ieee->current_network.rates_ex[2] = |
| 2663 | RTLLIB_OFDM_RATE_12MB; |
| 2664 | ieee->current_network.rates_ex[3] = |
| 2665 | RTLLIB_OFDM_RATE_18MB; |
| 2666 | ieee->current_network.rates_ex[4] = |
| 2667 | RTLLIB_OFDM_RATE_24MB; |
| 2668 | ieee->current_network.rates_ex[5] = |
| 2669 | RTLLIB_OFDM_RATE_36MB; |
| 2670 | ieee->current_network.rates_ex[6] = |
| 2671 | RTLLIB_OFDM_RATE_48MB; |
| 2672 | ieee->current_network.rates_ex[7] = |
| 2673 | RTLLIB_OFDM_RATE_54MB; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2674 | |
| 2675 | ieee->rate = 108; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2676 | } else { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2677 | ieee->current_network.rates_ex_len = 0; |
| 2678 | ieee->rate = 22; |
| 2679 | } |
| 2680 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2681 | ieee->current_network.qos_data.supported = 0; |
| 2682 | ieee->SetWirelessMode(ieee->dev, IEEE_G); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2683 | ieee->current_network.mode = ieee->mode; |
| 2684 | ieee->current_network.atim_window = 0; |
| 2685 | ieee->current_network.capability = WLAN_CAPABILITY_IBSS; |
| 2686 | } |
| 2687 | |
Mateusz Kulikowski | d69d205 | 2015-03-17 00:00:52 +0100 | [diff] [blame] | 2688 | netdev_info(ieee->dev, "%s(): ieee->mode = %d\n", __func__, ieee->mode); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2689 | if ((ieee->mode == IEEE_N_24G) || (ieee->mode == IEEE_N_5G)) |
| 2690 | HTUseDefaultSetting(ieee); |
| 2691 | else |
| 2692 | ieee->pHTInfo->bCurrentHTSupport = false; |
| 2693 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2694 | ieee->SetHwRegHandler(ieee->dev, HW_VAR_MEDIA_STATUS, |
| 2695 | (u8 *)(&ieee->state)); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2696 | |
| 2697 | ieee->state = RTLLIB_LINKED; |
| 2698 | ieee->link_change(ieee->dev); |
| 2699 | |
| 2700 | HTSetConnectBwMode(ieee, HT_CHANNEL_WIDTH_20, HT_EXTCHNL_OFFSET_NO_EXT); |
| 2701 | if (ieee->LedControlHandler != NULL) |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2702 | ieee->LedControlHandler(ieee->dev, LED_CTL_LINK); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2703 | |
| 2704 | rtllib_start_send_beacons(ieee); |
| 2705 | |
| 2706 | notify_wx_assoc_event(ieee); |
| 2707 | |
| 2708 | if (ieee->data_hard_resume) |
| 2709 | ieee->data_hard_resume(ieee->dev); |
| 2710 | |
| 2711 | netif_carrier_on(ieee->dev); |
| 2712 | |
Binoy Jayan | 9afa937 | 2016-06-01 14:56:52 +0530 | [diff] [blame] | 2713 | mutex_unlock(&ieee->wx_mutex); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2714 | } |
| 2715 | |
| 2716 | inline void rtllib_start_ibss(struct rtllib_device *ieee) |
| 2717 | { |
Amitoj Kaur Chawla | 354605f | 2016-02-20 15:36:26 +0530 | [diff] [blame] | 2718 | schedule_delayed_work(&ieee->start_ibss_wq, msecs_to_jiffies(150)); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2719 | } |
| 2720 | |
Binoy Jayan | 9afa937 | 2016-06-01 14:56:52 +0530 | [diff] [blame] | 2721 | /* this is called only in user context, with wx_mutex held */ |
Mateusz Kulikowski | 6957248 | 2015-07-14 22:04:26 +0200 | [diff] [blame] | 2722 | static void rtllib_start_bss(struct rtllib_device *ieee) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2723 | { |
| 2724 | unsigned long flags; |
Matthew Casey | 3a6b70c | 2014-08-22 06:27:52 -0400 | [diff] [blame] | 2725 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2726 | if (IS_DOT11D_ENABLE(ieee) && !IS_COUNTRY_IE_VALID(ieee)) { |
| 2727 | if (!ieee->bGlobalDomain) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2728 | return; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2729 | } |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2730 | /* check if we have already found the net we |
| 2731 | * are interested in (if any). |
| 2732 | * if not (we are disassociated and we are not |
| 2733 | * in associating / authenticating phase) start the background scanning. |
| 2734 | */ |
| 2735 | rtllib_softmac_check_all_nets(ieee); |
| 2736 | |
| 2737 | /* ensure no-one start an associating process (thus setting |
| 2738 | * the ieee->state to rtllib_ASSOCIATING) while we |
Justin P. Mattock | cd01712 | 2012-04-23 07:36:52 -0700 | [diff] [blame] | 2739 | * have just checked it and we are going to enable scan. |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2740 | * The rtllib_new_net function is always called with |
| 2741 | * lock held (from both rtllib_softmac_check_all_nets and |
| 2742 | * the rx path), so we cannot be in the middle of such function |
| 2743 | */ |
| 2744 | spin_lock_irqsave(&ieee->lock, flags); |
| 2745 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2746 | if (ieee->state == RTLLIB_NOLINK) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2747 | rtllib_start_scan(ieee); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2748 | spin_unlock_irqrestore(&ieee->lock, flags); |
| 2749 | } |
| 2750 | |
Larry Finger | ec0dc6be | 2011-08-25 14:07:04 -0500 | [diff] [blame] | 2751 | static void rtllib_link_change_wq(void *data) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2752 | { |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2753 | struct rtllib_device *ieee = container_of_dwork_rsl(data, |
| 2754 | struct rtllib_device, link_change_wq); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2755 | ieee->link_change(ieee->dev); |
| 2756 | } |
| 2757 | /* called only in userspace context */ |
| 2758 | void rtllib_disassociate(struct rtllib_device *ieee) |
| 2759 | { |
| 2760 | netif_carrier_off(ieee->dev); |
| 2761 | if (ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE) |
Mateusz Kulikowski | fc00af0 | 2015-09-20 21:04:26 +0200 | [diff] [blame] | 2762 | rtllib_reset_queue(ieee); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2763 | |
| 2764 | if (ieee->data_hard_stop) |
Mateusz Kulikowski | fc00af0 | 2015-09-20 21:04:26 +0200 | [diff] [blame] | 2765 | ieee->data_hard_stop(ieee->dev); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2766 | if (IS_DOT11D_ENABLE(ieee)) |
| 2767 | Dot11d_Reset(ieee); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2768 | ieee->state = RTLLIB_NOLINK; |
| 2769 | ieee->is_set_key = false; |
| 2770 | ieee->wap_set = 0; |
| 2771 | |
Amitoj Kaur Chawla | 354605f | 2016-02-20 15:36:26 +0530 | [diff] [blame] | 2772 | schedule_delayed_work(&ieee->link_change_wq, 0); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2773 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2774 | notify_wx_assoc_event(ieee); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2775 | } |
| 2776 | |
Larry Finger | ec0dc6be | 2011-08-25 14:07:04 -0500 | [diff] [blame] | 2777 | static void rtllib_associate_retry_wq(void *data) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2778 | { |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2779 | struct rtllib_device *ieee = container_of_dwork_rsl(data, |
| 2780 | struct rtllib_device, associate_retry_wq); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2781 | unsigned long flags; |
| 2782 | |
Binoy Jayan | 9afa937 | 2016-06-01 14:56:52 +0530 | [diff] [blame] | 2783 | mutex_lock(&ieee->wx_mutex); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2784 | if (!ieee->proto_started) |
| 2785 | goto exit; |
| 2786 | |
| 2787 | if (ieee->state != RTLLIB_ASSOCIATING_RETRY) |
| 2788 | goto exit; |
| 2789 | |
| 2790 | /* until we do not set the state to RTLLIB_NOLINK |
Mateusz Kulikowski | 14b40d9 | 2015-04-01 00:24:37 +0200 | [diff] [blame] | 2791 | * there are no possibility to have someone else trying |
| 2792 | * to start an association procedure (we get here with |
| 2793 | * ieee->state = RTLLIB_ASSOCIATING). |
| 2794 | * When we set the state to RTLLIB_NOLINK it is possible |
| 2795 | * that the RX path run an attempt to associate, but |
| 2796 | * both rtllib_softmac_check_all_nets and the |
| 2797 | * RX path works with ieee->lock held so there are no |
| 2798 | * problems. If we are still disassociated then start a scan. |
| 2799 | * the lock here is necessary to ensure no one try to start |
| 2800 | * an association procedure when we have just checked the |
| 2801 | * state and we are going to start the scan. |
| 2802 | */ |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2803 | ieee->beinretry = true; |
| 2804 | ieee->state = RTLLIB_NOLINK; |
| 2805 | |
| 2806 | rtllib_softmac_check_all_nets(ieee); |
| 2807 | |
| 2808 | spin_lock_irqsave(&ieee->lock, flags); |
| 2809 | |
| 2810 | if (ieee->state == RTLLIB_NOLINK) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2811 | rtllib_start_scan(ieee); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2812 | spin_unlock_irqrestore(&ieee->lock, flags); |
| 2813 | |
| 2814 | ieee->beinretry = false; |
| 2815 | exit: |
Binoy Jayan | 9afa937 | 2016-06-01 14:56:52 +0530 | [diff] [blame] | 2816 | mutex_unlock(&ieee->wx_mutex); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2817 | } |
| 2818 | |
Mateusz Kulikowski | 6957248 | 2015-07-14 22:04:26 +0200 | [diff] [blame] | 2819 | static struct sk_buff *rtllib_get_beacon_(struct rtllib_device *ieee) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2820 | { |
Mateusz Kulikowski | 06c1110 | 2015-05-31 20:19:21 +0200 | [diff] [blame] | 2821 | const u8 broadcast_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2822 | |
| 2823 | struct sk_buff *skb; |
| 2824 | struct rtllib_probe_response *b; |
Matthew Casey | 3a6b70c | 2014-08-22 06:27:52 -0400 | [diff] [blame] | 2825 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2826 | skb = rtllib_probe_resp(ieee, broadcast_addr); |
| 2827 | |
| 2828 | if (!skb) |
| 2829 | return NULL; |
| 2830 | |
| 2831 | b = (struct rtllib_probe_response *) skb->data; |
| 2832 | b->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_BEACON); |
| 2833 | |
| 2834 | return skb; |
| 2835 | |
| 2836 | } |
| 2837 | |
| 2838 | struct sk_buff *rtllib_get_beacon(struct rtllib_device *ieee) |
| 2839 | { |
| 2840 | struct sk_buff *skb; |
| 2841 | struct rtllib_probe_response *b; |
| 2842 | |
| 2843 | skb = rtllib_get_beacon_(ieee); |
| 2844 | if (!skb) |
| 2845 | return NULL; |
| 2846 | |
| 2847 | b = (struct rtllib_probe_response *) skb->data; |
| 2848 | b->header.seq_ctl = cpu_to_le16(ieee->seq_ctrl[0] << 4); |
| 2849 | |
| 2850 | if (ieee->seq_ctrl[0] == 0xFFF) |
| 2851 | ieee->seq_ctrl[0] = 0; |
| 2852 | else |
| 2853 | ieee->seq_ctrl[0]++; |
| 2854 | |
| 2855 | return skb; |
| 2856 | } |
Sean MacLennan | 3b28499 | 2011-11-28 20:20:26 -0500 | [diff] [blame] | 2857 | EXPORT_SYMBOL(rtllib_get_beacon); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2858 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2859 | void rtllib_softmac_stop_protocol(struct rtllib_device *ieee, u8 mesh_flag, |
| 2860 | u8 shutdown) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2861 | { |
| 2862 | rtllib_stop_scan_syncro(ieee); |
Binoy Jayan | 9afa937 | 2016-06-01 14:56:52 +0530 | [diff] [blame] | 2863 | mutex_lock(&ieee->wx_mutex); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2864 | rtllib_stop_protocol(ieee, shutdown); |
Binoy Jayan | 9afa937 | 2016-06-01 14:56:52 +0530 | [diff] [blame] | 2865 | mutex_unlock(&ieee->wx_mutex); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2866 | } |
Sean MacLennan | 3b28499 | 2011-11-28 20:20:26 -0500 | [diff] [blame] | 2867 | EXPORT_SYMBOL(rtllib_softmac_stop_protocol); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2868 | |
| 2869 | |
| 2870 | void rtllib_stop_protocol(struct rtllib_device *ieee, u8 shutdown) |
| 2871 | { |
| 2872 | if (!ieee->proto_started) |
| 2873 | return; |
| 2874 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2875 | if (shutdown) { |
| 2876 | ieee->proto_started = 0; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2877 | ieee->proto_stoppping = 1; |
| 2878 | if (ieee->rtllib_ips_leave != NULL) |
| 2879 | ieee->rtllib_ips_leave(ieee->dev); |
| 2880 | } |
| 2881 | |
| 2882 | rtllib_stop_send_beacons(ieee); |
| 2883 | del_timer_sync(&ieee->associate_timer); |
Amitoj Kaur Chawla | 354605f | 2016-02-20 15:36:26 +0530 | [diff] [blame] | 2884 | cancel_delayed_work_sync(&ieee->associate_retry_wq); |
| 2885 | cancel_delayed_work_sync(&ieee->start_ibss_wq); |
| 2886 | cancel_delayed_work_sync(&ieee->link_change_wq); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2887 | rtllib_stop_scan(ieee); |
| 2888 | |
| 2889 | if (ieee->state <= RTLLIB_ASSOCIATING_AUTHENTICATED) |
| 2890 | ieee->state = RTLLIB_NOLINK; |
| 2891 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2892 | if (ieee->state == RTLLIB_LINKED) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2893 | if (ieee->iw_mode == IW_MODE_INFRA) |
Paul Gortmaker | acd442d | 2015-04-27 01:25:41 -0400 | [diff] [blame] | 2894 | SendDisassociation(ieee, 1, WLAN_REASON_DEAUTH_LEAVING); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2895 | rtllib_disassociate(ieee); |
| 2896 | } |
| 2897 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2898 | if (shutdown) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2899 | RemoveAllTS(ieee); |
| 2900 | ieee->proto_stoppping = 0; |
| 2901 | } |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2902 | kfree(ieee->assocreq_ies); |
| 2903 | ieee->assocreq_ies = NULL; |
| 2904 | ieee->assocreq_ies_len = 0; |
| 2905 | kfree(ieee->assocresp_ies); |
| 2906 | ieee->assocresp_ies = NULL; |
| 2907 | ieee->assocresp_ies_len = 0; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2908 | } |
| 2909 | |
| 2910 | void rtllib_softmac_start_protocol(struct rtllib_device *ieee, u8 mesh_flag) |
| 2911 | { |
Binoy Jayan | 9afa937 | 2016-06-01 14:56:52 +0530 | [diff] [blame] | 2912 | mutex_lock(&ieee->wx_mutex); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2913 | rtllib_start_protocol(ieee); |
Binoy Jayan | 9afa937 | 2016-06-01 14:56:52 +0530 | [diff] [blame] | 2914 | mutex_unlock(&ieee->wx_mutex); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2915 | } |
Sean MacLennan | 3b28499 | 2011-11-28 20:20:26 -0500 | [diff] [blame] | 2916 | EXPORT_SYMBOL(rtllib_softmac_start_protocol); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2917 | |
| 2918 | void rtllib_start_protocol(struct rtllib_device *ieee) |
| 2919 | { |
| 2920 | short ch = 0; |
| 2921 | int i = 0; |
| 2922 | |
| 2923 | rtllib_update_active_chan_map(ieee); |
| 2924 | |
| 2925 | if (ieee->proto_started) |
| 2926 | return; |
| 2927 | |
| 2928 | ieee->proto_started = 1; |
| 2929 | |
| 2930 | if (ieee->current_network.channel == 0) { |
| 2931 | do { |
| 2932 | ch++; |
| 2933 | if (ch > MAX_CHANNEL_NUMBER) |
| 2934 | return; /* no channel found */ |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2935 | } while (!ieee->active_channel_map[ch]); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2936 | ieee->current_network.channel = ch; |
| 2937 | } |
| 2938 | |
| 2939 | if (ieee->current_network.beacon_interval == 0) |
| 2940 | ieee->current_network.beacon_interval = 100; |
| 2941 | |
| 2942 | for (i = 0; i < 17; i++) { |
| 2943 | ieee->last_rxseq_num[i] = -1; |
| 2944 | ieee->last_rxfrag_num[i] = -1; |
| 2945 | ieee->last_packet_time[i] = 0; |
| 2946 | } |
| 2947 | |
| 2948 | if (ieee->UpdateBeaconInterruptHandler) |
| 2949 | ieee->UpdateBeaconInterruptHandler(ieee->dev, false); |
| 2950 | |
| 2951 | ieee->wmm_acm = 0; |
| 2952 | /* if the user set the MAC of the ad-hoc cell and then |
| 2953 | * switch to managed mode, shall we make sure that association |
| 2954 | * attempts does not fail just because the user provide the essid |
| 2955 | * and the nic is still checking for the AP MAC ?? |
| 2956 | */ |
| 2957 | if (ieee->iw_mode == IW_MODE_INFRA) { |
| 2958 | rtllib_start_bss(ieee); |
| 2959 | } else if (ieee->iw_mode == IW_MODE_ADHOC) { |
| 2960 | if (ieee->UpdateBeaconInterruptHandler) |
| 2961 | ieee->UpdateBeaconInterruptHandler(ieee->dev, true); |
| 2962 | |
| 2963 | rtllib_start_ibss(ieee); |
| 2964 | |
| 2965 | } else if (ieee->iw_mode == IW_MODE_MASTER) { |
| 2966 | rtllib_start_master_bss(ieee); |
| 2967 | } else if (ieee->iw_mode == IW_MODE_MONITOR) { |
| 2968 | rtllib_start_monitor_mode(ieee); |
| 2969 | } |
| 2970 | } |
| 2971 | |
| 2972 | void rtllib_softmac_init(struct rtllib_device *ieee) |
| 2973 | { |
| 2974 | int i; |
Matthew Casey | 3a6b70c | 2014-08-22 06:27:52 -0400 | [diff] [blame] | 2975 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2976 | memset(&ieee->current_network, 0, sizeof(struct rtllib_network)); |
| 2977 | |
| 2978 | ieee->state = RTLLIB_NOLINK; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2979 | for (i = 0; i < 5; i++) |
| 2980 | ieee->seq_ctrl[i] = 0; |
Thomas Meyer | 929fa2a | 2011-11-10 19:04:19 +0100 | [diff] [blame] | 2981 | ieee->pDot11dInfo = kzalloc(sizeof(struct rt_dot11d_info), GFP_ATOMIC); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2982 | if (!ieee->pDot11dInfo) |
Mateusz Kulikowski | 11e672c | 2015-05-31 20:19:26 +0200 | [diff] [blame] | 2983 | netdev_err(ieee->dev, "Can't alloc memory for DOT11D\n"); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2984 | ieee->LinkDetectInfo.SlotIndex = 0; |
| 2985 | ieee->LinkDetectInfo.SlotNum = 2; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 2986 | ieee->LinkDetectInfo.NumRecvBcnInPeriod = 0; |
| 2987 | ieee->LinkDetectInfo.NumRecvDataInPeriod = 0; |
| 2988 | ieee->LinkDetectInfo.NumTxOkInPeriod = 0; |
| 2989 | ieee->LinkDetectInfo.NumRxOkInPeriod = 0; |
| 2990 | ieee->LinkDetectInfo.NumRxUnicastOkInPeriod = 0; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 2991 | ieee->bIsAggregateFrame = false; |
| 2992 | ieee->assoc_id = 0; |
| 2993 | ieee->queue_stop = 0; |
| 2994 | ieee->scanning_continue = 0; |
| 2995 | ieee->softmac_features = 0; |
| 2996 | ieee->wap_set = 0; |
| 2997 | ieee->ssid_set = 0; |
| 2998 | ieee->proto_started = 0; |
| 2999 | ieee->proto_stoppping = 0; |
| 3000 | ieee->basic_rate = RTLLIB_DEFAULT_BASIC_RATE; |
| 3001 | ieee->rate = 22; |
| 3002 | ieee->ps = RTLLIB_PS_DISABLED; |
| 3003 | ieee->sta_sleep = LPS_IS_WAKE; |
| 3004 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 3005 | ieee->Regdot11HTOperationalRateSet[0] = 0xff; |
| 3006 | ieee->Regdot11HTOperationalRateSet[1] = 0xff; |
| 3007 | ieee->Regdot11HTOperationalRateSet[4] = 0x01; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3008 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 3009 | ieee->Regdot11TxHTOperationalRateSet[0] = 0xff; |
| 3010 | ieee->Regdot11TxHTOperationalRateSet[1] = 0xff; |
| 3011 | ieee->Regdot11TxHTOperationalRateSet[4] = 0x01; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3012 | |
| 3013 | ieee->FirstIe_InScan = false; |
| 3014 | ieee->actscanning = false; |
| 3015 | ieee->beinretry = false; |
| 3016 | ieee->is_set_key = false; |
| 3017 | init_mgmt_queue(ieee); |
| 3018 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3019 | ieee->tx_pending.txb = NULL; |
| 3020 | |
Gnanachandran Dhanapal | 2e59e40 | 2015-06-16 07:25:48 +0000 | [diff] [blame] | 3021 | setup_timer(&ieee->associate_timer, |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3022 | rtllib_associate_abort_cb, |
| 3023 | (unsigned long) ieee); |
| 3024 | |
Gnanachandran Dhanapal | 2e59e40 | 2015-06-16 07:25:48 +0000 | [diff] [blame] | 3025 | setup_timer(&ieee->beacon_timer, |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3026 | rtllib_send_beacon_cb, |
| 3027 | (unsigned long) ieee); |
| 3028 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 3029 | INIT_DELAYED_WORK_RSL(&ieee->link_change_wq, |
| 3030 | (void *)rtllib_link_change_wq, ieee); |
| 3031 | INIT_DELAYED_WORK_RSL(&ieee->start_ibss_wq, |
| 3032 | (void *)rtllib_start_ibss_wq, ieee); |
| 3033 | INIT_WORK_RSL(&ieee->associate_complete_wq, |
| 3034 | (void *)rtllib_associate_complete_wq, ieee); |
| 3035 | INIT_DELAYED_WORK_RSL(&ieee->associate_procedure_wq, |
| 3036 | (void *)rtllib_associate_procedure_wq, ieee); |
| 3037 | INIT_DELAYED_WORK_RSL(&ieee->softmac_scan_wq, |
| 3038 | (void *)rtllib_softmac_scan_wq, ieee); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 3039 | INIT_DELAYED_WORK_RSL(&ieee->associate_retry_wq, |
| 3040 | (void *)rtllib_associate_retry_wq, ieee); |
| 3041 | INIT_WORK_RSL(&ieee->wx_sync_scan_wq, (void *)rtllib_wx_sync_scan_wq, |
| 3042 | ieee); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3043 | |
Binoy Jayan | 9afa937 | 2016-06-01 14:56:52 +0530 | [diff] [blame] | 3044 | mutex_init(&ieee->wx_mutex); |
Binoy Jayan | be10cee | 2016-06-01 14:56:55 +0530 | [diff] [blame] | 3045 | mutex_init(&ieee->scan_mutex); |
Binoy Jayan | 38bee76 | 2016-06-01 14:56:56 +0530 | [diff] [blame] | 3046 | mutex_init(&ieee->ips_mutex); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3047 | |
| 3048 | spin_lock_init(&ieee->mgmt_tx_lock); |
| 3049 | spin_lock_init(&ieee->beacon_lock); |
| 3050 | |
| 3051 | tasklet_init(&ieee->ps_task, |
| 3052 | (void(*)(unsigned long)) rtllib_sta_ps, |
| 3053 | (unsigned long)ieee); |
| 3054 | |
| 3055 | } |
| 3056 | |
| 3057 | void rtllib_softmac_free(struct rtllib_device *ieee) |
| 3058 | { |
Binoy Jayan | 9afa937 | 2016-06-01 14:56:52 +0530 | [diff] [blame] | 3059 | mutex_lock(&ieee->wx_mutex); |
Larry Finger | d7613e5 | 2011-09-01 12:23:21 -0500 | [diff] [blame] | 3060 | kfree(ieee->pDot11dInfo); |
| 3061 | ieee->pDot11dInfo = NULL; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3062 | del_timer_sync(&ieee->associate_timer); |
| 3063 | |
Amitoj Kaur Chawla | 354605f | 2016-02-20 15:36:26 +0530 | [diff] [blame] | 3064 | cancel_delayed_work_sync(&ieee->associate_retry_wq); |
| 3065 | cancel_delayed_work_sync(&ieee->associate_procedure_wq); |
| 3066 | cancel_delayed_work_sync(&ieee->softmac_scan_wq); |
| 3067 | cancel_delayed_work_sync(&ieee->start_ibss_wq); |
| 3068 | cancel_delayed_work_sync(&ieee->hw_wakeup_wq); |
| 3069 | cancel_delayed_work_sync(&ieee->hw_sleep_wq); |
| 3070 | cancel_delayed_work_sync(&ieee->link_change_wq); |
| 3071 | cancel_work_sync(&ieee->associate_complete_wq); |
| 3072 | cancel_work_sync(&ieee->ips_leave_wq); |
| 3073 | cancel_work_sync(&ieee->wx_sync_scan_wq); |
Binoy Jayan | 9afa937 | 2016-06-01 14:56:52 +0530 | [diff] [blame] | 3074 | mutex_unlock(&ieee->wx_mutex); |
Devendra Naga | 876e20d | 2014-11-23 22:12:20 -0500 | [diff] [blame] | 3075 | tasklet_kill(&ieee->ps_task); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3076 | } |
| 3077 | |
| 3078 | /******************************************************** |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 3079 | * Start of WPA code. * |
| 3080 | * this is stolen from the ipw2200 driver * |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3081 | ********************************************************/ |
| 3082 | |
| 3083 | |
| 3084 | static int rtllib_wpa_enable(struct rtllib_device *ieee, int value) |
| 3085 | { |
| 3086 | /* This is called when wpa_supplicant loads and closes the driver |
Mateusz Kulikowski | 14b40d9 | 2015-04-01 00:24:37 +0200 | [diff] [blame] | 3087 | * interface. |
| 3088 | */ |
Mateusz Kulikowski | d69d205 | 2015-03-17 00:00:52 +0100 | [diff] [blame] | 3089 | netdev_info(ieee->dev, "%s WPA\n", value ? "enabling" : "disabling"); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3090 | ieee->wpa_enabled = value; |
Vaishali Thakkar | 3e3148c | 2015-06-26 09:37:25 +0530 | [diff] [blame] | 3091 | eth_zero_addr(ieee->ap_mac_addr); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3092 | return 0; |
| 3093 | } |
| 3094 | |
| 3095 | |
Larry Finger | ec0dc6be | 2011-08-25 14:07:04 -0500 | [diff] [blame] | 3096 | static void rtllib_wpa_assoc_frame(struct rtllib_device *ieee, char *wpa_ie, |
| 3097 | int wpa_ie_len) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3098 | { |
| 3099 | /* make sure WPA is enabled */ |
| 3100 | rtllib_wpa_enable(ieee, 1); |
| 3101 | |
| 3102 | rtllib_disassociate(ieee); |
| 3103 | } |
| 3104 | |
| 3105 | |
| 3106 | static int rtllib_wpa_mlme(struct rtllib_device *ieee, int command, int reason) |
| 3107 | { |
| 3108 | |
| 3109 | int ret = 0; |
| 3110 | |
| 3111 | switch (command) { |
| 3112 | case IEEE_MLME_STA_DEAUTH: |
| 3113 | break; |
| 3114 | |
| 3115 | case IEEE_MLME_STA_DISASSOC: |
| 3116 | rtllib_disassociate(ieee); |
| 3117 | break; |
| 3118 | |
| 3119 | default: |
Mateusz Kulikowski | d69d205 | 2015-03-17 00:00:52 +0100 | [diff] [blame] | 3120 | netdev_info(ieee->dev, "Unknown MLME request: %d\n", command); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3121 | ret = -EOPNOTSUPP; |
| 3122 | } |
| 3123 | |
| 3124 | return ret; |
| 3125 | } |
| 3126 | |
| 3127 | |
| 3128 | static int rtllib_wpa_set_wpa_ie(struct rtllib_device *ieee, |
| 3129 | struct ieee_param *param, int plen) |
| 3130 | { |
| 3131 | u8 *buf; |
| 3132 | |
| 3133 | if (param->u.wpa_ie.len > MAX_WPA_IE_LEN || |
| 3134 | (param->u.wpa_ie.len && param->u.wpa_ie.data == NULL)) |
| 3135 | return -EINVAL; |
| 3136 | |
| 3137 | if (param->u.wpa_ie.len) { |
Thomas Meyer | d931753 | 2011-11-08 20:37:03 +0100 | [diff] [blame] | 3138 | buf = kmemdup(param->u.wpa_ie.data, param->u.wpa_ie.len, |
| 3139 | GFP_KERNEL); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3140 | if (buf == NULL) |
| 3141 | return -ENOMEM; |
| 3142 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3143 | kfree(ieee->wpa_ie); |
| 3144 | ieee->wpa_ie = buf; |
| 3145 | ieee->wpa_ie_len = param->u.wpa_ie.len; |
| 3146 | } else { |
| 3147 | kfree(ieee->wpa_ie); |
| 3148 | ieee->wpa_ie = NULL; |
| 3149 | ieee->wpa_ie_len = 0; |
| 3150 | } |
| 3151 | |
| 3152 | rtllib_wpa_assoc_frame(ieee, ieee->wpa_ie, ieee->wpa_ie_len); |
| 3153 | return 0; |
| 3154 | } |
| 3155 | |
| 3156 | #define AUTH_ALG_OPEN_SYSTEM 0x1 |
| 3157 | #define AUTH_ALG_SHARED_KEY 0x2 |
| 3158 | #define AUTH_ALG_LEAP 0x4 |
| 3159 | static int rtllib_wpa_set_auth_algs(struct rtllib_device *ieee, int value) |
| 3160 | { |
| 3161 | |
| 3162 | struct rtllib_security sec = { |
| 3163 | .flags = SEC_AUTH_MODE, |
| 3164 | }; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3165 | |
| 3166 | if (value & AUTH_ALG_SHARED_KEY) { |
| 3167 | sec.auth_mode = WLAN_AUTH_SHARED_KEY; |
| 3168 | ieee->open_wep = 0; |
| 3169 | ieee->auth_mode = 1; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 3170 | } else if (value & AUTH_ALG_OPEN_SYSTEM) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3171 | sec.auth_mode = WLAN_AUTH_OPEN; |
| 3172 | ieee->open_wep = 1; |
| 3173 | ieee->auth_mode = 0; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 3174 | } else if (value & AUTH_ALG_LEAP) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3175 | sec.auth_mode = WLAN_AUTH_LEAP >> 6; |
| 3176 | ieee->open_wep = 1; |
| 3177 | ieee->auth_mode = 2; |
| 3178 | } |
| 3179 | |
| 3180 | |
| 3181 | if (ieee->set_security) |
| 3182 | ieee->set_security(ieee->dev, &sec); |
| 3183 | |
Peter Senna Tschudin | 4764ca9 | 2014-05-26 16:08:50 +0200 | [diff] [blame] | 3184 | return 0; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3185 | } |
| 3186 | |
| 3187 | static int rtllib_wpa_set_param(struct rtllib_device *ieee, u8 name, u32 value) |
| 3188 | { |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 3189 | int ret = 0; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3190 | unsigned long flags; |
| 3191 | |
| 3192 | switch (name) { |
| 3193 | case IEEE_PARAM_WPA_ENABLED: |
| 3194 | ret = rtllib_wpa_enable(ieee, value); |
| 3195 | break; |
| 3196 | |
| 3197 | case IEEE_PARAM_TKIP_COUNTERMEASURES: |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 3198 | ieee->tkip_countermeasures = value; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3199 | break; |
| 3200 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 3201 | case IEEE_PARAM_DROP_UNENCRYPTED: |
| 3202 | { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3203 | /* HACK: |
| 3204 | * |
| 3205 | * wpa_supplicant calls set_wpa_enabled when the driver |
| 3206 | * is loaded and unloaded, regardless of if WPA is being |
| 3207 | * used. No other calls are made which can be used to |
| 3208 | * determine if encryption will be used or not prior to |
| 3209 | * association being expected. If encryption is not being |
| 3210 | * used, drop_unencrypted is set to false, else true -- we |
| 3211 | * can use this to determine if the CAP_PRIVACY_ON bit should |
| 3212 | * be set. |
| 3213 | */ |
| 3214 | struct rtllib_security sec = { |
| 3215 | .flags = SEC_ENABLED, |
| 3216 | .enabled = value, |
| 3217 | }; |
| 3218 | ieee->drop_unencrypted = value; |
| 3219 | /* We only change SEC_LEVEL for open mode. Others |
| 3220 | * are set by ipw_wpa_set_encryption. |
| 3221 | */ |
| 3222 | if (!value) { |
| 3223 | sec.flags |= SEC_LEVEL; |
| 3224 | sec.level = SEC_LEVEL_0; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 3225 | } else { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3226 | sec.flags |= SEC_LEVEL; |
| 3227 | sec.level = SEC_LEVEL_1; |
| 3228 | } |
| 3229 | if (ieee->set_security) |
| 3230 | ieee->set_security(ieee->dev, &sec); |
| 3231 | break; |
| 3232 | } |
| 3233 | |
| 3234 | case IEEE_PARAM_PRIVACY_INVOKED: |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 3235 | ieee->privacy_invoked = value; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3236 | break; |
| 3237 | |
| 3238 | case IEEE_PARAM_AUTH_ALGS: |
| 3239 | ret = rtllib_wpa_set_auth_algs(ieee, value); |
| 3240 | break; |
| 3241 | |
| 3242 | case IEEE_PARAM_IEEE_802_1X: |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 3243 | ieee->ieee802_1x = value; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3244 | break; |
| 3245 | case IEEE_PARAM_WPAX_SELECT: |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 3246 | spin_lock_irqsave(&ieee->wpax_suitlist_lock, flags); |
| 3247 | spin_unlock_irqrestore(&ieee->wpax_suitlist_lock, flags); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3248 | break; |
| 3249 | |
| 3250 | default: |
Mateusz Kulikowski | d69d205 | 2015-03-17 00:00:52 +0100 | [diff] [blame] | 3251 | netdev_info(ieee->dev, "Unknown WPA param: %d\n", name); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3252 | ret = -EOPNOTSUPP; |
| 3253 | } |
| 3254 | |
| 3255 | return ret; |
| 3256 | } |
| 3257 | |
| 3258 | /* implementation borrowed from hostap driver */ |
| 3259 | static int rtllib_wpa_set_encryption(struct rtllib_device *ieee, |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 3260 | struct ieee_param *param, int param_len, |
| 3261 | u8 is_mesh) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3262 | { |
| 3263 | int ret = 0; |
Sean MacLennan | 32c44cb | 2011-12-19 23:20:41 -0500 | [diff] [blame] | 3264 | struct lib80211_crypto_ops *ops; |
| 3265 | struct lib80211_crypt_data **crypt; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3266 | |
| 3267 | struct rtllib_security sec = { |
| 3268 | .flags = 0, |
| 3269 | }; |
| 3270 | |
| 3271 | param->u.crypt.err = 0; |
| 3272 | param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0'; |
| 3273 | |
| 3274 | if (param_len != |
| 3275 | (int) ((char *) param->u.crypt.key - (char *) param) + |
| 3276 | param->u.crypt.key_len) { |
Mateusz Kulikowski | d69d205 | 2015-03-17 00:00:52 +0100 | [diff] [blame] | 3277 | netdev_info(ieee->dev, "Len mismatch %d, %d\n", param_len, |
| 3278 | param->u.crypt.key_len); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3279 | return -EINVAL; |
| 3280 | } |
Wei Yongjun | 0c43e56 | 2012-08-26 09:04:23 +0800 | [diff] [blame] | 3281 | if (is_broadcast_ether_addr(param->sta_addr)) { |
Sean MacLennan | 184f193 | 2011-12-19 23:19:23 -0500 | [diff] [blame] | 3282 | if (param->u.crypt.idx >= NUM_WEP_KEYS) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3283 | return -EINVAL; |
Sean MacLennan | 0ddcf5f | 2011-12-19 23:21:41 -0500 | [diff] [blame] | 3284 | crypt = &ieee->crypt_info.crypt[param->u.crypt.idx]; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3285 | } else { |
| 3286 | return -EINVAL; |
| 3287 | } |
| 3288 | |
| 3289 | if (strcmp(param->u.crypt.alg, "none") == 0) { |
| 3290 | if (crypt) { |
| 3291 | sec.enabled = 0; |
| 3292 | sec.level = SEC_LEVEL_0; |
| 3293 | sec.flags |= SEC_ENABLED | SEC_LEVEL; |
Sean MacLennan | 3b148be | 2011-12-19 23:23:08 -0500 | [diff] [blame] | 3294 | lib80211_crypt_delayed_deinit(&ieee->crypt_info, crypt); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3295 | } |
| 3296 | goto done; |
| 3297 | } |
| 3298 | sec.enabled = 1; |
| 3299 | sec.flags |= SEC_ENABLED; |
| 3300 | |
| 3301 | /* IPW HW cannot build TKIP MIC, host decryption still needed. */ |
| 3302 | if (!(ieee->host_encrypt || ieee->host_decrypt) && |
Sean MacLennan | 3b148be | 2011-12-19 23:23:08 -0500 | [diff] [blame] | 3303 | strcmp(param->u.crypt.alg, "R-TKIP")) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3304 | goto skip_host_crypt; |
| 3305 | |
Sean MacLennan | 3b148be | 2011-12-19 23:23:08 -0500 | [diff] [blame] | 3306 | ops = lib80211_get_crypto_ops(param->u.crypt.alg); |
| 3307 | if (ops == NULL && strcmp(param->u.crypt.alg, "R-WEP") == 0) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3308 | request_module("rtllib_crypt_wep"); |
Sean MacLennan | 3b148be | 2011-12-19 23:23:08 -0500 | [diff] [blame] | 3309 | ops = lib80211_get_crypto_ops(param->u.crypt.alg); |
| 3310 | } else if (ops == NULL && strcmp(param->u.crypt.alg, "R-TKIP") == 0) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3311 | request_module("rtllib_crypt_tkip"); |
Sean MacLennan | 3b148be | 2011-12-19 23:23:08 -0500 | [diff] [blame] | 3312 | ops = lib80211_get_crypto_ops(param->u.crypt.alg); |
| 3313 | } else if (ops == NULL && strcmp(param->u.crypt.alg, "R-CCMP") == 0) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3314 | request_module("rtllib_crypt_ccmp"); |
Sean MacLennan | 3b148be | 2011-12-19 23:23:08 -0500 | [diff] [blame] | 3315 | ops = lib80211_get_crypto_ops(param->u.crypt.alg); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3316 | } |
| 3317 | if (ops == NULL) { |
Mateusz Kulikowski | d69d205 | 2015-03-17 00:00:52 +0100 | [diff] [blame] | 3318 | netdev_info(ieee->dev, "unknown crypto alg '%s'\n", |
| 3319 | param->u.crypt.alg); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3320 | param->u.crypt.err = IEEE_CRYPT_ERR_UNKNOWN_ALG; |
| 3321 | ret = -EINVAL; |
| 3322 | goto done; |
| 3323 | } |
| 3324 | if (*crypt == NULL || (*crypt)->ops != ops) { |
Sean MacLennan | 32c44cb | 2011-12-19 23:20:41 -0500 | [diff] [blame] | 3325 | struct lib80211_crypt_data *new_crypt; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3326 | |
Sean MacLennan | 3b148be | 2011-12-19 23:23:08 -0500 | [diff] [blame] | 3327 | lib80211_crypt_delayed_deinit(&ieee->crypt_info, crypt); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3328 | |
Navya Sri Nizamkari | d272f9d | 2015-03-10 17:58:07 +0530 | [diff] [blame] | 3329 | new_crypt = kzalloc(sizeof(*new_crypt), GFP_KERNEL); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3330 | if (new_crypt == NULL) { |
| 3331 | ret = -ENOMEM; |
| 3332 | goto done; |
| 3333 | } |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3334 | new_crypt->ops = ops; |
Sean MacLennan | 0bd3553 | 2015-11-15 19:51:43 -0500 | [diff] [blame] | 3335 | if (new_crypt->ops && try_module_get(new_crypt->ops->owner)) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3336 | new_crypt->priv = |
| 3337 | new_crypt->ops->init(param->u.crypt.idx); |
| 3338 | |
| 3339 | if (new_crypt->priv == NULL) { |
| 3340 | kfree(new_crypt); |
| 3341 | param->u.crypt.err = IEEE_CRYPT_ERR_CRYPT_INIT_FAILED; |
| 3342 | ret = -EINVAL; |
| 3343 | goto done; |
| 3344 | } |
| 3345 | |
| 3346 | *crypt = new_crypt; |
| 3347 | } |
| 3348 | |
| 3349 | if (param->u.crypt.key_len > 0 && (*crypt)->ops->set_key && |
| 3350 | (*crypt)->ops->set_key(param->u.crypt.key, |
| 3351 | param->u.crypt.key_len, param->u.crypt.seq, |
| 3352 | (*crypt)->priv) < 0) { |
Mateusz Kulikowski | d69d205 | 2015-03-17 00:00:52 +0100 | [diff] [blame] | 3353 | netdev_info(ieee->dev, "key setting failed\n"); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3354 | param->u.crypt.err = IEEE_CRYPT_ERR_KEY_SET_FAILED; |
| 3355 | ret = -EINVAL; |
| 3356 | goto done; |
| 3357 | } |
| 3358 | |
| 3359 | skip_host_crypt: |
| 3360 | if (param->u.crypt.set_tx) { |
Sean MacLennan | 0ddcf5f | 2011-12-19 23:21:41 -0500 | [diff] [blame] | 3361 | ieee->crypt_info.tx_keyidx = param->u.crypt.idx; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3362 | sec.active_key = param->u.crypt.idx; |
| 3363 | sec.flags |= SEC_ACTIVE_KEY; |
| 3364 | } else |
| 3365 | sec.flags &= ~SEC_ACTIVE_KEY; |
| 3366 | |
| 3367 | if (param->u.crypt.alg != NULL) { |
| 3368 | memcpy(sec.keys[param->u.crypt.idx], |
| 3369 | param->u.crypt.key, |
| 3370 | param->u.crypt.key_len); |
| 3371 | sec.key_sizes[param->u.crypt.idx] = param->u.crypt.key_len; |
| 3372 | sec.flags |= (1 << param->u.crypt.idx); |
| 3373 | |
Sean MacLennan | 3b148be | 2011-12-19 23:23:08 -0500 | [diff] [blame] | 3374 | if (strcmp(param->u.crypt.alg, "R-WEP") == 0) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3375 | sec.flags |= SEC_LEVEL; |
| 3376 | sec.level = SEC_LEVEL_1; |
Sean MacLennan | 3b148be | 2011-12-19 23:23:08 -0500 | [diff] [blame] | 3377 | } else if (strcmp(param->u.crypt.alg, "R-TKIP") == 0) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3378 | sec.flags |= SEC_LEVEL; |
| 3379 | sec.level = SEC_LEVEL_2; |
Sean MacLennan | 3b148be | 2011-12-19 23:23:08 -0500 | [diff] [blame] | 3380 | } else if (strcmp(param->u.crypt.alg, "R-CCMP") == 0) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3381 | sec.flags |= SEC_LEVEL; |
| 3382 | sec.level = SEC_LEVEL_3; |
| 3383 | } |
| 3384 | } |
| 3385 | done: |
| 3386 | if (ieee->set_security) |
| 3387 | ieee->set_security(ieee->dev, &sec); |
| 3388 | |
| 3389 | /* Do not reset port if card is in Managed mode since resetting will |
| 3390 | * generate new IEEE 802.11 authentication which may end up in looping |
| 3391 | * with IEEE 802.1X. If your hardware requires a reset after WEP |
| 3392 | * configuration (for example... Prism2), implement the reset_port in |
Mateusz Kulikowski | 14b40d9 | 2015-04-01 00:24:37 +0200 | [diff] [blame] | 3393 | * the callbacks structures used to initialize the 802.11 stack. |
| 3394 | */ |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3395 | if (ieee->reset_on_keychange && |
| 3396 | ieee->iw_mode != IW_MODE_INFRA && |
| 3397 | ieee->reset_port && |
| 3398 | ieee->reset_port(ieee->dev)) { |
Mateusz Kulikowski | d69d205 | 2015-03-17 00:00:52 +0100 | [diff] [blame] | 3399 | netdev_info(ieee->dev, "reset_port failed\n"); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3400 | param->u.crypt.err = IEEE_CRYPT_ERR_CARD_CONF_FAILED; |
| 3401 | return -EINVAL; |
| 3402 | } |
| 3403 | |
| 3404 | return ret; |
| 3405 | } |
| 3406 | |
Baoyou Xie | ec65ef8 | 2016-09-04 14:33:35 +0800 | [diff] [blame] | 3407 | static inline struct sk_buff * |
| 3408 | rtllib_disauth_skb(struct rtllib_network *beacon, |
| 3409 | struct rtllib_device *ieee, u16 asRsn) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3410 | { |
| 3411 | struct sk_buff *skb; |
| 3412 | struct rtllib_disauth *disauth; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3413 | int len = sizeof(struct rtllib_disauth) + ieee->tx_headroom; |
| 3414 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3415 | skb = dev_alloc_skb(len); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 3416 | if (!skb) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3417 | return NULL; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3418 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3419 | skb_reserve(skb, ieee->tx_headroom); |
| 3420 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 3421 | disauth = (struct rtllib_disauth *) skb_put(skb, |
| 3422 | sizeof(struct rtllib_disauth)); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3423 | disauth->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_DEAUTH); |
| 3424 | disauth->header.duration_id = 0; |
| 3425 | |
Mateusz Kulikowski | b57ceb1 | 2015-05-31 20:19:22 +0200 | [diff] [blame] | 3426 | ether_addr_copy(disauth->header.addr1, beacon->bssid); |
| 3427 | ether_addr_copy(disauth->header.addr2, ieee->dev->dev_addr); |
| 3428 | ether_addr_copy(disauth->header.addr3, beacon->bssid); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3429 | |
| 3430 | disauth->reason = cpu_to_le16(asRsn); |
| 3431 | return skb; |
| 3432 | } |
| 3433 | |
Baoyou Xie | ec65ef8 | 2016-09-04 14:33:35 +0800 | [diff] [blame] | 3434 | static inline struct sk_buff * |
| 3435 | rtllib_disassociate_skb(struct rtllib_network *beacon, |
| 3436 | struct rtllib_device *ieee, u16 asRsn) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3437 | { |
| 3438 | struct sk_buff *skb; |
| 3439 | struct rtllib_disassoc *disass; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3440 | int len = sizeof(struct rtllib_disassoc) + ieee->tx_headroom; |
Matthew Casey | 3a6b70c | 2014-08-22 06:27:52 -0400 | [diff] [blame] | 3441 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3442 | skb = dev_alloc_skb(len); |
| 3443 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 3444 | if (!skb) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3445 | return NULL; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3446 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3447 | skb_reserve(skb, ieee->tx_headroom); |
| 3448 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 3449 | disass = (struct rtllib_disassoc *) skb_put(skb, |
| 3450 | sizeof(struct rtllib_disassoc)); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3451 | disass->header.frame_ctl = cpu_to_le16(RTLLIB_STYPE_DISASSOC); |
| 3452 | disass->header.duration_id = 0; |
| 3453 | |
Mateusz Kulikowski | b57ceb1 | 2015-05-31 20:19:22 +0200 | [diff] [blame] | 3454 | ether_addr_copy(disass->header.addr1, beacon->bssid); |
| 3455 | ether_addr_copy(disass->header.addr2, ieee->dev->dev_addr); |
| 3456 | ether_addr_copy(disass->header.addr3, beacon->bssid); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3457 | |
| 3458 | disass->reason = cpu_to_le16(asRsn); |
| 3459 | return skb; |
| 3460 | } |
| 3461 | |
| 3462 | void SendDisassociation(struct rtllib_device *ieee, bool deauth, u16 asRsn) |
| 3463 | { |
| 3464 | struct rtllib_network *beacon = &ieee->current_network; |
| 3465 | struct sk_buff *skb; |
| 3466 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 3467 | if (deauth) |
| 3468 | skb = rtllib_disauth_skb(beacon, ieee, asRsn); |
| 3469 | else |
| 3470 | skb = rtllib_disassociate_skb(beacon, ieee, asRsn); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3471 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 3472 | if (skb) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3473 | softmac_mgmt_xmit(skb, ieee); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3474 | } |
| 3475 | |
| 3476 | u8 rtllib_ap_sec_type(struct rtllib_device *ieee) |
| 3477 | { |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 3478 | static u8 ccmp_ie[4] = {0x00, 0x50, 0xf2, 0x04}; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3479 | static u8 ccmp_rsn_ie[4] = {0x00, 0x0f, 0xac, 0x04}; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 3480 | int wpa_ie_len = ieee->wpa_ie_len; |
Sean MacLennan | 32c44cb | 2011-12-19 23:20:41 -0500 | [diff] [blame] | 3481 | struct lib80211_crypt_data *crypt; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3482 | int encrypt; |
| 3483 | |
Sean MacLennan | 0ddcf5f | 2011-12-19 23:21:41 -0500 | [diff] [blame] | 3484 | crypt = ieee->crypt_info.crypt[ieee->crypt_info.tx_keyidx]; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 3485 | encrypt = (ieee->current_network.capability & WLAN_CAPABILITY_PRIVACY) |
| 3486 | || (ieee->host_encrypt && crypt && crypt->ops && |
Mateusz Kulikowski | 4c29207 | 2015-09-20 21:04:27 +0200 | [diff] [blame] | 3487 | (strcmp(crypt->ops->name, "R-WEP") == 0)); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3488 | |
| 3489 | /* simply judge */ |
| 3490 | if (encrypt && (wpa_ie_len == 0)) { |
| 3491 | return SEC_ALG_WEP; |
| 3492 | } else if ((wpa_ie_len != 0)) { |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 3493 | if (((ieee->wpa_ie[0] == 0xdd) && |
| 3494 | (!memcmp(&(ieee->wpa_ie[14]), ccmp_ie, 4))) || |
| 3495 | ((ieee->wpa_ie[0] == 0x30) && |
| 3496 | (!memcmp(&ieee->wpa_ie[10], ccmp_rsn_ie, 4)))) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3497 | return SEC_ALG_CCMP; |
| 3498 | else |
| 3499 | return SEC_ALG_TKIP; |
| 3500 | } else { |
| 3501 | return SEC_ALG_NONE; |
| 3502 | } |
| 3503 | } |
| 3504 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 3505 | int rtllib_wpa_supplicant_ioctl(struct rtllib_device *ieee, struct iw_point *p, |
| 3506 | u8 is_mesh) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3507 | { |
| 3508 | struct ieee_param *param; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 3509 | int ret = 0; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3510 | |
Binoy Jayan | 9afa937 | 2016-06-01 14:56:52 +0530 | [diff] [blame] | 3511 | mutex_lock(&ieee->wx_mutex); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3512 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 3513 | if (p->length < sizeof(struct ieee_param) || !p->pointer) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3514 | ret = -EINVAL; |
| 3515 | goto out; |
| 3516 | } |
| 3517 | |
Teodora Baluta | 2162498 | 2013-10-26 09:18:22 +0300 | [diff] [blame] | 3518 | param = memdup_user(p->pointer, p->length); |
| 3519 | if (IS_ERR(param)) { |
| 3520 | ret = PTR_ERR(param); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3521 | goto out; |
| 3522 | } |
| 3523 | |
| 3524 | switch (param->cmd) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3525 | case IEEE_CMD_SET_WPA_PARAM: |
| 3526 | ret = rtllib_wpa_set_param(ieee, param->u.wpa_param.name, |
| 3527 | param->u.wpa_param.value); |
| 3528 | break; |
| 3529 | |
| 3530 | case IEEE_CMD_SET_WPA_IE: |
| 3531 | ret = rtllib_wpa_set_wpa_ie(ieee, param, p->length); |
| 3532 | break; |
| 3533 | |
| 3534 | case IEEE_CMD_SET_ENCRYPTION: |
| 3535 | ret = rtllib_wpa_set_encryption(ieee, param, p->length, 0); |
| 3536 | break; |
| 3537 | |
| 3538 | case IEEE_CMD_MLME: |
| 3539 | ret = rtllib_wpa_mlme(ieee, param->u.mlme.command, |
| 3540 | param->u.mlme.reason_code); |
| 3541 | break; |
| 3542 | |
| 3543 | default: |
Mateusz Kulikowski | d69d205 | 2015-03-17 00:00:52 +0100 | [diff] [blame] | 3544 | netdev_info(ieee->dev, "Unknown WPA supplicant request: %d\n", |
| 3545 | param->cmd); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3546 | ret = -EOPNOTSUPP; |
| 3547 | break; |
| 3548 | } |
| 3549 | |
| 3550 | if (ret == 0 && copy_to_user(p->pointer, param, p->length)) |
| 3551 | ret = -EFAULT; |
| 3552 | |
| 3553 | kfree(param); |
| 3554 | out: |
Binoy Jayan | 9afa937 | 2016-06-01 14:56:52 +0530 | [diff] [blame] | 3555 | mutex_unlock(&ieee->wx_mutex); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3556 | |
| 3557 | return ret; |
| 3558 | } |
Sean MacLennan | 3b28499 | 2011-11-28 20:20:26 -0500 | [diff] [blame] | 3559 | EXPORT_SYMBOL(rtllib_wpa_supplicant_ioctl); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3560 | |
Rashika Kheria | c5654c0 | 2013-11-07 19:05:09 +0530 | [diff] [blame] | 3561 | static void rtllib_MgntDisconnectIBSS(struct rtllib_device *rtllib) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3562 | { |
| 3563 | u8 OpMode; |
| 3564 | u8 i; |
| 3565 | bool bFilterOutNonAssociatedBSSID = false; |
| 3566 | |
| 3567 | rtllib->state = RTLLIB_NOLINK; |
| 3568 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 3569 | for (i = 0; i < 6; i++) |
| 3570 | rtllib->current_network.bssid[i] = 0x55; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3571 | |
| 3572 | rtllib->OpMode = RT_OP_MODE_NO_LINK; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 3573 | rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_BSSID, |
| 3574 | rtllib->current_network.bssid); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3575 | OpMode = RT_OP_MODE_NO_LINK; |
| 3576 | rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_MEDIA_STATUS, &OpMode); |
| 3577 | rtllib_stop_send_beacons(rtllib); |
| 3578 | |
| 3579 | bFilterOutNonAssociatedBSSID = false; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 3580 | rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_CECHK_BSSID, |
| 3581 | (u8 *)(&bFilterOutNonAssociatedBSSID)); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3582 | notify_wx_assoc_event(rtllib); |
| 3583 | |
| 3584 | } |
| 3585 | |
Mateusz Kulikowski | 35e33b0 | 2015-05-31 20:19:40 +0200 | [diff] [blame] | 3586 | static void rtllib_MlmeDisassociateRequest(struct rtllib_device *rtllib, |
| 3587 | u8 *asSta, u8 asRsn) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3588 | { |
| 3589 | u8 i; |
| 3590 | u8 OpMode; |
| 3591 | |
| 3592 | RemovePeerTS(rtllib, asSta); |
| 3593 | |
Larry Finger | ea9f10f | 2012-04-20 14:45:37 -0500 | [diff] [blame] | 3594 | if (memcmp(rtllib->current_network.bssid, asSta, 6) == 0) { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3595 | rtllib->state = RTLLIB_NOLINK; |
| 3596 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 3597 | for (i = 0; i < 6; i++) |
| 3598 | rtllib->current_network.bssid[i] = 0x22; |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3599 | OpMode = RT_OP_MODE_NO_LINK; |
| 3600 | rtllib->OpMode = RT_OP_MODE_NO_LINK; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 3601 | rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_MEDIA_STATUS, |
| 3602 | (u8 *)(&OpMode)); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3603 | rtllib_disassociate(rtllib); |
| 3604 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 3605 | rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_BSSID, |
| 3606 | rtllib->current_network.bssid); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3607 | |
| 3608 | } |
| 3609 | |
| 3610 | } |
| 3611 | |
Rashika Kheria | c5654c0 | 2013-11-07 19:05:09 +0530 | [diff] [blame] | 3612 | static void |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3613 | rtllib_MgntDisconnectAP( |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 3614 | struct rtllib_device *rtllib, |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3615 | u8 asRsn |
| 3616 | ) |
| 3617 | { |
| 3618 | bool bFilterOutNonAssociatedBSSID = false; |
| 3619 | |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3620 | bFilterOutNonAssociatedBSSID = false; |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 3621 | rtllib->SetHwRegHandler(rtllib->dev, HW_VAR_CECHK_BSSID, |
| 3622 | (u8 *)(&bFilterOutNonAssociatedBSSID)); |
| 3623 | rtllib_MlmeDisassociateRequest(rtllib, rtllib->current_network.bssid, |
| 3624 | asRsn); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3625 | |
| 3626 | rtllib->state = RTLLIB_NOLINK; |
| 3627 | } |
| 3628 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 3629 | bool rtllib_MgntDisconnect(struct rtllib_device *rtllib, u8 asRsn) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3630 | { |
| 3631 | if (rtllib->ps != RTLLIB_PS_DISABLED) |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 3632 | rtllib->sta_wake_up(rtllib->dev); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3633 | |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 3634 | if (rtllib->state == RTLLIB_LINKED) { |
| 3635 | if (rtllib->iw_mode == IW_MODE_ADHOC) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3636 | rtllib_MgntDisconnectIBSS(rtllib); |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 3637 | if (rtllib->iw_mode == IW_MODE_INFRA) |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3638 | rtllib_MgntDisconnectAP(rtllib, asRsn); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3639 | |
| 3640 | } |
| 3641 | |
| 3642 | return true; |
| 3643 | } |
Sean MacLennan | 3b28499 | 2011-11-28 20:20:26 -0500 | [diff] [blame] | 3644 | EXPORT_SYMBOL(rtllib_MgntDisconnect); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3645 | |
| 3646 | void notify_wx_assoc_event(struct rtllib_device *ieee) |
| 3647 | { |
| 3648 | union iwreq_data wrqu; |
| 3649 | |
| 3650 | if (ieee->cannot_notify) |
| 3651 | return; |
| 3652 | |
| 3653 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
| 3654 | if (ieee->state == RTLLIB_LINKED) |
Larry Finger | 9d92ece | 2011-08-25 11:48:26 -0500 | [diff] [blame] | 3655 | memcpy(wrqu.ap_addr.sa_data, ieee->current_network.bssid, |
| 3656 | ETH_ALEN); |
| 3657 | else { |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3658 | |
Mateusz Kulikowski | d69d205 | 2015-03-17 00:00:52 +0100 | [diff] [blame] | 3659 | netdev_info(ieee->dev, "%s(): Tell user space disconnected\n", |
| 3660 | __func__); |
Aya Mahfouz | cdbaf3f | 2015-03-03 16:03:35 +0200 | [diff] [blame] | 3661 | eth_zero_addr(wrqu.ap_addr.sa_data); |
Larry Finger | 94a7994 | 2011-08-23 19:00:42 -0500 | [diff] [blame] | 3662 | } |
| 3663 | wireless_send_event(ieee->dev, SIOCGIWAP, &wrqu, NULL); |
| 3664 | } |
Sean MacLennan | 3b28499 | 2011-11-28 20:20:26 -0500 | [diff] [blame] | 3665 | EXPORT_SYMBOL(notify_wx_assoc_event); |