/*
 ***************************************************************************
 * Ralink Tech Inc.
 * 4F, No. 2 Technology 5th Rd.
 * Science-based Industrial Park
 * Hsin-chu, Taiwan, R.O.C.
 *
 * (c) Copyright 2002-2004, Ralink Technology, Inc.
 *
 * All rights reserved. Ralink's source code is an unpublished work and the
 * use of a copyright notice does not imply otherwise. This source code
 * contains confidential trade secret material of Ralink Tech. Any attemp
 * or participation in deciphering, decoding, reverse engineering or in any
 * way altering the source code is stricitly prohibited, unless the prior
 * written consent of Ralink Technology, Inc. is obtained.
 ***************************************************************************

	Module Name:
	chlist.c

	Abstract:

	Revision History:
	Who         When          What
	--------    ----------    ----------------------------------------------
	Fonchi Wu   2007-12-19    created
*/

#ifndef __CHLIST_H__
#define __CHLIST_H__

#include "rtmp_type.h"
#include "rtmp_def.h"
#include "rom/wifi_os.h"

#define ODOR			0
#define IDOR			1
#define BOTH			2

#define BAND_5G         0
#define BAND_24G        1
#define BAND_BOTH       2

typedef struct _CH_DESP {
	UCHAR FirstChannel;
	UCHAR NumOfCh;
	CHAR MaxTxPwr;			// dBm
	UCHAR Geography;			// 0:out door, 1:in door, 2:both
	BOOLEAN DfsReq;			// Dfs require, 0: No, 1: yes.
} CH_DESP, *PCH_DESP; 

typedef struct _CH_REGION {
	UCHAR CountReg[3];
	UCHAR DfsType;			// 0: CE, 1: FCC, 2: JAP, 3:JAP_W53, JAP_W56
	CH_DESP ChDesp[10];
} CH_REGION, *PCH_REGION;

