1 // SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1)
2 /* src/prism2/driver/prism2mib.c
3  *
4  * Management request for mibset/mibget
5  *
6  * Copyright (C) 1999 AbsoluteValue Systems, Inc.  All Rights Reserved.
7  * --------------------------------------------------------------------
8  *
9  * linux-wlan
10  *
11  *   The contents of this file are subject to the Mozilla Public
12  *   License Version 1.1 (the "License"); you may not use this file
13  *   except in compliance with the License. You may obtain a copy of
14  *   the License at http://www.mozilla.org/MPL/
15  *
16  *   Software distributed under the License is distributed on an "AS
17  *   IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
18  *   implied. See the License for the specific language governing
19  *   rights and limitations under the License.
20  *
21  *   Alternatively, the contents of this file may be used under the
22  *   terms of the GNU Public License version 2 (the "GPL"), in which
23  *   case the provisions of the GPL are applicable instead of the
24  *   above.  If you wish to allow the use of your version of this file
25  *   only under the terms of the GPL and not to allow others to use
26  *   your version of this file under the MPL, indicate your decision
27  *   by deleting the provisions above and replace them with the notice
28  *   and other provisions required by the GPL.  If you do not delete
29  *   the provisions above, a recipient may use your version of this
30  *   file under either the MPL or the GPL.
31  *
32  * --------------------------------------------------------------------
33  *
34  * Inquiries regarding the linux-wlan Open Source project can be
35  * made directly to:
36  *
37  * AbsoluteValue Systems Inc.
38  * info@linux-wlan.com
39  * http://www.linux-wlan.com
40  *
41  * --------------------------------------------------------------------
42  *
43  * Portions of the development of this software were funded by
44  * Intersil Corporation as part of PRISM(R) chipset product development.
45  *
46  * --------------------------------------------------------------------
47  *
48  * The functions in this file handle the mibset/mibget management
49  * functions.
50  *
51  * --------------------------------------------------------------------
52  */
53 
54 #include <linux/module.h>
55 #include <linux/kernel.h>
56 #include <linux/sched.h>
57 #include <linux/types.h>
58 #include <linux/wireless.h>
59 #include <linux/netdevice.h>
60 #include <linux/io.h>
61 #include <linux/delay.h>
62 #include <asm/byteorder.h>
63 #include <linux/usb.h>
64 #include <linux/bitops.h>
65 
66 #include "p80211types.h"
67 #include "p80211hdr.h"
68 #include "p80211mgmt.h"
69 #include "p80211conv.h"
70 #include "p80211msg.h"
71 #include "p80211netdev.h"
72 #include "p80211metadef.h"
73 #include "p80211metastruct.h"
74 #include "hfa384x.h"
75 #include "prism2mgmt.h"
76 
77 #define MIB_TMP_MAXLEN    200	/* Max length of RID record (in bytes). */
78 
79 #define  F_STA        0x1	/* MIB is supported on stations. */
80 #define  F_READ       0x2	/* MIB may be read. */
81 #define  F_WRITE      0x4	/* MIB may be written. */
82 
83 struct mibrec {
84 	u32 did;
85 	u16 flag;
86 	u16 parm1;
87 	u16 parm2;
88 	u16 parm3;
89 	int (*func)(struct mibrec *mib,
90 		    int isget,
91 		    struct wlandevice *wlandev,
92 		    struct hfa384x *hw,
93 		    struct p80211msg_dot11req_mibset *msg, void *data);
94 };
95 
96 static int prism2mib_bytearea2pstr(struct mibrec *mib,
97 				   int isget,
98 				   struct wlandevice *wlandev,
99 				   struct hfa384x *hw,
100 				   struct p80211msg_dot11req_mibset *msg,
101 				   void *data);
102 
103 static int prism2mib_uint32(struct mibrec *mib,
104 			    int isget,
105 			    struct wlandevice *wlandev,
106 			    struct hfa384x *hw,
107 			    struct p80211msg_dot11req_mibset *msg, void *data);
108 
109 static int prism2mib_flag(struct mibrec *mib,
110 			  int isget,
111 			  struct wlandevice *wlandev,
112 			  struct hfa384x *hw,
113 			  struct p80211msg_dot11req_mibset *msg, void *data);
114 
115 static int prism2mib_wepdefaultkey(struct mibrec *mib,
116 				   int isget,
117 				   struct wlandevice *wlandev,
118 				   struct hfa384x *hw,
119 				   struct p80211msg_dot11req_mibset *msg,
120 				   void *data);
121 
122 static int prism2mib_privacyinvoked(struct mibrec *mib,
123 				    int isget,
124 				    struct wlandevice *wlandev,
125 				    struct hfa384x *hw,
126 				    struct p80211msg_dot11req_mibset *msg,
127 				    void *data);
128 
129 static int prism2mib_excludeunencrypted(struct mibrec *mib,
130 					int isget,
131 					struct wlandevice *wlandev,
132 					struct hfa384x *hw,
133 					struct p80211msg_dot11req_mibset *msg,
134 					void *data);
135 
136 static int
137 prism2mib_fragmentationthreshold(struct mibrec *mib,
138 				 int isget,
139 				 struct wlandevice *wlandev,
140 				 struct hfa384x *hw,
141 				 struct p80211msg_dot11req_mibset *msg,
142 				 void *data);
143 
144 static int prism2mib_priv(struct mibrec *mib,
145 			  int isget,
146 			  struct wlandevice *wlandev,
147 			  struct hfa384x *hw,
148 			  struct p80211msg_dot11req_mibset *msg, void *data);
149 
150 static struct mibrec mibtab[] = {
151 	/* dot11smt MIB's */
152 	{didmib_dot11smt_wepdefaultkeystable_key(1),
153 	 F_STA | F_WRITE,
154 	 HFA384x_RID_CNFWEPDEFAULTKEY0, 0, 0,
155 	 prism2mib_wepdefaultkey},
156 	{didmib_dot11smt_wepdefaultkeystable_key(2),
157 	 F_STA | F_WRITE,
158 	 HFA384x_RID_CNFWEPDEFAULTKEY1, 0, 0,
159 	 prism2mib_wepdefaultkey},
160 	{didmib_dot11smt_wepdefaultkeystable_key(3),
161 	 F_STA | F_WRITE,
162 	 HFA384x_RID_CNFWEPDEFAULTKEY2, 0, 0,
163 	 prism2mib_wepdefaultkey},
164 	{didmib_dot11smt_wepdefaultkeystable_key(4),
165 	 F_STA | F_WRITE,
166 	 HFA384x_RID_CNFWEPDEFAULTKEY3, 0, 0,
167 	 prism2mib_wepdefaultkey},
168 	{DIDMIB_DOT11SMT_PRIVACYTABLE_PRIVACYINVOKED,
169 	 F_STA | F_READ | F_WRITE,
170 	 HFA384x_RID_CNFWEPFLAGS, HFA384x_WEPFLAGS_PRIVINVOKED, 0,
171 	 prism2mib_privacyinvoked},
172 	{DIDMIB_DOT11SMT_PRIVACYTABLE_WEPDEFAULTKEYID,
173 	 F_STA | F_READ | F_WRITE,
174 	 HFA384x_RID_CNFWEPDEFAULTKEYID, 0, 0,
175 	 prism2mib_uint32},
176 	{DIDMIB_DOT11SMT_PRIVACYTABLE_EXCLUDEUNENCRYPTED,
177 	 F_STA | F_READ | F_WRITE,
178 	 HFA384x_RID_CNFWEPFLAGS, HFA384x_WEPFLAGS_EXCLUDE, 0,
179 	 prism2mib_excludeunencrypted},
180 
181 	/* dot11mac MIB's */
182 
183 	{DIDMIB_DOT11MAC_OPERATIONTABLE_MACADDRESS,
184 	 F_STA | F_READ | F_WRITE,
185 	 HFA384x_RID_CNFOWNMACADDR, HFA384x_RID_CNFOWNMACADDR_LEN, 0,
186 	 prism2mib_bytearea2pstr},
187 	{DIDMIB_DOT11MAC_OPERATIONTABLE_RTSTHRESHOLD,
188 	 F_STA | F_READ | F_WRITE,
189 	 HFA384x_RID_RTSTHRESH, 0, 0,
190 	 prism2mib_uint32},
191 	{DIDMIB_DOT11MAC_OPERATIONTABLE_SHORTRETRYLIMIT,
192 	 F_STA | F_READ,
193 	 HFA384x_RID_SHORTRETRYLIMIT, 0, 0,
194 	 prism2mib_uint32},
195 	{DIDMIB_DOT11MAC_OPERATIONTABLE_LONGRETRYLIMIT,
196 	 F_STA | F_READ,
197 	 HFA384x_RID_LONGRETRYLIMIT, 0, 0,
198 	 prism2mib_uint32},
199 	{DIDMIB_DOT11MAC_OPERATIONTABLE_FRAGMENTATIONTHRESHOLD,
200 	 F_STA | F_READ | F_WRITE,
201 	 HFA384x_RID_FRAGTHRESH, 0, 0,
202 	 prism2mib_fragmentationthreshold},
203 	{DIDMIB_DOT11MAC_OPERATIONTABLE_MAXTRANSMITMSDULIFETIME,
204 	 F_STA | F_READ,
205 	 HFA384x_RID_MAXTXLIFETIME, 0, 0,
206 	 prism2mib_uint32},
207 
208 	/* dot11phy MIB's */
209 
210 	{DIDMIB_DOT11PHY_DSSSTABLE_CURRENTCHANNEL,
211 	 F_STA | F_READ,
212 	 HFA384x_RID_CURRENTCHANNEL, 0, 0,
213 	 prism2mib_uint32},
214 	{DIDMIB_DOT11PHY_TXPOWERTABLE_CURRENTTXPOWERLEVEL,
215 	 F_STA | F_READ | F_WRITE,
216 	 HFA384x_RID_TXPOWERMAX, 0, 0,
217 	 prism2mib_uint32},
218 
219 	/* p2Static MIB's */
220 
221 	{DIDMIB_P2_STATIC_CNFPORTTYPE,
222 	 F_STA | F_READ | F_WRITE,
223 	 HFA384x_RID_CNFPORTTYPE, 0, 0,
224 	 prism2mib_uint32},
225 
226 	/* p2MAC MIB's */
227 
228 	{DIDMIB_P2_MAC_CURRENTTXRATE,
229 	 F_STA | F_READ,
230 	 HFA384x_RID_CURRENTTXRATE, 0, 0,
231 	 prism2mib_uint32},
232 
233 	/* And finally, lnx mibs */
234 	{DIDMIB_LNX_CONFIGTABLE_RSNAIE,
235 	 F_STA | F_READ | F_WRITE,
236 	 HFA384x_RID_CNFWPADATA, 0, 0,
237 	 prism2mib_priv},
238 	{0, 0, 0, 0, 0, NULL}
239 };
240 
241 /*
242  * prism2mgmt_mibset_mibget
243  *
244  * Set the value of a mib item.
245  *
246  * Arguments:
247  *	wlandev		wlan device structure
248  *	msgp		ptr to msg buffer
249  *
250  * Returns:
251  *	0	success and done
252  *	<0	success, but we're waiting for something to finish.
253  *	>0	an error occurred while handling the message.
254  * Side effects:
255  *
256  * Call context:
257  *	process thread  (usually)
258  *	interrupt
259  */
260 
261 int prism2mgmt_mibset_mibget(struct wlandevice *wlandev, void *msgp)
262 {
263 	struct hfa384x *hw = wlandev->priv;
264 	int result, isget;
265 	struct mibrec *mib;
266 
267 	u16 which;
268 
269 	struct p80211msg_dot11req_mibset *msg = msgp;
270 	struct p80211itemd *mibitem;
271 
272 	msg->resultcode.status = P80211ENUM_msgitem_status_data_ok;
273 	msg->resultcode.data = P80211ENUM_resultcode_success;
274 
275 	/*
276 	 ** Determine if this is an Access Point or a station.
277 	 */
278 
279 	which = F_STA;
280 
281 	/*
282 	 ** Find the MIB in the MIB table.  Note that a MIB may be in the
283 	 ** table twice...once for an AP and once for a station.  Make sure
284 	 ** to get the correct one.  Note that DID=0 marks the end of the
285 	 ** MIB table.
286 	 */
287 
288 	mibitem = (struct p80211itemd *)msg->mibattribute.data;
289 
290 	for (mib = mibtab; mib->did != 0; mib++)
291 		if (mib->did == mibitem->did && (mib->flag & which))
292 			break;
293 
294 	if (mib->did == 0) {
295 		msg->resultcode.data = P80211ENUM_resultcode_not_supported;
296 		goto done;
297 	}
298 
299 	/*
300 	 ** Determine if this is a "mibget" or a "mibset".  If this is a
301 	 ** "mibget", then make sure that the MIB may be read.  Otherwise,
302 	 ** this is a "mibset" so make make sure that the MIB may be written.
303 	 */
304 
305 	isget = (msg->msgcode == DIDMSG_DOT11REQ_MIBGET);
306 
307 	if (isget) {
308 		if (!(mib->flag & F_READ)) {
309 			msg->resultcode.data =
310 			    P80211ENUM_resultcode_cant_get_writeonly_mib;
311 			goto done;
312 		}
313 	} else {
314 		if (!(mib->flag & F_WRITE)) {
315 			msg->resultcode.data =
316 			    P80211ENUM_resultcode_cant_set_readonly_mib;
317 			goto done;
318 		}
319 	}
320 
321 	/*
322 	 ** Execute the MIB function.  If things worked okay, then make
323 	 ** sure that the MIB function also worked okay.  If so, and this
324 	 ** is a "mibget", then the status value must be set for both the
325 	 ** "mibattribute" parameter and the mib item within the data
326 	 ** portion of the "mibattribute".
327 	 */
328 
329 	result = mib->func(mib, isget, wlandev, hw, msg, (void *)mibitem->data);
330 
331 	if (msg->resultcode.data == P80211ENUM_resultcode_success) {
332 		if (result != 0) {
333 			pr_debug("get/set failure, result=%d\n", result);
334 			msg->resultcode.data =
335 			    P80211ENUM_resultcode_implementation_failure;
336 		} else {
337 			if (isget) {
338 				msg->mibattribute.status =
339 				    P80211ENUM_msgitem_status_data_ok;
340 				mibitem->status =
341 				    P80211ENUM_msgitem_status_data_ok;
342 			}
343 		}
344 	}
345 
346 done:
347 	return 0;
348 }
349 
350 /*
351  * prism2mib_bytearea2pstr
352  *
353  * Get/set pstr data to/from a byte area.
354  *
355  * MIB record parameters:
356  *       parm1    Prism2 RID value.
357  *       parm2    Number of bytes of RID data.
358  *       parm3    Not used.
359  *
360  * Arguments:
361  *       mib      MIB record.
362  *       isget    MIBGET/MIBSET flag.
363  *       wlandev  wlan device structure.
364  *       priv     "priv" structure.
365  *       hw       "hw" structure.
366  *       msg      Message structure.
367  *       data     Data buffer.
368  *
369  * Returns:
370  *       0   - Success.
371  *       ~0  - Error.
372  *
373  */
374 
375 static int prism2mib_bytearea2pstr(struct mibrec *mib,
376 				   int isget,
377 				   struct wlandevice *wlandev,
378 				   struct hfa384x *hw,
379 				   struct p80211msg_dot11req_mibset *msg,
380 				   void *data)
381 {
382 	int result;
383 	struct p80211pstrd *pstr = data;
384 	u8 bytebuf[MIB_TMP_MAXLEN];
385 
386 	if (isget) {
387 		result =
388 		    hfa384x_drvr_getconfig(hw, mib->parm1, bytebuf, mib->parm2);
389 		prism2mgmt_bytearea2pstr(bytebuf, pstr, mib->parm2);
390 	} else {
391 		memset(bytebuf, 0, mib->parm2);
392 		memcpy(bytebuf, pstr->data, pstr->len);
393 		result =
394 		    hfa384x_drvr_setconfig(hw, mib->parm1, bytebuf, mib->parm2);
395 	}
396 
397 	return result;
398 }
399 
400 /*
401  * prism2mib_uint32
402  *
403  * Get/set uint32 data.
404  *
405  * MIB record parameters:
406  *       parm1    Prism2 RID value.
407  *       parm2    Not used.
408  *       parm3    Not used.
409  *
410  * Arguments:
411  *       mib      MIB record.
412  *       isget    MIBGET/MIBSET flag.
413  *       wlandev  wlan device structure.
414  *       priv     "priv" structure.
415  *       hw       "hw" structure.
416  *       msg      Message structure.
417  *       data     Data buffer.
418  *
419  * Returns:
420  *       0   - Success.
421  *       ~0  - Error.
422  *
423  */
424 
425 static int prism2mib_uint32(struct mibrec *mib,
426 			    int isget,
427 			    struct wlandevice *wlandev,
428 			    struct hfa384x *hw,
429 			    struct p80211msg_dot11req_mibset *msg, void *data)
430 {
431 	int result;
432 	u32 *uint32 = data;
433 	u8 bytebuf[MIB_TMP_MAXLEN];
434 	u16 *wordbuf = (u16 *)bytebuf;
435 
436 	if (isget) {
437 		result = hfa384x_drvr_getconfig16(hw, mib->parm1, wordbuf);
438 		*uint32 = *wordbuf;
439 	} else {
440 		*wordbuf = *uint32;
441 		result = hfa384x_drvr_setconfig16(hw, mib->parm1, *wordbuf);
442 	}
443 
444 	return result;
445 }
446 
447 /*
448  * prism2mib_flag
449  *
450  * Get/set a flag.
451  *
452  * MIB record parameters:
453  *       parm1    Prism2 RID value.
454  *       parm2    Bit to get/set.
455  *       parm3    Not used.
456  *
457  * Arguments:
458  *       mib      MIB record.
459  *       isget    MIBGET/MIBSET flag.
460  *       wlandev  wlan device structure.
461  *       priv     "priv" structure.
462  *       hw       "hw" structure.
463  *       msg      Message structure.
464  *       data     Data buffer.
465  *
466  * Returns:
467  *       0   - Success.
468  *       ~0  - Error.
469  *
470  */
471 
472 static int prism2mib_flag(struct mibrec *mib,
473 			  int isget,
474 			  struct wlandevice *wlandev,
475 			  struct hfa384x *hw,
476 			  struct p80211msg_dot11req_mibset *msg, void *data)
477 {
478 	int result;
479 	u32 *uint32 = data;
480 	u8 bytebuf[MIB_TMP_MAXLEN];
481 	u16 *wordbuf = (u16 *)bytebuf;
482 	u32 flags;
483 
484 	result = hfa384x_drvr_getconfig16(hw, mib->parm1, wordbuf);
485 	if (result == 0) {
486 		flags = *wordbuf;
487 		if (isget) {
488 			*uint32 = (flags & mib->parm2) ?
489 			    P80211ENUM_truth_true : P80211ENUM_truth_false;
490 		} else {
491 			if ((*uint32) == P80211ENUM_truth_true)
492 				flags |= mib->parm2;
493 			else
494 				flags &= ~mib->parm2;
495 			*wordbuf = flags;
496 			result =
497 			    hfa384x_drvr_setconfig16(hw, mib->parm1, *wordbuf);
498 		}
499 	}
500 
501 	return result;
502 }
503 
504 /*
505  * prism2mib_wepdefaultkey
506  *
507  * Get/set WEP default keys.
508  *
509  * MIB record parameters:
510  *       parm1    Prism2 RID value.
511  *       parm2    Number of bytes of RID data.
512  *       parm3    Not used.
513  *
514  * Arguments:
515  *       mib      MIB record.
516  *       isget    MIBGET/MIBSET flag.
517  *       wlandev  wlan device structure.
518  *       priv     "priv" structure.
519  *       hw       "hw" structure.
520  *       msg      Message structure.
521  *       data     Data buffer.
522  *
523  * Returns:
524  *       0   - Success.
525  *       ~0  - Error.
526  *
527  */
528 
529 static int prism2mib_wepdefaultkey(struct mibrec *mib,
530 				   int isget,
531 				   struct wlandevice *wlandev,
532 				   struct hfa384x *hw,
533 				   struct p80211msg_dot11req_mibset *msg,
534 				   void *data)
535 {
536 	int result;
537 	struct p80211pstrd *pstr = data;
538 	u8 bytebuf[MIB_TMP_MAXLEN];
539 	u16 len;
540 
541 	if (isget) {
542 		result = 0;	/* Should never happen. */
543 	} else {
544 		len = (pstr->len > 5) ? HFA384x_RID_CNFWEP128DEFAULTKEY_LEN :
545 		    HFA384x_RID_CNFWEPDEFAULTKEY_LEN;
546 		memset(bytebuf, 0, len);
547 		memcpy(bytebuf, pstr->data, pstr->len);
548 		result = hfa384x_drvr_setconfig(hw, mib->parm1, bytebuf, len);
549 	}
550 
551 	return result;
552 }
553 
554 /*
555  * prism2mib_privacyinvoked
556  *
557  * Get/set the dot11PrivacyInvoked value.
558  *
559  * MIB record parameters:
560  *       parm1    Prism2 RID value.
561  *       parm2    Bit value for PrivacyInvoked flag.
562  *       parm3    Not used.
563  *
564  * Arguments:
565  *       mib      MIB record.
566  *       isget    MIBGET/MIBSET flag.
567  *       wlandev  wlan device structure.
568  *       priv     "priv" structure.
569  *       hw       "hw" structure.
570  *       msg      Message structure.
571  *       data     Data buffer.
572  *
573  * Returns:
574  *       0   - Success.
575  *       ~0  - Error.
576  *
577  */
578 
579 static int prism2mib_privacyinvoked(struct mibrec *mib,
580 				    int isget,
581 				    struct wlandevice *wlandev,
582 				    struct hfa384x *hw,
583 				    struct p80211msg_dot11req_mibset *msg,
584 				    void *data)
585 {
586 	if (wlandev->hostwep & HOSTWEP_DECRYPT) {
587 		if (wlandev->hostwep & HOSTWEP_DECRYPT)
588 			mib->parm2 |= HFA384x_WEPFLAGS_DISABLE_RXCRYPT;
589 		if (wlandev->hostwep & HOSTWEP_ENCRYPT)
590 			mib->parm2 |= HFA384x_WEPFLAGS_DISABLE_TXCRYPT;
591 	}
592 
593 	return prism2mib_flag(mib, isget, wlandev, hw, msg, data);
594 }
595 
596 /*
597  * prism2mib_excludeunencrypted
598  *
599  * Get/set the dot11ExcludeUnencrypted value.
600  *
601  * MIB record parameters:
602  *       parm1    Prism2 RID value.
603  *       parm2    Bit value for ExcludeUnencrypted flag.
604  *       parm3    Not used.
605  *
606  * Arguments:
607  *       mib      MIB record.
608  *       isget    MIBGET/MIBSET flag.
609  *       wlandev  wlan device structure.
610  *       priv     "priv" structure.
611  *       hw       "hw" structure.
612  *       msg      Message structure.
613  *       data     Data buffer.
614  *
615  * Returns:
616  *       0   - Success.
617  *       ~0  - Error.
618  *
619  */
620 
621 static int prism2mib_excludeunencrypted(struct mibrec *mib,
622 					int isget,
623 					struct wlandevice *wlandev,
624 					struct hfa384x *hw,
625 					struct p80211msg_dot11req_mibset *msg,
626 					void *data)
627 {
628 	return prism2mib_flag(mib, isget, wlandev, hw, msg, data);
629 }
630 
631 /*
632  * prism2mib_fragmentationthreshold
633  *
634  * Get/set the fragmentation threshold.
635  *
636  * MIB record parameters:
637  *       parm1    Prism2 RID value.
638  *       parm2    Not used.
639  *       parm3    Not used.
640  *
641  * Arguments:
642  *       mib      MIB record.
643  *       isget    MIBGET/MIBSET flag.
644  *       wlandev  wlan device structure.
645  *       priv     "priv" structure.
646  *       hw       "hw" structure.
647  *       msg      Message structure.
648  *       data     Data buffer.
649  *
650  * Returns:
651  *       0   - Success.
652  *       ~0  - Error.
653  *
654  */
655 
656 static int
657 prism2mib_fragmentationthreshold(struct mibrec *mib,
658 				 int isget,
659 				 struct wlandevice *wlandev,
660 				 struct hfa384x *hw,
661 				 struct p80211msg_dot11req_mibset *msg,
662 				 void *data)
663 {
664 	u32 *uint32 = data;
665 
666 	if (!isget)
667 		if ((*uint32) % 2) {
668 			netdev_warn(wlandev->netdev,
669 				    "Attempt to set odd number FragmentationThreshold\n");
670 			msg->resultcode.data =
671 			    P80211ENUM_resultcode_not_supported;
672 			return 0;
673 		}
674 
675 	return prism2mib_uint32(mib, isget, wlandev, hw, msg, data);
676 }
677 
678 /*
679  * prism2mib_priv
680  *
681  * Get/set values in the "priv" data structure.
682  *
683  * MIB record parameters:
684  *       parm1    Not used.
685  *       parm2    Not used.
686  *       parm3    Not used.
687  *
688  * Arguments:
689  *       mib      MIB record.
690  *       isget    MIBGET/MIBSET flag.
691  *       wlandev  wlan device structure.
692  *       priv     "priv" structure.
693  *       hw       "hw" structure.
694  *       msg      Message structure.
695  *       data     Data buffer.
696  *
697  * Returns:
698  *       0   - Success.
699  *       ~0  - Error.
700  *
701  */
702 
703 static int prism2mib_priv(struct mibrec *mib,
704 			  int isget,
705 			  struct wlandevice *wlandev,
706 			  struct hfa384x *hw,
707 			  struct p80211msg_dot11req_mibset *msg, void *data)
708 {
709 	struct p80211pstrd *pstr = data;
710 
711 	switch (mib->did) {
712 	case DIDMIB_LNX_CONFIGTABLE_RSNAIE: {
713 		struct hfa384x_wpa_data wpa;
714 
715 		if (isget) {
716 			hfa384x_drvr_getconfig(hw,
717 					       HFA384x_RID_CNFWPADATA,
718 					       (u8 *)&wpa,
719 					       sizeof(wpa));
720 			pstr->len = le16_to_cpu(wpa.datalen);
721 			memcpy(pstr->data, wpa.data, pstr->len);
722 		} else {
723 			wpa.datalen = cpu_to_le16(pstr->len);
724 			memcpy(wpa.data, pstr->data, pstr->len);
725 
726 			hfa384x_drvr_setconfig(hw,
727 					       HFA384x_RID_CNFWPADATA,
728 					       (u8 *)&wpa,
729 					       sizeof(wpa));
730 		}
731 		break;
732 	}
733 	default:
734 		netdev_err(wlandev->netdev, "Unhandled DID 0x%08x\n", mib->did);
735 	}
736 
737 	return 0;
738 }
739 
740 /*
741  * prism2mgmt_pstr2bytestr
742  *
743  * Convert the pstr data in the WLAN message structure into an hfa384x
744  * byte string format.
745  *
746  * Arguments:
747  *	bytestr		hfa384x byte string data type
748  *	pstr		wlan message data
749  *
750  * Returns:
751  *	Nothing
752  *
753  */
754 
755 void prism2mgmt_pstr2bytestr(struct hfa384x_bytestr *bytestr,
756 			     struct p80211pstrd *pstr)
757 {
758 	bytestr->len = cpu_to_le16((u16)(pstr->len));
759 	memcpy(bytestr->data, pstr->data, pstr->len);
760 }
761 
762 /*
763  * prism2mgmt_bytestr2pstr
764  *
765  * Convert the data in an hfa384x byte string format into a
766  * pstr in the WLAN message.
767  *
768  * Arguments:
769  *	bytestr		hfa384x byte string data type
770  *	msg		wlan message
771  *
772  * Returns:
773  *	Nothing
774  *
775  */
776 
777 void prism2mgmt_bytestr2pstr(struct hfa384x_bytestr *bytestr,
778 			     struct p80211pstrd *pstr)
779 {
780 	pstr->len = (u8)(le16_to_cpu(bytestr->len));
781 	memcpy(pstr->data, bytestr->data, pstr->len);
782 }
783 
784 /*
785  * prism2mgmt_bytearea2pstr
786  *
787  * Convert the data in an hfa384x byte area format into a pstr
788  * in the WLAN message.
789  *
790  * Arguments:
791  *	bytearea	hfa384x byte area data type
792  *	msg		wlan message
793  *
794  * Returns:
795  *	Nothing
796  *
797  */
798 
799 void prism2mgmt_bytearea2pstr(u8 *bytearea, struct p80211pstrd *pstr, int len)
800 {
801 	pstr->len = (u8)len;
802 	memcpy(pstr->data, bytearea, len);
803 }
804