From c5f2a23c79e32b35d739b562d27b1054419a396b Mon Sep 17 00:00:00 2001 From: Adrian Chadd Date: Fri, 22 Jul 2011 09:39:49 +0000 Subject: [PATCH] Implement a basic radar parameter API in the dfs_null module. Since no actual radar data is ever handled, this won't do anything. It's mostly here as a reference for those who wish to experiment with radar detection. Approved by: re (kib) --- sys/dev/ath/ath_dfs/null/dfs_null.c | 74 +++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 3 deletions(-) diff --git a/sys/dev/ath/ath_dfs/null/dfs_null.c b/sys/dev/ath/ath_dfs/null/dfs_null.c index 2f050a40d1cf..b5c85bf63bb9 100644 --- a/sys/dev/ath/ath_dfs/null/dfs_null.c +++ b/sys/dev/ath/ath_dfs/null/dfs_null.c @@ -61,7 +61,7 @@ __FBSDID("$FreeBSD$"); #include #ifdef INET -#include +#include #include #endif @@ -141,12 +141,80 @@ ath_dfs_tasklet_needed(struct ath_softc *sc, struct ieee80211_channel *chan) } /* - * Handle ioctl requests from the diagnostic interface + * Handle ioctl requests from the diagnostic interface. + * + * The initial part of this code resembles ath_ioctl_diag(); + * it's likely a good idea to reduce duplication between + * these two routines. */ int ath_ioctl_phyerr(struct ath_softc *sc, struct ath_diag *ad) { - return 1; + unsigned int id = ad->ad_id & ATH_DIAG_ID; + void *indata = NULL; + void *outdata = NULL; + u_int32_t insize = ad->ad_in_size; + u_int32_t outsize = ad->ad_out_size; + int error = 0; + HAL_PHYERR_PARAM peout; + HAL_PHYERR_PARAM *pe; + + if (ad->ad_id & ATH_DIAG_IN) { + /* + * Copy in data. + */ + indata = malloc(insize, M_TEMP, M_NOWAIT); + if (indata == NULL) { + error = ENOMEM; + goto bad; + } + error = copyin(ad->ad_in_data, indata, insize); + if (error) + goto bad; + } + if (ad->ad_id & ATH_DIAG_DYN) { + /* + * Allocate a buffer for the results (otherwise the HAL + * returns a pointer to a buffer where we can read the + * results). Note that we depend on the HAL leaving this + * pointer for us to use below in reclaiming the buffer; + * may want to be more defensive. + */ + outdata = malloc(outsize, M_TEMP, M_NOWAIT); + if (outdata == NULL) { + error = ENOMEM; + goto bad; + } + } + switch (id) { + case DFS_SET_THRESH: + if (insize < sizeof(HAL_PHYERR_PARAM)) { + error = -EINVAL; + break; + } + pe = (HAL_PHYERR_PARAM *) indata; + ath_hal_enabledfs(sc->sc_ah, pe); + break; + case DFS_GET_THRESH: + memset(&peout, 0, sizeof(peout)); + outsize = sizeof(HAL_PHYERR_PARAM); + ath_hal_getdfsthresh(sc->sc_ah, &peout); + pe = (HAL_PHYERR_PARAM *) outdata; + memcpy(pe, &peout, sizeof(*pe)); + break; + default: + error = -EINVAL; + } + if (outsize < ad->ad_out_size) + ad->ad_out_size = outsize; + if (outdata && copyout(outdata, ad->ad_out_data, ad->ad_out_size)) + error = -EFAULT; +bad: + if ((ad->ad_id & ATH_DIAG_IN) && indata != NULL) + free(indata, M_TEMP); + if ((ad->ad_id & ATH_DIAG_DYN) && outdata != NULL) + free(outdata, M_TEMP); + return error; } /*