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