11d.c 18.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
/**
  * This file contains functions for 802.11D.
  */
#include <linux/ctype.h>
#include <linux/kernel.h>
#include <linux/wireless.h>

#include "host.h"
#include "decl.h"
#include "11d.h"
#include "dev.h"
#include "wext.h"

#define TX_PWR_DEFAULT	10

static struct region_code_mapping region_code_mapping[] = {
	{"US ", 0x10},		/* US FCC      */
	{"CA ", 0x10},		/* IC Canada   */
	{"SG ", 0x10},		/* Singapore   */
	{"EU ", 0x30},		/* ETSI        */
	{"AU ", 0x30},		/* Australia   */
	{"KR ", 0x30},		/* Republic Of Korea */
	{"ES ", 0x31},		/* Spain       */
	{"FR ", 0x32},		/* France      */
	{"JP ", 0x40},		/* Japan       */
};

/* Following 2 structure defines the supported channels */
static struct chan_freq_power channel_freq_power_UN_BG[] = {
	{1, 2412, TX_PWR_DEFAULT},
	{2, 2417, TX_PWR_DEFAULT},
	{3, 2422, TX_PWR_DEFAULT},
	{4, 2427, TX_PWR_DEFAULT},
	{5, 2432, TX_PWR_DEFAULT},
	{6, 2437, TX_PWR_DEFAULT},
	{7, 2442, TX_PWR_DEFAULT},
	{8, 2447, TX_PWR_DEFAULT},
	{9, 2452, TX_PWR_DEFAULT},
	{10, 2457, TX_PWR_DEFAULT},
	{11, 2462, TX_PWR_DEFAULT},
	{12, 2467, TX_PWR_DEFAULT},
	{13, 2472, TX_PWR_DEFAULT},
	{14, 2484, TX_PWR_DEFAULT}
};

static u8 wlan_region_2_code(u8 * region)
{
	u8 i;
	u8 size = sizeof(region_code_mapping)/
		  sizeof(struct region_code_mapping);

	for (i = 0; region[i] && i < COUNTRY_CODE_LEN; i++)
		region[i] = toupper(region[i]);

	for (i = 0; i < size; i++) {
		if (!memcmp(region, region_code_mapping[i].region,
			    COUNTRY_CODE_LEN))
			return (region_code_mapping[i].code);
	}

	/* default is US */
	return (region_code_mapping[0].code);
}

static u8 *wlan_code_2_region(u8 code)
{
	u8 i;
	u8 size = sizeof(region_code_mapping)
		  / sizeof(struct region_code_mapping);
	for (i = 0; i < size; i++) {
		if (region_code_mapping[i].code == code)
			return (region_code_mapping[i].region);
	}
	/* default is US */
	return (region_code_mapping[0].region);
}

/**
 *  @brief This function finds the nrchan-th chan after the firstchan
 *  @param band       band
 *  @param firstchan  first channel number
 *  @param nrchan   number of channels
 *  @return 	      the nrchan-th chan number
*/
static u8 wlan_get_chan_11d(u8 band, u8 firstchan, u8 nrchan, u8 * chan)
/*find the nrchan-th chan after the firstchan*/
{
	u8 i;
	struct chan_freq_power *cfp;
	u8 cfp_no;

	cfp = channel_freq_power_UN_BG;
	cfp_no = sizeof(channel_freq_power_UN_BG) /
	    sizeof(struct chan_freq_power);

	for (i = 0; i < cfp_no; i++) {
		if ((cfp + i)->channel == firstchan) {
98
			lbs_deb_11d("firstchan found\n");
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
			break;
		}
	}

	if (i < cfp_no) {
		/*if beyond the boundary */
		if (i + nrchan < cfp_no) {
			*chan = (cfp + i + nrchan)->channel;
			return 1;
		}
	}

	return 0;
}

/**
 *  @brief This function Checks if chan txpwr is learned from AP/IBSS
 *  @param chan                 chan number
 *  @param parsed_region_chan   pointer to parsed_region_chan_11d
 *  @return 	                TRUE; FALSE
*/
static u8 wlan_channel_known_11d(u8 chan,
			  struct parsed_region_chan_11d * parsed_region_chan)
{
	struct chan_power_11d *chanpwr = parsed_region_chan->chanpwr;
	u8 nr_chan = parsed_region_chan->nr_chan;
	u8 i = 0;