static CH_REGION ChRegion[] =
{
		{	// Antigua and Berbuda
			"AG",
			CE,
			{
				{ 1,   13, 20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36,  4,  23, BOTH, FALSE},	// 5G, ch 36~48
				{ 52,  4,  23, BOTH, FALSE},	// 5G, ch 52~64
				{ 100, 11, 30, BOTH, FALSE},	// 5G, ch 100~140
				{ 0 },							// end
			}
		},
		{	// Argentina
			"AR",
			CE,
			{
				{ 1,   13, 20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 52,  4,  24, BOTH, FALSE},	// 5G, ch 52~64
				{ 149, 4,  30, BOTH, FALSE},	// 5G, ch 149~161
				{ 0},							// end
			}
		},

		{	// Aruba
			"AW",
			CE,
			{
				{ 1,   13, 20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36,  4,  23, BOTH, FALSE},	// 5G, ch 36~48
				{ 52,  4,  23, BOTH, FALSE},	// 5G, ch 52~64
				{ 100, 11, 30, BOTH, FALSE},	// 5G, ch 100~140
				{ 0},							// end
			}
		},

		{	// Australia
			"AU",
			CE,
			{
				{ 1,   13, 20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36,  4,  23, BOTH, FALSE},	// 5G, ch 36~48
				{ 52,  4,  24, BOTH, FALSE},	// 5G, ch 52~64
				{ 149, 5,  30, BOTH, FALSE},	// 5G, ch 149~165
				{ 0},							// end
			}
		},

		{	// Austria
			"AT",
			CE,
			{
				{ 1,   13, 20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36,  4,  23, IDOR, TRUE},		// 5G, ch 36~48
				{ 52,  4,  23, IDOR, TRUE},		// 5G, ch 52~64
				{ 100, 11, 30, BOTH, TRUE},		// 5G, ch 100~140
				{ 0},							// end
			}
		},

		{	// Bahamas
			"BS",
			CE,
			{
				{ 1,   13, 20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36,  4,  23, BOTH, FALSE},	// 5G, ch 36~48
				{ 52,  4,  24, BOTH, FALSE},	// 5G, ch 52~64
				{ 149, 5,  30, BOTH, FALSE},	// 5G, ch 149~165
				{ 0},							// end
			}
		},

		{	// Barbados
			"BB",
			CE,
			{
				{ 1,   13, 20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36,  4,  23, BOTH, FALSE},	// 5G, ch 36~48
				{ 52,  4,  24, BOTH, FALSE},	// 5G, ch 52~64
				{ 100, 11, 30, BOTH, FALSE},	// 5G, ch 100~140
				{ 0},							// end
			}
		},

		{	// Bermuda
			"BM",
			CE,
			{
				{ 1,   13, 20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36,  4,  23, BOTH, FALSE},	// 5G, ch 36~48
				{ 52,  4,  24, BOTH, FALSE},	// 5G, ch 52~64
				{ 100, 11, 30, BOTH, FALSE},	// 5G, ch 100~140
				{ 0},							// end
			}
		},

		{	// Brazil
			"BR",
			CE,
			{
				{ 1,   13, 20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36,  4,  23, BOTH, FALSE},	// 5G, ch 36~48
				{ 52,  4,  24, BOTH, FALSE},	// 5G, ch 52~64
				{ 100, 11, 24, BOTH, FALSE},	// 5G, ch 100~140
				{ 149, 5,  30, BOTH, FALSE},	// 5G, ch 100~140
				{ 0},							// end
			}
		},

		{	// Belgium
			"BE",
			CE,
			{
				{ 1,   13, 20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36,  4,  18, IDOR, FALSE},	// 5G, ch 36~48
				{ 52,  4,  18, IDOR, FALSE},	// 5G, ch 52~64
				{ 0},							// end
			}
		},

		{	// Bulgaria
			"BG",
			CE,
			{
				{ 1,   13, 20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36,  4,  23, IDOR, FALSE},	// 5G, ch 36~48
				{ 52,  4,  23, IDOR, TRUE},	// 5G, ch 52~64
				{ 100, 11, 30, ODOR, TRUE},	// 5G, ch 100~140
				{ 0},							// end
			}
		},

		{	// Canada
			"CA",
			CE,
			{
				{ 1,   13, 20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36,  4,  23, BOTH, FALSE},	// 5G, ch 36~48
				{ 52,  4,  23, BOTH, FALSE},	// 5G, ch 52~64
				{ 149, 5,  30, BOTH, FALSE},	// 5G, ch 149~165
				{ 0},							// end
			}
		},

		{	// Cayman IsLands
			"KY",
			CE,
			{
				{ 1,   13, 20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36,  4,  23, BOTH, FALSE},	// 5G, ch 36~48
				{ 52,  4,  24, BOTH, FALSE},	// 5G, ch 52~64
				{ 100, 11, 30, BOTH, FALSE},	// 5G, ch 100~140
				{ 0},							// end
			}
		},

		{	// Chile
			"CL",
			CE,
			{
				{ 1,   13, 20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36,  4,  20, BOTH, FALSE},	// 5G, ch 36~48
				{ 52,  4,  20, BOTH, FALSE},	// 5G, ch 52~64
				{ 149, 5,  20, BOTH, FALSE},	// 5G, ch 149~165
				{ 0},							// end
			}
		},

		{	// China
			"CN",
			CE,
			{
				{ 1,   13, 20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 149, 4,  27, BOTH, FALSE},	// 5G, ch 149~161
				{ 0},							// end
			}
		},

		{	// Colombia
			"CO",
			CE,
			{
				{ 1,   13, 20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36,  4,  17, BOTH, FALSE},	// 5G, ch 36~48
				{ 52,  4,  24, BOTH, FALSE},	// 5G, ch 52~64
				{ 100, 11, 30, BOTH, FALSE},	// 5G, ch 100~140
				{ 149, 5,  30, BOTH, FALSE},	// 5G, ch 149~165
				{ 0},							// end
			}
		},

		{	// Costa Rica
			"CR",
			CE,
			{
				{ 1,   13, 20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36,  4,  17, BOTH, FALSE},	// 5G, ch 36~48
				{ 52,  4,  24, BOTH, FALSE},	// 5G, ch 52~64
				{ 149, 4,  30, BOTH, FALSE},	// 5G, ch 149~161
				{ 0},							// end
			}
		},

		{	// Cyprus
			"CY",
			CE,
			{
				{ 1,   13, 20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36,  4,  23, IDOR, FALSE},	// 5G, ch 36~48
				{ 52,  4,  24, IDOR, TRUE},		// 5G, ch 52~64
				{ 100, 11, 30, BOTH, TRUE},		// 5G, ch 100~140
				{ 0},							// end
			}
		},

		{	// Czech_Republic
			"CZ",
			CE,
			{
				{ 1,   13, 20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36,  4,  23, IDOR, FALSE},	// 5G, ch 36~48
				{ 52,  4,  23, IDOR, TRUE},		// 5G, ch 52~64
				{ 0},							// end
			}
		},

		{	// Denmark
			"DK",
			CE,
			{
				{ 1,   13, 20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36,  4,  23, IDOR, FALSE},	// 5G, ch 36~48
				{ 52,  4,  23, IDOR, TRUE},		// 5G, ch 52~64
				{ 100, 11, 30, BOTH, TRUE},		// 5G, ch 100~140
				{ 0},							// end
			}
		},

		{	// Dominican Republic
			"DO",
			CE,
			{
				{ 1,   0,  20, BOTH, FALSE},	// 2.4 G, ch 0
				{ 149, 4,  20, BOTH, FALSE},	// 5G, ch 149~161
				{ 0},							// end
			}
		},

		{	// Equador
			"EC",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 100, 11,  27, BOTH, FALSE},	// 5G, ch 100~140
				{ 0},							// end
			}
		},

		{	// El Salvador
			"SV",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36,  4,   23, IDOR, FALSE},	// 5G, ch 36~48
				{ 52,  4,   30, BOTH, TRUE},	// 5G, ch 52~64
				{ 149, 4,   36, BOTH, TRUE},	// 5G, ch 149~165
				{ 0},							// end
			}
		},

		{	// Finland
			"FI",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36,  4,   23, IDOR, FALSE},	// 5G, ch 36~48
				{ 52,  4,   23, IDOR, TRUE},	// 5G, ch 52~64
				{ 100, 11,  30, BOTH, TRUE},	// 5G, ch 100~140
				{ 0},							// end
			}
		},

		{	// France
			"FR",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36,  4,   23, IDOR, FALSE},	// 5G, ch 36~48
				{ 52,  4,   23, IDOR, TRUE},	// 5G, ch 52~64
				{ 0},							// end
			}
		},

		{	// Germany
			"DE",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36,  4,   23, IDOR, FALSE},	// 5G, ch 36~48
				{ 52,  4,   23, IDOR, TRUE},	// 5G, ch 52~64
				{ 100, 11,  30, BOTH, TRUE},	// 5G, ch 100~140
				{ 0},							// end
			}
		},

		{	// Greece
			"GR",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36,  4,   23, IDOR, FALSE},	// 5G, ch 36~48
				{ 52,  4,   23, IDOR, TRUE},	// 5G, ch 52~64
				{ 100, 11,  30, ODOR, TRUE},	// 5G, ch 100~140
				{ 0},							// end
			}
		},

		{	// Guam
			"GU",
			CE,
			{
				{ 1,   11,  20, BOTH, FALSE},	// 2.4 G, ch 1~11
				{ 36,  4,   17, BOTH, FALSE},	// 5G, ch 36~48
				{ 52,  4,   24, BOTH, FALSE},	// 5G, ch 52~64
				{ 100, 11,  30, BOTH, FALSE},	// 5G, ch 100~140
				{ 149,  5,  30, BOTH, FALSE},	// 5G, ch 149~165
				{ 0},							// end
			}
		},

		{	// Guatemala
			"GT",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36,  4,   17, BOTH, FALSE},	// 5G, ch 36~48
				{ 52,  4,   24, BOTH, FALSE},	// 5G, ch 52~64
				{ 149,  4,  30, BOTH, FALSE},	// 5G, ch 149~161
				{ 0},							// end
			}
		},

		{	// Haiti
			"HT",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36,  4,   17, BOTH, FALSE},	// 5G, ch 36~48
				{ 52,  4,   24, BOTH, FALSE},	// 5G, ch 52~64
				{ 149,  4,  30, BOTH, FALSE},	// 5G, ch 149~161
				{ 0},							// end
			}
		},

		{	// Honduras
			"HN",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 149,  4,  27, BOTH, FALSE},	// 5G, ch 149~161
				{ 0},							// end
			}
		},

		{	// Hong Kong
			"HK",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36,   4,  23, IDOR, FALSE},	// 5G, ch 36~48
				{ 52,   4,  23, IDOR, FALSE},	// 5G, ch 52~64
				{ 149,  4,  30, BOTH, FALSE},	// 5G, ch 149~161
				{ 0},							// end
			}
		},

		{	// Hungary
			"HU",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36,   4,  23, IDOR, FALSE},	// 5G, ch 36~48
				{ 52,   4,  23, IDOR, TRUE},	// 5G, ch 52~64
				{ 0},							// end
			}
		},

		{	// Iceland
			"IS",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36,   4,  23, IDOR, FALSE},	// 5G, ch 36~48
				{ 52,   4,  23, IDOR, TRUE},	// 5G, ch 52~64
				{ 100, 11,  30, BOTH, TRUE},	// 5G, ch 100~140
				{ 0},							// end
			}
		},

		{	// India
			"IN",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 149, 	4,  24, IDOR, FALSE},	// 5G, ch 149~161
				{ 0},							// end
			}
		},

		{	// Indonesia
			"ID",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 149, 	4,  27, BOTH, FALSE},	// 5G, ch 149~161
				{ 0},							// end
			}
		},

		{	// Indonesia
			"ID",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 149, 	4,  27, BOTH, FALSE},	// 5G, ch 149~161
				{ 0},							// end
			}
		},

		{	// Ireland
			"IE",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36, 	4,  23, IDOR, FALSE},	// 5G, ch 36~48
				{ 52, 	4,  23, IDOR, TRUE},	// 5G, ch 52~64
				{ 100, 11,  30, ODOR, TRUE},	// 5G, ch 100~140
				{ 0},							// end
			}
		},

		{	// Israel
			"IL",
			CE,
			{
				{ 1,    3,  20, IDOR, FALSE},	// 2.4 G, ch 1~3
				{ 4, 	6,  20, BOTH, FALSE},	// 2.4 G, ch 4~9
				{ 10, 	4,  20, IDOR, FALSE},	// 2.4 G, ch 10~13
				{ 0},							// end
			}
		},

		{	// Italy
			"IT",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36, 	4,  23, IDOR, FALSE},	// 5G, ch 36~48
				{ 52, 	4,  23, IDOR, TRUE},	// 5G, ch 52~64
				{ 100, 11,  30, ODOR, TRUE},	// 5G, ch 100~140
				{ 0},							// end
			}
		},

		{	// Japan
			"JP",
			JAP,
			{
				{ 1,   14,  20, BOTH, FALSE},	// 2.4 G, ch 1~14
				{ 34, 	4,  23, IDOR, FALSE},	// 5G, ch 34~46
				{ 0},							// end
			}
		},

		{	// Jordan
			"JO",
			CE,
			{
				{ 1,   13,  20, IDOR, FALSE},	// 2.4 G, ch 1~13
				{ 36, 	4,  23, IDOR, FALSE},	// 5G, ch 36~48
				{ 149, 	4,  23, IDOR, FALSE},	// 5G, ch 149~161
				{ 0},							// end
			}
		},

		{	// Latvia
			"LV",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36, 	4,  23, IDOR, FALSE},	// 5G, ch 36~48
				{ 52, 	4,  23, IDOR, TRUE},	// 5G, ch 52~64
				{ 100, 11,  30, BOTH, TRUE},	// 5G, ch 100~140
				{ 0},							// end
			}
		},

		{	// Liechtenstein
			"LI",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 52, 	4,  23, IDOR, TRUE},	// 5G, ch 52~64
				{ 100, 11,  30, BOTH, TRUE},	// 5G, ch 100~140
				{ 0},							// end
			}
		},

		{	// Lithuania
			"LT",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36, 	4,  23, IDOR, FALSE},	// 5G, ch 36~48
				{ 52, 	4,  23, IDOR, TRUE},	// 5G, ch 52~64
				{ 100, 11,  30, BOTH, TRUE},	// 5G, ch 100~140
				{ 0},							// end
			}
		},

		{	// Luxemburg
			"LU",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36, 	4,  23, IDOR, FALSE},	// 5G, ch 36~48
				{ 52, 	4,  23, IDOR, TRUE},	// 5G, ch 52~64
				{ 100, 11,  30, BOTH, TRUE},	// 5G, ch 100~140
				{ 0},							// end
			}
		},

		{	// Malaysia
			"MY",
			CE,
			{
				{ 36, 	4,  23, BOTH, FALSE},	// 5G, ch 36~48
				{ 52, 	4,  23, BOTH, FALSE},	// 5G, ch 52~64
				{ 149,  5,  20, BOTH, FALSE},	// 5G, ch 149~165
				{ 0},							// end
			}
		},

		{	// Malta
			"MT",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36, 	4,  23, IDOR, FALSE},	// 5G, ch 36~48
				{ 52, 	4,  23, IDOR, TRUE},	// 5G, ch 52~64
				{ 100, 11,  30, BOTH, TRUE},	// 5G, ch 100~140
				{ 0},							// end
			}
		},

		{	// Marocco
			"MA",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36, 	4,  24, IDOR, FALSE},	// 5G, ch 36~48
				{ 0},							// end
			}
		},

		{	// Mexico
			"MX",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36, 	4,  23, BOTH, FALSE},	// 5G, ch 36~48
				{ 52, 	4,  24, BOTH, FALSE},	// 5G, ch 52~64
				{ 149,  5,  30, IDOR, FALSE},	// 5G, ch 149~165
				{ 0},							// end
			}
		},

		{	// Netherlands
			"NL",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36, 	4,  23, IDOR, FALSE},	// 5G, ch 36~48
				{ 52, 	4,  24, IDOR, TRUE},	// 5G, ch 52~64
				{ 100, 11,  30, BOTH, TRUE},	// 5G, ch 100~140
				{ 0},							// end
			}
		},

		{	// New Zealand
			"NZ",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36, 	4,  24, BOTH, FALSE},	// 5G, ch 36~48
				{ 52, 	4,  24, BOTH, FALSE},	// 5G, ch 52~64
				{ 149,  4,  30, BOTH, FALSE},	// 5G, ch 149~161
				{ 0},							// end
			}
		},

		{	// Norway
			"NO",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36, 	4,  24, IDOR, FALSE},	// 5G, ch 36~48
				{ 52, 	4,  24, IDOR, TRUE},	// 5G, ch 52~64
				{ 100, 11,  30, BOTH, TRUE},	// 5G, ch 149~161
				{ 0},							// end
			}
		},

		{	// Peru
			"PE",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 149,  4,  27, BOTH, FALSE},	// 5G, ch 149~161
				{ 0},							// end
			}
		},

		{	// Portugal
			"PT",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36,   4,  23, IDOR, FALSE},	// 5G, ch 36~48
				{ 52,   4,  23, IDOR, TRUE},	// 5G, ch 52~64
				{ 100, 11,  30, BOTH, TRUE},	// 5G, ch 100~140
				{ 0},							// end
			}
		},

		{	// Poland
			"PL",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36,   4,  23, IDOR, FALSE},	// 5G, ch 36~48
				{ 52,   4,  23, IDOR, TRUE},	// 5G, ch 52~64
				{ 100, 11,  30, BOTH, TRUE},	// 5G, ch 100~140
				{ 0},							// end
			}
		},

		{	// Romania
			"RO",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36,   4,  23, IDOR, FALSE},	// 5G, ch 36~48
				{ 52,   4,  23, IDOR, TRUE},	// 5G, ch 52~64
				{ 100, 11,  30, BOTH, TRUE},	// 5G, ch 100~140
				{ 0},							// end
			}
		},

		{	// Russia
			"RU",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 149,  4,  20, IDOR, FALSE},	// 5G, ch 149~161
				{ 0},							// end
			}
		},

		{	// Saudi Arabia
			"SA",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36,   4,  23, BOTH, FALSE},	// 5G, ch 36~48
				{ 52,   4,  23, BOTH, FALSE},	// 5G, ch 52~64
				{ 149,  4,  23, BOTH, FALSE},	// 5G, ch 149~161
				{ 0},							// end
			}
		},

		{	// Serbia_and_Montenegro
			"CS",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 0},							// end
			}
		},

		{	// Singapore
			"SG",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36,   4,  23, BOTH, FALSE},	// 5G, ch 36~48
				{ 52,   4,  23, BOTH, FALSE},	// 5G, ch 52~64
				{ 149,  4,  20, BOTH, FALSE},	// 5G, ch 149~161
				{ 0},							// end
			}
		},

		{	// Slovakia
			"SK",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36,   4,  23, IDOR, FALSE},	// 5G, ch 36~48
				{ 52,   4,  23, IDOR, TRUE},	// 5G, ch 52~64
				{ 100, 11,  30, BOTH, TRUE},	// 5G, ch 100~140
				{ 0},							// end
			}
		},

		{	// Slovenia
			"SI",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36,   4,  23, IDOR, FALSE},	// 5G, ch 36~48
				{ 52,   4,  23, IDOR, TRUE},	// 5G, ch 52~64
				{ 0},							// end
			}
		},

		{	// South Africa
			"ZA",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36,   4,  23, BOTH, FALSE},	// 5G, ch 36~48
				{ 52,   4,  23, IDOR, FALSE},	// 5G, ch 52~64
				{ 100, 11,  30, BOTH, TRUE},	// 5G, ch 100~140
				{ 149,  4,  30, BOTH, FALSE},	// 5G, ch 149~161
				{ 0},							// end
			}
		},

		{	// South Korea
			"KR",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36,   4,  20, BOTH, FALSE},	// 5G, ch 36~48
				{ 52,   4,  20, BOTH, FALSE},	// 5G, ch 52~64
				{ 100,  8,  20, BOTH, FALSE},	// 5G, ch 100~128
				{ 149,  4,  20, BOTH, FALSE},	// 5G, ch 149~161
				{ 0},							// end
			}
		},

		{	// Spain
			"ES",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36,   4,  17, IDOR, FALSE},	// 5G, ch 36~48
				{ 52,   4,  23, IDOR, TRUE},	// 5G, ch 52~64
				{ 100, 11,  30, BOTH, TRUE},	// 5G, ch 100~140
				{ 0},							// end
			}
		},

		{	// Sweden
			"SE",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36,   4,  23, IDOR, FALSE},	// 5G, ch 36~48
				{ 52,   4,  23, IDOR, TRUE},	// 5G, ch 52~64
				{ 100, 11,  30, BOTH, TRUE},	// 5G, ch 100~140
				{ 0},							// end
			}
		},

		{	// Switzerland
			"CH",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~13
				{ 36,   4,  23, IDOR, TRUE},	// 5G, ch 36~48
				{ 52,   4,  23, IDOR, TRUE},	// 5G, ch 52~64
				{ 0},							// end
			}
		},

		{	// Taiwan
			"TW",
			CE,
			{
				{ 1,   11,  30, BOTH, FALSE},	// 2.4 G, ch 1~11
				{ 52,   4,  23, IDOR, FALSE},	// 5G, ch 52~64
				{ 0},							// end
			}
		},

		{	// Turkey
			"TR",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~11
				{ 36,   4,  23, BOTH, FALSE},	// 5G, ch 36~48
				{ 52,   4,  23, BOTH, FALSE},	// 5G, ch 52~64
				{ 0},							// end
			}
		},

		{	// UK
			"GB",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~11
				{ 36,   4,  23, IDOR, FALSE},	// 5G, ch 52~64
				{ 52,   4,  23, IDOR, TRUE},	// 5G, ch 52~64
				{ 100, 11,  30, BOTH, TRUE},	// 5G, ch 100~140
				{ 0},							// end
			}
		},

		{	// Ukraine
			"UA",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~11
				{ 0},							// end
			}
		},

		{	// United_Arab_Emirates
			"AE",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~11
				{ 0},							// end
			}
		},

		{	// United_States
			"US",
			CE,
			{
				{ 1,   11,  30, BOTH, FALSE},	// 2.4 G, ch 1~11
				{ 36,   4,  17, IDOR, FALSE},	// 5G, ch 52~64
				{ 52,   4,  24, BOTH, TRUE},	// 5G, ch 52~64
				{ 100, 11,  30, BOTH, TRUE},	// 5G, ch 100~140
				{ 149,  5,  30, BOTH, FALSE},	// 5G, ch 149~165
				{ 0},							// end
			}
		},

		{	// Venezuela
			"VE",
			CE,
			{
				{ 1,   13,  20, BOTH, FALSE},	// 2.4 G, ch 1~11
				{ 149,  4,  27, BOTH, FALSE},	// 5G, ch 149~161
				{ 0},							// end
			}
		},

		{	// Default
			"",
			CE,
			{
				{ 1,   11,  20, BOTH, FALSE},	// 2.4 G, ch 1~11
				{ 36,   4,  20, BOTH, FALSE},	// 5G, ch 52~64
				{ 52,   4,  20, BOTH, FALSE},	// 5G, ch 52~64
				{ 100, 11,  20, BOTH, FALSE},	// 5G, ch 100~140
				{ 149,  5,  20, BOTH, FALSE},	// 5G, ch 149~165
				{ 0},							// end
			}
		},
};

