Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 22 Jul 2011 09:39:49 +0000 (UTC)
From:      Adrian Chadd <adrian@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r224267 - head/sys/dev/ath/ath_dfs/null
Message-ID:  <201107220939.p6M9dnsR008517@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: adrian
Date: Fri Jul 22 09:39:49 2011
New Revision: 224267
URL: http://svn.freebsd.org/changeset/base/224267

Log:
  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)

Modified:
  head/sys/dev/ath/ath_dfs/null/dfs_null.c

Modified: head/sys/dev/ath/ath_dfs/null/dfs_null.c
==============================================================================
--- head/sys/dev/ath/ath_dfs/null/dfs_null.c	Fri Jul 22 09:34:31 2011	(r224266)
+++ head/sys/dev/ath/ath_dfs/null/dfs_null.c	Fri Jul 22 09:39:49 2011	(r224267)
@@ -61,7 +61,7 @@ __FBSDID("$FreeBSD$");
 #include <net/bpf.h>
 
 #ifdef INET
-#include <netinet/in.h> 
+#include <netinet/in.h>
 #include <netinet/if_ether.h>
 #endif
 
@@ -141,12 +141,80 @@ ath_dfs_tasklet_needed(struct ath_softc 
 }
 
 /*
- * 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;
 }
 
 /*



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201107220939.p6M9dnsR008517>