	lbs_dbg_hex("11D:parsed_region_chan:", (char *)chanpwr,
		sizeof(struct chan_power_11d) * nr_chan);

	for (i = 0; i < nr_chan; i++) {
		if (chan == chanpwr[i].chan) {
132
			lbs_deb_11d("11D: Found Chan:%d\n", chan);
133 134 135 136
			return 1;
		}
	}

137
	lbs_deb_11d("11D: Not Find Chan:%d\n", chan);
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
	return 0;
}

u32 libertas_chan_2_freq(u8 chan, u8 band)
{
	struct chan_freq_power *cf;
	u16 cnt;
	u16 i;
	u32 freq = 0;

	cf = channel_freq_power_UN_BG;
	cnt =
	    sizeof(channel_freq_power_UN_BG) /
	    sizeof(struct chan_freq_power);

	for (i = 0; i < cnt; i++) {
		if (chan == cf[i].channel)
			freq = cf[i].freq;
	}

	return freq;
}

static int generate_domain_info_11d(struct parsed_region_chan_11d
				  *parsed_region_chan,
				  struct wlan_802_11d_domain_reg * domaininfo)
{
	u8 nr_subband = 0;

	u8 nr_chan = parsed_region_chan->nr_chan;
	u8 nr_parsedchan = 0;

	u8 firstchan = 0, nextchan = 0, maxpwr = 0;

	u8 i, flag = 0;

	memcpy(domaininfo->countrycode, parsed_region_chan->countrycode,
	       COUNTRY_CODE_LEN);

177
	lbs_deb_11d("11D:nrchan=%d\n", nr_chan);
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
	lbs_dbg_hex("11D:parsed_region_chan:", (char *)parsed_region_chan,
		sizeof(struct parsed_region_chan_11d));

	for (i = 0; i < nr_chan; i++) {
		if (!flag) {
			flag = 1;
			nextchan = firstchan =
			    parsed_region_chan->chanpwr[i].chan;
			maxpwr = parsed_region_chan->chanpwr[i].pwr;
			nr_parsedchan = 1;
			continue;
		}

		if (parsed_region_chan->chanpwr[i].chan == nextchan + 1 &&
		    parsed_region_chan->chanpwr[i].pwr == maxpwr) {
			nextchan++;
			nr_parsedchan++;
		} else {
			domaininfo->subband[nr_subband].firstchan = firstchan;
			domaininfo->subband[nr_subband].nrchan =
			    nr_parsedchan;
			domaininfo->subband[nr_subband].maxtxpwr = maxpwr;
			nr_subband++;
			nextchan = firstchan =
			    parsed_region_chan->chanpwr[i].chan;
			maxpwr = parsed_region_chan->chanpwr[i].pwr;
		}
	}

	if (flag) {
		domaininfo->subband[nr_subband].firstchan = firstchan;
		domaininfo->subband[nr_subband].nrchan = nr_parsedchan;
		domaininfo->subband[nr_subband].maxtxpwr = maxpwr;
		nr_subband++;
	}
	domaininfo->nr_subband = nr_subband;

215
	lbs_deb_11d("nr_subband=%x\n", domaininfo->nr_subband);
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
	lbs_dbg_hex("11D:domaininfo:", (char *)domaininfo,
		COUNTRY_CODE_LEN + 1 +
		sizeof(struct ieeetypes_subbandset) * nr_subband);
	return 0;
}

/**
 *  @brief This function generates parsed_region_chan from Domain Info learned from AP/IBSS
 *  @param region_chan          pointer to struct region_channel
 *  @param *parsed_region_chan  pointer to parsed_region_chan_11d
 *  @return 	                N/A
*/
static void wlan_generate_parsed_region_chan_11d(struct region_channel * region_chan,
					  struct parsed_region_chan_11d *
					  parsed_region_chan)
{
	u8 i;
	struct chan_freq_power *cfp;

	if (region_chan == NULL) {
236
		lbs_deb_11d("11D: region_chan is NULL\n");
237 238 239 240 241
		return;
	}

	cfp = region_chan->CFP;
	if (cfp == NULL) {
242
		lbs_deb_11d("11D: cfp equal NULL \n");
243 244 245 246 247 248 249 250
		return;
	}

	parsed_region_chan->band = region_chan->band;
	parsed_region_chan->region = region_chan->region;
	memcpy(parsed_region_chan->countrycode,
	       wlan_code_2_region(region_chan->region), COUNTRY_CODE_LEN);

251
	lbs_deb_11d("11D: region[0x%x] band[%d]\n", parsed_region_chan->region,
252 253 254 255 256
	       parsed_region_chan->band);

	for (i = 0; i < region_chan->nrcfp; i++, cfp++) {
		parsed_region_chan->chanpwr[i].chan = cfp->channel;
		parsed_region_chan->chanpwr[i].pwr = cfp->maxtxpower;
257
		lbs_deb_11d("11D: Chan[%d] Pwr[%d]\n",
258 259 260 261 262
		       parsed_region_chan->chanpwr[i].chan,
		       parsed_region_chan->chanpwr[i].pwr);
	}
	parsed_region_chan->nr_chan = region_chan->nrcfp;

263
	lbs_deb_11d("11D: nrchan[%d]\n", parsed_region_chan->nr_chan);
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279

	return;
}

