pcmcia: do not use io_req_t after call to pcmcia_request_io()
[linux-2.6.git] / drivers / staging / rtl8192su / r8192SU_led.c
1 /*
2  * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved.
3  *
4  * This program is distributed in the hope that it will be useful, but WITHOUT
5  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
7  * more details.
8  *
9  * You should have received a copy of the GNU General Public License along with
10  * this program; if not, write to the Free Software Foundation, Inc.,
11  * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
12  *
13  * The full GNU General Public License is included in this distribution in the
14  * file called LICENSE.
15  *
16  * Contact Information:
17  * wlanfae <wlanfae@realtek.com>
18  */
19
20 #include "r8192U.h"
21 #include "r8192S_hw.h"
22 #include "r8192SU_led.h"
23
24 #define LED_BLINK_NORMAL_INTERVAL               100
25 #define LED_BLINK_SLOWLY_INTERVAL               200
26 #define LED_BLINK_LONG_INTERVAL                 400
27
28 #define LED_BLINK_NO_LINK_INTERVAL_ALPHA        1000
29 #define LED_BLINK_LINK_INTERVAL_ALPHA           500
30 #define LED_BLINK_SCAN_INTERVAL_ALPHA           180
31 #define LED_BLINK_FASTER_INTERVAL_ALPHA         50
32 #define LED_BLINK_WPS_SUCESS_INTERVAL_ALPHA     5000
33
34
35
36 static void BlinkTimerCallback (unsigned long data);
37
38 static void BlinkWorkItemCallback (struct work_struct *work);
39
40 void InitLed819xUsb (struct net_device *dev, PLED_819xUsb pLed,
41                                                         LED_PIN_819xUsb LedPin)
42 {
43         struct r8192_priv *priv = ieee80211_priv(dev);
44
45         pLed->dev = dev;
46         pLed->LedPin = LedPin;
47         pLed->CurrLedState = LED_OFF;
48         pLed->bLedOn = FALSE;
49
50         pLed->bLedBlinkInProgress = FALSE;
51         pLed->BlinkTimes = 0;
52         pLed->BlinkingLedState = LED_OFF;
53
54         init_timer(&pLed->BlinkTimer);
55         pLed->BlinkTimer.data = (unsigned long)dev;
56         pLed->BlinkTimer.function = BlinkTimerCallback;
57
58         INIT_WORK(&priv->BlinkWorkItem, (void*)BlinkWorkItemCallback);
59         priv->pLed = pLed;
60 }
61
62
63 void DeInitLed819xUsb (PLED_819xUsb pLed)
64 {
65         del_timer_sync(&(pLed->BlinkTimer));
66         pLed->bLedBlinkInProgress = FALSE;
67 }
68
69 void SwLedOn (struct net_device *dev, PLED_819xUsb pLed)
70 {
71         u8 LedCfg;
72
73         LedCfg = read_nic_byte(dev, LEDCFG);
74         switch (pLed->LedPin) {
75         case LED_PIN_GPIO0:
76                 break;
77         case LED_PIN_LED0:
78                 write_nic_byte(dev, LEDCFG, LedCfg&0xf0); 
79                 break;
80         case LED_PIN_LED1:
81                 write_nic_byte(dev, LEDCFG, LedCfg&0x0f); 
82                 break;
83         default:
84                 break;
85         }
86         pLed->bLedOn = TRUE;
87 }
88
89 void SwLedOff (struct net_device *dev, PLED_819xUsb pLed)
90 {
91         u8 LedCfg;
92
93         LedCfg = read_nic_byte(dev, LEDCFG);
94         switch (pLed->LedPin) {
95         case LED_PIN_GPIO0:
96                 break;
97         case LED_PIN_LED0:
98                 LedCfg &= 0xf0; 
99                 write_nic_byte(dev, LEDCFG, (LedCfg|BIT3));
100                 break;
101         case LED_PIN_LED1:
102                 LedCfg &= 0x0f; 
103                 write_nic_byte(dev, LEDCFG, (LedCfg|BIT7));
104                 break;
105         default:
106                 break;
107         }
108         pLed->bLedOn = FALSE;
109 }
110
111
112 void
113 InitSwLeds(
114         struct net_device       *dev
115         )
116 {
117         struct r8192_priv *priv = ieee80211_priv(dev);
118
119         InitLed819xUsb(dev, &(priv->SwLed0), LED_PIN_LED0);
120
121         InitLed819xUsb(dev,&(priv->SwLed1), LED_PIN_LED1);
122 }
123
124
125 void
126 DeInitSwLeds(
127         struct net_device       *dev
128         )
129 {
130         struct r8192_priv *priv = ieee80211_priv(dev);
131
132         DeInitLed819xUsb( &(priv->SwLed0) );
133         DeInitLed819xUsb( &(priv->SwLed1) );
134 }
135
136
137 void
138 SwLedBlink(
139         PLED_819xUsb                    pLed
140         )
141 {
142         struct net_device       *dev = (struct net_device *)(pLed->dev); 
143         struct r8192_priv       *priv = ieee80211_priv(dev);
144         bool                            bStopBlinking = FALSE;
145
146         if( pLed->BlinkingLedState == LED_ON ) 
147         {
148                 SwLedOn(dev, pLed);
149                 RT_TRACE(COMP_LED, "Blinktimes (%d): turn on\n", pLed->BlinkTimes);
150         }
151         else 
152         {
153                 SwLedOff(dev, pLed);
154                 RT_TRACE(COMP_LED, "Blinktimes (%d): turn off\n", pLed->BlinkTimes);
155         }
156
157         pLed->BlinkTimes--;
158         switch(pLed->CurrLedState)
159         {
160
161         case LED_BLINK_NORMAL: 
162                 if(pLed->BlinkTimes == 0)
163                 {
164                         bStopBlinking = TRUE;
165                 }
166                 break;
167                 
168         case LED_BLINK_StartToBlink:    
169                 if( (priv->ieee80211->state == IEEE80211_LINKED) && (priv->ieee80211->iw_mode == IW_MODE_INFRA)) 
170                 {
171                         bStopBlinking = TRUE;
172                 }
173                 else if((priv->ieee80211->state == IEEE80211_LINKED) && (priv->ieee80211->iw_mode == IW_MODE_ADHOC))
174                 {
175                         bStopBlinking = TRUE;
176                 }
177                 else if(pLed->BlinkTimes == 0)
178                 {
179                         bStopBlinking = TRUE;
180                 }
181                 break;
182
183         case LED_BLINK_WPS:
184                 if( pLed->BlinkTimes == 0 )
185                 {
186                         bStopBlinking = TRUE;
187                 }
188                 break;
189
190
191         default:
192                 bStopBlinking = TRUE;
193                 break;
194                         
195         }
196         
197         if(bStopBlinking)
198         {
199                 if( priv->ieee80211->eRFPowerState != eRfOn )
200                 {
201                         SwLedOff(dev, pLed);
202                 }
203                 else if( (priv->ieee80211->state == IEEE80211_LINKED) && (pLed->bLedOn == false))
204                 {
205                         SwLedOn(dev, pLed);
206                 }
207                 else if( (priv->ieee80211->state != IEEE80211_LINKED) &&  pLed->bLedOn == true)
208                 {
209                         SwLedOff(dev, pLed);
210                 }
211
212                 pLed->BlinkTimes = 0;
213                 pLed->bLedBlinkInProgress = FALSE;
214         }
215         else
216         {
217                 if( pLed->BlinkingLedState == LED_ON ) 
218                         pLed->BlinkingLedState = LED_OFF;
219                 else 
220                         pLed->BlinkingLedState = LED_ON;
221
222                 switch( pLed->CurrLedState )
223                 {
224                 case LED_BLINK_NORMAL:
225                         mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_NORMAL_INTERVAL));
226                         break;
227                 
228                 case LED_BLINK_SLOWLY:
229                 case LED_BLINK_StartToBlink:
230                         mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_SLOWLY_INTERVAL));
231                         break;
232
233                 case LED_BLINK_WPS:
234                         {
235                                 if( pLed->BlinkingLedState == LED_ON )
236                                         mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_LONG_INTERVAL));
237                                 else
238                                         mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_LONG_INTERVAL));
239                         }
240                         break;
241
242                 default:
243                         mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_SLOWLY_INTERVAL));
244                         break;
245                 }
246         }
247 }
248
249
250 void
251 SwLedBlink1(
252         PLED_819xUsb                    pLed
253         )
254 {
255         struct net_device       *dev = (struct net_device *)(pLed->dev); 
256         struct r8192_priv       *priv = ieee80211_priv(dev);
257         PLED_819xUsb    pLed1 = &(priv->SwLed1);        
258         bool                            bStopBlinking = FALSE;
259
260         if(priv->CustomerID == RT_CID_819x_CAMEO)
261                 pLed = &(priv->SwLed1); 
262
263         if( pLed->BlinkingLedState == LED_ON ) 
264         {
265                 SwLedOn(dev, pLed);
266                 RT_TRACE(COMP_LED, "Blinktimes (%d): turn on\n", pLed->BlinkTimes);
267         }
268         else 
269         {
270                 SwLedOff(dev, pLed);
271                 RT_TRACE(COMP_LED, "Blinktimes (%d): turn off\n", pLed->BlinkTimes);
272         }
273
274
275         if(priv->CustomerID == RT_CID_DEFAULT)
276         {
277                 if(priv->ieee80211->state == IEEE80211_LINKED)
278                 {
279                         if(!pLed1->bSWLedCtrl)
280                         {
281                                 SwLedOn(dev, pLed1);    
282                                 pLed1->bSWLedCtrl = TRUE;
283                         }
284                         else if(!pLed1->bLedOn) 
285                                 SwLedOn(dev, pLed1);
286                         RT_TRACE(COMP_LED, "Blinktimes (): turn on pLed1\n");
287         }
288                 else 
289         {
290                         if(!pLed1->bSWLedCtrl)
291                 {
292                                 SwLedOff(dev, pLed1);
293                                 pLed1->bSWLedCtrl = TRUE;
294                 }
295                 else if(pLed1->bLedOn)
296                         SwLedOff(dev, pLed1);
297                         RT_TRACE(COMP_LED, "Blinktimes (): turn off pLed1\n");          
298                 }
299         }
300
301         switch(pLed->CurrLedState)
302         {
303                 case LED_BLINK_SLOWLY:                  
304                         if( pLed->bLedOn )
305                                 pLed->BlinkingLedState = LED_OFF; 
306                         else
307                                 pLed->BlinkingLedState = LED_ON; 
308                         mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_NO_LINK_INTERVAL_ALPHA));
309                         break;
310
311                 case LED_BLINK_NORMAL:
312                         if( pLed->bLedOn )
313                                 pLed->BlinkingLedState = LED_OFF; 
314                         else
315                                 pLed->BlinkingLedState = LED_ON; 
316                         mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_LINK_INTERVAL_ALPHA));
317                         break;
318                         
319                 case LED_SCAN_BLINK:
320                         pLed->BlinkTimes--;
321                         if( pLed->BlinkTimes == 0 )
322                         {
323                                 bStopBlinking = TRUE;
324                         }
325                         
326                         if(bStopBlinking)
327                         {
328                                 if( priv->ieee80211->eRFPowerState != eRfOn )
329                                 {
330                                         SwLedOff(dev, pLed);
331                                 }
332                                 else if(priv->ieee80211->state == IEEE80211_LINKED)
333                                 {
334                                         pLed->bLedLinkBlinkInProgress = TRUE;
335                                         pLed->CurrLedState = LED_BLINK_NORMAL;
336                                         if( pLed->bLedOn )
337                                                 pLed->BlinkingLedState = LED_OFF; 
338                                         else
339                                                 pLed->BlinkingLedState = LED_ON; 
340                                         mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_LINK_INTERVAL_ALPHA));
341                                         RT_TRACE(COMP_LED, "CurrLedState %d\n", pLed->CurrLedState);
342                                         
343                                 }
344                                 else if(priv->ieee80211->state != IEEE80211_LINKED)
345                                 {
346                                         pLed->bLedNoLinkBlinkInProgress = TRUE;
347                                         pLed->CurrLedState = LED_BLINK_SLOWLY;
348                                         if( pLed->bLedOn )
349                                                 pLed->BlinkingLedState = LED_OFF; 
350                                         else
351                                                 pLed->BlinkingLedState = LED_ON; 
352                                         mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_NO_LINK_INTERVAL_ALPHA));
353                                         RT_TRACE(COMP_LED, "CurrLedState %d\n", pLed->CurrLedState);                                    
354                                 }
355                                 pLed->bLedScanBlinkInProgress = FALSE;
356                         }
357                         else
358                         {
359                                 if( priv->ieee80211->eRFPowerState != eRfOn )
360                                 {
361                                         SwLedOff(dev, pLed);
362                                 }
363                                 else
364                                 {
365                                          if( pLed->bLedOn )
366                                                 pLed->BlinkingLedState = LED_OFF; 
367                                         else
368                                                 pLed->BlinkingLedState = LED_ON; 
369                                         mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_SCAN_INTERVAL_ALPHA));
370                                 }
371                         }
372                         break;
373
374                 case LED_TXRX_BLINK:
375                         pLed->BlinkTimes--;
376                         if( pLed->BlinkTimes == 0 )
377                         {
378                                 bStopBlinking = TRUE;
379                         }
380                         if(bStopBlinking)
381                         {
382                                 if( priv->ieee80211->eRFPowerState != eRfOn )
383                                 {
384                                         SwLedOff(dev, pLed);
385                                 }
386                                 else if(priv->ieee80211->state == IEEE80211_LINKED)
387                                 {
388                                         pLed->bLedLinkBlinkInProgress = TRUE;
389                                         pLed->CurrLedState = LED_BLINK_NORMAL;
390                                         if( pLed->bLedOn )
391                                                 pLed->BlinkingLedState = LED_OFF; 
392                                         else
393                                                 pLed->BlinkingLedState = LED_ON; 
394                                         mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_LINK_INTERVAL_ALPHA));
395                                         RT_TRACE(COMP_LED, "CurrLedState %d\n", pLed->CurrLedState);                                    
396                                 }
397                                 else if(priv->ieee80211->state != IEEE80211_LINKED)
398                                 {
399                                         pLed->bLedNoLinkBlinkInProgress = TRUE;
400                                         pLed->CurrLedState = LED_BLINK_SLOWLY;
401                                         if( pLed->bLedOn )
402                                                 pLed->BlinkingLedState = LED_OFF; 
403                                         else
404                                                 pLed->BlinkingLedState = LED_ON; 
405                                         mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_NO_LINK_INTERVAL_ALPHA));
406                                         RT_TRACE(COMP_LED, "CurrLedState %d\n", pLed->CurrLedState);                                    
407                                 }
408                                 pLed->BlinkTimes = 0;
409                                 pLed->bLedBlinkInProgress = FALSE;      
410                         }
411                         else
412                         {
413                                 if( priv->ieee80211->eRFPowerState != eRfOn )
414                                 {
415                                         SwLedOff(dev, pLed);
416                                 }
417                                 else
418                                 {
419                                          if( pLed->bLedOn )
420                                                 pLed->BlinkingLedState = LED_OFF; 
421                                         else
422                                                 pLed->BlinkingLedState = LED_ON; 
423                                         mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_FASTER_INTERVAL_ALPHA));
424                                 }
425                         }
426                         break;
427
428                 case LED_BLINK_WPS:
429                         if( pLed->bLedOn )
430                                 pLed->BlinkingLedState = LED_OFF; 
431                         else
432                                 pLed->BlinkingLedState = LED_ON; 
433                         mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_SCAN_INTERVAL_ALPHA));
434                         break;
435
436                 case LED_BLINK_WPS_STOP:        
437                         if(pLed->BlinkingLedState == LED_ON)
438                         {
439                                 pLed->BlinkingLedState = LED_OFF;
440                                 mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_WPS_SUCESS_INTERVAL_ALPHA));                           
441                                 bStopBlinking = FALSE;
442                         }
443                         else
444                         {
445                                 bStopBlinking = TRUE;                           
446                         }
447                         
448                         if(bStopBlinking)
449                         {
450                                 if( priv->ieee80211->eRFPowerState != eRfOn )
451                                 {
452                                         SwLedOff(dev, pLed);
453                                 }
454                                 else 
455                                 {
456                                         pLed->bLedLinkBlinkInProgress = TRUE;
457                                         pLed->CurrLedState = LED_BLINK_NORMAL;
458                                         if( pLed->bLedOn )
459                                                 pLed->BlinkingLedState = LED_OFF; 
460                                         else
461                                                 pLed->BlinkingLedState = LED_ON; 
462                                         mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_LINK_INTERVAL_ALPHA));
463                                         RT_TRACE(COMP_LED, "CurrLedState %d\n", pLed->CurrLedState);                                    
464                                 }
465                                 pLed->bLedWPSBlinkInProgress = FALSE;   
466                         }               
467                         break;
468                                         
469                 default:
470                         break;
471         }
472
473 }
474
475 void
476 SwLedBlink2(
477         PLED_819xUsb                    pLed
478         )
479 {
480         struct net_device       *dev = (struct net_device *)(pLed->dev); 
481         struct r8192_priv       *priv = ieee80211_priv(dev);
482         bool                            bStopBlinking = FALSE;
483
484         if( pLed->BlinkingLedState == LED_ON) 
485         {
486                 SwLedOn(dev, pLed);
487                 RT_TRACE(COMP_LED, "Blinktimes (%d): turn on\n", pLed->BlinkTimes);
488         }
489         else 
490         {
491                 SwLedOff(dev, pLed);
492                 RT_TRACE(COMP_LED, "Blinktimes (%d): turn off\n", pLed->BlinkTimes);
493         }
494
495         switch(pLed->CurrLedState)
496         {       
497                 case LED_SCAN_BLINK:
498                         pLed->BlinkTimes--;
499                         if( pLed->BlinkTimes == 0 )
500                         {
501                                 bStopBlinking = TRUE;
502                         }
503                         
504                         if(bStopBlinking)
505                         {
506                                 if( priv->ieee80211->eRFPowerState != eRfOn )
507                                 {
508                                         SwLedOff(dev, pLed);
509                                         RT_TRACE(COMP_LED, "eRFPowerState %d\n", priv->ieee80211->eRFPowerState);                                       
510                                 }
511                                 else if(priv->ieee80211->state == IEEE80211_LINKED)
512                                 {
513                                         pLed->CurrLedState = LED_ON;
514                                         pLed->BlinkingLedState = LED_ON; 
515                                         SwLedOn(dev, pLed);
516                                         RT_TRACE(COMP_LED, "stop scan blink CurrLedState %d\n", pLed->CurrLedState);
517                                         
518                                 }
519                                 else if(priv->ieee80211->state != IEEE80211_LINKED)
520                                 {
521                                         pLed->CurrLedState = LED_OFF;
522                                         pLed->BlinkingLedState = LED_OFF; 
523                                         SwLedOff(dev, pLed);
524                                         RT_TRACE(COMP_LED, "stop scan blink CurrLedState %d\n", pLed->CurrLedState);                                    
525                                 }
526                                 pLed->bLedScanBlinkInProgress = FALSE;
527                         }
528                         else
529                         {
530                                 if( priv->ieee80211->eRFPowerState != eRfOn )
531                                 {
532                                         SwLedOff(dev, pLed);
533                                 }
534                                 else
535                                 {
536                                          if( pLed->bLedOn )
537                                                 pLed->BlinkingLedState = LED_OFF; 
538                                         else
539                                                 pLed->BlinkingLedState = LED_ON; 
540                                         mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_SCAN_INTERVAL_ALPHA));
541                                 }
542                         }
543                         break;
544
545                 case LED_TXRX_BLINK:
546                         pLed->BlinkTimes--;
547                         if( pLed->BlinkTimes == 0 )
548                         {
549                                 bStopBlinking = TRUE;
550                         }
551                         if(bStopBlinking)
552                         {
553                                 if( priv->ieee80211->eRFPowerState != eRfOn )
554                                 {
555                                         SwLedOff(dev, pLed);
556                                 }
557                                 else if(priv->ieee80211->state == IEEE80211_LINKED)
558                                 {
559                                         pLed->CurrLedState = LED_ON;
560                                         pLed->BlinkingLedState = LED_ON; 
561                                         SwLedOn(dev, pLed);
562                                         RT_TRACE(COMP_LED, "stop CurrLedState %d\n", pLed->CurrLedState);
563                                         
564                                 }
565                                 else if(priv->ieee80211->state != IEEE80211_LINKED)
566                                 {
567                                         pLed->CurrLedState = LED_OFF;
568                                         pLed->BlinkingLedState = LED_OFF; 
569                                         SwLedOff(dev, pLed);
570                                         RT_TRACE(COMP_LED, "stop CurrLedState %d\n", pLed->CurrLedState);                                       
571                                 }
572                                 pLed->bLedBlinkInProgress = FALSE;
573                         }
574                         else
575                         {
576                                 if( priv->ieee80211->eRFPowerState != eRfOn )
577                                 {
578                                         SwLedOff(dev, pLed);
579                                 }
580                                 else
581                                 {
582                                          if( pLed->bLedOn )
583                                                 pLed->BlinkingLedState = LED_OFF; 
584                                         else
585                                                 pLed->BlinkingLedState = LED_ON; 
586                                         mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_FASTER_INTERVAL_ALPHA));
587                                 }
588                         }
589                         break;
590                                         
591                 default:
592                         break;
593         }
594
595 }
596
597 void
598 SwLedBlink3(
599         PLED_819xUsb                    pLed
600         )
601 {
602         struct net_device       *dev = (struct net_device *)(pLed->dev); 
603         struct r8192_priv       *priv = ieee80211_priv(dev);
604         bool bStopBlinking = FALSE;
605
606         if( pLed->BlinkingLedState == LED_ON ) 
607         {
608                 SwLedOn(dev, pLed);
609                 RT_TRACE(COMP_LED, "Blinktimes (%d): turn on\n", pLed->BlinkTimes);
610         }
611         else 
612         {
613                 if(pLed->CurrLedState != LED_BLINK_WPS_STOP)
614                         SwLedOff(dev, pLed);
615                 RT_TRACE(COMP_LED, "Blinktimes (%d): turn off\n", pLed->BlinkTimes);
616         }       
617
618         switch(pLed->CurrLedState)
619         {                       
620                 case LED_SCAN_BLINK:
621                         pLed->BlinkTimes--;
622                         if( pLed->BlinkTimes == 0 )
623                         {
624                                 bStopBlinking = TRUE;
625                         }
626                         
627                         if(bStopBlinking)
628                         {
629                                 if( priv->ieee80211->eRFPowerState != eRfOn )
630                                 {
631                                         SwLedOff(dev, pLed);
632                                 }
633                                 else if(priv->ieee80211->state == IEEE80211_LINKED)
634                                 {
635                                         pLed->CurrLedState = LED_ON;
636                                         pLed->BlinkingLedState = LED_ON;                                
637                                         if( !pLed->bLedOn )
638                                                 SwLedOn(dev, pLed);
639
640                                         RT_TRACE(COMP_LED, "CurrLedState %d\n", pLed->CurrLedState);                                    
641                                 }
642                                 else if(priv->ieee80211->state != IEEE80211_LINKED)
643                                 {
644                                         pLed->CurrLedState = LED_OFF;
645                                         pLed->BlinkingLedState = LED_OFF;                                                                       
646                                         if( pLed->bLedOn )
647                                                 SwLedOff(dev, pLed);
648
649                                         RT_TRACE(COMP_LED, "CurrLedState %d\n", pLed->CurrLedState);                                    
650                                 }
651                                 pLed->bLedScanBlinkInProgress = FALSE;
652                         }
653                         else
654                         {
655                                 if( priv->ieee80211->eRFPowerState != eRfOn )
656                                 {
657                                         SwLedOff(dev, pLed);
658                                 }
659                                 else
660                                 {
661                                         if( pLed->bLedOn )
662                                                 pLed->BlinkingLedState = LED_OFF; 
663                                         else
664                                                 pLed->BlinkingLedState = LED_ON; 
665                                         mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_SCAN_INTERVAL_ALPHA));
666                                 }
667                         }
668                         break;
669
670                 case LED_TXRX_BLINK:
671                         pLed->BlinkTimes--;
672                         if( pLed->BlinkTimes == 0 )
673                         {
674                                 bStopBlinking = TRUE;
675                         }
676                         if(bStopBlinking)
677                         {
678                                 if( priv->ieee80211->eRFPowerState != eRfOn )
679                                 {
680                                         SwLedOff(dev, pLed);
681                                 }
682                                 else if(priv->ieee80211->state == IEEE80211_LINKED)
683                                 {
684                                         pLed->CurrLedState = LED_ON;
685                                         pLed->BlinkingLedState = LED_ON;
686                                 
687                                         if( !pLed->bLedOn )
688                                                 SwLedOn(dev, pLed);
689
690                                         RT_TRACE(COMP_LED, "CurrLedState %d\n", pLed->CurrLedState);                                    
691                                 }
692                                 else if(priv->ieee80211->state != IEEE80211_LINKED)
693                                 {
694                                         pLed->CurrLedState = LED_OFF;
695                                         pLed->BlinkingLedState = LED_OFF;                                       
696                                 
697                                         if( pLed->bLedOn )
698                                                 SwLedOff(dev, pLed);
699
700
701                                         RT_TRACE(COMP_LED, "CurrLedState %d\n", pLed->CurrLedState);                                    
702                                 }
703                                 pLed->bLedBlinkInProgress = FALSE;      
704                         }
705                         else
706                         {
707                                 if( priv->ieee80211->eRFPowerState != eRfOn )
708                                 {
709                                         SwLedOff(dev, pLed);
710                                 }
711                                 else
712                                 {
713                                         if( pLed->bLedOn )
714                                                 pLed->BlinkingLedState = LED_OFF; 
715                                         else
716                                                 pLed->BlinkingLedState = LED_ON; 
717                                         mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_FASTER_INTERVAL_ALPHA));
718                                 }
719                         }
720                         break;
721
722                 case LED_BLINK_WPS:
723                         if( pLed->bLedOn )
724                                 pLed->BlinkingLedState = LED_OFF; 
725                         else
726                                 pLed->BlinkingLedState = LED_ON; 
727                         mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_SCAN_INTERVAL_ALPHA));
728                         break;
729
730                 case LED_BLINK_WPS_STOP:        
731                         if(pLed->BlinkingLedState == LED_ON)
732                         {
733                                 pLed->BlinkingLedState = LED_OFF;
734                                 mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_WPS_SUCESS_INTERVAL_ALPHA));                           
735                                 bStopBlinking = FALSE;
736                         }
737                         else
738                         {
739                                 bStopBlinking = TRUE;                           
740                         }
741                         
742                         if(bStopBlinking)
743                         {
744                                 if( priv->ieee80211->eRFPowerState != eRfOn )
745                                 {
746                                         SwLedOff(dev, pLed);
747                                 }
748                                 else 
749                                 {
750                                         pLed->CurrLedState = LED_ON;
751                                         pLed->BlinkingLedState = LED_ON; 
752                                         SwLedOn(dev, pLed);
753                                         RT_TRACE(COMP_LED, "CurrLedState %d\n", pLed->CurrLedState);                                    
754                                 }
755                                 pLed->bLedWPSBlinkInProgress = FALSE;   
756                         }               
757                         break;
758                         
759                                         
760                 default:
761                         break;
762         }
763
764 }
765
766
767 void
768 SwLedBlink4(
769         PLED_819xUsb                    pLed
770         )
771 {
772         struct net_device       *dev = (struct net_device *)(pLed->dev); 
773         struct r8192_priv       *priv = ieee80211_priv(dev);
774         PLED_819xUsb    pLed1 = &(priv->SwLed1);        
775         bool bStopBlinking = FALSE;
776
777         if( pLed->BlinkingLedState == LED_ON ) 
778         {
779                 SwLedOn(dev, pLed);
780                 RT_TRACE(COMP_LED, "Blinktimes (%d): turn on\n", pLed->BlinkTimes);
781         }
782         else 
783         {
784                 SwLedOff(dev, pLed);
785                 RT_TRACE(COMP_LED, "Blinktimes (%d): turn off\n", pLed->BlinkTimes);
786         }       
787
788         if(!pLed1->bLedWPSBlinkInProgress && pLed1->BlinkingLedState == LED_UNKNOWN)
789         {
790                 pLed1->BlinkingLedState = LED_OFF;
791                 pLed1->CurrLedState = LED_OFF;
792                 SwLedOff(dev, pLed1);
793         }       
794
795         switch(pLed->CurrLedState)
796         {
797                 case LED_BLINK_SLOWLY:                  
798                         if( pLed->bLedOn )
799                                 pLed->BlinkingLedState = LED_OFF; 
800                         else
801                                 pLed->BlinkingLedState = LED_ON;
802                         mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_NO_LINK_INTERVAL_ALPHA));
803                         break;
804
805                 case LED_BLINK_StartToBlink:
806                         if( pLed->bLedOn )
807                         {
808                                 pLed->BlinkingLedState = LED_OFF;
809                                 mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_SLOWLY_INTERVAL));
810                         }
811                         else
812                         {
813                                 pLed->BlinkingLedState = LED_ON;
814                                 mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_NORMAL_INTERVAL));
815                         }
816                         break;                  
817                         
818                 case LED_SCAN_BLINK:
819                         pLed->BlinkTimes--;
820                         if( pLed->BlinkTimes == 0 )
821                         {
822                                 bStopBlinking = TRUE;
823                         }
824                         
825                         if(bStopBlinking)
826                         {
827                                 if( priv->ieee80211->eRFPowerState != eRfOn && priv->ieee80211->RfOffReason > RF_CHANGE_BY_PS)
828                                 {
829                                         SwLedOff(dev, pLed);
830                                 }
831                                 else 
832                                 {
833                                         pLed->bLedNoLinkBlinkInProgress = TRUE;
834                                         pLed->CurrLedState = LED_BLINK_SLOWLY;
835                                         if( pLed->bLedOn )
836                                                 pLed->BlinkingLedState = LED_OFF; 
837                                         else
838                                                 pLed->BlinkingLedState = LED_ON;
839                                         mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_NO_LINK_INTERVAL_ALPHA));
840                                 }
841                                 pLed->bLedScanBlinkInProgress = FALSE;
842                         }
843                         else
844                         {
845                                 if( priv->ieee80211->eRFPowerState != eRfOn && priv->ieee80211->RfOffReason > RF_CHANGE_BY_PS)
846                                 {
847                                         SwLedOff(dev, pLed);
848                                 }
849                                 else
850                                 {
851                                          if( pLed->bLedOn )
852                                                 pLed->BlinkingLedState = LED_OFF; 
853                                         else
854                                                 pLed->BlinkingLedState = LED_ON;
855                                         mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_SCAN_INTERVAL_ALPHA));
856                                 }
857                         }
858                         break;
859
860                 case LED_TXRX_BLINK:
861                         pLed->BlinkTimes--;
862                         if( pLed->BlinkTimes == 0 )
863                         {
864                                 bStopBlinking = TRUE;
865                         }
866                         if(bStopBlinking)
867                         {
868                                 if( priv->ieee80211->eRFPowerState != eRfOn && priv->ieee80211->RfOffReason > RF_CHANGE_BY_PS)
869                                 {
870                                         SwLedOff(dev, pLed);
871                                 }
872                                 else 
873                                 {
874                                         pLed->bLedNoLinkBlinkInProgress = TRUE;
875                                         pLed->CurrLedState = LED_BLINK_SLOWLY;
876                                         if( pLed->bLedOn )
877                                                 pLed->BlinkingLedState = LED_OFF; 
878                                         else
879                                                 pLed->BlinkingLedState = LED_ON;
880                                         mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_NO_LINK_INTERVAL_ALPHA));
881                                 }
882                                 pLed->bLedBlinkInProgress = FALSE;      
883                         }
884                         else
885                         {
886                                 if( priv->ieee80211->eRFPowerState != eRfOn && priv->ieee80211->RfOffReason > RF_CHANGE_BY_PS)
887                                 {
888                                         SwLedOff(dev, pLed);
889                                 }
890                                 else
891                                 {
892                                          if( pLed->bLedOn )
893                                                 pLed->BlinkingLedState = LED_OFF; 
894                                         else
895                                                 pLed->BlinkingLedState = LED_ON;
896                                         mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_FASTER_INTERVAL_ALPHA));
897                                 }
898                         }
899                         break;
900
901                 case LED_BLINK_WPS:
902                         if( pLed->bLedOn )
903                         {
904                                 pLed->BlinkingLedState = LED_OFF;
905                                 mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_SLOWLY_INTERVAL));
906                         }
907                         else
908                         {
909                                 pLed->BlinkingLedState = LED_ON;
910                                 mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_NORMAL_INTERVAL));
911                         }
912                         break;
913
914                 case LED_BLINK_WPS_STOP:        
915                         if( pLed->bLedOn )                      
916                                 pLed->BlinkingLedState = LED_OFF;                       
917                         else                    
918                                 pLed->BlinkingLedState = LED_ON;
919
920                         mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_NORMAL_INTERVAL));
921                         break;
922
923                 case LED_BLINK_WPS_STOP_OVERLAP:        
924                         pLed->BlinkTimes--;
925                         if(pLed->BlinkTimes == 0)
926                         {
927                                 if(pLed->bLedOn)
928                                 {
929                                         pLed->BlinkTimes = 1;                                                   
930                                 }
931                                 else
932                                 {
933                                         bStopBlinking = TRUE;
934                                 }
935                         }
936
937                         if(bStopBlinking)
938                         {                               
939                                 pLed->BlinkTimes = 10;                  
940                                 pLed->BlinkingLedState = LED_ON;
941                                 mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_LINK_INTERVAL_ALPHA));
942                         }
943                         else
944                         {
945                                 if( pLed->bLedOn )                      
946                                         pLed->BlinkingLedState = LED_OFF;                       
947                                 else                    
948                                         pLed->BlinkingLedState = LED_ON;
949
950                                 mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_NORMAL_INTERVAL));
951                         }
952                         break;
953
954                                         
955                 default:
956                         break;
957         }
958
959         RT_TRACE(COMP_LED, "SwLedBlink4 CurrLedState %d\n", pLed->CurrLedState);
960
961
962 }
963
964 void
965 SwLedBlink5(
966         PLED_819xUsb                    pLed
967         )
968 {
969         struct net_device       *dev = (struct net_device *)(pLed->dev); 
970         struct r8192_priv       *priv = ieee80211_priv(dev);
971         bool bStopBlinking = FALSE;
972
973         if( pLed->BlinkingLedState == LED_ON ) 
974         {
975                 SwLedOn(dev, pLed);
976                 RT_TRACE(COMP_LED, "Blinktimes (%d): turn on\n", pLed->BlinkTimes);
977         }
978         else 
979         {
980                 SwLedOff(dev, pLed);
981                 RT_TRACE(COMP_LED, "Blinktimes (%d): turn off\n", pLed->BlinkTimes);
982         }
983
984         switch(pLed->CurrLedState)
985         {
986                 case LED_SCAN_BLINK:
987                         pLed->BlinkTimes--;
988                         if( pLed->BlinkTimes == 0 )
989                         {
990                                 bStopBlinking = TRUE;
991                         }
992                         
993                         if(bStopBlinking)
994                         {
995                                 if( priv->ieee80211->eRFPowerState != eRfOn && priv->ieee80211->RfOffReason > RF_CHANGE_BY_PS)
996                                 {
997                                         pLed->CurrLedState = LED_OFF;
998                                         pLed->BlinkingLedState = LED_OFF;                                                                       
999                                         if(pLed->bLedOn)                                
1000                                                 SwLedOff(dev, pLed);
1001                                 }
1002                                 else 
1003                                 {               pLed->CurrLedState = LED_ON;
1004                                                 pLed->BlinkingLedState = LED_ON;                                        
1005                                                 if(!pLed->bLedOn)
1006                                                         mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_FASTER_INTERVAL_ALPHA));
1007                                 }
1008
1009                                 pLed->bLedScanBlinkInProgress = FALSE;
1010                         }
1011                         else
1012                         {
1013                                 if( priv->ieee80211->eRFPowerState != eRfOn && priv->ieee80211->RfOffReason > RF_CHANGE_BY_PS)
1014                                 {
1015                                         SwLedOff(dev, pLed);
1016                                 }
1017                                 else
1018                                 {
1019                                         if( pLed->bLedOn )
1020                                                 pLed->BlinkingLedState = LED_OFF; 
1021                                         else
1022                                                 pLed->BlinkingLedState = LED_ON;
1023                                         mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_SCAN_INTERVAL_ALPHA));
1024                                 }
1025                         }
1026                         break;
1027
1028         
1029                 case LED_TXRX_BLINK:
1030                         pLed->BlinkTimes--;
1031                         if( pLed->BlinkTimes == 0 )
1032                         {
1033                                 bStopBlinking = TRUE;
1034                         }
1035                         
1036                         if(bStopBlinking)
1037                         {
1038                                 if( priv->ieee80211->eRFPowerState != eRfOn && priv->ieee80211->RfOffReason > RF_CHANGE_BY_PS)
1039                                 {
1040                                         pLed->CurrLedState = LED_OFF;
1041                                         pLed->BlinkingLedState = LED_OFF;                                                                       
1042                                         if(pLed->bLedOn)
1043                                                 SwLedOff(dev, pLed);
1044                                 }
1045                                 else
1046                                 {
1047                                         pLed->CurrLedState = LED_ON;
1048                                         pLed->BlinkingLedState = LED_ON;                                        
1049                                         if(!pLed->bLedOn)
1050                                                 mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_FASTER_INTERVAL_ALPHA));
1051                                 }                               
1052
1053                                 pLed->bLedBlinkInProgress = FALSE;      
1054                         }
1055                         else
1056                         {
1057                                 if( priv->ieee80211->eRFPowerState != eRfOn && priv->ieee80211->RfOffReason > RF_CHANGE_BY_PS)
1058                                 {
1059                                         SwLedOff(dev, pLed);
1060                                 }
1061                                 else
1062                                 {
1063                                          if( pLed->bLedOn )
1064                                                 pLed->BlinkingLedState = LED_OFF; 
1065                                         else
1066                                                 pLed->BlinkingLedState = LED_ON;
1067                                         mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_FASTER_INTERVAL_ALPHA));
1068                                 }
1069                         }
1070                         break;
1071                                         
1072                 default:
1073                         break;
1074         }
1075
1076         RT_TRACE(COMP_LED, "SwLedBlink5 CurrLedState %d\n", pLed->CurrLedState);
1077
1078
1079 }
1080
1081
1082 void
1083 BlinkTimerCallback(
1084         unsigned long data
1085         )
1086 {
1087         struct net_device       *dev = (struct net_device *)data;
1088         struct r8192_priv       *priv = ieee80211_priv(dev);
1089
1090 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
1091         schedule_work(&(priv->BlinkWorkItem));
1092 #endif
1093 }
1094
1095
1096 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
1097 void BlinkWorkItemCallback(struct work_struct *work)
1098 {
1099         struct r8192_priv *priv = container_of(work, struct r8192_priv, BlinkWorkItem);
1100 #else
1101 void BlinkWorkItemCallback(void * Context)
1102 {
1103         struct net_device *dev = (struct net_device *)Context;
1104         struct r8192_priv *priv = ieee80211_priv(dev);
1105 #endif
1106
1107         PLED_819xUsb     pLed = priv->pLed;
1108
1109         switch(priv->LedStrategy)
1110         {
1111                 case SW_LED_MODE0:
1112                         SwLedBlink(pLed);
1113                         break;
1114                 
1115                 case SW_LED_MODE1:
1116                         SwLedBlink1(pLed);
1117                         break;
1118                 
1119                 case SW_LED_MODE2:
1120                         SwLedBlink2(pLed);
1121                         break;
1122                         
1123                 case SW_LED_MODE3:
1124                         SwLedBlink3(pLed);
1125                         break;
1126
1127                 case SW_LED_MODE4:
1128                         SwLedBlink4(pLed);
1129                         break;                  
1130
1131                 case SW_LED_MODE5:
1132                         SwLedBlink5(pLed);
1133                         break;
1134
1135                 default:
1136                         SwLedBlink(pLed);
1137                         break;
1138         }
1139 }
1140
1141
1142
1143
1144 void
1145 SwLedControlMode0(
1146         struct net_device               *dev,
1147         LED_CTL_MODE            LedAction
1148 )
1149 {
1150         struct r8192_priv *priv = ieee80211_priv(dev);
1151         PLED_819xUsb    pLed = &(priv->SwLed1);
1152
1153         switch(LedAction)
1154         {
1155         case LED_CTL_TX:
1156         case LED_CTL_RX:
1157                 if( pLed->bLedBlinkInProgress == FALSE )
1158                 {
1159                         pLed->bLedBlinkInProgress = TRUE;
1160
1161                         pLed->CurrLedState = LED_BLINK_NORMAL;
1162                         pLed->BlinkTimes = 2;
1163
1164                         if( pLed->bLedOn )
1165                                 pLed->BlinkingLedState = LED_OFF; 
1166                         else
1167                                 pLed->BlinkingLedState = LED_ON; 
1168                         mod_timer(&(pLed->BlinkTimer),  jiffies + MSECS(LED_BLINK_NORMAL_INTERVAL));
1169                 }
1170                 break;
1171
1172         case LED_CTL_START_TO_LINK:
1173                 if( pLed->bLedBlinkInProgress == FALSE )
1174                 {
1175                         pLed->bLedBlinkInProgress = TRUE;
1176
1177                         pLed->CurrLedState = LED_BLINK_StartToBlink;
1178                         pLed->BlinkTimes = 24;
1179
1180                         if( pLed->bLedOn )
1181                                 pLed->BlinkingLedState = LED_OFF; 
1182                         else
1183                                 pLed->BlinkingLedState = LED_ON; 
1184                         mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_SLOWLY_INTERVAL));
1185                 }
1186                 else
1187                 {
1188                         pLed->CurrLedState = LED_BLINK_StartToBlink;
1189                 }       
1190                 break;
1191                 
1192         case LED_CTL_LINK:
1193                 pLed->CurrLedState = LED_ON;
1194                 if( pLed->bLedBlinkInProgress == FALSE )
1195                 {
1196                         SwLedOn(dev, pLed);
1197                 }
1198                 break;
1199
1200         case LED_CTL_NO_LINK:
1201                 pLed->CurrLedState = LED_OFF;
1202                 if( pLed->bLedBlinkInProgress == FALSE )
1203                 {
1204                         SwLedOff(dev, pLed);
1205                 }
1206                 break;
1207         
1208         case LED_CTL_POWER_OFF:
1209                 pLed->CurrLedState = LED_OFF;
1210                 if(pLed->bLedBlinkInProgress)
1211                 {
1212                         del_timer_sync(&(pLed->BlinkTimer));
1213                         pLed->bLedBlinkInProgress = FALSE;
1214                 }
1215                 SwLedOff(dev, pLed);
1216                 break;
1217
1218         case LED_CTL_START_WPS:
1219                 if( pLed->bLedBlinkInProgress == FALSE || pLed->CurrLedState == LED_ON)
1220                 {
1221                         pLed->bLedBlinkInProgress = TRUE;
1222
1223                         pLed->CurrLedState = LED_BLINK_WPS;
1224                         pLed->BlinkTimes = 20;
1225
1226                         if( pLed->bLedOn )
1227                         {
1228                                 pLed->BlinkingLedState = LED_OFF; 
1229                                 mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_LONG_INTERVAL));
1230                         }
1231                         else
1232                         {
1233                                 pLed->BlinkingLedState = LED_ON; 
1234                                 mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_LONG_INTERVAL));
1235                         }
1236                 }
1237                 break;
1238
1239         case LED_CTL_STOP_WPS:
1240                 if(pLed->bLedBlinkInProgress)
1241                 {
1242                         pLed->CurrLedState = LED_OFF;
1243                         del_timer_sync(&(pLed->BlinkTimer));
1244                         pLed->bLedBlinkInProgress = FALSE;
1245                 }
1246                 break;
1247                 
1248
1249         default:
1250                 break;
1251         }
1252         
1253         RT_TRACE(COMP_LED, "Led %d\n", pLed->CurrLedState);
1254         
1255 }
1256
1257 void
1258 SwLedControlMode1(
1259         struct net_device               *dev,
1260         LED_CTL_MODE            LedAction
1261 )
1262 {
1263         struct r8192_priv       *priv = ieee80211_priv(dev);
1264         PLED_819xUsb    pLed = &(priv->SwLed0);
1265
1266         if(priv->CustomerID == RT_CID_819x_CAMEO)
1267                 pLed = &(priv->SwLed1);
1268         
1269         switch(LedAction)
1270         {               
1271                 case LED_CTL_START_TO_LINK:     
1272                 case LED_CTL_NO_LINK:
1273                         if( pLed->bLedNoLinkBlinkInProgress == FALSE )
1274                         {
1275                                 if(pLed->CurrLedState == LED_SCAN_BLINK || IS_LED_WPS_BLINKING(pLed))
1276                                 {
1277                                         return;
1278                                 }
1279                                 if( pLed->bLedLinkBlinkInProgress == TRUE )
1280                                 {
1281                                         del_timer_sync(&(pLed->BlinkTimer));
1282                                         pLed->bLedLinkBlinkInProgress = FALSE;
1283                                 }
1284                                 if(pLed->bLedBlinkInProgress ==TRUE)
1285                                 {       
1286                                         del_timer_sync(&(pLed->BlinkTimer));
1287                                         pLed->bLedBlinkInProgress = FALSE;
1288                                 }
1289                                 
1290                                 pLed->bLedNoLinkBlinkInProgress = TRUE;
1291                                 pLed->CurrLedState = LED_BLINK_SLOWLY;
1292                                 if( pLed->bLedOn )
1293                                         pLed->BlinkingLedState = LED_OFF; 
1294                                 else
1295                                         pLed->BlinkingLedState = LED_ON; 
1296                                 mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_NO_LINK_INTERVAL_ALPHA));
1297                         }
1298                         break;          
1299
1300                 case LED_CTL_LINK:
1301                         if( pLed->bLedLinkBlinkInProgress == FALSE )
1302                         {
1303                                 if(pLed->CurrLedState == LED_SCAN_BLINK || IS_LED_WPS_BLINKING(pLed))
1304                                 {
1305                                         return;
1306                                 }
1307                                 if(pLed->bLedNoLinkBlinkInProgress == TRUE)
1308                                 {
1309                                         del_timer_sync(&(pLed->BlinkTimer));
1310                                         pLed->bLedNoLinkBlinkInProgress = FALSE;
1311                                 }
1312                                 if(pLed->bLedBlinkInProgress ==TRUE)
1313                                 {       
1314                                         del_timer_sync(&(pLed->BlinkTimer));
1315                                         pLed->bLedBlinkInProgress = FALSE;
1316                                 }
1317                                 pLed->bLedLinkBlinkInProgress = TRUE;
1318                                 pLed->CurrLedState = LED_BLINK_NORMAL;
1319                                 if( pLed->bLedOn )
1320                                         pLed->BlinkingLedState = LED_OFF; 
1321                                 else
1322                                         pLed->BlinkingLedState = LED_ON; 
1323                                 mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_LINK_INTERVAL_ALPHA));
1324                         }
1325                         break;
1326
1327                 case LED_CTL_SITE_SURVEY:
1328                          if((priv->ieee80211->LinkDetectInfo.bBusyTraffic) && (priv->ieee80211->state == IEEE80211_LINKED))
1329                                 ;                
1330                          else if(pLed->bLedScanBlinkInProgress ==FALSE)
1331                          {
1332                                 if(IS_LED_WPS_BLINKING(pLed))
1333                                         return;
1334                                 
1335                                 if(pLed->bLedNoLinkBlinkInProgress == TRUE)
1336                                 {
1337                                         del_timer_sync(&(pLed->BlinkTimer));
1338                                         pLed->bLedNoLinkBlinkInProgress = FALSE;
1339                                 }
1340                                 if( pLed->bLedLinkBlinkInProgress == TRUE )
1341                                 {
1342                                         del_timer_sync(&(pLed->BlinkTimer));
1343                                          pLed->bLedLinkBlinkInProgress = FALSE;
1344                                 }
1345                                 if(pLed->bLedBlinkInProgress ==TRUE)
1346                                 {
1347                                         del_timer_sync(&(pLed->BlinkTimer));
1348                                         pLed->bLedBlinkInProgress = FALSE;
1349                                 }
1350                                 pLed->bLedScanBlinkInProgress = TRUE;
1351                                 pLed->CurrLedState = LED_SCAN_BLINK;
1352                                 pLed->BlinkTimes = 24;
1353                                 if( pLed->bLedOn )
1354                                         pLed->BlinkingLedState = LED_OFF; 
1355                                 else
1356                                         pLed->BlinkingLedState = LED_ON; 
1357                                 mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_SCAN_INTERVAL_ALPHA));
1358
1359                          }
1360                         break;
1361                 
1362                 case LED_CTL_TX:
1363                 case LED_CTL_RX:
1364                         if(pLed->bLedBlinkInProgress ==FALSE)
1365                         {
1366                             if(pLed->CurrLedState == LED_SCAN_BLINK || IS_LED_WPS_BLINKING(pLed))
1367                             {
1368                             }
1369                             if(pLed->bLedNoLinkBlinkInProgress == TRUE)
1370                             {
1371                                 del_timer_sync(&(pLed->BlinkTimer));
1372                                 pLed->bLedNoLinkBlinkInProgress = FALSE;
1373                             }
1374                             if( pLed->bLedLinkBlinkInProgress == TRUE )
1375                             {
1376                                 del_timer_sync(&(pLed->BlinkTimer));
1377                                 pLed->bLedLinkBlinkInProgress = FALSE;
1378                             }
1379                             pLed->bLedBlinkInProgress = TRUE;
1380                             pLed->CurrLedState = LED_TXRX_BLINK;
1381                             pLed->BlinkTimes = 2;
1382                             if( pLed->bLedOn )
1383                                 pLed->BlinkingLedState = LED_OFF; 
1384                             else
1385                                 pLed->BlinkingLedState = LED_ON; 
1386                             mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_FASTER_INTERVAL_ALPHA));
1387                         }
1388                         break;
1389
1390                 case LED_CTL_START_WPS: 
1391                 case LED_CTL_START_WPS_BOTTON:
1392                          if(pLed->bLedWPSBlinkInProgress ==FALSE)
1393                          {
1394                                 if(pLed->bLedNoLinkBlinkInProgress == TRUE)
1395                                 {
1396                                         del_timer_sync(&(pLed->BlinkTimer));
1397                                         pLed->bLedNoLinkBlinkInProgress = FALSE;
1398                                 }
1399                                 if( pLed->bLedLinkBlinkInProgress == TRUE )
1400                                 {
1401                                         del_timer_sync(&(pLed->BlinkTimer));
1402                                          pLed->bLedLinkBlinkInProgress = FALSE;
1403                                 }
1404                                 if(pLed->bLedBlinkInProgress ==TRUE)
1405                                 {
1406                                         del_timer_sync(&(pLed->BlinkTimer));
1407                                         pLed->bLedBlinkInProgress = FALSE;
1408                                 }
1409                                 if(pLed->bLedScanBlinkInProgress ==TRUE)
1410                                 {
1411                                         del_timer_sync(&(pLed->BlinkTimer));
1412                                         pLed->bLedScanBlinkInProgress = FALSE;
1413                                 }                               
1414                                 pLed->bLedWPSBlinkInProgress = TRUE;
1415                                 pLed->CurrLedState = LED_BLINK_WPS;
1416                                 if( pLed->bLedOn )
1417                                         pLed->BlinkingLedState = LED_OFF; 
1418                                 else
1419                                         pLed->BlinkingLedState = LED_ON; 
1420                                 mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_SCAN_INTERVAL_ALPHA));
1421                         
1422                          }
1423                         break;
1424
1425                 
1426                 case LED_CTL_STOP_WPS:
1427                         if(pLed->bLedNoLinkBlinkInProgress == TRUE)
1428                         {
1429                                 del_timer_sync(&(pLed->BlinkTimer));
1430                                 pLed->bLedNoLinkBlinkInProgress = FALSE;
1431                         }
1432                         if( pLed->bLedLinkBlinkInProgress == TRUE )
1433                         {
1434                                 del_timer_sync(&(pLed->BlinkTimer));
1435                                  pLed->bLedLinkBlinkInProgress = FALSE;
1436                         }
1437                         if(pLed->bLedBlinkInProgress ==TRUE)
1438                         {
1439                                 del_timer_sync(&(pLed->BlinkTimer));
1440                                 pLed->bLedBlinkInProgress = FALSE;
1441                         }
1442                         if(pLed->bLedScanBlinkInProgress ==TRUE)
1443                         {
1444                                 del_timer_sync(&(pLed->BlinkTimer));
1445                                 pLed->bLedScanBlinkInProgress = FALSE;
1446                         }                       
1447                         if(pLed->bLedWPSBlinkInProgress)
1448                         {
1449                                 del_timer_sync(&(pLed->BlinkTimer));                                                    
1450                         }
1451                         else
1452                         {
1453                                 pLed->bLedWPSBlinkInProgress = TRUE;
1454                         }
1455                         
1456                         pLed->CurrLedState = LED_BLINK_WPS_STOP;
1457                         if(pLed->bLedOn)
1458                         {
1459                                 pLed->BlinkingLedState = LED_OFF;                       
1460                                 mod_timer(&(pLed->BlinkTimer),  jiffies + MSECS(LED_BLINK_WPS_SUCESS_INTERVAL_ALPHA));                          
1461                         }
1462                         else
1463                         {
1464                                 pLed->BlinkingLedState = LED_ON;                                                
1465                                 mod_timer(&(pLed->BlinkTimer), 0);
1466                         }                                       
1467                         break;          
1468
1469                 case LED_CTL_STOP_WPS_FAIL:                     
1470                         if(pLed->bLedWPSBlinkInProgress)
1471                         {
1472                                 del_timer_sync(&(pLed->BlinkTimer));                                                    
1473                                 pLed->bLedWPSBlinkInProgress = FALSE;                           
1474                         }                       
1475
1476                         pLed->bLedNoLinkBlinkInProgress = TRUE;
1477                         pLed->CurrLedState = LED_BLINK_SLOWLY;
1478                         if( pLed->bLedOn )
1479                                 pLed->BlinkingLedState = LED_OFF; 
1480                         else
1481                                 pLed->BlinkingLedState = LED_ON; 
1482                         mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_NO_LINK_INTERVAL_ALPHA));                      
1483                         break;                          
1484
1485                 case LED_CTL_POWER_OFF:
1486                         pLed->CurrLedState = LED_OFF;
1487                         if( pLed->bLedNoLinkBlinkInProgress)
1488                         {
1489                                 del_timer_sync(&(pLed->BlinkTimer));
1490                                 pLed->bLedNoLinkBlinkInProgress = FALSE;
1491                         }
1492                         if( pLed->bLedLinkBlinkInProgress)
1493                         {
1494                                 del_timer_sync(&(pLed->BlinkTimer));
1495                                 pLed->bLedLinkBlinkInProgress = FALSE;
1496                         }
1497                         if( pLed->bLedBlinkInProgress)
1498                         {
1499                                 del_timer_sync(&(pLed->BlinkTimer));
1500                                 pLed->bLedBlinkInProgress = FALSE;
1501                         }
1502                         if( pLed->bLedWPSBlinkInProgress )
1503                         {
1504                                 del_timer_sync(&(pLed->BlinkTimer));
1505                                 pLed->bLedWPSBlinkInProgress = FALSE;
1506                         }
1507                         if( pLed->bLedScanBlinkInProgress)
1508                         {
1509                                 del_timer_sync(&(pLed->BlinkTimer));
1510                                 pLed->bLedScanBlinkInProgress = FALSE;
1511                         }                       
1512                                 
1513                         SwLedOff(dev, pLed);
1514                         break;
1515                         
1516                 default:
1517                         break;
1518
1519         }
1520
1521         RT_TRACE(COMP_LED, "Led %d\n", pLed->CurrLedState);
1522 }
1523
1524 void
1525 SwLedControlMode2(
1526         struct net_device               *dev,
1527         LED_CTL_MODE            LedAction
1528 )
1529 {
1530         struct r8192_priv       *priv = ieee80211_priv(dev);
1531         PLED_819xUsb    pLed = &(priv->SwLed0);
1532         
1533         switch(LedAction)
1534         {               
1535                 case LED_CTL_SITE_SURVEY:
1536                          if(priv->ieee80211->LinkDetectInfo.bBusyTraffic)
1537                                 ;                
1538                          else if(pLed->bLedScanBlinkInProgress ==FALSE)
1539                          {
1540                                 if(IS_LED_WPS_BLINKING(pLed))
1541                                         return;
1542                          
1543                                 if(pLed->bLedBlinkInProgress ==TRUE)
1544                                 {
1545                                         del_timer_sync(&(pLed->BlinkTimer));
1546                                         pLed->bLedBlinkInProgress = FALSE;
1547                                 }
1548                                 pLed->bLedScanBlinkInProgress = TRUE;
1549                                 pLed->CurrLedState = LED_SCAN_BLINK;
1550                                 pLed->BlinkTimes = 24;
1551                                 if( pLed->bLedOn )
1552                                         pLed->BlinkingLedState = LED_OFF; 
1553                                 else
1554                                         pLed->BlinkingLedState = LED_ON; 
1555                                 mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_SCAN_INTERVAL_ALPHA));
1556
1557                          }
1558                         break;
1559                 
1560                 case LED_CTL_TX:
1561                 case LED_CTL_RX:
1562                         if((pLed->bLedBlinkInProgress ==FALSE) && (priv->ieee80211->state == IEEE80211_LINKED))
1563                         {
1564                                 if(pLed->CurrLedState == LED_SCAN_BLINK || IS_LED_WPS_BLINKING(pLed))
1565                                 {
1566                                         return;
1567                                 }
1568
1569                                 pLed->bLedBlinkInProgress = TRUE;
1570                                 pLed->CurrLedState = LED_TXRX_BLINK;
1571                                 pLed->BlinkTimes = 2;
1572                                 if( pLed->bLedOn )
1573                                         pLed->BlinkingLedState = LED_OFF; 
1574                                 else
1575                                         pLed->BlinkingLedState = LED_ON; 
1576                                 mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_FASTER_INTERVAL_ALPHA));
1577                         }
1578                         break;
1579
1580                 case LED_CTL_LINK:
1581                         pLed->CurrLedState = LED_ON;
1582                         pLed->BlinkingLedState = LED_ON;
1583                         if( pLed->bLedBlinkInProgress)
1584                         {
1585                                 del_timer_sync(&(pLed->BlinkTimer));
1586                                 pLed->bLedBlinkInProgress = FALSE;
1587                         }
1588                         if( pLed->bLedScanBlinkInProgress)
1589                         {
1590                                 del_timer_sync(&(pLed->BlinkTimer));
1591                                 pLed->bLedScanBlinkInProgress = FALSE;
1592                         }                       
1593
1594                         mod_timer(&(pLed->BlinkTimer), 0);
1595                         break;                  
1596
1597                 case LED_CTL_START_WPS: 
1598                 case LED_CTL_START_WPS_BOTTON:          
1599                         if(pLed->bLedWPSBlinkInProgress ==FALSE)
1600                         {
1601                                 if(pLed->bLedBlinkInProgress ==TRUE)
1602                                 {
1603                                         del_timer_sync(&(pLed->BlinkTimer));
1604                                         pLed->bLedBlinkInProgress = FALSE;
1605                                 }
1606                                 if(pLed->bLedScanBlinkInProgress ==TRUE)
1607                                 {
1608                                         del_timer_sync(&(pLed->BlinkTimer));
1609                                         pLed->bLedScanBlinkInProgress = FALSE;
1610                                 }                               
1611                                 pLed->bLedWPSBlinkInProgress = TRUE;
1612                                 pLed->CurrLedState = LED_ON;
1613                                 pLed->BlinkingLedState = LED_ON; 
1614                                 mod_timer(&(pLed->BlinkTimer), 0);                      
1615                          }                      
1616                         break;
1617                         
1618                 case LED_CTL_STOP_WPS:
1619                         pLed->bLedWPSBlinkInProgress = FALSE;                   
1620                         if( priv->ieee80211->eRFPowerState != eRfOn )
1621                         {
1622                                 SwLedOff(dev, pLed);
1623                         }
1624                         else
1625                         {
1626                                 pLed->CurrLedState = LED_ON;
1627                                 pLed->BlinkingLedState = LED_ON; 
1628                                 mod_timer(&(pLed->BlinkTimer), 0);
1629                                 RT_TRACE(COMP_LED, "CurrLedState %d\n", pLed->CurrLedState);
1630                         }
1631                         break;
1632                         
1633                 case LED_CTL_STOP_WPS_FAIL:                     
1634                         pLed->bLedWPSBlinkInProgress = FALSE;                   
1635                         if( priv->ieee80211->eRFPowerState != eRfOn )
1636                         {
1637                                 SwLedOff(dev, pLed);
1638                         }
1639                         else 
1640                         {
1641                                 pLed->CurrLedState = LED_OFF;
1642                                 pLed->BlinkingLedState = LED_OFF; 
1643                                 mod_timer(&(pLed->BlinkTimer), 0);
1644                                 RT_TRACE(COMP_LED, "CurrLedState %d\n", pLed->CurrLedState);                            
1645                         }       
1646                         break;                          
1647
1648                 case LED_CTL_START_TO_LINK: 
1649                 case LED_CTL_NO_LINK:
1650                         if(!IS_LED_BLINKING(pLed))
1651                         {
1652                                 pLed->CurrLedState = LED_OFF;
1653                                 pLed->BlinkingLedState = LED_OFF;                               
1654                                 mod_timer(&(pLed->BlinkTimer), 0);                              
1655                         }
1656                         break;
1657                         
1658                 case LED_CTL_POWER_OFF:
1659                         pLed->CurrLedState = LED_OFF;
1660                         pLed->BlinkingLedState = LED_OFF;
1661                         if( pLed->bLedBlinkInProgress)
1662                         {
1663                                 del_timer_sync(&(pLed->BlinkTimer));
1664                                 pLed->bLedBlinkInProgress = FALSE;
1665                         }
1666                         if( pLed->bLedScanBlinkInProgress)
1667                         {
1668                                 del_timer_sync(&(pLed->BlinkTimer));
1669                                 pLed->bLedScanBlinkInProgress = FALSE;
1670                         }                       
1671                         if( pLed->bLedWPSBlinkInProgress )
1672                         {
1673                                 del_timer_sync(&(pLed->BlinkTimer));
1674                                 pLed->bLedWPSBlinkInProgress = FALSE;
1675                         }
1676
1677                         mod_timer(&(pLed->BlinkTimer), 0);
1678                         break;
1679                         
1680                 default:
1681                         break;
1682
1683         }
1684
1685         RT_TRACE(COMP_LED, "CurrLedState %d\n", pLed->CurrLedState);
1686 }
1687
1688  void
1689  SwLedControlMode3(
1690         struct net_device               *dev,
1691         LED_CTL_MODE            LedAction
1692 )
1693 {
1694         struct r8192_priv       *priv = ieee80211_priv(dev);
1695         PLED_819xUsb pLed = &(priv->SwLed0);
1696         
1697         switch(LedAction)
1698         {               
1699                 case LED_CTL_SITE_SURVEY:
1700                          if(priv->ieee80211->LinkDetectInfo.bBusyTraffic)
1701                                 ;                
1702                          else if(pLed->bLedScanBlinkInProgress ==FALSE)
1703                          {
1704                                 if(IS_LED_WPS_BLINKING(pLed))
1705                                         return;
1706                          
1707                                 if(pLed->bLedBlinkInProgress ==TRUE)
1708                                 {
1709                                         del_timer_sync(&(pLed->BlinkTimer));
1710                                         pLed->bLedBlinkInProgress = FALSE;
1711                                 }
1712                                 pLed->bLedScanBlinkInProgress = TRUE;
1713                                 pLed->CurrLedState = LED_SCAN_BLINK;
1714                                 pLed->BlinkTimes = 24;
1715                                 if( pLed->bLedOn )
1716                                         pLed->BlinkingLedState = LED_OFF; 
1717                                 else
1718                                         pLed->BlinkingLedState = LED_ON; 
1719                                 mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_SCAN_INTERVAL_ALPHA));
1720
1721                          }
1722                         break;
1723                 
1724                 case LED_CTL_TX:
1725                 case LED_CTL_RX:
1726                         if((pLed->bLedBlinkInProgress ==FALSE) && (priv->ieee80211->state == IEEE80211_LINKED))
1727                         {
1728                                 if(pLed->CurrLedState == LED_SCAN_BLINK || IS_LED_WPS_BLINKING(pLed))
1729                                 {
1730                                         return;
1731                                 }
1732
1733                                 pLed->bLedBlinkInProgress = TRUE;
1734                                 pLed->CurrLedState = LED_TXRX_BLINK;
1735                                 pLed->BlinkTimes = 2;
1736                                 if( pLed->bLedOn )
1737                                         pLed->BlinkingLedState = LED_OFF; 
1738                                 else
1739                                         pLed->BlinkingLedState = LED_ON; 
1740                                 mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_FASTER_INTERVAL_ALPHA));
1741                         }
1742                         break;
1743
1744                 case LED_CTL_LINK:
1745                         if(IS_LED_WPS_BLINKING(pLed))
1746                                 return;
1747                         
1748                         pLed->CurrLedState = LED_ON;
1749                         pLed->BlinkingLedState = LED_ON;
1750                         if( pLed->bLedBlinkInProgress)
1751                         {
1752                                 del_timer_sync(&(pLed->BlinkTimer));
1753                                 pLed->bLedBlinkInProgress = FALSE;
1754                         }
1755                         if( pLed->bLedScanBlinkInProgress)
1756                         {
1757                                 del_timer_sync(&(pLed->BlinkTimer));
1758                                 pLed->bLedScanBlinkInProgress = FALSE;
1759                         }                       
1760
1761                         mod_timer(&(pLed->BlinkTimer), 0);
1762                         break;                  
1763
1764                 case LED_CTL_START_WPS: 
1765                 case LED_CTL_START_WPS_BOTTON:          
1766                         if(pLed->bLedWPSBlinkInProgress ==FALSE)
1767                         {
1768                                 if(pLed->bLedBlinkInProgress ==TRUE)
1769                                 {
1770                                         del_timer_sync(&(pLed->BlinkTimer));
1771                                         pLed->bLedBlinkInProgress = FALSE;
1772                                 }
1773                                 if(pLed->bLedScanBlinkInProgress ==TRUE)
1774                                 {
1775                                         del_timer_sync(&(pLed->BlinkTimer));
1776                                         pLed->bLedScanBlinkInProgress = FALSE;
1777                                 }                               
1778                                 pLed->bLedWPSBlinkInProgress = TRUE;
1779                                 pLed->CurrLedState = LED_BLINK_WPS;
1780                                 if( pLed->bLedOn )
1781                                         pLed->BlinkingLedState = LED_OFF; 
1782                                 else
1783                                         pLed->BlinkingLedState = LED_ON; 
1784                                 mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_SCAN_INTERVAL_ALPHA));
1785                         
1786                          }                      
1787                         break;
1788                         
1789                 case LED_CTL_STOP_WPS:                  
1790                         if(pLed->bLedWPSBlinkInProgress)
1791                         {
1792                                 del_timer_sync(&(pLed->BlinkTimer));                                                    
1793                                 pLed->bLedWPSBlinkInProgress = FALSE;                           
1794                         }                                               
1795                         else
1796                         {
1797                                 pLed->bLedWPSBlinkInProgress = TRUE;
1798                         }
1799                                 
1800                         pLed->CurrLedState = LED_BLINK_WPS_STOP;
1801                         if(pLed->bLedOn)
1802                         {
1803                                 pLed->BlinkingLedState = LED_OFF;                       
1804                                 mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_WPS_SUCESS_INTERVAL_ALPHA));                           
1805                         }
1806                         else
1807                         {
1808                                 pLed->BlinkingLedState = LED_ON;                                                
1809                                 mod_timer(&(pLed->BlinkTimer), 0);
1810                         }                                       
1811
1812                         break;          
1813
1814                         
1815                 case LED_CTL_STOP_WPS_FAIL:                     
1816                         if(pLed->bLedWPSBlinkInProgress)
1817                         {
1818                                 del_timer_sync(&(pLed->BlinkTimer));                                                    
1819                                 pLed->bLedWPSBlinkInProgress = FALSE;                           
1820                         }                       
1821
1822                         pLed->CurrLedState = LED_OFF;
1823                         pLed->BlinkingLedState = LED_OFF;                               
1824                         mod_timer(&(pLed->BlinkTimer), 0);                              
1825                         break;                          
1826
1827                 case LED_CTL_START_TO_LINK: 
1828                 case LED_CTL_NO_LINK:
1829                         if(!IS_LED_BLINKING(pLed))
1830                         {
1831                                 pLed->CurrLedState = LED_OFF;
1832                                 pLed->BlinkingLedState = LED_OFF;                               
1833                                 mod_timer(&(pLed->BlinkTimer), 0);                              
1834                         }
1835                         break;
1836                         
1837                 case LED_CTL_POWER_OFF:
1838                         pLed->CurrLedState = LED_OFF;
1839                         pLed->BlinkingLedState = LED_OFF;
1840                         if( pLed->bLedBlinkInProgress)
1841                         {
1842                                 del_timer_sync(&(pLed->BlinkTimer));
1843                                 pLed->bLedBlinkInProgress = FALSE;
1844                         }
1845                         if( pLed->bLedScanBlinkInProgress)
1846                         {
1847                                 del_timer_sync(&(pLed->BlinkTimer));
1848                                 pLed->bLedScanBlinkInProgress = FALSE;
1849                         }                       
1850                         if( pLed->bLedWPSBlinkInProgress )
1851                         {
1852                                 del_timer_sync(&(pLed->BlinkTimer));
1853                                 pLed->bLedWPSBlinkInProgress = FALSE;
1854                         }
1855
1856                         mod_timer(&(pLed->BlinkTimer), 0);
1857                         break;
1858                         
1859                 default:
1860                         break;
1861
1862         }
1863
1864         RT_TRACE(COMP_LED, "CurrLedState %d\n", pLed->CurrLedState);
1865 }
1866
1867
1868 void
1869 SwLedControlMode4(
1870         struct net_device               *dev,
1871         LED_CTL_MODE            LedAction
1872 )
1873 {
1874         struct r8192_priv       *priv = ieee80211_priv(dev);
1875         PLED_819xUsb pLed = &(priv->SwLed0);
1876         PLED_819xUsb pLed1 = &(priv->SwLed1);
1877         
1878         switch(LedAction)
1879         {               
1880                 case LED_CTL_START_TO_LINK:     
1881                                 if(pLed1->bLedWPSBlinkInProgress)
1882                                 {
1883                                         pLed1->bLedWPSBlinkInProgress = FALSE;
1884                                         del_timer_sync(&(pLed1->BlinkTimer));
1885                         
1886                                         pLed1->BlinkingLedState = LED_OFF;
1887                                         pLed1->CurrLedState = LED_OFF;
1888
1889                                         if(pLed1->bLedOn)
1890                                                 mod_timer(&(pLed1->BlinkTimer), 0);
1891                                 }
1892                                 
1893                         if( pLed->bLedStartToLinkBlinkInProgress == FALSE )
1894                         {
1895                                 if(pLed->CurrLedState == LED_SCAN_BLINK || IS_LED_WPS_BLINKING(pLed))
1896                                 {
1897                                         return;
1898                                 }
1899                                 if(pLed->bLedBlinkInProgress ==TRUE)
1900                                 {
1901                                         del_timer_sync(&(pLed->BlinkTimer));
1902                                         pLed->bLedBlinkInProgress = FALSE;
1903                                 }
1904                                 if(pLed->bLedNoLinkBlinkInProgress ==TRUE)
1905                                 {       
1906                                         del_timer_sync(&(pLed->BlinkTimer));
1907                                         pLed->bLedNoLinkBlinkInProgress = FALSE;
1908                                 }                               
1909                                 
1910                                 pLed->bLedStartToLinkBlinkInProgress = TRUE;
1911                                 pLed->CurrLedState = LED_BLINK_StartToBlink;
1912                                 if( pLed->bLedOn )
1913                                 {
1914                                         pLed->BlinkingLedState = LED_OFF;
1915                                         mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_SLOWLY_INTERVAL));
1916                                 }
1917                                 else
1918                                 {
1919                                         pLed->BlinkingLedState = LED_ON;
1920                                         mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_NORMAL_INTERVAL));
1921                                 }
1922                         }
1923                         break;          
1924
1925                 case LED_CTL_LINK:                      
1926                 case LED_CTL_NO_LINK:
1927                         if(LedAction == LED_CTL_LINK)
1928                         {
1929                                 if(pLed1->bLedWPSBlinkInProgress)
1930                                 {
1931                                         pLed1->bLedWPSBlinkInProgress = FALSE;
1932                                         del_timer_sync(&(pLed1->BlinkTimer));
1933                         
1934                                         pLed1->BlinkingLedState = LED_OFF;
1935                                         pLed1->CurrLedState = LED_OFF;
1936
1937                                         if(pLed1->bLedOn)
1938                                                 mod_timer(&(pLed1->BlinkTimer), 0);
1939                                 }                               
1940                         }
1941                         
1942                         if( pLed->bLedNoLinkBlinkInProgress == FALSE )
1943                         {
1944                                 if(pLed->CurrLedState == LED_SCAN_BLINK || IS_LED_WPS_BLINKING(pLed))
1945                                 {
1946                                         return;
1947                                 }
1948                                 if(pLed->bLedBlinkInProgress ==TRUE)
1949                                 {
1950                                         del_timer_sync(&(pLed->BlinkTimer));
1951                                         pLed->bLedBlinkInProgress = FALSE;
1952                                 }
1953                                 
1954                                 pLed->bLedNoLinkBlinkInProgress = TRUE;
1955                                 pLed->CurrLedState = LED_BLINK_SLOWLY;
1956                                 if( pLed->bLedOn )
1957                                         pLed->BlinkingLedState = LED_OFF; 
1958                                 else
1959                                         pLed->BlinkingLedState = LED_ON;
1960                                 mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_NO_LINK_INTERVAL_ALPHA));
1961                         }
1962                         
1963                         break;          
1964
1965                 case LED_CTL_SITE_SURVEY:
1966                          if((priv->ieee80211->LinkDetectInfo.bBusyTraffic) && (priv->ieee80211->state == IEEE80211_LINKED))
1967                                 ;                
1968                          else if(pLed->bLedScanBlinkInProgress ==FALSE)
1969                          {
1970                                 if(IS_LED_WPS_BLINKING(pLed))
1971                                         return;
1972                                 
1973                                 if(pLed->bLedNoLinkBlinkInProgress == TRUE)
1974                                 {
1975                                         del_timer_sync(&(pLed->BlinkTimer));
1976                                         pLed->bLedNoLinkBlinkInProgress = FALSE;
1977                                 }
1978                                 if(pLed->bLedBlinkInProgress ==TRUE)
1979                                 {
1980                                         del_timer_sync(&(pLed->BlinkTimer));
1981                                         pLed->bLedBlinkInProgress = FALSE;
1982                                 }
1983                                 pLed->bLedScanBlinkInProgress = TRUE;
1984                                 pLed->CurrLedState = LED_SCAN_BLINK;
1985                                 pLed->BlinkTimes = 24;
1986                                 if( pLed->bLedOn )
1987                                         pLed->BlinkingLedState = LED_OFF; 
1988                                 else
1989                                         pLed->BlinkingLedState = LED_ON;
1990                                 mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_SCAN_INTERVAL_ALPHA));
1991
1992                          }
1993                         break;
1994                 
1995                 case LED_CTL_TX:
1996                 case LED_CTL_RX:
1997                         if(pLed->bLedBlinkInProgress ==FALSE)
1998                         {
1999                                 if(pLed->CurrLedState == LED_SCAN_BLINK || IS_LED_WPS_BLINKING(pLed))
2000                                 {
2001                                         return;
2002                                 }
2003                                 if(pLed->bLedNoLinkBlinkInProgress == TRUE)
2004                                 {
2005                                         del_timer_sync(&(pLed->BlinkTimer));
2006                                         pLed->bLedNoLinkBlinkInProgress = FALSE;
2007                                 }
2008                                 pLed->bLedBlinkInProgress = TRUE;
2009                                 pLed->CurrLedState = LED_TXRX_BLINK;
2010                                 pLed->BlinkTimes = 2;
2011                                 if( pLed->bLedOn )
2012                                         pLed->BlinkingLedState = LED_OFF; 
2013                                 else
2014                                         pLed->BlinkingLedState = LED_ON;
2015                                 mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_FASTER_INTERVAL_ALPHA));
2016                         }
2017                         break;
2018
2019                 case LED_CTL_START_WPS: 
2020                 case LED_CTL_START_WPS_BOTTON:
2021                         if(pLed1->bLedWPSBlinkInProgress)
2022                         {
2023                                 pLed1->bLedWPSBlinkInProgress = FALSE;
2024                                 del_timer_sync(&(pLed1->BlinkTimer));
2025                         
2026                                 pLed1->BlinkingLedState = LED_OFF;
2027                                 pLed1->CurrLedState = LED_OFF;
2028
2029                                 if(pLed1->bLedOn)
2030                                         mod_timer(&(pLed1->BlinkTimer), 0);
2031                         }
2032                                 
2033                         if(pLed->bLedWPSBlinkInProgress ==FALSE)
2034                         {
2035                                 if(pLed->bLedNoLinkBlinkInProgress == TRUE)
2036                                 {
2037                                         del_timer_sync(&(pLed->BlinkTimer));
2038                                         pLed->bLedNoLinkBlinkInProgress = FALSE;
2039                                 }
2040                                 if(pLed->bLedBlinkInProgress ==TRUE)
2041                                 {
2042                                         del_timer_sync(&(pLed->BlinkTimer));
2043                                         pLed->bLedBlinkInProgress = FALSE;
2044                                 }
2045                                 if(pLed->bLedScanBlinkInProgress ==TRUE)
2046                                 {
2047                                         del_timer_sync(&(pLed->BlinkTimer));
2048                                         pLed->bLedScanBlinkInProgress = FALSE;
2049                                 }                               
2050                                 pLed->bLedWPSBlinkInProgress = TRUE;
2051                                 pLed->CurrLedState = LED_BLINK_WPS;
2052                                 if( pLed->bLedOn )
2053                                 {
2054                                         pLed->BlinkingLedState = LED_OFF;
2055                                         mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_SLOWLY_INTERVAL));
2056                                 }
2057                                 else
2058                                 {
2059                                         pLed->BlinkingLedState = LED_ON; 
2060                                         mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_NORMAL_INTERVAL));
2061                                 }
2062                         
2063                          }
2064                         break;
2065                 
2066                 case LED_CTL_STOP_WPS:  
2067                         if(pLed->bLedWPSBlinkInProgress)
2068                         {
2069                                 del_timer_sync(&(pLed->BlinkTimer));
2070                                 pLed->bLedWPSBlinkInProgress = FALSE;                                                           
2071                         }
2072
2073                         pLed->bLedNoLinkBlinkInProgress = TRUE;
2074                         pLed->CurrLedState = LED_BLINK_SLOWLY;
2075                         if( pLed->bLedOn )
2076                                 pLed->BlinkingLedState = LED_OFF; 
2077                         else
2078                                 pLed->BlinkingLedState = LED_ON;
2079                         mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_NO_LINK_INTERVAL_ALPHA));
2080                                 
2081                         break;          
2082
2083                 case LED_CTL_STOP_WPS_FAIL:             
2084                         if(pLed->bLedWPSBlinkInProgress)
2085                         {
2086                                 del_timer_sync(&(pLed->BlinkTimer));
2087                                 pLed->bLedWPSBlinkInProgress = FALSE;                           
2088                         }                       
2089
2090                         pLed->bLedNoLinkBlinkInProgress = TRUE;
2091                         pLed->CurrLedState = LED_BLINK_SLOWLY;
2092                         if( pLed->bLedOn )
2093                                 pLed->BlinkingLedState = LED_OFF; 
2094                         else
2095                                 pLed->BlinkingLedState = LED_ON;
2096                         mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_NO_LINK_INTERVAL_ALPHA));
2097
2098                         if(pLed1->bLedWPSBlinkInProgress)
2099                                 del_timer_sync(&(pLed1->BlinkTimer));
2100                         else    
2101                                 pLed1->bLedWPSBlinkInProgress = TRUE;                           
2102
2103                         pLed1->CurrLedState = LED_BLINK_WPS_STOP;
2104                         if( pLed1->bLedOn )
2105                                 pLed1->BlinkingLedState = LED_OFF; 
2106                         else
2107                                 pLed1->BlinkingLedState = LED_ON;
2108                         mod_timer(&(pLed1->BlinkTimer), jiffies + MSECS(LED_BLINK_NORMAL_INTERVAL));
2109                                                 
2110                         break;                          
2111
2112                 case LED_CTL_STOP_WPS_FAIL_OVERLAP:     
2113                         if(pLed->bLedWPSBlinkInProgress)
2114                         {
2115                                 del_timer_sync(&(pLed->BlinkTimer));
2116                                 pLed->bLedWPSBlinkInProgress = FALSE;                                                           
2117                         }
2118                         
2119                         pLed->bLedNoLinkBlinkInProgress = TRUE;
2120                         pLed->CurrLedState = LED_BLINK_SLOWLY;
2121                         if( pLed->bLedOn )
2122                                 pLed->BlinkingLedState = LED_OFF; 
2123                         else
2124                                 pLed->BlinkingLedState = LED_ON;
2125                         mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_NO_LINK_INTERVAL_ALPHA));
2126
2127                         if(pLed1->bLedWPSBlinkInProgress)
2128                                 del_timer_sync(&(pLed1->BlinkTimer));
2129                         else    
2130                                 pLed1->bLedWPSBlinkInProgress = TRUE;                           
2131
2132                         pLed1->CurrLedState = LED_BLINK_WPS_STOP_OVERLAP;
2133                         pLed1->BlinkTimes = 10;
2134                         if( pLed1->bLedOn )
2135                                 pLed1->BlinkingLedState = LED_OFF; 
2136                         else
2137                                 pLed1->BlinkingLedState = LED_ON;
2138                         mod_timer(&(pLed1->BlinkTimer), jiffies + MSECS(LED_BLINK_NORMAL_INTERVAL));
2139                         
2140                         break;
2141
2142                 case LED_CTL_POWER_OFF:
2143                         pLed->CurrLedState = LED_OFF;
2144                         pLed->BlinkingLedState = LED_OFF; 
2145                         
2146                         if( pLed->bLedNoLinkBlinkInProgress)
2147                         {
2148                                 del_timer_sync(&(pLed->BlinkTimer));
2149                                 pLed->bLedNoLinkBlinkInProgress = FALSE;
2150                         }
2151                         if( pLed->bLedLinkBlinkInProgress)
2152                         {
2153                                 del_timer_sync(&(pLed->BlinkTimer));
2154                                 pLed->bLedLinkBlinkInProgress = FALSE;
2155                         }
2156                         if( pLed->bLedBlinkInProgress)
2157                         {
2158                                 del_timer_sync(&(pLed->BlinkTimer));
2159                                 pLed->bLedBlinkInProgress = FALSE;
2160                         }
2161                         if( pLed->bLedWPSBlinkInProgress )
2162                         {
2163                                 del_timer_sync(&(pLed->BlinkTimer));
2164                                 pLed->bLedWPSBlinkInProgress = FALSE;
2165                         }
2166                         if( pLed->bLedScanBlinkInProgress)
2167                         {
2168                                 del_timer_sync(&(pLed->BlinkTimer));
2169                                 pLed->bLedScanBlinkInProgress = FALSE;
2170                         }       
2171                         if( pLed->bLedStartToLinkBlinkInProgress)
2172                         {
2173                                 del_timer_sync(&(pLed->BlinkTimer));
2174                                 pLed->bLedStartToLinkBlinkInProgress = FALSE;
2175                         }                       
2176
2177                         if( pLed1->bLedWPSBlinkInProgress )
2178                         {
2179                                 del_timer_sync(&(pLed1->BlinkTimer));
2180                                 pLed1->bLedWPSBlinkInProgress = FALSE;
2181                         }
2182
2183
2184                         pLed1->BlinkingLedState = LED_UNKNOWN;                          
2185                         SwLedOff(dev, pLed);
2186                         SwLedOff(dev, pLed1);                   
2187                         break;
2188                         
2189                 default:
2190                         break;
2191
2192         }
2193
2194         RT_TRACE(COMP_LED, "Led %d\n", pLed->CurrLedState);
2195 }
2196
2197
2198
2199 void
2200 SwLedControlMode5(
2201         struct net_device               *dev,
2202         LED_CTL_MODE            LedAction
2203 )
2204 {
2205         struct r8192_priv       *priv = ieee80211_priv(dev);
2206         PLED_819xUsb pLed = &(priv->SwLed0);
2207
2208         if(priv->CustomerID == RT_CID_819x_CAMEO)
2209                 pLed = &(priv->SwLed1);
2210         
2211         switch(LedAction)
2212         {               
2213                 case LED_CTL_POWER_ON:
2214                 case LED_CTL_NO_LINK:
2215                 case LED_CTL_LINK:      
2216                         if(pLed->CurrLedState == LED_SCAN_BLINK)
2217                         {
2218                                 return;
2219                         }               
2220                         pLed->CurrLedState = LED_ON;
2221                         pLed->BlinkingLedState = LED_ON; 
2222                         pLed->bLedBlinkInProgress = FALSE;
2223                         mod_timer(&(pLed->BlinkTimer), 0);
2224                         break;
2225
2226                 case LED_CTL_SITE_SURVEY:
2227                          if((priv->ieee80211->LinkDetectInfo.bBusyTraffic) && (priv->ieee80211->state == IEEE80211_LINKED))
2228                                 ;                
2229                          else if(pLed->bLedScanBlinkInProgress ==FALSE)
2230                          {                              
2231                                 if(pLed->bLedBlinkInProgress ==TRUE)
2232                                 {
2233                                         del_timer_sync(&(pLed->BlinkTimer));
2234                                         pLed->bLedBlinkInProgress = FALSE;
2235                                 }
2236                                 pLed->bLedScanBlinkInProgress = TRUE;
2237                                 pLed->CurrLedState = LED_SCAN_BLINK;
2238                                 pLed->BlinkTimes = 24;
2239                                 if( pLed->bLedOn )
2240                                         pLed->BlinkingLedState = LED_OFF; 
2241                                 else
2242                                         pLed->BlinkingLedState = LED_ON;
2243                                 mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_SCAN_INTERVAL_ALPHA));
2244
2245                          }
2246                         break;
2247                 
2248                 case LED_CTL_TX:
2249                 case LED_CTL_RX:
2250                         if(pLed->bLedBlinkInProgress ==FALSE)
2251                         {
2252                                 if(pLed->CurrLedState == LED_SCAN_BLINK)
2253                                 {
2254                                         return;
2255                                 }                       
2256                                 pLed->bLedBlinkInProgress = TRUE;
2257                                 pLed->CurrLedState = LED_TXRX_BLINK;
2258                                 pLed->BlinkTimes = 2;
2259                                 if( pLed->bLedOn )
2260                                         pLed->BlinkingLedState = LED_OFF; 
2261                                 else
2262                                         pLed->BlinkingLedState = LED_ON;
2263                                 mod_timer(&(pLed->BlinkTimer), jiffies + MSECS(LED_BLINK_FASTER_INTERVAL_ALPHA));
2264                         }
2265                         break;                          
2266
2267                 case LED_CTL_POWER_OFF:
2268                         pLed->CurrLedState = LED_OFF;
2269                         pLed->BlinkingLedState = LED_OFF; 
2270
2271                         if( pLed->bLedBlinkInProgress)
2272                         {
2273                                 del_timer_sync(&(pLed->BlinkTimer));
2274                                 pLed->bLedBlinkInProgress = FALSE;
2275                         }                       
2276                                 
2277                         SwLedOff(dev, pLed);
2278                         break;
2279                         
2280                 default:
2281                         break;
2282
2283         }
2284
2285         RT_TRACE(COMP_LED, "Led %d\n", pLed->CurrLedState);
2286 }
2287
2288
2289 void
2290 LedControl8192SUsb(
2291         struct net_device               *dev,
2292         LED_CTL_MODE            LedAction
2293         )
2294 {
2295         struct r8192_priv *priv = ieee80211_priv(dev);
2296
2297         if( priv->bRegUseLed == FALSE)
2298                 return;
2299
2300         if (!priv->up)
2301                 return;
2302
2303         if(priv->bInHctTest)
2304                 return;
2305         
2306         if(     priv->ieee80211->eRFPowerState != eRfOn && 
2307                 (LedAction == LED_CTL_TX || LedAction == LED_CTL_RX || 
2308                  LedAction == LED_CTL_SITE_SURVEY || 
2309                  LedAction == LED_CTL_LINK || 
2310                  LedAction == LED_CTL_NO_LINK ||
2311                  LedAction == LED_CTL_POWER_ON) )
2312         {
2313                 return;
2314         }
2315         
2316         switch(priv->LedStrategy)
2317         {
2318                 case SW_LED_MODE0:
2319                         break;
2320
2321                 case SW_LED_MODE1:
2322                         SwLedControlMode1(dev, LedAction);
2323                         break;
2324                 case SW_LED_MODE2:
2325                         SwLedControlMode2(dev, LedAction);
2326                         break;
2327
2328                 case SW_LED_MODE3:
2329                         SwLedControlMode3(dev, LedAction);
2330                         break;  
2331
2332                 case SW_LED_MODE4:
2333                         SwLedControlMode4(dev, LedAction);
2334                         break;                  
2335
2336                 case SW_LED_MODE5:
2337                         SwLedControlMode5(dev, LedAction);
2338                         break;
2339
2340                 default:
2341                         break;
2342         }
2343         
2344         RT_TRACE(COMP_LED, "LedStrategy:%d, LedAction %d\n", priv->LedStrategy,LedAction);
2345 }
2346
2347