(LED+iwlist scan "quality"+timer BUG()) + patches

Live forum: http://rt2x00.serialmonkey.com/viewtopic.php?t=4257

javispedro

10-09-2007 16:14:11

Hi! I recently bought a Conceptronic PCMCIA card, which is based on the RT61 chip. I downloaded legacy rt61 driver and started playing with it (distro is Debian Lenny). It worked flawlessly, but there were some minor issues
[listmzzq1ucc][*mzzq1ucc]The first time you up the interface, the LEDs work fine (like in Windows). The second time you up the interface, LEDs are off. Even the activity LED is off. It seems that the driver calls RTMPSetLed(LED_HALT) at ifdown, but it won't call LED_RADIO_ON at ifup. It should call LED_RADIO_ON at MlmeRadioOn() but this function is never called. Don't know why. [/*mmzzq1ucc]
[*mzzq1ucc]Sometimes, after [imzzq1ucc]downing[/imzzq1ucc] the interface, the kernel would BUG() at timer.h. This is a timebomb after the BUG(), the kernel will crash later or sooner. pccardctl eject usually makes it crash. The cause is that add_timer(&pAd->Mlme.LinkDownTimer) is called while timer_pending() is true (connect.c, function LinkDown).[/*mmzzq1ucc]
[*mzzq1ucc]iwlist scan does not report signal quality; as such, wpa_supplicant does not, so NetworkManager does not either. I've indeed found the code to report signal quality, only to find it is commented with "#if 0". Why? [/*mmzzq1ucc][/listumzzq1ucc]

Those seem easy to resolve issues, but take care [umzzq1ucc]I don't really understand what's happening nor what's Wi-Fi about, i'm just doing newbie debugging[/umzzq1ucc].
[listmzzq1ucc]
[*mzzq1ucc]I've solved the LED issue by forcing a SetLED(LED_RADIO_ON) in SetLED(LED_LINK_UP). Example patch
[codemzzq1ucc]diff -ruN rt61-cvs-2007091007.orig/Module/rtmp_init.c rt61-cvs-2007091007/Module/rtmp_init.c
--- rt61-cvs-2007091007.orig/Module/rtmp_init.c 2007-09-10 13:13:54.000000000 +0000
+++ rt61-cvs-2007091007/Module/rtmp_init.c 2007-09-10 15:33:28.000000000 +0000
@@ -2150,6 +2150,9 @@

switch (Status) {
case LED_LINK_DOWN:
+ DBGPRINT(RT_DEBUG_INFO,
+ "RTMPSetLED::LED_LINK_DOWN\n");
+
pAd->LedCntl.field.LinkGStatus = 0;
pAd->LedCntl.field.LinkAStatus = 0;

@@ -2159,6 +2162,11 @@
pAd->LedIndicatorStregth = 0;
break;
case LED_LINK_UP:
+ DBGPRINT(RT_DEBUG_INFO,
+ "RTMPSetLED::LED_LINK_UP\n");
+
+ pAd->LedCntl.field.RadioStatus = 1; //javispedro: Force enable LED_RADIO_ON
+
if (pAd->PortCfg.Channel <= 14) {
// 11 G mode
pAd->LedCntl.field.LinkGStatus = 1;
@@ -2174,6 +2182,9 @@
AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte);
break;
case LED_RADIO_ON:
+ DBGPRINT(RT_DEBUG_INFO,
+ "RTMPSetLED::LED_RADIO_ON\n");
+
pAd->LedCntl.field.RadioStatus = 1;
HighByte = pAd->LedCntl.word >> 8;
LowByte = pAd->LedCntl.word & 0xFF;
@@ -2182,6 +2193,8 @@
case LED_HALT:
//Same as Radio Off.
case LED_RADIO_OFF:
+ DBGPRINT(RT_DEBUG_INFO,
+ "RTMPSetLED::LED_RADIO_OFF\n");
pAd->LedCntl.field.RadioStatus = 0;
pAd->LedCntl.field.LinkGStatus = 0;
pAd->LedCntl.field.LinkAStatus = 0;[/codemzzq1ucc][/*mmzzq1ucc]
[*mzzq1ucc]I've workaround the kernel bug by just checking timer_pending before add_timer. Again, this is an ugly hack (or not!), because I don't know/understand why is it adding the timer in the first place with the timer_pending, or if that's indicating a bug in some other place. Example patch
[codemzzq1ucc]diff -ruN rt61-cvs-2007091007.orig/Module/connect.c rt61-cvs-2007091007/Module/connect.c
--- rt61-cvs-2007091007.orig/Module/connect.c 2007-09-10 13:13:54.000000000 +0000
+++ rt61-cvs-2007091007/Module/connect.c 2007-09-10 13:49:33.000000000 +0000
@@ -1367,8 +1367,17 @@
pAd->MlmeAux.CurrReqIsFromNdis = FALSE;
} else {
// Set linkdown timer
+#if 0
pAd->Mlme.LinkDownTimer.expires = jiffies + 10 * HZ; // timeout Timer
add_timer(&pAd->Mlme.LinkDownTimer);
+#else
+ //Javispedro: hack to remove BUG
+ if (!timer_pending(&pAd->Mlme.LinkDownTimer))
+ {
+ pAd->Mlme.LinkDownTimer.expires = jiffies + 10 * HZ; // timeout Timer
+ add_timer(&pAd->Mlme.LinkDownTimer);
+ }
+#endif
}

BssTableDeleteEntry(&pAd->ScanTab, pAd->PortCfg.Bssid,[/codemzzq1ucc][/*mmzzq1ucc]
[*mzzq1ucc]As for the iwlist scan missing quality, well... just replace the #if 0 with #if 1 ) there is a missing } somewhere, it will syntax error, but that's easy to fix. The following patch is more complex than that, it reorders the code and does #if ENABLE_ADVANCED_INFO instead of #if 1.
[codemzzq1ucc]diff -ruN rt61-cvs-2007091007.orig/Module/rtmp_info.c rt61-cvs-2007091007/Module/rtmp_info.c
--- rt61-cvs-2007091007.orig/Module/rtmp_info.c 2007-09-10 13:13:54.000000000 +0000
+++ rt61-cvs-2007091007/Module/rtmp_info.c 2007-09-10 13:31:56.000000000 +0000
@@ -49,6 +49,8 @@
#include "rt_config.h"
#include <net/iw_handler.h>

+#define ENABLE_ADVANCED_INFO 1 // support bit rate, extended rate, quality and last beacon timing
+
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,29)
static inline unsigned int jiffies_to_msecs(const unsigned long j)
{
@@ -1887,7 +1889,7 @@
char *current_val;
struct iw_event iwe;

-#if 0 // support bit rate, extended rate, quality and last beacon timing
+#if ENABLE_ADVANCED_INFO // support bit rate, extended rate, quality and last beacon timing
//-------------------------------------------
char custom[MAX_CUSTOM_LEN];
char *p;
@@ -1995,30 +1997,7 @@
if (current_ev == previous_ev)
break;

-#if 1 // support bit rate
- //Bit Rate
- //================================
- memset(&iwe, 0, sizeof(iwe));
- iwe.cmd = SIOCGIWRATE;
- current_val = current_ev + IW_EV_LCP_LEN;
- //for (j = 0; j < pAdapter->ScanTab.BssEntry[i].RatesLen;j++)
- for (j = 0; j < 1; j++) {
- iwe.u.bitrate.value =
- RateIdToMbps[pAdapter->ScanTab.BssEntry[i].
- SupRate[i] / 2] * 1000000;
- iwe.u.bitrate.disabled = 0;
- current_val = iwe_stream_add_value(current_ev,
- current_val, end_buf,
- &iwe,
- IW_EV_PARAM_LEN);
-
- if ((current_val - current_ev) > IW_EV_LCP_LEN)
- current_ev = current_val;
- else
- break;
-
- }
-#else // support bit rate, extended rate, quality and last beacon timing
+#if ENABLE_ADVANCED_INFO // support bit rate, extended rate, quality and last beacon timing
// max. of displays used IW_SCAN_MAX_DATA are about 22~24 cells
//Bit Rate
//================================
@@ -2117,8 +2096,30 @@
custom);
if (current_ev == previous_ev)
break;
-#endif
+ }
+#else // support bit rate only
+ //Bit Rate
+ //================================
+ memset(&iwe, 0, sizeof(iwe));
+ iwe.cmd = SIOCGIWRATE;
+ current_val = current_ev + IW_EV_LCP_LEN;
+ //for (j = 0; j < pAdapter->ScanTab.BssEntry[i].RatesLen;j++)
+ for (j = 0; j < 1; j++) {
+ iwe.u.bitrate.value =
+ RateIdToMbps[pAdapter->ScanTab.BssEntry[i].
+ SupRate[i] / 2] * 1000000;
+ iwe.u.bitrate.disabled = 0;
+ current_val = iwe_stream_add_value(current_ev,
+ current_val, end_buf,
+ &iwe,
+ IW_EV_PARAM_LEN);

+ if ((current_val - current_ev) > IW_EV_LCP_LEN)
+ current_ev = current_val;
+ else
+ break;
+
+ }
//================================
memset(&iwe, 0, sizeof(iwe));
iwe.cmd = IWEVQUAL;
@@ -2135,6 +2136,7 @@
iwe_stream_add_event(current_ev, end_buf, &iwe,
IW_EV_QUAL_LEN);
//================================
+#endif
memset(&iwe, 0, sizeof(iwe));
}
data->length = current_ev - extra;[/codemzzq1ucc][/*mmzzq1ucc][/listumzzq1ucc]

As I said, I assume the patches are of bad quality, I didn't look at the whole code carefully. You have been warned! ;) They work fine on my laptop ([umzzq1ucc]even NetworkManager works with WPA[/umzzq1ucc], after having patched NetworkManager to support the ralink wpa_supplicant P ).

I also assume the driver is not mantained anymore (rt2x00 being the replacement), so I post the patches here in case anyone finds them useful; they're free for use.

Spy84464

12-09-2007 18:05:48

Hello,

I also assume the driver is not mantained anymore (rt2x00 being the replacement), so I post the patches here in case anyone finds them useful; they're free for use.[/quote1n6vss4t]
The legacy drivers are still maintained, but rt2x00 is indeed given the priority. I don't know if a driver developer had a look at them yet, but thanks for the patches!

Regards,
Romain

Vern

24-09-2007 16:39:45

Hi javispedro,

Please attach a file conatining your patches to a posting here.

Thanks,

javispedro

14-10-2007 13:54:42

Sorry for being late, here are the patches.

I've found that some things are still weird, like that wpa_supplicant is unable to connect to a open network (NetworkManager tries to do it even when it knows the network is open).

As I said on the first post, this patch file is mostly quick & dirty; even tough I think it applies cleanly to cvs 2007091007 it may or may not work for you...

Edit they apply to 2007101408 too.

Vern

15-10-2007 00:52:48

Hi javispedro,

Thanks for the file "conatining" your patches.