/**
 *  @brief generate parsed_region_chan from Domain Info learned from AP/IBSS
 *  @param region               region ID
 *  @param band                 band
 *  @param chan                 chan
 *  @return 	                TRUE;FALSE
*/
static u8 wlan_region_chan_supported_11d(u8 region, u8 band, u8 chan)
{
	struct chan_freq_power *cfp;
	int cfp_no;
	u8 idx;
280
	int ret = 0;
281

282
	lbs_deb_enter(LBS_DEB_11D);
283 284 285 286 287 288 289 290 291

	cfp = libertas_get_region_cfp_table(region, band, &cfp_no);
	if (cfp == NULL)
		return 0;

	for (idx = 0; idx < cfp_no; idx++) {
		if (chan == (cfp + idx)->channel) {
			/* If Mrvl Chip Supported? */
			if ((cfp + idx)->unsupported) {
292
				ret = 0;
293
			} else {
294
				ret = 1;
295
			}
296
			goto done;
297 298 299 300
		}
	}

	/*chan is not in the region table */
301 302 303 304

done:
	lbs_deb_leave_args(LBS_DEB_11D, "ret %d", ret);
	return ret;
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
}

/**
 *  @brief This function checks if chan txpwr is learned from AP/IBSS
 *  @param chan                 chan number
 *  @param parsed_region_chan   pointer to parsed_region_chan_11d
 *  @return 	                0
*/
static int parse_domain_info_11d(struct ieeetypes_countryinfofullset*
				 countryinfo,
				 u8 band,
				 struct parsed_region_chan_11d *
				 parsed_region_chan)
{
	u8 nr_subband, nrchan;
	u8 lastchan, firstchan;
	u8 region;
	u8 curchan = 0;

	u8 idx = 0;		/*chan index in parsed_region_chan */

	u8 j, i;

328
	lbs_deb_enter(LBS_DEB_11D);
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343

	/*validation Rules:
	   1. valid region Code
	   2. First Chan increment
	   3. channel range no overlap
	   4. channel is valid?
	   5. channel is supported by region?
	   6. Others
	 */

	lbs_dbg_hex("CountryInfo:", (u8 *) countryinfo, 30);

	if ((*(countryinfo->countrycode)) == 0
	    || (countryinfo->len <= COUNTRY_CODE_LEN)) {
		/* No region Info or Wrong region info: treat as No 11D info */
344
		goto done;
345 346 347 348 349 350
	}

	/*Step1: check region_code */
	parsed_region_chan->region = region =
	    wlan_region_2_code(countryinfo->countrycode);

351
	lbs_deb_11d("regioncode=%x\n", (u8) parsed_region_chan->region);
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366
	lbs_dbg_hex("CountryCode:", (char *)countryinfo->countrycode,
		COUNTRY_CODE_LEN);

	parsed_region_chan->band = band;

	memcpy(parsed_region_chan->countrycode, countryinfo->countrycode,
	       COUNTRY_CODE_LEN);

	nr_subband = (countryinfo->len - COUNTRY_CODE_LEN) /
	    sizeof(struct ieeetypes_subbandset);

	for (j = 0, lastchan = 0; j < nr_subband; j++) {

		if (countryinfo->subband[j].firstchan <= lastchan) {
			/*Step2&3. Check First Chan Num increment and no overlap */
367
			lbs_deb_11d("11D: Chan[%d>%d] Overlap\n",
368 369 370 371 372 373 374 375 376 377 378 379
			       countryinfo->subband[j].firstchan, lastchan);
			continue;
		}

		firstchan = countryinfo->subband[j].firstchan;
		nrchan = countryinfo->subband[j].nrchan;

		for (i = 0; idx < MAX_NO_OF_CHAN && i < nrchan; i++) {
			/*step4: channel is supported? */

			if (!wlan_get_chan_11d(band, firstchan, i, &curchan)) {
				/* Chan is not found in UN table */
380
				lbs_deb_11d("chan is not supported: %d \n", i);
381 382 383 384 385 386 387 388 389 390 391 392 393 394
				break;
			}

			lastchan = curchan;

			if (wlan_region_chan_supported_11d
			    (region, band, curchan)) {
				/*step5: Check if curchan is supported by mrvl in region */
				parsed_region_chan->chanpwr[idx].chan = curchan;
				parsed_region_chan->chanpwr[idx].pwr =
				    countryinfo->subband[j].maxtxpwr;
				idx++;
			} else {
				/*not supported and ignore the chan */
395
				lbs_deb_11d(
396 397 398 399 400 401 402 403 404 405 406
				       "11D:i[%d] chan[%d] unsupported in region[%x] band[%d]\n",
				       i, curchan, region, band);
			}
		}

		/*Step6: Add other checking if any */

	}

	parsed_region_chan->nr_chan = idx;

407
	lbs_deb_11d("nrchan=%x\n", parsed_region_chan->nr_chan);
408 409 410
	lbs_dbg_hex("11D:parsed_region_chan:", (u8 *) parsed_region_chan,
		2 + COUNTRY_CODE_LEN + sizeof(struct parsed_region_chan_11d) * idx);

411 412
done:
	lbs_deb_enter(LBS_DEB_11D);
413 414 415 416 417 418 419 420 421 422 423 424
	return 0;
}

