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