]> bbs.cooldavid.org Git - net-next-2.6.git/blob - drivers/staging/winbond/wbusb.c
a23e7208249ce45d89cd0e3866870f08c6d10214
[net-next-2.6.git] / drivers / staging / winbond / wbusb.c
1 /*
2  * Copyright 2008 Pavel Machek <pavel@suse.cz>
3  *
4  * Distribute under GPLv2.
5  */
6 #include <net/mac80211.h>
7 #include <linux/usb.h>
8
9 #include "core.h"
10 #include "mds_f.h"
11 #include "mlmetxrx_f.h"
12 #include "mto.h"
13 #include "wbhal_f.h"
14 #include "wblinux_f.h"
15
16 MODULE_AUTHOR("Original by: Jeff Lee<YY_Lee@issc.com.tw> Adapted to 2.6.x by Costantino Leandro (Rxart Desktop) <le_costantino@pixartargentina.com.ar>");
17 MODULE_DESCRIPTION("IS89C35 802.11bg WLAN USB Driver");
18 MODULE_LICENSE("GPL");
19 MODULE_VERSION("0.1");
20
21 static struct usb_device_id wb35_table[] __devinitdata = {
22         {USB_DEVICE(0x0416, 0x0035)},
23         {USB_DEVICE(0x18E8, 0x6201)},
24         {USB_DEVICE(0x18E8, 0x6206)},
25         {USB_DEVICE(0x18E8, 0x6217)},
26         {USB_DEVICE(0x18E8, 0x6230)},
27         {USB_DEVICE(0x18E8, 0x6233)},
28         {USB_DEVICE(0x1131, 0x2035)},
29         { 0, }
30 };
31
32 MODULE_DEVICE_TABLE(usb, wb35_table);
33
34 static struct ieee80211_rate wbsoft_rates[] = {
35         { .bitrate = 10, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
36 };
37
38 static struct ieee80211_channel wbsoft_channels[] = {
39         { .center_freq = 2412},
40 };
41
42 static struct ieee80211_supported_band wbsoft_band_2GHz = {
43         .channels       = wbsoft_channels,
44         .n_channels     = ARRAY_SIZE(wbsoft_channels),
45         .bitrates       = wbsoft_rates,
46         .n_bitrates     = ARRAY_SIZE(wbsoft_rates),
47 };
48
49 static int wbsoft_add_interface(struct ieee80211_hw *dev,
50                                  struct ieee80211_if_init_conf *conf)
51 {
52         printk("wbsoft_add interface called\n");
53         return 0;
54 }
55
56 static void wbsoft_remove_interface(struct ieee80211_hw *dev,
57                                      struct ieee80211_if_init_conf *conf)
58 {
59         printk("wbsoft_remove interface called\n");
60 }
61
62 static void wbsoft_stop(struct ieee80211_hw *hw)
63 {
64         printk(KERN_INFO "%s called\n", __func__);
65 }
66
67 static int wbsoft_get_stats(struct ieee80211_hw *hw,
68                             struct ieee80211_low_level_stats *stats)
69 {
70         printk(KERN_INFO "%s called\n", __func__);
71         return 0;
72 }
73
74 static int wbsoft_get_tx_stats(struct ieee80211_hw *hw,
75                                struct ieee80211_tx_queue_stats *stats)
76 {
77         printk(KERN_INFO "%s called\n", __func__);
78         return 0;
79 }
80
81 static void wbsoft_configure_filter(struct ieee80211_hw *dev,
82                                      unsigned int changed_flags,
83                                      unsigned int *total_flags,
84                                      int mc_count, struct dev_mc_list *mclist)
85 {
86         unsigned int new_flags;
87
88         new_flags = 0;
89
90         if (*total_flags & FIF_PROMISC_IN_BSS)
91                 new_flags |= FIF_PROMISC_IN_BSS;
92         else if ((*total_flags & FIF_ALLMULTI) || (mc_count > 32))
93                 new_flags |= FIF_ALLMULTI;
94
95         dev->flags &= ~IEEE80211_HW_RX_INCLUDES_FCS;
96
97         *total_flags = new_flags;
98 }
99
100 static int wbsoft_tx(struct ieee80211_hw *dev, struct sk_buff *skb)
101 {
102         struct wbsoft_priv *priv = dev->priv;
103
104         MLMESendFrame(priv, skb->data, skb->len, FRAME_TYPE_802_11_MANAGEMENT);
105
106         return NETDEV_TX_OK;
107 }
108
109
110 static int wbsoft_start(struct ieee80211_hw *dev)
111 {
112         struct wbsoft_priv *priv = dev->priv;
113
114         priv->enabled = true;
115
116         return 0;
117 }
118
119 static int wbsoft_config(struct ieee80211_hw *dev, u32 changed)
120 {
121         struct wbsoft_priv *priv = dev->priv;
122         struct ieee80211_conf *conf = &dev->conf;
123         ChanInfo ch;
124
125         printk("wbsoft_config called\n");
126
127         ch.band = 1;
128         ch.ChanNo = 1;  /* Should use channel_num, or something, as that is already pre-translated */
129
130
131         hal_set_current_channel(&priv->sHwData, ch);
132         hal_set_beacon_period(&priv->sHwData, conf->beacon_int);
133 //      hal_set_cap_info(&priv->sHwData, ?? );
134 // hal_set_ssid(struct hw_data * pHwData,  u8 * pssid,  u8 ssid_len); ??
135         hal_set_accept_broadcast(&priv->sHwData, 1);
136         hal_set_accept_promiscuous(&priv->sHwData,  1);
137         hal_set_accept_multicast(&priv->sHwData,  1);
138         hal_set_accept_beacon(&priv->sHwData,  1);
139         hal_set_radio_mode(&priv->sHwData,  0);
140         //hal_set_antenna_number(  struct hw_data * pHwData, u8 number )
141         //hal_set_rf_power(struct hw_data * pHwData, u8 PowerIndex)
142
143
144 //      hal_start_bss(&priv->sHwData, WLAN_BSSTYPE_INFRASTRUCTURE);     ??
145
146 //void hal_set_rates(struct hw_data * pHwData, u8 * pbss_rates,
147 //                 u8 length, unsigned char basic_rate_set)
148
149         return 0;
150 }
151
152 static int wbsoft_config_interface(struct ieee80211_hw *dev,
153                                     struct ieee80211_vif *vif,
154                                     struct ieee80211_if_conf *conf)
155 {
156         printk("wbsoft_config_interface called\n");
157         return 0;
158 }
159
160 static u64 wbsoft_get_tsf(struct ieee80211_hw *dev)
161 {
162         printk("wbsoft_get_tsf called\n");
163         return 0;
164 }
165
166 static const struct ieee80211_ops wbsoft_ops = {
167         .tx                     = wbsoft_tx,
168         .start                  = wbsoft_start,         /* Start can be pretty much empty as we do wb35_hw_init() during probe? */
169         .stop                   = wbsoft_stop,
170         .add_interface          = wbsoft_add_interface,
171         .remove_interface       = wbsoft_remove_interface,
172         .config                 = wbsoft_config,
173         .config_interface       = wbsoft_config_interface,
174         .configure_filter       = wbsoft_configure_filter,
175         .get_stats              = wbsoft_get_stats,
176         .get_tx_stats           = wbsoft_get_tx_stats,
177         .get_tsf                = wbsoft_get_tsf,
178 // conf_tx: hal_set_cwmin()/hal_set_cwmax;
179 };
180
181 static void hal_led_control(unsigned long data)
182 {
183         struct wbsoft_priv *adapter = (struct wbsoft_priv *) data;
184         struct hw_data * pHwData = &adapter->sHwData;
185         struct wb35_reg *reg = &pHwData->reg;
186         u32     LEDSet = (pHwData->SoftwareSet & HAL_LED_SET_MASK) >> HAL_LED_SET_SHIFT;
187         u8      LEDgray[20] = { 0,3,4,6,8,10,11,12,13,14,15,14,13,12,11,10,8,6,4,2 };
188         u8      LEDgray2[30] = { 7,8,9,10,11,12,13,14,15,0,0,0,0,0,0,0,0,0,0,0,0,0,15,14,13,12,11,10,9,8 };
189         u32     TimeInterval = 500, ltmp, ltmp2;
190         ltmp=0;
191
192         if( pHwData->SurpriseRemove ) return;
193
194         if( pHwData->LED_control ) {
195                 ltmp2 = pHwData->LED_control & 0xff;
196                 if( ltmp2 == 5 ) // 5 is WPS mode
197                 {
198                         TimeInterval = 100;
199                         ltmp2 = (pHwData->LED_control>>8) & 0xff;
200                         switch( ltmp2 )
201                         {
202                                 case 1: // [0.2 On][0.1 Off]...
203                                         pHwData->LED_Blinking %= 3;
204                                         ltmp = 0x1010; // Led 1 & 0 Green and Red
205                                         if( pHwData->LED_Blinking == 2 ) // Turn off
206                                                 ltmp = 0;
207                                         break;
208                                 case 2: // [0.1 On][0.1 Off]...
209                                         pHwData->LED_Blinking %= 2;
210                                         ltmp = 0x0010; // Led 0 red color
211                                         if( pHwData->LED_Blinking ) // Turn off
212                                                 ltmp = 0;
213                                         break;
214                                 case 3: // [0.1 On][0.1 Off][0.1 On][0.1 Off][0.1 On][0.1 Off][0.1 On][0.1 Off][0.1 On][0.1 Off][0.5 Off]...
215                                         pHwData->LED_Blinking %= 15;
216                                         ltmp = 0x0010; // Led 0 red color
217                                         if( (pHwData->LED_Blinking >= 9) || (pHwData->LED_Blinking%2) ) // Turn off 0.6 sec
218                                                 ltmp = 0;
219                                         break;
220                                 case 4: // [300 On][ off ]
221                                         ltmp = 0x1000; // Led 1 Green color
222                                         if( pHwData->LED_Blinking >= 3000 )
223                                                 ltmp = 0; // led maybe on after 300sec * 32bit counter overlap.
224                                         break;
225                         }
226                         pHwData->LED_Blinking++;
227
228                         reg->U1BC_LEDConfigure = ltmp;
229                         if( LEDSet != 7 ) // Only 111 mode has 2 LEDs on PCB.
230                         {
231                                 reg->U1BC_LEDConfigure |= (ltmp &0xff)<<8; // Copy LED result to each LED control register
232                                 reg->U1BC_LEDConfigure |= (ltmp &0xff00)>>8;
233                         }
234                         Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure );
235                 }
236         }
237         else if( pHwData->CurrentRadioSw || pHwData->CurrentRadioHw ) // If radio off
238         {
239                 if( reg->U1BC_LEDConfigure & 0x1010 )
240                 {
241                         reg->U1BC_LEDConfigure &= ~0x1010;
242                         Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure );
243                 }
244         }
245         else
246         {
247                 switch( LEDSet )
248                 {
249                         case 4: // [100] Only 1 Led be placed on PCB and use pin 21 of IC. Use LED_0 for showing
250                                 if( !pHwData->LED_LinkOn ) // Blink only if not Link On
251                                 {
252                                         // Blinking if scanning is on progress
253                                         if( pHwData->LED_Scanning )
254                                         {
255                                                 if( pHwData->LED_Blinking == 0 )
256                                                 {
257                                                         reg->U1BC_LEDConfigure |= 0x10;
258                                                         Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure ); // LED_0 On
259                                                         pHwData->LED_Blinking = 1;
260                                                         TimeInterval = 300;
261                                                 }
262                                                 else
263                                                 {
264                                                         reg->U1BC_LEDConfigure &= ~0x10;
265                                                         Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure ); // LED_0 Off
266                                                         pHwData->LED_Blinking = 0;
267                                                         TimeInterval = 300;
268                                                 }
269                                         }
270                                         else
271                                         {
272                                                 //Turn Off LED_0
273                                                 if( reg->U1BC_LEDConfigure & 0x10 )
274                                                 {
275                                                         reg->U1BC_LEDConfigure &= ~0x10;
276                                                         Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure ); // LED_0 Off
277                                                 }
278                                         }
279                                 }
280                                 else
281                                 {
282                                         // Turn On LED_0
283                                         if( (reg->U1BC_LEDConfigure & 0x10) == 0 )
284                                         {
285                                                 reg->U1BC_LEDConfigure |= 0x10;
286                                                 Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure ); // LED_0 Off
287                                         }
288                                 }
289                                 break;
290
291                         case 6: // [110] Only 1 Led be placed on PCB and use pin 21 of IC. Use LED_0 for showing
292                                 if( !pHwData->LED_LinkOn ) // Blink only if not Link On
293                                 {
294                                         // Blinking if scanning is on progress
295                                         if( pHwData->LED_Scanning )
296                                         {
297                                                 if( pHwData->LED_Blinking == 0 )
298                                                 {
299                                                         reg->U1BC_LEDConfigure &= ~0xf;
300                                                         reg->U1BC_LEDConfigure |= 0x10;
301                                                         Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure ); // LED_0 On
302                                                         pHwData->LED_Blinking = 1;
303                                                         TimeInterval = 300;
304                                                 }
305                                                 else
306                                                 {
307                                                         reg->U1BC_LEDConfigure &= ~0x1f;
308                                                         Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure ); // LED_0 Off
309                                                         pHwData->LED_Blinking = 0;
310                                                         TimeInterval = 300;
311                                                 }
312                                         }
313                                         else
314                                         {
315                                                 // 20060901 Gray blinking if in disconnect state and not scanning
316                                                 ltmp = reg->U1BC_LEDConfigure;
317                                                 reg->U1BC_LEDConfigure &= ~0x1f;
318                                                 if( LEDgray2[(pHwData->LED_Blinking%30)] )
319                                                 {
320                                                         reg->U1BC_LEDConfigure |= 0x10;
321                                                         reg->U1BC_LEDConfigure |= LEDgray2[ (pHwData->LED_Blinking%30) ];
322                                                 }
323                                                 pHwData->LED_Blinking++;
324                                                 if( reg->U1BC_LEDConfigure != ltmp )
325                                                         Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure ); // LED_0 Off
326                                                 TimeInterval = 100;
327                                         }
328                                 }
329                                 else
330                                 {
331                                         // Turn On LED_0
332                                         if( (reg->U1BC_LEDConfigure & 0x10) == 0 )
333                                         {
334                                                 reg->U1BC_LEDConfigure |= 0x10;
335                                                 Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure ); // LED_0 Off
336                                         }
337                                 }
338                                 break;
339
340                         case 5: // [101] Only 1 Led be placed on PCB and use LED_1 for showing
341                                 if( !pHwData->LED_LinkOn ) // Blink only if not Link On
342                                 {
343                                         // Blinking if scanning is on progress
344                                         if( pHwData->LED_Scanning )
345                                         {
346                                                 if( pHwData->LED_Blinking == 0 )
347                                                 {
348                                                         reg->U1BC_LEDConfigure |= 0x1000;
349                                                         Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure ); // LED_1 On
350                                                         pHwData->LED_Blinking = 1;
351                                                         TimeInterval = 300;
352                                                 }
353                                                 else
354                                                 {
355                                                         reg->U1BC_LEDConfigure &= ~0x1000;
356                                                         Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure ); // LED_1 Off
357                                                         pHwData->LED_Blinking = 0;
358                                                         TimeInterval = 300;
359                                                 }
360                                         }
361                                         else
362                                         {
363                                                 //Turn Off LED_1
364                                                 if( reg->U1BC_LEDConfigure & 0x1000 )
365                                                 {
366                                                         reg->U1BC_LEDConfigure &= ~0x1000;
367                                                         Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure ); // LED_1 Off
368                                                 }
369                                         }
370                                 }
371                                 else
372                                 {
373                                         // Is transmitting/receiving ??
374                                         if( (adapter->RxByteCount != pHwData->RxByteCountLast ) ||
375                                                 (adapter->TxByteCount != pHwData->TxByteCountLast ) )
376                                         {
377                                                 if( (reg->U1BC_LEDConfigure & 0x3000) != 0x3000 )
378                                                 {
379                                                         reg->U1BC_LEDConfigure |= 0x3000;
380                                                         Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure ); // LED_1 On
381                                                 }
382
383                                                 // Update variable
384                                                 pHwData->RxByteCountLast = adapter->RxByteCount;
385                                                 pHwData->TxByteCountLast = adapter->TxByteCount;
386                                                 TimeInterval = 200;
387                                         }
388                                         else
389                                         {
390                                                 // Turn On LED_1 and blinking if transmitting/receiving
391                                                  if( (reg->U1BC_LEDConfigure & 0x3000) != 0x1000 )
392                                                  {
393                                                          reg->U1BC_LEDConfigure &= ~0x3000;
394                                                          reg->U1BC_LEDConfigure |= 0x1000;
395                                                          Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure ); // LED_1 On
396                                                  }
397                                         }
398                                 }
399                                 break;
400
401                         default: // Default setting. 2 LED be placed on PCB. LED_0: Link On LED_1 Active
402                                 if( (reg->U1BC_LEDConfigure & 0x3000) != 0x3000 )
403                                 {
404                                         reg->U1BC_LEDConfigure |= 0x3000;// LED_1 is always on and event enable
405                                         Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure );
406                                 }
407
408                                 if( pHwData->LED_Blinking )
409                                 {
410                                         // Gray blinking
411                                         reg->U1BC_LEDConfigure &= ~0x0f;
412                                         reg->U1BC_LEDConfigure |= 0x10;
413                                         reg->U1BC_LEDConfigure |= LEDgray[ (pHwData->LED_Blinking-1)%20 ];
414                                         Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure );
415
416                                         pHwData->LED_Blinking += 2;
417                                         if( pHwData->LED_Blinking < 40 )
418                                                 TimeInterval = 100;
419                                         else
420                                         {
421                                                 pHwData->LED_Blinking = 0; // Stop blinking
422                                                 reg->U1BC_LEDConfigure &= ~0x0f;
423                                                 Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure );
424                                         }
425                                         break;
426                                 }
427
428                                 if( pHwData->LED_LinkOn )
429                                 {
430                                         if( !(reg->U1BC_LEDConfigure & 0x10) ) // Check the LED_0
431                                         {
432                                                 //Try to turn ON LED_0 after gray blinking
433                                                 reg->U1BC_LEDConfigure |= 0x10;
434                                                 pHwData->LED_Blinking = 1; //Start blinking
435                                                 TimeInterval = 50;
436                                         }
437                                 }
438                                 else
439                                 {
440                                         if( reg->U1BC_LEDConfigure & 0x10 ) // Check the LED_0
441                                         {
442                                                 reg->U1BC_LEDConfigure &= ~0x10;
443                                                 Wb35Reg_Write( pHwData, 0x03bc, reg->U1BC_LEDConfigure );
444                                         }
445                                 }
446                                 break;
447                 }
448
449                 //20060828.1 Active send null packet to avoid AP disconnect
450                 if( pHwData->LED_LinkOn )
451                 {
452                         pHwData->NullPacketCount += TimeInterval;
453                         if( pHwData->NullPacketCount >= DEFAULT_NULL_PACKET_COUNT )
454                         {
455                                 pHwData->NullPacketCount = 0;
456                         }
457                 }
458         }
459
460         pHwData->time_count += TimeInterval;
461         Wb35Tx_CurrentTime(adapter, pHwData->time_count); // 20060928 add
462         pHwData->LEDTimer.expires = jiffies + msecs_to_jiffies(TimeInterval);
463         add_timer(&pHwData->LEDTimer);
464 }
465
466 static int hal_init_hardware(struct ieee80211_hw *hw)
467 {
468         struct wbsoft_priv *priv = hw->priv;
469         struct hw_data * pHwData = &priv->sHwData;
470         u16 SoftwareSet;
471
472         // Initial the variable
473         pHwData->MaxReceiveLifeTime = DEFAULT_MSDU_LIFE_TIME; // Setting Rx maximum MSDU life time
474         pHwData->FragmentThreshold = DEFAULT_FRAGMENT_THRESHOLD; // Setting default fragment threshold
475
476         if (!Wb35Reg_initial(pHwData))
477                 goto error_reg_destroy;
478
479         if (!Wb35Tx_initial(pHwData))
480                 goto error_tx_destroy;
481
482         if (!Wb35Rx_initial(pHwData))
483                 goto error_rx_destroy;
484
485         init_timer(&pHwData->LEDTimer);
486         pHwData->LEDTimer.function = hal_led_control;
487         pHwData->LEDTimer.data = (unsigned long) priv;
488         pHwData->LEDTimer.expires = jiffies + msecs_to_jiffies(1000);
489         add_timer(&pHwData->LEDTimer);
490
491         //
492         // For restrict to vendor's hardware
493         //
494         SoftwareSet = hal_software_set( pHwData );
495
496         #ifdef Vendor2
497         // Try to make sure the EEPROM contain
498         SoftwareSet >>= 8;
499         if( SoftwareSet != 0x82 )
500                 return false;
501         #endif
502
503         Wb35Rx_start(hw);
504         Wb35Tx_EP2VM_start(priv);
505
506         return 0;
507
508 error_rx_destroy:
509         Wb35Rx_destroy(pHwData);
510 error_tx_destroy:
511         Wb35Tx_destroy(pHwData);
512 error_reg_destroy:
513         Wb35Reg_destroy(pHwData);
514
515         pHwData->SurpriseRemove = 1;
516         return -EINVAL;
517 }
518
519 static int wb35_hw_init(struct ieee80211_hw *hw)
520 {
521         struct wbsoft_priv *priv = hw->priv;
522         struct hw_data *        pHwData;
523         u8              *pMacAddr;
524         u8              *pMacAddr2;
525         u8              EEPROM_region;
526         u8              HwRadioOff;
527         int err;
528
529         //
530         // Setting default value for Linux
531         //
532         priv->sLocalPara.region_INF = REGION_AUTO;
533         priv->sLocalPara.TxRateMode = RATE_AUTO;
534         priv->sLocalPara.bMacOperationMode = MODE_802_11_BG;    // B/G mode
535         priv->Mds.TxRTSThreshold = DEFAULT_RTSThreshold;
536         priv->Mds.TxFragmentThreshold = DEFAULT_FRAGMENT_THRESHOLD;
537         hal_set_phy_type( &priv->sHwData, RF_WB_242_1 );
538         priv->sLocalPara.MTUsize = MAX_ETHERNET_PACKET_SIZE;
539         priv->sLocalPara.bPreambleMode = AUTO_MODE;
540         priv->sLocalPara.RadioOffStatus.boSwRadioOff = false;
541         pHwData = &priv->sHwData;
542         hal_set_phy_type( pHwData, RF_DECIDE_BY_INF );
543
544         //added by ws for wep key error detection
545         priv->sLocalPara.bWepKeyError= false;
546         priv->sLocalPara.bToSelfPacketReceived = false;
547         priv->sLocalPara.WepKeyDetectTimerCount= 2 * 100; /// 2 seconds
548
549         // Initial USB hal
550         pHwData = &priv->sHwData;
551         err = hal_init_hardware(hw);
552         if (err)
553                 goto error;
554
555         EEPROM_region = hal_get_region_from_EEPROM( pHwData );
556         if (EEPROM_region != REGION_AUTO)
557                 priv->sLocalPara.region = EEPROM_region;
558         else {
559                 if (priv->sLocalPara.region_INF != REGION_AUTO)
560                         priv->sLocalPara.region = priv->sLocalPara.region_INF;
561                 else
562                         priv->sLocalPara.region = REGION_USA;   //default setting
563         }
564
565         // Get Software setting flag from hal
566         priv->sLocalPara.boAntennaDiversity = false;
567         if (hal_software_set(pHwData) & 0x00000001)
568                 priv->sLocalPara.boAntennaDiversity = true;
569
570         // For MDS module
571         Mds_initial(priv);
572
573         //=======================================
574         // Initialize the SME, SCAN, MLME, ROAM
575         //=======================================
576
577         // If no user-defined address in the registry, use the addresss "burned" on the NIC instead.
578         pMacAddr = priv->sLocalPara.ThisMacAddress;
579         pMacAddr2 = priv->sLocalPara.PermanentAddress;
580         hal_get_permanent_address( pHwData, priv->sLocalPara.PermanentAddress );// Reading ethernet address from EEPROM
581         if (memcmp(pMacAddr, "\x00\x00\x00\x00\x00\x00", MAC_ADDR_LENGTH) == 0)
582                 memcpy(pMacAddr, pMacAddr2, MAC_ADDR_LENGTH);
583         else {
584                 // Set the user define MAC address
585                 hal_set_ethernet_address(pHwData, priv->sLocalPara.ThisMacAddress);
586         }
587
588         //get current antenna
589         priv->sLocalPara.bAntennaNo = hal_get_antenna_number(pHwData);
590 #ifdef _PE_STATE_DUMP_
591         printk("Driver init, antenna no = %d\n", psLOCAL->bAntennaNo);
592 #endif
593         hal_get_hw_radio_off( pHwData );
594
595         // Waiting for HAL setting OK
596         while (!hal_idle(pHwData))
597                 msleep(10);
598
599         MTO_Init(priv);
600
601         HwRadioOff = hal_get_hw_radio_off( pHwData );
602         priv->sLocalPara.RadioOffStatus.boHwRadioOff = !!HwRadioOff;
603
604         hal_set_radio_mode( pHwData, (unsigned char)(priv->sLocalPara.RadioOffStatus.boSwRadioOff || priv->sLocalPara.RadioOffStatus.boHwRadioOff) );
605
606         hal_driver_init_OK(pHwData) = 1; // Notify hal that the driver is ready now.
607         //set a tx power for reference.....
608 //      sme_set_tx_power_level(priv, 12);       FIXME?
609
610 error:
611         return err;
612 }
613
614 static int wb35_probe(struct usb_interface *intf, const struct usb_device_id *id_table)
615 {
616         struct wb_usb *pWbUsb;
617         struct usb_host_interface *interface;
618         struct usb_endpoint_descriptor *endpoint;
619         u32     ltmp;
620         struct usb_device *udev = interface_to_usbdev(intf);
621         struct wbsoft_priv *priv;
622         struct ieee80211_hw *dev;
623         int nr, err;
624
625         usb_get_dev(udev);
626
627         // 20060630.2 Check the device if it already be opened
628         nr = usb_control_msg(udev, usb_rcvctrlpipe( udev, 0 ),
629                              0x01, USB_TYPE_VENDOR|USB_RECIP_DEVICE|USB_DIR_IN,
630                              0x0, 0x400, &ltmp, 4, HZ*100 );
631         if (nr < 0) {
632                 err = nr;
633                 goto error;
634         }
635
636         ltmp = cpu_to_le32(ltmp);
637         if (ltmp) {  // Is already initialized?
638                 err = -EBUSY;
639                 goto error;
640         }
641
642         dev = ieee80211_alloc_hw(sizeof(*priv), &wbsoft_ops);
643         if (!dev) {
644                 err = -ENOMEM;
645                 goto error;
646         }
647
648         priv = dev->priv;
649
650         spin_lock_init(&priv->SpinLock);
651
652         pWbUsb = &priv->sHwData.WbUsb;
653         pWbUsb->udev = udev;
654
655         interface = intf->cur_altsetting;
656         endpoint = &interface->endpoint[0].desc;
657
658         if (endpoint[2].wMaxPacketSize == 512) {
659                 printk("[w35und] Working on USB 2.0\n");
660                 pWbUsb->IsUsb20 = 1;
661         }
662
663         err = wb35_hw_init(dev);
664         if (err)
665                 goto error_free_hw;
666
667         SET_IEEE80211_DEV(dev, &udev->dev);
668         {
669                 struct hw_data * pHwData = &priv->sHwData;
670                 unsigned char           dev_addr[MAX_ADDR_LEN];
671                 hal_get_permanent_address(pHwData, dev_addr);
672                 SET_IEEE80211_PERM_ADDR(dev, dev_addr);
673         }
674
675         dev->extra_tx_headroom = 12;    /* FIXME */
676         dev->flags = IEEE80211_HW_SIGNAL_UNSPEC;
677         dev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
678
679         dev->channel_change_time = 1000;
680         dev->max_signal = 100;
681         dev->queues = 1;
682
683         dev->wiphy->bands[IEEE80211_BAND_2GHZ] = &wbsoft_band_2GHz;
684
685         err = ieee80211_register_hw(dev);
686         if (err)
687                 goto error_free_hw;
688
689         usb_set_intfdata(intf, dev);
690
691         return 0;
692
693 error_free_hw:
694         ieee80211_free_hw(dev);
695 error:
696         usb_put_dev(udev);
697         return err;
698 }
699
700 static void hal_halt(struct hw_data *pHwData)
701 {
702         del_timer_sync(&pHwData->LEDTimer);
703         /* XXX: Wait for Timer DPC exit. */
704         msleep(100);
705         Wb35Rx_destroy(pHwData);
706         Wb35Tx_destroy(pHwData);
707         Wb35Reg_destroy(pHwData);
708 }
709
710 static void wb35_hw_halt(struct wbsoft_priv *adapter)
711 {
712         Mds_Destroy( adapter );
713
714         // Turn off Rx and Tx hardware ability
715         hal_stop( &adapter->sHwData );
716 #ifdef _PE_USB_INI_DUMP_
717         printk("[w35und] Hal_stop O.K.\n");
718 #endif
719         msleep(100);// Waiting Irp completed
720
721         // Halt the HAL
722         hal_halt(&adapter->sHwData);
723 }
724
725
726 static void wb35_disconnect(struct usb_interface *intf)
727 {
728         struct ieee80211_hw *hw = usb_get_intfdata(intf);
729         struct wbsoft_priv *priv = hw->priv;
730
731         wb35_hw_halt(priv);
732
733         ieee80211_stop_queues(hw);
734         ieee80211_unregister_hw(hw);
735         ieee80211_free_hw(hw);
736
737         usb_set_intfdata(intf, NULL);
738         usb_put_dev(interface_to_usbdev(intf));
739 }
740
741 static struct usb_driver wb35_driver = {
742         .name           = "w35und",
743         .id_table       = wb35_table,
744         .probe          = wb35_probe,
745         .disconnect     = wb35_disconnect,
746 };
747
748 static int __init wb35_init(void)
749 {
750         return usb_register(&wb35_driver);
751 }
752
753 static void __exit wb35_exit(void)
754 {
755         usb_deregister(&wb35_driver);
756 }
757
758 module_init(wb35_init);
759 module_exit(wb35_exit);