]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/wlan-ng/cfg80211.c
Merge 3.12-rc6 into staging-next.
[karo-tx-linux.git] / drivers / staging / wlan-ng / cfg80211.c
1 /* cfg80211 Interface for prism2_usb module */
2
3
4 /* Prism2 channel/frequency/bitrate declarations */
5 static const struct ieee80211_channel prism2_channels[] = {
6         { .center_freq = 2412 },
7         { .center_freq = 2417 },
8         { .center_freq = 2422 },
9         { .center_freq = 2427 },
10         { .center_freq = 2432 },
11         { .center_freq = 2437 },
12         { .center_freq = 2442 },
13         { .center_freq = 2447 },
14         { .center_freq = 2452 },
15         { .center_freq = 2457 },
16         { .center_freq = 2462 },
17         { .center_freq = 2467 },
18         { .center_freq = 2472 },
19         { .center_freq = 2484 },
20 };
21
22 static const struct ieee80211_rate prism2_rates[] = {
23         { .bitrate = 10 },
24         { .bitrate = 20 },
25         { .bitrate = 55 },
26         { .bitrate = 110 }
27 };
28
29 #define PRISM2_NUM_CIPHER_SUITES 2
30 static const u32 prism2_cipher_suites[PRISM2_NUM_CIPHER_SUITES] = {
31         WLAN_CIPHER_SUITE_WEP40,
32         WLAN_CIPHER_SUITE_WEP104
33 };
34
35
36 /* prism2 device private data */
37 struct prism2_wiphy_private {
38         wlandevice_t *wlandev;
39
40         struct ieee80211_supported_band band;
41         struct ieee80211_channel channels[ARRAY_SIZE(prism2_channels)];
42         struct ieee80211_rate rates[ARRAY_SIZE(prism2_rates)];
43
44         struct cfg80211_scan_request *scan_request;
45 };
46
47 static const void * const prism2_wiphy_privid = &prism2_wiphy_privid;
48
49
50 /* Helper Functions */
51 static int prism2_result2err(int prism2_result)
52 {
53         int err = 0;
54
55         switch (prism2_result) {
56         case P80211ENUM_resultcode_invalid_parameters:
57                 err = -EINVAL;
58                 break;
59         case P80211ENUM_resultcode_implementation_failure:
60                 err = -EIO;
61                 break;
62         case P80211ENUM_resultcode_not_supported:
63                 err = -EOPNOTSUPP;
64                 break;
65         default:
66                 err = 0;
67                 break;
68         }
69
70         return err;
71 }
72
73 static int prism2_domibset_uint32(wlandevice_t *wlandev, u32 did, u32 data)
74 {
75         struct p80211msg_dot11req_mibset msg;
76         p80211item_uint32_t *mibitem = (p80211item_uint32_t *) &msg.mibattribute.data;
77
78         msg.msgcode = DIDmsg_dot11req_mibset;
79         mibitem->did = did;
80         mibitem->data = data;
81
82         return p80211req_dorequest(wlandev, (u8 *) &msg);
83 }
84
85 static int prism2_domibset_pstr32(wlandevice_t *wlandev,
86                                   u32 did, u8 len, u8 *data)
87 {
88         struct p80211msg_dot11req_mibset msg;
89         p80211item_pstr32_t *mibitem = (p80211item_pstr32_t *) &msg.mibattribute.data;
90
91         msg.msgcode = DIDmsg_dot11req_mibset;
92         mibitem->did = did;
93         mibitem->data.len = len;
94         memcpy(mibitem->data.data, data, len);
95
96         return p80211req_dorequest(wlandev, (u8 *) &msg);
97 }
98
99
100 /* The interface functions, called by the cfg80211 layer */
101 static int prism2_change_virtual_intf(struct wiphy *wiphy,
102                                       struct net_device *dev,
103                                       enum nl80211_iftype type, u32 *flags,
104                                       struct vif_params *params)
105 {
106         wlandevice_t *wlandev = dev->ml_priv;
107         u32 data;
108         int result;
109         int err = 0;
110
111         switch (type) {
112         case NL80211_IFTYPE_ADHOC:
113                 if (wlandev->macmode == WLAN_MACMODE_IBSS_STA)
114                         goto exit;
115                 wlandev->macmode = WLAN_MACMODE_IBSS_STA;
116                 data = 0;
117                 break;
118         case NL80211_IFTYPE_STATION:
119                 if (wlandev->macmode == WLAN_MACMODE_ESS_STA)
120                         goto exit;
121                 wlandev->macmode = WLAN_MACMODE_ESS_STA;
122                 data = 1;
123                 break;
124         default:
125                 netdev_warn(dev, "Operation mode: %d not support\n", type);
126                 return -EOPNOTSUPP;
127         }
128
129         /* Set Operation mode to the PORT TYPE RID */
130         result = prism2_domibset_uint32(wlandev,
131                                         DIDmib_p2_p2Static_p2CnfPortType,
132                                         data);
133
134         if (result)
135                 err = -EFAULT;
136
137         dev->ieee80211_ptr->iftype = type;
138
139 exit:
140         return err;
141 }
142
143 static int prism2_add_key(struct wiphy *wiphy, struct net_device *dev,
144                           u8 key_index, bool pairwise, const u8 *mac_addr,
145                           struct key_params *params)
146 {
147         wlandevice_t *wlandev = dev->ml_priv;
148         u32 did;
149
150         int err = 0;
151         int result = 0;
152
153         switch (params->cipher) {
154         case WLAN_CIPHER_SUITE_WEP40:
155         case WLAN_CIPHER_SUITE_WEP104:
156                 result = prism2_domibset_uint32(wlandev,
157                                                 DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID,
158                                                 key_index);
159                 if (result)
160                         goto exit;
161
162                 /* send key to driver */
163                 switch (key_index) {
164                 case 0:
165                         did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey0;
166                         break;
167
168                 case 1:
169                         did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey1;
170                         break;
171
172                 case 2:
173                         did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey2;
174                         break;
175
176                 case 3:
177                         did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey3;
178                         break;
179
180                 default:
181                         err = -EINVAL;
182                         goto exit;
183                 }
184
185                 result = prism2_domibset_pstr32(wlandev, did, params->key_len, params->key);
186                 if (result)
187                         goto exit;
188                 break;
189
190         default:
191                 pr_debug("Unsupported cipher suite\n");
192                 result = 1;
193         }
194
195 exit:
196         if (result)
197                 err = -EFAULT;
198
199         return err;
200 }
201
202 static int prism2_get_key(struct wiphy *wiphy, struct net_device *dev,
203                           u8 key_index, bool pairwise,
204                           const u8 *mac_addr, void *cookie,
205                           void (*callback)(void *cookie, struct key_params*))
206 {
207         wlandevice_t *wlandev = dev->ml_priv;
208         struct key_params params;
209         int len;
210
211         if (key_index >= NUM_WEPKEYS)
212                 return -EINVAL;
213
214         len = wlandev->wep_keylens[key_index];
215         memset(&params, 0, sizeof(params));
216
217         if (len == 13)
218                 params.cipher = WLAN_CIPHER_SUITE_WEP104;
219         else if (len == 5)
220                 params.cipher = WLAN_CIPHER_SUITE_WEP104;
221         else
222                 return -ENOENT;
223         params.key_len = len;
224         params.key = wlandev->wep_keys[key_index];
225         params.seq_len = 0;
226
227         callback(cookie, &params);
228
229         return 0;
230 }
231
232 static int prism2_del_key(struct wiphy *wiphy, struct net_device *dev,
233                           u8 key_index, bool pairwise, const u8 *mac_addr)
234 {
235         wlandevice_t *wlandev = dev->ml_priv;
236         u32 did;
237         int err = 0;
238         int result = 0;
239
240         /* There is no direct way in the hardware (AFAIK) of removing
241            a key, so we will cheat by setting the key to a bogus value */
242         /* send key to driver */
243         switch (key_index) {
244         case 0:
245                 did =
246                     DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey0;
247                 break;
248
249         case 1:
250                 did =
251                     DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey1;
252                 break;
253
254         case 2:
255                 did =
256                     DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey2;
257                 break;
258
259         case 3:
260                 did =
261                     DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey3;
262                 break;
263
264         default:
265                 err = -EINVAL;
266                 goto exit;
267         }
268
269         result = prism2_domibset_pstr32(wlandev, did, 13, "0000000000000");
270
271 exit:
272         if (result)
273                 err = -EFAULT;
274
275         return err;
276 }
277
278 static int prism2_set_default_key(struct wiphy *wiphy, struct net_device *dev,
279                                   u8 key_index, bool unicast, bool multicast)
280 {
281         wlandevice_t *wlandev = dev->ml_priv;
282
283         int err = 0;
284         int result = 0;
285
286         result = prism2_domibset_uint32(wlandev,
287                 DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID,
288                 key_index);
289
290         if (result)
291                 err = -EFAULT;
292
293         return err;
294 }
295
296
297 static int prism2_get_station(struct wiphy *wiphy, struct net_device *dev,
298                               u8 *mac, struct station_info *sinfo)
299 {
300         wlandevice_t *wlandev = dev->ml_priv;
301         struct p80211msg_lnxreq_commsquality quality;
302         int result;
303
304         memset(sinfo, 0, sizeof(*sinfo));
305
306         if ((wlandev == NULL) || (wlandev->msdstate != WLAN_MSD_RUNNING))
307                 return -EOPNOTSUPP;
308
309         /* build request message */
310         quality.msgcode = DIDmsg_lnxreq_commsquality;
311         quality.dbm.data = P80211ENUM_truth_true;
312         quality.dbm.status = P80211ENUM_msgitem_status_data_ok;
313
314         /* send message to nsd */
315         if (wlandev->mlmerequest == NULL)
316                 return -EOPNOTSUPP;
317
318         result = wlandev->mlmerequest(wlandev, (struct p80211msg *) &quality);
319
320
321         if (result == 0) {
322                 sinfo->txrate.legacy = quality.txrate.data;
323                 sinfo->filled |= STATION_INFO_TX_BITRATE;
324                 sinfo->signal = quality.level.data;
325                 sinfo->filled |= STATION_INFO_SIGNAL;
326         }
327
328         return result;
329 }
330
331 static int prism2_scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
332 {
333         struct net_device *dev;
334         struct prism2_wiphy_private *priv = wiphy_priv(wiphy);
335         wlandevice_t *wlandev;
336         struct p80211msg_dot11req_scan msg1;
337         struct p80211msg_dot11req_scan_results msg2;
338         struct cfg80211_bss *bss;
339         int result;
340         int err = 0;
341         int numbss = 0;
342         int i = 0;
343         u8 ie_buf[46];
344         int ie_len;
345
346         if (!request)
347                 return -EINVAL;
348
349         dev = request->wdev->netdev;
350         wlandev = dev->ml_priv;
351
352         if (priv->scan_request && priv->scan_request != request)
353                 return -EBUSY;
354
355         if (wlandev->macmode == WLAN_MACMODE_ESS_AP) {
356                 netdev_err(dev, "Can't scan in AP mode\n");
357                 return -EOPNOTSUPP;
358         }
359
360         priv->scan_request = request;
361
362         memset(&msg1, 0x00, sizeof(struct p80211msg_dot11req_scan));
363         msg1.msgcode = DIDmsg_dot11req_scan;
364         msg1.bsstype.data = P80211ENUM_bsstype_any;
365
366         memset(&msg1.bssid.data.data, 0xFF, sizeof(msg1.bssid.data.data));
367         msg1.bssid.data.len = 6;
368
369         if (request->n_ssids > 0) {
370                 msg1.scantype.data = P80211ENUM_scantype_active;
371                 msg1.ssid.data.len = request->ssids->ssid_len;
372                 memcpy(msg1.ssid.data.data,
373                         request->ssids->ssid, request->ssids->ssid_len);
374         } else {
375                 msg1.scantype.data = 0;
376         }
377         msg1.probedelay.data = 0;
378
379         for (i = 0;
380                 (i < request->n_channels) && i < ARRAY_SIZE(prism2_channels);
381                 i++)
382                 msg1.channellist.data.data[i] =
383                         ieee80211_frequency_to_channel(request->channels[i]->center_freq);
384         msg1.channellist.data.len = request->n_channels;
385
386         msg1.maxchanneltime.data = 250;
387         msg1.minchanneltime.data = 200;
388
389         result = p80211req_dorequest(wlandev, (u8 *) &msg1);
390         if (result) {
391                 err = prism2_result2err(msg1.resultcode.data);
392                 goto exit;
393         }
394         /* Now retrieve scan results */
395         numbss = msg1.numbss.data;
396
397         for (i = 0; i < numbss; i++) {
398                 memset(&msg2, 0, sizeof(msg2));
399                 msg2.msgcode = DIDmsg_dot11req_scan_results;
400                 msg2.bssindex.data = i;
401
402                 result = p80211req_dorequest(wlandev, (u8 *) &msg2);
403                 if ((result != 0) ||
404                     (msg2.resultcode.data != P80211ENUM_resultcode_success)) {
405                         break;
406                 }
407
408                 ie_buf[0] = WLAN_EID_SSID;
409                 ie_buf[1] = msg2.ssid.data.len;
410                 ie_len = ie_buf[1] + 2;
411                 memcpy(&ie_buf[2], &(msg2.ssid.data.data), msg2.ssid.data.len);
412                 bss = cfg80211_inform_bss(wiphy,
413                         ieee80211_get_channel(wiphy, ieee80211_dsss_chan_to_freq(msg2.dschannel.data)),
414                         (const u8 *) &(msg2.bssid.data.data),
415                         msg2.timestamp.data, msg2.capinfo.data,
416                         msg2.beaconperiod.data,
417                         ie_buf,
418                         ie_len,
419                         (msg2.signal.data - 65536) * 100, /* Conversion to signed type */
420                         GFP_KERNEL
421                 );
422
423                 if (!bss) {
424                         err = -ENOMEM;
425                         goto exit;
426                 }
427
428                 cfg80211_put_bss(wiphy, bss);
429         }
430
431         if (result)
432                 err = prism2_result2err(msg2.resultcode.data);
433
434 exit:
435         cfg80211_scan_done(request, err ? 1 : 0);
436         priv->scan_request = NULL;
437         return err;
438 }
439
440 static int prism2_set_wiphy_params(struct wiphy *wiphy, u32 changed)
441 {
442         struct prism2_wiphy_private *priv = wiphy_priv(wiphy);
443         wlandevice_t *wlandev = priv->wlandev;
444         u32 data;
445         int result;
446         int err = 0;
447
448         if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
449                 if (wiphy->rts_threshold == -1)
450                         data = 2347;
451                 else
452                         data = wiphy->rts_threshold;
453
454                 result = prism2_domibset_uint32(wlandev,
455                                                 DIDmib_dot11mac_dot11OperationTable_dot11RTSThreshold,
456                                                 data);
457                 if (result) {
458                         err = -EFAULT;
459                         goto exit;
460                 }
461         }
462
463         if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
464                 if (wiphy->frag_threshold == -1)
465                         data = 2346;
466                 else
467                         data = wiphy->frag_threshold;
468
469                 result = prism2_domibset_uint32(wlandev,
470                                                 DIDmib_dot11mac_dot11OperationTable_dot11FragmentationThreshold,
471                                                 data);
472                 if (result) {
473                         err = -EFAULT;
474                         goto exit;
475                 }
476         }
477
478 exit:
479         return err;
480 }
481
482 static int prism2_connect(struct wiphy *wiphy, struct net_device *dev,
483                           struct cfg80211_connect_params *sme)
484 {
485         wlandevice_t *wlandev = dev->ml_priv;
486         struct ieee80211_channel *channel = sme->channel;
487         struct p80211msg_lnxreq_autojoin msg_join;
488         u32 did;
489         int length = sme->ssid_len;
490         int chan = -1;
491         int is_wep = (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP40) ||
492             (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP104);
493         int result;
494         int err = 0;
495
496         /* Set the channel */
497         if (channel) {
498                 chan = ieee80211_frequency_to_channel(channel->center_freq);
499                 result = prism2_domibset_uint32(wlandev,
500                                                 DIDmib_dot11phy_dot11PhyDSSSTable_dot11CurrentChannel,
501                                                 chan);
502                 if (result)
503                         goto exit;
504         }
505
506         /* Set the authorization */
507         if ((sme->auth_type == NL80211_AUTHTYPE_OPEN_SYSTEM) ||
508                 ((sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) && !is_wep))
509                         msg_join.authtype.data = P80211ENUM_authalg_opensystem;
510         else if ((sme->auth_type == NL80211_AUTHTYPE_SHARED_KEY) ||
511                 ((sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) && is_wep))
512                         msg_join.authtype.data = P80211ENUM_authalg_sharedkey;
513         else
514                 netdev_warn(dev,
515                         "Unhandled authorisation type for connect (%d)\n",
516                         sme->auth_type);
517
518         /* Set the encryption - we only support wep */
519         if (is_wep) {
520                 if (sme->key) {
521                         result = prism2_domibset_uint32(wlandev,
522                                 DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID,
523                                 sme->key_idx);
524                         if (result)
525                                 goto exit;
526
527                         /* send key to driver */
528                         switch (sme->key_idx) {
529                         case 0:
530                                 did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey0;
531                                 break;
532
533                         case 1:
534                                 did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey1;
535                                 break;
536
537                         case 2:
538                                 did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey2;
539                                 break;
540
541                         case 3:
542                                 did = DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey3;
543                                 break;
544
545                         default:
546                                 err = -EINVAL;
547                                 goto exit;
548                         }
549
550                         result = prism2_domibset_pstr32(wlandev,
551                                                         did, sme->key_len,
552                                                         (u8 *)sme->key);
553                         if (result)
554                                 goto exit;
555
556                 }
557
558                 /* Assume we should set privacy invoked and exclude unencrypted
559                    We could possibly use sme->privacy here, but the assumption
560                    seems reasonable anyway */
561                 result = prism2_domibset_uint32(wlandev,
562                                                 DIDmib_dot11smt_dot11PrivacyTable_dot11PrivacyInvoked,
563                                                 P80211ENUM_truth_true);
564                 if (result)
565                         goto exit;
566
567                 result = prism2_domibset_uint32(wlandev,
568                                                 DIDmib_dot11smt_dot11PrivacyTable_dot11ExcludeUnencrypted,
569                                                 P80211ENUM_truth_true);
570                 if (result)
571                         goto exit;
572
573         } else {
574                 /* Assume we should unset privacy invoked
575                    and exclude unencrypted */
576                 result = prism2_domibset_uint32(wlandev,
577                                                 DIDmib_dot11smt_dot11PrivacyTable_dot11PrivacyInvoked,
578                                                 P80211ENUM_truth_false);
579                 if (result)
580                         goto exit;
581
582                 result = prism2_domibset_uint32(wlandev,
583                                                 DIDmib_dot11smt_dot11PrivacyTable_dot11ExcludeUnencrypted,
584                                                 P80211ENUM_truth_false);
585                 if (result)
586                         goto exit;
587
588         }
589
590         /* Now do the actual join. Note there is no way that I can
591            see to request a specific bssid */
592         msg_join.msgcode = DIDmsg_lnxreq_autojoin;
593
594         memcpy(msg_join.ssid.data.data, sme->ssid, length);
595         msg_join.ssid.data.len = length;
596
597         result = p80211req_dorequest(wlandev, (u8 *) &msg_join);
598
599 exit:
600         if (result)
601                 err = -EFAULT;
602
603         return err;
604 }
605
606 static int prism2_disconnect(struct wiphy *wiphy, struct net_device *dev,
607                              u16 reason_code)
608 {
609         wlandevice_t *wlandev = dev->ml_priv;
610         struct p80211msg_lnxreq_autojoin msg_join;
611         int result;
612         int err = 0;
613
614
615         /* Do a join, with a bogus ssid. Thats the only way I can think of */
616         msg_join.msgcode = DIDmsg_lnxreq_autojoin;
617
618         memcpy(msg_join.ssid.data.data, "---", 3);
619         msg_join.ssid.data.len = 3;
620
621         result = p80211req_dorequest(wlandev, (u8 *) &msg_join);
622
623         if (result)
624                 err = -EFAULT;
625
626         return err;
627 }
628
629
630 static int prism2_join_ibss(struct wiphy *wiphy, struct net_device *dev,
631                             struct cfg80211_ibss_params *params)
632 {
633         return -EOPNOTSUPP;
634 }
635
636 static int prism2_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
637 {
638         return -EOPNOTSUPP;
639 }
640
641
642 static int prism2_set_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
643                                enum nl80211_tx_power_setting type, int mbm)
644 {
645         struct prism2_wiphy_private *priv = wiphy_priv(wiphy);
646         wlandevice_t *wlandev = priv->wlandev;
647         u32 data;
648         int result;
649         int err = 0;
650
651         if (type == NL80211_TX_POWER_AUTOMATIC)
652                 data = 30;
653         else
654                 data = MBM_TO_DBM(mbm);
655
656         result = prism2_domibset_uint32(wlandev,
657                 DIDmib_dot11phy_dot11PhyTxPowerTable_dot11CurrentTxPowerLevel,
658                 data);
659
660         if (result) {
661                 err = -EFAULT;
662                 goto exit;
663         }
664
665 exit:
666         return err;
667 }
668
669 static int prism2_get_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
670                                int *dbm)
671 {
672         struct prism2_wiphy_private *priv = wiphy_priv(wiphy);
673         wlandevice_t *wlandev = priv->wlandev;
674         struct p80211msg_dot11req_mibget msg;
675         p80211item_uint32_t *mibitem;
676         int result;
677         int err = 0;
678
679         mibitem = (p80211item_uint32_t *) &msg.mibattribute.data;
680         msg.msgcode = DIDmsg_dot11req_mibget;
681         mibitem->did =
682             DIDmib_dot11phy_dot11PhyTxPowerTable_dot11CurrentTxPowerLevel;
683
684         result = p80211req_dorequest(wlandev, (u8 *) &msg);
685
686         if (result) {
687                 err = -EFAULT;
688                 goto exit;
689         }
690
691         *dbm = mibitem->data;
692
693 exit:
694         return err;
695 }
696
697
698
699
700 /* Interface callback functions, passing data back up to the cfg80211 layer */
701 void prism2_connect_result(wlandevice_t *wlandev, u8 failed)
702 {
703         u16 status = failed ?
704                      WLAN_STATUS_UNSPECIFIED_FAILURE : WLAN_STATUS_SUCCESS;
705
706         cfg80211_connect_result(wlandev->netdev, wlandev->bssid,
707                                 NULL, 0, NULL, 0, status, GFP_KERNEL);
708 }
709
710 void prism2_disconnected(wlandevice_t *wlandev)
711 {
712         cfg80211_disconnected(wlandev->netdev, 0, NULL,
713                 0, GFP_KERNEL);
714 }
715
716 void prism2_roamed(wlandevice_t *wlandev)
717 {
718         cfg80211_roamed(wlandev->netdev, NULL, wlandev->bssid,
719                 NULL, 0, NULL, 0, GFP_KERNEL);
720 }
721
722
723 /* Structures for declaring wiphy interface */
724 static const struct cfg80211_ops prism2_usb_cfg_ops = {
725         .change_virtual_intf = prism2_change_virtual_intf,
726         .add_key = prism2_add_key,
727         .get_key = prism2_get_key,
728         .del_key = prism2_del_key,
729         .set_default_key = prism2_set_default_key,
730         .get_station = prism2_get_station,
731         .scan = prism2_scan,
732         .set_wiphy_params = prism2_set_wiphy_params,
733         .connect = prism2_connect,
734         .disconnect = prism2_disconnect,
735         .join_ibss = prism2_join_ibss,
736         .leave_ibss = prism2_leave_ibss,
737         .set_tx_power = prism2_set_tx_power,
738         .get_tx_power = prism2_get_tx_power,
739 };
740
741
742 /* Functions to create/free wiphy interface */
743 struct wiphy *wlan_create_wiphy(struct device *dev, wlandevice_t *wlandev)
744 {
745         struct wiphy *wiphy;
746         struct prism2_wiphy_private *priv;
747
748         wiphy = wiphy_new(&prism2_usb_cfg_ops, sizeof(*priv));
749         if (!wiphy)
750                 return NULL;
751
752         priv = wiphy_priv(wiphy);
753         priv->wlandev = wlandev;
754         memcpy(priv->channels, prism2_channels, sizeof(prism2_channels));
755         memcpy(priv->rates, prism2_rates, sizeof(prism2_rates));
756         priv->band.channels = priv->channels;
757         priv->band.n_channels = ARRAY_SIZE(prism2_channels);
758         priv->band.bitrates = priv->rates;
759         priv->band.n_bitrates = ARRAY_SIZE(prism2_rates);
760         priv->band.band = IEEE80211_BAND_2GHZ;
761         priv->band.ht_cap.ht_supported = false;
762         wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
763
764         set_wiphy_dev(wiphy, dev);
765         wiphy->privid = prism2_wiphy_privid;
766         wiphy->max_scan_ssids = 1;
767         wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION)
768                                  | BIT(NL80211_IFTYPE_ADHOC);
769         wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
770         wiphy->n_cipher_suites = PRISM2_NUM_CIPHER_SUITES;
771         wiphy->cipher_suites = prism2_cipher_suites;
772
773         if (wiphy_register(wiphy) < 0)
774                 return NULL;
775
776         return wiphy;
777 }
778
779
780 void wlan_free_wiphy(struct wiphy *wiphy)
781 {
782         wiphy_unregister(wiphy);
783         wiphy_free(wiphy);
784 }