/**
 *  @brief This function calculates the scan type for channels
 *  @param chan                 chan number
 *  @param parsed_region_chan   pointer to parsed_region_chan_11d
 *  @return 	                PASSIVE if chan is unknown; ACTIVE if chan is known
*/
u8 libertas_get_scan_type_11d(u8 chan,
			  struct parsed_region_chan_11d * parsed_region_chan)
{
425
	u8 scan_type = CMD_SCAN_TYPE_PASSIVE;
426

427
	lbs_deb_enter(LBS_DEB_11D);
428 429

	if (wlan_channel_known_11d(chan, parsed_region_chan)) {
430
		lbs_deb_11d("11D: Found and do Active Scan\n");
431
		scan_type = CMD_SCAN_TYPE_ACTIVE;
432
	} else {
433
		lbs_deb_11d("11D: Not Find and do Passive Scan\n");
434 435
	}

436
	lbs_deb_leave_args(LBS_DEB_11D, "ret scan_type %d", scan_type);
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458
	return scan_type;

}

void libertas_init_11d(wlan_private * priv)
{
	priv->adapter->enable11d = 0;
	memset(&(priv->adapter->parsed_region_chan), 0,
	       sizeof(struct parsed_region_chan_11d));
	return;
}

/**
 *  @brief This function sets DOMAIN INFO to FW
 *  @param priv       pointer to wlan_private
 *  @return 	      0; -1
*/
static int set_domain_info_11d(wlan_private * priv)
{
	int ret;

	if (!priv->adapter->enable11d) {
459
		lbs_deb_11d("11D: dnld domain Info with 11d disabled\n");
460 461 462
		return 0;
	}

463 464 465
	ret = libertas_prepare_and_send_command(priv, CMD_802_11D_DOMAIN_INFO,
				    CMD_ACT_SET,
				    CMD_OPTION_WAITFORRSP, 0, NULL);
466
	if (ret)
467
		lbs_deb_11d("11D: Fail to dnld domain Info\n");
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488

	return ret;
}

/**
 *  @brief This function setups scan channels
 *  @param priv       pointer to wlan_private
 *  @param band       band
 *  @return 	      0
*/
int libertas_set_universaltable(wlan_private * priv, u8 band)
{
	wlan_adapter *adapter = priv->adapter;
	u16 size = sizeof(struct chan_freq_power);
	u16 i = 0;

	memset(adapter->universal_channel, 0,
	       sizeof(adapter->universal_channel));

	adapter->universal_channel[i].nrcfp =
	    sizeof(channel_freq_power_UN_BG) / size;
489
	lbs_deb_11d("11D: BG-band nrcfp=%d\n",
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518
	       adapter->universal_channel[i].nrcfp);

	adapter->universal_channel[i].CFP = channel_freq_power_UN_BG;
	adapter->universal_channel[i].valid = 1;
	adapter->universal_channel[i].region = UNIVERSAL_REGION_CODE;
	adapter->universal_channel[i].band = band;
	i++;

	return 0;
}