static inline PCH_REGION GetChRegion(
	IN PUCHAR CntryCode)
{
	INT loop = 0;
	PCH_REGION pChRegion = NULL;

	while (rom_strcmp((char *)ChRegion[loop].CountReg, "") != 0)
	{
		if (rom_strncmp((char *)ChRegion[loop].CountReg, (char *)CntryCode, 2) == 0)
		{
			pChRegion = &ChRegion[loop];
			break;
		}
		loop++;
	}

	if (pChRegion == NULL)
		pChRegion = &ChRegion[loop];
	return pChRegion;
}

static inline VOID ChBandCheck(
	IN UCHAR PhyMode,
	OUT PUCHAR pChType)
{
	switch(PhyMode)
	{
        case PHY_11A:
		case PHY_11AN_MIXED:
			*pChType = BAND_5G;
			break;
        case PHY_11AGN_MIXED:
        case PHY_11ABG_MIXED:
        case PHY_11ABGN_MIXED:
			*pChType = BAND_BOTH;
            break;

		default:
			*pChType = BAND_24G;
			break;
	}
}

static inline UCHAR FillChList(
	IN PRTMP_ADAPTER pAd,
	IN PCH_DESP pChDesp,
	IN UCHAR Offset, 
	IN UCHAR increment)
{
	INT i, j, l;
	UCHAR channel;

	j = Offset;
	for (i = 0; i < pChDesp->NumOfCh; i++)
	{
		channel = pChDesp->FirstChannel + i * increment;
		for (l=0; l<MAX_NUM_OF_CHANNELS; l++)
		{
			if (channel == pAd->TxPower[l].Channel)
			{
				pAd->ChannelList[j].Power = pAd->TxPower[l].Power;
				pAd->ChannelList[j].Power2 = pAd->TxPower[l].Power2;
				break;
			}
		}
		if (l == MAX_NUM_OF_CHANNELS)
			continue;

		pAd->ChannelList[j].Channel = pChDesp->FirstChannel + i * increment;
		pAd->ChannelList[j].MaxTxPwr = pChDesp->MaxTxPwr;
		pAd->ChannelList[j].DfsReq = pChDesp->DfsReq;
		j++;
	}
	pAd->ChannelListNum = j;

	return j;
}

