1133759Srwatson/*-
2133759Srwatson * Copyright (c) 2011 Adrian Chadd, Xenion Pty Ltd
3133759Srwatson * All rights reserved.
4133759Srwatson *
5133759Srwatson * Redistribution and use in source and binary forms, with or without
6133759Srwatson * modification, are permitted provided that the following conditions
7133759Srwatson * are met:
8133759Srwatson * 1. Redistributions of source code must retain the above copyright
9133759Srwatson *    notice, this list of conditions and the following disclaimer,
10133759Srwatson *    without modification.
11133759Srwatson * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12133759Srwatson *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
13133759Srwatson *    redistribution must be conditioned upon including a substantially
14133759Srwatson *    similar Disclaimer requirement for further binary redistribution.
15133759Srwatson *
16133759Srwatson * NO WARRANTY
17133759Srwatson * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18133759Srwatson * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19133759Srwatson * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
20133759Srwatson * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21133759Srwatson * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
22133759Srwatson * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23133759Srwatson * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24133759Srwatson * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25133759Srwatson * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26133759Srwatson * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27133759Srwatson * THE POSSIBILITY OF SUCH DAMAGES.
28133759Srwatson *
29133759Srwatson * $FreeBSD$
30133759Srwatson */
31133759Srwatson#include <sys/cdefs.h>
32133759Srwatson__FBSDID("$FreeBSD$");
33133759Srwatson
34133759Srwatson/*
35 * This implements an empty DFS module.
36 */
37#include "opt_inet.h"
38#include "opt_wlan.h"
39
40#include <sys/param.h>
41#include <sys/systm.h>
42#include <sys/sysctl.h>
43#include <sys/kernel.h>
44#include <sys/lock.h>
45#include <sys/mutex.h>
46#include <sys/errno.h>
47
48#include <machine/bus.h>
49#include <machine/resource.h>
50#include <sys/bus.h>
51
52#include <sys/socket.h>
53
54#include <net/if.h>
55#include <net/if_media.h>
56#include <net/if_arp.h>
57#include <net/ethernet.h>		/* XXX for ether_sprintf */
58
59#include <net80211/ieee80211_var.h>
60
61#include <net/bpf.h>
62
63#ifdef INET
64#include <netinet/in.h>
65#include <netinet/if_ether.h>
66#endif
67
68#include <dev/ath/if_athvar.h>
69#include <dev/ath/if_athdfs.h>
70
71#include <dev/ath/ath_hal/ah_desc.h>
72
73/*
74 * Methods which are required
75 */
76
77/*
78 * Attach DFS to the given interface
79 */
80int
81ath_dfs_attach(struct ath_softc *sc)
82{
83	return 1;
84}
85
86/*
87 * Detach DFS from the given interface
88 */
89int
90ath_dfs_detach(struct ath_softc *sc)
91{
92	return 1;
93}
94
95/*
96 * Enable radar check
97 */
98void
99ath_dfs_radar_enable(struct ath_softc *sc, struct ieee80211_channel *chan)
100{
101	/* Check if the current channel is radar-enabled */
102	if (! IEEE80211_IS_CHAN_DFS(chan))
103		return;
104}
105
106/*
107 * Process DFS related PHY errors
108 */
109void
110ath_dfs_process_phy_err(struct ath_softc *sc, const char *buf,
111    uint64_t tsf, struct ath_rx_status *rxstat)
112{
113
114}
115
116/*
117 * Process the radar events and determine whether a DFS event has occured.
118 *
119 * This is designed to run outside of the RX processing path.
120 * The RX path will call ath_dfs_tasklet_needed() to see whether
121 * the task/callback running this routine needs to be called.
122 */
123int
124ath_dfs_process_radar_event(struct ath_softc *sc,
125    struct ieee80211_channel *chan)
126{
127	return 0;
128}
129
130/*
131 * Determine whether the DFS check task needs to be queued.
132 *
133 * This is called in the RX task when the current batch of packets
134 * have been received. It will return whether there are any radar
135 * events for ath_dfs_process_radar_event() to handle.
136 */
137int
138ath_dfs_tasklet_needed(struct ath_softc *sc, struct ieee80211_channel *chan)
139{
140	return 0;
141}
142
143/*
144 * Handle ioctl requests from the diagnostic interface.
145 *
146 * The initial part of this code resembles ath_ioctl_diag();
147 * it's likely a good idea to reduce duplication between
148 * these two routines.
149 */
150int
151ath_ioctl_phyerr(struct ath_softc *sc, struct ath_diag *ad)
152{
153	unsigned int id = ad->ad_id & ATH_DIAG_ID;
154	void *indata = NULL;
155	void *outdata = NULL;
156	u_int32_t insize = ad->ad_in_size;
157	u_int32_t outsize = ad->ad_out_size;
158	int error = 0;
159	HAL_PHYERR_PARAM peout;
160	HAL_PHYERR_PARAM *pe;
161
162	if (ad->ad_id & ATH_DIAG_IN) {
163		/*
164		 * Copy in data.
165		 */
166		indata = malloc(insize, M_TEMP, M_NOWAIT);
167		if (indata == NULL) {
168			error = ENOMEM;
169			goto bad;
170		}
171		error = copyin(ad->ad_in_data, indata, insize);
172		if (error)
173			goto bad;
174	}
175	if (ad->ad_id & ATH_DIAG_DYN) {
176		/*
177		 * Allocate a buffer for the results (otherwise the HAL
178		 * returns a pointer to a buffer where we can read the
179		 * results).  Note that we depend on the HAL leaving this
180		 * pointer for us to use below in reclaiming the buffer;
181		 * may want to be more defensive.
182		 */
183		outdata = malloc(outsize, M_TEMP, M_NOWAIT);
184		if (outdata == NULL) {
185			error = ENOMEM;
186			goto bad;
187		}
188	}
189	switch (id) {
190		case DFS_SET_THRESH:
191			if (insize < sizeof(HAL_PHYERR_PARAM)) {
192				error = EINVAL;
193				break;
194			}
195			pe = (HAL_PHYERR_PARAM *) indata;
196			ath_hal_enabledfs(sc->sc_ah, pe);
197			break;
198		case DFS_GET_THRESH:
199			memset(&peout, 0, sizeof(peout));
200			outsize = sizeof(HAL_PHYERR_PARAM);
201			ath_hal_getdfsthresh(sc->sc_ah, &peout);
202			pe = (HAL_PHYERR_PARAM *) outdata;
203			memcpy(pe, &peout, sizeof(*pe));
204			break;
205		default:
206			error = EINVAL;
207	}
208	if (outsize < ad->ad_out_size)
209		ad->ad_out_size = outsize;
210	if (outdata && copyout(outdata, ad->ad_out_data, ad->ad_out_size))
211		error = EFAULT;
212bad:
213	if ((ad->ad_id & ATH_DIAG_IN) && indata != NULL)
214		free(indata, M_TEMP);
215	if ((ad->ad_id & ATH_DIAG_DYN) && outdata != NULL)
216		free(outdata, M_TEMP);
217	return error;
218}
219
220/*
221 * Get the current DFS thresholds from the HAL
222 */
223int
224ath_dfs_get_thresholds(struct ath_softc *sc, HAL_PHYERR_PARAM *param)
225{
226	ath_hal_getdfsthresh(sc->sc_ah, param);
227	return 1;
228}
229