xref: /freebsd/sys/dev/ath/ath_dfs/null/dfs_null.c (revision b7c60aadbbd5c846a250c05791fe7406d6d78bf4)
1 /*-
2  * Copyright (c) 2011 Adrian Chadd, Xenion Pty Ltd
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer,
10  *    without modification.
11  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12  *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
13  *    redistribution must be conditioned upon including a substantially
14  *    similar Disclaimer requirement for further binary redistribution.
15  *
16  * NO WARRANTY
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
20  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21  * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
22  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27  * THE POSSIBILITY OF SUCH DAMAGES.
28  *
29  * $FreeBSD$
30  */
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
33 
34 /*
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  */
80 int
81 ath_dfs_attach(struct ath_softc *sc)
82 {
83 	return 1;
84 }
85 
86 /*
87  * Detach DFS from the given interface
88  */
89 int
90 ath_dfs_detach(struct ath_softc *sc)
91 {
92 	return 1;
93 }
94 
95 /*
96  * Enable radar check
97  */
98 int
99 ath_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 (0);
104 
105 	/*
106 	 * Enabling the radar parameters and setting sc->sc_dodfs = 1
107 	 * would occur here.
108 	 */
109 
110 	return (1);
111 }
112 
113 /*
114  * Process DFS related PHY errors
115  */
116 void
117 ath_dfs_process_phy_err(struct ath_softc *sc, const char *buf,
118     uint64_t tsf, struct ath_rx_status *rxstat)
119 {
120 
121 }
122 
123 /*
124  * Process the radar events and determine whether a DFS event has occured.
125  *
126  * This is designed to run outside of the RX processing path.
127  * The RX path will call ath_dfs_tasklet_needed() to see whether
128  * the task/callback running this routine needs to be called.
129  */
130 int
131 ath_dfs_process_radar_event(struct ath_softc *sc,
132     struct ieee80211_channel *chan)
133 {
134 	return 0;
135 }
136 
137 /*
138  * Determine whether the DFS check task needs to be queued.
139  *
140  * This is called in the RX task when the current batch of packets
141  * have been received. It will return whether there are any radar
142  * events for ath_dfs_process_radar_event() to handle.
143  */
144 int
145 ath_dfs_tasklet_needed(struct ath_softc *sc, struct ieee80211_channel *chan)
146 {
147 	return 0;
148 }
149 
150 /*
151  * Handle ioctl requests from the diagnostic interface.
152  *
153  * The initial part of this code resembles ath_ioctl_diag();
154  * it's likely a good idea to reduce duplication between
155  * these two routines.
156  */
157 int
158 ath_ioctl_phyerr(struct ath_softc *sc, struct ath_diag *ad)
159 {
160 	unsigned int id = ad->ad_id & ATH_DIAG_ID;
161 	void *indata = NULL;
162 	void *outdata = NULL;
163 	u_int32_t insize = ad->ad_in_size;
164 	u_int32_t outsize = ad->ad_out_size;
165 	int error = 0;
166 	HAL_PHYERR_PARAM peout;
167 	HAL_PHYERR_PARAM *pe;
168 
169 	if (ad->ad_id & ATH_DIAG_IN) {
170 		/*
171 		 * Copy in data.
172 		 */
173 		indata = malloc(insize, M_TEMP, M_NOWAIT);
174 		if (indata == NULL) {
175 			error = ENOMEM;
176 			goto bad;
177 		}
178 		error = copyin(ad->ad_in_data, indata, insize);
179 		if (error)
180 			goto bad;
181 	}
182 	if (ad->ad_id & ATH_DIAG_DYN) {
183 		/*
184 		 * Allocate a buffer for the results (otherwise the HAL
185 		 * returns a pointer to a buffer where we can read the
186 		 * results).  Note that we depend on the HAL leaving this
187 		 * pointer for us to use below in reclaiming the buffer;
188 		 * may want to be more defensive.
189 		 */
190 		outdata = malloc(outsize, M_TEMP, M_NOWAIT);
191 		if (outdata == NULL) {
192 			error = ENOMEM;
193 			goto bad;
194 		}
195 	}
196 	switch (id) {
197 		case DFS_SET_THRESH:
198 			if (insize < sizeof(HAL_PHYERR_PARAM)) {
199 				error = EINVAL;
200 				break;
201 			}
202 			pe = (HAL_PHYERR_PARAM *) indata;
203 			ath_hal_enabledfs(sc->sc_ah, pe);
204 			break;
205 		case DFS_GET_THRESH:
206 			memset(&peout, 0, sizeof(peout));
207 			outsize = sizeof(HAL_PHYERR_PARAM);
208 			ath_hal_getdfsthresh(sc->sc_ah, &peout);
209 			pe = (HAL_PHYERR_PARAM *) outdata;
210 			memcpy(pe, &peout, sizeof(*pe));
211 			break;
212 		default:
213 			error = EINVAL;
214 	}
215 	if (outsize < ad->ad_out_size)
216 		ad->ad_out_size = outsize;
217 	if (outdata && copyout(outdata, ad->ad_out_data, ad->ad_out_size))
218 		error = EFAULT;
219 bad:
220 	if ((ad->ad_id & ATH_DIAG_IN) && indata != NULL)
221 		free(indata, M_TEMP);
222 	if ((ad->ad_id & ATH_DIAG_DYN) && outdata != NULL)
223 		free(outdata, M_TEMP);
224 	return error;
225 }
226 
227 /*
228  * Get the current DFS thresholds from the HAL
229  */
230 int
231 ath_dfs_get_thresholds(struct ath_softc *sc, HAL_PHYERR_PARAM *param)
232 {
233 	ath_hal_getdfsthresh(sc->sc_ah, param);
234 	return 1;
235 }
236