[PATCH] implement sensitivity control (resend)

Denis Vlasenko vda
Tue Aug 5 06:13:56 PDT 2003


I haven't seen any comments, maybe a resend is in order

==============================================================
From: Denis Vlasenko <vda at port.imtp.ilyichevsk.odessa.ua>
To: Jouni Malinen <jkmaline at cc.hut.fi>, Pavel Roskin <proski at gnu.org>
Subject: [PATCH] implement sensitivity control
Date: Thu, 3 Jul 2003 12:29:43 +0300
 
Hi Jouni, Pavel, folks.

I made a patch which implements sensitivity control for hostap.
Currently it does not program sensitivity at card initialization
(you'll need explicit iwconfig wlan# sens N or card remains
programmed as per default (max sens)) and sens settings do not
survive card reset. These can be fixed later.

Applies to today's CVS.

After iwconfig wlan0 sens 117:
wlan0     IEEE 802.11b
          Mode:Master  Frequency:2.422GHz
          Bit Rate:11Mb/s   Tx-Power=-1 dBm   Sensitivity=117/127

Untouched by iwconfig sens N:
wlan1     IEEE 802.11b
          Mode:Managed  Frequency:2.462GHz
          Bit Rate:2Mb/s   Tx-Power:5 dBm   Sensitivity=0/127

(this is wrong, should show 127/127. later...)

This is what I get in my logs with these patches:
=================================================
01:21:45 kernel:    A1=01:02:2d:61:49:cd A2=00:02:2d:51:3e:ab A3=00:00:00:00:00:00 A4=aa:aa:03:00:20:f6
01:21:45 kernel: wlan0: dropped received packet from 00:02:2d:51:3e:ab with no ToDS flag (type=0x02, subtype=0x00)
01:21:45 kernel: wlan0: RX signal=163 noise=156 rate=20 len=118 jiffies=16877
01:21:45 kernel:    FC=0x0008 (type=2:0) dur=0x0000 seq=0xdca0
01:21:45 kernel:    A1=01:02:2d:61:49:cd A2=00:02:2d:51:3e:ab A3=00:00:00:00:00:00 A4=aa:aa:03:00:20:f6
01:21:46 kernel: wlan0: dropped received packet from 00:02:2d:51:3e:ab with no ToDS flag (type=0x02, subtype=0x00)
01:21:46 kernel: wlan0: RX signal=163 noise=156 rate=20 len=281 jiffies=16892
01:21:46 kernel:    FC=0x0008 (type=2:0) dur=0x0000 seq=0xdd20
01:21:46 kernel:    A1=01:02:2d:61:49:cd A2=00:02:2d:51:3e:ab A3=00:00:00:00:00:00 A4=aa:aa:03:00:20:f6
01:21:46 kernel: wlan0: dropped received packet from 00:02:2d:51:3e:ab with no ToDS flag (type=0x02, subtype=0x00)

these are 'foreign' packets which I do not want to receive...

01:21:46 kernel: wlan0: RX signal=163 noise=156 rate=20 len=118 jiffies=16897
01:21:46 kernel:    FC=0x0008 (type=2:0) dur=0x0000 seq=0xdd40
01:21:46 kernel:    A1=01:02:2d:61:49:cd A2=00:02:2d:51:3e:ab A3=00:00:00:00:00:00 A4=aa:aa:03:00:20:f6
01:21:47 kernel: wlan0: dropped received packet from 00:02:2d:51:3e:ab with no ToDS flag (type=0x02, subtype=0x00)
01:21:47 kernel: wlan0: RX signal=163 noise=156 rate=20 len=50 jiffies=17030
01:21:47 kernel:    FC=0x0008 (type=2:0) dur=0x0000 seq=0xe240
01:21:47 kernel:    A1=01:02:2d:61:49:cd A2=00:02:2d:51:3e:ab A3=00:00:00:00:00:00 A4=aa:aa:03:00:20:f6

I do 'iwconfig wlan0 sens 117'

01:21:52 kernel: wlan0: ED_THRESHOLD: ->0a
01:21:52 kernel: wlan0: ACQUISITION_THRESHOLDS: 1e->5e

and no more bad packets seen ;)
--
vda

Now iwconfig sens N (0..127) does indeed have some effect

