2 * This file contains functions for 802.11D.
4 #include <linux/ctype.h>
5 #include <linux/kernel.h>
6 #include <linux/wireless.h>
14 #define TX_PWR_DEFAULT 10
16 static 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 */
28 /* Following 2 structure defines the supported channels */
29 static 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
}
46 static u8
lbs_region_2_code(u8
*region
)
50 for (i
= 0; region
[i
] && i
< COUNTRY_CODE_LEN
; i
++)
51 region
[i
] = toupper(region
[i
]);
53 for (i
= 0; i
< ARRAY_SIZE(region_code_mapping
); i
++) {
54 if (!memcmp(region
, region_code_mapping
[i
].region
,
56 return (region_code_mapping
[i
].code
);
60 return (region_code_mapping
[0].code
);
63 static u8
*lbs_code_2_region(u8 code
)
67 for (i
= 0; i
< ARRAY_SIZE(region_code_mapping
); i
++) {
68 if (region_code_mapping
[i
].code
== code
)
69 return (region_code_mapping
[i
].region
);
72 return (region_code_mapping
[0].region
);
76 * @brief This function finds the nrchan-th chan after the firstchan
78 * @param firstchan first channel number
79 * @param nrchan number of channels
80 * @return the nrchan-th chan number
82 static u8
lbs_get_chan_11d(u8 firstchan
, u8 nrchan
, u8
*chan
)
83 /*find the nrchan-th chan after the firstchan*/
86 struct chan_freq_power
*cfp
;
89 cfp
= channel_freq_power_UN_BG
;
90 cfp_no
= ARRAY_SIZE(channel_freq_power_UN_BG
);
92 for (i
= 0; i
< cfp_no
; i
++) {
93 if ((cfp
+ i
)->channel
== firstchan
) {
94 lbs_deb_11d("firstchan found\n");
100 /*if beyond the boundary */
101 if (i
+ nrchan
< cfp_no
) {
102 *chan
= (cfp
+ i
+ nrchan
)->channel
;
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
116 static u8
lbs_channel_known_11d(u8 chan
,
117 struct parsed_region_chan_11d
* parsed_region_chan
)
119 struct chan_power_11d
*chanpwr
= parsed_region_chan
->chanpwr
;
120 u8 nr_chan
= parsed_region_chan
->nr_chan
;
123 lbs_deb_hex(LBS_DEB_11D
, "parsed_region_chan", (char *)chanpwr
,
124 sizeof(struct chan_power_11d
) * nr_chan
);
126 for (i
= 0; i
< nr_chan
; i
++) {
127 if (chan
== chanpwr
[i
].chan
) {
128 lbs_deb_11d("found chan %d\n", chan
);
133 lbs_deb_11d("chan %d not found\n", chan
);
137 u32
lbs_chan_2_freq(u8 chan
)
139 struct chan_freq_power
*cf
;
143 cf
= channel_freq_power_UN_BG
;
145 for (i
= 0; i
< ARRAY_SIZE(channel_freq_power_UN_BG
); i
++) {
146 if (chan
== cf
[i
].channel
)
153 static int generate_domain_info_11d(struct parsed_region_chan_11d
155 struct lbs_802_11d_domain_reg
*domaininfo
)
159 u8 nr_chan
= parsed_region_chan
->nr_chan
;
160 u8 nr_parsedchan
= 0;
162 u8 firstchan
= 0, nextchan
= 0, maxpwr
= 0;
166 memcpy(domaininfo
->countrycode
, parsed_region_chan
->countrycode
,
169 lbs_deb_11d("nrchan %d\n", nr_chan
);
170 lbs_deb_hex(LBS_DEB_11D
, "parsed_region_chan", (char *)parsed_region_chan
,
171 sizeof(struct parsed_region_chan_11d
));
173 for (i
= 0; i
< nr_chan
; i
++) {
176 nextchan
= firstchan
=
177 parsed_region_chan
->chanpwr
[i
].chan
;
178 maxpwr
= parsed_region_chan
->chanpwr
[i
].pwr
;
183 if (parsed_region_chan
->chanpwr
[i
].chan
== nextchan
+ 1 &&
184 parsed_region_chan
->chanpwr
[i
].pwr
== maxpwr
) {
188 domaininfo
->subband
[nr_subband
].firstchan
= firstchan
;
189 domaininfo
->subband
[nr_subband
].nrchan
=
191 domaininfo
->subband
[nr_subband
].maxtxpwr
= maxpwr
;
193 nextchan
= firstchan
=
194 parsed_region_chan
->chanpwr
[i
].chan
;
195 maxpwr
= parsed_region_chan
->chanpwr
[i
].pwr
;
200 domaininfo
->subband
[nr_subband
].firstchan
= firstchan
;
201 domaininfo
->subband
[nr_subband
].nrchan
= nr_parsedchan
;
202 domaininfo
->subband
[nr_subband
].maxtxpwr
= maxpwr
;
205 domaininfo
->nr_subband
= nr_subband
;
207 lbs_deb_11d("nr_subband=%x\n", domaininfo
->nr_subband
);
208 lbs_deb_hex(LBS_DEB_11D
, "domaininfo", (char *)domaininfo
,
209 COUNTRY_CODE_LEN
+ 1 +
210 sizeof(struct ieeetypes_subbandset
) * nr_subband
);
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
220 static void lbs_generate_parsed_region_chan_11d(struct region_channel
*region_chan
,
221 struct parsed_region_chan_11d
*
225 struct chan_freq_power
*cfp
;
227 if (region_chan
== NULL
) {
228 lbs_deb_11d("region_chan is NULL\n");
232 cfp
= region_chan
->CFP
;
234 lbs_deb_11d("cfp is NULL \n");
238 parsed_region_chan
->band
= region_chan
->band
;
239 parsed_region_chan
->region
= region_chan
->region
;
240 memcpy(parsed_region_chan
->countrycode
,
241 lbs_code_2_region(region_chan
->region
), COUNTRY_CODE_LEN
);
243 lbs_deb_11d("region 0x%x, band %d\n", parsed_region_chan
->region
,
244 parsed_region_chan
->band
);
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
;
249 lbs_deb_11d("chan %d, pwr %d\n",
250 parsed_region_chan
->chanpwr
[i
].chan
,
251 parsed_region_chan
->chanpwr
[i
].pwr
);
253 parsed_region_chan
->nr_chan
= region_chan
->nrcfp
;
255 lbs_deb_11d("nrchan %d\n", parsed_region_chan
->nr_chan
);
261 * @brief generate parsed_region_chan from Domain Info learned from AP/IBSS
262 * @param region region ID
267 static u8
lbs_region_chan_supported_11d(u8 region
, u8 chan
)
269 struct chan_freq_power
*cfp
;
274 lbs_deb_enter(LBS_DEB_11D
);
276 cfp
= lbs_get_region_cfp_table(region
, &cfp_no
);
280 for (idx
= 0; idx
< cfp_no
; idx
++) {
281 if (chan
== (cfp
+ idx
)->channel
) {
282 /* If Mrvl Chip Supported? */
283 if ((cfp
+ idx
)->unsupported
) {
292 /*chan is not in the region table */
295 lbs_deb_leave_args(LBS_DEB_11D
, "ret %d", ret
);
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
305 static int parse_domain_info_11d(struct ieeetypes_countryinfofullset
*
308 struct parsed_region_chan_11d
*
311 u8 nr_subband
, nrchan
;
312 u8 lastchan
, firstchan
;
316 u8 idx
= 0; /*chan index in parsed_region_chan */
320 lbs_deb_enter(LBS_DEB_11D
);
324 2. First Chan increment
325 3. channel range no overlap
327 5. channel is supported by region?
331 lbs_deb_hex(LBS_DEB_11D
, "countryinfo", (u8
*) countryinfo
, 30);
333 if ((*(countryinfo
->countrycode
)) == 0
334 || (countryinfo
->len
<= COUNTRY_CODE_LEN
)) {
335 /* No region Info or Wrong region info: treat as No 11D info */
339 /*Step1: check region_code */
340 parsed_region_chan
->region
= region
=
341 lbs_region_2_code(countryinfo
->countrycode
);
343 lbs_deb_11d("regioncode=%x\n", (u8
) parsed_region_chan
->region
);
344 lbs_deb_hex(LBS_DEB_11D
, "countrycode", (char *)countryinfo
->countrycode
,
347 parsed_region_chan
->band
= band
;
349 memcpy(parsed_region_chan
->countrycode
, countryinfo
->countrycode
,
352 nr_subband
= (countryinfo
->len
- COUNTRY_CODE_LEN
) /
353 sizeof(struct ieeetypes_subbandset
);
355 for (j
= 0, lastchan
= 0; j
< nr_subband
; j
++) {
357 if (countryinfo
->subband
[j
].firstchan
<= lastchan
) {
358 /*Step2&3. Check First Chan Num increment and no overlap */
359 lbs_deb_11d("chan %d>%d, overlap\n",
360 countryinfo
->subband
[j
].firstchan
, lastchan
);
364 firstchan
= countryinfo
->subband
[j
].firstchan
;
365 nrchan
= countryinfo
->subband
[j
].nrchan
;
367 for (i
= 0; idx
< MAX_NO_OF_CHAN
&& i
< nrchan
; i
++) {
368 /*step4: channel is supported? */
370 if (!lbs_get_chan_11d(firstchan
, i
, &curchan
)) {
371 /* Chan is not found in UN table */
372 lbs_deb_11d("chan is not supported: %d \n", i
);
378 if (lbs_region_chan_supported_11d(region
, curchan
)) {
379 /*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
;
385 /*not supported and ignore the chan */
387 "i %d, chan %d unsupported in region %x, band %d\n",
388 i
, curchan
, region
, band
);
392 /*Step6: Add other checking if any */
396 parsed_region_chan
->nr_chan
= idx
;
398 lbs_deb_11d("nrchan=%x\n", parsed_region_chan
->nr_chan
);
399 lbs_deb_hex(LBS_DEB_11D
, "parsed_region_chan", (u8
*) parsed_region_chan
,
400 2 + COUNTRY_CODE_LEN
+ sizeof(struct parsed_region_chan_11d
) * idx
);
403 lbs_deb_enter(LBS_DEB_11D
);
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
413 u8
lbs_get_scan_type_11d(u8 chan
,
414 struct parsed_region_chan_11d
* parsed_region_chan
)
416 u8 scan_type
= CMD_SCAN_TYPE_PASSIVE
;
418 lbs_deb_enter(LBS_DEB_11D
);
420 if (lbs_channel_known_11d(chan
, parsed_region_chan
)) {
421 lbs_deb_11d("found, do active scan\n");
422 scan_type
= CMD_SCAN_TYPE_ACTIVE
;
424 lbs_deb_11d("not found, do passive scan\n");
427 lbs_deb_leave_args(LBS_DEB_11D
, "ret scan_type %d", scan_type
);
432 void lbs_init_11d(struct lbs_private
*priv
)
435 memset(&(priv
->parsed_region_chan
), 0,
436 sizeof(struct parsed_region_chan_11d
));
441 * @brief This function sets DOMAIN INFO to FW
442 * @param priv pointer to struct lbs_private
445 static int set_domain_info_11d(struct lbs_private
*priv
)
449 if (!priv
->enable11d
) {
450 lbs_deb_11d("dnld domain Info with 11d disabled\n");
454 ret
= lbs_prepare_and_send_command(priv
, CMD_802_11D_DOMAIN_INFO
,
456 CMD_OPTION_WAITFORRSP
, 0, NULL
);
458 lbs_deb_11d("fail to dnld domain info\n");
464 * @brief This function setups scan channels
465 * @param priv pointer to struct lbs_private
469 int lbs_set_universaltable(struct lbs_private
*priv
, u8 band
)
471 u16 size
= sizeof(struct chan_freq_power
);
474 memset(priv
->universal_channel
, 0,
475 sizeof(priv
->universal_channel
));
477 priv
->universal_channel
[i
].nrcfp
=
478 sizeof(channel_freq_power_UN_BG
) / size
;
479 lbs_deb_11d("BG-band nrcfp %d\n",
480 priv
->universal_channel
[i
].nrcfp
);
482 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
;
492 * @brief This function implements command CMD_802_11D_DOMAIN_INFO
493 * @param priv pointer to struct lbs_private
494 * @param cmd pointer to cmd buffer
495 * @param cmdno cmd ID
496 * @param cmdOption cmd action
499 int lbs_cmd_802_11d_domain_info(struct lbs_private
*priv
,
500 struct cmd_ds_command
*cmd
, u16 cmdno
,
503 struct cmd_ds_802_11d_domain_info
*pdomaininfo
=
504 &cmd
->params
.domaininfo
;
505 struct mrvlietypes_domainparamset
*domain
= &pdomaininfo
->domain
;
506 u8 nr_subband
= priv
->domainreg
.nr_subband
;
508 lbs_deb_enter(LBS_DEB_11D
);
510 lbs_deb_11d("nr_subband=%x\n", nr_subband
);
512 cmd
->command
= cpu_to_le16(cmdno
);
513 pdomaininfo
->action
= cpu_to_le16(cmdoption
);
514 if (cmdoption
== CMD_ACT_GET
) {
516 cpu_to_le16(sizeof(pdomaininfo
->action
) + S_DS_GEN
);
517 lbs_deb_hex(LBS_DEB_11D
, "802_11D_DOMAIN_INFO", (u8
*) cmd
,
518 le16_to_cpu(cmd
->size
));
522 domain
->header
.type
= cpu_to_le16(TLV_TYPE_DOMAIN
);
523 memcpy(domain
->countrycode
, priv
->domainreg
.countrycode
,
524 sizeof(domain
->countrycode
));
527 cpu_to_le16(nr_subband
* sizeof(struct ieeetypes_subbandset
) +
528 sizeof(domain
->countrycode
));
531 memcpy(domain
->subband
, priv
->domainreg
.subband
,
532 nr_subband
* sizeof(struct ieeetypes_subbandset
));
534 cmd
->size
= cpu_to_le16(sizeof(pdomaininfo
->action
) +
535 le16_to_cpu(domain
->header
.len
) +
536 sizeof(struct mrvlietypesheader
) +
540 cpu_to_le16(sizeof(pdomaininfo
->action
) + S_DS_GEN
);
543 lbs_deb_hex(LBS_DEB_11D
, "802_11D_DOMAIN_INFO", (u8
*) cmd
, le16_to_cpu(cmd
->size
));
546 lbs_deb_enter(LBS_DEB_11D
);
551 * @brief This function parses countryinfo from AP and download country info to FW
552 * @param priv pointer to struct lbs_private
553 * @param resp pointer to command response buffer
556 int lbs_ret_802_11d_domain_info(struct cmd_ds_command
*resp
)
558 struct cmd_ds_802_11d_domain_info
*domaininfo
= &resp
->params
.domaininforesp
;
559 struct mrvlietypes_domainparamset
*domain
= &domaininfo
->domain
;
560 u16 action
= le16_to_cpu(domaininfo
->action
);
564 lbs_deb_enter(LBS_DEB_11D
);
566 lbs_deb_hex(LBS_DEB_11D
, "domain info resp", (u8
*) resp
,
567 (int)le16_to_cpu(resp
->size
));
569 nr_subband
= (le16_to_cpu(domain
->header
.len
) - COUNTRY_CODE_LEN
) /
570 sizeof(struct ieeetypes_subbandset
);
572 lbs_deb_11d("domain info resp: nr_subband %d\n", nr_subband
);
574 if (nr_subband
> MRVDRV_MAX_SUBBAND_802_11D
) {
575 lbs_deb_11d("Invalid Numrer of Subband returned!!\n");
580 case CMD_ACT_SET
: /*Proc Set action */
586 lbs_deb_11d("Invalid action:%d\n", domaininfo
->action
);
591 lbs_deb_leave_args(LBS_DEB_11D
, "ret %d", ret
);
596 * @brief This function parses countryinfo from AP and download country info to FW
597 * @param priv pointer to struct lbs_private
600 int lbs_parse_dnld_countryinfo_11d(struct lbs_private
*priv
,
601 struct bss_descriptor
* bss
)
605 lbs_deb_enter(LBS_DEB_11D
);
606 if (priv
->enable11d
) {
607 memset(&priv
->parsed_region_chan
, 0,
608 sizeof(struct parsed_region_chan_11d
));
609 ret
= parse_domain_info_11d(&bss
->countryinfo
, 0,
610 &priv
->parsed_region_chan
);
613 lbs_deb_11d("error parsing domain_info from AP\n");
617 memset(&priv
->domainreg
, 0,
618 sizeof(struct lbs_802_11d_domain_reg
));
619 generate_domain_info_11d(&priv
->parsed_region_chan
,
622 ret
= set_domain_info_11d(priv
);
625 lbs_deb_11d("error setting domain info\n");
632 lbs_deb_leave_args(LBS_DEB_11D
, "ret %d", ret
);
637 * @brief This function generates 11D info from user specified regioncode and download to FW
638 * @param priv pointer to struct lbs_private
641 int lbs_create_dnld_countryinfo_11d(struct lbs_private
*priv
)
644 struct region_channel
*region_chan
;
647 lbs_deb_enter(LBS_DEB_11D
);
648 lbs_deb_11d("curbssparams.band %d\n", priv
->curbssparams
.band
);
650 if (priv
->enable11d
) {
651 /* update parsed_region_chan_11; dnld domaininf to FW */
653 for (j
= 0; j
< ARRAY_SIZE(priv
->region_channel
); j
++) {
654 region_chan
= &priv
->region_channel
[j
];
656 lbs_deb_11d("%d region_chan->band %d\n", j
,
659 if (!region_chan
|| !region_chan
->valid
660 || !region_chan
->CFP
)
662 if (region_chan
->band
!= priv
->curbssparams
.band
)
667 if (j
>= ARRAY_SIZE(priv
->region_channel
)) {
668 lbs_deb_11d("region_chan not found, band %d\n",
669 priv
->curbssparams
.band
);
674 memset(&priv
->parsed_region_chan
, 0,
675 sizeof(struct parsed_region_chan_11d
));
676 lbs_generate_parsed_region_chan_11d(region_chan
,
680 memset(&priv
->domainreg
, 0,
681 sizeof(struct lbs_802_11d_domain_reg
));
682 generate_domain_info_11d(&priv
->parsed_region_chan
,
685 ret
= set_domain_info_11d(priv
);
688 lbs_deb_11d("error setting domain info\n");
696 lbs_deb_leave_args(LBS_DEB_11D
, "ret %d", ret
);