1178354Ssam/*-
2178354Ssam * Copyright (c) 2007-2008 Sam Leffler, Errno Consulting
3178354Ssam * All rights reserved.
4178354Ssam *
5178354Ssam * Redistribution and use in source and binary forms, with or without
6178354Ssam * modification, are permitted provided that the following conditions
7178354Ssam * are met:
8178354Ssam * 1. Redistributions of source code must retain the above copyright
9178354Ssam *    notice, this list of conditions and the following disclaimer.
10178354Ssam * 2. Redistributions in binary form must reproduce the above copyright
11178354Ssam *    notice, this list of conditions and the following disclaimer in the
12178354Ssam *    documentation and/or other materials provided with the distribution.
13178354Ssam *
14178354Ssam * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15178354Ssam * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16178354Ssam * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17178354Ssam * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18178354Ssam * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19178354Ssam * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20178354Ssam * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21178354Ssam * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22178354Ssam * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23178354Ssam * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24178354Ssam *
25178354Ssam * $FreeBSD$
26178354Ssam */
27178354Ssam#ifndef _LIB80211_H_
28178354Ssam#define _LIB80211_H_
29178354Ssam
30178354Ssam#include <sys/cdefs.h>
31178354Ssam#include <sys/queue.h>
32178354Ssam
33178354Ssam#include <net80211/ieee80211_regdomain.h>
34178354Ssam
35178354Ssam__BEGIN_DECLS
36178354Ssam
37178354Ssamstruct freqband {
38178354Ssam	uint16_t	freqStart;	/* starting frequency (MHz) */
39178354Ssam	uint16_t	freqEnd;	/* ending frequency (MHz) */
40178354Ssam	uint8_t		chanWidth;	/* channel width (MHz) */
41178354Ssam	uint8_t		chanSep;	/* channel sepaaration (MHz) */
42178354Ssam	uint32_t	flags;		/* common operational constraints */
43178354Ssam
44178354Ssam	const void	*id;
45178354Ssam	LIST_ENTRY(freqband) next;
46178354Ssam};
47178354Ssam
48188258Ssam/* private flags, don't pass to os */
49188258Ssam#define	REQ_ECM		0x1		/* enable if ECM set */
50188258Ssam#define	REQ_INDOOR	0x2		/* enable only for indoor operation */
51188258Ssam#define	REQ_OUTDOOR	0x4		/* enable only for outdoor operation */
52188258Ssam
53188258Ssam#define	REQ_FLAGS	(REQ_ECM|REQ_INDOOR|REQ_OUTDOOR)
54188258Ssam
55178354Ssamstruct netband {
56178354Ssam	const struct freqband *band;	/* channel list description */
57178354Ssam	uint8_t		maxPower;	/* regulatory cap on tx power (dBm) */
58178354Ssam	uint8_t		maxPowerDFS;	/* regulatory cap w/ DFS (dBm) */
59188155Ssam	uint8_t		maxAntGain;	/* max allowed antenna gain (.5 dBm) */
60178354Ssam	uint32_t	flags;		/* net80211 channel flags */
61178354Ssam
62178354Ssam	LIST_ENTRY(netband) next;
63178354Ssam};
64178354Ssamtypedef LIST_HEAD(, netband) netband_head;
65178354Ssam
66178354Ssamstruct country;
67178354Ssam
68178354Ssamstruct regdomain {
69178354Ssam	enum RegdomainCode	sku;	/* regdomain code/SKU */
70178354Ssam	const char		*name;	/* printable name */
71178354Ssam	const struct country	*cc;	/* country code for 1-1/default map */
72178354Ssam
73178354Ssam	netband_head	 bands_11b;	/* 11b operation */
74178354Ssam	netband_head	 bands_11g;	/* 11g operation */
75178354Ssam	netband_head	 bands_11a;	/* 11a operation */
76178354Ssam	netband_head	 bands_11ng;/* 11ng operation */
77178354Ssam	netband_head	 bands_11na;/* 11na operation */
78178354Ssam
79178354Ssam	LIST_ENTRY(regdomain)	next;
80178354Ssam};
81178354Ssam
82178354Ssamstruct country {
83178354Ssam	enum ISOCountryCode	code;
84186100Ssam#define	NO_COUNTRY	0xffff
85178354Ssam	const struct regdomain	*rd;
86178354Ssam	const char*		isoname;
87178354Ssam	const char*		name;
88178354Ssam
89178354Ssam	LIST_ENTRY(country)	next;
90178354Ssam};
91178354Ssam
92178354Ssamstruct ident;
93178354Ssam
94178354Ssamstruct regdata {
95178354Ssam	LIST_HEAD(, country)	countries;	/* country code table */
96178354Ssam	LIST_HEAD(, regdomain)	domains;	/* regulatory domains */
97178354Ssam	LIST_HEAD(, freqband)	freqbands;	/* frequency band table */
98178354Ssam	struct ident		*ident;		/* identifier table */
99178354Ssam};
100178354Ssam
101178354Ssam#define	_PATH_REGDOMAIN	"/etc/regdomain.xml"
102178354Ssam
103178354Ssamstruct regdata *lib80211_alloc_regdata(void);
104178354Ssamvoid	lib80211_free_regdata(struct regdata *);
105178354Ssam
106178354Ssamint	lib80211_regdomain_readconfig(struct regdata *, const void *, size_t);
107178354Ssamvoid	lib80211_regdomain_cleanup(struct regdata *);
108178354Ssam
109178354Ssamconst struct regdomain *lib80211_regdomain_findbysku(const struct regdata *,
110178354Ssam	enum RegdomainCode);
111178354Ssamconst struct regdomain *lib80211_regdomain_findbyname(const struct regdata *,
112178354Ssam	const char *);
113178354Ssam
114178354Ssamconst struct country *lib80211_country_findbycc(const struct regdata *,
115178354Ssam	enum ISOCountryCode);
116178354Ssamconst struct country *lib80211_country_findbyname(const struct regdata *,
117178354Ssam	const char *);
118178354Ssam
119178354Ssam__END_DECLS
120178354Ssam
121178354Ssam#endif /* _LIB80211_H_ */
122