/**
 *  @brief This function implements command CMD_802_11D_DOMAIN_INFO
 *  @param priv       pointer to wlan_private
 *  @param cmd        pointer to cmd buffer
 *  @param cmdno      cmd ID
 *  @param cmdOption  cmd action
 *  @return 	      0
*/
int libertas_cmd_802_11d_domain_info(wlan_private * priv,
				 struct cmd_ds_command *cmd, u16 cmdno,
				 u16 cmdoption)
{
	struct cmd_ds_802_11d_domain_info *pdomaininfo =
	    &cmd->params.domaininfo;
	struct mrvlietypes_domainparamset *domain = &pdomaininfo->domain;
	wlan_adapter *adapter = priv->adapter;
	u8 nr_subband = adapter->domainreg.nr_subband;

519
	lbs_deb_enter(LBS_DEB_11D);
520

521
	lbs_deb_11d("nr_subband=%x\n", nr_subband);
522 523 524

	cmd->command = cpu_to_le16(cmdno);
	pdomaininfo->action = cpu_to_le16(cmdoption);
525
	if (cmdoption == CMD_ACT_GET) {
526 527 528 529
		cmd->size =
		    cpu_to_le16(sizeof(pdomaininfo->action) + S_DS_GEN);
		lbs_dbg_hex("11D: 802_11D_DOMAIN_INFO:", (u8 *) cmd,
			(int)(cmd->size));
530
		goto done;
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553
	}

	domain->header.type = cpu_to_le16(TLV_TYPE_DOMAIN);
	memcpy(domain->countrycode, adapter->domainreg.countrycode,
	       sizeof(domain->countrycode));

	domain->header.len =
	    cpu_to_le16(nr_subband * sizeof(struct ieeetypes_subbandset) +
			     sizeof(domain->countrycode));

	if (nr_subband) {
		memcpy(domain->subband, adapter->domainreg.subband,
		       nr_subband * sizeof(struct ieeetypes_subbandset));

		cmd->size = cpu_to_le16(sizeof(pdomaininfo->action) +
					     domain->header.len +
					     sizeof(struct mrvlietypesheader) +
					     S_DS_GEN);
	} else {
		cmd->size =
		    cpu_to_le16(sizeof(pdomaininfo->action) + S_DS_GEN);
	}

554
	lbs_dbg_hex("11D:802_11D_DOMAIN_INFO:", (u8 *) cmd, le16_to_cpu(cmd->size));
555

556 557
done:
	lbs_deb_enter(LBS_DEB_11D);
558 559 560 561 562 563 564 565 566 567 568 569
	return 0;
}

/**
 *  @brief This function parses countryinfo from AP and download country info to FW
 *  @param priv    pointer to wlan_private
 *  @param resp    pointer to command response buffer
 *  @return 	   0; -1
 */
int libertas_ret_802_11d_domain_info(wlan_private * priv,
				 struct cmd_ds_command *resp)
{
570
	struct cmd_ds_802_11d_domain_info *domaininfo = &resp->params.domaininforesp;
571 572 573 574 575
	struct mrvlietypes_domainparamset *domain = &domaininfo->domain;
	u16 action = le16_to_cpu(domaininfo->action);
	s16 ret = 0;
	u8 nr_subband = 0;

576
	lbs_deb_enter(LBS_DEB_11D);
577 578 579 580

	lbs_dbg_hex("11D DOMAIN Info Rsp Data:", (u8 *) resp,
		(int)le16_to_cpu(resp->size));

581 582
	nr_subband = (le16_to_cpu(domain->header.len) - COUNTRY_CODE_LEN) /
		      sizeof(struct ieeetypes_subbandset);
583

584
	lbs_deb_11d("11D Domain Info Resp: nr_subband=%d\n", nr_subband);
585 586

	if (nr_subband > MRVDRV_MAX_SUBBAND_802_11D) {
587
		lbs_deb_11d("Invalid Numrer of Subband returned!!\n");
588 589 590 591
		return -1;
	}

