p80211req.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. // SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1)
  2. /* src/p80211/p80211req.c
  3. *
  4. * Request/Indication/MacMgmt interface handling functions
  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. * This file contains the functions, types, and macros to support the
  49. * MLME request interface that's implemented via the device ioctls.
  50. *
  51. * --------------------------------------------------------------------
  52. */
  53. #include <linux/module.h>
  54. #include <linux/kernel.h>
  55. #include <linux/sched.h>
  56. #include <linux/types.h>
  57. #include <linux/skbuff.h>
  58. #include <linux/wireless.h>
  59. #include <linux/netdevice.h>
  60. #include <linux/etherdevice.h>
  61. #include <net/sock.h>
  62. #include <linux/netlink.h>
  63. #include "p80211types.h"
  64. #include "p80211hdr.h"
  65. #include "p80211mgmt.h"
  66. #include "p80211conv.h"
  67. #include "p80211msg.h"
  68. #include "p80211netdev.h"
  69. #include "p80211ioctl.h"
  70. #include "p80211metadef.h"
  71. #include "p80211metastruct.h"
  72. #include "p80211req.h"
  73. static void p80211req_handlemsg(struct wlandevice *wlandev,
  74. struct p80211msg *msg);
  75. static void p80211req_mibset_mibget(struct wlandevice *wlandev,
  76. struct p80211msg_dot11req_mibget *mib_msg,
  77. int isget);
  78. static void p80211req_handle_action(struct wlandevice *wlandev, u32 *data,
  79. int isget, u32 flag)
  80. {
  81. if (isget) {
  82. if (wlandev->hostwep & flag)
  83. *data = P80211ENUM_truth_true;
  84. else
  85. *data = P80211ENUM_truth_false;
  86. } else {
  87. wlandev->hostwep &= ~flag;
  88. if (*data == P80211ENUM_truth_true)
  89. wlandev->hostwep |= flag;
  90. }
  91. }
  92. /*----------------------------------------------------------------
  93. * p80211req_dorequest
  94. *
  95. * Handles an MLME request/confirm message.
  96. *
  97. * Arguments:
  98. * wlandev WLAN device struct
  99. * msgbuf Buffer containing a request message
  100. *
  101. * Returns:
  102. * 0 on success, an errno otherwise
  103. *
  104. * Call context:
  105. * Potentially blocks the caller, so it's a good idea to
  106. * not call this function from an interrupt context.
  107. *----------------------------------------------------------------
  108. */
  109. int p80211req_dorequest(struct wlandevice *wlandev, u8 *msgbuf)
  110. {
  111. struct p80211msg *msg = (struct p80211msg *)msgbuf;
  112. /* Check to make sure the MSD is running */
  113. if (!((wlandev->msdstate == WLAN_MSD_HWPRESENT &&
  114. msg->msgcode == DIDmsg_lnxreq_ifstate) ||
  115. wlandev->msdstate == WLAN_MSD_RUNNING ||
  116. wlandev->msdstate == WLAN_MSD_FWLOAD)) {
  117. return -ENODEV;
  118. }
  119. /* Check Permissions */
  120. if (!capable(CAP_NET_ADMIN) &&
  121. (msg->msgcode != DIDmsg_dot11req_mibget)) {
  122. netdev_err(wlandev->netdev,
  123. "%s: only dot11req_mibget allowed for non-root.\n",
  124. wlandev->name);
  125. return -EPERM;
  126. }
  127. /* Check for busy status */
  128. if (test_and_set_bit(1, &wlandev->request_pending))
  129. return -EBUSY;
  130. /* Allow p80211 to look at msg and handle if desired. */
  131. /* So far, all p80211 msgs are immediate, no waitq/timer necessary */
  132. /* This may change. */
  133. p80211req_handlemsg(wlandev, msg);
  134. /* Pass it down to wlandev via wlandev->mlmerequest */
  135. if (wlandev->mlmerequest)
  136. wlandev->mlmerequest(wlandev, msg);
  137. clear_bit(1, &wlandev->request_pending);
  138. return 0; /* if result==0, msg->status still may contain an err */
  139. }
  140. /*----------------------------------------------------------------
  141. * p80211req_handlemsg
  142. *
  143. * p80211 message handler. Primarily looks for messages that
  144. * belong to p80211 and then dispatches the appropriate response.
  145. * TODO: we don't do anything yet. Once the linuxMIB is better
  146. * defined we'll need a get/set handler.
  147. *
  148. * Arguments:
  149. * wlandev WLAN device struct
  150. * msg message structure
  151. *
  152. * Returns:
  153. * nothing (any results are set in the status field of the msg)
  154. *
  155. * Call context:
  156. * Process thread
  157. *----------------------------------------------------------------
  158. */
  159. static void p80211req_handlemsg(struct wlandevice *wlandev,
  160. struct p80211msg *msg)
  161. {
  162. switch (msg->msgcode) {
  163. case DIDmsg_lnxreq_hostwep:{
  164. struct p80211msg_lnxreq_hostwep *req =
  165. (struct p80211msg_lnxreq_hostwep *)msg;
  166. wlandev->hostwep &=
  167. ~(HOSTWEP_DECRYPT | HOSTWEP_ENCRYPT);
  168. if (req->decrypt.data == P80211ENUM_truth_true)
  169. wlandev->hostwep |= HOSTWEP_DECRYPT;
  170. if (req->encrypt.data == P80211ENUM_truth_true)
  171. wlandev->hostwep |= HOSTWEP_ENCRYPT;
  172. break;
  173. }
  174. case DIDmsg_dot11req_mibget:
  175. case DIDmsg_dot11req_mibset:{
  176. int isget = (msg->msgcode == DIDmsg_dot11req_mibget);
  177. struct p80211msg_dot11req_mibget *mib_msg =
  178. (struct p80211msg_dot11req_mibget *)msg;
  179. p80211req_mibset_mibget(wlandev, mib_msg, isget);
  180. break;
  181. }
  182. } /* switch msg->msgcode */
  183. }
  184. static void p80211req_mibset_mibget(struct wlandevice *wlandev,
  185. struct p80211msg_dot11req_mibget *mib_msg,
  186. int isget)
  187. {
  188. struct p80211itemd *mibitem =
  189. (struct p80211itemd *)mib_msg->mibattribute.data;
  190. struct p80211pstrd *pstr = (struct p80211pstrd *)mibitem->data;
  191. u8 *key = mibitem->data + sizeof(struct p80211pstrd);
  192. switch (mibitem->did) {
  193. case DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(1):
  194. case DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(2):
  195. case DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(3):
  196. case DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(4):
  197. if (!isget)
  198. wep_change_key(wlandev,
  199. P80211DID_ITEM(mibitem->did) - 1,
  200. key, pstr->len);
  201. break;
  202. case DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID:{
  203. u32 *data = (u32 *)mibitem->data;
  204. if (isget) {
  205. *data = wlandev->hostwep & HOSTWEP_DEFAULTKEY_MASK;
  206. } else {
  207. wlandev->hostwep &= ~(HOSTWEP_DEFAULTKEY_MASK);
  208. wlandev->hostwep |= (*data & HOSTWEP_DEFAULTKEY_MASK);
  209. }
  210. break;
  211. }
  212. case DIDmib_dot11smt_dot11PrivacyTable_dot11PrivacyInvoked:{
  213. u32 *data = (u32 *)mibitem->data;
  214. p80211req_handle_action(wlandev, data, isget,
  215. HOSTWEP_PRIVACYINVOKED);
  216. break;
  217. }
  218. case DIDmib_dot11smt_dot11PrivacyTable_dot11ExcludeUnencrypted:{
  219. u32 *data = (u32 *)mibitem->data;
  220. p80211req_handle_action(wlandev, data, isget,
  221. HOSTWEP_EXCLUDEUNENCRYPTED);
  222. break;
  223. }
  224. }
  225. }