p80211req.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /* src/p80211/p80211req.c
  2. *
  3. * Request/Indication/MacMgmt interface handling functions
  4. *
  5. * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
  6. * --------------------------------------------------------------------
  7. *
  8. * linux-wlan
  9. *
  10. * The contents of this file are subject to the Mozilla Public
  11. * License Version 1.1 (the "License"); you may not use this file
  12. * except in compliance with the License. You may obtain a copy of
  13. * the License at http://www.mozilla.org/MPL/
  14. *
  15. * Software distributed under the License is distributed on an "AS
  16. * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  17. * implied. See the License for the specific language governing
  18. * rights and limitations under the License.
  19. *
  20. * Alternatively, the contents of this file may be used under the
  21. * terms of the GNU Public License version 2 (the "GPL"), in which
  22. * case the provisions of the GPL are applicable instead of the
  23. * above. If you wish to allow the use of your version of this file
  24. * only under the terms of the GPL and not to allow others to use
  25. * your version of this file under the MPL, indicate your decision
  26. * by deleting the provisions above and replace them with the notice
  27. * and other provisions required by the GPL. If you do not delete
  28. * the provisions above, a recipient may use your version of this
  29. * file under either the MPL or the GPL.
  30. *
  31. * --------------------------------------------------------------------
  32. *
  33. * Inquiries regarding the linux-wlan Open Source project can be
  34. * made directly to:
  35. *
  36. * AbsoluteValue Systems Inc.
  37. * info@linux-wlan.com
  38. * http://www.linux-wlan.com
  39. *
  40. * --------------------------------------------------------------------
  41. *
  42. * Portions of the development of this software were funded by
  43. * Intersil Corporation as part of PRISM(R) chipset product development.
  44. *
  45. * --------------------------------------------------------------------
  46. *
  47. * This file contains the functions, types, and macros to support the
  48. * MLME request interface that's implemented via the device ioctls.
  49. *
  50. * --------------------------------------------------------------------
  51. */
  52. #include <linux/module.h>
  53. #include <linux/kernel.h>
  54. #include <linux/sched.h>
  55. #include <linux/types.h>
  56. #include <linux/skbuff.h>
  57. #include <linux/wireless.h>
  58. #include <linux/netdevice.h>
  59. #include <linux/etherdevice.h>
  60. #include <net/sock.h>
  61. #include <linux/netlink.h>
  62. #include "p80211types.h"
  63. #include "p80211hdr.h"
  64. #include "p80211mgmt.h"
  65. #include "p80211conv.h"
  66. #include "p80211msg.h"
  67. #include "p80211netdev.h"
  68. #include "p80211ioctl.h"
  69. #include "p80211metadef.h"
  70. #include "p80211metastruct.h"
  71. #include "p80211req.h"
  72. static void p80211req_handlemsg(wlandevice_t *wlandev, struct p80211msg *msg);
  73. static int p80211req_mibset_mibget(wlandevice_t *wlandev,
  74. struct p80211msg_dot11req_mibget *mib_msg,
  75. int isget);
  76. /*----------------------------------------------------------------
  77. * p80211req_dorequest
  78. *
  79. * Handles an MLME reqest/confirm message.
  80. *
  81. * Arguments:
  82. * wlandev WLAN device struct
  83. * msgbuf Buffer containing a request message
  84. *
  85. * Returns:
  86. * 0 on success, an errno otherwise
  87. *
  88. * Call context:
  89. * Potentially blocks the caller, so it's a good idea to
  90. * not call this function from an interrupt context.
  91. ----------------------------------------------------------------*/
  92. int p80211req_dorequest(wlandevice_t *wlandev, u8 *msgbuf)
  93. {
  94. int result = 0;
  95. struct p80211msg *msg = (struct p80211msg *) msgbuf;
  96. /* Check to make sure the MSD is running */
  97. if (!((wlandev->msdstate == WLAN_MSD_HWPRESENT &&
  98. msg->msgcode == DIDmsg_lnxreq_ifstate) ||
  99. wlandev->msdstate == WLAN_MSD_RUNNING ||
  100. wlandev->msdstate == WLAN_MSD_FWLOAD)) {
  101. return -ENODEV;
  102. }
  103. /* Check Permissions */
  104. if (!capable(CAP_NET_ADMIN) &&
  105. (msg->msgcode != DIDmsg_dot11req_mibget)) {
  106. printk(KERN_ERR
  107. "%s: only dot11req_mibget allowed for non-root.\n",
  108. wlandev->name);
  109. return -EPERM;
  110. }
  111. /* Check for busy status */
  112. if (test_and_set_bit(1, &(wlandev->request_pending)))
  113. return -EBUSY;
  114. /* Allow p80211 to look at msg and handle if desired. */
  115. /* So far, all p80211 msgs are immediate, no waitq/timer necessary */
  116. /* This may change. */
  117. p80211req_handlemsg(wlandev, msg);
  118. /* Pass it down to wlandev via wlandev->mlmerequest */
  119. if (wlandev->mlmerequest != NULL)
  120. wlandev->mlmerequest(wlandev, msg);
  121. clear_bit(1, &(wlandev->request_pending));
  122. return result; /* if result==0, msg->status still may contain an err */
  123. }
  124. /*----------------------------------------------------------------
  125. * p80211req_handlemsg
  126. *
  127. * p80211 message handler. Primarily looks for messages that
  128. * belong to p80211 and then dispatches the appropriate response.
  129. * TODO: we don't do anything yet. Once the linuxMIB is better
  130. * defined we'll need a get/set handler.
  131. *
  132. * Arguments:
  133. * wlandev WLAN device struct
  134. * msg message structure
  135. *
  136. * Returns:
  137. * nothing (any results are set in the status field of the msg)
  138. *
  139. * Call context:
  140. * Process thread
  141. ----------------------------------------------------------------*/
  142. static void p80211req_handlemsg(wlandevice_t *wlandev, struct p80211msg *msg)
  143. {
  144. switch (msg->msgcode) {
  145. case DIDmsg_lnxreq_hostwep:{
  146. struct p80211msg_lnxreq_hostwep *req =
  147. (struct p80211msg_lnxreq_hostwep *) msg;
  148. wlandev->hostwep &=
  149. ~(HOSTWEP_DECRYPT | HOSTWEP_ENCRYPT);
  150. if (req->decrypt.data == P80211ENUM_truth_true)
  151. wlandev->hostwep |= HOSTWEP_DECRYPT;
  152. if (req->encrypt.data == P80211ENUM_truth_true)
  153. wlandev->hostwep |= HOSTWEP_ENCRYPT;
  154. break;
  155. }
  156. case DIDmsg_dot11req_mibget:
  157. case DIDmsg_dot11req_mibset:{
  158. int isget = (msg->msgcode == DIDmsg_dot11req_mibget);
  159. struct p80211msg_dot11req_mibget *mib_msg =
  160. (struct p80211msg_dot11req_mibget *) msg;
  161. p80211req_mibset_mibget(wlandev, mib_msg, isget);
  162. }
  163. default:
  164. ;
  165. } /* switch msg->msgcode */
  166. return;
  167. }
  168. static int p80211req_mibset_mibget(wlandevice_t *wlandev,
  169. struct p80211msg_dot11req_mibget *mib_msg,
  170. int isget)
  171. {
  172. p80211itemd_t *mibitem = (p80211itemd_t *) mib_msg->mibattribute.data;
  173. p80211pstrd_t *pstr = (p80211pstrd_t *) mibitem->data;
  174. u8 *key = mibitem->data + sizeof(p80211pstrd_t);
  175. switch (mibitem->did) {
  176. case DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey0:{
  177. if (!isget)
  178. wep_change_key(wlandev, 0, key, pstr->len);
  179. break;
  180. }
  181. case DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey1:{
  182. if (!isget)
  183. wep_change_key(wlandev, 1, key, pstr->len);
  184. break;
  185. }
  186. case DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey2:{
  187. if (!isget)
  188. wep_change_key(wlandev, 2, key, pstr->len);
  189. break;
  190. }
  191. case DIDmib_dot11smt_dot11WEPDefaultKeysTable_dot11WEPDefaultKey3:{
  192. if (!isget)
  193. wep_change_key(wlandev, 3, key, pstr->len);
  194. break;
  195. }
  196. case DIDmib_dot11smt_dot11PrivacyTable_dot11WEPDefaultKeyID:{
  197. u32 *data = (u32 *) mibitem->data;
  198. if (isget) {
  199. *data =
  200. wlandev->hostwep & HOSTWEP_DEFAULTKEY_MASK;
  201. } else {
  202. wlandev->hostwep &= ~(HOSTWEP_DEFAULTKEY_MASK);
  203. wlandev->hostwep |=
  204. (*data & HOSTWEP_DEFAULTKEY_MASK);
  205. }
  206. break;
  207. }
  208. case DIDmib_dot11smt_dot11PrivacyTable_dot11PrivacyInvoked:{
  209. u32 *data = (u32 *) mibitem->data;
  210. if (isget) {
  211. if (wlandev->hostwep & HOSTWEP_PRIVACYINVOKED)
  212. *data = P80211ENUM_truth_true;
  213. else
  214. *data = P80211ENUM_truth_false;
  215. } else {
  216. wlandev->hostwep &= ~(HOSTWEP_PRIVACYINVOKED);
  217. if (*data == P80211ENUM_truth_true)
  218. wlandev->hostwep |=
  219. HOSTWEP_PRIVACYINVOKED;
  220. }
  221. break;
  222. }
  223. case DIDmib_dot11smt_dot11PrivacyTable_dot11ExcludeUnencrypted:{
  224. u32 *data = (u32 *) mibitem->data;
  225. if (isget) {
  226. if (wlandev->hostwep &
  227. HOSTWEP_EXCLUDEUNENCRYPTED)
  228. *data = P80211ENUM_truth_true;
  229. else
  230. *data = P80211ENUM_truth_false;
  231. } else {
  232. wlandev->hostwep &=
  233. ~(HOSTWEP_EXCLUDEUNENCRYPTED);
  234. if (*data == P80211ENUM_truth_true)
  235. wlandev->hostwep |=
  236. HOSTWEP_EXCLUDEUNENCRYPTED;
  237. }
  238. break;
  239. }
  240. default:
  241. ;
  242. }
  243. return 0;
  244. }