	switch (action) {
592
	case CMD_ACT_SET:	/*Proc Set action */
593 594
		break;

595
	case CMD_ACT_GET:
596 597
		break;
	default:
598
		lbs_deb_11d("Invalid action:%d\n", domaininfo->action);
599 600 601 602
		ret = -1;
		break;
	}

603
	lbs_deb_leave_args(LBS_DEB_11D, "ret %d", ret);
604 605 606 607 608 609 610 611
	return ret;
}

/**
 *  @brief This function parses countryinfo from AP and download country info to FW
 *  @param priv    pointer to wlan_private
 *  @return 	   0; -1
 */
612 613
int libertas_parse_dnld_countryinfo_11d(wlan_private * priv,
                                        struct bss_descriptor * bss)
614 615 616 617
{
	int ret;
	wlan_adapter *adapter = priv->adapter;

618
	lbs_deb_enter(LBS_DEB_11D);
619 620 621
	if (priv->adapter->enable11d) {
		memset(&adapter->parsed_region_chan, 0,
		       sizeof(struct parsed_region_chan_11d));
622
		ret = parse_domain_info_11d(&bss->countryinfo, 0,
623 624 625
					       &adapter->parsed_region_chan);

		if (ret == -1) {
626 627
			lbs_deb_11d("11D: Err Parse domain_info from AP..\n");
			goto done;
628 629 630 631 632 633 634 635 636 637
		}

		memset(&adapter->domainreg, 0,
		       sizeof(struct wlan_802_11d_domain_reg));
		generate_domain_info_11d(&adapter->parsed_region_chan,
				      &adapter->domainreg);

		ret = set_domain_info_11d(priv);

		if (ret) {
638 639
			lbs_deb_11d("11D: Err set domainInfo to FW\n");
			goto done;
640 641
		}
	}
642 643 644 645 646
	ret = 0;

done:
	lbs_deb_leave_args(LBS_DEB_11D, "ret %d", ret);
	return ret;
647 648 649 650 651 652 653 654 655 656 657 658 659 660
}

/**
 *  @brief This function generates 11D info from user specified regioncode and download to FW
 *  @param priv    pointer to wlan_private
 *  @return 	   0; -1
 */
int libertas_create_dnld_countryinfo_11d(wlan_private * priv)
{
	int ret;
	wlan_adapter *adapter = priv->adapter;
	struct region_channel *region_chan;
	u8 j;

661 662
	lbs_deb_enter(LBS_DEB_11D);
	lbs_deb_11d("11D:curbssparams.band[%d]\n", adapter->curbssparams.band);
663 664 665 666 667 668 669 670

	if (priv->adapter->enable11d) {
		/* update parsed_region_chan_11; dnld domaininf to FW */

		for (j = 0; j < sizeof(adapter->region_channel) /
		     sizeof(adapter->region_channel[0]); j++) {
			region_chan = &adapter->region_channel[j];

671
			lbs_deb_11d("11D:[%d] region_chan->band[%d]\n", j,
672 673 674 675 676 677 678 679 680 681 682 683
			       region_chan->band);

			if (!region_chan || !region_chan->valid
			    || !region_chan->CFP)
				continue;
			if (region_chan->band != adapter->curbssparams.band)
				continue;
			break;
		}

		if (j >= sizeof(adapter->region_channel) /
		    sizeof(adapter->region_channel[0])) {
684
			lbs_deb_11d("11D:region_chan not found. band[%d]\n",
685
			       adapter->curbssparams.band);
686 687
			ret = -1;
			goto done;
688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703
		}

		memset(&adapter->parsed_region_chan, 0,
		       sizeof(struct parsed_region_chan_11d));
		wlan_generate_parsed_region_chan_11d(region_chan,
						     &adapter->
						     parsed_region_chan);

		memset(&adapter->domainreg, 0,
		       sizeof(struct wlan_802_11d_domain_reg));
		generate_domain_info_11d(&adapter->parsed_region_chan,
					 &adapter->domainreg);

		ret = set_domain_info_11d(priv);

		if (ret) {
704 705
			lbs_deb_11d("11D: Err set domainInfo to FW\n");
			goto done;
706 707 708
		}

	}
709
	ret = 0;
710

711 712 713
done:
	lbs_deb_leave_args(LBS_DEB_11D, "ret %d", ret);
	return ret;
714
}