static inline VOID CreateChList(
	IN PRTMP_ADAPTER pAd,
	IN PCH_REGION pChRegion,
	IN UCHAR Geography)
{
	INT i;
	UCHAR offset = 0;
	PCH_DESP pChDesp;
	UCHAR ChType;
	UCHAR increment;

	if (pChRegion == NULL)
		return;

	ChBandCheck(pAd->CommonCfg.PhyMode, &ChType);

	for (i=0; i<10; i++)
	{
		pChDesp = &pChRegion->ChDesp[i];
		if (pChDesp->FirstChannel == 0)
			break;

		if (ChType == BAND_5G)
		{
			if (pChDesp->FirstChannel <= 14)
				continue;
		}
		else if (ChType == BAND_24G)
		{
			if (pChDesp->FirstChannel > 14)
				continue;
		}

		if ((pChDesp->Geography == BOTH)
			|| (Geography == BOTH)
			|| (pChDesp->Geography == Geography))
        {
			if (pChDesp->FirstChannel > 14)
                increment = 4;
            else
                increment = 1;
			offset = FillChList(pAd, pChDesp, offset, increment);
        }
	}
}

static inline VOID BuildChannelListEx(
	IN PRTMP_ADAPTER pAd)
{
	PCH_REGION pChReg;

	pChReg = GetChRegion(pAd->CommonCfg.CountryCode);
	CreateChList(pAd, pChReg, pAd->CommonCfg.Geography);
}