diff -ur hostap-2003-06-16/driver/modules/hostap_ioctl.c hostap-2003-06-16.sens/driver/modules/hostap_ioctl.c
--- hostap-2003-06-16/driver/modules/hostap_ioctl.c     Fri Jun  6 06:07:01 2003
+++ hostap-2003-06-16.sens/driver/modules/hostap_ioctl.c        Thu Jul  3 01:13:48 2003
@@ -503,14 +503,75 @@
                                struct iw_param *sens, char *extra)
 {
        local_info_t *local = (local_info_t *) dev->priv;
-
-       /* Set the desired AP density */
-       if (sens->value < 1 || sens->value > 3)
+       u16 val,newv;
+       
+       /* Energy Detected threshold: 0..127 <-> Sensitivity 127..0 */
+       
+       /* NB:  by default ED seen programmed to 127 (maxed out, lowest sens)
+       *       but ignored in both TX_CONFIGURE and ACQ_THRESH regs
+       *       That's how hw was prgrammed in my DWL-520
+       *       before I started to have fun with sens.
+       * TODO: special case sens 128: do not make Acquisition Thresholds
+       *       honour Energy Detected threshold.
+       *       Maybe it can pick weaker signals with that setting
+       * TODO: set max sens 127 (128) at init.
+       * TODO: teach driver to set sens after hw reset.
+       */
+       /* Set Energy Detected threshold */
+       if(sens->value < 0 || sens->value > 127)
+               return -EINVAL;
+       val = 127 - sens->value; /* bit 7=0 - threshold is rel to noise */
+       printk(KERN_DEBUG "%s: ED_THRESHOLD: ->%02x\n", dev->name, val);
+       if(local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF,
+         HFA386X_CR_ED_THRESHOLD, &val, NULL)) {
+               printk(KERN_ERR "%s: failure writing ED_THRESHOLD\n",
+                       dev->name);
                return -EINVAL;
-
-       if (hostap_set_word(dev, HFA384X_RID_CNFSYSTEMSCALE, sens->value) ||
-           local->func->reset_port(dev))
+       }
+#if 0  /* Seems like it has no effect (on my hw/fw conf) */
+       /* Make Clear Channel Assessment honour Energy Detected threshold */
+       if(local->func->cmd(dev, HFA384X_CMDCODE_READMIF,
+         HFA386X_CR_TX_CONFIGURE, NULL, &val)) {
+               printk(KERN_ERR "%s: failure reading TX_CONFIGURE\n",
+                       dev->name);
                return -EINVAL;
+       }
+       /* bits 6:5
+       * 00 - CCA is based only on ED. 
+       * 01 - CCA is based on (CS1 OR SQ1). 
+       * 10 - CCA is based on (ED AND (CS1 OR SQ1)). 
+       * 11 - CCA is based on (ED OR (CS1 OR SQ1)). */
+       newv = (val&0x9f)|0x40; /* 6:5=10 */
+       printk(KERN_DEBUG "%s: TX_CONFIGURE: %02x->%02x\n",
+               dev->name, val, newv);
+       if(val != newv) {
+               if(local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF,
+                 HFA386X_CR_TX_CONFIGURE, &newv, NULL)) {
+                       printk(KERN_ERR "%s: failure writing TX_CONFIGURE\n",
+                               dev->name);
+                       return -EINVAL;
+               }
+       }
+#endif
+       /* Make Acquisition Thresholds honour Energy Detected threshold */
+       if(local->func->cmd(dev, HFA384X_CMDCODE_READMIF,
+         HFA386X_CR_ACQUISITION_THRESHOLDS, NULL, &val)) {
+               printk(KERN_ERR "%s: failure reading ACQUISITION_THRESHOLDS\n",
+                       dev->name);
+               return -EINVAL;
+       }
+       /* bit 6 - ED and SQ1 control for acquisition. 0 = SQ1. 1 = ED and SQ1. */
+       newv = val|0x40;
+       printk(KERN_DEBUG "%s: ACQUISITION_THRESHOLDS: %02x->%02x\n",
+               dev->name, val, newv);
+       if(val != newv) {
+               if(local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF,
+                 HFA386X_CR_ACQUISITION_THRESHOLDS, &newv, NULL)) {
+                       printk(KERN_ERR "%s: failure writing "
+                               "ACQUISITION_THRESHOLDS\n", dev->name);
+                       return -EINVAL;
+               }
+       }
 
        return 0;
 }
@@ -520,14 +581,15 @@
                                struct iw_param *sens, char *extra)
 {
        local_info_t *local = (local_info_t *) dev->priv;
-       u16 val;
-
-       /* Get the current AP density */
-       if (local->func->get_rid(dev, HFA384X_RID_CNFSYSTEMSCALE, &val, 2, 1) <
-           0)
-               return -EINVAL;
 
-       sens->value = __le16_to_cpu(val);
+       u16 val;
+       if (local->func->cmd(dev, HFA384X_CMDCODE_READMIF,
+         HFA386X_CR_ED_THRESHOLD, NULL, &val)) {
+               printk(KERN_ERR "%s: failure reading ED_THRESHOLD\n",
+                       dev->name);
+               return -EINVAL;         /* or what? */
+       }
+       sens->value = 127-(val&0x7f);
        sens->fixed = 1;
 
        return 0;
@@ -932,7 +994,7 @@
        range->max_qual.qual = 92; /* 0 .. 92 */
        range->max_qual.level = 154; /* 27 .. 154 */
        range->max_qual.noise = 154; /* 27 .. 154 */
-       range->sensitivity = 3;
+       range->sensitivity = 127;
 
        range->max_encoding_tokens = WEP_KEYS;
        range->num_encoding_sizes = 2;
diff -ur hostap-2003-06-16/driver/modules/hostap_wlan.h hostap-2003-06-16.sens/driver/modules/hostap_wlan.h
--- hostap-2003-06-16/driver/modules/hostap_wlan.h      Fri May 23 05:23:48 2003
+++ hostap-2003-06-16.sens/driver/modules/hostap_wlan.h Sat Jun 28 23:38:54 2003
@@ -681,6 +681,8 @@
 #define HFA386X_CR_RX_CONFIGURE 0x14
 #define HFA386X_CR_A_D_TEST_MODES2 0x1A
 #define HFA386X_CR_MANUAL_TX_POWER 0x3E
+#define HFA386X_CR_ED_THRESHOLD 0x46
+#define HFA386X_CR_ACQUISITION_THRESHOLDS 0x5E
 
 /* IEEE 802.11 defines */
 




More information about the Hostap mailing list