Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Marvell Wireless LAN device driver: Channel, Frequence and Power |
| 3 | * |
| 4 | * Copyright (C) 2011, Marvell International Ltd. |
| 5 | * |
| 6 | * This software file (the "File") is distributed by Marvell International |
| 7 | * Ltd. under the terms of the GNU General Public License Version 2, June 1991 |
| 8 | * (the "License"). You may use, redistribute and/or modify this File in |
| 9 | * accordance with the terms and conditions of the License, a copy of which |
| 10 | * is available by writing to the Free Software Foundation, Inc., |
| 11 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the |
| 12 | * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. |
| 13 | * |
| 14 | * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE |
| 16 | * ARE EXPRESSLY DISCLAIMED. The License provides additional details about |
| 17 | * this warranty disclaimer. |
| 18 | */ |
| 19 | |
| 20 | #include "decl.h" |
| 21 | #include "ioctl.h" |
| 22 | #include "util.h" |
| 23 | #include "fw.h" |
| 24 | #include "main.h" |
| 25 | #include "cfg80211.h" |
| 26 | |
| 27 | /* 100mW */ |
| 28 | #define MWIFIEX_TX_PWR_DEFAULT 20 |
| 29 | /* 100mW */ |
| 30 | #define MWIFIEX_TX_PWR_US_DEFAULT 20 |
| 31 | /* 50mW */ |
| 32 | #define MWIFIEX_TX_PWR_JP_DEFAULT 16 |
| 33 | /* 100mW */ |
| 34 | #define MWIFIEX_TX_PWR_FR_100MW 20 |
| 35 | /* 10mW */ |
| 36 | #define MWIFIEX_TX_PWR_FR_10MW 10 |
| 37 | /* 100mW */ |
| 38 | #define MWIFIEX_TX_PWR_EMEA_DEFAULT 20 |
| 39 | |
| 40 | static u8 adhoc_rates_b[B_SUPPORTED_RATES] = { 0x82, 0x84, 0x8b, 0x96, 0 }; |
| 41 | |
| 42 | static u8 adhoc_rates_g[G_SUPPORTED_RATES] = { 0x8c, 0x12, 0x98, 0x24, |
| 43 | 0xb0, 0x48, 0x60, 0x6c, 0 }; |
| 44 | |
| 45 | static u8 adhoc_rates_bg[BG_SUPPORTED_RATES] = { 0x82, 0x84, 0x8b, 0x96, |
| 46 | 0x0c, 0x12, 0x18, 0x24, |
| 47 | 0x30, 0x48, 0x60, 0x6c, 0 }; |
| 48 | |
| 49 | static u8 adhoc_rates_a[A_SUPPORTED_RATES] = { 0x8c, 0x12, 0x98, 0x24, |
| 50 | 0xb0, 0x48, 0x60, 0x6c, 0 }; |
Amitkumar Karwar | 711825a | 2011-10-12 20:29:33 -0700 | [diff] [blame] | 51 | static u8 supported_rates_a[A_SUPPORTED_RATES] = { 0x0c, 0x12, 0x18, 0x24, |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 52 | 0xb0, 0x48, 0x60, 0x6c, 0 }; |
| 53 | static u16 mwifiex_data_rates[MWIFIEX_SUPPORTED_RATES_EXT] = { 0x02, 0x04, |
| 54 | 0x0B, 0x16, 0x00, 0x0C, 0x12, 0x18, |
| 55 | 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90, |
| 56 | 0x0D, 0x1A, 0x27, 0x34, 0x4E, 0x68, |
| 57 | 0x75, 0x82, 0x0C, 0x1B, 0x36, 0x51, |
| 58 | 0x6C, 0xA2, 0xD8, 0xF3, 0x10E, 0x00 }; |
| 59 | |
Amitkumar Karwar | 711825a | 2011-10-12 20:29:33 -0700 | [diff] [blame] | 60 | static u8 supported_rates_b[B_SUPPORTED_RATES] = { 0x02, 0x04, 0x0b, 0x16, 0 }; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 61 | |
Amitkumar Karwar | 711825a | 2011-10-12 20:29:33 -0700 | [diff] [blame] | 62 | static u8 supported_rates_g[G_SUPPORTED_RATES] = { 0x0c, 0x12, 0x18, 0x24, |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 63 | 0x30, 0x48, 0x60, 0x6c, 0 }; |
| 64 | |
Amitkumar Karwar | 711825a | 2011-10-12 20:29:33 -0700 | [diff] [blame] | 65 | static u8 supported_rates_bg[BG_SUPPORTED_RATES] = { 0x02, 0x04, 0x0b, 0x0c, |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 66 | 0x12, 0x16, 0x18, 0x24, 0x30, 0x48, |
| 67 | 0x60, 0x6c, 0 }; |
| 68 | |
| 69 | u16 region_code_index[MWIFIEX_MAX_REGION_CODE] = { 0x10, 0x20, 0x30, |
| 70 | 0x32, 0x40, 0x41, 0xff }; |
| 71 | |
Amitkumar Karwar | 711825a | 2011-10-12 20:29:33 -0700 | [diff] [blame] | 72 | static u8 supported_rates_n[N_SUPPORTED_RATES] = { 0x02, 0x04, 0 }; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 73 | |
Amitkumar Karwar | 9e04a7c | 2012-04-09 20:06:54 -0700 | [diff] [blame] | 74 | struct region_code_mapping { |
| 75 | u8 code; |
| 76 | u8 region[IEEE80211_COUNTRY_STRING_LEN]; |
| 77 | }; |
| 78 | |
| 79 | static struct region_code_mapping region_code_mapping_t[] = { |
| 80 | { 0x10, "US " }, /* US FCC */ |
| 81 | { 0x20, "CA " }, /* IC Canada */ |
| 82 | { 0x30, "EU " }, /* ETSI */ |
| 83 | { 0x31, "ES " }, /* Spain */ |
| 84 | { 0x32, "FR " }, /* France */ |
| 85 | { 0x40, "JP " }, /* Japan */ |
| 86 | { 0x41, "JP " }, /* Japan */ |
| 87 | { 0x50, "CN " }, /* China */ |
| 88 | }; |
| 89 | |
| 90 | /* This function converts integer code to region string */ |
| 91 | u8 *mwifiex_11d_code_2_region(u8 code) |
| 92 | { |
| 93 | u8 i; |
| 94 | u8 size = sizeof(region_code_mapping_t)/ |
| 95 | sizeof(struct region_code_mapping); |
| 96 | |
| 97 | /* Look for code in mapping table */ |
| 98 | for (i = 0; i < size; i++) |
| 99 | if (region_code_mapping_t[i].code == code) |
| 100 | return region_code_mapping_t[i].region; |
| 101 | |
| 102 | return NULL; |
| 103 | } |
| 104 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 105 | /* |
| 106 | * This function maps an index in supported rates table into |
| 107 | * the corresponding data rate. |
| 108 | */ |
Yogesh Ashok Powar | a5f3905 | 2013-02-15 21:44:30 -0800 | [diff] [blame] | 109 | u32 mwifiex_index_to_acs_data_rate(struct mwifiex_private *priv, |
| 110 | u8 index, u8 ht_info) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 111 | { |
Bing Zhao | e3bea1c | 2011-11-16 20:40:35 -0800 | [diff] [blame] | 112 | /* |
| 113 | * For every mcs_rate line, the first 8 bytes are for stream 1x1, |
| 114 | * and all 16 bytes are for stream 2x2. |
| 115 | */ |
| 116 | u16 mcs_rate[4][16] = { |
| 117 | /* LGI 40M */ |
| 118 | { 0x1b, 0x36, 0x51, 0x6c, 0xa2, 0xd8, 0xf3, 0x10e, |
| 119 | 0x36, 0x6c, 0xa2, 0xd8, 0x144, 0x1b0, 0x1e6, 0x21c }, |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 120 | |
Bing Zhao | e3bea1c | 2011-11-16 20:40:35 -0800 | [diff] [blame] | 121 | /* SGI 40M */ |
| 122 | { 0x1e, 0x3c, 0x5a, 0x78, 0xb4, 0xf0, 0x10e, 0x12c, |
| 123 | 0x3c, 0x78, 0xb4, 0xf0, 0x168, 0x1e0, 0x21c, 0x258 }, |
| 124 | |
| 125 | /* LGI 20M */ |
| 126 | { 0x0d, 0x1a, 0x27, 0x34, 0x4e, 0x68, 0x75, 0x82, |
| 127 | 0x1a, 0x34, 0x4e, 0x68, 0x9c, 0xd0, 0xea, 0x104 }, |
| 128 | |
| 129 | /* SGI 20M */ |
| 130 | { 0x0e, 0x1c, 0x2b, 0x39, 0x56, 0x73, 0x82, 0x90, |
| 131 | 0x1c, 0x39, 0x56, 0x73, 0xad, 0xe7, 0x104, 0x120 } |
| 132 | }; |
Yogesh Ashok Powar | a5f3905 | 2013-02-15 21:44:30 -0800 | [diff] [blame] | 133 | /* AC rates */ |
| 134 | u16 ac_mcs_rate_nss1[8][10] = { |
| 135 | /* LG 160M */ |
| 136 | { 0x75, 0xEA, 0x15F, 0x1D4, 0x2BE, 0x3A8, 0x41D, |
| 137 | 0x492, 0x57C, 0x618 }, |
| 138 | |
| 139 | /* SG 160M */ |
| 140 | { 0x82, 0x104, 0x186, 0x208, 0x30C, 0x410, 0x492, |
| 141 | 0x514, 0x618, 0x6C6 }, |
| 142 | |
| 143 | /* LG 80M */ |
| 144 | { 0x3B, 0x75, 0xB0, 0xEA, 0x15F, 0x1D4, 0x20F, |
| 145 | 0x249, 0x2BE, 0x30C }, |
| 146 | |
| 147 | /* SG 80M */ |
| 148 | { 0x41, 0x82, 0xC3, 0x104, 0x186, 0x208, 0x249, |
| 149 | 0x28A, 0x30C, 0x363 }, |
| 150 | |
| 151 | /* LG 40M */ |
| 152 | { 0x1B, 0x36, 0x51, 0x6C, 0xA2, 0xD8, 0xF3, |
| 153 | 0x10E, 0x144, 0x168 }, |
| 154 | |
| 155 | /* SG 40M */ |
| 156 | { 0x1E, 0x3C, 0x5A, 0x78, 0xB4, 0xF0, 0x10E, |
| 157 | 0x12C, 0x168, 0x190 }, |
| 158 | |
| 159 | /* LG 20M */ |
| 160 | { 0xD, 0x1A, 0x27, 0x34, 0x4E, 0x68, 0x75, 0x82, 0x9C, 0x00 }, |
| 161 | |
| 162 | /* SG 20M */ |
| 163 | { 0xF, 0x1D, 0x2C, 0x3A, 0x57, 0x74, 0x82, 0x91, 0xAE, 0x00 }, |
| 164 | }; |
| 165 | /* NSS2 note: the value in the table is 2 multiplier of the actual |
| 166 | * rate |
| 167 | */ |
| 168 | u16 ac_mcs_rate_nss2[8][10] = { |
| 169 | /* LG 160M */ |
| 170 | { 0xEA, 0x1D4, 0x2BE, 0x3A8, 0x57C, 0x750, 0x83A, |
| 171 | 0x924, 0xAF8, 0xC30 }, |
| 172 | |
| 173 | /* SG 160M */ |
| 174 | { 0x104, 0x208, 0x30C, 0x410, 0x618, 0x820, 0x924, |
| 175 | 0xA28, 0xC30, 0xD8B }, |
| 176 | |
| 177 | /* LG 80M */ |
| 178 | { 0x75, 0xEA, 0x15F, 0x1D4, 0x2BE, 0x3A8, 0x41D, |
| 179 | 0x492, 0x57C, 0x618 }, |
| 180 | |
| 181 | /* SG 80M */ |
| 182 | { 0x82, 0x104, 0x186, 0x208, 0x30C, 0x410, 0x492, |
| 183 | 0x514, 0x618, 0x6C6 }, |
| 184 | |
| 185 | /* LG 40M */ |
| 186 | { 0x36, 0x6C, 0xA2, 0xD8, 0x144, 0x1B0, 0x1E6, |
| 187 | 0x21C, 0x288, 0x2D0 }, |
| 188 | |
| 189 | /* SG 40M */ |
| 190 | { 0x3C, 0x78, 0xB4, 0xF0, 0x168, 0x1E0, 0x21C, |
| 191 | 0x258, 0x2D0, 0x320 }, |
| 192 | |
| 193 | /* LG 20M */ |
| 194 | { 0x1A, 0x34, 0x4A, 0x68, 0x9C, 0xD0, 0xEA, 0x104, |
| 195 | 0x138, 0x00 }, |
| 196 | |
| 197 | /* SG 20M */ |
| 198 | { 0x1D, 0x3A, 0x57, 0x74, 0xAE, 0xE6, 0x104, 0x121, |
| 199 | 0x15B, 0x00 }, |
| 200 | }; |
| 201 | u32 rate = 0; |
| 202 | u8 mcs_index = 0; |
| 203 | u8 bw = 0; |
| 204 | u8 gi = 0; |
| 205 | |
| 206 | if ((ht_info & 0x3) == MWIFIEX_RATE_FORMAT_VHT) { |
| 207 | mcs_index = min(index & 0xF, 9); |
| 208 | |
| 209 | /* 20M: bw=0, 40M: bw=1, 80M: bw=2, 160M: bw=3 */ |
| 210 | bw = (ht_info & 0xC) >> 2; |
| 211 | |
| 212 | /* LGI: gi =0, SGI: gi = 1 */ |
| 213 | gi = (ht_info & 0x10) >> 4; |
| 214 | |
| 215 | if ((index >> 4) == 1) /* NSS = 2 */ |
| 216 | rate = ac_mcs_rate_nss2[2 * (3 - bw) + gi][mcs_index]; |
| 217 | else /* NSS = 1 */ |
| 218 | rate = ac_mcs_rate_nss1[2 * (3 - bw) + gi][mcs_index]; |
| 219 | } else if ((ht_info & 0x3) == MWIFIEX_RATE_FORMAT_HT) { |
| 220 | /* 20M: bw=0, 40M: bw=1 */ |
| 221 | bw = (ht_info & 0xC) >> 2; |
| 222 | |
| 223 | /* LGI: gi =0, SGI: gi = 1 */ |
| 224 | gi = (ht_info & 0x10) >> 4; |
| 225 | |
| 226 | if (index == MWIFIEX_RATE_BITMAP_MCS0) { |
| 227 | if (gi == 1) |
| 228 | rate = 0x0D; /* MCS 32 SGI rate */ |
| 229 | else |
| 230 | rate = 0x0C; /* MCS 32 LGI rate */ |
| 231 | } else if (index < 16) { |
| 232 | if ((bw == 1) || (bw == 0)) |
| 233 | rate = mcs_rate[2 * (1 - bw) + gi][index]; |
| 234 | else |
| 235 | rate = mwifiex_data_rates[0]; |
| 236 | } else { |
| 237 | rate = mwifiex_data_rates[0]; |
| 238 | } |
| 239 | } else { |
| 240 | /* 11n non-HT rates */ |
| 241 | if (index >= MWIFIEX_SUPPORTED_RATES_EXT) |
| 242 | index = 0; |
| 243 | rate = mwifiex_data_rates[index]; |
| 244 | } |
| 245 | |
| 246 | return rate; |
| 247 | } |
| 248 | |
| 249 | /* This function maps an index in supported rates table into |
| 250 | * the corresponding data rate. |
| 251 | */ |
| 252 | u32 mwifiex_index_to_data_rate(struct mwifiex_private *priv, |
| 253 | u8 index, u8 ht_info) |
| 254 | { |
| 255 | /* For every mcs_rate line, the first 8 bytes are for stream 1x1, |
| 256 | * and all 16 bytes are for stream 2x2. |
| 257 | */ |
| 258 | u16 mcs_rate[4][16] = { |
| 259 | /* LGI 40M */ |
| 260 | { 0x1b, 0x36, 0x51, 0x6c, 0xa2, 0xd8, 0xf3, 0x10e, |
| 261 | 0x36, 0x6c, 0xa2, 0xd8, 0x144, 0x1b0, 0x1e6, 0x21c }, |
| 262 | |
| 263 | /* SGI 40M */ |
| 264 | { 0x1e, 0x3c, 0x5a, 0x78, 0xb4, 0xf0, 0x10e, 0x12c, |
| 265 | 0x3c, 0x78, 0xb4, 0xf0, 0x168, 0x1e0, 0x21c, 0x258 }, |
| 266 | |
| 267 | /* LGI 20M */ |
| 268 | { 0x0d, 0x1a, 0x27, 0x34, 0x4e, 0x68, 0x75, 0x82, |
| 269 | 0x1a, 0x34, 0x4e, 0x68, 0x9c, 0xd0, 0xea, 0x104 }, |
| 270 | |
| 271 | /* SGI 20M */ |
| 272 | { 0x0e, 0x1c, 0x2b, 0x39, 0x56, 0x73, 0x82, 0x90, |
| 273 | 0x1c, 0x39, 0x56, 0x73, 0xad, 0xe7, 0x104, 0x120 } |
| 274 | }; |
Bing Zhao | e3bea1c | 2011-11-16 20:40:35 -0800 | [diff] [blame] | 275 | u32 mcs_num_supp = |
| 276 | (priv->adapter->hw_dev_mcs_support == HT_STREAM_2X2) ? 16 : 8; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 277 | u32 rate; |
| 278 | |
Yogesh Ashok Powar | a5f3905 | 2013-02-15 21:44:30 -0800 | [diff] [blame] | 279 | if (priv->adapter->is_hw_11ac_capable) |
| 280 | return mwifiex_index_to_acs_data_rate(priv, index, ht_info); |
| 281 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 282 | if (ht_info & BIT(0)) { |
| 283 | if (index == MWIFIEX_RATE_BITMAP_MCS0) { |
| 284 | if (ht_info & BIT(2)) |
| 285 | rate = 0x0D; /* MCS 32 SGI rate */ |
| 286 | else |
| 287 | rate = 0x0C; /* MCS 32 LGI rate */ |
Bing Zhao | e3bea1c | 2011-11-16 20:40:35 -0800 | [diff] [blame] | 288 | } else if (index < mcs_num_supp) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 289 | if (ht_info & BIT(1)) { |
| 290 | if (ht_info & BIT(2)) |
| 291 | /* SGI, 40M */ |
| 292 | rate = mcs_rate[1][index]; |
| 293 | else |
| 294 | /* LGI, 40M */ |
| 295 | rate = mcs_rate[0][index]; |
| 296 | } else { |
| 297 | if (ht_info & BIT(2)) |
| 298 | /* SGI, 20M */ |
| 299 | rate = mcs_rate[3][index]; |
| 300 | else |
| 301 | /* LGI, 20M */ |
| 302 | rate = mcs_rate[2][index]; |
| 303 | } |
| 304 | } else |
| 305 | rate = mwifiex_data_rates[0]; |
| 306 | } else { |
| 307 | if (index >= MWIFIEX_SUPPORTED_RATES_EXT) |
| 308 | index = 0; |
| 309 | rate = mwifiex_data_rates[index]; |
| 310 | } |
| 311 | return rate; |
| 312 | } |
| 313 | |
| 314 | /* |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 315 | * This function returns the current active data rates. |
| 316 | * |
| 317 | * The result may vary depending upon connection status. |
| 318 | */ |
| 319 | u32 mwifiex_get_active_data_rates(struct mwifiex_private *priv, u8 *rates) |
| 320 | { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 321 | if (!priv->media_connected) |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 322 | return mwifiex_get_supported_rates(priv, rates); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 323 | else |
Yogesh Ashok Powar | 636c459 | 2011-04-15 20:50:40 -0700 | [diff] [blame] | 324 | return mwifiex_copy_rates(rates, 0, |
Yogesh Ashok Powar | aea0701 | 2012-03-13 19:22:35 -0700 | [diff] [blame] | 325 | priv->curr_bss_params.data_rates, |
| 326 | priv->curr_bss_params.num_of_rates); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | /* |
| 330 | * This function locates the Channel-Frequency-Power triplet based upon |
Yogesh Ashok Powar | 6685d10 | 2012-03-12 19:35:10 -0700 | [diff] [blame] | 331 | * band and channel/frequency parameters. |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 332 | */ |
| 333 | struct mwifiex_chan_freq_power * |
Yogesh Ashok Powar | 6685d10 | 2012-03-12 19:35:10 -0700 | [diff] [blame] | 334 | mwifiex_get_cfp(struct mwifiex_private *priv, u8 band, u16 channel, u32 freq) |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 335 | { |
| 336 | struct mwifiex_chan_freq_power *cfp = NULL; |
| 337 | struct ieee80211_supported_band *sband; |
Yogesh Ashok Powar | 6685d10 | 2012-03-12 19:35:10 -0700 | [diff] [blame] | 338 | struct ieee80211_channel *ch = NULL; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 339 | int i; |
| 340 | |
Yogesh Ashok Powar | 6685d10 | 2012-03-12 19:35:10 -0700 | [diff] [blame] | 341 | if (!channel && !freq) |
| 342 | return cfp; |
| 343 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 344 | if (mwifiex_band_to_radio_type(band) == HostCmd_SCAN_RADIO_TYPE_BG) |
| 345 | sband = priv->wdev->wiphy->bands[IEEE80211_BAND_2GHZ]; |
| 346 | else |
| 347 | sband = priv->wdev->wiphy->bands[IEEE80211_BAND_5GHZ]; |
| 348 | |
| 349 | if (!sband) { |
Yogesh Ashok Powar | 6685d10 | 2012-03-12 19:35:10 -0700 | [diff] [blame] | 350 | dev_err(priv->adapter->dev, "%s: cannot find cfp by band %d\n", |
| 351 | __func__, band); |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 352 | return cfp; |
| 353 | } |
| 354 | |
| 355 | for (i = 0; i < sband->n_channels; i++) { |
| 356 | ch = &sband->channels[i]; |
Yogesh Ashok Powar | 6685d10 | 2012-03-12 19:35:10 -0700 | [diff] [blame] | 357 | |
| 358 | if (ch->flags & IEEE80211_CHAN_DISABLED) |
| 359 | continue; |
| 360 | |
| 361 | if (freq) { |
| 362 | if (ch->center_freq == freq) |
| 363 | break; |
| 364 | } else { |
| 365 | /* find by valid channel*/ |
| 366 | if (ch->hw_value == channel || |
| 367 | channel == FIRST_VALID_CHANNEL) |
| 368 | break; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 369 | } |
| 370 | } |
Yogesh Ashok Powar | 6685d10 | 2012-03-12 19:35:10 -0700 | [diff] [blame] | 371 | if (i == sband->n_channels) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 372 | dev_err(priv->adapter->dev, "%s: cannot find cfp by band %d" |
Yogesh Ashok Powar | 6685d10 | 2012-03-12 19:35:10 -0700 | [diff] [blame] | 373 | " & channel=%d freq=%d\n", __func__, band, channel, |
| 374 | freq); |
| 375 | } else { |
| 376 | if (!ch) |
| 377 | return cfp; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 378 | |
Yogesh Ashok Powar | 6685d10 | 2012-03-12 19:35:10 -0700 | [diff] [blame] | 379 | priv->cfp.channel = ch->hw_value; |
| 380 | priv->cfp.freq = ch->center_freq; |
| 381 | priv->cfp.max_tx_power = ch->max_power; |
| 382 | cfp = &priv->cfp; |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 383 | } |
| 384 | |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 385 | return cfp; |
| 386 | } |
| 387 | |
| 388 | /* |
| 389 | * This function checks if the data rate is set to auto. |
| 390 | */ |
| 391 | u8 |
| 392 | mwifiex_is_rate_auto(struct mwifiex_private *priv) |
| 393 | { |
| 394 | u32 i; |
| 395 | int rate_num = 0; |
| 396 | |
| 397 | for (i = 0; i < ARRAY_SIZE(priv->bitmap_rates); i++) |
| 398 | if (priv->bitmap_rates[i]) |
| 399 | rate_num++; |
| 400 | |
| 401 | if (rate_num > 1) |
| 402 | return true; |
| 403 | else |
| 404 | return false; |
| 405 | } |
| 406 | |
Avinash Patil | 78dfca6 | 2013-07-30 17:18:56 -0700 | [diff] [blame] | 407 | /* This function gets the supported data rates from bitmask inside |
| 408 | * cfg80211_scan_request. |
| 409 | */ |
| 410 | u32 mwifiex_get_rates_from_cfg80211(struct mwifiex_private *priv, |
| 411 | u8 *rates, u8 radio_type) |
| 412 | { |
| 413 | struct wiphy *wiphy = priv->adapter->wiphy; |
| 414 | struct cfg80211_scan_request *request = priv->scan_request; |
| 415 | u32 num_rates, rate_mask; |
| 416 | struct ieee80211_supported_band *sband; |
| 417 | int i; |
| 418 | |
| 419 | if (radio_type) { |
| 420 | sband = wiphy->bands[IEEE80211_BAND_5GHZ]; |
| 421 | if (WARN_ON_ONCE(!sband)) |
| 422 | return 0; |
| 423 | rate_mask = request->rates[IEEE80211_BAND_5GHZ]; |
| 424 | } else { |
| 425 | sband = wiphy->bands[IEEE80211_BAND_2GHZ]; |
| 426 | if (WARN_ON_ONCE(!sband)) |
| 427 | return 0; |
| 428 | rate_mask = request->rates[IEEE80211_BAND_2GHZ]; |
| 429 | } |
| 430 | |
| 431 | num_rates = 0; |
| 432 | for (i = 0; i < sband->n_bitrates; i++) { |
| 433 | if ((BIT(i) & rate_mask) == 0) |
| 434 | continue; /* skip rate */ |
| 435 | rates[num_rates++] = (u8)(sband->bitrates[i].bitrate / 5); |
| 436 | } |
| 437 | |
| 438 | return num_rates; |
| 439 | } |
| 440 | |
| 441 | /* This function gets the supported data rates. The function works in |
| 442 | * both Ad-Hoc and infra mode by printing the band and returning the |
| 443 | * data rates. |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 444 | */ |
| 445 | u32 mwifiex_get_supported_rates(struct mwifiex_private *priv, u8 *rates) |
| 446 | { |
| 447 | u32 k = 0; |
| 448 | struct mwifiex_adapter *adapter = priv->adapter; |
Yogesh Ashok Powar | a5f3905 | 2013-02-15 21:44:30 -0800 | [diff] [blame] | 449 | |
Avinash Patil | 237b2ac | 2013-07-29 16:32:38 -0700 | [diff] [blame] | 450 | if (priv->bss_mode == NL80211_IFTYPE_STATION || |
| 451 | priv->bss_mode == NL80211_IFTYPE_P2P_CLIENT) { |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 452 | switch (adapter->config_bands) { |
| 453 | case BAND_B: |
| 454 | dev_dbg(adapter->dev, "info: infra band=%d " |
| 455 | "supported_rates_b\n", adapter->config_bands); |
| 456 | k = mwifiex_copy_rates(rates, k, supported_rates_b, |
| 457 | sizeof(supported_rates_b)); |
| 458 | break; |
| 459 | case BAND_G: |
| 460 | case BAND_G | BAND_GN: |
Yogesh Ashok Powar | a5f3905 | 2013-02-15 21:44:30 -0800 | [diff] [blame] | 461 | case BAND_G | BAND_GN | BAND_GAC: |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 462 | dev_dbg(adapter->dev, "info: infra band=%d " |
| 463 | "supported_rates_g\n", adapter->config_bands); |
| 464 | k = mwifiex_copy_rates(rates, k, supported_rates_g, |
| 465 | sizeof(supported_rates_g)); |
| 466 | break; |
| 467 | case BAND_B | BAND_G: |
| 468 | case BAND_A | BAND_B | BAND_G: |
| 469 | case BAND_A | BAND_B: |
| 470 | case BAND_A | BAND_B | BAND_G | BAND_GN | BAND_AN: |
Yogesh Ashok Powar | a5f3905 | 2013-02-15 21:44:30 -0800 | [diff] [blame] | 471 | case BAND_A | BAND_B | BAND_G | BAND_GN | BAND_AN | BAND_AAC: |
| 472 | case BAND_A | BAND_B | BAND_G | BAND_GN | BAND_AN | |
| 473 | BAND_AAC | BAND_GAC: |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 474 | case BAND_B | BAND_G | BAND_GN: |
Yogesh Ashok Powar | a5f3905 | 2013-02-15 21:44:30 -0800 | [diff] [blame] | 475 | case BAND_B | BAND_G | BAND_GN | BAND_GAC: |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 476 | dev_dbg(adapter->dev, "info: infra band=%d " |
| 477 | "supported_rates_bg\n", adapter->config_bands); |
| 478 | k = mwifiex_copy_rates(rates, k, supported_rates_bg, |
| 479 | sizeof(supported_rates_bg)); |
| 480 | break; |
| 481 | case BAND_A: |
| 482 | case BAND_A | BAND_G: |
| 483 | dev_dbg(adapter->dev, "info: infra band=%d " |
| 484 | "supported_rates_a\n", adapter->config_bands); |
| 485 | k = mwifiex_copy_rates(rates, k, supported_rates_a, |
| 486 | sizeof(supported_rates_a)); |
| 487 | break; |
Yogesh Ashok Powar | a5f3905 | 2013-02-15 21:44:30 -0800 | [diff] [blame] | 488 | case BAND_AN: |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 489 | case BAND_A | BAND_AN: |
Yogesh Ashok Powar | a5f3905 | 2013-02-15 21:44:30 -0800 | [diff] [blame] | 490 | case BAND_A | BAND_AN | BAND_AAC: |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 491 | case BAND_A | BAND_G | BAND_AN | BAND_GN: |
Yogesh Ashok Powar | a5f3905 | 2013-02-15 21:44:30 -0800 | [diff] [blame] | 492 | case BAND_A | BAND_G | BAND_AN | BAND_GN | BAND_AAC: |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 493 | dev_dbg(adapter->dev, "info: infra band=%d " |
| 494 | "supported_rates_a\n", adapter->config_bands); |
| 495 | k = mwifiex_copy_rates(rates, k, supported_rates_a, |
| 496 | sizeof(supported_rates_a)); |
| 497 | break; |
| 498 | case BAND_GN: |
Yogesh Ashok Powar | a5f3905 | 2013-02-15 21:44:30 -0800 | [diff] [blame] | 499 | case BAND_GN | BAND_GAC: |
Bing Zhao | 5e6e3a9 | 2011-03-21 18:00:50 -0700 | [diff] [blame] | 500 | dev_dbg(adapter->dev, "info: infra band=%d " |
| 501 | "supported_rates_n\n", adapter->config_bands); |
| 502 | k = mwifiex_copy_rates(rates, k, supported_rates_n, |
| 503 | sizeof(supported_rates_n)); |
| 504 | break; |
| 505 | } |
| 506 | } else { |
| 507 | /* Ad-hoc mode */ |
| 508 | switch (adapter->adhoc_start_band) { |
| 509 | case BAND_B: |
| 510 | dev_dbg(adapter->dev, "info: adhoc B\n"); |
| 511 | k = mwifiex_copy_rates(rates, k, adhoc_rates_b, |
| 512 | sizeof(adhoc_rates_b)); |
| 513 | break; |
| 514 | case BAND_G: |
| 515 | case BAND_G | BAND_GN: |
| 516 | dev_dbg(adapter->dev, "info: adhoc G only\n"); |
| 517 | k = mwifiex_copy_rates(rates, k, adhoc_rates_g, |
| 518 | sizeof(adhoc_rates_g)); |
| 519 | break; |
| 520 | case BAND_B | BAND_G: |
| 521 | case BAND_B | BAND_G | BAND_GN: |
| 522 | dev_dbg(adapter->dev, "info: adhoc BG\n"); |
| 523 | k = mwifiex_copy_rates(rates, k, adhoc_rates_bg, |
| 524 | sizeof(adhoc_rates_bg)); |
| 525 | break; |
| 526 | case BAND_A: |
| 527 | case BAND_A | BAND_AN: |
| 528 | dev_dbg(adapter->dev, "info: adhoc A\n"); |
| 529 | k = mwifiex_copy_rates(rates, k, adhoc_rates_a, |
| 530 | sizeof(adhoc_rates_a)); |
| 531 | break; |
| 532 | } |
| 533 | } |
| 534 | |
| 535 | return k; |
| 536 | } |