Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 30 Sep 2003 14:53:55 +0200
From:      Jiri Mikulas <konfer@mikulas.com>
To:        freebsd-current@freebsd.org
Subject:   wicontrol TX patch
Message-ID:  <3F797CE3.7060506@mikulas.com>

next in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------040908030209040104050607
Content-Type: text/plain; charset=ISO-8859-2; format=flowed
Content-Transfer-Encoding: 7bit

Hello
My questoin is about status of wicontrol TX power control  in current ?
Anybody planing to commit it into wicontrol ?
I use modified patch from "imp" for three months
it works well, but problem is, that if card is reseted by wi_reset - i 
guess,
value from register is owerwrited by default (I think ALC also turns on)
any ideas/solutions how keep this TX power value after card reset ?
for this time I use cron to  periodicaly refresh TX power ..
sorry for my english ;)
thaks for reply
Jiri

--------------040908030209040104050607
Content-Type: text/plain;
 name="wicontrol-1.37-TX.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="wicontrol-1.37-TX.diff"

--- usr.sbin/wicontrol/wicontrol.c	Tue Sep 30 00:55:25 2003
+++ usr.sbin/wicontrol/wicontrol.c	Tue Sep 30 12:54:26 2003
@@ -1070,6 +1070,135 @@
 	    opt);
 }
 
+/* TX Power patch */
+static void
+wi_setdebug(const char *iface, struct wi_req *wreq)
+{
+	struct ifreq		ifr;
+	int			s;
+
+	bzero((char *)&ifr, sizeof(ifr));
+
+	strlcpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name));
+	ifr.ifr_data = (caddr_t)wreq;
+
+	s = socket(AF_INET, SOCK_DGRAM, 0);
+
+	if (s == -1)
+		err(1, "socket");
+
+	if (ioctl(s, SIOCSPRISM2DEBUG, &ifr) == -1)
+		err(1, "SIOCSPRISM2DEBUG");
+
+	close(s);
+
+	return;
+}
+
+#if 0
+static void
+wi_getdebug(const char *iface, struct wi_req *wreq)
+{
+	struct ifreq		ifr;
+	int			s;
+
+	bzero((char *)&ifr, sizeof(ifr));
+
+	strlcpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name));
+	ifr.ifr_data = (caddr_t)wreq;
+
+	s = socket(AF_INET, SOCK_DGRAM, 0);
+
+	if (s == -1)
+		err(1, "socket");
+
+	if (ioctl(s, SIOCGPRISM2DEBUG, &ifr) == -1)
+		err(1, "SIOCGPRISM2DEBUG");
+
+	close(s);
+
+	return;
+}
+#endif
+
+/* Map HFA386x's CR31 to and from dBm with some sort of ad hoc mapping..
+ * This version assumes following mapping:
+ * CR31 is 7-bit value with -64 to 63 range.
+ * -64 is mapped into 20dBm and 63 into -43dBm.
+ * This is certainly not an exact mapping for every card, but at least
+ * increasing dBm value should correspond to increasing TX power.
+ */
+
+static int
+wi_txpower_to_dBm(uint16_t val)
+{
+	signed char tmp;
+
+	if (val > 255)
+		val = 255;
+       
+	tmp = val;
+	tmp >>= 2;
+
+	return -12 - tmp;
+}
+
+#if 0
+static uint16_t
+wi_dBm_to_txpower(int val)
+{
+	signed char tmp;
+
+	if (val > 20)
+		return 128;
+	else if (val < -43)
+		return 127;
+       
+	tmp = val;
+	tmp = -12 - tmp; 
+	tmp <<= 2;
+
+	return (unsigned char) tmp;
+}
+#endif
+
+static void
+wi_readpower(const char *iface)
+{
+	struct wi_req wreq;
+
+	printf("reading power\n");
+
+	wreq.wi_type = WI_RID_MIF;
+	wreq.wi_val[0] = WI_HFA386X_CR_MANUAL_TX_POWER;
+	wreq.wi_len = 1 + 1;
+
+	wi_getval(iface, &wreq);
+	printf("Value returned was 0x%x or %d dBm\n", wreq.wi_val[0],
+	wi_txpower_to_dBm(wreq.wi_val[0]));
+}
+
+static void
+wi_writepower(const char *iface, int power)
+{
+	struct wi_req wreq;
+
+	wreq.wi_type = WI_RID_MIF;
+	wreq.wi_val[0] = WI_HFA386X_CR_MANUAL_TX_POWER;
+	wreq.wi_val[1] = power;
+	wreq.wi_len = 1 + 1 + 1;
+	wi_setval(iface, &wreq);
+
+	wreq.wi_type = WI_DEBUG_CONFBITS;
+	wreq.wi_val[0] = 0;
+	wreq.wi_val[1] = 0x8;
+	wreq.wi_len = 1 + 1 + 1;
+	wi_setdebug(iface, &wreq);
+
+}
+
+/* TX Power patch end */
+
 int
 main(int argc, char *argv[])
 {
@@ -1097,8 +1226,20 @@
 	opterr = 1;
 		
 	while((ch = getopt(argc, argv,
-	    "a:c:d:e:f:hi:k:lm:n:op:q:r:s:t:v:CF:LP:QS:T:Z")) != -1) {
+		/* Patched ARGS for tx power (AB added) */
+		/* old: "a:c:d:e:f:hi:k:lm:n:op:q:r:s:t:v:CF:LP:QS:T:Z")) != -1) { */
+		"a:c:d:e:f:hi:k:lm:n:op:q:r:s:t:v:AB:CF:LP:QS:T:Z")) != -1) {
 		switch(ch) {
+		/* TX Power patch */
+		case 'A':
+			wi_readpower(iface);
+			exit(0);
+			break;
+		case 'B':
+			wi_writepower(iface, atoi(optarg));
+			exit(0);
+			break;
+		/* TX Power patch end */
 		case 'Z':
 #ifdef WICACHE
 			wi_zerocache(iface);

--------------040908030209040104050607--



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