static inline UCHAR GetExtCh(
	IN UCHAR Channel,
	IN UCHAR Direction)
{
	CHAR ExtCh;

	if (Direction == EXTCHA_ABOVE)
		ExtCh = Channel + 4;
	else
		ExtCh = (Channel - 4) > 0 ? (Channel - 4) : 0;

	return ExtCh;
}

static inline BOOLEAN IsValidChannel(
	IN PRTMP_ADAPTER pAd,
	IN UCHAR channel)

{
	INT i;

	for (i = 0; i < pAd->ChannelListNum; i++)
	{
		if (pAd->ChannelList[i].Channel == channel)
			break;
	}

	if (i == pAd->ChannelListNum)
		return FALSE;
	else
		return TRUE;
}

static inline VOID N_ChannelCheck(
	IN PRTMP_ADAPTER pAd)
{
	//UCHAR ChannelNum = pAd->ChannelListNum;
	UCHAR Channel = pAd->CommonCfg.Channel;
#ifdef PHYMODE_TO_WDEV
	if (WMODE_CAP_N(pAd->CommonCfg.PhyMode)&& (pAd->CommonCfg.RegTransmitSetting.field.BW  == BW_40))
#else
	if ((pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED) && (pAd->CommonCfg.RegTransmitSetting.field.BW  == BW_40))
#endif
	{
		if (Channel > 14)
		{
			if ((Channel == 36) || (Channel == 44) || (Channel == 52) || (Channel == 60) || (Channel == 100) || (Channel == 108) ||
			    (Channel == 116) || (Channel == 124) || (Channel == 132) || (Channel == 149) || (Channel == 157))
			{
				pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_ABOVE;
			}
			else if ((Channel == 40) || (Channel == 48) || (Channel == 56) || (Channel == 64) || (Channel == 104) || (Channel == 112) ||
					(Channel == 120) || (Channel == 128) || (Channel == 136) || (Channel == 153) || (Channel == 161))
			{
				pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_BELOW;
			}
			else
			{
				pAd->CommonCfg.RegTransmitSetting.field.BW  = BW_20;
			}
		}
		else
		{
			do
			{
				UCHAR ExtCh;
				UCHAR Dir = pAd->CommonCfg.RegTransmitSetting.field.EXTCHA;
				ExtCh = GetExtCh(Channel, Dir);
				if (IsValidChannel(pAd, ExtCh))
					break;

				Dir = (Dir == EXTCHA_ABOVE) ? EXTCHA_BELOW : EXTCHA_ABOVE;
				ExtCh = GetExtCh(Channel, Dir);
				if (IsValidChannel(pAd, ExtCh))
				{
					pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = Dir;
					break;
				}
				pAd->CommonCfg.RegTransmitSetting.field.BW  = BW_20;
			} while(FALSE);

			if (Channel == 14)
			{
				pAd->CommonCfg.RegTransmitSetting.field.BW  = BW_20;
				/*pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_NONE; We didn't set the ExtCh as NONE due to it'll set in RTMPSetHT()*/
			}
#if 0
			switch (pAd->CommonCfg.CountryRegion  & 0x7f)
			{
				case REGION_0_BG_BAND:	// 1 -11
				case REGION_1_BG_BAND:	// 1 - 13
				case REGION_5_BG_BAND:	// 1 - 14
					if (Channel <= 4)
					{
						pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_ABOVE;
					}
					else if (Channel >= 8)
					{
						if ((ChannelNum - Channel) < 4)
							pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_BELOW;
					}
					break;

				case REGION_2_BG_BAND:	// 10 - 11
				case REGION_3_BG_BAND:	// 10 - 13
				case REGION_4_BG_BAND:	// 14
					pAd->CommonCfg.RegTransmitSetting.field.BW  = BW_20;
					break;

				case REGION_6_BG_BAND:	// 3 - 9
					if (Channel <= 5)
						pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_ABOVE;
					else if (Channel == 6)
						pAd->CommonCfg.RegTransmitSetting.field.BW  = BW_20;
					else if (Channel >= 7)
						pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_BELOW;
					break;

				case REGION_7_BG_BAND:  // 5 - 13
					if (Channel <= 8)
						pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_ABOVE;
					else if (Channel >= 10)
						pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_BELOW;
					break;

				default:	// Error. should never happen
					break;
			}
#endif
		}
	}
}

static inline UCHAR N_SetCenCh(RTMP_ADAPTER *pAd, UCHAR prim_ch)
{
	if (pAd->CommonCfg.RegTransmitSetting.field.BW == BW_40)
	{
		pAd->CommonCfg.BBPCurrentBW = BW_40;
		if (pAd->CommonCfg.RegTransmitSetting.field.EXTCHA == EXTCHA_ABOVE)
			pAd->CommonCfg.CentralChannel = prim_ch + 2;
		else
		{
			if (prim_ch == 14)
				pAd->CommonCfg.CentralChannel = prim_ch - 1;
			else
				pAd->CommonCfg.CentralChannel = prim_ch - 2;
		}
	}
	else
		pAd->CommonCfg.CentralChannel = prim_ch;

	return pAd->CommonCfg.CentralChannel;
}
#endif // __CHLIST_H__

