blob: 4bc46a60ae2fd6bd9ec1d30ded33e9f2f3244108 [file] [log] [blame]
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001/**
2 * This file contains functions for 802.11D.
3 */
4#include <linux/ctype.h>
5#include <linux/kernel.h>
6#include <linux/wireless.h>
7
8#include "host.h"
9#include "decl.h"
10#include "11d.h"
11#include "dev.h"
12#include "wext.h"
13
14#define TX_PWR_DEFAULT 10
15
16static struct region_code_mapping region_code_mapping[] = {
17 {"US ", 0x10}, /* US FCC */
18 {"CA ", 0x10}, /* IC Canada */
19 {"SG ", 0x10}, /* Singapore */
20 {"EU ", 0x30}, /* ETSI */
21 {"AU ", 0x30}, /* Australia */
22 {"KR ", 0x30}, /* Republic Of Korea */
23 {"ES ", 0x31}, /* Spain */
24 {"FR ", 0x32}, /* France */
25 {"JP ", 0x40}, /* Japan */
26};
27
28/* Following 2 structure defines the supported channels */
29static struct chan_freq_power channel_freq_power_UN_BG[] = {
30 {1, 2412, TX_PWR_DEFAULT},
31 {2, 2417, TX_PWR_DEFAULT},
32 {3, 2422, TX_PWR_DEFAULT},
33 {4, 2427, TX_PWR_DEFAULT},
34 {5, 2432, TX_PWR_DEFAULT},
35 {6, 2437, TX_PWR_DEFAULT},
36 {7, 2442, TX_PWR_DEFAULT},
37 {8, 2447, TX_PWR_DEFAULT},
38 {9, 2452, TX_PWR_DEFAULT},
39 {10, 2457, TX_PWR_DEFAULT},
40 {11, 2462, TX_PWR_DEFAULT},
41 {12, 2467, TX_PWR_DEFAULT},
42 {13, 2472, TX_PWR_DEFAULT},
43 {14, 2484, TX_PWR_DEFAULT}
44};
45
Holger Schurig10078322007-11-15 18:05:47 -050046static u8 lbs_region_2_code(u8 *region)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020047{
48 u8 i;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020049
50 for (i = 0; region[i] && i < COUNTRY_CODE_LEN; i++)
51 region[i] = toupper(region[i]);
52
Alejandro Martinez Ruizc00acf42007-10-18 10:16:33 +020053 for (i = 0; i < ARRAY_SIZE(region_code_mapping); i++) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020054 if (!memcmp(region, region_code_mapping[i].region,
55 COUNTRY_CODE_LEN))
56 return (region_code_mapping[i].code);
57 }
58
59 /* default is US */
60 return (region_code_mapping[0].code);
61}
62
Holger Schurig10078322007-11-15 18:05:47 -050063static u8 *lbs_code_2_region(u8 code)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020064{
65 u8 i;
Alejandro Martinez Ruizc00acf42007-10-18 10:16:33 +020066
67 for (i = 0; i < ARRAY_SIZE(region_code_mapping); i++) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020068 if (region_code_mapping[i].code == code)
69 return (region_code_mapping[i].region);
70 }
71 /* default is US */
72 return (region_code_mapping[0].region);
73}
74
75/**
76 * @brief This function finds the nrchan-th chan after the firstchan
77 * @param band band
78 * @param firstchan first channel number
79 * @param nrchan number of channels
80 * @return the nrchan-th chan number
81*/
Holger Schurige98a88d2008-03-19 14:25:58 +010082static u8 lbs_get_chan_11d(u8 firstchan, u8 nrchan, u8 *chan)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020083/*find the nrchan-th chan after the firstchan*/
84{
85 u8 i;
86 struct chan_freq_power *cfp;
87 u8 cfp_no;
88
89 cfp = channel_freq_power_UN_BG;
Alejandro Martinez Ruizc00acf42007-10-18 10:16:33 +020090 cfp_no = ARRAY_SIZE(channel_freq_power_UN_BG);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020091
92 for (i = 0; i < cfp_no; i++) {
93 if ((cfp + i)->channel == firstchan) {
Holger Schurig9012b282007-05-25 11:27:16 -040094 lbs_deb_11d("firstchan found\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020095 break;
96 }
97 }
98
99 if (i < cfp_no) {
100 /*if beyond the boundary */
101 if (i + nrchan < cfp_no) {
102 *chan = (cfp + i + nrchan)->channel;
103 return 1;
104 }
105 }
106
107 return 0;
108}
109
110/**
111 * @brief This function Checks if chan txpwr is learned from AP/IBSS
112 * @param chan chan number
113 * @param parsed_region_chan pointer to parsed_region_chan_11d
114 * @return TRUE; FALSE
115*/
Holger Schurig10078322007-11-15 18:05:47 -0500116static u8 lbs_channel_known_11d(u8 chan,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200117 struct parsed_region_chan_11d * parsed_region_chan)
118{
119 struct chan_power_11d *chanpwr = parsed_region_chan->chanpwr;
120 u8 nr_chan = parsed_region_chan->nr_chan;
121 u8 i = 0;
122
Holger Schurigece56192007-08-02 11:53:06 -0400123 lbs_deb_hex(LBS_DEB_11D, "parsed_region_chan", (char *)chanpwr,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200124 sizeof(struct chan_power_11d) * nr_chan);
125
126 for (i = 0; i < nr_chan; i++) {
127 if (chan == chanpwr[i].chan) {
Holger Schurigece56192007-08-02 11:53:06 -0400128 lbs_deb_11d("found chan %d\n", chan);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200129 return 1;
130 }
131 }
132
Holger Schurigece56192007-08-02 11:53:06 -0400133 lbs_deb_11d("chan %d not found\n", chan);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200134 return 0;
135}
136
Holger Schurige98a88d2008-03-19 14:25:58 +0100137u32 lbs_chan_2_freq(u8 chan)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200138{
139 struct chan_freq_power *cf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200140 u16 i;
141 u32 freq = 0;
142
143 cf = channel_freq_power_UN_BG;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200144
Alejandro Martinez Ruizc00acf42007-10-18 10:16:33 +0200145 for (i = 0; i < ARRAY_SIZE(channel_freq_power_UN_BG); i++) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200146 if (chan == cf[i].channel)
147 freq = cf[i].freq;
148 }
149
150 return freq;
151}
152
153static int generate_domain_info_11d(struct parsed_region_chan_11d
154 *parsed_region_chan,
Holger Schurig10078322007-11-15 18:05:47 -0500155 struct lbs_802_11d_domain_reg *domaininfo)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200156{
157 u8 nr_subband = 0;
158
159 u8 nr_chan = parsed_region_chan->nr_chan;
160 u8 nr_parsedchan = 0;
161
162 u8 firstchan = 0, nextchan = 0, maxpwr = 0;
163
164 u8 i, flag = 0;
165
166 memcpy(domaininfo->countrycode, parsed_region_chan->countrycode,
167 COUNTRY_CODE_LEN);
168
Holger Schurigece56192007-08-02 11:53:06 -0400169 lbs_deb_11d("nrchan %d\n", nr_chan);
170 lbs_deb_hex(LBS_DEB_11D, "parsed_region_chan", (char *)parsed_region_chan,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200171 sizeof(struct parsed_region_chan_11d));
172
173 for (i = 0; i < nr_chan; i++) {
174 if (!flag) {
175 flag = 1;
176 nextchan = firstchan =
177 parsed_region_chan->chanpwr[i].chan;
178 maxpwr = parsed_region_chan->chanpwr[i].pwr;
179 nr_parsedchan = 1;
180 continue;
181 }
182
183 if (parsed_region_chan->chanpwr[i].chan == nextchan + 1 &&
184 parsed_region_chan->chanpwr[i].pwr == maxpwr) {
185 nextchan++;
186 nr_parsedchan++;
187 } else {
188 domaininfo->subband[nr_subband].firstchan = firstchan;
189 domaininfo->subband[nr_subband].nrchan =
190 nr_parsedchan;
191 domaininfo->subband[nr_subband].maxtxpwr = maxpwr;
192 nr_subband++;
193 nextchan = firstchan =
194 parsed_region_chan->chanpwr[i].chan;
195 maxpwr = parsed_region_chan->chanpwr[i].pwr;
196 }
197 }
198
199 if (flag) {
200 domaininfo->subband[nr_subband].firstchan = firstchan;
201 domaininfo->subband[nr_subband].nrchan = nr_parsedchan;
202 domaininfo->subband[nr_subband].maxtxpwr = maxpwr;
203 nr_subband++;
204 }
205 domaininfo->nr_subband = nr_subband;
206
Holger Schurig9012b282007-05-25 11:27:16 -0400207 lbs_deb_11d("nr_subband=%x\n", domaininfo->nr_subband);
Holger Schurigece56192007-08-02 11:53:06 -0400208 lbs_deb_hex(LBS_DEB_11D, "domaininfo", (char *)domaininfo,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200209 COUNTRY_CODE_LEN + 1 +
210 sizeof(struct ieeetypes_subbandset) * nr_subband);
211 return 0;
212}
213
214/**
215 * @brief This function generates parsed_region_chan from Domain Info learned from AP/IBSS
216 * @param region_chan pointer to struct region_channel
217 * @param *parsed_region_chan pointer to parsed_region_chan_11d
218 * @return N/A
219*/
Holger Schurig10078322007-11-15 18:05:47 -0500220static void lbs_generate_parsed_region_chan_11d(struct region_channel *region_chan,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200221 struct parsed_region_chan_11d *
222 parsed_region_chan)
223{
224 u8 i;
225 struct chan_freq_power *cfp;
226
227 if (region_chan == NULL) {
Holger Schurigece56192007-08-02 11:53:06 -0400228 lbs_deb_11d("region_chan is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200229 return;
230 }
231
232 cfp = region_chan->CFP;
233 if (cfp == NULL) {
Holger Schurigece56192007-08-02 11:53:06 -0400234 lbs_deb_11d("cfp is NULL \n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200235 return;
236 }
237
238 parsed_region_chan->band = region_chan->band;
239 parsed_region_chan->region = region_chan->region;
240 memcpy(parsed_region_chan->countrycode,
Holger Schurig10078322007-11-15 18:05:47 -0500241 lbs_code_2_region(region_chan->region), COUNTRY_CODE_LEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200242
Holger Schurigece56192007-08-02 11:53:06 -0400243 lbs_deb_11d("region 0x%x, band %d\n", parsed_region_chan->region,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200244 parsed_region_chan->band);
245
246 for (i = 0; i < region_chan->nrcfp; i++, cfp++) {
247 parsed_region_chan->chanpwr[i].chan = cfp->channel;
248 parsed_region_chan->chanpwr[i].pwr = cfp->maxtxpower;
Holger Schurigece56192007-08-02 11:53:06 -0400249 lbs_deb_11d("chan %d, pwr %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200250 parsed_region_chan->chanpwr[i].chan,
251 parsed_region_chan->chanpwr[i].pwr);
252 }
253 parsed_region_chan->nr_chan = region_chan->nrcfp;
254
Holger Schurigece56192007-08-02 11:53:06 -0400255 lbs_deb_11d("nrchan %d\n", parsed_region_chan->nr_chan);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200256
257 return;
258}
259
260/**
261 * @brief generate parsed_region_chan from Domain Info learned from AP/IBSS
262 * @param region region ID
263 * @param band band
264 * @param chan chan
265 * @return TRUE;FALSE
266*/
Holger Schurige98a88d2008-03-19 14:25:58 +0100267static u8 lbs_region_chan_supported_11d(u8 region, u8 chan)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200268{
269 struct chan_freq_power *cfp;
270 int cfp_no;
271 u8 idx;
Holger Schurig9012b282007-05-25 11:27:16 -0400272 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200273
Holger Schurig9012b282007-05-25 11:27:16 -0400274 lbs_deb_enter(LBS_DEB_11D);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200275
Holger Schurige98a88d2008-03-19 14:25:58 +0100276 cfp = lbs_get_region_cfp_table(region, &cfp_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200277 if (cfp == NULL)
278 return 0;
279
280 for (idx = 0; idx < cfp_no; idx++) {
281 if (chan == (cfp + idx)->channel) {
282 /* If Mrvl Chip Supported? */
283 if ((cfp + idx)->unsupported) {
Holger Schurig9012b282007-05-25 11:27:16 -0400284 ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200285 } else {
Holger Schurig9012b282007-05-25 11:27:16 -0400286 ret = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200287 }
Holger Schurig9012b282007-05-25 11:27:16 -0400288 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200289 }
290 }
291
292 /*chan is not in the region table */
Holger Schurig9012b282007-05-25 11:27:16 -0400293
294done:
295 lbs_deb_leave_args(LBS_DEB_11D, "ret %d", ret);
296 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200297}
298
299/**
300 * @brief This function checks if chan txpwr is learned from AP/IBSS
301 * @param chan chan number
302 * @param parsed_region_chan pointer to parsed_region_chan_11d
303 * @return 0
304*/
305static int parse_domain_info_11d(struct ieeetypes_countryinfofullset*
306 countryinfo,
307 u8 band,
308 struct parsed_region_chan_11d *
309 parsed_region_chan)
310{
311 u8 nr_subband, nrchan;
312 u8 lastchan, firstchan;
313 u8 region;
314 u8 curchan = 0;
315
316 u8 idx = 0; /*chan index in parsed_region_chan */
317
318 u8 j, i;
319
Holger Schurig9012b282007-05-25 11:27:16 -0400320 lbs_deb_enter(LBS_DEB_11D);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200321
322 /*validation Rules:
323 1. valid region Code
324 2. First Chan increment
325 3. channel range no overlap
326 4. channel is valid?
327 5. channel is supported by region?
328 6. Others
329 */
330
Holger Schurigece56192007-08-02 11:53:06 -0400331 lbs_deb_hex(LBS_DEB_11D, "countryinfo", (u8 *) countryinfo, 30);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200332
333 if ((*(countryinfo->countrycode)) == 0
334 || (countryinfo->len <= COUNTRY_CODE_LEN)) {
335 /* No region Info or Wrong region info: treat as No 11D info */
Holger Schurig9012b282007-05-25 11:27:16 -0400336 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200337 }
338
339 /*Step1: check region_code */
340 parsed_region_chan->region = region =
Holger Schurig10078322007-11-15 18:05:47 -0500341 lbs_region_2_code(countryinfo->countrycode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200342
Holger Schurig9012b282007-05-25 11:27:16 -0400343 lbs_deb_11d("regioncode=%x\n", (u8) parsed_region_chan->region);
Holger Schurigece56192007-08-02 11:53:06 -0400344 lbs_deb_hex(LBS_DEB_11D, "countrycode", (char *)countryinfo->countrycode,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200345 COUNTRY_CODE_LEN);
346
347 parsed_region_chan->band = band;
348
349 memcpy(parsed_region_chan->countrycode, countryinfo->countrycode,
350 COUNTRY_CODE_LEN);
351
352 nr_subband = (countryinfo->len - COUNTRY_CODE_LEN) /
353 sizeof(struct ieeetypes_subbandset);
354
355 for (j = 0, lastchan = 0; j < nr_subband; j++) {
356
357 if (countryinfo->subband[j].firstchan <= lastchan) {
358 /*Step2&3. Check First Chan Num increment and no overlap */
Holger Schurigece56192007-08-02 11:53:06 -0400359 lbs_deb_11d("chan %d>%d, overlap\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200360 countryinfo->subband[j].firstchan, lastchan);
361 continue;
362 }
363
364 firstchan = countryinfo->subband[j].firstchan;
365 nrchan = countryinfo->subband[j].nrchan;
366
367 for (i = 0; idx < MAX_NO_OF_CHAN && i < nrchan; i++) {
368 /*step4: channel is supported? */
369
Holger Schurige98a88d2008-03-19 14:25:58 +0100370 if (!lbs_get_chan_11d(firstchan, i, &curchan)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200371 /* Chan is not found in UN table */
Holger Schurig9012b282007-05-25 11:27:16 -0400372 lbs_deb_11d("chan is not supported: %d \n", i);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200373 break;
374 }
375
376 lastchan = curchan;
377
Holger Schurige98a88d2008-03-19 14:25:58 +0100378 if (lbs_region_chan_supported_11d(region, curchan)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200379 /*step5: Check if curchan is supported by mrvl in region */
380 parsed_region_chan->chanpwr[idx].chan = curchan;
381 parsed_region_chan->chanpwr[idx].pwr =
382 countryinfo->subband[j].maxtxpwr;
383 idx++;
384 } else {
385 /*not supported and ignore the chan */
Holger Schurig9012b282007-05-25 11:27:16 -0400386 lbs_deb_11d(
Holger Schurigece56192007-08-02 11:53:06 -0400387 "i %d, chan %d unsupported in region %x, band %d\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200388 i, curchan, region, band);
389 }
390 }
391
392 /*Step6: Add other checking if any */
393
394 }
395
396 parsed_region_chan->nr_chan = idx;
397
Holger Schurig9012b282007-05-25 11:27:16 -0400398 lbs_deb_11d("nrchan=%x\n", parsed_region_chan->nr_chan);
Holger Schurigece56192007-08-02 11:53:06 -0400399 lbs_deb_hex(LBS_DEB_11D, "parsed_region_chan", (u8 *) parsed_region_chan,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200400 2 + COUNTRY_CODE_LEN + sizeof(struct parsed_region_chan_11d) * idx);
401
Holger Schurig9012b282007-05-25 11:27:16 -0400402done:
403 lbs_deb_enter(LBS_DEB_11D);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200404 return 0;
405}
406
407/**
408 * @brief This function calculates the scan type for channels
409 * @param chan chan number
410 * @param parsed_region_chan pointer to parsed_region_chan_11d
411 * @return PASSIVE if chan is unknown; ACTIVE if chan is known
412*/
Holger Schurig10078322007-11-15 18:05:47 -0500413u8 lbs_get_scan_type_11d(u8 chan,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200414 struct parsed_region_chan_11d * parsed_region_chan)
415{
Dan Williams0aef64d2007-08-02 11:31:18 -0400416 u8 scan_type = CMD_SCAN_TYPE_PASSIVE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200417
Holger Schurig9012b282007-05-25 11:27:16 -0400418 lbs_deb_enter(LBS_DEB_11D);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200419
Holger Schurig10078322007-11-15 18:05:47 -0500420 if (lbs_channel_known_11d(chan, parsed_region_chan)) {
Holger Schurigece56192007-08-02 11:53:06 -0400421 lbs_deb_11d("found, do active scan\n");
Dan Williams0aef64d2007-08-02 11:31:18 -0400422 scan_type = CMD_SCAN_TYPE_ACTIVE;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200423 } else {
Holger Schurigece56192007-08-02 11:53:06 -0400424 lbs_deb_11d("not found, do passive scan\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200425 }
426
Holger Schurig9012b282007-05-25 11:27:16 -0400427 lbs_deb_leave_args(LBS_DEB_11D, "ret scan_type %d", scan_type);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200428 return scan_type;
429
430}
431
Holger Schurig69f90322007-11-23 15:43:44 +0100432void lbs_init_11d(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200433{
David Woodhouseaa21c002007-12-08 20:04:36 +0000434 priv->enable11d = 0;
435 memset(&(priv->parsed_region_chan), 0,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200436 sizeof(struct parsed_region_chan_11d));
437 return;
438}
439
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200440/**
441 * @brief This function sets DOMAIN INFO to FW
Holger Schurig69f90322007-11-23 15:43:44 +0100442 * @param priv pointer to struct lbs_private
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200443 * @return 0; -1
444*/
Holger Schurig69f90322007-11-23 15:43:44 +0100445static int set_domain_info_11d(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200446{
447 int ret;
448
David Woodhouseaa21c002007-12-08 20:04:36 +0000449 if (!priv->enable11d) {
Holger Schurigece56192007-08-02 11:53:06 -0400450 lbs_deb_11d("dnld domain Info with 11d disabled\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200451 return 0;
452 }
453
Holger Schurig10078322007-11-15 18:05:47 -0500454 ret = lbs_prepare_and_send_command(priv, CMD_802_11D_DOMAIN_INFO,
Dan Williams0aef64d2007-08-02 11:31:18 -0400455 CMD_ACT_SET,
456 CMD_OPTION_WAITFORRSP, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200457 if (ret)
Holger Schurigece56192007-08-02 11:53:06 -0400458 lbs_deb_11d("fail to dnld domain info\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200459
460 return ret;
461}
462
463/**
464 * @brief This function setups scan channels
Holger Schurig69f90322007-11-23 15:43:44 +0100465 * @param priv pointer to struct lbs_private
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200466 * @param band band
467 * @return 0
468*/
Holger Schurig69f90322007-11-23 15:43:44 +0100469int lbs_set_universaltable(struct lbs_private *priv, u8 band)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200470{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200471 u16 size = sizeof(struct chan_freq_power);
472 u16 i = 0;
473
David Woodhouseaa21c002007-12-08 20:04:36 +0000474 memset(priv->universal_channel, 0,
475 sizeof(priv->universal_channel));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200476
David Woodhouseaa21c002007-12-08 20:04:36 +0000477 priv->universal_channel[i].nrcfp =
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200478 sizeof(channel_freq_power_UN_BG) / size;
Holger Schurigece56192007-08-02 11:53:06 -0400479 lbs_deb_11d("BG-band nrcfp %d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000480 priv->universal_channel[i].nrcfp);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200481
David Woodhouseaa21c002007-12-08 20:04:36 +0000482 priv->universal_channel[i].CFP = channel_freq_power_UN_BG;
483 priv->universal_channel[i].valid = 1;
484 priv->universal_channel[i].region = UNIVERSAL_REGION_CODE;
485 priv->universal_channel[i].band = band;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200486 i++;
487
488 return 0;
489}
490
491/**
492 * @brief This function implements command CMD_802_11D_DOMAIN_INFO
Holger Schurig69f90322007-11-23 15:43:44 +0100493 * @param priv pointer to struct lbs_private
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200494 * @param cmd pointer to cmd buffer
495 * @param cmdno cmd ID
496 * @param cmdOption cmd action
497 * @return 0
498*/
Holger Schurig69f90322007-11-23 15:43:44 +0100499int lbs_cmd_802_11d_domain_info(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200500 struct cmd_ds_command *cmd, u16 cmdno,
501 u16 cmdoption)
502{
503 struct cmd_ds_802_11d_domain_info *pdomaininfo =
504 &cmd->params.domaininfo;
505 struct mrvlietypes_domainparamset *domain = &pdomaininfo->domain;
David Woodhouseaa21c002007-12-08 20:04:36 +0000506 u8 nr_subband = priv->domainreg.nr_subband;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200507
Holger Schurig9012b282007-05-25 11:27:16 -0400508 lbs_deb_enter(LBS_DEB_11D);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200509
Holger Schurig9012b282007-05-25 11:27:16 -0400510 lbs_deb_11d("nr_subband=%x\n", nr_subband);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200511
512 cmd->command = cpu_to_le16(cmdno);
513 pdomaininfo->action = cpu_to_le16(cmdoption);
Dan Williams0aef64d2007-08-02 11:31:18 -0400514 if (cmdoption == CMD_ACT_GET) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200515 cmd->size =
516 cpu_to_le16(sizeof(pdomaininfo->action) + S_DS_GEN);
Holger Schurigece56192007-08-02 11:53:06 -0400517 lbs_deb_hex(LBS_DEB_11D, "802_11D_DOMAIN_INFO", (u8 *) cmd,
Holger Schurigc2df2ef2007-12-07 15:30:44 +0000518 le16_to_cpu(cmd->size));
Holger Schurig9012b282007-05-25 11:27:16 -0400519 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200520 }
521
522 domain->header.type = cpu_to_le16(TLV_TYPE_DOMAIN);
David Woodhouseaa21c002007-12-08 20:04:36 +0000523 memcpy(domain->countrycode, priv->domainreg.countrycode,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200524 sizeof(domain->countrycode));
525
526 domain->header.len =
527 cpu_to_le16(nr_subband * sizeof(struct ieeetypes_subbandset) +
528 sizeof(domain->countrycode));
529
530 if (nr_subband) {
David Woodhouseaa21c002007-12-08 20:04:36 +0000531 memcpy(domain->subband, priv->domainreg.subband,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200532 nr_subband * sizeof(struct ieeetypes_subbandset));
533
534 cmd->size = cpu_to_le16(sizeof(pdomaininfo->action) +
Dan Williams8362cd42007-08-03 09:40:55 -0400535 le16_to_cpu(domain->header.len) +
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200536 sizeof(struct mrvlietypesheader) +
537 S_DS_GEN);
538 } else {
539 cmd->size =
540 cpu_to_le16(sizeof(pdomaininfo->action) + S_DS_GEN);
541 }
542
Holger Schurigece56192007-08-02 11:53:06 -0400543 lbs_deb_hex(LBS_DEB_11D, "802_11D_DOMAIN_INFO", (u8 *) cmd, le16_to_cpu(cmd->size));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200544
Holger Schurig9012b282007-05-25 11:27:16 -0400545done:
546 lbs_deb_enter(LBS_DEB_11D);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200547 return 0;
548}
549
550/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200551 * @brief This function parses countryinfo from AP and download country info to FW
Holger Schurig69f90322007-11-23 15:43:44 +0100552 * @param priv pointer to struct lbs_private
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200553 * @param resp pointer to command response buffer
554 * @return 0; -1
555 */
Holger Schurige98a88d2008-03-19 14:25:58 +0100556int lbs_ret_802_11d_domain_info(struct cmd_ds_command *resp)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200557{
David Woodhouse981f1872007-05-25 23:36:54 -0400558 struct cmd_ds_802_11d_domain_info *domaininfo = &resp->params.domaininforesp;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200559 struct mrvlietypes_domainparamset *domain = &domaininfo->domain;
560 u16 action = le16_to_cpu(domaininfo->action);
561 s16 ret = 0;
562 u8 nr_subband = 0;
563
Holger Schurig9012b282007-05-25 11:27:16 -0400564 lbs_deb_enter(LBS_DEB_11D);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200565
Holger Schurigece56192007-08-02 11:53:06 -0400566 lbs_deb_hex(LBS_DEB_11D, "domain info resp", (u8 *) resp,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200567 (int)le16_to_cpu(resp->size));
568
David Woodhouse981f1872007-05-25 23:36:54 -0400569 nr_subband = (le16_to_cpu(domain->header.len) - COUNTRY_CODE_LEN) /
570 sizeof(struct ieeetypes_subbandset);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200571
Holger Schurigece56192007-08-02 11:53:06 -0400572 lbs_deb_11d("domain info resp: nr_subband %d\n", nr_subband);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200573
574 if (nr_subband > MRVDRV_MAX_SUBBAND_802_11D) {
Holger Schurig9012b282007-05-25 11:27:16 -0400575 lbs_deb_11d("Invalid Numrer of Subband returned!!\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200576 return -1;
577 }
578
579 switch (action) {
Dan Williams0aef64d2007-08-02 11:31:18 -0400580 case CMD_ACT_SET: /*Proc Set action */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200581 break;
582
Dan Williams0aef64d2007-08-02 11:31:18 -0400583 case CMD_ACT_GET:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200584 break;
585 default:
Holger Schurig9012b282007-05-25 11:27:16 -0400586 lbs_deb_11d("Invalid action:%d\n", domaininfo->action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200587 ret = -1;
588 break;
589 }
590
Holger Schurig9012b282007-05-25 11:27:16 -0400591 lbs_deb_leave_args(LBS_DEB_11D, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200592 return ret;
593}
594
595/**
596 * @brief This function parses countryinfo from AP and download country info to FW
Holger Schurig69f90322007-11-23 15:43:44 +0100597 * @param priv pointer to struct lbs_private
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200598 * @return 0; -1
599 */
Holger Schurig69f90322007-11-23 15:43:44 +0100600int lbs_parse_dnld_countryinfo_11d(struct lbs_private *priv,
Dan Williamse76850d2007-05-25 17:09:41 -0400601 struct bss_descriptor * bss)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200602{
603 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200604
Holger Schurig9012b282007-05-25 11:27:16 -0400605 lbs_deb_enter(LBS_DEB_11D);
David Woodhouseaa21c002007-12-08 20:04:36 +0000606 if (priv->enable11d) {
607 memset(&priv->parsed_region_chan, 0,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200608 sizeof(struct parsed_region_chan_11d));
Dan Williamse76850d2007-05-25 17:09:41 -0400609 ret = parse_domain_info_11d(&bss->countryinfo, 0,
David Woodhouseaa21c002007-12-08 20:04:36 +0000610 &priv->parsed_region_chan);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200611
612 if (ret == -1) {
Holger Schurigece56192007-08-02 11:53:06 -0400613 lbs_deb_11d("error parsing domain_info from AP\n");
Holger Schurig9012b282007-05-25 11:27:16 -0400614 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200615 }
616
David Woodhouseaa21c002007-12-08 20:04:36 +0000617 memset(&priv->domainreg, 0,
Holger Schurig10078322007-11-15 18:05:47 -0500618 sizeof(struct lbs_802_11d_domain_reg));
David Woodhouseaa21c002007-12-08 20:04:36 +0000619 generate_domain_info_11d(&priv->parsed_region_chan,
620 &priv->domainreg);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200621
622 ret = set_domain_info_11d(priv);
623
624 if (ret) {
Holger Schurigece56192007-08-02 11:53:06 -0400625 lbs_deb_11d("error setting domain info\n");
Holger Schurig9012b282007-05-25 11:27:16 -0400626 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200627 }
628 }
Holger Schurig9012b282007-05-25 11:27:16 -0400629 ret = 0;
630
631done:
632 lbs_deb_leave_args(LBS_DEB_11D, "ret %d", ret);
633 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200634}
635
636/**
637 * @brief This function generates 11D info from user specified regioncode and download to FW
Holger Schurig69f90322007-11-23 15:43:44 +0100638 * @param priv pointer to struct lbs_private
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200639 * @return 0; -1
640 */
Holger Schurig69f90322007-11-23 15:43:44 +0100641int lbs_create_dnld_countryinfo_11d(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200642{
643 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200644 struct region_channel *region_chan;
645 u8 j;
646
Holger Schurig9012b282007-05-25 11:27:16 -0400647 lbs_deb_enter(LBS_DEB_11D);
David Woodhouseaa21c002007-12-08 20:04:36 +0000648 lbs_deb_11d("curbssparams.band %d\n", priv->curbssparams.band);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200649
David Woodhouseaa21c002007-12-08 20:04:36 +0000650 if (priv->enable11d) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200651 /* update parsed_region_chan_11; dnld domaininf to FW */
652
David Woodhouseaa21c002007-12-08 20:04:36 +0000653 for (j = 0; j < ARRAY_SIZE(priv->region_channel); j++) {
654 region_chan = &priv->region_channel[j];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200655
Holger Schurigece56192007-08-02 11:53:06 -0400656 lbs_deb_11d("%d region_chan->band %d\n", j,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200657 region_chan->band);
658
659 if (!region_chan || !region_chan->valid
660 || !region_chan->CFP)
661 continue;
David Woodhouseaa21c002007-12-08 20:04:36 +0000662 if (region_chan->band != priv->curbssparams.band)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200663 continue;
664 break;
665 }
666
David Woodhouseaa21c002007-12-08 20:04:36 +0000667 if (j >= ARRAY_SIZE(priv->region_channel)) {
Holger Schurigece56192007-08-02 11:53:06 -0400668 lbs_deb_11d("region_chan not found, band %d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +0000669 priv->curbssparams.band);
Holger Schurig9012b282007-05-25 11:27:16 -0400670 ret = -1;
671 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200672 }
673
David Woodhouseaa21c002007-12-08 20:04:36 +0000674 memset(&priv->parsed_region_chan, 0,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200675 sizeof(struct parsed_region_chan_11d));
Holger Schurig10078322007-11-15 18:05:47 -0500676 lbs_generate_parsed_region_chan_11d(region_chan,
David Woodhouseaa21c002007-12-08 20:04:36 +0000677 &priv->
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200678 parsed_region_chan);
679
David Woodhouseaa21c002007-12-08 20:04:36 +0000680 memset(&priv->domainreg, 0,
Holger Schurig10078322007-11-15 18:05:47 -0500681 sizeof(struct lbs_802_11d_domain_reg));
David Woodhouseaa21c002007-12-08 20:04:36 +0000682 generate_domain_info_11d(&priv->parsed_region_chan,
683 &priv->domainreg);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200684
685 ret = set_domain_info_11d(priv);
686
687 if (ret) {
Holger Schurigece56192007-08-02 11:53:06 -0400688 lbs_deb_11d("error setting domain info\n");
Holger Schurig9012b282007-05-25 11:27:16 -0400689 goto done;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200690 }
691
692 }
Holger Schurig9012b282007-05-25 11:27:16 -0400693 ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200694
Holger Schurig9012b282007-05-25 11:27:16 -0400695done:
696 lbs_deb_leave_args(LBS_DEB_11D, "ret %d", ret);
697 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200698}