109cbe818SShteryana Shopova /*-
24d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
31de7b4b8SPedro F. Giffuni  *
409cbe818SShteryana Shopova  * Copyright (c) 2010 The FreeBSD Foundation
509cbe818SShteryana Shopova  *
609cbe818SShteryana Shopova  * This software was developed by Shteryana Sotirova Shopova under
709cbe818SShteryana Shopova  * sponsorship from the FreeBSD Foundation.
809cbe818SShteryana Shopova  *
909cbe818SShteryana Shopova  * Redistribution and use in source and binary forms, with or without
1009cbe818SShteryana Shopova  * modification, are permitted provided that the following conditions
1109cbe818SShteryana Shopova  * are met:
1209cbe818SShteryana Shopova  * 1. Redistributions of source code must retain the above copyright
1309cbe818SShteryana Shopova  *    notice, this list of conditions and the following disclaimer.
1409cbe818SShteryana Shopova  * 2. Redistributions in binary form must reproduce the above copyright
1509cbe818SShteryana Shopova  *    notice, this list of conditions and the following disclaimer in the
1609cbe818SShteryana Shopova  *    documentation and/or other materials provided with the distribution.
1709cbe818SShteryana Shopova  *
1809cbe818SShteryana Shopova  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1909cbe818SShteryana Shopova  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2009cbe818SShteryana Shopova  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2109cbe818SShteryana Shopova  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2209cbe818SShteryana Shopova  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2309cbe818SShteryana Shopova  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2409cbe818SShteryana Shopova  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2509cbe818SShteryana Shopova  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2609cbe818SShteryana Shopova  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2709cbe818SShteryana Shopova  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2809cbe818SShteryana Shopova  * SUCH DAMAGE.
2909cbe818SShteryana Shopova  */
3009cbe818SShteryana Shopova 
3109cbe818SShteryana Shopova #define	WLAN_IFMODE_MAX				WlanIfaceOperatingModeType_tdma
3209cbe818SShteryana Shopova #define	WLAN_COUNTRY_CODE_SIZE			3
3309cbe818SShteryana Shopova #define	WLAN_BGSCAN_IDLE_MIN			100 /* XXX */
3409cbe818SShteryana Shopova #define	WLAN_SCAN_VALID_MIN			10 /* XXX */
3509cbe818SShteryana Shopova #define	WLAN_TDMA_MAXSLOTS			2 /* XXX */
3609cbe818SShteryana Shopova 
3709cbe818SShteryana Shopova struct wlan_iface;
3809cbe818SShteryana Shopova 
3909cbe818SShteryana Shopova struct wlan_peer {
4009cbe818SShteryana Shopova 	uint8_t				pmac[IEEE80211_ADDR_LEN]; /* key */
4109cbe818SShteryana Shopova 	uint16_t			associd;
4209cbe818SShteryana Shopova 	uint16_t			vlan;
4309cbe818SShteryana Shopova 	uint16_t			frequency;
4409cbe818SShteryana Shopova 	uint32_t			fflags;
4509cbe818SShteryana Shopova 	uint8_t				txrate;
4609cbe818SShteryana Shopova 	int8_t				rssi;
4709cbe818SShteryana Shopova 	uint16_t			idle;
4809cbe818SShteryana Shopova 	uint16_t			txseqs;
4909cbe818SShteryana Shopova 	uint16_t			rxseqs;
5009cbe818SShteryana Shopova 	uint16_t			txpower;
5109cbe818SShteryana Shopova 	uint8_t				capinfo;
5209cbe818SShteryana Shopova 	uint32_t			state;
5309cbe818SShteryana Shopova 	uint16_t			local_id;
5409cbe818SShteryana Shopova 	uint16_t			peer_id;
5509cbe818SShteryana Shopova 	SLIST_ENTRY(wlan_peer)		wp;
5609cbe818SShteryana Shopova };
5709cbe818SShteryana Shopova 
5809cbe818SShteryana Shopova SLIST_HEAD(wlan_peerlist, wlan_peer);
5909cbe818SShteryana Shopova 
6009cbe818SShteryana Shopova struct wlan_scan_result {
6109cbe818SShteryana Shopova 	uint8_t				ssid[IEEE80211_NWID_LEN + 1];
6209cbe818SShteryana Shopova 	uint8_t				bssid[IEEE80211_ADDR_LEN];
6309cbe818SShteryana Shopova 	uint8_t				opchannel;
6409cbe818SShteryana Shopova 	int8_t				rssi;
6509cbe818SShteryana Shopova 	uint16_t			frequency;
6609cbe818SShteryana Shopova 	int8_t				noise;
6709cbe818SShteryana Shopova 	uint16_t			bintval;
6809cbe818SShteryana Shopova 	uint8_t				capinfo;
6909cbe818SShteryana Shopova 	struct wlan_iface		*pwif;
7009cbe818SShteryana Shopova 	SLIST_ENTRY(wlan_scan_result)	wsr;
7109cbe818SShteryana Shopova };
7209cbe818SShteryana Shopova 
7309cbe818SShteryana Shopova SLIST_HEAD(wlan_scanlist, wlan_scan_result);
7409cbe818SShteryana Shopova 
7509cbe818SShteryana Shopova struct wlan_mac_mac {
7609cbe818SShteryana Shopova 	uint8_t				mac[IEEE80211_ADDR_LEN];
7709cbe818SShteryana Shopova 	enum RowStatus			mac_status;
7809cbe818SShteryana Shopova 	SLIST_ENTRY(wlan_mac_mac)	wm;
7909cbe818SShteryana Shopova };
8009cbe818SShteryana Shopova 
8109cbe818SShteryana Shopova SLIST_HEAD(wlan_maclist, wlan_mac_mac);
8209cbe818SShteryana Shopova 
8309cbe818SShteryana Shopova struct wlan_mesh_route {
8409cbe818SShteryana Shopova 	struct ieee80211req_mesh_route	imroute;
8509cbe818SShteryana Shopova 	enum RowStatus			mroute_status;
8609cbe818SShteryana Shopova 	SLIST_ENTRY(wlan_mesh_route)	wr;
8709cbe818SShteryana Shopova };
8809cbe818SShteryana Shopova 
8909cbe818SShteryana Shopova SLIST_HEAD(wlan_mesh_routes, wlan_mesh_route);
9009cbe818SShteryana Shopova 
9109cbe818SShteryana Shopova struct wlan_iface {
9209cbe818SShteryana Shopova 	char				wname[IFNAMSIZ];
9309cbe818SShteryana Shopova 	uint32_t			index;
9409cbe818SShteryana Shopova 	char				pname[IFNAMSIZ];
9509cbe818SShteryana Shopova 	enum WlanIfaceOperatingModeType	mode;
9609cbe818SShteryana Shopova 	uint32_t			flags;
9709cbe818SShteryana Shopova 	uint8_t				dbssid[IEEE80211_ADDR_LEN];
9809cbe818SShteryana Shopova 	uint8_t				dlmac[IEEE80211_ADDR_LEN];
9909cbe818SShteryana Shopova 	enum RowStatus			status;
10009cbe818SShteryana Shopova 	enum wlanIfaceState		state;
10109cbe818SShteryana Shopova 	uint8_t				internal;
10209cbe818SShteryana Shopova 
10309cbe818SShteryana Shopova 	uint32_t			drivercaps;
10409cbe818SShteryana Shopova 	uint32_t			cryptocaps;
10509cbe818SShteryana Shopova 	uint32_t			htcaps;
10609cbe818SShteryana Shopova 
10709cbe818SShteryana Shopova 	uint32_t			packet_burst;
10809cbe818SShteryana Shopova 	uint8_t				country_code[WLAN_COUNTRY_CODE_SIZE];
10909cbe818SShteryana Shopova 	enum WlanRegDomainCode		reg_domain;
11009cbe818SShteryana Shopova 	uint8_t				desired_ssid[IEEE80211_NWID_LEN + 1];
11109cbe818SShteryana Shopova 	uint32_t			desired_channel;
11209cbe818SShteryana Shopova 	enum TruthValue			dyn_frequency;
11309cbe818SShteryana Shopova 	enum TruthValue			fast_frames;
11409cbe818SShteryana Shopova 	enum TruthValue			dturbo;
11509cbe818SShteryana Shopova 	int32_t				tx_power;
11609cbe818SShteryana Shopova 	int32_t				frag_threshold;
11709cbe818SShteryana Shopova 	int32_t				rts_threshold;
11809cbe818SShteryana Shopova 	enum TruthValue			priv_subscribe;
11909cbe818SShteryana Shopova 	enum TruthValue			bg_scan;
12009cbe818SShteryana Shopova 	int32_t				bg_scan_idle;
12109cbe818SShteryana Shopova 	int32_t				bg_scan_interval;
12209cbe818SShteryana Shopova 	int32_t				beacons_missed;
12309cbe818SShteryana Shopova 	uint8_t				desired_bssid[IEEE80211_ADDR_LEN];
12409cbe818SShteryana Shopova 	enum wlanIfaceRoamingMode	roam_mode;
12509cbe818SShteryana Shopova 	enum TruthValue			dot11d;
12609cbe818SShteryana Shopova 	enum TruthValue			dot11h;
12709cbe818SShteryana Shopova 	enum TruthValue			dynamic_wds;
12809cbe818SShteryana Shopova 	enum TruthValue			power_save;
12909cbe818SShteryana Shopova 	enum TruthValue			ap_bridge;
13009cbe818SShteryana Shopova 	int32_t				beacon_interval;
13109cbe818SShteryana Shopova 	int32_t				dtim_period;
13209cbe818SShteryana Shopova 	enum TruthValue			hide_ssid;
13309cbe818SShteryana Shopova 	enum TruthValue			inact_process;
13409cbe818SShteryana Shopova 	enum wlanIfaceDot11gProtMode	do11g_protect;
13509cbe818SShteryana Shopova 	enum TruthValue			dot11g_pure;
13609cbe818SShteryana Shopova 	enum TruthValue			dot11n_pure;
13709cbe818SShteryana Shopova 	enum WlanIfaceDot11nPduType	ampdu;
13809cbe818SShteryana Shopova 	int32_t				ampdu_density;
13909cbe818SShteryana Shopova 	int32_t				ampdu_limit;
14009cbe818SShteryana Shopova 	enum WlanIfaceDot11nPduType	amsdu;
14109cbe818SShteryana Shopova 	int32_t				amsdu_limit;
14209cbe818SShteryana Shopova 	enum TruthValue			ht_enabled;
14309cbe818SShteryana Shopova 	enum TruthValue			ht_compatible;
14409cbe818SShteryana Shopova 	enum wlanIfaceDot11nHTProtMode	ht_prot_mode;
14509cbe818SShteryana Shopova 	enum TruthValue			rifs;
14609cbe818SShteryana Shopova 	enum TruthValue			short_gi;
14709cbe818SShteryana Shopova 	enum wlanIfaceDot11nSMPSMode	smps_mode;
14809cbe818SShteryana Shopova 	int32_t				tdma_slot;
14909cbe818SShteryana Shopova 	int32_t				tdma_slot_count;
15009cbe818SShteryana Shopova 	int32_t				tdma_slot_length;
15109cbe818SShteryana Shopova 	int32_t				tdma_binterval;
15209cbe818SShteryana Shopova 
15309cbe818SShteryana Shopova 	struct wlan_peerlist		peerlist;
15409cbe818SShteryana Shopova 	struct ieee80211_stats		stats;
15509cbe818SShteryana Shopova 	uint32_t			nchannels;
15609cbe818SShteryana Shopova 	struct ieee80211_channel	*chanlist;
15709cbe818SShteryana Shopova 	struct ieee80211_roamparams_req	roamparams;
15809cbe818SShteryana Shopova 	struct ieee80211_txparams_req	txparams;
15909cbe818SShteryana Shopova 
16009cbe818SShteryana Shopova 	uint32_t			scan_flags;
16109cbe818SShteryana Shopova 	uint32_t			scan_duration;
16209cbe818SShteryana Shopova 	uint32_t			scan_mindwell;
16309cbe818SShteryana Shopova 	uint32_t			scan_maxdwell;
16409cbe818SShteryana Shopova 	enum wlanScanConfigStatus	scan_status;
16509cbe818SShteryana Shopova 	struct wlan_scanlist		scanlist;
16609cbe818SShteryana Shopova 
16709cbe818SShteryana Shopova 	uint8_t				wepsupported;
16809cbe818SShteryana Shopova 	enum wlanWepMode		wepmode;
16909cbe818SShteryana Shopova 	int32_t				weptxkey;
17009cbe818SShteryana Shopova 
17109cbe818SShteryana Shopova 	uint8_t				macsupported;
17209cbe818SShteryana Shopova 	enum wlanMACAccessControlPolicy	mac_policy;
17309cbe818SShteryana Shopova 	uint32_t			mac_nacls;
17409cbe818SShteryana Shopova 	struct wlan_maclist		mac_maclist;
17509cbe818SShteryana Shopova 
17609cbe818SShteryana Shopova 	uint32_t			mesh_ttl;
1771605515dSDimitry Andric 	enum wlanMeshPeeringEnabled	mesh_peering;
1781605515dSDimitry Andric 	enum wlanMeshForwardingEnabled	mesh_forwarding;
17909cbe818SShteryana Shopova 	enum wlanMeshMetric		mesh_metric;
18009cbe818SShteryana Shopova 	enum wlanMeshPath		mesh_path;
18109cbe818SShteryana Shopova 	enum wlanHWMPRootMode		hwmp_root_mode;
18209cbe818SShteryana Shopova 	uint32_t			hwmp_max_hops;
18309cbe818SShteryana Shopova 	struct wlan_mesh_routes		mesh_routelist;
18409cbe818SShteryana Shopova 
18509cbe818SShteryana Shopova 	SLIST_ENTRY(wlan_iface)		w_if;
18609cbe818SShteryana Shopova };
18709cbe818SShteryana Shopova 
18809cbe818SShteryana Shopova enum wlan_syscl {
18909cbe818SShteryana Shopova 	WLAN_MESH_RETRY_TO = 0,
19009cbe818SShteryana Shopova 	WLAN_MESH_HOLDING_TO,
19109cbe818SShteryana Shopova 	WLAN_MESH_CONFIRM_TO,
19209cbe818SShteryana Shopova 	WLAN_MESH_MAX_RETRIES,
19309cbe818SShteryana Shopova 	WLAN_HWMP_TARGET_ONLY,
19409cbe818SShteryana Shopova 	WLAN_HWMP_REPLY_FORWARD,
19509cbe818SShteryana Shopova 	WLAN_HWMP_PATH_LIFETIME,
19609cbe818SShteryana Shopova 	WLAN_HWMP_ROOT_TO,
19709cbe818SShteryana Shopova 	WLAN_HWMP_ROOT_INT,
19809cbe818SShteryana Shopova 	WLAN_HWMP_RANN_INT,
19909cbe818SShteryana Shopova 	WLAN_HWMP_INACTIVITY_TO,
20009cbe818SShteryana Shopova 	WLAN_SYSCTL_MAX
20109cbe818SShteryana Shopova };
20209cbe818SShteryana Shopova 
20309cbe818SShteryana Shopova struct wlan_config {
20409cbe818SShteryana Shopova 	int32_t				mesh_retryto;
20509cbe818SShteryana Shopova 	int32_t				mesh_holdingto;
20609cbe818SShteryana Shopova 	int32_t				mesh_confirmto;
20709cbe818SShteryana Shopova 	int32_t				mesh_maxretries;
20809cbe818SShteryana Shopova 	int32_t				hwmp_targetonly;
20909cbe818SShteryana Shopova 	int32_t				hwmp_replyforward;
21009cbe818SShteryana Shopova 	int32_t				hwmp_pathlifetime;
21109cbe818SShteryana Shopova 	int32_t				hwmp_roottimeout;
21209cbe818SShteryana Shopova 	int32_t				hwmp_rootint;
21309cbe818SShteryana Shopova 	int32_t				hwmp_rannint;
21409cbe818SShteryana Shopova 	int32_t				hwmp_inact;
21509cbe818SShteryana Shopova };
21609cbe818SShteryana Shopova 
21709cbe818SShteryana Shopova int wlan_ioctl_init(void);
21809cbe818SShteryana Shopova int wlan_kmodules_load(void);
21909cbe818SShteryana Shopova int wlan_check_media(char *);
22009cbe818SShteryana Shopova int wlan_config_state(struct wlan_iface *, uint8_t);
22109cbe818SShteryana Shopova int wlan_get_opmode(struct wlan_iface *wif);
22209cbe818SShteryana Shopova int wlan_get_local_addr(struct wlan_iface *wif);
22309cbe818SShteryana Shopova int wlan_get_parent(struct wlan_iface *wif);
22409cbe818SShteryana Shopova int wlan_get_driver_caps(struct wlan_iface *wif);
22509cbe818SShteryana Shopova uint8_t wlan_channel_state_to_snmp(uint8_t cstate);
22609cbe818SShteryana Shopova uint32_t wlan_channel_flags_to_snmp(uint32_t cflags);
22709cbe818SShteryana Shopova int wlan_get_channel_list(struct wlan_iface *wif);
22809cbe818SShteryana Shopova int wlan_get_roam_params(struct wlan_iface *wif);
22909cbe818SShteryana Shopova int wlan_get_tx_params(struct wlan_iface *wif);
23009cbe818SShteryana Shopova int wlan_set_tx_params(struct wlan_iface *wif, int32_t pmode);
23109cbe818SShteryana Shopova int wlan_clone_create(struct wlan_iface *);
23209cbe818SShteryana Shopova int wlan_clone_destroy(struct wlan_iface *wif);
23309cbe818SShteryana Shopova int wlan_config_get_dssid(struct wlan_iface *wif);
23409cbe818SShteryana Shopova int wlan_config_set_dssid(struct wlan_iface *wif, char *ssid, int slen);
23509cbe818SShteryana Shopova int wlan_config_get_ioctl(struct wlan_iface *wif, int which);
23609cbe818SShteryana Shopova int wlan_config_set_ioctl(struct wlan_iface *wif, int which, int val,
23709cbe818SShteryana Shopova     char *strval, int len);
23809cbe818SShteryana Shopova int wlan_set_scan_config(struct wlan_iface *wif);
23909cbe818SShteryana Shopova int wlan_get_scan_results(struct wlan_iface *wif);
24009cbe818SShteryana Shopova int wlan_get_stats(struct wlan_iface *wif);
24109cbe818SShteryana Shopova int wlan_get_wepmode(struct wlan_iface *wif);
24209cbe818SShteryana Shopova int wlan_set_wepmode(struct wlan_iface *wif);
24309cbe818SShteryana Shopova int wlan_get_weptxkey(struct wlan_iface *wif);
24409cbe818SShteryana Shopova int wlan_set_weptxkey(struct wlan_iface *wif);
24509cbe818SShteryana Shopova int wlan_get_wepkeys(struct wlan_iface *wif);
24609cbe818SShteryana Shopova int wlan_set_wepkeys(struct wlan_iface *wif);
24709cbe818SShteryana Shopova int wlan_get_mac_policy(struct wlan_iface *wif);
24809cbe818SShteryana Shopova int wlan_set_mac_policy(struct wlan_iface *wif);
24909cbe818SShteryana Shopova int wlan_flush_mac_mac(struct wlan_iface *wif);
25009cbe818SShteryana Shopova int wlan_get_mac_acl_macs(struct wlan_iface *wif);
25109cbe818SShteryana Shopova int wlan_add_mac_acl_mac(struct wlan_iface *wif, struct wlan_mac_mac *mmac);
25209cbe818SShteryana Shopova int wlan_del_mac_acl_mac(struct wlan_iface *wif, struct wlan_mac_mac *mmac);
25309cbe818SShteryana Shopova 
25409cbe818SShteryana Shopova int32_t wlan_do_sysctl(struct wlan_config *cfg, enum wlan_syscl which, int set);
25509cbe818SShteryana Shopova int wlan_mesh_config_get(struct wlan_iface *wif, int which);
25609cbe818SShteryana Shopova int wlan_mesh_config_set(struct wlan_iface *wif, int which);
25709cbe818SShteryana Shopova int wlan_mesh_flush_routes(struct wlan_iface *wif);
25809cbe818SShteryana Shopova int wlan_mesh_add_route(struct wlan_iface *wif, struct wlan_mesh_route *wmr);
25909cbe818SShteryana Shopova int wlan_mesh_del_route(struct wlan_iface *wif, struct wlan_mesh_route *wmr);
26009cbe818SShteryana Shopova int wlan_mesh_get_routelist(struct wlan_iface *wif);
26109cbe818SShteryana Shopova int wlan_hwmp_config_get(struct wlan_iface *wif, int which);
26209cbe818SShteryana Shopova int wlan_hwmp_config_set(struct wlan_iface *wif, int which);
26309cbe818SShteryana Shopova 
26409cbe818SShteryana Shopova /* XXX: static */
26509cbe818SShteryana Shopova 
26609cbe818SShteryana Shopova int wlan_peer_set_vlan(struct wlan_iface *wif, struct wlan_peer *wip, int vlan);
26709cbe818SShteryana Shopova int wlan_get_peerinfo(struct wlan_iface *wif);
26809cbe818SShteryana Shopova 
26909cbe818SShteryana Shopova /* XXX*/
27009cbe818SShteryana Shopova struct wlan_peer *wlan_new_peer(const uint8_t *pmac);
27109cbe818SShteryana Shopova void wlan_free_peer(struct wlan_peer *wip);
27209cbe818SShteryana Shopova int wlan_add_peer(struct wlan_iface *wif, struct wlan_peer *wip);
27309cbe818SShteryana Shopova 
27409cbe818SShteryana Shopova struct wlan_scan_result * wlan_scan_new_result(const uint8_t *ssid,
27509cbe818SShteryana Shopova     const uint8_t *bssid);
27609cbe818SShteryana Shopova void wlan_scan_free_result(struct wlan_scan_result *sr);
27709cbe818SShteryana Shopova int wlan_scan_add_result(struct wlan_iface *wif, struct wlan_scan_result *sr);
27809cbe818SShteryana Shopova 
27909cbe818SShteryana Shopova struct wlan_mac_mac *wlan_mac_new_mac(const uint8_t *mac);
28009cbe818SShteryana Shopova void wlan_mac_free_mac(struct wlan_mac_mac *wmm);
28109cbe818SShteryana Shopova int wlan_mac_add_mac(struct wlan_iface *wif, struct wlan_mac_mac *wmm);
28209cbe818SShteryana Shopova 
28309cbe818SShteryana Shopova struct wlan_mesh_route *wlan_mesh_new_route(const uint8_t *dstmac);
28409cbe818SShteryana Shopova int wlan_mesh_add_rtentry(struct wlan_iface *wif, struct wlan_mesh_route *wmr);
28509cbe818SShteryana Shopova void wlan_mesh_free_route(struct wlan_mesh_route *wmr);
286