2 * This file contains functions for 802.11D.
4 #include <linux/ctype.h>
5 #include <linux/kernel.h>
6 #include <linux/wireless.h>
15 #define TX_PWR_DEFAULT 10
17 static struct region_code_mapping region_code_mapping[] = {
18 {"US ", 0x10}, /* US FCC */
19 {"CA ", 0x10}, /* IC Canada */
20 {"SG ", 0x10}, /* Singapore */
21 {"EU ", 0x30}, /* ETSI */
22 {"AU ", 0x30}, /* Australia */
23 {"KR ", 0x30}, /* Republic Of Korea */
24 {"ES ", 0x31}, /* Spain */
25 {"FR ", 0x32}, /* France */
26 {"JP ", 0x40}, /* Japan */
29 /* Following 2 structure defines the supported channels */
30 static struct chan_freq_power channel_freq_power_UN_BG[] = {
31 {1, 2412, TX_PWR_DEFAULT},
32 {2, 2417, TX_PWR_DEFAULT},
33 {3, 2422, TX_PWR_DEFAULT},
34 {4, 2427, TX_PWR_DEFAULT},
35 {5, 2432, TX_PWR_DEFAULT},
36 {6, 2437, TX_PWR_DEFAULT},
37 {7, 2442, TX_PWR_DEFAULT},
38 {8, 2447, TX_PWR_DEFAULT},
39 {9, 2452, TX_PWR_DEFAULT},
40 {10, 2457, TX_PWR_DEFAULT},
41 {11, 2462, TX_PWR_DEFAULT},
42 {12, 2467, TX_PWR_DEFAULT},
43 {13, 2472, TX_PWR_DEFAULT},
44 {14, 2484, TX_PWR_DEFAULT}
47 static u8 lbs_region_2_code(u8 *region)
51 for (i = 0; i < COUNTRY_CODE_LEN && region[i]; i++)
52 region[i] = toupper(region[i]);
54 for (i = 0; i < ARRAY_SIZE(region_code_mapping); i++) {
55 if (!memcmp(region, region_code_mapping[i].region,
57 return (region_code_mapping[i].code);
61 return (region_code_mapping[0].code);
64 static u8 *lbs_code_2_region(u8 code)
68 for (i = 0; i < ARRAY_SIZE(region_code_mapping); i++) {
69 if (region_code_mapping[i].code == code)
70 return (region_code_mapping[i].region);
73 return (region_code_mapping[0].region);
77 * @brief This function finds the nrchan-th chan after the firstchan
79 * @param firstchan first channel number
80 * @param nrchan number of channels
81 * @return the nrchan-th chan number
83 static u8 lbs_get_chan_11d(u8 firstchan, u8 nrchan, u8 *chan)
84 /*find the nrchan-th chan after the firstchan*/
87 struct chan_freq_power *cfp;
90 cfp = channel_freq_power_UN_BG;
91 cfp_no = ARRAY_SIZE(channel_freq_power_UN_BG);
93 for (i = 0; i < cfp_no; i++) {
94 if ((cfp + i)->channel == firstchan) {
95 lbs_deb_11d("firstchan found\n");
101 /*if beyond the boundary */
102 if (i + nrchan < cfp_no) {
103 *chan = (cfp + i + nrchan)->channel;
112 * @brief This function Checks if chan txpwr is learned from AP/IBSS
113 * @param chan chan number
114 * @param parsed_region_chan pointer to parsed_region_chan_11d
115 * @return TRUE; FALSE
117 static u8 lbs_channel_known_11d(u8 chan,
118 struct parsed_region_chan_11d * parsed_region_chan)
120 struct chan_power_11d *chanpwr = parsed_region_chan->chanpwr;
121 u8 nr_chan = parsed_region_chan->nr_chan;
124 lbs_deb_hex(LBS_DEB_11D, "parsed_region_chan", (char *)chanpwr,
125 sizeof(struct chan_power_11d) * nr_chan);
127 for (i = 0; i < nr_chan; i++) {
128 if (chan == chanpwr[i].chan) {
129 lbs_deb_11d("found chan %d\n", chan);
134 lbs_deb_11d("chan %d not found\n", chan);
138 u32 lbs_chan_2_freq(u8 chan)
140 struct chan_freq_power *cf;
144 cf = channel_freq_power_UN_BG;
146 for (i = 0; i < ARRAY_SIZE(channel_freq_power_UN_BG); i++) {
147 if (chan == cf[i].channel)
154 static int generate_domain_info_11d(struct parsed_region_chan_11d
156 struct lbs_802_11d_domain_reg *domaininfo)
160 u8 nr_chan = parsed_region_chan->nr_chan;
161 u8 nr_parsedchan = 0;
163 u8 firstchan = 0, nextchan = 0, maxpwr = 0;
167 memcpy(domaininfo->countrycode, parsed_region_chan->countrycode,
170 lbs_deb_11d("nrchan %d\n", nr_chan);
171 lbs_deb_hex(LBS_DEB_11D, "parsed_region_chan", (char *)parsed_region_chan,
172 sizeof(struct parsed_region_chan_11d));
174 for (i = 0; i < nr_chan; i++) {
177 nextchan = firstchan =
178 parsed_region_chan->chanpwr[i].chan;
179 maxpwr = parsed_region_chan->chanpwr[i].pwr;
184 if (parsed_region_chan->chanpwr[i].chan == nextchan + 1 &&
185 parsed_region_chan->chanpwr[i].pwr == maxpwr) {
189 domaininfo->subband[nr_subband].firstchan = firstchan;
190 domaininfo->subband[nr_subband].nrchan =
192 domaininfo->subband[nr_subband].maxtxpwr = maxpwr;
194 nextchan = firstchan =
195 parsed_region_chan->chanpwr[i].chan;
196 maxpwr = parsed_region_chan->chanpwr[i].pwr;
201 domaininfo->subband[nr_subband].firstchan = firstchan;
202 domaininfo->subband[nr_subband].nrchan = nr_parsedchan;
203 domaininfo->subband[nr_subband].maxtxpwr = maxpwr;
206 domaininfo->nr_subband = nr_subband;
208 lbs_deb_11d("nr_subband=%x\n", domaininfo->nr_subband);
209 lbs_deb_hex(LBS_DEB_11D, "domaininfo", (char *)domaininfo,
210 COUNTRY_CODE_LEN + 1 +
211 sizeof(struct ieee_subbandset) * nr_subband);
216 * @brief This function generates parsed_region_chan from Domain Info learned from AP/IBSS
217 * @param region_chan pointer to struct region_channel
218 * @param *parsed_region_chan pointer to parsed_region_chan_11d
221 static void lbs_generate_parsed_region_chan_11d(struct region_channel *region_chan,
222 struct parsed_region_chan_11d *
226 struct chan_freq_power *cfp;
228 if (region_chan == NULL) {
229 lbs_deb_11d("region_chan is NULL\n");
233 cfp = region_chan->CFP;
235 lbs_deb_11d("cfp is NULL \n");
239 parsed_region_chan->band = region_chan->band;
240 parsed_region_chan->region = region_chan->region;
241 memcpy(parsed_region_chan->countrycode,
242 lbs_code_2_region(region_chan->region), COUNTRY_CODE_LEN);
244 lbs_deb_11d("region 0x%x, band %d\n", parsed_region_chan->region,
245 parsed_region_chan->band);
247 for (i = 0; i < region_chan->nrcfp; i++, cfp++) {
248 parsed_region_chan->chanpwr[i].chan = cfp->channel;
249 parsed_region_chan->chanpwr[i].pwr = cfp->maxtxpower;
250 lbs_deb_11d("chan %d, pwr %d\n",
251 parsed_region_chan->chanpwr[i].chan,
252 parsed_region_chan->chanpwr[i].pwr);
254 parsed_region_chan->nr_chan = region_chan->nrcfp;
256 lbs_deb_11d("nrchan %d\n", parsed_region_chan->nr_chan);
262 * @brief generate parsed_region_chan from Domain Info learned from AP/IBSS
263 * @param region region ID
268 static u8 lbs_region_chan_supported_11d(u8 region, u8 chan)
270 struct chan_freq_power *cfp;
275 lbs_deb_enter(LBS_DEB_11D);
277 cfp = lbs_get_region_cfp_table(region, &cfp_no);
281 for (idx = 0; idx < cfp_no; idx++) {
282 if (chan == (cfp + idx)->channel) {
283 /* If Mrvl Chip Supported? */
284 if ((cfp + idx)->unsupported) {
293 /*chan is not in the region table */
296 lbs_deb_leave_args(LBS_DEB_11D, "ret %d", ret);
301 * @brief This function checks if chan txpwr is learned from AP/IBSS
302 * @param chan chan number
303 * @param parsed_region_chan pointer to parsed_region_chan_11d
306 static int parse_domain_info_11d(struct ieee_ie_country_info_full_set *countryinfo,
308 struct parsed_region_chan_11d *parsed_region_chan)
310 u8 nr_subband, nrchan;
311 u8 lastchan, firstchan;
315 u8 idx = 0; /*chan index in parsed_region_chan */
319 lbs_deb_enter(LBS_DEB_11D);
323 2. First Chan increment
324 3. channel range no overlap
326 5. channel is supported by region?
330 lbs_deb_hex(LBS_DEB_11D, "countryinfo", (u8 *) countryinfo, 30);
332 if ((*(countryinfo->countrycode)) == 0
333 || (countryinfo->header.len <= COUNTRY_CODE_LEN)) {
334 /* No region Info or Wrong region info: treat as No 11D info */
338 /*Step1: check region_code */
339 parsed_region_chan->region = region =
340 lbs_region_2_code(countryinfo->countrycode);
342 lbs_deb_11d("regioncode=%x\n", (u8) parsed_region_chan->region);
343 lbs_deb_hex(LBS_DEB_11D, "countrycode", (char *)countryinfo->countrycode,
346 parsed_region_chan->band = band;
348 memcpy(parsed_region_chan->countrycode, countryinfo->countrycode,
351 nr_subband = (countryinfo->header.len - COUNTRY_CODE_LEN) /
352 sizeof(struct ieee_subbandset);
354 for (j = 0, lastchan = 0; j < nr_subband; j++) {
356 if (countryinfo->subband[j].firstchan <= lastchan) {
357 /*Step2&3. Check First Chan Num increment and no overlap */
358 lbs_deb_11d("chan %d>%d, overlap\n",
359 countryinfo->subband[j].firstchan, lastchan);
363 firstchan = countryinfo->subband[j].firstchan;
364 nrchan = countryinfo->subband[j].nrchan;
366 for (i = 0; idx < MAX_NO_OF_CHAN && i < nrchan; i++) {
367 /*step4: channel is supported? */
369 if (!lbs_get_chan_11d(firstchan, i, &curchan)) {
370 /* Chan is not found in UN table */
371 lbs_deb_11d("chan is not supported: %d \n", i);
377 if (lbs_region_chan_supported_11d(region, curchan)) {
378 /*step5: Check if curchan is supported by mrvl in region */
379 parsed_region_chan->chanpwr[idx].chan = curchan;
380 parsed_region_chan->chanpwr[idx].pwr =
381 countryinfo->subband[j].maxtxpwr;
384 /*not supported and ignore the chan */
386 "i %d, chan %d unsupported in region %x, band %d\n",
387 i, curchan, region, band);
391 /*Step6: Add other checking if any */
395 parsed_region_chan->nr_chan = idx;
397 lbs_deb_11d("nrchan=%x\n", parsed_region_chan->nr_chan);
398 lbs_deb_hex(LBS_DEB_11D, "parsed_region_chan", (u8 *) parsed_region_chan,
399 2 + COUNTRY_CODE_LEN + sizeof(struct parsed_region_chan_11d) * idx);
402 lbs_deb_enter(LBS_DEB_11D);
407 * @brief This function calculates the scan type for channels
408 * @param chan chan number
409 * @param parsed_region_chan pointer to parsed_region_chan_11d
410 * @return PASSIVE if chan is unknown; ACTIVE if chan is known
412 u8 lbs_get_scan_type_11d(u8 chan,
413 struct parsed_region_chan_11d * parsed_region_chan)
415 u8 scan_type = CMD_SCAN_TYPE_PASSIVE;
417 lbs_deb_enter(LBS_DEB_11D);
419 if (lbs_channel_known_11d(chan, parsed_region_chan)) {
420 lbs_deb_11d("found, do active scan\n");
421 scan_type = CMD_SCAN_TYPE_ACTIVE;
423 lbs_deb_11d("not found, do passive scan\n");
426 lbs_deb_leave_args(LBS_DEB_11D, "ret scan_type %d", scan_type);
431 void lbs_init_11d(struct lbs_private *priv)
434 memset(&(priv->parsed_region_chan), 0,
435 sizeof(struct parsed_region_chan_11d));
440 * @brief This function sets DOMAIN INFO to FW
441 * @param priv pointer to struct lbs_private
444 static int set_domain_info_11d(struct lbs_private *priv)
448 if (!priv->enable11d) {
449 lbs_deb_11d("dnld domain Info with 11d disabled\n");
453 ret = lbs_prepare_and_send_command(priv, CMD_802_11D_DOMAIN_INFO,
455 CMD_OPTION_WAITFORRSP, 0, NULL);
457 lbs_deb_11d("fail to dnld domain info\n");
463 * @brief This function setups scan channels
464 * @param priv pointer to struct lbs_private
468 int lbs_set_universaltable(struct lbs_private *priv, u8 band)
470 u16 size = sizeof(struct chan_freq_power);
473 memset(priv->universal_channel, 0,
474 sizeof(priv->universal_channel));
476 priv->universal_channel[i].nrcfp =
477 sizeof(channel_freq_power_UN_BG) / size;
478 lbs_deb_11d("BG-band nrcfp %d\n",
479 priv->universal_channel[i].nrcfp);
481 priv->universal_channel[i].CFP = channel_freq_power_UN_BG;
482 priv->universal_channel[i].valid = 1;
483 priv->universal_channel[i].region = UNIVERSAL_REGION_CODE;
484 priv->universal_channel[i].band = band;
491 * @brief This function implements command CMD_802_11D_DOMAIN_INFO
492 * @param priv pointer to struct lbs_private
493 * @param cmd pointer to cmd buffer
494 * @param cmdno cmd ID
495 * @param cmdOption cmd action
498 int lbs_cmd_802_11d_domain_info(struct lbs_private *priv,
499 struct cmd_ds_command *cmd, u16 cmdno,
502 struct cmd_ds_802_11d_domain_info *pdomaininfo =
503 &cmd->params.domaininfo;
504 struct mrvl_ie_domain_param_set *domain = &pdomaininfo->domain;
505 u8 nr_subband = priv->domainreg.nr_subband;
507 lbs_deb_enter(LBS_DEB_11D);
509 lbs_deb_11d("nr_subband=%x\n", nr_subband);
511 cmd->command = cpu_to_le16(cmdno);
512 pdomaininfo->action = cpu_to_le16(cmdoption);
513 if (cmdoption == CMD_ACT_GET) {
515 cpu_to_le16(sizeof(pdomaininfo->action) + S_DS_GEN);
516 lbs_deb_hex(LBS_DEB_11D, "802_11D_DOMAIN_INFO", (u8 *) cmd,
517 le16_to_cpu(cmd->size));
521 domain->header.type = cpu_to_le16(TLV_TYPE_DOMAIN);
522 memcpy(domain->countrycode, priv->domainreg.countrycode,
523 sizeof(domain->countrycode));
526 cpu_to_le16(nr_subband * sizeof(struct ieee_subbandset) +
527 sizeof(domain->countrycode));
530 memcpy(domain->subband, priv->domainreg.subband,
531 nr_subband * sizeof(struct ieee_subbandset));
533 cmd->size = cpu_to_le16(sizeof(pdomaininfo->action) +
534 le16_to_cpu(domain->header.len) +
535 sizeof(struct mrvl_ie_header) +
539 cpu_to_le16(sizeof(pdomaininfo->action) + S_DS_GEN);
542 lbs_deb_hex(LBS_DEB_11D, "802_11D_DOMAIN_INFO", (u8 *) cmd, le16_to_cpu(cmd->size));
545 lbs_deb_enter(LBS_DEB_11D);
550 * @brief This function parses countryinfo from AP and download country info to FW
551 * @param priv pointer to struct lbs_private
552 * @param resp pointer to command response buffer
555 int lbs_ret_802_11d_domain_info(struct cmd_ds_command *resp)
557 struct cmd_ds_802_11d_domain_info *domaininfo = &resp->params.domaininforesp;
558 struct mrvl_ie_domain_param_set *domain = &domaininfo->domain;
559 u16 action = le16_to_cpu(domaininfo->action);
563 lbs_deb_enter(LBS_DEB_11D);
565 lbs_deb_hex(LBS_DEB_11D, "domain info resp", (u8 *) resp,
566 (int)le16_to_cpu(resp->size));
568 nr_subband = (le16_to_cpu(domain->header.len) - COUNTRY_CODE_LEN) /
569 sizeof(struct ieee_subbandset);
571 lbs_deb_11d("domain info resp: nr_subband %d\n", nr_subband);
573 if (nr_subband > MRVDRV_MAX_SUBBAND_802_11D) {
574 lbs_deb_11d("Invalid Numrer of Subband returned!!\n");
579 case CMD_ACT_SET: /*Proc Set action */
585 lbs_deb_11d("Invalid action:%d\n", domaininfo->action);
590 lbs_deb_leave_args(LBS_DEB_11D, "ret %d", ret);
595 * @brief This function parses countryinfo from AP and download country info to FW
596 * @param priv pointer to struct lbs_private
599 int lbs_parse_dnld_countryinfo_11d(struct lbs_private *priv,
600 struct bss_descriptor * bss)
604 lbs_deb_enter(LBS_DEB_11D);
605 if (priv->enable11d) {
606 memset(&priv->parsed_region_chan, 0,
607 sizeof(struct parsed_region_chan_11d));
608 ret = parse_domain_info_11d(&bss->countryinfo, 0,
609 &priv->parsed_region_chan);
612 lbs_deb_11d("error parsing domain_info from AP\n");
616 memset(&priv->domainreg, 0,
617 sizeof(struct lbs_802_11d_domain_reg));
618 generate_domain_info_11d(&priv->parsed_region_chan,
621 ret = set_domain_info_11d(priv);
624 lbs_deb_11d("error setting domain info\n");
631 lbs_deb_leave_args(LBS_DEB_11D, "ret %d", ret);
636 * @brief This function generates 11D info from user specified regioncode and download to FW
637 * @param priv pointer to struct lbs_private
640 int lbs_create_dnld_countryinfo_11d(struct lbs_private *priv)
643 struct region_channel *region_chan;
646 lbs_deb_enter(LBS_DEB_11D);
647 lbs_deb_11d("curbssparams.band %d\n", priv->curbssparams.band);
649 if (priv->enable11d) {
650 /* update parsed_region_chan_11; dnld domaininf to FW */
652 for (j = 0; j < ARRAY_SIZE(priv->region_channel); j++) {
653 region_chan = &priv->region_channel[j];
655 lbs_deb_11d("%d region_chan->band %d\n", j,
658 if (!region_chan || !region_chan->valid
659 || !region_chan->CFP)
661 if (region_chan->band != priv->curbssparams.band)
666 if (j >= ARRAY_SIZE(priv->region_channel)) {
667 lbs_deb_11d("region_chan not found, band %d\n",
668 priv->curbssparams.band);
673 memset(&priv->parsed_region_chan, 0,
674 sizeof(struct parsed_region_chan_11d));
675 lbs_generate_parsed_region_chan_11d(region_chan,
679 memset(&priv->domainreg, 0,
680 sizeof(struct lbs_802_11d_domain_reg));
681 generate_domain_info_11d(&priv->parsed_region_chan,
684 ret = set_domain_info_11d(priv);
687 lbs_deb_11d("error setting domain info\n");
695 lbs_deb_leave_args(LBS_DEB_11D, "ret %d", ret);